﻿# FMI Event Mode: finish discrete iteration before returning to time advancement

Follow FMI discreteStatesNeedUpdate, termination and continuous-state changes instead of treating a single event update call as settled model state.

Author: Retrivium team
Updated: 2026-11-06
Canonical URL: https://retrivium.ai/journal/simulation-fmi-event-mode-discrete-iteration-exit/
Language: en

## An event can need more than a callback

A hybrid twin changes a switching condition and immediately publishes the first returned discrete state as its settled observation. An FMU may still require another event iteration at the same real time. The importer has confused a completed function call with completion of the event protocol. Define the observation boundary around settled event handling, especially when switches alter other conditions or reinitialize continuous states before the next integration segment.

## Scope Event Mode to the actual interface

The [specification](https://fmi-standard.org/docs/3.0.2/) defines Event Mode for Model Exchange and for Co-Simulation using that mode; it is unavailable in Scheduled Execution. Do not impose a generic event loop on every FMI interface. Establish the instantiated interface and supported event contract first. In a supported Event Mode, equations and active partitions participate in event handling, and the importer must follow the protocol rather than resume time advancement after an arbitrary callback count.

## Read every returned decision

The [discrete-update declaration](https://raw.githubusercontent.com/modelica/fmi-standard/v3.0.2/headers/fmi3FunctionTypes.h) separates the need for another iteration from termination, changed continuous values, changed nominals and future event time. A true discreteStatesNeedUpdate requires remaining in Event Mode for another event iteration. A termination request requires a stopping decision. For Model Exchange, changed continuous states must be retrieved so the external integrator does not continue from obsolete values. Do not reduce these independent outputs to a generic success boolean.

## Propose a cascading-switch fixture

A proposed fixture should use a model whose event can cause a further discrete change and, separately, a continuous-state reinitialization. Preserve the sequence of update flags and the state read back before returning to continuous integration or Step Mode. Confirm that a report marked post-event is emitted only at the declared settled boundary. No FMU event experiment was executed here; the fixture describes a discriminating check rather than a claimed reproduction.

## A guard against nonconvergence is not convergence

The importer needs an explicit failure policy if event iteration does not settle. A watchdog can prevent an endless computation, but reaching its limit must not be reported as a converged event. Keep the last flags, model identity and termination reason for diagnosis. Likewise, a reported future event time is meaningful only when its validity flag is set; stale scheduling information should not override a newer event decision from the FMU.

## Keep the event boundary separate from task success

The [CALVIN state-carryover guide](/journal/fg2-calvin-chain-prefix-success-environment-state-carryover/) discusses another simulation boundary; [stack reproducibility](/journal/software-stack-reproducibility/) helps retain importer behavior. Here acceptance establishes that a supported event protocol reaches its declared exit. It does not validate switching thresholds, real-plant behavior or controller success. Those questions should be evaluated after post-event observations refer to a defined state rather than an unfinished discrete iteration.
