# Thermodynamics In Scilab

In this page, we present some toolboxes which are providing thermodynamics features for Scilab. We review two toolboxes in this field: AmsterChem's toolboxes for Scilab, based on the CAPE-OPEN standard and Excel Engineering's toolbox for water and steam computations in Scilab.

Contents

## Introduction

Scilab can be used for thermodynamics calculations. For example, chemical equilibrium may result in nonlinear systems of equations, which can be solved by the Scilab function *fsolve*. An example of this is given in the paper :

http://www.ifi.unicamp.br/ceneh/WICaC2008/PDF/19-AdilsonJAssis.pdf

where Assis, Hori, Avila-Neto and Franco, four researchers from the School of Chemical Engineering of the Federal University of Uberlandia in Brazil have used Scilab to conduct a comparative thermodynamic analysis of methane reforming reactions and to asses the influence of key operational variables on chemical equilibrium.

In this page, we present two toolboxes in this field:

AmsterChem's toolboxes for Scilab, based on the CAPE-OPEN standard,

- Excel Engineering's toolboxes for water and steam computations in Scilab.

## AmsterChem's tools for Scilab

AmsterChem is a company which has an expertise in providing consultancy in the field of process simulation and modeling. They are experts in CAPE-OPEN software development.

AmsterChem provides two tools for Scilab:

SciLab CAPE-OPEN Unit Operation: http://www.amsterchem.com/scilabunitop.html

SciLab CAPE-OPEN Thermo Import: http://www.amsterchem.com/scilabthermo.html

Both modules are available for Windows can be downloaded at :

http://www.amsterchem.com/downloads.html

These toolboxes have been updated in 2010.

### CAPE-OPEN Unit Operation

The SciLab CAPE-OPEN Unit Operation is a unit operation implementation for which the calculations can be entered in SciLab.

The toolbox provides the following functions:

- getAggregationState get the state of aggregation for a given phase
- getAggregationStateName get the name of the state of aggregation for a given phase
- getCompoundConstant get a constant property for each compound
- getEquilibrium calculate thermodynamic phase equilibrium
- getEquilibriumProperty calculate a property at thermodynamic phase equilibrium
- getFeedEquilibrium get the thermodynamic phase equilibrium of a feed
- getFeedProp get a property of a feed
- getNumberOfFeeds returns the number of feeds
- getNumberOfProducts returns the number of products
- getParameter get the value of a parameter
- getPDependentProperty get a value for each compound that only depends on pressure
- getPropertyUnitOfMeasure get a textual unit of measure description for a property
- getSinglePhaseProperty calculate a mixture property for a given phase
- getTDependentProperty get a value for each compound that only depends on temperature
- getTwoPhaseProperty calculate a mixture property for the combination of two given phases
- getUnitOperationName returns the name of the unit operation
- setParameter set the value of parameter
- setProduct specify the state of a product stream; must be called for each product
- setReport set the content of a report

In addition to the functions, the toolbox provides the following global variables:

- nComp : number of compounds
- compNames : names of the compounds; one string for each compound
- nPhase : number of defined phases
- phaseNames : names of defined phases; one string for each defined phase
- phaseAggregationStates : aggregation states for defined phases; one integer for each string

The following is a simple example.

f1=getFeedProp(1,"flow") f2=getFeedProp(2,"flow") h1=getFeedProp(1,"enthalpy") h2=getFeedProp(2,"enthalpy") p1=getFeedProp(1,"pressure") p2=getFeedProp(2,"pressure") p=min(p1,p2) f=f1+f2 h=(h1*f1+h2*f2)/f totF=sum(f) setProduct(1,totF,f/totF,"pressure",p,"enthalpy",h)

The SciLab CAPE-OPEN Unit Operation is free of charge for personal and academic use. For commercial use, a license fee must be paid.

### SciLab CAPE-OPEN Thermo Import

This SciLab package allows for importing CAPE-OPEN version 1.1 thermodynamic and physical Property Packages into SciLab.

The toolbox provides functions for:

- Package Maintenance,
- Package Information,
- Property and equilibrium calculations,
- General functions.

For example, the following functions can be used to calculate thermodynamic and physical properties and thermodynamic phase equilibria:

