Access to simulation parameters, data and variables

Access to function parameters

Functions parameters are passed through the model.xml file. They can be accessed in the source code from the initParams method of the simulation function, unsing OPENFLUID_GetFunctionParameter . The requested parameter name must be the same as the one used in the model.xml file.

model.xml file:

<?xml version="1.0" standalone="yes"?>
    <function fileID="myfunction">
      <param name="myparam" value="2" />          

initParam method of the simulation function source code:

bool MyFunction::initParams(openfluid::core::FuncParamsMap_t Params)
  m_MyParam = 0; //default value

  return true;

To be reused in other part of the simulation function, the variable to store the value of function parameters should be declared as class variables. The parameters type can be string, double, integer, boolean, vector of string, vector of double, ... (see definitions of OPENFLUID_GetFunctionParameter to get more information about available types).

Access to simulation variables

The values for the simulation variables are attached to the homogeneous units.


Currently, the variables can be typed with one of the two defined types:

The scalar type is a double precision floating point type. The corresponding plain old type in C++ is double.


The methods to access simulation variables exist in two flavours, for scalar and vector, depending on the type you pass for the value:

They can be accessed only from the runStep method.

bool MyFunction::runStep(const openfluid::base::SimulationStatus* SimStatus)
  int CurrentStep;
  openfluid::core::ScalarValue TmpValue;
  openfluid::core::Unit* SU;

  CurrentStep = SimStatus->getCurrentStep();


    TmpValue = TmpValue * 2;


  return true;

Access to input data

In order to access to input data provided through standard input files, you can use the following methods. They are usable from initializeRun , runStep , and finalizeRun :

The name of the accessed input data must match the name given in the standard input files.

Access to discrete events

A discrete event is defined in the class openfluid::core::Event. It is defined by a date and a list of key-value information that can be accessed by methods proposed by the openfluid::core::Event class.
A collection of discrete events can be contained by an openfluid::core::EventsCollection class.

To get a collection of events occuring during a period on a given unit, you should use the OPENFLUID_GetEvents method. It returns an openfluid::core::EventsCollection that can be processed.
in order to process an event collection, you can parse it using specific macros:

At each iteration, the current event can be processed.

To add an event occuring on a specific Unit at specific date, you can use the OPENFLUID_AppendEvent method.

Example of process of events occurring on the current time step:

bool MyFunction::runStep(const openfluid::base::SimulationStatus* SimStatus)
  openfluid::core::Unit* SU;
  openfluid::core::EventCollection EvColl;
  openfluid::core::Event* Ev;
  std::list<openfluid::core::Event* > *EvList;
  openfluid::core::DateTime BTime, ETime;

  BTime = SimStatus->getCurrentTime();
  ETime = BTime + SimStatus->getTimeStep()-1;



    EvList = EvColl.getEventsList();

      if (Ev->isInfoEquals("molecule","glyphosate"))
        // process the event


  return true;

Generated using Doxygen 1.6.3
Creative Commons License Creative Commons By-NC-ND license