Modelica is an object-oriented, declarative, multi-domain modeling language for component-oriented modeling of complex systems, e.g., systems containing mechanical, electrical, electronic, hydraulic, thermal, control, electric power or process-oriented subcomponents.

The free Modelica language

is developed by the non-profit Modelica Association. The Modelica Association also develops the free Modelica Standard Library that contains about 1400 generic model components and 1200 functions in various domains, as of version 4.0.0.

Characteristics

While Modelica resembles object-oriented programming languages, such as C++ or Java, it differs in two important respects. First, Modelica is a modeling language rather than a conventional programming language. Modelica classes are not compiled in the usual sense, but they are translated into objects which are then exercised by a simulation engine. The simulation engine is not specified by the language, although certain required capabilities are outlined.

Second, although classes may contain algorithmic components similar to statements or blocks in programming languages, their primary content is a set of equations. In contrast to a typical assignment statement, such as

: <syntaxhighlight inline lang=modelica>x := 2 + y;</syntaxhighlight>

where the left-hand side of the statement is assigned a value calculated from the expression on the right-hand side, an equation may have expressions on both its right- and left-hand sides, for example,

: <syntaxhighlight inline lang=modelica>x + y = 3 * z;</syntaxhighlight>

Equations do not describe assignment but equality. In Modelica terms, equations have no pre-defined causality. The simulation engine may (and usually must) manipulate the equations symbolically to determine their order of execution and which components in the equation are inputs and which are outputs.

History

The Modelica design effort was initiated in September 1996 by Hilding Elmqvist.

The goal was to develop an object-oriented language for modeling

of technical systems in order to reuse and exchange dynamic system models in

a standardized format. Modelica 1.0 is based on the

PhD thesis of Hilding Elmqvist and on the experience with the modeling languages Allan,

Dymola, NMF

ObjectMath,

Omola,

