2.2.5. The Algorithm elementΒΆ

The Algorithm element implements the mathematical behaviour of the model componenent in a language.

..An Algorithm element information item is a child of a ModelUnit element.

<ModelUnit modelid=" " timestep=" " name=" " version =" ">
   ...
   <Algorithm language =" " filename= "" platform=" ">
   ...
</ModelUnit>
  1. An Algorithm element MUST contain one of the language attribute

  2. An Algorithm element MAY contain one of each following attributes

    1. The platform attribute

    2. The filename attribute

The model specifications defined in Inputs and outputs are sufficient to generate the signature of the function or a skeleton of class in a specific language. So, in this code, It is just necessary to express a snippet of code to describe the dynamic of the model.

This is an example of algorithm of Diffusion Limited Evaporation of Energy Balance component implemented in C++. In this case all variables used have already declared in the model specification.

if (deficitOnTopLayers / 1000 <= 0)
        diffusionLimitedEvaporation = 8.3 * 1000;
else
{
        if (deficitOnTopLayers / 1000 < 25)
                diffusionLimitedEvaporation = (2 * soilDiffusionConstant * soilDiffusionConstant / (deficitOnTopLayers / 1000)) * 1000;
        else
                diffusionLimitedEvaporation = 0;
}

Six languages are supported : Fortran, Java, C++, C#, Python and R. In order to avoid a re-implementation in this multiplicity of languages, Crop2Ml defines a minimal language CyML based on an intersection of the above languages.

You can visit a full documentation of CyML Here .

Algorithm implemented in CyML

if deficitOnTopLayers / 1000 <= 0:
   diffusionLimitedEvaporation = 8.3 * 1000
else:
   if deficitOnTopLayers / 1000 < 25:
      diffusionLimitedEvaporation = (2 * soilDiffusionConstant * soilDiffusionConstant / (deficitOnTopLayers / 1000)) * 1000
   else:
      diffusionLimitedEvaporation = 0