ALC MODELLING Programming Methods
ALC MODELLING Programming Methods
Programming Methods
1.
ALICES DOCUMENTATION
Programming Methods
2.
BASIC TYPES
The classical C++ types (int, float) should not be used in thermo-hydraulic
objects source code. Actually, ALICES provides a full list of classes that have the
same functionalities but that also brings much more services (for example,
checking that a variable has a value before using it). Beside the redefinition of
basic types, a few original types are also available.
2.1
INTEGER
Usual int variables should be declared as DifInteger.
The classical arithmetic operators (+, -, *, /, %, +=, -=, *=, /=, %=, ++, --, min,
max) are overloaded and can thus be used just like with normal int. This is also
true for comparison operators (<, <=, >, >=, == and !=).
No other particular method is available in this class, but some checks are
performed internally (a DifInteger variable must be initialized before being used
before being used on the left side of the affectation operator).
It is possible to check manually if a DifInteger is initialized with the following
method:
DifInteger vi_N ;
if ( vi_N.IsInitialized() )
2.2
REAL
Usual float variables should be declared as DifReal.
The classical operators (+, -, *, /, +=, -=, *=, /=, ++, --, min, max) are also
overloaded for this new type, as well as usual comparison operators.
Moreover, usual mathematical functions are also overloaded (sin, cos, tan, asin,
acos, atan, sinh, cosh, tanh, asinh, acosh, atanh, abs, sqr, sqrt, exp, log, power).
The classical rules of type cast when mixing DifInteger and DifReal can be applied
just like with int and float (e.g. DifInteger + DifReal -> DiReal). Actually, most
of the operations with DifInteger first perform implicitly a type cast to get DifReal.
This can be done explicitly with the following method:
DifInteger vi_N ;
ALC-MODELLING-Programming Methods, Page 2
This document is the property of CORYS T.E.S.S., any communication, reproduction, publication, even partial, is forbidden without the written consent of CORYS
T.E.S.S.
ALICES DOCUMENTATION
Programming Methods
DifReal vdif_X ;
vdif_X = DifReal(vi_N) ;
No other particular method is available in this class, but as for DifInteger some
checks are performed internally (a DifReal variable must be initialized before being
used on the left side of the affectation operator).
It is possible to check manually if a DifReal is initialized with the following method:
DifReal vdif_X ;
If ( vdif_X.IsInitialized() )
2.3
VECTOR OF REAL
Usual float[ ] should be declared as DifVectorOfReal.
There is a copy constructor associated with this class. Thus if a vector OldV has
already been defined and dimensioned, a new identical vector may be created with
the syntax:
DifVectorOfReal NewV ( OldV ) ;
The DifVectorOfReal class supports the classical + and operators if the 2 operand
vectors have the same size. The operator is then applied to each element of the
vector and the result is a new vector of the same size as the two operands.
It is also possible to multiply a DifVectorOfReal by a DifReal with the classical *
sign (each element of the vector is multiplied by the scalar). As mentioned above, it
is also possible to multiply a DifVectorOfReal by a DifInteger: the DifInteger is then
implicitly cast into a DifReal before performing the multiplication. The
multiplication can be done with the scalar (DifInteger or DifReal) either on the left
or on the right of the multiplication sign. The result is a new vector of the same size
as the operand vector.
Similarly, a DifVectorOfReal can be divided by a DifReal (or a DifInteger).
The = operator enables either to assign a DifVectorOfReal to another (if they have
the same size) or to assign a DifReal (or a DifInteger) to all the elements of a
DifVectorOfReal (if the vector has been dimensioned before):
DifVectorOfReal V, V1, V2 ;
DifReal r ;
V1 = V ;
// the vector V1 and V must have been dimensioned before and
must have the same size
ALC-MODELLING-Programming Methods, Page 3
This document is the property of CORYS T.E.S.S., any communication, reproduction, publication, even partial, is forbidden without the written consent of CORYS
T.E.S.S.
ALICES DOCUMENTATION
Programming Methods
V2 = r ;
All the previous operators can be extended to the equivalent assignment operator
when this is meaningful (+=, *= ).
The elements of a DifVectorOfReal can be accessed individually with the indexing
operator [ ]:
DifVectorOfReal V ;
V[ 2 ] = 1.41 ;
Finally, it is possible to compare 2 vectors with the == and != operators (vectors
are identical if they have the same size and if all their element are identical).
A method that may also be useful is the reduction method that will return the
sum of all the element of the vector:
DifReal vdif_sum = V.Sum() ;
Another very interesting method is the Items() method that returns the number
of element of the vector:
DifInteger vi_NV = V.Items() ;
The IsInitialized() method is also provided, like for DifInteger and DifReal.
The last (but not the least) method that must be mentioned is the method that
enables to dimension a vector. Actually, when a new DifVectorOfReal is declared, its
size is unknown (except when it has been created with a copy constructor). It must
absolutely be dimensioned before it is used (or an error will occur).
The method that enables to dimension a DifVectorOfReal is named Capacity and
it can be called with two different syntaxes:
DifVectorOfReal V1, V2 ;
V1.Capacity(12) ;
V2.Capacity(pInfo->CaxAllocator(),12) ;
In the example above, both vectors will be dimensioned with 12 elements. The
difference is the presence of an additional argument in the second call (the reason
of this difference is out of the scope of this document). Basically, you should always
use the second one (with the CaxAllocator) to avoid problems.
2.4
COMPLEX
ALICES DOCUMENTATION
Programming Methods
It is also possible to use complex numbers with the class DifComplex. However, this
classes is mostly dedicated to Electrical modeling and will not be described here
(its behavior is very similar to the one of the DifReal class).
2.5
VECTOR OF COMPLEX
As for real, a DifVectorOfComplex class exists. It will not be discussed here.
2.6
This document is the property of CORYS T.E.S.S., any communication, reproduction, publication, even partial, is forbidden without the written consent of CORYS
T.E.S.S.
ALICES DOCUMENTATION
Programming Methods
All the usual arithmetical operators (but also mathematical functions as sin, exp)
have been overloaded so that they bring this functionality when they are used in a
CaxReal context.
The reason of all this work is that the Jacobian matrix of the system (that is
necessary for the Newton algorithm) is computed automatically by the solver.
For the modeliser, the use of CaxReal is nearly identical to the use of DifReal (that
is the power of the method): only the variable declaration is different, but the
syntax of operations is the same.
A few words may be added about special methods provided by the CaxReal class:
The HasDerivatives() method returns true if the CaxReal variable has some
derivatives defined.
The Value() method returns a DifReal which is the value of the CaxReal
(the first element of the conceptual array).
Finally, lets say that some variables are CaxReal by default: the principal variables
and the visible variables (although these last ones never have derivatives).
2.7
2.8
ALICES DOCUMENTATION
Programming Methods
2.9
2.10
STRINGS
The class SruString brings a very powerful environment for strings manipulation
(instead of the usual C++ char* context which is very limited). These objects are
though quite large and should be used with care to avoid a lost of performance.
This class provides many operations as comparison, concatenation, conversion,
length computation, formatting, find and replace, hashing
Only the main methods are reminded below:
SruString sru_str0 ;
// only declaration
SruString sru_str1(text) ;
// 1st constructor
SruString sru_str2(sru_str1) ;
// 2nd constructor
SruString sru_str3(80) ;
capacity)
// affectation
sru_str.Length() ;
The last method (Token) is very powerful to cut a string with a given separator into
substrings.
The
variable
ysru_str_array
must
be
of
the
type
SruValOrderedVector<SruString> (see below).
Example:
SruString sru_str = A & B & C ;
SruValOrderedVector<SruString> ysru_str_array ;
sru_str.Token( ysru_str_array , '&' ) ;
ALC-MODELLING-Programming Methods, Page 7
This document is the property of CORYS T.E.S.S., any communication, reproduction, publication, even partial, is forbidden without the written consent of CORYS
T.E.S.S.
ALICES DOCUMENTATION
Programming Methods
MULTICHAR
The concept of multichar is to take benefit of the 4 bytes encoding of integers to
get 4 characters pseudo-strings with a very efficient method. The class that brings
that functionality is DaxSignature.
For example, it is possible to write:
DaxSignature dax_a(test) ;
// test has 4 letters: OK. However testing (7
letters) will throw an exception.
cout << dax_a ;
This last line will just print test on the output device (screen, file).
This class also provides the comparison operators == and !=.
It is also possible to transform a DaxSignature in a SruString:
SruString sru_foo = dax_a.String() ;
2.12
GENERIC VECTOR
Another type of vector is available in ALICES. They are provided by the template
SruValOrderedVector<T>.
Here T is any of the previously defined types (DifReal, SruString).
In thermo-hydraulic objects, the SruValOrderedVector is mostly used with
SruString.
On the other hand, you should better use DifVectorOfReal rather
SruValOrderedVector<DifReal> (although there is no clear rule about that).
than
ALICES DOCUMENTATION
Programming Methods
3.
type
of
the
(it
is
equivalent
to
ALICES DOCUMENTATION
Programming Methods
4.
Example:
DifReal vdif_Bound_Min_T =
SRU_STRING_CAST(
aEnvironment.Value("Bound_Min_T",c_Bound_Min_T) ) ;
DifReal,
ALICES DOCUMENTATION
Programming Methods
5.
ImsMessageStack xMessageStack ;
throw xMessageStack ;
Once the message is thrown, it will be catch by ALICES and printed on the output
device.
A few explanations must be added here.
First, the arguments of the InsertErrorMessage are the following:
majr and minr are the major and minor signature of the message. These
arguments are just identifiers. They are used internally to recognize each
error message. They are DaxSignature (multichar) and thus they must be 4
letter words (maximum). You can for example use the object type as the
ALC-MODELLING-Programming Methods, Page 11
This document is the property of CORYS T.E.S.S., any communication, reproduction, publication, even partial, is forbidden without the written consent of CORYS
T.E.S.S.
ALICES DOCUMENTATION
Programming Methods
major signature (Node, Arc, Sens) and its particular type as the
minor signature (Valv, Qe).
- cImsFatal
- cImsError
: error
- cImsWarning
- cImsInfo
- cImsSameSeverity
ptAFL
].IsConnected()
&&
{
ALC-MODELLING-Programming Methods, Page 12
This document is the property of CORYS T.E.S.S., any communication, reproduction, publication, even partial, is forbidden without the written consent of CORYS
T.E.S.S.
ALICES DOCUMENTATION
Programming Methods
xMessageStack.InsertErrorMessage(
DAX_DEBUG_INFO( PreCondition ) ) ;
"Arc"
"Emty"
cImsFatal
xMessageStack ;
}
These lines throw a fatal error message (simulation stops) if an Arc is not
connected at both sides.
ALICES DOCUMENTATION
Programming Methods
6.
CaxAllocator() : this method has already been mentioned above (see section
2). It returns a pointer on a memory space (a stack) where temporary objects
can be stored. You should use this method only in the context of
DifVectorOfReal dimensioning.
DifModuleInfo::cSelectEquations
DifModuleInfo::cInitFunctionDynamic
DifModuleInfo::cComputePrediction
DifModuleInfo::cTimeStep
DifModuleInfo::cSteadyState
DifModuleInfo::cDiscontinuity
DifModuleInfo::cLifeStart
DifModuleInfo::cLifeEnd
ALC-MODELLING-Programming Methods, Page 14
This document is the property of CORYS T.E.S.S., any communication, reproduction, publication, even partial, is forbidden without the written consent of CORYS
T.E.S.S.
ALICES DOCUMENTATION
Programming Methods
DifModuleInfo::cCycleStart
DifModuleInfo::cCycleEnd
This list is not exhaustive but the other values have no reason to be mentioned here
(indeed, only the cInitFunctionDynamic is used yet).
Finally, remind that pInfo is a pointer on a class and thus the member of the
pointed objects are accessed with the -> operator and not with the . operator:
pInfo->Phase() ;
// GOOD !!!
pInfo.Phase() ;
// BAD !!!!
Another interesting property of the DifModuleInfo class is that it inherits from the
DifNewtonInfo class: it is also possible to access to the solver properties with the
pInfo variable.
The following procedure is an example of such a method (defined in the
DifNewtonInfo class):
pInfo->Iteration()
This method returns the number of iteration performed by the Newton solver until
it is called.
WARNING:
This method can not be called in the InitFunctionDynamic phase. It is thus always
preceded by a test such as:
if ( pInfo->Phase() != DifModuleInfo::cInitFunctionDynamic )
{
cout << pInfo->Iteration() << endl ;
}
Finally, another property of the DifNewtonInfo class must be pointed out. As said
before, this class contains the properties of the Newton solver. Particularly, this
class has a member data named yNewtonControl which enables to manipulate each
equation of the object.
More precisely, if an object has a principal variable mP_Y, the syntax pInfo>yNewtonControl[mP_Y] refers to an object of the generic class DifNewtonControl.
ALC-MODELLING-Programming Methods, Page 15
This document is the property of CORYS T.E.S.S., any communication, reproduction, publication, even partial, is forbidden without the written consent of CORYS
T.E.S.S.
ALICES DOCUMENTATION
Programming Methods
This class has many important methods than enable to get information about the
associated equation, principal variable and equation variable. Moreover, it is also
possible with some other methods to modify the behavior of the solver with respect
to the concerned equation/variables (convergence criterion).
What follows is a list of the most important member data and methods of this class:
Prediction( vdif_X ) which sets the value vdif_X in the principal variable
before the solver is called (this method can only be used in CycleStart).
Posdiction ( vdif_X ) which also sets the value vdif_X in the principal variable
after the solver is called (this method can only be used in CycleEnd).
mKindOfEquation: this member data is an integer that can only be (in our
case) one of the following pre-defined constants cRealAlgebraic or
cRealEuler1Implicit.
Examples:
pInfo->yNewtonControl[mP_Qm].mStateAtLastCycle.Real() ;
pInfo->yNewtonControl[mP_T].Prediction(vdif_T) ;
// in CycleStart
pInfo->yNewtonControl[mP_P].Postdiction(vcax_P.Value()) ;
// in CycleEnd
if ( pInfo-> yNewtonControl[mP_T].IsConverged() ) { }
The two last member data of the DifNewtonControl class are mControlState and
mControlResidual which are objects of classes DifNewtonControlState and
DifNewtonControlResidual. Their role is to set some parameters associated to the
State (principal variable) and the Residual, like convergence criterions, validity
domain
The following lines illustrate the main methods of these objects:
ALC-MODELLING-Programming Methods, Page 16
This document is the property of CORYS T.E.S.S., any communication, reproduction, publication, even partial, is forbidden without the written consent of CORYS
T.E.S.S.
ALICES DOCUMENTATION
Programming Methods
pInfo->yNewtonControl[mP_P].mControlState.BoundMinimal(vdif_Bound_Min_P) ;
pInfo->yNewtonControl[mP_P].mControlState.BoundMaximal(vdif_Bound_Max_P) ;
pInfo>yNewtonControl[mP_T].mControlResidual.ToleranceAbsolute(vdif_Tol_abs_H) ;
ALICES DOCUMENTATION
Programming Methods
7.
ADAPTED FUNCTIONS
As said before, a problem arises when dealing with functions having a zero, an
infinite or a non-continue derivative in CaxReal context. This is the case for very
common functions such as square root, square or absolute value. To avoid these
problems, some special objects are provided by ALICES.
7.1
7.1.1
7.1.2
}
ALC-MODELLING-Programming Methods, Page 18
This document is the property of CORYS T.E.S.S., any communication, reproduction, publication, even partial, is forbidden without the written consent of CORYS
T.E.S.S.
ALICES DOCUMENTATION
Programming Methods
The only difference between this function and the classical symmetric square
function is its derivative in the interval [-gap;+gap] (it is 2 * gap, instead of 2 * X).
With this method, the function in itself is identical to the non-adapted symmetric
square function. Only the derivative is different in a user defined interval (with the
gap parameter). Moreover, with this method, the derivative is continuous and is
never zero.
7.2
7.2.1
7.2.2
sym_sqrt( X ) = - sqrt( - X )
when X<0
sym_sqrt( X ) = + sqrt( + X )
when X>=0
return
CaxReal(
sqrt(
}
The derivative of this adapted function is continuous and has never an infinite
value.
7.3
ALICES DOCUMENTATION
Programming Methods
return - vcax_X ;
return
CaxReal(-
return
CaxReal(
vcax_X.Value(),
+
vcax_X.Value(),
return + vcax_X ;
}
The problem of the absolute value function is that its derivative is discontinuous at
X=0.
The adapted function solves this problem with a similar method (definition of a gap
and modification of the derivatives in this interval). In the interval [-gap;+gap], the
derivative of the adapted function is build to be a linear function. Moreover, the
derivative must be continuous at X=-gap and X=+gap.
In this interval, the derivative of the adapted absolute function is thus CaxAbs( X )
= X/gap.
7.4
7.4.1
Interface Includes
The following header file must be included in the section Interface Includes to be
able to use the adapted functions.
#include "Cax/CaxFunctions.h"
7.4.2
Concealed Data
The adapted function object must be declared in the Concealed Data section to
be member data of the thermo-hydraulic object:
CaxSymSqrt vSymSqrt ; // function square root with continuous derivatives
7.4.3
LifeStart0(DaxEnvironment& aEnvironment)
ALC-MODELLING-Programming Methods, Page 20
This document is the property of CORYS T.E.S.S., any communication, reproduction, publication, even partial, is forbidden without the written consent of CORYS
T.E.S.S.
ALICES DOCUMENTATION
Programming Methods
Computation
The adapted function can then be used in any other method as shown below:
vcax_Qm = vdif_Cv_hy * vSymSqrt ( vdif_R * vcax_DP) ;
// vcax_Qm will have
finite and smooth derivatives even
when vcax_DP is close to zero.
ALICES DOCUMENTATION
Programming Methods
8.
INTERPOLATION FUNCTIONS
Another very powerful tool provided by the Cax utilities is the interpolation
functions.
Yet, this functionality is used only in the Arc_fan object, but it may be used in
some other objects.
Two types of interpolations are possible: 1D interpolation and 2D interpolation.
The following sections describe how to use them.
8.1
CONCEALED DATA
CaxInterpolation1L vcax_1D_interp_X; // 1D interpolation
CaxInterpolation2L vcax_2D_interp_XY;
8.2
// 2D interpolation
INTERFACE INCLUDES
#include "Cax/CaxInterpolation.h"
8.3
READING DATA
ifstream vStream ;
// stream declaration
vStream.open( "File_1D.txt" ) ;
vStream.ignore(1000, '\n' ) ;
Return character
vcax_1D_interp_X.Read ( vStream ) ;
interpolation function.
vStream.close() ;
vStream.open( "File_2D.txt" ) ;
vStream.ignore(1000, '\n' ) ;
Return character
This document is the property of CORYS T.E.S.S., any communication, reproduction, publication, even partial, is forbidden without the written consent of CORYS
T.E.S.S.
ALICES DOCUMENTATION
Programming Methods
8.4
8.4.1
1D Data
The structure of the file consists in 5 lines:
Example:
$ vcax_1D_interp_X
8
{ -90 , -85 , -75 , -60 , -45 , -30 , -15 , 0 }
8
{ 1250 , 3600 , 3900 , 4200 , 4275 , 4350 , 4425 , 4500 }
8.4.2
2D Data
The structure of the file consists in 7 lines:
This document is the property of CORYS T.E.S.S., any communication, reproduction, publication, even partial, is forbidden without the written consent of CORYS
T.E.S.S.
ALICES DOCUMENTATION
Programming Methods
The two number Nvx Nvy of value at the interpolation points (must be equal
to Nx and Ny).
Example:
$ vcax_2D_interp_XY
8
{ -90 , -85 , -75 , -60 , -45 , -30 , -15 , 0 }
10
{ 0 , 500 , 1000 , 1500 , 2000 , 2500 , 3000 , 3500 , 4000 , 4500 }
810
{ { 0.00 , 0.01 , 0.10 , 0.00 , 0.00 , 0.00 , 0.00 , 0.00 , 0.00 , 0.00 } ,
{ 0.00 , 0.08 , 0.18 , 0.23 , 0.26 , 0.26 , 0.20 , 0.10 , 0.00 , 0.00 } ,
{ 0.00 , 0.11 , 0.26 , 0.37 , 0.46 , 0.51 , 0.51 , 0.45 , 0.00 , 0.00 } ,
{ 0.00 , 0.12 , 0.28 , 0.43 , 0.53 , 0.62 , 0.67 , 0.67 , 0.52 , 0.00 } ,
{ 0.00 , 0.12 , 0.28 , 0.47 , 0.61 , 0.69 , 0.76 , 0.77 , 0.70 , 0.00 } ,
{ 0.00 , 0.12 , 0.28 , 0.50 , 0.64 , 0.73 , 0.79 , 0.80 , 0.76 , 0.00 } ,
{ 0.00 , 0.12 , 0.28 , 0.51 , 0.65 , 0.75 , 0.80 , 0.826 , 0.79 , 0.00 } ,
{ 0.00 , 0.06 , 0.10 , 0.17 , 0.25 , 0.38 , 0.54 , 0.67 , 0.77 , 0.81 } }
8.5
INTERPOLATION
When the previous steps have been performed, it is possible to compute an
interpolated value at any point in the definition domain as shown below:
vdif_Value_1D = vcax_1D_interp_X ( vdif_X ) ;
// 1D interpolation
ALICES DOCUMENTATION
Programming Methods
// 2D interpolation
The definition domain is given by the first and the last point in each interpolation
direction (they must be ordered from the smaller to the larger value).
In the example above, the definition domain of the vcax_1D_interp_X interpolator is
[-90;0] in x direction, and the definition domain of the vcax_2D_interp_XY
interpolator is [-90;0] in x direction and [0;4500] in y direction.
If the arguments given for interpolation are out of the definition domain, an error
occurs. To avoid thir error, it is possible to perform a test such as:
vcax_1D_interp_X.BoundX( vdif_X ). This test returns one of the following integer
constants cNotBounded, cBoundedLower or cBoundedUpper.
The interpolation function is linear in 1D and bilinear in 2D.
ALICES DOCUMENTATION
Programming Methods
9.
ACTIVATING/DESACTIVATING AN EQUATION
It is possible to choose dynamically if an equation should be solved for or not. The
function that enables to do that is bool SelectEquation(const int32 aDescriptor)
const which is a method defined in the differential objects base class DifBaseClass.
At each time step, this method is applied to each of the equation of the object: if it
has not been modified by the user, the default return value is true, which means
that the equation is activated.
However, it is possible for the user to modify this function and to tell the solver if a
given equation should be solved for (return true) or not (return false).
The following lines show an example of such a possibility:
if the parameter mEq is 1, the pressure equation is solved for but not the
temperature equation
if the parameter mEq is 2, the temperature equation is solved for but not the
pressure equation
switch ( aDescriptor )
principal variable
{
case cDescr_P_P :
equation
{
if (mEq == 2)
{ return false ;}
else
{ return true ;}
}
ALC-MODELLING-Programming Methods, Page 26
This document is the property of CORYS T.E.S.S., any communication, reproduction, publication, even partial, is forbidden without the written consent of CORYS
T.E.S.S.
ALICES DOCUMENTATION
Programming Methods
break;
case cDescr_P_T :
temperature equation
{
if (mEq == 1 )
{ return false ;}
else
{ return true ;}
}
break;
default :
possibilities
{ return true ;}
break;
}
ALICES DOCUMENTATION
Programming Methods
AVAILABLE LIBRARIES
The following libraries are available:
10.2
Eau01
Eau2K
Eauliq97Sol
Melange_gaz97
WATER LIBRARY
The library that is commonly used for computing water properties is the library
Eau97Sol.
This library gives the main thermodynamic properties of water in a large range of
pressure and temperature.
Here again, all the data and procedures have been encapsulated in a C++ class
named FluidMonoElt.
ALC-MODELLING-Programming Methods, Page 28
This document is the property of CORYS T.E.S.S., any communication, reproduction, publication, even partial, is forbidden without the written consent of CORYS
T.E.S.S.
ALICES DOCUMENTATION
Programming Methods
The interface between ALICES and the tables is done by creating an object of this
class and by calling some appropriate methods. There are two main kinds of
method: those which define the current thermodynamic state and those which
compute a property at this given state.
The following subsections explain how to create and to use such an object.
10.2.1 Concealed Data
The FluidMonoElt objects must be declared here. It is a good idea to declare one
object for each different use (see further).
FluidMonoElt vSatState ;
FluidMonoElt vLiqVapState ;
10.2.2 Interface Includes
The following header file must be included in the Interface Includes section:
#include "Fluid/FluidMonoElt.h"
10.2.3 LifeStart0
In this section (that is performed only once at the beginning of the simulation), all
the FluidMonoElt objects must be initialized. For that, the fluid library name must
be read from the configuration file:
SruString sru_LiqLib = aEnvironment.Value("LiqLib");
SruString sru_Environment = "FluidLib=" ;
sru_Environment << sru_LiqLib ;
vSatState.Setup( sru_Environment ) ;
vLiqVapState.Setup( sru_Environment ) ;
In this example, the name of the library is stored in the keyword LiqLib (there is
another keyword GasLib for the gas library). The first line is used to read the
content of this keyword.
The two following lines are necessary to build the string FluidLib = Eau97Sol.
This string is then passed to the objects as the argument of the Setup() method.
This must be done for all the FluidMonoElt objects that were declared in the
Concealed Data section.
ALC-MODELLING-Programming Methods, Page 29
This document is the property of CORYS T.E.S.S., any communication, reproduction, publication, even partial, is forbidden without the written consent of CORYS
T.E.S.S.
ALICES DOCUMENTATION
Programming Methods
vState.P ( vcax_P ) ;
vState.T ( vcax_T ) ;
It is very important to notice that in the example above, all the argument are
CaxReal. The consequence is that when a property will be computed, it will be a
CaxReal and it will have derivatives with respect to the CaxReal variables.
It is however possible to use DifReal instead of CaxReal: in this case, the return
value will also be a DifReal (no derivatives).
Finally, it is also to mix CaxReal and DifReal (e.g. vState.PT(vcax_P,vdif_T) ). In this
case, the value returned (when a property will be computed) will be a CaxReal but
the derivatives will only be computed with respect to the CaxReal variable. In our
case, there will be derivatives with respect to P but not with respect to T.
The two first methods just set either pressure P or temperature T. The
thermodynamic state is not totally defined (2 state variables are necessary to
describe full the state of a pure body).
These two methods are mainly used for computing saturation properties (e.g.
compute Psat from T or Tsat from P).
The three following methods set exactly the thermodynamic state. The pressure is
always needed as the first parameter. The difference between these methods is in
the second parameter which can either be the temperature T, the enthalpy H or the
entropy S. The choice of any from these three methods is determined mostly by the
data that are available.
Most of the time, the principal variables of the Nodes are pressure P and
temperature T. Thus the PT() method is often used in a first time. It is mostly used
to compute the enthalpy H. Then the PH() method is used to compute all the other
ALC-MODELLING-Programming Methods, Page 30
This document is the property of CORYS T.E.S.S., any communication, reproduction, publication, even partial, is forbidden without the written consent of CORYS
T.E.S.S.
ALICES DOCUMENTATION
Programming Methods
Example 1:
vSatState.P(vcax_P) ;
vcax_Tsat = vSatState.Tsat() ;
vcax_Tsat
//
enthalpy
of
steam
phase
in
these
Example 2:
vLiqVapState1.PT( vcax_P, vcax_T ) ;
and T
vcax_H = vLiqVapState1.H() ;
vcax_R = vLiqVapState2.Rho() ;
vcax_S = vLiqVapState2.S() ;
The examples above show the most important function calls. Some more exist (for
computing viscosity, speed of sound, Cp) but they are not supported by all the
libraries and should thus be avoided.
For example, to get the steam and liquid mass fraction of a saturated mixture, the
best way to proceed is to compute it from the enthalpy:
vcax_Xv = ( vcax_H vcax_HLsat ) / ( vcax_HVsat vcax_HLsat) ;
vcax_Xl = 1.0 vcax_Xv ;
ALC-MODELLING-Programming Methods, Page 31
This document is the property of CORYS T.E.S.S., any communication, reproduction, publication, even partial, is forbidden without the written consent of CORYS
T.E.S.S.
ALICES DOCUMENTATION
Programming Methods
The liquid and steam volume fraction can also be computed in a similar way from
density:
vcax_Yl = ( vcax_R vcax_RVsat ) / ( vcax_RLsat vcax_RVsat) ;
vcax_Yv = 1.0 vcax_Yl ;
10.3
GAS LIBRARY
The library that is commonly used for computing gases properties is the library
MelangeGasPlus97Sol.
This library gives the main thermodynamic properties of many gases (and of their
mixtures) in a large range of pressure and temperature.
Here again, all the data and procedures have been encapsulated in a C++ class
named FluidMelangeGaz.
The interface between ALICES and the tables is done by creating an object of this
class and by calling some appropriate methods. There are two main kinds of
method: those which define the current thermodynamic state and those which
compute a property at this given state.
The following subsections explain how to create and to use such an object.
ALICES DOCUMENTATION
Programming Methods
SruValOrderedVector<SruString> ysru_Gas_Name ;
sru_Gas_Name.Token( ysru_Gas_Name , '&' ) ;
DifInteger zGas = ysru_Gas_Name.Items() ;
This syntax is very similar to the one used for liquid library. The main difference
comes from the species names that must also be read from another keyword
(Gas_Name in this case). This operation is performed at lines 2 in this example.
The corresponding line in the configuration file should look like:
Gas_Name = O2 & N2 & CO2
The other difference comes from the environment string that is passed to the
Setup() method: it must also contain the Species= keyword followed by the
species list (lines 5 and 6).
Notice also the use of a SruValOrderedVector<SruString> array and as well as the
use of the Token() and Items() methods at the end of this example to get each
species name, as well as the total number of species.
Another important difference arises: the gas composition must be fixed before
computing any properties. This is often achieved in CycleStart0 (because
composition is fixed during iterations) by the following lines:
vGasState.Y( ydif_Gas ) ;
The method which is used is Y( DifVectorOfReal ydif_Gas). It is necessary to use a
DifVectorOfReal as argument (this is the natural type for vector in ALICES). Of
course, the values in this vector must be ordered to match the species name order
that was given in LifeStart0.
ALC-MODELLING-Programming Methods, Page 33
This document is the property of CORYS T.E.S.S., any communication, reproduction, publication, even partial, is forbidden without the written consent of CORYS
T.E.S.S.
ALICES DOCUMENTATION
Programming Methods
vGasState.PT(vcax_P,vcax_T) ;
vGasState.PH(vcax_P,vcax_H) ;
vGasState.T() ;
vGasState.H();
vGasState.Rho() ;
Not from P and T)
and so on
Basically, the thermodynamic laws that are used are very close from the perfect
gas law.
ALICES DOCUMENTATION
Programming Methods
11. MALFUNCTIONS
Another important subject to describe is malfunctions.
Actually, most of the malfunctions are processed by the sequential modules, but a
few malfunctions may be implemented in thermo-hydraulic objects (in filters, valves
or exchanger for example).
The main actions are performed in
Notification(DaxExtractStream aStream).
particular
method
named
void
The idea is that the Instructor Station (IS) can send a notification to all the
objects (with a DaxExtractStream) to inform them that a malfunction is
occurring. The objects then have to analyze if they are concerned by this
notification and what they should do if they are.
The following lines show a typical example of Notification method:
ImsMessageStack vMessage;
iActif ;
if ( sRequestTypePI.MultiChar() == 'Mlft' )
malfunction ?
//
is
this
message
{
aStream >> iActif;
while ( aStream->DataAvailable() )
stream
//
get
following
data
from
{
sRequestNamePI = "";
aStream >> sRequestNamePI;
if ( sRequestNamePI.MultiChar() == 'FDeg' )
malfunction type
ALICES DOCUMENTATION
Programming Methods
{
if ( iActif != 0 )
// activated malfunction
{
mMalf_type = 1 ;
is set to 1
}
else
// deactivated malfunction
{
mMalf_type = 0 ;
is reset to 0
}
}
else
malfunction type)
//
if
no
'FDeg'
(unknown
{
vMessage.InsertErrorMessage("Mlft", "Err", cImsError, "") << " Unknown
malfunction type";
throw vMessage;
}
}
}
// end if no 'FDeg'
// end while
// end if 'Mlft'
ALICES DOCUMENTATION
Programming Methods