You are on page 1of 37

ALICES DOCUMENTATION

Programming Methods

1.

INTRODUCTION AND FOREWORDS


Basically, all the variables in ALICES are C++ objects. These objects are
instantiation of generic classes that bring many methods to the user and that finally
provide a very powerful working environment.
The aim of this document is to give an overview of the methods available when
developing a thermo-hydraulic object. The rough idea is to help the developers both
understanding the objects that already exist and creating new objects.
This manual should thus be considered as a How to or a F.A.Q. document,
rather than an explicit description of all the available methods: most of the classes
in ALICES are not designed to be used by thermo-hydraulic modeliser, and even in
the ones that should be used, only a few methods are really useful.

ALC-MODELLING-Programming Methods, Page 1


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

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 ;

// the vector V2 must have been dimensioned before

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

ALC-MODELLING-Programming Methods, Page 4


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

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

REAL WITH DERIVATIVES


This type is one of the most important for thermo-hydraulic modeling. This class
has no classical equivalent in C++. Indeed, this class enables to perform usual
operations (as the DifReal class) but also brings an additional functionality: it
automatically computes the partial derivatives of the variable with respect to the
principal variables. Basically, all the variables used in the Function cycle should be
declared to be object of this class (its name is CaxReal).
First, it is useful to say that a CaxReal brings exactly the same methods than a
DifReal: any DifReal could be declared as a CaxReal and would have the same
behavior. However, this class is much bigger and it would be a lost of time.
The main mechanism occurring when performing operations on CaxReal is the
following:
CaxReal vcax_X = mP_Y ; // the principal variable mP_Y is affected to the CaxReal
variable vcax_X
After this operation, the vcax_X object can be thought as the following array:
vcax_X ~ (value of mP_Y, 1.0, mP_Y).
Three data are stored in this array: first is the value of the variable, and then a pair
that is the partial derivative of vcax_X with respect to a principal variable and the
name of the concerned principal variable.
After the following operation (lets take mP_Y = 3.0 and mP_Z = 16.0):
vcax_X = 2.0 * mP_Y * sqrt( mP_Z ) ;
the conceptual array associated to vcax_X is the following:
vcax_X ~ (24.0, 8.0, mP_Y, 0.75, mP_Z)
with:

24.0 = 2.0 * 3.0 * sqrt( 16.0 )

8.0 = d(vcax_X)/d(mP_Y) = 2.0 * sqrt(mP_Z) = 2.0 * sqrt( 16.0 )


ALC-MODELLING-Programming Methods, Page 5

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

0.75 = d(vcax_X)/d(mP_Z) = 2.0 * mP_Y * (


sqrt( 16.0 )

0.5 / sqrt(mP_Z) ) = 3.0 *

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 Derivatives() method returns the number of derivative of the CaxReal


variable.

The Value() method returns a DifReal which is the value of the CaxReal
(the first element of the conceptual array).

It is possible to build a CaxReal with a constructor (e.g. vcax_X = CaxReal


( 1.0, 0.5, mP_Y )). This syntax is very close from the conceptual array point
of view.

A special attention must be paid to the existence of derivatives: e.g. even if


sqrt(0.0) is defined, its derivative is not. Thus it is allowed to write sqrt(0.0)
(because in this context 0.0 is considered as a DifReal) but it is not to write
sqrt(mP_Y) if mP_Y is zero (this will induce a division by zero exception
when computing derivatives).

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

VECTOR OF REAL WITH DERIVATIVES


The class CaxVectorOfReal exists, but is not used. It will not be described here.

2.8

COMPLEX WITH DERIVATIVES


The class CaxComplex also exists but will not be described here.

ALC-MODELLING-Programming Methods, Page 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

2.9

VECTOR OF COMPLEX WITH DERIVATIVES


The class CaxVectorOfComplex also exists but will not be described here.

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)

// 3rd constructor (just allocate a given

SruString sru_str4 = text ;

// affectation

sru_str.Length() ;

// returns the strings length

sru_str << Hello ;


sru_str ;

SRU_STRING_CAST( DifReal , sru_str ) ;


DifReal if possible

sru_str.Token( ysru_str_array , '&' ) ;


them into an array.

// concatenate the string Hello at the end of


// cast the string sru_str in a

// find substrings in a string and place

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

After these lines, ysru_str_array[ 0 ] contains A, ysru_str_array[ 1 ] contains B


and ysru_str_array[ 2 ] contains C.
2.11

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

The indexation operator [ ] is used to access a given element of such a vector.

ALC-MODELLING-Programming Methods, Page 8


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

3.

METHODS ASSOCIATED WITH CONNECTYPES


