Extending the model¶
Overall organisation of the model code¶
The model source code is structured to be as modular as possible. This means for example that generic model infrastructure such as the numerical schemes, grid definitions and input/output-routines are as detached from the actual physical formulation of the model as reasonably possible within the limitations of Fortran. Further, the different physical models are all self-contained and can be run independently from each other; add-ons to physical models such as the atmospheric tracer module are formulated such that they will work without adaptation with each of the available atmospheric models.
Some specific consequences of this modular approach are:
Model components need to register themselves which variables are to be included in the netCDF output.
Model components need to register the variables required for the exchange with other model components.
Fortran modules need to define their own routines for initialisation and termination, called
init_<module_name>
andterm_<module_name>
as far as relevant.All relevant API to run the model is contained in the
runctrl
module. This module coordinates the overall initialisation and termination of a model simulation. Therunctrl
module is used in both the Fortran executable and the python runscripts.Preprocessors share the model numerics and grid definitions and all other generic infrastructure in
src_base
andsrc_numerics
.Different model components can be swiched on/off both at compile time and (as far as available in the executable) for each model simulation. Each model component thus needs to be guarded by a compile-time switch to include/exclude the model from the compilation.
The following table gives a brief overview over the functions and content of each Fortran module in an order in which all interdependencies between modules have been resolved (i.e. modules depend on only on other modules that appear earlier in the list). The first list of modules contains the basic infrastruture and numerics used for all physical models and the preprocessors.
Fortran module |
Folder |
Description |
---|---|---|
|
src_base |
Defines the numerical precision used throughout. |
|
src_base |
Fortran boilerplate necessary to define and use procedure pointers. |
|
src_base |
Defines physical constants and model parameters. |
|
src_base |
Defines the report and status files and functions for error reporting. |
|
src_base |
Defines parameterised 2d-functions, e.g. Gaussian ridges and hills. |
|
src_base |
Reads netCDF files for initialisation/restart. |
|
src_base |
Defines and parses the grid, topo and metio namelists. |
|
src_base |
Defines various grids (main, staggered, multigrid for the QG-inversion). |
|
src_numerics |
Defines interpolation functions between grids of different resolutions. |
|
src_numerics |
Defines different boundary conditions and makes them available in a common interface. |
|
src_numerics |
Defines routines to solve elliptical PDEs, for example to do a Laplace-inversion. |
|
src_numerics |
Defines derivatives on the grid at different numerical precision. |
|
src_numerics |
Defines abstract time integration routines. |
|
src_base |
Defines the interfaces used to exchange information between model components. |
|
src_base |
Writes results from the simulation as netCDF output. |
With all these basics established, we can proceed to define the different physical model components. The model compomnents each typically contain several Fortran modules. Typically each model component contains
a configuration module defining the model-specific namelists,
a module containing functions to calculate diagnostic variables, and
a module containing the prognostic equations and a function advancing the model by a time step.
Currently, the following physical models are available:
Model component |
Folder |
Description |
---|---|---|
|
src_atmos |
Physical core of the namegiving QG/PE model. |
|
src_atmos |
An optimised PE model (currently defunct). |
|
src_atmos |
An atmospheric passive tracer module. |
|
src_ocean |
A slab-ocean with different parameterisation for prescribed and wind-induced currents. |
With all physical models defined, the src_core
folder contains first and foremost the runctrl
module which orchestrates all of the above and provides functions to initialise, run and terminate the model. These functions are used in the Bedymo standalone executable defined in bedymo_main
and the python runscripts.
Fortran module |
Folder |
Description |
---|---|---|
|
src_core |
Defines and parses the models, numerics and timectrl namelists. |
|
src_core |
Provides the API to run the model for the Fortran executable and the python run scripts. |
|
src_core |
Defines the Fortran executable and its command line options. |
Finally, preprocessors are defined in the src_pre
folder. Currently there is only one preprocessor available which can be used to define custom idealised initial conditions for Bedymo.
Preprocessor |
Folder |
Description |
---|---|---|
|
src_pre |
Defines an executable to create custom idealised initial conditions for Bedymo. |
Adding parameterisations and model components¶
Given the modular approach and the comprehesive basic infrastructure it is relatively straightforward to add new model components to Bedymo. The existing physical models provide a template on how to best structure the new code to fit into the modelling framework.
The only place where existing code must be touched to include a new model component is the runctrl
module. Here, the new model component must be included in the model initialitsaion and termination choreography as well as in the function that advances all model components by a time step. With that in place, remember to document the new model component
in the top section of the
compile
script, listing the models that can be included in the compilation.this documentation page defined in the
doc/source
-directory of the model code repository.
Note that parameterisations beyond a certain complexity are best included as new model components similar to the tracer module. This allows to enable/disable/configure the parameterisations independently from, for example, the atmospheric model which they hook onto.
Happy coding!