Models
Overview
Models in mufem represent individual simulation components. Each model may define
coefficient functions, participate in refinement, and contribute to the global system
via weak forms or conditions. Models are derived from the abstract base mufem.ModelTrait
.
All models are managed through the mufem.ModelManager
, which coordinates their
initialization, solving, and optional time stepping.
Model Manager
The mufem.ModelManager
controls the lifecycle of all models in a simulation.
Once added to the model manager, models are automatically initialized, invoked during each simulation step, and queried for residuals if applicable.
model = mufem.RefinementModel()
model_manager = sim.get_model_manager()
model_manager.add_model(model)
model_manager.initialize()
residuals = model_manager.get_residuals("refinement.RefinementModel")
[None]
Model Interface
All models must implement the following core methods from mufem.ModelTrait
:
register_coefficient_functions: Register scalar or vector fields with the coefficient manager.
initialize: Allocate spaces, load meshes, and set up internal structures.
solve: Perform one iteration step of the model (e.g. assemble, solve system).
update_time_step: Update model state after each simulation time step (for unsteady models).
Optional methods:
initialize_solution: Called before simulation begins to seed initial values.
finalize_time_step: Called after a time step is completed.
register_forms: Register weak forms for PDE assembly.
show_residual: Whether to print/log residuals from the model.
reset_conditions: Reset user-defined conditions (e.g. Dirichlet, Neumann).
Example
import mufem
sim = mufem.Simulation.New("My Case", "data/geometry.mesh", print_only_warnings=True)
model = mufem.RefinementModel()
model_manager = sim.get_model_manager()
model_manager.add_model(model)
model_manager.initialize()
print(model_manager.list_models())
['mufem.Models.RefinementModel']