- capeOpenCompoundConstant: obtain compound constant values
- capeOpenTDepProp: calculate temperature dependent properties
- capeOpenPDepProp: calculate pressure dependent properties
- capeOpen1PhaseProp: calculate single-phase properties
- capeOpen2PhaseProp: calculate two-phase properties
- capeOpenEquilibrium: calculate thermodynamic phase equilibrium
- capeOpenEquilibriumProp: calculate properties at specified thermodynamic phase equilibrium

We cannot list all the function in this page. Please read the help pages provided in the toolbox for more details on this topic.

### Older versions

An older version of this toolbox was released in 2009 on the former Toolbox center :

http://www.scilab.org/contrib/index_contrib.php?page=displayContribution&fileID=1203

## Excel Engineering's tools for Scilab

Excel Engineering has developped open source softwares for Scilab, including Steam and water properties based on the "International Association for Properties of Water and Steam Industrial Formulation 1997 (IAPWS IF-97).

http://xsteam.sourceforge.net/

Download it here : https://sourceforge.net/projects/xsteam/

A full implementation of the IF-97 standard that provides very accurate steam and water properties in ranges from 0-1000 bar and 0-2000°C for use in process Engineering Industry.

Provided thermodynamic properties are:

- Temperature
- Pressure
- Enthalpy
- Specific volume
- Density
- Specific entropy
- Specific internal energy
- Specific isobaric heat capacity
- Specific isochoric heat capacity
- Speed of sound
- Viscosity
- Vapour fraction

We are free to use, modify and distribute the code as long as authorship is properly acknowledged.

### An example

The latest version of XSteam.sci is available here:

https://fileexchange.scilab.org/toolboxes/502000

In order to use the toolbox, we simply download the script XSteam.sci, and execute it:

exec("XSteam.sci");

The toolbox provides the following functions:

- Out=XSteam(fun,In1,In2)
- v1_pT = v1_pT(p, T)
- h1_pT = h1_pT(p, T)
- u1_pT = u1_pT(p, T)
- s1_pT = s1_pT(p, T)
- Cp1_pT = Cp1_pT(p, T)
- Cv1_pT = Cv1_pT(p, T)
- w1_pT = w1_pT(p, T)
- T1_ph = T1_ph(p, h)
- T1_ps = T1_ps(p, s)
- p1_hs = p1_hs(h, s)
- T1_prho = T1_prho(p ,rho)
- v2_pT = v2_pT(p, T)
- h2_pT = h2_pT(p, T)
- u2_pT = u2_pT(p, T)
- s2_pT = s2_pT(p, T)
- Cp2_pT = Cp2_pT(p, T)
- Cv2_pT = Cv2_pT(p, T)
- w2_pT = w2_pT(p, T)
- T2_ph = T2_ph(p, h)
- T2_ps = T2_ps(p, s)
- p2_hs = p2_hs(h, s)
- p3_rhoT = p3_rhoT(rho, T)
- u3_rhoT = u3_rhoT(rho, T)
- h3_rhoT = h3_rhoT(rho, T)
- s3_rhoT = s3_rhoT(rho, T)
- Cp3_rhoT = Cp3_rhoT(rho, T)
- Cv3_rhoT = Cv3_rhoT(rho, T)
- w3_rhoT = w3_rhoT(rho, T)
- T3_ph = T3_ph(p, h)
- v3_ph = v3_ph(p, h)
- T3_ps = T3_ps(p, s)
- v3_ps = v3_ps(p, s)
- p3_hs = p3_hs(h, s)
- h3_pT = h3_pT(p, T)
- T3_prho = T3_prho(p, rho)
- p4_T = p4_T(T)
- T4_p = T4_p(p)
- h4_s = h4_s(s)
- p4_s = p4_s(s)
- h4L_p = h4L_p(p)
- h4V_p = h4V_p(p)
- x4_ph = x4_ph(p, h)
- x4_ps = x4_ps(p, s)
- T4_hs = T4_hs(h, s)
- h5_pT = h5_pT(p, T)
- v5_pT = v5_pT(p, T)
- u5_pT = u5_pT(p, T)
- Cp5_pT = Cp5_pT(p, T)
- s5_pT = s5_pT(p, T)
- Cv5_pT = Cv5_pT(p, T)
- w5_pT = w5_pT(p, T)
- T5_ph = T5_ph(p, h)
- T5_ps = T5_ps(p, s)
- T5_prho=T5_prho(p,rho)
- region_pT = region_pT(p, T)
- region_ph = region_ph( p, h)
- region_ps = region_ps( p, s)
- region_hs = region_hs( h, s)
- Region_prho = Region_prho(p,rho)
- B23p_T = B23p_T(T)
- B23T_p = B23T_p(p)
- p3sat_h = p3sat_h(h)
- p3sat_s = p3sat_s(s)
- hB13_s = hB13_s(s)
- TB23_hs = TB23_hs(h, s)
my_AllRegions_pT = my_AllRegions_pT( p, T)

