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.
After you add a model to the manager, it initializes automatically. The manager then invokes it at each step and queries it for residuals.
model = mufem.RefinementModel()
model_manager = sim.get_model_manager()
model_manager.add_model(model)
model_manager.initialize()
residuals = model_manager.get_residuals("refinement.RefinementModel")
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 (for example assemble and solve the 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: Indicates whether to print/log residuals from the model.reset_conditions: Reset user-defined conditions (for example Dirichlet or Neumann).