Models¶
Introduction¶
Models in mufem represent individual simulation components.
Each model can define coefficient functions, participate in refinement, and
contribute to the global system with weak forms or conditions.
Each model derives from the abstract base mufem.ModelTrait.
The mufem.ModelManager manages all models. It coordinates their
initialization, solving, and optional time stepping.
Model Manager¶
The mufem.ModelManager controls the lifecycle of all models in a simulation.
You add a model to the manager with add_model. The manager does not initialize
the model at once. The simulation initializes all models when you call
sim.run() or sim.initialize(). The manager then calls the models at each
step and collects their residuals.
model = mufem.RefinementModel()
model_manager = sim.get_model_manager()
model_manager.add_model(model)
sim.set_runner(mufem.SteadyRunner(total_iterations=1))
sim.run()
residuals = model_manager.get_residuals()
| Method | Description |
|---|---|
add_model(model) | Add a model. If you add the same model again, the manager ignores it. |
list_models() | Display names (get_model_name()) of the registered models. |
get_model(model_name) | The model with the given internal name (get_name()). |
get_residuals() | Dictionary from the display name of each model to its list of residuals. Models that do not show residuals are not included. |
get_model_residuals(model_name) | List of residuals of the model with the given internal name (get_name()). |
Note
ModelManager.initialize() is not available in the Python interface.
Use sim.initialize() instead. This also initializes the runner and
fires Event.Initialization.
Model Interface¶
Each model class in Python derives from mufem.ModelTrait and has these
methods:
get_name(): The internal name of the model.get_model_name(): The name of the model that mufem shows in the log.is_initialized():Trueafter the simulation initialized the model.
The models implement the steps below in C++. mufem calls them. You do not call them from Python:
- Register the coefficient functions of the model with the coefficient manager.
- Initialize: allocate the spaces and set up the internal data.
- Solve: do one iteration step (for example, assemble and solve the system).
- Update the model state after each time step (unsteady models).
- Optional: seed the initial solution, finalize a time step, register weak forms, and reset the conditions.