Skip to content

Simulation Clock Advancement Modes

Maggie Sullivan edited this page Jun 20, 2023 · 10 revisions

When interacting with simulation, there are two clocks to consider: real-world and simulated. All modeled output values available via Alfalfa reflect the state of the simulation at the current simulation time, which advances with a fixed timestep of one minute. For many applications, the relationship between real and simulated time is crucial. An example is hardware-in-the-loop experimentation: hardware is bound to real-world time and therefor the simulated aspects of the experiment must also remain synced to real time.

On starting a run, Alfalfa has 3 settings available that impact the rate at which the simulation clock advances: timescale, externalClock, and realtime. These modes are described below.

Advance via an external clock

  1. In this scenario, the model will only advance when explicitly told to advance by an external call. It has no regard for real time passing but sits in an idle state until told to advance. The simulation will advance non-interactively to the specified start time and then wait for an API call to advance.
  2. Upon call to advance, Alfalfa will look for any points written from external sources, write these into the simulation, and advance the simulation one time step (1-minute in model time).
  3. It then waits to advance until the next call is made.
  4. It will stop if the model has advanced enough times such that the end datetime has passed or if it is specifically told to stop.

Advance at a specified timescale

  1. In this scenario, the timescale parameter is used to control the rate at which the internal clock advances through the simulation. It represents the integer ratio of model_time:real_time. For example, a value of 5 means that the simulation will advance at 5x the rate of real time. In other words, the simulation advance one minute for every 12 seconds of real time.
  2. The simulation will advance non-interactively to the configured start time and then begin running at the configured timescale.
  3. Upon reaching the time to advance (every 12 real-world seconds in the above example), Alfalfa will look for any points from external sources, write these into the simulation, and advance the simulation one time step (1-minute in model time).
  4. It then waits X time in real time before advancing through the next time step.
  5. It will proceed until it has reached the specified end datetime or until it is specifically told to stop.
  6. In some cases, the simulation may not be able to advance quickly enough to achieve the configured timescale. For a timescale of 5, this would be the case if the simulation takes more than 12 seconds to advance. If the simulation falls more than 2 timesteps behind it will throw an error and kill the simulation. The real-world time required to advance a model one time step depends on the complexity of the model and the compute resources allocated to the Alfalfa worker.

Advance in real time

  1. This scenario is similar to the timescale with the following caveats.
  2. The timescale parameter is always one (i.e. the model advances one minute in model time for every one minute that passes in real time).
  3. It will then proceed until it has reached the specified end datetime or if it is specifically told to stop.
  4. All external calls to advance the simulation are ignored.

Model Configuration

Openstudio

Tutorials

Guides

Reference

Modelica

Guides

Alfalfa Interaction

Tutorials

Guides

Reference

Explanation

Alfalfa Development

Guides

General

Reference

Explanation

Clone this wiki locally