Module#
- class fridom.framework.modules.module.Module[source]#
Bases:
objectBase class for all modules.
Description#
A module is a component of the model that is executed at each time step. It can for example be a tendency term, a parameterization, or a diagnostic as for example outputting the model state to a file.
Required methods: 1. __init__(self, …) -> None: The constructor only takes keyword argument which are stored as attributes. Always call the parent constructor with super().__init__(name, **kwargs). The name of the module is stored in the timing module and should not be too long. 2. update(self, mz: ModelState) -> None: This method is called by the model at each time step. It can for example update the tendency state mz.dz based on the model state mz. Or write the model state to a file. Make sure to wrap the method with the @update_module decorator.
Optional methods: 1. start(self, mset: ModelSettingsBase) -> None: This method is called by the model when the module is started. It can for example open an output file. Make sure to wrap the method with the @start_module decorator. 2. stop(self) -> None: This method is called by the model when the module is stopped. It can for example close an output file. Make sure to wrap the method with the @stop_module decorator.
Parameters#
- namestr
The name of the module.
- **kwargs
Keyword arguments that are stored as attributes of the module.
Flags#
- required_haloint
The number of halo points required by the module.
- mpi_availablebool
Whether the module can be run in parallel.
- execute_at_startbool
Whether the module should be executed before the first time step.
Examples#
import fridom.framework as fr class Increment(fr.modules.Module): def __init__(self): # sets the module name to "Increment", and the number to None super().__init__("Increment", number=None) @fr.modules.start_module def start(self): self.number = 0 # sets the number to 0 @fr.modules.update_module def update(self, mz: fr.ModelSettingsBase) -> None: self.number += 1 # increments the number by 1 @fr.modules.stop_module def stop(self): self.number = None # sets the number to None
Methods
__init__()disable()Disable the module.
enable()Enable the module.
Whether the module is enabled or not.
reset()Stop and start the module.
setup(mset[, setup_mode])Set the module up.
start()Start the module.
stop()Stop the module.
update(mz)Update the model state.
Attributes
The differentiation module to be used by this module.
The grid of the model settings.
Return a dictionary with information about the time stepper.
The interpolation module to be used by this module.
Whether the module is set up.
The model settings.
The required halo points for this module.
Examples using
fridom.framework.modules.Module#- name = 'Base Module'#
- setup(mset: ModelSettingsBase, setup_mode: Literal['default', 'forced'] = 'default') None[source]#
Set the module up.
Description#
This method is called by the ModelSettings.setup() and sets the ModelSettings as well as the differentiation and interpolation modules.
Parameters#
- msetfr.ModelSettingsBase
The model settings object.
- setup_modeLiteral[“default”, “forced”]
The setup mode. If the setup mode is “default” and the module is already setup, the method will return. If the setup mode is “forced”, the module will be setup again.
- start() None[source]#
Start the module.
Description#
This method is called at the beginning of the model run. Child classes that require a start method (for example to start an output writer) should overwrite this method. Make sure to decorate the method with the @module_method decorator.
- stop() None[source]#
Stop the module.
Description#
This method is called by the model at the end of the model run or when the model is reset. Child classes that require a stop method (for example to close an output file) should overwrite this method. Make sure to decorate the method with the @module_method decorator.
- update(mz: ModelState) ModelState[source]#
Update the model state.
Description#
This method is called by the model at each time step. Child classes should overwrite this method to update the module. Make sure to decorate the method with the @module_method decorator.
Parameters#
- mzfr.ModelState
The model state at the current time step.
Returns#
- fr.ModelState
The updated model state.
- enable() None[source]#
Enable the module.
Description#
Enabling the module means that it will be executed at each time step. Disabled modules are neither initialized nor updated.
- disable() None[source]#
Disable the module.
Description#
Enabling the module means that it will be executed at each time step. Disabled modules are neither initialized nor updated.
- property info: dict#
Return a dictionary with information about the time stepper.
Description#
This method should be overridden by the child class to return a dictionary with information about the time stepper. This information is used to print the time stepper in the __repr__ method.
- property is_setup: bool#
Whether the module is set up.
- property mset: ModelSettingsBase#
The model settings.
- property diff_module: DiffModule | None#
The differentiation module to be used by this module.
- property interp_module: InterpolationModule | None#
The interpolation module to be used by this module.
- property required_halo: int#
The required halo points for this module.