Event Support for Simulation and Sensitivity Analysis in CasADi for use with Modelica and FMI
CasADi is an open-source framework that can be used to efficiently solve optimization problems involving user-defined ODE/DAE models. Supported solution methods include so-called shooting methods, where solvers for initial-value problems in ODEs or DAEs are referenced inside nonlinear programming (NLP) formulations. In order to solve such NLP formulations with gradient-based algorithms, CasADi implements a fully automatic sensitivity analysis. This analysis includes forward sensitivity analysis, adjoint sensitivity analysis as well as the calculation of higher-order sensitivities for the ODE/DAE models. Because of the variational (differentiate-then-integrate) approach used, the numerical solution can be performed with variable-step size, variable-order integrators such as those from the SUNDIALS suite.In this work, we present a generalization of the sensitivity analysis support in CasADi to systems with events, as are common in real-world cyber-physical models. In particular, the event extension enables us to formulate and solve optimization problems with such event systems, without a priori knowledge of the number and ordering of events. Ultimately, we expect the proposed approach to be compatible with general cyber-physical models formulated in Modelica or available as model-exchange FMUs.We demonstrate the proposed approach for two proof-of-concept examples; the classical bouncing ball written in CasADi directly and a simple hybrid DAE describing a breaking spring formulated in Modelica and imported symbolically into CasADi. In the examples, we show that the forward sensitivities calculated to high precision using the proposed approach are consistent with a cruder finite-difference approximation and provide an example of how they can be embedded into optimization formulations. We discuss how the approach can be extended to handle standard FMUs, adhering to FMI 2 or FMI 3, as well as non-trivial Modelica models imported via a symbolic interface based on the emerging Base Modelica standard.
Authors
- James Goppert (ORCID: https://orcid.org/0000-0002-2044-4931)
- Joel Andersson (ORCID: https://orcid.org/0000-0003-2530-0520)
Institutions
- Software and Engineering Associates (United States) (US)
- American Institute of Aeronautics and Astronautics (US)
Publication Details
- Journal
- Linköping electronic conference proceedings
- Published
- 2025-01-16
- DOI
- https://doi.org/10.3384/ecp20799
- Primary Topic
- Modeling and Simulation Systems
- Type
- article
- Field-Weighted Citation Impact
- 0.00
Funders
- Defense Advanced Research Projects Agency