SIDOPS+, and Smile. Hilding Elmqvist is the key architect of Modelica, but many other people have contributed as well (see appendix E in the Modelica specification

{| class="wikitable"

|-

!width=30| Release

!width=110| Release date

!width=550| Highlights

|-

|1.0||1997, September||First version to model continuous dynamic systems.

|-

|1.1||1998, December||Language elements to model discrete systems (pre, when)

|-

|1.2||1999, June||Interface to C and Fortran, inner/outer for global variables, refined semantics of event handling

|-

|1.3||1999, December||Improved semantics for inner/outer connections, protected elements, array expressions.

|-

|1.4||2000, December||Removed declare-before-use rule, refined package concept, refined when-clause

|-

|2.0||2002, July||Initialization of models, standardization of graphical appearance, functions with mixed positional and named arguments, record constructor, enumerations

|-

|2.1||2004, March||Overdetermined connector to model 3-dim. mechanical systems, enhanced redeclaration of submodels, array and array indices of enumerations

|-

|2.2||2005, February||Expandable connector to model signal buses, conditional component declarations, arrays with dynamic size changes in functions

|-

|3.0||2007, September||Clean-up version: specification newly written, type system and graphical appearance refined, language flaws fixed, balanced model concept to detect model errors in a much better way

|-

|3.1||2009, May||Stream connector to handle bi-directional flow of fluid, operator overloading, mapping model parts to execution environments (for use in embedded systems)

|-

|3.2||2010, March||Improved initialization with homotopy method, functions as formal inputs to functions, Unicode support, access control to protect IP, improved support of object libraries

|-

|3.3||2012, May||Added language elements to describe periodic and non-periodic synchronous controllers based on clocked equations, as well as synchronous state machines.

|-

|3.4||2017, April||Automatic conversion of models. Many minor improvements

|-

|3.5||2021, February||Annotations for predefined plots. Change of specification format, with many editorial changes. Clarifications to synchronous language elements and state machines. Many minor clarifications to functions, model conversions, and several other parts of the specification.

|-

|3.6

|2023, March

|Removing modifiers with <code>break</code> and selective model extensions. Multilingual support to present Modelica libraries in multiple languages.

|-

|}

Implementations

Commercial front-ends for Modelica include AMESim from the French company Imagine SA (now part of Siemens Digital Industries Software), Dymola from the Swedish company Dynasim AB (now part of Dassault Systèmes), Wolfram SystemModeler (formerly MathModelica) from the Swedish company Wolfram MathCore AB (now part of Wolfram Research), SimulationX from the German company ESI ITI GmbH, MapleSim from the Canadian company Maplesoft,

JModelica.org (open source, discontinued) and Modelon Impact, from the Swedish company Modelon AB, and

CATIA Systems

from Dassault Systèmes (CATIA is one of the major CAD systems).

OpenModelica is an open-source Modelica-based modeling and simulation environment intended for industrial and academic usage. Its long-term development is supported by a non-profit organization – the Open Source Modelica Consortium (OSMC). The goal with the OpenModelica effort is to create a comprehensive Open Source Modelica modeling, compilation and simulation environment based on free software distributed in binary and source code form for research, teaching, and industrial usage.

The free simulation environment Scicos uses a subset of Modelica for component modeling. Support for a larger part of the Modelica language is currently under development.

Nevertheless, there is still some incompatibility and diverging interpretation between all the different tools concerning the Modelica language.

Examples

The following code fragment shows a very simple example of a first order system

(<math>\dot x = - c \cdot x, x(0)=10 </math>):

<syntaxhighlight lang=modelica>

model FirstOrder

parameter Real c=1 "Time constant";

Real x (start=10) "An unknown";

equation

der(x) = -c*x "A first order differential equation";

end FirstOrder;

</syntaxhighlight>

The following code fragment shows an example to calculate the second derivative of a trigonometric function, using OMShell, as a means to develop the program written below.

<syntaxhighlight lang=modelica>

model second_derivative

Real l;

Real z=sin(w*time);

Real m;

parameter Real w = 1;

equation

l=der(z);

m=der(l);

end second_derivative;

</syntaxhighlight>

center|400px|caption

Interesting things to note about this example are the 'parameter' qualifier, which indicates that a given variable is time-invariant and the 'der' operator, which represents (symbolically) the time derivative of a variable. Also worth noting are the documentation strings that can be associated with declarations and equations.

The main application area of Modelica is the modeling of physical systems. The most basic structuring concepts are shown at hand of simple examples from the electrical domain:

Built-in and user derived types

Modelica has the four built-in types Real, Integer, Boolean, String. Typically, user-defined types are derived, to associate physical quantity, unit, nominal values, and other attributes:

<syntaxhighlight lang=modelica>

type Voltage = Real(quantity="ElectricalPotential", unit="V");

type Current = Real(quantity="ElectricalCurrent", unit="A");

...

</syntaxhighlight>

Connectors describing physical interaction

The interaction of a component to other components is defined by physical ports, called connectors, e.g., an electrical pin is defined as

<syntaxhighlight lang=modelica>

connector Pin "Electrical pin"

Voltage v "Potential at the pin";

flow Current i "Current flowing into the component";

end Pin;

</syntaxhighlight>

When drawing connection lines between ports, the meaning is that corresponding connector variables without the "flow" prefix are identical (here: "v") and that corresponding connector variables with the "flow" prefix (here: "i") are defined by a zero-sum equation (the sum of all corresponding "flow" variables is zero). The motivation is to automatically fulfill the relevant balance equations at the infinitesimally small connection point.

Basic model components

A basic model component is defined by a model and contains equations that describe the relationship between the connector variables in a declarative form (i.e., without specifying the calculation order):

<syntaxhighlight lang=modelica>

model Capacitor

parameter Capacitance C;

Voltage u "Voltage drop between pin_p and pin_n";

Pin pin_p, pin_n;

equation

0 = pin_p.i + pin_n.i;

u = pin_p.v - pin_n.v;

C * der(u) = pin_p.i;

end Capacitor;

</syntaxhighlight>

The goal is that a connected set of model components leads to a set of differential, algebraic and discrete equations where the number of unknowns and the number of equations is identical. In Modelica, this is achieved by requiring so called balanced models.

The full rules for defining balanced models are rather complex, and can be read from

and mechanical systems (for example, multi-body systems, mechatronics, etc.).

In the automotive sector, many of the major automotive OEMs are using Modelica. These include Ford, General Motors, Toyota, BMW, and Daimler.

Modelica is also being increasingly used for the simulation of thermo-fluid and energy systems.

The characteristics of Modelica (acausal, object-oriented, domain neutral) make it well suited to system-level simulation, a domain where Modelica is now well established.

See also

  • AMESim
  • AMPL
  • APMonitor
  • ASCEND
  • Domain-Specific Modeling DSM
  • Dymola
  • EcosimPro: Continuous and Discrete Modelling and Simulation Software
  • EMSO
  • GAMS
  • JModelica.org
  • OpenModelica
  • MapleSim
  • MATLAB
  • SimulationX
  • Simulink
  • Wolfram SystemModeler
  • Scilab/Xcos
  • Kepler (Ptolemy)

Notes

  • Modelica Language Specification Version 3.6
  • Modelica Association, the homepage of the non-profit Modelica Association (developing Modelica)
  • Modelica by Example A free interactive HTML book for learning Modelica, by Michael Tiller
  • Introduction to Physical Modeling with Modelica, book by Michael Tiller
  • Modelica Overview