Control flow

Model Creation

A YAML format configuration file defines both the model structure (spatial domains containing biogeochemical variables and reactions that operate on them) and model parameter values. Reactions (subtypes of AbstractReaction) are identified by Type name (without module prefix) in the configuration file.

To create the model, the numerical solver or host should call create_model_from_config which reads the configuration file, and then:

Model initialisation

To initialise the model, the numerical solver or host should then:

State Variable initialization

To initialise state Variables and perform any Reaction-specific initialisation, the numerical solver or host should:

  • call dispatch_setup with attribute_name = :norm_value. These Reaction setup methods should set state Variables according to the :norm_value Variable attribute (which can be set in the variable_attributes: section of the config file). Reactions may also use these values internally.
    • optionally (if normalisation values are required by a numerical solver), copy the Variable normalisation values from the arrays in ModelData to the solver.
  • optionally call dispatch_setup with attribute_name = :initial_value to set state Variables according to the :initial_value Variable attribute (which can be set in the variable_attributes: section of the config file).

Main loop

To calculate the model derivative, the numerical solver or host should:

Additional notes

Operator splitting and Domain tiling: Reaction and Domain subsets

The default initialisation described above calculates the model derivative for all model Reactions for all Domains, using the cellranges_all, and dispatchlists_all fields of the ModelData struct. A custom Vector of CellRanges can be used to select a subset of ReactionMethods by Domain and operatorID, eg to implement operator splitting. Tiles within Domain eg to implement Domain decomposition for a multithreaded model can be defined by specifying CellRanges with a subset of cell indices within Domains.

The custom Vector of CellRanges should then be supplied to

Multithreaded models

To use with a multithreaded solver eg for a spatially tiled model:

  • Set threadsafe=true when calling create_modeldata. The subsequent call to allocate_variables! will then allocate Julia Threads.Atomic variables for PALEO Variables with attribute atomic: = true (usually scalar accumulator variables for totals etc).
  • Supply a method_barrier implementing a thread barrier function to initialize_reactiondata!. Reactions are sorted into groups, where each group has no dependencies and later groups depend on earlier ones. The method_barrier will be inserted between these groups of independent Reactions.

Automatic differentiation

  • Set eltype when calling create_modeldata to the appropriate dual number type for a (forward) automatic differentation implementation. All model arrays are held in the created ModelData struct and multiple ModelData instances can be created, allowing a combination of eg AD Jacobian and standard derivative calculations with different array types.