Modelica is a language for modeling of physical systems, designed to support effective library development and model exchange. It is a modern language built on acausal modeling with mathematical equations and object-oriented constructs to facilitate reuse of modeling knowledge.
The semantics of the Modelica language is specified by means of a set of rules for translating any class described in the Modelica language to a flat Modelica structure. The semantic specification should be read together with the Modelica grammar.
A class (of specialized class model, class or block) intended to be simulated on its own is called a simulation model.
The flat Modelica structure is also defined for other cases than simulation models; including functions (can be used to provide algorithmic contents), packages (used as a structuring mechanism), and partial models (used as base-models). This allows correctness to be verified for those classes, before using them to build the simulation model.
There are specific semantic restrictions for a simulation model to ensure that the model is complete; they allow its flat Modelica structure to be further transformed into a set of differential, algebraic and discrete equations (= flat hybrid DAE). Note that satisfying the semantic restrictions does not guarantee that the model can be initialized from the initial conditions and simulated.
Modelica was designed to facilitate symbolic transformations of models, especially by mapping basically every Modelica language construct to equations in the flat Modelica structure. Many Modelica models, especially in the associated Modelica Standard Library, are higher index systems, and can only be reasonably simulated if symbolic index reduction is performed, i.e., equations are differentiated and appropriate variables are selected as states, so that the resulting system of equations can be transformed to state space form (at least locally numerically), i.e., a hybrid DAE of index zero. In order to allow this structural analysis, a tool may reject simulating a model if parameters cannot be evaluated during translation – due to calls of external functions or initial equations/initial algorithms for fixed = false parameters. Accepting such models is a quality of implementation issue. The Modelica specification does not define how to simulate a model. However, it defines a set of equations that the simulation result should satisfy as well as possible.
The key issues of the translation (or flattening) are:
Expansion of inherited base classes
Parameterization of base classes, local classes and components
Generation of connection equations from connect-equations
The flat hybrid DAE form consists of:
Declarations of variables with the appropriate basic types, prefixes and attributes, such as parameter Real v=5.
Equations from equation sections.
Function invocations where an invocation is treated as a set of equations which involves all input and all result variables (number of equations = number of basic result variables).
Algorithm sections where every section is treated as a set of equations which involves the variables occurring in the algorithm section (number of equations = number of different assigned variables).
The when-clauses where every when-clause is treated as a set of conditionally evaluated equations, which are functions of the variables occurring in the clause (number of equations = number of different assigned variables).
Therefore, a flat hybrid DAE is seen as a set of equations where some of the equations are only conditionally evaluated. Initial setup of the model is specified using start-attributes and equations that hold only during initialization.
A Modelica class may also contain annotations, i.e. formal comments, which specify graphical representations of the class (icon and diagram), documentation text for the class, and version information.
Explanations of many terms can be found using the document index in Modelica^{®} Language Specification version 3.6-dev. Some important terms are defined below.
An element defined by the production component-clause in the Modelica grammar (basically a variable or an instance of a class) ∎
Class definition, extends-clause, or component-clause declared in a class (basically a class reference or a component in a declaration). ∎
The translation of a model described in Modelica to the corresponding model described as a hybrid DAE, involving expansion of inherited base classes, parameterization of base classes, local classes and components, and generation of connection equations from connect-equations (basically, mapping the hierarchical structure of a model into a set of differential, algebraic and discrete equations together with the corresponding variable declarations and function definitions from the model). ∎
The remainder of this section shows examples of the presentation used in this document.
Syntax highlighting of Modelica code is illustrated by the code listing below. Things to note include keywords that define code structure such as equation, keywords that do not define code structure such as connect, and recognized identifiers with meaning defined by the specification such as semiLinear:
Relying on implicit conversion of Integer literals to Real is common, as seen in the equation above (note use of Modelica code appearing inline in the text).
It is common to mix Modelica code with mathematical notation. For example, average($\colorbox[rgb]{1,1,1}{$x$}$, $\colorbox[rgb]{1,1,1}{$y$}$) could be defined as $\frac{x+y}{2}$.
Text defining the meaning of something. ∎
In addition to the style of definition above, new terminology can be introduced in the running text. For example, a dummy is something that…
[This is non-normative content that provides some explanation, motivation, and/or additional things to keep in mind. It has no defining power and may be skipped by readers strictly interested in just the definition of the Modelica language.]
[Example: This is an example, which is a special kind of non-normative content. Examples often contain a mix of code listings and explanatory text, and this is no exception:
To fix the type mismatch above, the number has to be replaced by a String expression, such as "1.0".]
Other code listings in the document include specification of lexical units and grammatical structure, both using metasymbols of the extended BNF-grammar defined in section A.1. Lexical units are named with all upper-case letters and introduced with the ‘=’ sign:
Grammatical structure is recognized by production rules being named with lower-case letters and introduced with the ‘:’ sign (also note appearance of the Modelica keyword der):