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.
There are three different kinds of model objects that can be created with JModelica.org:
FMUModel(ME/CS)1 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
JMUModel is created by loading a JMU, which is a compressed file with a JModelica.org specific structure. 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 RC2. 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.
JMUs are created by compiling Modelica or Optimica models with JModelica.org. The JMU can then be loaded in a
JMUModel object in Python and used for optimization purposes.
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 6, “Dynamic optimization of DAEs using direct collocation with CasADi” in Chapter 7, Optimization.