my_AllRegions_ph = my_AllRegions_ph( p, h)

- tc_ptrho = tc_ptrho( p, T, rho)
- Surface_Tension_T = Surface_Tension_T( T)
- toSIunit_p = toSIunit_p( Ins )
- fromSIunit_p = fromSIunit_p( Ins )
- toSIunit_T = toSIunit_T( Ins )
- fromSIunit_T = fromSIunit_T( Ins )
- toSIunit_h = toSIunit_h( Ins )
- fromSIunit_h = fromSIunit_h( Ins )
- toSIunit_v = toSIunit_v( Ins )
- fromSIunit_v = fromSIunit_v( Ins )
- toSIunit_s = toSIunit_s( Ins )
- fromSIunit_s = fromSIunit_s( Ins )
- toSIunit_u = toSIunit_u( Ins )
- fromSIunit_u = fromSIunit_u( Ins )
- toSIunit_Cp = toSIunit_Cp( Ins )
- fromSIunit_Cp = fromSIunit_Cp( Ins )
- toSIunit_Cv = toSIunit_Cv( Ins )
- fromSIunit_Cv = fromSIunit_Cv( Ins )
- toSIunit_w = toSIunit_w( Ins )
- fromSIunit_w = fromSIunit_w( Ins )
- toSIunit_tc = toSIunit_tc( Ins )
- fromSIunit_tc = fromSIunit_tc( Ins )
- toSIunit_st = toSIunit_st( Ins )
- fromSIunit_st = fromSIunit_st( Ins )
- toSIunit_x = toSIunit_x( Ins )
- fromSIunit_x = fromSIunit_x( Ins )
- toSIunit_vx = toSIunit_vx( Ins )
- fromSIunit_vx = fromSIunit_vx( Ins )
- toSIunit_my = toSIunit_my( Ins )
- fromSIunit_my = fromSIunit_my( Ins )
- err = check()

One of the main functions is the XSteam function. This function uses strings to specify which thermodynamical variable we want to compute. The main variables are the following:

- T : Temperature (deg C)
- p : Pressure (bar)
- h : Enthalpy (kJ/kg)
- v : Specific volume (m3/kg)
- rho : Density
- s : Specific entropy
- u : Specific internal energy
- Cp : Specific isobaric heat capacity
- Cv : Specific isochoric heat capacity
- w : Speed of sound
- my : Viscosity
- tc : Thermal Conductivity
- st : Surface Tension
- x : Vapour fraction
- vx : Vapour Volume Fraction

There are much more variables available in the function, including:

- Temperature
- Pressure
- Enthalpy
- Specific volume
- Density
- Specific entropy
- Specific internal energy
- Specific isobaric heat capacity
- Specific isochoric heat capacity
- Speed of sound
- Viscosity
- Thermal Conductivity
- Surface tension
- Vapour volume fraction

For example, to compute the enthalpy as a function of pressure (1 bar) and temperature (20 degC), we use the following script:

-->XSteam("h_pT",1,20) ans= 84.011811

Actually, the function provides so many variables that it is not possible to list them all in this page. Please read the comments in the file for more informations.

### Some more details

The first release of toolbox was released in 2006 by Magnus Holmgren.

The script was translated to Scilab format from XSteam.m using m2sci.pl (created by Torbjørn Pettersen).