All the connectypes are classes that inherit from a bas class: MoxBaseConnectype.
For example, the C++ source code of the class associated to the graphical
connectype Equip_out is declared with:
class MoxConnectype_Equip_Out : public MoxBaseConnectype
The main method provided by this base class is IsConnected() which returns
either true or false according if the connectype is connected or not.
This method is intensively used because if a connectype is not connected, an
exception will be thrown when trying to access its data.
Example:
if (ySens_Out[ 0 ].IsConnected() ) ySens_Out[ 0 ].mIn_Sens = 0.0 ;
In thermo-hydraulic objects, all the connectype of a given type are stored into an
array. For example, in an Arc that has 2 connectypes of type Arc_Flow, the
following array is declared as a member data of the Arc:
MoxConnectype_Arc_Flow yArc_Flow[ zArc_Flow ] ;
In the previous line, zArc_Flow is an integer constant which represents the number
of connectypes of the given type (i.e. zArc_Flow = 2 in this case). It is also a
member data of the Arc and can thus be used in the object source code.
If a connectype has been given a name when it has been created (for example the
two Arc_Flow connectypes of an Arc are often named AFL and AFR), it is possible
to access this particular connectype with a predefined constant integer (ptAFL or
ptAFR in our example): this variable is the rank of the connectype in its array.
Example: yArc_Flow[ ptAFL ] is the object representing the connectype AFL.
Finally, it is often use to work on an alias when dealing with connectypes:
Example:
PtArc_Flow& xAFL = yNode_Flow[ ptAFL ] ;
yArc_Flow[ ptAFL ]
Here PtArc_Flow is the
MoxConnectype_Arc_Flow).

type

of

the

// defines the alias xAFL for


connectype

(it

is

equivalent

to

ALC-MODELLING-Programming Methods, Page 9


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

4.

GETTING DATA FROM THE CONFIGURATION FILE


In LifeStart0, the argument DaxEnvironment& aEnvironment is passed to the
method.
This variable contains all the data that were entered in the configuration file
(the .Modules.env file).
Several interesting methods are defined in the DaxEnvionment class:

aEnvironment.Defined(AnyKeyWord) which returns true if the keyword


AnyKeyWord is defined in the configuration file.

aEnvironment.Value(AnyKeyword) which returns the value of the keyword


AnyKeyWord. Warning: this keyword must be defined or an error will occur
at run-time.

aEnvironment.Value(AnyKeyword , DefaultValue) which returns the value


of the keyword AnyKeyWord (if this keyword is defined) or DefaultValue
(if the keyword is not defined).

The two previous methods return a SruString. The SRU_STRING_CAST


function should be used to cast this SruString into a DifReal.

Example:
DifReal vdif_Bound_Min_T =
SRU_STRING_CAST(
aEnvironment.Value("Bound_Min_T",c_Bound_Min_T) ) ;

DifReal,

ALC-MODELLING-Programming Methods, Page 10


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

5.

SENDING MESSAGES TO USER


The Ims service has been designed to provide an easy way for message
manipulation.
In thermo-hydraulic modeling, this service is mainly used for printing warnings or
error message in certain circumstances (generally after errors). For example, it is
often use to perform tests in the PreCondition method and to send such a
message to aware the user when a problem occurs (bad parameter, missing
connection). The class that enables this is ImsMessageStack.
Four main steps can be identified in the message sending procedure.

Declaration of the message object :

ImsMessageStack xMessageStack ;

Definition of the properties of the message :

xMessageStack.InsertErrorMessage( "majr", "minr", severity ,


IMS_DEBUG_INFO( context ) ) ;
or
xMessageStack.InsertText( "majr", "minr", severity ) ;

Addition of the message body:

xMessageStack<< "message ( parameter 0 = %0, parameter 1 = %1)" << param0


<< param1 << endl ;

Throw the message as an exception:

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).

Severity indicates what kind of message should be send. This argument


allows to have different behavior according to the severity of the message (a
simple warning or a fatal error). This argument MUST be chosen between
the following pre-defined constants:
o

- cImsFatal

: error ending the simulation

- cImsError

: error

- cImsWarning

- cImsInfo

- cImsSameSeverity

: error with no consequence


: information
: same thing as previous message

The last argument IMS_DEBUG_INFO(context) is a procedure call that


returns a string containing the file name, the line number and some
additional context, that can for example be the method name
(PreCondition most of the time).

Notice that the syntax xMessageStack.InsertText( majr, minr, severity ) can


