ModelSettingsBase#
- class fridom.framework.model_settings_base.ModelSettingsBase(grid: GridBase, **kwargs: dict)[source]#
Bases:
objectBase class for model settings container.
Description#
This class should be used as a base class for all model settings containers. It provides a set of attributes and methods that are common to all models. Child classes should override the following attributes: - n_dims - model_name - tendencies - diagnostics
And the following methods: - state_constructor - diagnostic_state_constructor
Examples#
Create a new model settings class by inheriting from ModelSettingsBase:
import fridom.framework as fr class ModelSettings(fr.ModelSettingsBase): def __init__(self, grid, **kwargs): super().__init__(grid) self.model_name = "MyModel" # set other parameters self.my_parameter = 1.0 # Finally, set attributes from keyword arguments self.set_attributes(**kwargs) # optional: override the parameters property @property def parameters(self): res = super().parameters res["my_parameter"] = self.my_parameter return res
Methods
__init__(grid, **kwargs)Construct the diagnostic state vector from this model settings.
set_attributes(**kwargs)Set model settings attributes from keyword arguments.
setup([setup_mode])Set the model settings up.
setup_grid([setup_mode])Set the grid object up.
Set the model settings parameters up.
Construct the state vector from this model settings.
Attributes
List of custom diagnostic fields.
List of custom state fields.
The module container for all diagnostics.
The spatial grid.
Return the halo size of the model.
Return whether the model settings are set up.
The NaN checker object (default: NaNChecker).
Return a dictionary with all parameters of the model settings.
The progress bar object (default: ProgressBar).
Raise an error when something goes wrong.
The restart module.
The module container for all tendencies.
The time stepper object (default: AdamBashforth).
The timing module.
Examples using
fridom.framework.ModelSettingsBase#- model_name = 'Unnamed model'#
- set_attributes(**kwargs: dict) None[source]#
Set model settings attributes from keyword arguments.
Parameters#
- kwargsdict
Keyword arguments to set the attributes of the model settings.
Raises#
- AttributeError
The attribute does not exist in the model settings.
- setup_grid(setup_mode: Literal['default', 'forced'] = 'default') None[source]#
Set the grid object up.
- setup(setup_mode: Literal['default', 'forced'] = 'default') T[source]#
Set the model settings up.
Description#
This method will initialize the grid object and setup all modules. It must be called before accessing any attributes of the grid or modules.
Returns#
- ModelSettingsBase
The model settings object
- diagnostic_state_constructor() VectorField[source]#
Construct the diagnostic state vector from this model settings.
- property parameters: dict#
Return a dictionary with all parameters of the model settings.
Description#
This method should be overridden by the child class to return a dictionary with all parameters of the model settings. This dictionary is used to print the model settings in the __repr__ method.
- property time_stepper: None#
The time stepper object (default: AdamBashforth).
- property progress_bar: ProgressBar#
The progress bar object (default: ProgressBar).
- property nan_checker: NaNChecker#
The NaN checker object (default: NaNChecker).
- property tendencies: ModuleContainer#
The module container for all tendencies.
- property diagnostics: ModuleContainer#
The module container for all diagnostics.
- property restart_module: RestartModule#
The restart module.
- property timer: TimingModule#
The timing module.
- property raise_error_when_something_goes_wrong: bool#
Raise an error when something goes wrong.
- property is_setup: bool#
Return whether the model settings are set up.
- property halo: int#
Return the halo size of the model.
- property custom_state_fields: list[FieldMetadata]#
List of custom state fields.
- property custom_diagnostic_fields: list[FieldMetadata]#
List of custom diagnostic fields.