1. Introduction to models

Modelica and Optimica models can be compiled and loaded as model objects using the JModelica.org Python interface. These model objects can be used for both simulation and optimization purposes. This chapter will cover how to compile Modelica and Optimica models, set compiler options, load the compiled model in a Python model object and use the model object to perform model manipulations such as setting and getting parameters.

1.1. The different model objects in JModelica.org

There are several different kinds of model objects that can be created with JModelica.org: FMUModel(ME/CS)(1/2) and OptimizationProblem. The FMUModel(ME/CS)(1/2) is created by loading an FMU (Functional Mock-up Unit), which is a compressed file compliant with the FMI (Functional Mock-up Interface) standard. The OptimizationProblem is created by transferring an optimization problem into the CasADi-based optimization tool chain.

FMUs are created by compiling Modelica models with JModelica.org, or any other tool supporting FMU export. JModelica.org supports both export and import of FMUs for Model Exchange (FMU-ME) and FMUs for Co-Simulation (FMU-CS), version 1.0 and 2.0. Generated FMUs can be loaded in an FMUModel(ME/CS)1 object in Python and then be used for simulation purposes. Optimica models can not be compiled into FMUs.

OptimizationProblem objects for CasADi optimization do not currently have a corresponding file format, but are transferred directly from the JModelica.org compiler, based on Modelica and Optimica models. They contain a symbolic representation of the optimization problem, which is used with the automatic differentiation tool CasADi for optimization purposes. Read more about CasADi and how a OptimizationProblem object can be used for optimization in Section 5, “Dynamic optimization of DAEs using direct collocation with CasADi” in Chapter 6, Optimization.