Hybrid Simulation Safety: Limbos and Zero Crossings

David Broman

Abstract

Hybrid simulations of cyber-physical systems often suffer from "untrapped" errors—silent failures that produce physically impossible results without alerting the user. This paper introduces the Limbo State framework, a conceptual model for simulators to detect and resolve such errors. By distinguishing between safe, limbo, and unsafe states, we propose methods for safety-augmented zero-crossing detection and deterministic event handling. Implementations in Modelica and Ptolemy II demonstrate how this approach prevents common artifacts like object tunneling and accidental determinism in simultaneous events.

Introduction

The reliability of a simulation is typically measured by its fidelity to the physical world. However, for safety-critical Cyber-Physical Systems (CPS), fidelity alone is insufficient; the simulation environment itself must be "safe." Borrowing from programming language theory, a safe simulation is one where all errors are "trapped" (detected and reported) rather than "untrapped" (silent failures). This paper addresses two major untrapped errors: unsafe zero-crossing detection and accidental determinism.

The Problem: Untrapped Errors in Hybrid Systems

Hybrid simulators use zero-crossing detection to trigger discrete events. Numerical imprecision can lead to Unsafe Zero-Crossing Detection, where an event is missed because the signal magnitude falls below the simulator's tolerance. As shown in Figure 1, this causes a bouncing ball to "tunnel" through the ground.

Figure 1: Numerical imprecision in a bouncing ball simulation leads to "tunneling," where the ball passes through the ground due to numerical tolerance issues in zero-crossing detection.

Another issue is Accidental Determinism, which occurs when simultaneous events are resolved in an arbitrary order by the simulator. This produces repeatable but physically inconsistent results, masking the underlying ambiguity of the model.

Methods: The Limbo State Framework

We propose modeling the simulator as a finite state machine with a Limbo State. This state represents a "gray area" where the simulator detects a potential error or ambiguity before it leads to an invalid result.

Three-Level Zero-Crossing

Instead of a single zero-crossing line, we implement a three-level system: Safe, Limbo, and Unsafe. If the system enters the Limbo region (e.g., a very low bounce height), the modeler can define a safe exit, such as transitioning the ball to a resting state. Crossing into the Unsafe region triggers an immediate trapped error.

Deterministic Event Handling

When multiple events occur within a numerical tolerance of each other, the simulator enters Limbo. The modeler must explicitly define how to handle these simultaneous cases (e.g., using an elsewhen construct). If no logic is provided, the simulator throws an error rather than making an arbitrary choice.

Results and Discussion

The framework was evaluated using the Three-Ball Elastic Collision model. As illustrated in Figure 3, different event orderings in simultaneous collisions can lead to wildly divergent trajectories. By requiring explicit resolution, the Limbo State framework ensures that simulation outcomes are physically grounded and intentional.

Figure 3: Different simulation outcomes for a three-ball elastic collision demonstrate "accidental determinism," where arbitrary event ordering leads to divergent physical behaviors.

Successful implementations were demonstrated in Modelica and Ptolemy II. In Modelica, safety-augmented models correctly transitioned to stable states or terminated with errors instead of tunneling. In Ptolemy II, a custom "Safe Level-Crossing Detector" actor enabled robust mode changes upon detecting potential failures.

Conclusion and Future Work

The Limbo State framework transforms silent simulation failures into manageable, trapped errors. Future work should explore automating these safety checks within modeling languages via language extensions or static analysis to detect missing event handlers before simulation starts.

Summary updated

Abstract

Physical systems can be naturally modeled by combining continuous and discrete models. Such hybrid models may simplify the modeling task of complex system, as well as increase simulation performance. Moreover, modern simulation engines can often efficiently generate simulation traces, but how do we know that the simulation results are correct? If we detect an error, is the error in the model or in the simulation itself? This paper discusses the problem of simulation safety, with the focus on hybrid modeling and simulation. In particular, two key aspects are studied: safe zero-crossing detection and deterministic hybrid event handling. The problems and solutions are discussed and partially implemented in Modelica and Ptolemy II.
BibTeX
@inproceedings{broman2018hybrid,
  author = {David Broman},
  title = {{Hybrid Simulation Safety: Limbos and Zero Crossings}},
  booktitle = {Principles of Modeling},
  year = {2018},
  doi = {10.1007/978-3-319-95246-8\_7},
}

Loading related content...

Figure