Skip to content

Model container

The model container is the core object that holds and runs a full ERS simulation. It manages a set of simulators, handles their dependencies, and coordinates execution.

Each simulator in a model container owns one submodel, which holds the simulation data. The model container is responsible for updating all simulators in the correct order and resolving event scheduling between them.

Responsibilities

  • Group simulators into a single simulation.
  • Handle sync-events between simulators.
  • Execute the complete model step-by-step.
  • Manage simulation time.

Lifecycle

  1. Create the model container
  2. Add simulators
  3. Define dependencies (optional)
  4. Start the simulation
  5. Run updates

After starting the model container, no new simulators can be added or removed, and dependencies cannot be created or removed.

Adding simulators

Each simulator is added by name and formalism. Once added, it is assigned a unique ID within the container. Each simulator also automatically creates and owns a submodel for its internal data.

Simulators can be connected using dependencies, which define how and when events can be scheduled between them.

Sync and execution

When the model container is updated, it steps each simulator. ERS ensures that each simulator is run on one thread at a time, even in parallel setups. Sync-events between simulators are managed through declared dependencies.

Simulators with dependencies are executed in an order that respects data flow and timing promises, ensuring consistent causal behavior across the model.

Time management

The model container tracks global simulation time. Each update step advances the simulation by a fixed time step. All simulators are stepped together during this process.

You can query the current time using GetCurrentTime() or check whether the simulation has started with IsStarted().

Model precision

The model precision defines the smallest time unit in your simulation and is set on the model container. Note that model precision must be set before adding any simulators.

Ers::ModelContainer model = Ers::ModelContainer::Create();

// Set model precision (must be done before adding simulators)
// Default is 1,000,000 (microseconds when using seconds as base unit)
model.SetPrecision(1'000'000);
ModelContainer model = ModelContainer.Create();

// Set model precision (must be done before adding simulators)
// Default is 1,000,000 (microseconds when using seconds as base unit)
model.Precision = 1_000_000;

Example

using Ers;

// Create a new model container
ModelContainer container = ModelContainer.Create();
container.Precision = 1_000_000;

// Add simulators
Simulator simA = model.AddSimulator("A", SimulatorType.DiscreteEvent);
Simulator simB = model.AddSimulator("B", SimulatorType.DiscreteEvent);

// Define dependencies
container.AddSimulatorDependency(simA, simB); // A can send events to B

// Start the simulation
container.Start();

// Step forward 100 seconds (100 * 1,000,000 time units)
container.Update(100 * container.Precision);

Summary

The model container is the entry point to building and running ERS simulations. It manages simulators, handles execution flow, and ensures proper synchronization. Always finalize your model setup before starting it, as the structure becomes locked once the simulation is started.

Was this page helpful?