also be found and is nearly equivalent (although there is no IMS_DEBUG_INFO in
this case) to define the message.
The second important thing to explain is how the addition of message works.
Actually, it is very easy because the << operator has been overloaded for this
class. Everything works as if a cout had been written instead of the object name.
Thee text behind the << operator is concatenated at the end of the error
message instead of going to the standard output. Finally, notice that parameters
can be included with the %0, %1 symbols.
The last thing to explain is the mechanism of printing: the ImsMessageStack object
that contains all the data about the error message is just thrown as a classical
exception. The treatment of this error message is performed automatically by
ALICES, according to the severity of the message.
Below is an illustrating example (the following lines could be found in the
PreCondition method of an Arc):
ImsMessageStack xMessageStack ;
if
!
(
(
yArc_Flow[
( yArc_Flow[ ptAFR ].IsConnected() ) )

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 << Arc must be connected at both sides ;


throw

xMessageStack ;

}
These lines throw a fatal error message (simulation stops) if an Arc is not
connected at both sides.

ALC-MODELLING-Programming Methods, Page 13


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

6.

THE PINFO POINTER


Each thermo-hydraulic object inherits from a base class: the DifBaseClass class.
This class mainly provides the methods that are common to all the differential
objects (LifeStart0, ). Moreover, a special member data is declared in this base
class: the pInfo pointer.
The pInfo variable is a pointer on a DifModuleInfo class (this class contains all the
information about a given differential module). Each differential module has a
DifModuleInfo object in its member data, and each thermo-hydraulic object of this
module has a pInfo member data pointing on this DifModuleInfo object. It is thus
possible to access the module properties directly from a thermo-hydraulic object
with the pInfo pointer.
The following methods are provided by the DifModuleInfo class:

EulerTimeStep() : this method returns the time step of the differential


module in seconds.

SimulatedTime() : this method returns the total simulated time in seconds.

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.

Phase(): this method returns an integer representing the actual computation


phase. This integer has only a finite number of possible values. These values
are represented by the following C++ constants:
o

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:

IsConverged() which returns true if convergence criterions on both


principal variable and on residual are satisfied.

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.

mStateAtLastCycle, mStateAtLastIteration, mFunctionAtLastCycle and


mFunctionAtLastIteration. The content of these four member data is quite
obvious. However, they must be used with the following point in mind: they
are all structures for being generic in term of real or complex data. Thus to
access the desired value, in Real context, they must be followed by the
.Real() method (see below for an example). Finally let us say that the
m*AtLastIteration data are not defined at the first iteration.

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) ;

ALC-MODELLING-Programming Methods, Page 17


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

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

ADAPTED SYMMETRIC SQUARE FUNCTION

7.1.1

Definition of the symmetric square function


In thermo-hydraulic objects, the square function is rarely used. Actually, the most
useful function is the symmetric square function. This function is defined by:
sym_sqr( X ) = X * abs( X )
This function is thus equal to sqr( X ) when X is positive and is equal to sqr( X )
when X is negative.

7.1.2

Definition of the adapted symmetric square function


The problem with the previous function is that it has a zero derivative at X=0.
It is a problem because the linear system that should be solved by the Newton
algorithm is not solvable when a diagonal coefficient of the Jacobian matrix is zero.
To avoid this, the adapted symmetric square function CaxSymSqr is defined with
the following C++ source code:
CaxReal CaxSymSqr ( CaxReal vcax_X )
{
if ( vcax_X.Value()<-gap )
else if ( vcax_X.Value()<0 )
2.0*gap, vcax_X ) ;

return - vcax_X * vcax_X ;


return CaxReal( - vcax_X.Value() * vcax_X.Value(),

else if ( vcax_X.Value()<+gap ) return CaxReal( + vcax_X.Value() * vcax_X.Value(),


2.0*gap, vcax_X ) ;
else

return + vcax_X * vcax_X ;

}
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

ADAPTED SYMETRIC SQUARE ROOT FUNCTION

7.2.1

Definition of the symmetric square root function


The symmetric square root function is the reverse function of the symmetric square
function:

7.2.2

sym_sqrt( X ) = - sqrt( - X )

when X<0

sym_sqrt( X ) = + sqrt( + X )

when X>=0

Definition of the adapted symmetric square function


The principle is the same as for the adapted square function: the adapted square
root function values are identical to its non-adapted counterpart everywhere.
Their derivatives are also identical outside of the interval [-gap*gap;+gap*gap].
Only the derivative is different in this interval.
CaxReal CaxSymSqrt ( CaxReal vcax_X )
{
if ( vcax_X.Value() < - gap * gap )
else if ( vcax_X.Value() < 0 )
0.5/gap, vcax_X ) ;

return - sqrt( - vcax_X ) ;


