Skip to content

Simulation

Introduction

Simulation is the top-level object of a mufem analysis. It owns the geometry, the physics models, and the runner that drives execution. It also owns the supporting managers. These managers query coefficients, collect reports, monitor metrics, and export fields.

You create a simulation with the Simulation.New factory. Then you configure it with a runner and one or more models, and run it with run().

Creating a Simulation

import mufem

sim = mufem.Simulation.New("My Example", "data/geometry.mesh")

Simulation.New accepts:

Parameter Description
name Display name of the simulation.
mesh_path Optional path to the mesh file. If omitted, load the mesh later via sim.get_domain().load_mesh(...).

Lifecycle

A simulation runs in three phases:

  1. Initializationsim.initialize() prepares the domain, models, materials, and the initial solution. sim.run() calls it automatically, so you rarely call it directly.
  2. Runsim.run() hands control to the configured runner, which advances the simulation until it completes.
  3. Resetsim.reset() returns the runner to its starting state so you can replay the simulation.

Accessors

The simulation exposes the managers that hold the rest of the state:

Method Returns
get_domain() The computational domain (mesh, regions).
get_model_manager() Registry of the active physics models.
get_coefficient_manager() Coefficient functions available as inputs to models.
get_report_manager() Reports collected during the run.
get_monitor_manager() Monitors emitted during the run.
get_field_exporter() Field exporter for visualization output.
get_runner() The currently configured runner.
get_machine() Machine context (e.g. MPI process information).
get_name() The simulation name.

Lifecycle Events

Components attach callbacks to Event instances so that work runs at well-defined points in the simulation lifecycle. The most common use configures the field exporter to write at run completion (see Runners and the field exporter documentation).

The built-in events are:

Event Fires
Event.Initialization Once after sim.initialize() completes.
Event.RunCompletion Once when the runner's main loop finishes.
Event.TimeStep At the end of each time step (unsteady runs).
Event.Iteration At the end of each inner iteration.

Two policies are available to thin out a stream of events:

# Fire on every 10th time step.
every_ten = mufem.Event.TimeStep(10)

# Fire when the simulation passes specific times.
checkpoints = mufem.Event.AtTimes([0.1, 0.5, 1.0])

Example

import mufem

sim = mufem.Simulation.New("My Example", "data/geometry.mesh")

runner = mufem.SteadyRunner(total_iterations=3)
sim.set_runner(runner)

# Configure models, materials, exports here ...

sim.run()