Version 1 (modified by Rafael de Pelegrini Soares, 15 years ago) (diff)


CalcObject - External Calculation Objects

EMSO is an equation-based tool, therefore most type of mathematical relations can be expressed directly as equations, using its modeling language. However, there are some cases in which using equations is barely convenient. Typical examples include:

  • The relationship cannot be expressed in a closed algebraic form without introducing many intermediate quantities with no physical sense;
  • The relationship requires lots of data parameters;
  • Already exists well established software that provides the required calculation;
  • It is difficult to converge the problem without decoupling the system.

Exactly for the above cases, EMSO provides a mechanism where the user can plug code written in C, C++, or FORTRAN into the models.

Using a CalcObject's

In order to plug external calculation code into the models the user needs to declare a special parameter, a CalcObject:

Model stream_therm as stream
   PP as CalcObject (Brief = "External Physical Properties");
   h = (1-v)*PP.LiquidEnthalpy(T, P, z) + v*PP.VapourEnthalpy(T, P, z);

In the above example (see streams.mso?), the parameter PP is the CalcObject.

CalcObject Methods

Once the CalcObject was declared, the user can call its methods. Methods can have arguments and are called using the dot notation, eg:

PP.LiquidEnthalpy(T, P, z)

In the above call three arguments are supplied: T, P, and z. Before running a simulation, EMSO will check if all methods used in models actually were implemented by the CalcObject. EMSO also check if the number of arguments and its units of measurement are correct.