Modelica


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 1360 generic model components and 1280 functions in various domains, as of version 3.2.1.

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
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,
Equations do not describe assignment but equality. In Modelica terms, equations have no pre-defined causality. The simulation engine may 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. In September 1997, version 1.0 of the Modelica specification was released which was the basis for a prototype implementation within the commercial Dymola software system. In year 2000, the non-profit Modelica Association was formed to manage the continually evolving Modelica language and the development of the free Modelica Standard Library. In the same year, the usage of Modelica in industrial applications started.
This table presents the timeline of the Modelica specification history:
ReleaseRelease DateHighlights
1.01997, SeptemberFirst version to model continuous dynamic systems.
1.11998, DecemberLanguage elements to model discrete systems
1.21999, JuneInterface to C and Fortran, inner/outer for global variables, refined semantics of event handling
1.31999, DecemberImproved semantics for inner/outer connections, protected elements, array expressions.
1.42000, DecemberRemoved declare-before-use rule, refined package concept, refined when-clause
2.02002, JulyInitialization of models, standardization of graphical appearance, functions with mixed positional and named arguments, record constructor, enumerations
2.12004, MarchOverdetermined connector to model 3-dim. mechanical systems, enhanced redeclaration of submodels, array and array indices of enumerations
2.22005, FebruaryExpandable connector to model signal buses, conditional component declarations, arrays with dynamic size changes in functions
3.02007, SeptemberClean-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.12009, MayStream connector to handle bi-directional flow of fluid, operator overloading, mapping model parts to execution environments
3.22010, MarchImproved initialization with homotopy method, functions as formal inputs to functions, Unicode support, access control to protect IP, improved support of object libraries
3.32012, MayAdded language elements to describe periodic and non-periodic synchronous controllers based on clocked equations, as well as synchronous state machines.
3.42017, AprilAutomatic conversion of models. Many minor improvements

Implementations

Commercial front-ends for Modelica include AMESim from the French company Imagine SA, Dymola from the Swedish company Dynasim AB, CyModelica from the American company CyDesign Labs now ESI Group, Wolfram SystemModeler from the Swedish company Wolfram MathCore AB, SimulationX from the German company ESI ITI GmbH, MapleSim from the Canadian company Maplesoft, and
CATIA Systems
from Dassault Systemes.
JModelica.org is an extensible Modelica-based open source platform for optimization, simulation and analysis of complex dynamic systems. The main objective of the project is to create an industrially viable open source platform for simulation optimization of Modelica models, while offering a flexible platform serving as a virtual lab for algorithm development and research.
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. 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
:

model FirstOrder
parameter Real c=1 "Time constant";
Real x "An unknown";
equation
der = -c*x "A first order differential equation";
end FirstOrder;

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 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:

type Voltage = Real;
type Current = Real;
...

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

connector Pin "Electrical pin"
Voltage v "Potential at the pin";
flow Current i "Current flowing into the component";
end Pin;

When drawing connection lines between ports, the meaning is that corresponding connector variables without the "flow" prefix are identical and that corresponding connector variables with the "flow" prefix are defined by a zero-sum equation. 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 :

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 = pin_p.i;
end Capacitor;

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
in section 4.7.
However, for most cases, a simple rule can be issued, that counts variables and equations the same way as most simulation tools do:

A model is balanced when the number of its equations
equals the number of its variables.

given that variables and equations must be counted according to the following rule:

->Number of model equations =
Number of equations defined in the model +
number of flow variables in the outside connectors
->Number of model variables = Number of variables defined in the model


Note that standard input connectors do not contribute to the count of variables since no new variables are defined inside them.
The reason for this rule can be understood thinking of the capacitor defined above. Its pins contain a flow variable, i.e. a current, each. When we check it, it is connected to nothing. This corresponds to set an equation pin.i=0 for each pin. That's why we must add an equation for each flow variable.
Obviously the example can be extended to other cases, in which other kinds of flow variables are involved.
When our capacitor is connected to another model through one of its pins, a connection equation will be generated that will substitute the two i=0 equations of the pins being connected. Since the connection equation corresponds to two scalar equations, the connection operation will leave the balanced larger model.
The Capacitor model above is balanced, since

number of equations = 3+2=5
number of variables = 5

Verification using OpenModelica of this model gives, in fact

Class Capacitor has 5 equation and 5 variable.
3 of these are trivial equation.

Another example, containing both input connectors and physical connectors is the following component from Modelica Standard Library:

model SignalVoltage
"Generic voltage source using the input signal as source voltage"
Interfaces.PositivePin p;
Interfaces.NegativePin n;
Modelica.Blocks.Interfaces.RealInput v
"Voltage between pin p and n as input signal";
SI.Current i "Current flowing from pin p to pin n";
equation
v = p.v - n.v;
0 = p.i + n.i;
i = p.i;
end SignalVoltage;

The component SignalVoltage is balanced since

number of equations = 3+2=5
number of variables = 5

Again, checking with OpenModelica gives

Class Modelica.Electrical.Analog.Sources.SignalVoltage has 5 equation and 5 variable.
4 of these are trivial equation.

Hierarchical models

A hierarchical model is built-up from basic models, by instantiating basic models, providing suitable values for the model parameters, and by connecting model connectors. A typical example is the following electrical circuit:

model Circuit
Capacitor C1 "A Capacitor instance from the model above";
Capacitor C2 "A Capacitor instance from the model above";
...
equation
connect;
...
end Circuit;

Via the language element annotation, definitions can be added to a model that do not have an influence on a simulation. Annotations are used to define graphical layout, documentation and version information. A basic set of graphical annotations is standardized to ensure that the graphical appearance and layout of models in different Modelica tools is the same.
The freely available book "" contains many more examples like these along with detailed
explanations for nearly all the language features in Modelica version 3.3.

Applications

Modelica is designed to be domain neutral and, as a result, is used in a wide variety of applications, such as fluid systems, automotive applications and mechanical systems.
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 make it well suited to system-level simulation, a domain where Modelica is now well established.