Search code examples
modelicadymola

What does "class" mean in Modelica?


I do not understand the meaning of class in Modelica context.

From the Modelica Tutorial, version 1.4 on https://modelica.org/publications.html:

In Modelica, the basic structuring element is a class. There are seven restricted classes with specific names, such as model...". Anyone have a simpler explanation? I am very new to Modelica.


Solution

  • If you open the Modelica library in a tool like Dymola or OpenModelica, everything you see in the package or library browser are classes.

    As soon as you use one of these classes, e.g. with drag and drop in the diagram layer, you create a new component of this class type. The instantiated component is not a copy of the class, but a reference to it. Therefore, if you update the class definition, you also update the behavior of all components that are instances of this class.

    There are several kinds of classes available. The most general class is actually called class, but it’s not used very often. It has no restrictions, so it can contain everything that is possible with Modelica: equations, algorithms, public and protected components, etc.

    There are more specific class types, which restrict the usage. This helps to make correct use of a class. A function or a record for example cannot be simulated.

    The most important restricted class types are:

    • package: used to group other classes
    • model: typically used for components with physical connectors and for examples which are simulated
    • block: used for components with causal connectors (only inputs and outputs, so everything you have in Modelica.Blocks)
    • function: used for function calls, comparable to other programming languages
    • record: often used to contain data sets for other components (which allows to quickly change a complete data set)
    • connector: used to define the interface variables which are needed to connect different components of a domain (e.g. v and i in the electric domain)
    • type: typically used to define physical quantities like mass, length or time with their unit (e.g. all units in the package Modelica.Units)

    More information can be found in chapter 4.6 of the Modelica specification: Specialized Classes