Restricted Classes

1 General Description

The class concept is fundamental to Modelica, almost anything in Modelica is a class. Special keywords, replacing the word class, are used for different purposes, not changing the syntax of the structure. The keywords model, connector, record, block and type have some restrictions compared to the class keyword and they can be used in specific cases.

2 Model

The model keyword is used for modeling purposes. The only restriction is that a model may not be used in connections.

3 Record

A record is a class for specifying a record data structure. Equations are not allowed in a record at all and a record may not be used in a connection.

4 Type

The restricted class type is often used to introduce new type names. A type may be an extension to either a predefined type (e.g. Real or Integer), a record class or some kind of array.

5 Connector

Connector classes are used for communication between objects. No equations are allowed at all in a connector class. Instances of connector classes form the interface of a component (how it connects to the outer world).

6 Block

A block is a class for which the data flow direction is known for each of its variables. All variables declared in a block must have one of the prefixes input or output. A block may not be used in connections.

7 Function

The function concept in Modelica corresponds to mathematical functions without external side effects. These are the restrictions of a function:Each formal parameter of the function must be prefixed by either input or output and be public and non-constant. A function may not be used in connections, may have no equations, and can have at most one algorithm.For a function to be called, it must either have an algorithm or an external function interface as its body.A function cannot contain calls to the Modelica built-in operators, der, initial, terminal, sample, pre, edge, change, reinit, delay, cardinality, and is not allowed to contain when-statements.A subtype of a function type needs to be equivalent to the function type itself.The size of each array result or array local variable of a function must either be given by the formal parameters, or given by constant or parameter expressions.

7.1 Multiply Function Example

The function
multiply can be called from within a class:

7.2 Calling multiply

The function multiply can also be called directly:

7.3 MultCall2

The second argument can be left out, since the default value is available for this argument.

The function multiply can also be called directly:

Simulate MultCall2:

The function multiply can also be called directly with named arguments:

8 Package

8.1 What is a Package?

The definitions in a package should be related in some way, which is the main reason they are placed in a particular package. Parameters and variables cannot be declared in a package.

A package is a restricted and enhanced class that is primarily used to manage name spaces and organize Modelica code. A package has the restrictions of only containing declarations of classes including all kinds of restricted classes and constants, i.e. no variable declarations. Also a package has the enhancement of being allowed to import from.