return CaxReal( - sqrt( - vcax_X.Value() ),

else if ( vcax_X.Value() < +gap * gap )


vcax_X.Value() ), 0.5/gap, vcax_X ) ;
else

return

CaxReal(

sqrt(

return + sqrt( + vcax_X ) ;

}
The derivative of this adapted function is continuous and has never an infinite
value.
7.3

ADAPTED ABSOLUTE VALUE FUNCTION


The C++ source code of the adapted absolute function is:
ALC-MODELLING-Programming Methods, Page 19
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

CaxReal CaxAbs ( CaxReal vcax_X )


{
if ( vcax_X.Value() < - gap)
else if ( vcax_X.Value() < 0 )
vcax_X.Value()/gap, vcax_X ) ;

return - vcax_X ;
return

else if ( vcax_X.Value() < +gap)


vcax_X.Value()/gap, vcax_X ) ;
else

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

HOW TO USE THESE FUNCTIONS IN THERMO-HYDRAULIC OBJECTS


Basically, the adapted functions described above are provided as C++ objects
functionalities. This section describes how to use them.

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

In this method, the gap parameter must be given to the object:


vSymSqrt.Gap( 1.0 ) ;
range [-1.0; +1.0]
7.4.4

// The function derivatives will only be modified in the

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.

ALC-MODELLING-Programming Methods, Page 21


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.

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" ) ;

// open the file File_1D.txt

vStream.ignore(1000, '\n' ) ;
Return character

// ignore what is written until the next

vcax_1D_interp_X.Read ( vStream ) ;
interpolation function.

// read the data points and build the

vStream.close() ;

// close the file File_1D.txt

vStream.open( "File_2D.txt" ) ;

// open the file File_2D.txt

vStream.ignore(1000, '\n' ) ;
Return character

// ignore what is written until the next


ALC-MODELLING-Programming Methods, Page 22

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

vcax_2D_interp_XY.Read ( vStream ) ; // read the data points and build the


interpolation function.
vStream.close() ;

8.4

// close the file File_2D.txt

STRUCTURE OF THE TEXT FILE CONTAINING DATA


The text files containing the interpolation data must of course be in a fixed format
to be readable. This section gives the required structure for both 1D and 2D
interpolation data.

8.4.1

1D Data
The structure of the file consists in 5 lines:

a dollar $ sign followed by an identifier

The number Nx of interpolation points in x direction

The Nx interpolation points in x direction, between { } and separated by


comma ,.

The number Nv of value at the interpolation points (must be equal to Nx).

The Nv values at interpolation points, between { } and separated by comma


,.

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:

a dollar $ sign followed by an identifier

The number Nx of interpolation points in x direction.


ALC-MODELLING-Programming Methods, Page 23

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 Nx interpolation points in x direction, between { } and separated by


comma ,.

The number Ny of interpolation points in y direction.

The Ny interpolation points in y direction, between { } and separated by


comma ,.

The two number Nvx Nvy of value at the interpolation points (must be equal
to Nx and Ny).

The Nx*Ny values at interpolation points, between { } and separated by


comma ,.

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

ALC-MODELLING-Programming Methods, Page 24


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

vdif_Value_2D = vcax_2D_interp_XY ( vdif_X , vdif_Y ) ;

// 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.

ALC-MODELLING-Programming Methods, Page 25


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

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 0, both equations are solved for

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

// aDescriptor is an integer which represents a

