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()Enabling the module means that it will be executed at each time step.
enable()Enabling the module means that it will be executed at each time step.
Return whether the module is enabled or not.
reset()Stop and start the module.
setup(mset)Start the module
start()Start the module
stop()Stop the module
update(mz)Update the module
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.
The model settings
Examples using
fridom.framework.modules.Module#- name = 'Base Module'#
- setup(mset: ModelSettingsBase) None[source]#
Start the module
Description#
This method is called by the ModelSettings.setup() and sets the ModelSettings as well as the differentiation and interpolation modules.
- 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 module
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]#
Enabling the module means that it will be executed at each time step. Disabled modules are neither initialized nor updated.
- disable() None[source]#
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 mset: ModelSettingsBase#
The model settings
- property diff_module: DiffModule#
The differentiation module to be used by this module.
- property interp_module: InterpolationModule#
The interpolation module to be used by this module.
- property required_halo: int#