Advanced Modelica language topics > The Modelica compiler
Compilation stages
compilation
Simcenter Amesim's Modelica compiler performs the process of converting a Modelica model (.mo file) into a Simcenter Amesim submodel (.c file) in several stages with a FMU generation in the loop, as shown in figure equations Figure 33.
Figure 33: Flowchart of the compilation process
In the first stage, the raw Modelica source code is run through the translator. In this stage, the translator parses and checks the model (e.g., checking for syntax errors, checking for undeclared elements, type matching in function calls and equations, checking for respect of restrictions on Modelica constructs, etc.). Next, it elaborates the system of equations:
structural parameters (i.e., parameters that affect the shape of the model) are looked up and corresponding reductions are performed,
all classes and structures that require flattening are flattened, and,
connection equations are expanded.
During this flattening step some errors can also be detected (e.g., array dimensions mismatch or missing inner declarations). The result of this stage is referred to as a flat Modelica "flat" Modelica model, in that it only consists of a simple set of declarations and equations.
The second stage passes the translated model to the Optimica Compiler Toolkit from Modelon®, which constructs a constrained data flow representation of the model. During this stage, a state reduction is performed when appropriate. The set of equations required to solve the initialization problem is constructed. The Optimica Compiler Toolkit from Modelon® generates then a FMU package, for Model-Exchange, where the model is explicited using its own internal mechanisms.
The final stage of compilation is where the FMI import compiler is invoked to produce C code generation C code that generates an interface in the form of a native Simcenter Amesim submodel.
In this way, Modelica models can be simulated along with native Simcenter Amesim submodels. When all three stages are completed, the compiler has successfully transformed a mathematical model originally declared in the Modelica code into C code that can be simulated by Simcenter Amesim’s solvers in order to generate the time varying profiles of all variables in the model.
Source: https://docs.sw.siemens.com/en-US/doc/254352342/PL20250521841123434.amesim_collection.Modelica_Platform/Compilation_stages · retrieved 2026-07-17