Model Approach in SINDBAD
This documentation explains how to work with model approaches in SINDBAD. For a comprehensive understanding of SINDBAD's modeling framework, see the SINDBAD concept documentation.
INFO
When working with SINDBAD, it is highly recommended to utilize the built-in function generateSindbadApproach
to create your model and approach files. This function automates the process of setting up the necessary structs and functions of the model, ensuring that your model adheres to the established conventions for code structure, performance tips, modularity, and documentation.
Check the documentation of the function for further details as:
using Sindbad
?generateSindbadApproach
Viewing Model Approaches
To view available model approaches and their implementations:
using Sindbad: showMethodsOf
showMethodsOf(LandEcosystem)
This will display all available model approaches that are subtypes of LandEcosystem
.
Model Approach Structure
A model approach in SINDBAD typically follows this structure:
# Define the model type
abstract type newModel <: LandEcosystem end
@bounds @describe @units @timescale @with_kw struct newModel_v1{T1,T2} <: newModel
param1::T1 = 1.0 | (2.0, 5.0) | "description 1" | "units 1" | ""
param2::T2 = 0.0 | (1.0, 2.0) | "description 2" | "units 2" | ""
end
# Define the purpose
purpose(::Type{newModel}) = "Description of what this model does"
For more details about the modeling conventions and required methods, see the modeling conventions documentation.
Required Methods
1. define
function define(params::newModel_v1, forcing, land, helpers)
## unpack parameters, forcing and variables store in land
@unpack_newModel_v1 params
@unpack_nt (f1, f2) ⇐ forcing
@unpack_nt var1 ⇐ land.diagnostics
## calculate variables
new_var_1 = f1*param1 + param2 + var1*f2
## pack land variables
@pack_nt begin
new_var_1 ⇒ land.diagnostics
end
return land
end
Initializes model-specific variables
Sets up model parameters
Returns modified
land
structure
For more information about variable initialization, see the land concept documentation.
2. compute
function compute(params::newModel_v1, forcing, land, helpers)
## unpack parameters, forcing and variables store in land
@unpack_newModel_v1 params
@unpack_nt (f1, f2) ⇐ forcing
@unpack_nt var1 ⇐ land.diagnostics
## calculate variables
var_1 = f1*param1 + param2 + f2
## pack land variables
@pack_nt begin
var_1 ⇒ land.diagnostics
end
return land
end
Implements core model calculations
Updates model state
Returns modified
land
structure
Input Arguments
All models are defined as follows:
abstract type newModel <: LandEcosystem end
@bounds @describe @units @timescale @with_kw struct newModel_v1{T1,T2} <: newModel
param1::T1 = 1.0 | (2.0, 5.0) | "description 1" | "units 1" | ""
param2::T2 = 0.0 | (1.0, 2.0) | "description 2" | "units 2" | ""
end