Free Fluids Manual
Free Fluids Manual
4. FreeFluidsGui 17
5. FreeFluidsModelica 19
5.1. MediaCommon package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
5.1.1. DataRecord and associated packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
5.1.2. Functions package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
5.1.3. Types package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
5.2. IdealGasMedia package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
5.3. IdealGasMixture package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Contents
When we want to use the database information in a C program we need previously to export it, using FreeFluidsGui, as a binary file, and place this
file in a subdirectory labelled ’Data’, just as with UNIFAC data.
1. Basic data for the substances: MW, CAS number, boiling temperature, critical properties etc. All data are in SI units, with the exception of
dipole moment (Debye), quadrupole moment(Debye·m), and Van der Waals area and volume (A). The data is stored in the Products table,
and each product is identified by an unique Id.
2. Coefficients for the correlation of physical properties. The equations used are defined in the table CorrelationEquations. The combination of
equation, and input and output units, identifies completely how the correlation is used. The different combinations are defined in the table
Correlations. And in the table CorrelationParam we have the value of the parameters, identifying the substance and the correlation for which
these parameters apply.
3. EOS data. The different EOS used are defined in the table EOS. In the table EosParam you will find the parameters for each EOS, referencing
the product and EOS for which they apply. Due to the special complexity of the parametric EOS, in this table only the number of terms of
each type is indicated for these EOS, and the values for the parameters are stored in the table SWparam.
4. Substance description for different group contribution models: different flavours of UNIFAC, Bondi, Joback. The description is stored in tables
that link the substance Id, the group Id and the number of occurrences of the group in the substance. The tables are named Product_Model
5. Binary interaction parameters (BIP) for EOS and activity models. The supported activity models are defined in the table ActivityModels.
The BIP are stored in the tables EosInteraction and ActInteraction. There are 12 parameters for each pair, the first 6 are for the pair i,j and
the last 6 for the pair j,i. So, if you need to enter the BIP for the mixture acetone-water, you use the first 6 values for the acetone-water pair,
and the last 6 for the water-acetone pair. It seems too many parameters, but the number has been selected in order to give compatibility with
the Aspen format. Each register in the table identifies the first and second elements of the pair, the EOS type and mixing rule (the model in
case of activity) for which they apply, and the formula to use for the computation of the BIP from the parameters. The different formulas are
defined in the table InteractEquations. For cubic EOS with VdW or PR mixing rules, the first 3 parameters are for the calculation of k, using
the formula k = a + b ∗ T + Tc , and the forth for the calculation of l. In this case ki,j = kji and li,j = lji . For MKP mixing rule, only the first 3
parameters are used for the calculation of k, but ki,j 6= kji . For SAFT type EOS the first 3 parameters are used to compute the k for the εij
calculation, using also the formula: k = a + b ∗ T + Tc . For activity models it is also necessary to take into account the units used for the energy.
The database has been filled from different sources but only a small part is delivered with the program. Nevertheless you can populate it with data
from several interesting projects as: Caleb Bell’s Thermo, J.J. Gomera’s PychemQt, Chemsep, CoolProp, CHERIC, AIST, GESTIS, .... I have used
Python scripts to automate the transfer and probably I will publicate them in the future.
2.2. The GUI
You select the substance to use (from the connected database) at the combo-box located at the top of the program window. The substances are now
arranged in alphabetical order, but I expect to add a CAS based alternative. When you select a substance a FF_SubstanceData structure is loaded
with its basic data, and two more combo-box are loaded with the options available for this substance. You will find these combo-boxes at the top
of the ’Substance EOS calc’ tab. These combo-boxes allow you to select the EOS and the ideal gas heat capacity correlation to use. The selection
of an EOS is mandatory. If you do not select a Cp0 correlation the energy related properties will not be computed. When you select an EOS or a
correlation, its data is charged in the FF_SubstanceData structure.
The EOS implemented are: different flavours of Cubics, PCSAFT including association, polar PCSAFT using the dipole terms of Gross & Vrabeck
or that of Jog & Chapman, VR SAFT with Mie potential, and high precision reference equations using the multi-parameter methodology of Schmidt
&Wagner.
Once you have selected the EOS and the ideal gas heat capacity correlation, you specify the pressure at which the calculation will be performed
and the minimum and maximum temperatures. If you check the label ’Calc.saturation prop.’, vapor pressure, saturated densities, and vaporization
heat calculations will be added. When you press the button ’Calculate’ you will obtain 11 calculations between the minimum and the maximum
temperatures. The results of the calculation is displayed on the table; they are mainly obtained by EOS calculation, but at the bottom of the table,
after the derivatives of the reduced residual Helmhotz energy, you will find some additional calculations.
First there is the liquid density, calculated according to the correlation selected on the “Correlations/Tools” tab. If no correlation has been selected,
no data will be here. In the next row the Rackett equation is used to calculate the liquid density. A pressure correction is applied to both densities,
according to the Chueh-Prausnitz method.
2. How to use FreeFluids
It follows the liquid viscosity. As no reliable general equation has been found, it is calculated only if a correlation has previously been selected in the
corresponding tab. On the value given by the correlation, the pressure correction is applied using the Lucas method.
For liquid thermal conductivity and surface tension, the selected correlations are applied. Below the correlation results there are the results applying
selected prediction methods. The thermal conductivity is calculated according to the Latini methodology, and the surface tension according to
Sastri-Rao and to McLeod-Sugden. No pressure correction is applied later.
Gas viscosity and gas thermal conductivity are calculated by the selected correlations, and also by predictive methods. Lucas for viscosity, and
Chung for thermal conductivity. Later a pressure correction is applied to all results.
The liquid heat capacity at constant pressure (Cp) is also calculated according to the selected correlation and to the Bondi method.
The boiling point, at the defined pressure, is also calculated and displayed. The values of H and S displayed are always referenced to the ideal gas
state at 298.15ºK and 101325 Pa.
In plus to the main calculation from known P and T, you can perform alternative calculations from known thermodynamic variables. On the left of
the tab, you select the known variables, fill them with data and press the ’Calculate’ button located at the bottom. The unknown variables will be
filled.
At the left bottom of the tab you will find some check boxes and a ’Transfer’ button. Checking no more than two boxes, and pressing the ’Transfer’
button will copy the selected data in the columns 5 and 6 of the ’Substance Correlations/Tools’ table. The finality of this will be explained in the
next section.
On the top right of the tab you will find two buttons: ’Export calculations’ and ’Export substance as structure’. The first one will export the results
in the table in ’csv’ format, that can be imported for example by Excel for graphic representation. The second will create two files in the user selected
directory. The one with extension ’.sd’ will contain the FF_SubstanceData structure, with all the data charged, in binary format. The file with ’.txt’
extension will contain the Modelica package definition of the substance, to be copied to the FreeFluids.ExternalMedia.Fluids package.
It will work with the substance selected in the upper most combo-box. There are three different functionalities: Calculation and display of physical
properties, for the selected substance, using the correlations stored in the database. Regression of parameters for correlations and EOS from data
entered in the main table. Finding, and storage in the database, of the critical point given by a SAFT type EOS.
For the calculation and display of physical properties from the stored correlations, the use is simple: You select the correlation to use at the combo-
box, the minimum and maximum temperature for the calculation, and the initial row, and number of rows to calculate. You press the ’fill table’
button and you will obtain the result in SI units. The selected correlation is charged in the FF_SubstanceData structure, so when you export the
substance (described in the previous tab) it will bring with it the parameters of the used correlations. The correlations that have been selected (and
2.2. The GUI
are charged) are displayed at the top right of the tab, and you can control if they are displayed or not in the next calculation, by checking or not the
check boxes.
At the bottom of the table are buttons for clear the table, exchange columns, and apply common operations to a column (normally for unit conversion).
You can perform also extended corresponding states (ECS) calculations for the transport properties of the saturated liquid phase. You will find a
description of how to proceed in the tooltip popup.
The second functionality is the regression of parameters from data. Two type of parameters can be regressed: parameters for physical properties
correlations, and parameters for EOS. Lets review the first type: You need to put the data on the main table, with the first column being always for
temperature (or more generally for the independent variable). On the second column you put the data of the physical variable (dependent variable).
You can fill these data manually, import from a file with ’;’ delimited data, of fill with a previous calculation. Once you have the data in place,
tell the system from which row to which row you have filled the data, select the correlation to use for the regression and define limits and initial
values for the parameters to find. This last pass is normally not necessary as the system will use normal limits, if you do not specify any. If you
specify a limit for a parameter you must supply low and high limits and initial value. Once you press the ’Find corr.coef.’ button the result for
the best parameters will be displayed at the bottom of the tab in 30 seconds. For some calculations it is mandatory to fill previously (If it has not
been filled automatically, or you want to use different values) some data, for example critical temperature and pressure for Wagner equation. Some
of the correlations are not explicit functions of T, by swapping the columns of temperature and vapor pressure you can regress the correlation for
boiling point. And by bringing the enthalpy, obtained from a Cp correlation, to the first column, and the temperature to the second, you can find
the coefficients for the correlation of T as function of H. Finally by transferring the liquid density and the logarithm of the reduced bulk modulus,
from the EOS calculation tab to the correlations/tools tab and bringing the density to the first column and the bulk modulus to the second, you can
regress the correlation for the liquid reduced bulk modulus, and add it to the database.
Once you have the result of the parameters you can add them to the data base. This is done at the right bottom of the tab by pressing the ’Add
corr. to DB’ button. Previously you must specify which correlation are you adding (not all the correlations can be added), the valid limits for the
data used, and any other comment.
For the EOS parameter regression, there are two possible situations: you are regressing for a cubic EOS, using the critical values displayed at the
top of the tab. In this case the regression take into account only vapor pressure data, located at the second column of the table. This is the case for
almost all cubic EOS variations, except for ’PR 78 fit Tc,Pc,w’ and for ’PR fit b,a,w and Tc’. In this two cases density data (kg/m3) located on the
second column is also used. For SAFT type EOS you must fill vapor pressure and density data, but the format is more flexible than for cubic EOS.
As not necessarily you will have, at a defined temperature, data for both vapor pressure and density, you can enter rows with only vapor pressure or
only density data. For the rows with density data it is mandatory to specify the pressure at which the data is obtained, if it is at saturation pressure
you enter this pressure on the second column. If the pressure doesn’t correspond to a saturation pressure, you enter this pressure on the forth column.
Always in Pascal. Before to proceed with the calculation you indicate the range of rows to use, the maximum time to use in the optimization in
minutes (if you left to 0 it will take 30 seconds), and the number of dipoles in the molecule (only if you are using a polar SAFT equation).
In order to speed up calculations, when density data is used, a screening system is used for the possible solutions. You specify the maximum error
2. How to use FreeFluids
acceptable for the critical point (Zc) and for the the liquid density. All solutions over these limits will be automatically rejected. If you are regressing
data far from the critical point you can go up with the Zc filter (20% error could be OK), but if you are regressing data close to the critical point is
better to maintain it lower (7-8% could be OK). The obtained parameters and the errors are displayed at the bottom of the tab.
As with the correlations you can add the result of the optimization to the database. In this case you do not need to specify the type of EOS (it is
taken automatically from the regression), but you can add limits and comments.
After the regression of an EOS the parameters are automatically charged to the FF_SubstanceData structure and you can return to the ’Sub-
stance Eos calc.’ tab and perform the calculations with the parameters found. And transfer later the result of the calculations to the ’Substance
Correlations/Tools’ tab to compare with the regressed data.
The selected substance, with the correlations previously selected, can be exported in a format adequate for the FreeFluids.MediaCommon.DataRecord
used in the Modelica medium definition of FreeFluids.IdealGasMedia, FreeFluids.IdealGasMixture, and FreeFluids.TMedia. You need to export the
substance, better with .txt extension, edit it with a text editor, and copy to the FreeFluids.MediaCommon.MediaData package. Later you can use
this data in the medium definition extended from IdealGasMedium or from TMedium.
The last functionality is the calculation and storage of the critical point given by a SAFT type EOS. You must select the substance and load the
SAFT type EOS to use. If you have just calculated the coefficients for the SAFT EOS, it is already loaded. You have two buttons at the bottom of
the form: one for performing the calculation, and the other for storing the result in the database.
You define the mixture to use, and the conditions, in this tab, and you obtain the results in the ’Mixture Results’ tab.
You need to begin by selecting the substances that will form part of the mixture. This is done by selecting them in the upper combo-box and by
pressing the button ’Add subs.’ The substance will be added to the table on the upper left. If you are going to do a calculation that need a fixed
composition, you need enter the quantities in mass or moles and when pressing the ’Calc. fractions’ button they will be passed to molar and mass
fractions. If you are going to calculate the full envelope it is not necessary to enter these quantities.
Once specified the composition, it is necessary to establish the thermodynamic model to use. This is done by selecting options from the different
combo-boxes. First it is necessary to choose the model for the liquid phase. At the combo-box ’Liquid phase model’ you must choose between
Activity or Fugacity(EOS). Next you must choose the EOS for the gas phase (it will be used also for the liquid if you have chosen Fugacity). Once
you have selected the EOS you must select the exact EOS you are going to use for each substance. And depending on the properties you want to
calculate you must choose also the Cp0 correlation to use.
2.2. The GUI
Once established the models for the gas and liquid phases, it is still necessary do some selections. Once of them is the selection of the mixing rule
to use. If you have selected Activity as the liquid model, you must select ’VdW with out int.param.’ if you selected cubic EOS for the gas phase, or
nothing if you selected a SAFT EOS for the gas phase. Otherwise you select the mixing rule that will be used both for the liquid and gas phase.
If you selected Activity for the liquid phase, or you selected a cubic EOS with a gE mixing rule, you must select now the exact activity model to
use (UNIQUAC, UNIFAC ....). Otherwise this step is not necessary. If Activity has been selected for the liquid phase, you must also choose if the
reference fugacity will be the vapor pressure of the pure substances, or its fugacities at the same conditions. But I have observed that calculations
using Vp as reference are not performing.
Finally, if necessary, you must define the binary interaction parameters. By default they are initialized to 0 and are not necessary for UNIFAC activity
models. If you are using an activity model not based on UNIFAC the interaction parameters will be used for this model, otherwise they will be used
for the selected EOS. The system of entering the parameters (if needed) is the following: You touch on the left table ’Pair substances selection’ the
position of the pair to specify. If there are values in the database for this pair you will be able to open the combo-box ’Binary interaction parameter
selection’. You select the option you want and the values will be charged on the table ready for use. Otherwise you can enter the values manually
for the selected pair.
When you finish all the selections you press the ’Create system’ button and the system will be ready for performing calculations. After creating the
system you can still change the quantities in the composition and the thermodynamic variables at which the calculations are done. But if you need
to change the substances used or the thermodynamic models you will need to press again the ’Create system’ button.
When the system has been created you can export it, if needed, to a file. A FF_MixData structure, containing the thermodynamic model selected,
and a array with the composition will be exported in binary format. You can later import this file to charge the thermodynamic model selection and
the composition, in order to avoid duplicate work entering data.
Once you have created or imported the system you can perform the following calculations:
1. Stability check: According to the Michel L. Michelsen methodology or with a global optimizer, depending on your selection on the radio
buttons. If the modified tangent plane distance is lower than −1e−4 it indicates a unstable composition. It should be just when it is below 0,
but probably due to numerical precision problems you can get tpd of for example −1e−6 for stable systems.
2. P,T flash calculation: Again according to the Michelsen methodology, or with a global optimizer (improved simulated annealing, or differential
evolution ). All methodologies will manage VL and LL flashes, but for LL the global optimizers are probably more adequate.
In this tab you will find the results of the flash and phase envelope calculations. In order to confirm that the result of the flash has been stable
phases, you can check its stability. Select the phase you want to check and press the check button. The algorithm used for the check will be the one
selected in the Mixture Calc. tab. Any value lower than −1e−4 will indicate an unstable phase.
You can perform also the calculation of the transport properties of the selected phase. You must indicate if you want the phase to be treated as
liquid or gas.
Packages description
3. FreeFluidsC
To be filled in the future.
4. FreeFluidsGui
To be filled in the future.
5. FreeFluidsModelica
The DataRecord record in the MediaCommon package defines the container for the individual substance data. This data will be used later by the
media packages written directly in Modelica language: IdealGasMedia, IdealGasMixture and TMedia. It contains basic data regarding the substance:
name, description, CAS, chemical family,...and correlations for several physical properties, normally as function of temperature. Each correlation
has: equation to use for its calculation, coefficients, and limits of usage.
The data for each individual fluid is inside the subpackages: MediaDataAL, and MediaDataMZ. Each data is defined as a constant DataRecord, with
the name of the substance.
You can create a new record, in those subpackages, copying the MediaDataTemplate (it is inside the MediaCommon package) and filling it manually.
Nevertheless the faster and more convenient way is to create the record from the FreeFluidsGui program. You need to select the substance from the
database, select the correlations you want to be included in the record, and export it in Modelica format. You can put the file in any place, better
with the .txt extension. Later you edit the file, copy its content, and paste it inside the MediaData package. You still need to declare the substance
inside the Media packages, filling the name and the origin of the data, that will be the record you just copied.
When using the data in the IdealGasMedia package, only the Cp0 is needed, but you can use also gas viscosity, and gas thermal conductivity
correlations. The vapor pressure correlation is also recommended, in order to check if we are working in the gas state.
When using the data in the TMedia package, you will need at least the following correlations: saturated density, vapor pressure, liquid heat capacity.
Plus vaporization enthalpy and saturated gas density, if you want to work also with the gas phase. Transport properties correlations as for your
needs, and reduced liquid bulk modulus if you want to work at high pressures (till 200 bars). If you want to force the liquid state you can set Tc at
a high value, and Pc at a low value (look as example to the MarlothermSH medium).
5. FreeFluidsModelica
Contains the functions that are common to several media packages. It follows their description.
• CorrelationSolver: It uses the Anderson-Bjork modification of Regula Falsi method for the inverse solving of a correlation. The correlation (f)
is defined as a replaceable function. You must extend the CorrelationSolver redeclaring f as the function you want to use. This function must
return a Real value, and must accept the calling parameters that will be used by the solver.
• PhysPropCorr: Provides the calculations of physical properties as function of one independent variable (normally T). It needs as input: the
number of the correlation to use, the coefficients for the correlation, the molecular weight of the substance, and the value of the independent
variable. It returns the value of the physical property. It has an equivalent written in C inside the FFphysprop.c file in the Resources directory.
• PhysPropCorrInv: Performs the inverse solving of the PhysPropCorr function.
• SpecificEnthalpyCorr: Provides the calculation of the specific enthalpy as function of T. You can use correlations using ideal gas constant
pressure heat capacity, or liquid heat capacity. Inputs are the same and it has also its equivalent in C.
• SpecificEnthalpyCorrInv: Provides the calculation of T as function of enthalpy. It needs as input: the number of the correlation to use, the
coefficients for the correlation, the molecular weight of the substance, the maximum value for the temperature and the value of the enthalpy.
It returns the value of T.
• SpecificEntropyCorr: Provides the calculation of the specific entropy as function of T, in similar way than enthalpy.
• SpecificEntropyCorrInv: Similar to SpecificEnthalpyCorrInv but for entropy.
• SpecificEnthalpyCorr2: Receives a DataRecord record as input instead of correlation parameters. Calls the SpecificEnthalpyCorr to performs
the calculation of the ideal gas specific enthalpy.
• SpecificEntropyCorr2: Similar to SpecificEnthalpyCorr2 for ideal gas specific entropy.
• Cp0Corr: Calculates ideal gas heat capacity from a given DataRecord and a given temperature.
• Several functions for transport properties calculation.
Contains definitions not used yet, mainly due to the lack of graphical support for using choices inside mediums in OpenModelica.
5.2. IdealGasMedia package
As a resume: The medium is for fast calculation of liquid phase, condensation, evaporation, and gas phase, when the liquid heat capacity correlation
is available. In the liquid and saturated phases, the results are quite good. In the gas phase, the results are better than the ideal gas approach
in density and enthalpy. The medium is compatible with OpenModelica 1.17 old and new frontends. The medium is also compatible, since the
modification of the BaseProperties model and addition of derivative functions calculation, with Modelica.Fluid and ThermoPower libraries.
Surface tension is calculated also by correlation, or using the Sastri-Rao method, if the first is not available.
Saturated gas density is calculated using a dedicated correlation. At temperature higher than saturation, for a given pressure, a temperature
correction is introduced.
Enthalpy and entropy are calculated from the saturated values at the given pressure (obtained from liquid Cp and vaporization enthalpy correlations),
by adding the increase from the saturated temperature to the given temperature, calculated according to the ideal gas Cp, but with a pressure and
temperature correction.
Low pressure viscosity and thermal conductivity are calculated by correlations or, when not available, by the Chung method. Pressure correction is
later applied.
Transport properties are not calculated for the two phases situation.
The quality of the results is very high when multiparameter (Seltzmann and Wagner, SW) EOS are available. If not, PCSAFT or different flavours
of cubic EOS can be used.
The transport properties are normally computed from temperature dependent correlations, with pressure correction. Nevertheless, for viscosity, the
system will perform phase independent viscosity calculation (from temperature and density) for selected substances, using dedicated calculation
or extended correspondent states with NIST correction polynomia, when available. In order to use the phase independent viscosity calculation
the thermoModel parameter must be 3 (multiparameter EOS), as it is the only way to be sure that the supplied density is reliable. For thermal
conductivity the same type of calculations are already programmed, but have been inactivated till finishing testing.
The medium implements all the requirements of Modelica.Media.PartialTwoPhaseMedium. It is compatible with the old frontend of OpenModelica,
but not with the new frontend, as it does not support external functions yet. It is also compatible, at least partially, with the ThermoPower library.
Compared with other high quality libraries, it is very easy to use and, although it is not as complete as for example CoolProp, or RefProp, the quality
of the thermodynamic results is practically the same. In plus there is the possibility of using PCSAFT and cubic EOS for substances for which no
multiparameter EOS are available.
The main limitation of the medium, when using SW or PCSAFT EOS, is in the vicinity of the critical point, as no special technique, as for example
splines, is used. Nevertheless you can go normally quite close to the critical point with SW, not so with PCSAFT as there is still some problems
with its density solver. The medium is much slower than the TMedia one, but it is the price for the better precision and wider range of use.
The ThermodynamicState record is quite big, in order to allow all the thermodynamic calculations with just one call to external functions.
The BaseProperties model has been implemented using algorithms instead of equations. I do not know if this is correct, but seems the logical decision
when you know the order in which calculations must be performed.
When extending the medium, the following configuration must be done:
The thermoModel Integer constant must be made equal to 1 for using the cubic EOS, 2 for the PCSAFT, or 3 for the SW.
The referenceState Integer constant must be made equal to 1 for using ASHRAE reference state, to 2 for using IIR, to 3 for using NBP, to 4 for
using user reference_T and reference_p. Any other number will produce an unreferenced calculation for enthalpy and entropy.
If you are going to use the BaseProperties model, you must make the inputChoice constant String equal to ’ph’, ’pT’ or ’dT’, as needed. When
instantiating the model, you can still change the selection just for the object, specifying the value for the localInputChoice constant.
With the Test1aXXX models of the Tests package, you can compare the performance of the cubic, PCSAFT, IAPWS95 and GERG2004 EOS, against
the standard Modelica.Media.Water.StandardWater. Test1bXXX compare R410A, Test1cXXX compare propane, and Test1dXXX compare ethanol.
ExternalMedia is not working with Open Modelica 1.17 due to the change of the C compiler from MinGW to CLang. I hope to solve this in the
future.
5. FreeFluidsModelica
This partial model contains a FluidPortA PortA, and a FluidPortB PortB connectors, and some equations linking the values of both connectors
variables. The more fundamental equation is:
0=PortA.G+PortB.G. This grants that all massic flow entering one port goes out by the other. G is considered positive if the flow enters the port.
Some parameters will configure more possible links between the ports variables:
• parameter Boolean useElevDifference=true will activate the use of an extra equation for ports elevation.
• parameter FreeFluids.Types.ElevationOption elevCalcMethod. If useElevDifference=true, selects the equation to use for the elevation calcu-
lation. If the selection is “differential” the equation PortB.elevation=PortA.Elevation+elevDifference is applied. If the selection is “absolute”
the equation PortB.Elevation= portBelevation is applied. Being elevDifference and portBelevation parameters with default value of 0.
• parameter Boolean calcEnthalpyDifference=true will control if a calculation of the difference of enthalpy between ports is applied or not. But
the calculation to apply remains undefined.
• parameter Boolean passComposition = true will control if the composition of both ports is made equal or not.
Finally two variables, with the equations to solve them are added: Hdiff = PortB.H-PortA.H, and Pdiff=PortB.P-PortA.P.
With this implementation the model is imbalanced in two way: For the two pairs of potential/flow variables, there are three equations(PortA.G=0,
PortB.G=0, PortA.G=-PortB.G), so an equation linking these variables is missing. Normally it will be the calculation of the pressure drop as
function of flow. The second point of imbalance is that there is no equation for the calculation of the output PortB.H. The extending models must
provide the missing equations.
Although not correct according to the Modelica standard, the model is prepared for the connection of more than one PortB to a PortA, with the
idea of making simpler and faster some connections. When doing so we must take into account that, in a connection point elevation, enthalpy, and
composition, must be supplied only by one connector. If not, we will have an over specification for the value. The situation is different for elevation
than for enthalpy and composition. In a connection point all the ports must have the same elevation, so the only thing that we have to do is to
inhibit the duplicate propagation of the elevation, making useHeightDifference=true only in one of the elements that can supply the elevation value
to the connection. For enthalpy and composition, it must be possible to connect elements with different enthalpy or composition output, and this can
be done using mixers, that for simplification are coded as no reverse flow. But, if the enthalpy variation inside the elements is only due to elevation
changes, we can grant that all connectors have the same enthalpy at the connection point, and solve the problem in the same way that we did with
elevation, allowing reverse flow. The same is applicable for composition, if composition is constant.
A second point must be considered: In a connection of more than two connectors, regardless the physical size of the connections could be the same,
there is normally a change in velocity, so in kinetic energy and enthalpy. This means that the equal enthalpy solution is only an approximate solution
valid when the velocity is low (liquids and gases at not high velocity).
5.7. Interfaces package
As a resume, we will develop elements allowing for reverse flow, based in a fixed enthalpy and composition at each connection point, and elements
without reverse flow capability, valid for situations with different enthalpy, or composition, of the connectors.
As origin/end of the flow, except for loops, we need at least a source, and at least a sink. There are defined two source models: a general FlowSource,
valid for one and two phases Mediums, and a FlowSourceSP valid only for single phase Mediums.
The FlowSource model contains a FluidPortB PortB connector, which pressure and enthalpy are generated in different ways, coming from configurable
parameters, that fix temperature, pressure, enthalpy or density, or from Real connectors for temperature and pressure. Remember to give the value
at the Real input connectors in SI units. In order to enhance the possibility of giving enthalpy start values at the different elements of the model,
the local parameter H receives a calculated value when its value is not directly given.
Flow and elevation can be specified, or not, using parameters (or a Real connector for flow). First you choose if the flow or elevation must be defined
for the connector, and later you choose if the external value for flow, coming from the connector, must be accepted. If you choose to define the flow,
and you don’t accept the external value, the local value for the flow will be used. According to the Modelica standard, this situation is incorrect: we
should supply always the value of elevation (as it is an output), and never the value of flow, in order to prevent an unbalanced model (as the value
of P has been already fixed). But in order to gain in flexibility, the possibility of an overspecified model has been used, taking into account that if
we overspecify the FlowSource, a FlowSink must be underspecified.
The implementation of the Real connectors, for receiving temperature, pressure and flow from external sources, has been implemented according to
the Modelica standard way for conditional connectors. The connector receiving the external values is conditional, and is connected to a protected
connector which, in case that the conditional connector is deactivated, receives its value from the corresponding parameter.
The composition is always fixed at the values entered in the parameters window. Its default value is the default value of the Medium.
The FlowSourceSP model is a simplified version, without the options of generating pressure and enthalpy values at saturated conditions for the
PortB.
The FlowSink model contains a FluidPortA PortA connector, provision for receiving fixed flow, or pressure, from external sources, and the following
parameters:
• parameter FreeFluids.Types.BoundaryOption fix= FreeFluids.Types.BoundaryOption.fixFlow. Used to select between fix the flow, the pressure
or nothing at the PortA.
• parameter Modelica.SIunits.AbsolutePressure P= 1e5. Value used for PortA.P if fixDP is selected.
• parameter Modelica.SIunits.MassFlowRate G. Value used for PortA.G if fixFlow is selected.
5. FreeFluidsModelica
The third alternative is fixNone, that will produce an underspecified connector, that must be matched by an overspecified connector elsewhere.
It is very important to understand that the FlowSource and the FlowSink can act both as source or sink for flow. The only difference between them
is that the FlowSource will inject values for enthalpy and elevation, and the FlowSink not. In order to improve convergence, as the start for flow is
defined as negative (flow leaves the element) for the FlowSource and positive for the FlowSink, we should provide oposite start values if we are using
FlowSource as receiving flow, and FlowSink as an origin for flow.
In order to allow for the specification of pressure and elevation at the connection points, there are several extensions of the FreeReference model.
This base model contains a FluidPortB connector and just one equation: PortB.G=0. The extensions allow for the specification of pressure and
elevation by parameters. This is against the Modelica standard, because in this way we are connecting several outputs to the same input.
Which is the situation if we want to stick to the Modelica standard? The answer is: do not fix flow at the sources, give flow or pressure at the sinks,
make all connections of two or more outputs to the same input using mixers, and do not use pressure or elevation references.
It is an extension of the Interfaces.TwoFluidPorts model. It adds the following parameters to configure a two ports valve:
• parameter FreeFluids.Types.ValveFixOption fix = FreeFluids.Types.ValveFixOption.fixKv, in order to select if we are going to specify a fized
Kv, a fixed pressure drop or a fixed flow along the valve.
• And the following parameters: fixedKv, fixedDP and fixedFlow, in order to allow the user specification of the needed value.
It adds also the following variables:
Kv for the valve Kv
Cv for the valve Cv
Medium.ThermodynamicState State, in order to specify the state at which physical properties will be evaluated.
Q for the volumetric flow at State conditions.
T for fluid temperature at State conditions.
Rho for fluid density at State conditions.
5.8. Valves package
Extends from the ValveBase model. It treats always the flow as incompressible and isenthalpic.
The State variable is defined at PortA pressure and enthalpy.
Pressure drop is calculated if PortA.P>PortB.P, otherwise the flow is made 0.
If calcEnthalpyDifference=true, the enthalpy of both ports is made equal.
Allows the calculation of the flow or the area of a safety relief valve or disk. It uses an isentropic calculation between the inlet, supposed with
velocity equal to 0, and the orifice. The gas flow can be chocked or not, and all the calculations are done with the physical properties calculated
by the Medium, except the possibility of manual entering of the isentropic coefficient. Correction coefficients are applied for backpressure and for
viscosity, according to the API 520 methodology. It is capable for biphasic flow calculation, but the model SafetyValveFlash, that conforms to the
API recommenations, is probably more adequate.
Two thermodynamic states are declared at the orifice outlet, both isentropics with the inlet. One of them at the discharge pressure of the valve, the
other adjusted to obtain sonic speed at the orifice. If the discharge pressure is below the obtained critical pressure, the flow is taken from the critical
calculation, if not from the discharge pressure calculation.
5.9. Pumps package
API 520 and ISO 4126-1 calculation methods are implemented, with the API one as default. It is limited to monophasic flow. Although a Medium
is declared, and physical properties can be taken from it (except the isentropic coefficient for gases, that must be always entered by hand), there is
the possibility of manual entering of all the physical properties. If you enter all physical properties manually, you can use data for a different fluid
than that of the Medium. The Medium will be used just for generating P and H at the PortA, with H being passed to the PortB if the calculation
has been activated. As H is not used in the calculation of the flow, if the pressures are OK the calculation should be fine.
5.8.8. SafetyValveFlash
It implements the calculation methodology described at API 520 Annex C section C.2.1, based on isentropic flow. In order to get the flow, an array
of 25 pressures, between inlet and outlet pressures, are tested, and the higher flow is taken. Instead of implementing the integration of dP
ρ
to obtain
d(v 2)
the velocity, the relationship 2
= −dH has been used.
5.8.9. SafetyValveOmega
It a model for safety valves working with flashing liquids, according to API 520 Annex C sections C.2.2 and C.2.3. The parameter Boolean liquidInlet
allows you so select the calculation method to use, if made true it will use the C.2.3 methodology, that works with an inlet 100% in liquid state.
Otherwise the C.2.2 method will be used. The parameters allow you to choose between fixing the discharge area or the flow, configure the basic
characteristics of the valve, and enter the physical properties or let them to be taken from the Medium.
Its function is to define the common elements needed for different type of pumps, providing just few equations between them.
Parameters:
• forceSpeed=false. If made true, the pump speed will be made equal to the manual defined parameter, or to the speed received via a connector,
depending on the selection made.
5. FreeFluidsModelica
• useExternalSpeed=false. If made true, the speed received at the connector is used. Otherwise the manually filled parameter will be used. (the
forceSpeed parameter must be true for calculation to apply).
• fixedSpeed. The manually fixed speed request.
• numParallelUnits=1. The number of identical pumps working in parallel.
• directFlow=true. If true, the flow will be from port A to port B. And the reverse if false.
Variables:
• N. for the pump speed. In order to assign it, a conditional RealInput connector ’Speed’ connected to a protected RealInput connector ’SpeedIn’
are used. I ’useExternalSpeed’ is false the ’Speed’ connector and its connection disappears, and N is made equal to ’fixedSpeed’.
• Qunit and Qtotal. For the volumetric flow of each individual pump, and of all parallel pumps. They are related by Qtotal = Qunit *
numParallelUnits. And Qtotal is related to the mass flow by PortA.G = Qtotal * Rho.
• A ThermodynamicState ’State’ is defined in order to gate the physical properties of the fluid. The state is defined at the enthalpy and pressure
of PortA, as we do not expect too much change for the physical properties between the ports.
• The variables Rho and T, get the density and the temperature of the State.
• The variables specific energy: ’SE’, pump efficiency: ’Efficiency’, total absorbed power: ’Wabs’. Two equations are provided here, one comes
from the definition of efficiency, and the other relates ’Wabs’ with flow, differential pressure and efficiency.
• A pump impulsion height variable ’Dh’ that express the differential pressure between ports a liquid height. An equation relating Dh with the
differential pressure and density is given.
An equation is missing for finding Efficiency, and it is missing also an equation relating N, Qunit and Dh.
It extends the PumpBase model and introduces parameters for the pump curve definition. They are flow, head, and efficiency, at two points of the
curve, plus the head at zero flow.
It defines three variables for: flow, head and efficiency with a nonviscous fluid.
It defines two equations relating the three variables with the pump speed. So, if the pump speed is fixing, the definition of one of the three variables
will allow the calculation of the other two.
5.10. Pipes package
• parameter SI.Distance lTube = 0. In order to allow direct user input of individual tube length.
• parameter Integer numTubes = 1. To specify the number of existing identical parallel tubes. It is useful mainly for exchangers.
• parameter SI.Distance di = 0. In order to allow user specification of the diameter for circular pipes.
• parameter SI.Area section = 0, and parameter SI.Distance perimeter = 0. In order to specify perimeter and section for non-circular pipes.
• parameter SI.Distance roughness = 1.5e-005. Pipe internal roughness.
• parameter SI.Distance thickness = 1e-3. Pipe wall thickness.
• parameter SI.Density rhoWall(displayUnit = "kg/m3") = 8000. Wall density, for weight calculation.
• parameter SI.Distance thicknessInsul = 0. Insulation thickness, if applicable.
And the following parameters for configuration of the applicable equations:
• parameter Boolean useTubeLength: is used to make equal, or not, the individual tube length to the parameter lTube. If false, the pipe length
remains as unsolved variable. This should allow us to retrieve the individual tube length from the total length and the number of tubes, if we
have fixed the total length as for example in coils.
• parameter Boolean fixNumTubes = true. To specify if the number of tubes must be fixed at numTubes.
• parameter Boolean isCircular = true: If true, establish the relation between the perimeter and the diameter of the pipe as PathPerimeter=pi
* Di. If parameter Boolean useDiameter = true is also true, the equation Di=di is activated. If the diameter Di is not fixed, we will need
an extra equation to solve for it. As the equation: Di = 4 * PathSection / PathPerimeter is always active, we can solve Di, PathSection or
PathPerimeter. With this definition is clear that Di is the hydraulic diameter except for a double pipe.
• parameter Boolean useDiameter = true. If true and isCircular is also true, the supplied(parameter) diameter will be used, activating the
equation Di=di;
• parameter Boolean useSectionAndPerimeter = false. If isCircular=false, making useSectionAndPerimeter=true will activate the equations that
make PathPerimeter and PathSection equal to the given parameters. If none of the options for circular or section and perimeter is activated,
we will need two extra equations to solve for diameter, section and perimeter.
A lot of extra variables are calculated for the pipe, related with length, diameters, surfaces, volumes and weight.
• parameter Integer numActiveTubes=1. Although the physical pipe already has the parameter numTubes, it is possible use only some of them
as active for flow.
• parameter Real pipeComplexity = 0. Allows a fast calculation of the equivalent tube length without detailing the existing accessories. Approx.
estimation of equivalent length: 0=not used, 0.25=supply lines, 0.5=long runs, 1=normal, 2=valves, 4=complex valves. If it is 0, the equivalent
length will be calculated using the equivalent length of accessories.
• parameter Real equivL_Di = 0. Used to give the equivalent length of existing accessories.
• parameter Real numVelocityHeads=0. In order to add pressure losses expressed as number of velocity heads.
• parameter SI.Area kv = 0. Gives the possibility to add Kv of valves and other accessories to the pressure drop calculation. This will be used
in plus to the equivalent length used.
• parameter Fraction aperture = 1. Fraction of the Kv that will be applied.
And the following parameters for configuration of the applicable equations:
• parameter Boolean fullBore = true. If true activates the equations: PathSectionActive = PathSection, and PathPerimeterActive = PathPeri-
meter. If the pipe is double, it will be necessary to add the internal perimeter, and to subtract the internal section. If it is a falling film pipe, the
flow section will be reduced. The final hydraulic diameter that will be used is calculated as: Dh = 4 * PathSectionActive / PathPerimeterActive.
• parameter Boolean isCompressibleFlow = false. If true, the velocity change between ports will be used for the momentum and energy
conservation equations.
Several variables are calculated: Surface and volume for the active tubes, PathSectionActive, PathPerimeterActive, Dh, Slope.
Is an extension of the Pipe model. It is in fact the base model for all thermal and non thermal pipes, one or two phases.
It adds one important configuration parameter:
• parameter FreeFluids.Types.ThermalType thermalType. If its value is isenthalpic will activate PortA.H=PortB.H. If adiabatic : W = 0. If
isothermal: Ta=Tb. If fixedPower: W= fixedW. If fixedDeltaT: Tb=Ta+fixedDeltaT. Otherwise an equation must be defined for the heat
transfer calculation.
• parameter Modelica.SIunits.HeatFlowRate fixedW = 0. The exchanged heat if thermalType=fixedPower.
• parameter Modelica.SIunits.HeatFlowRate fixedDeltaT = 0. The differential T to apply if fixedDeltaT has been selected.
5.10. Pipes package
It defines Medium.ThermodynamicState records for PortA(StateA) and PortB(StateB) obtained from the values of P,H and X at the ports. From
them, the density, velocity, volumetric flow, and temperature are calculated.
It contains the momentum and energy conservation equations, with two missing variables: the pressure drop and the exchanged heat. The last only
in the case of a detailed heat transfer model.
• parameter Boolean fullHTperimeter = true. If false, it will be necessary to define the perimeter zone used for heat transfer, for example in half
pipes.
• parameter Boolean fullHTlength = true. If false, the tube length used in heat transfer must be specified. It is the case in partially immersed
pipes.
• parameter Boolean useThermalConnector = true. Allows or not the transmission of the heat flow from the thermal connector to the internal
variable used as heat exchange.
The following variables are also defined:
• Twall and Tsurf: Temperatures at internal and external surfaces.
• LMTD: The mean logarithmic temperature difference between ports and Tsurf.
• H: The heat transfer coefficient, to be calculated by the detailed model used.
• SactiveHT. Is the total surface available for heat transfer. If fullHTperimeter is true, the equation SactiveHT = SiActive is activated. Otherwise
it is necessary to calculate it.
• SusedHT. Is the total surface used for heat transfer. If fullHTlength = true, the equation SusedHT = SactiveHT is activated.
A HeatPortB connector is defined. It is used for the transmission of the pipe information to the surrounding, in plus to the pipe surface temperature
and heat flow. The heat flow defined in the connector is used internally in the pipe only if the parameter useThermalConnector=true. If it is false
the heat flow at the connector will have no effect. The use of the connector will be probably limited, as the connection must be done fixing the pipe
external temperature. In the case of heat exchangers, the calculation of W will be done using LMTD or e-NTU methods, with no need of connectors.
The following variables remain unsolved:
Pressure drop regarding flow.
H, Tsurf or Twall, and W, if thermalType=detailed, otherwise only H and Tsurf or Twall. The equation for H must be provided by the extending
models.
5.10.10. PipeForcedConvection
It is the pipe for forced convection heat transfer in single phase flow. Extends PipeThermalBase model. It must calculate the pressure drop by
friction and define a relationship between the surface temperature and the exchanged heat. In order to perform the pressure loss calculation, the
Reynolds number and the friction factor are defined and calculate. The calculation of H (heat exchange coefficient) is also performed. Finally a
relationship between the heat exchanged and the surface temperature is established using the LMTD. If the parameter useThermalConnector=true,
the model is balanced, as the equation for the connection of W (heat exchanged) will be activated. If not, an equation determining the heat exchanged
5.10. Pipes package
must be present in the receiving model. This will be the system used for more elaborated models of heat transfer than just consider a fixed surface
temperature.
5.10.11. PipeThermalFallingFilm
The flow is incompressible. The pressure loss is exactly the geodesical height loss, so there is no relationship between pressure loss and flow, and the
outlet and inlet pressure are identical. The flow will depend mainly on the film thickness and slope of the pipe. This minds that the flow must come
always from one of the two connectors of the pipe. Other characteristics and limitations are the same than for the forced convection model.
5.10.13. PipeThermalCondensing
Extends from PipeCondensingBase and contains just the equation needed as for the selected option, plus the calculation of the total mass of fluid
inside the pipe, and the assumption that all exchanged heat has been by condensation. By now there is not the possibility of combine condensation
plus subcooling in the same pipe.