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"?>
<openfluid>
  <model>
   
    <function fileID="myfunction">
      <param name="myparam" value="2" />          
    </function>
    
  </model>
</openfluid>            


initParam method of the simulation function source code:

bool MyFunction::initParams(openfluid::core::FuncParamsMap_t Params)
{
  m_MyParam = 0; //default value
  OPENFLUID_GetFunctionParameter(Params,"myparam",&m_MyParam);

  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.

Types

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.

Access

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;
  DECLARE_UNITS_ORDERED_LOOP(12);

  CurrentStep = SimStatus->getCurrentStep();

  BEGIN_UNITS_ORDERED_LOOP(12,"SU",SU)

    OPENFLUID_GetVariable(SU,"MyVar",CurrentStep,&TmpValue);
    TmpValue = TmpValue * 2;
    OPENFLUID_AppendVariable(SU,"MyVarX2",QOutput);

  END_LOOP

  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;
  DECLARE_EVENT_COLLECTION_LOOP;
  DECLARE_UNITS_ORDERED_LOOP(1);

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

  BEGIN_UNITS_ORDERED_LOOP(1,"SU",SU)

    EvColl.clear();

    OPENFLUID_GetEvents(SU,BTime,ETime,&EvColl);
    EvList = EvColl.getEventsList();

    BEGIN_EVENT_COLLECTION_LOOP(EvColl.getEventsList(),Ev)
      if (Ev->isInfoEquals("molecule","glyphosate"))
      {
        // process the event
      }
    END_LOOP;

  END_LOOP;

  return true;
}

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