{
case cDescr_P_P :
equation

// cDescr_P_P is an integer that represent the pressure

{
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

// cDescr_P_T is an integer that represent the

{
if (mEq == 1 )
{ return false ;}
else
{ return true ;}
}
break;

default :
possibilities

// default must be present, even if there are no more

{ return true ;}
break;
}

Each equation is identified by the descriptor of its principal variable (actually by an


integer referencing to a principal variable).
This method is performed for each equation of the object: the current equation
descriptor is passed to the SelectEquation method and is seen locally as the integer
aDescriptor.
A comparison between the current equation descriptor and each descriptor
(cDescr_*) is then performed to identify the action that should take place.

ALC-MODELLING-Programming Methods, Page 27


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

10. FLUID LIBRARIES


All the thermodynamic properties computations in the objects are performed
through the use of some fluid libraries. Several fluid libraries are available (they
are chosen in the configuration file Module.Env).
Each of them have different target (for gases, for liquid water, for oil) but they all
give the same basic functionalities: for example computing the enthalpy or the
density from pressure and temperature.
Moreover, the methods name is identical, thanks to a common interface between
ALICES and all theses thermodynamic tables.
10.1

AVAILABLE LIBRARIES
The following libraries are available:

10.2

Eau01

Eau2K

Eau97Sol: this is the mostly used library for water properties.

Eauliq97Sol

Melange_gaz97

MelangeGazPlus97Sol: this is the mostly used library for gas properties.

Fioul_lourd97: for heavy fuel properties.

Oil97: for oil properties.

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

10.2.4 Computing a property at a given state


Once fluid object is initialized, it can be used to compute any given thermodynamic
state properties.
The first thing to do is to set the current thermodynamic state. Several methods are
available, according to what properties are known and according to what
properties should be computed after:

vState.P ( vcax_P ) ;

vState.T ( vcax_T ) ;

vState.PT ( vcax_P , vcax_T ) ;

vState.PH ( vcax_P, vcax_H ) ;

vState.PS ( vcax_P, vcax_S) ;

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

properties (actually, some properties as density can only be computed in a PH


context).

Example 1:
vSatState.P(vcax_P) ;

// the pressure is vcax_P

vcax_Tsat = vSatState.Tsat() ;
vcax_Tsat

// at this pressure, saturation temperature is

vcax_HLsat = vSatState.HLsat();// enthalpy of liquid phase in these conditions


vcax_HVsat = vSatState.HVlsat();
conditions

//

enthalpy

of

steam

phase

in

these

vcax_RLsat = vSatState.RLsat(); // density of liquid phase in these conditions


vcax_RVsat = vSatState.RVsat(); // density of steam phase in these conditions

Example 2:
vLiqVapState1.PT( vcax_P, vcax_T ) ;
and T

// the thermodynamic state is fixed with P

vcax_H = vLiqVapState1.H() ;

// the enthalpy is computed from P and T.

vLiqVapState2.PH( vcax_P, vcax_H ) ;


and H

// the thermodynamic state is fixed with P

vcax_R = vLiqVapState2.Rho() ;

// the density is computed from P and H.

vcax_S = vLiqVapState2.S() ;

// the entropy is computed from P and H.

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.

10.3.1 Concealed Data


The FluidMelangeGaz objects must be declared here.
FluidMelangeGaz vGasState ;
10.3.2 Interface Includes
The following header file must be included in the Interface Includes section:
#include "Fluid/FluidMelangeGaz.h"
10.3.3 LifeStart0
In this section (that is performed only once at the beginning of the simulation), all
the FluidMelangeGaz objects must be initialized. For that, the fluid library name
must be read from the configuration file:
SruString sru_GasLib = aEnvironment.Value("GasLib");
ALC-MODELLING-Programming Methods, Page 32
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

SruString sru_Gas_Name = aEnvironment.Value("Gas_Name");

SruString sru_Environment = "FluidLib=" ;


sru_Environment << sru_GasLib ;
sru_Environment << ", Species=" ;
sru_Environment << sru_Gas_Name ;
vGasState.Setup( sru_Environment ) ;

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

10.3.4 Computing a property at a given state


After this step has been achieved, the FluidMelangeGaz objects can be used exactly
as the FluidMonoElt objects: the same methods are available (except those
associated to saturation state):

vGasState.PT(vcax_P,vcax_T) ;

// fix the state with P and T

vGasState.PH(vcax_P,vcax_H) ;

// fix the state with P and H

vGasState.T() ;

// compute T from P and H

vGasState.H();

// compute H from P and T

vGasState.Rho() ;
Not from P and T)

// compute Rho from P and H (only!!!

and so on

Basically, the thermodynamic laws that are used are very close from the perfect
gas law.

ALC-MODELLING-Programming Methods, Page 34


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

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;

// for error messages

DaxSignature sRequestTypePI, sRequestNamePI;


use of multichar
DifInteger
is active

iActif ;

// this class enables the

// this variable tells if the malfunction

aStream >> sRequestTypePI;

// get message from IS

if ( sRequestTypePI.MultiChar() == 'Mlft' )
malfunction ?

//

is

this

message

{
aStream >> iActif;

// get activation flag

while ( aStream->DataAvailable() )
stream

//

get

following

data

from

{
sRequestNamePI = "";
aStream >> sRequestNamePI;
if ( sRequestNamePI.MultiChar() == 'FDeg' )
malfunction type

// FDeg is the expected

ALC-MODELLING-Programming Methods, Page 35


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

{
if ( iActif != 0 )

// activated malfunction

{
mMalf_type = 1 ;
is set to 1

// the member data mMalf_type

}
else

// deactivated malfunction

{
mMalf_type = 0 ;
is reset to 0

// the member data mMalf_type

}
}
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'

ALC-MODELLING-Programming Methods, Page 36


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

ALC-MODELLING-Programming Methods, Page 1


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.

You might also like