Modelica
- Evaluate Cell: shift+enter
- Insert Input Cell: Ctrl+Shift+I
- Insert New Cell of type above: Alt+Enter
Identifier:
- constant
- input
- output
Assignment: done via :=
Equation: done via =
Variables:
- Base Types:
Integer
Real(unit = "<unit>" ~ opt, min = <min> ~ opt, max = <max> ~ opt)
Boolean
- Variability:
- constant - never changes
- parameter - changes between simulations
- discrete - changes on events
- Starting Value:
<type> <var>(start = <val>);
- Visibility:
public
-
protected
- treated as headers, all variables after a visibility statement and before another control statement will have that visibility
Libraries:
- loadModel(
); - Standard Library: Modelica
Classes:
Nested (local) classes are allowed
- Special words to replace “class”:
model
: intended for models; cannot be used for connectionsrecord
: intended for data structures; cannot have equations, cannot be used for connectionstype
: intended to introduce new types; must extend another type, record, or be an arrayconnector
: defines connections; no equationsblock
: data flow of variables is known; all variables must be declared with “input” or “output” * followed by a type or class; no connectionsfunction
: defines inputs and outputs, no equation, exactly one algorithm(<output var>:=<computation>
)calling
:( ,...)
- Define:
class <classname>
- public
parameter <type> <var> = <val ~ opt>;
- public
-
end
<classname - to instantiate>
; type <classname> = <sourceClass to instantiate>
- Container Classes:
class <container classname>
<contained classname> <thisname>(<paramater ~ opt>=<val>,...);
- end
<container classname>
- Drilling Down:
<classname>.<classname...>.<parameter>
<classname>(<paramater1>,<paramater2>,...)
- View flattened class:
instantiateModel(<class>)
- Inheritance:
class <name>
extends <super>;
…Standard class stuff
- Generics:
- prefix type with keyword : “replaceable” ::
replaceable <type> <name>;
- Declaring:
class <name> = <c lass type>(redeclare <type> <name>,...)
- prefix type with keyword : “replaceable” ::
- Partial Classes:
- may be extended, but not instantiated
partial class <classname>
- Package:
- Organizes classes of all types and constants
- if importing other packages, prevent conflicts by using encapsulated package:
* `import <packageName>;`
* `import <alias>=<packageName>;`
- Simulation:
simulate(<class>)
- Visualization:
- Plot:
plot(<args>)
- Plot:
- Arrays:
- Declaration:
<type>[<dim1,...>] <name>;
- OR
-
<type> <name>[<dim1,...>];
- Can initialize with declaration:
<type>[<dim1,...>] <name> = {x,y,z};
- OR
<type> <name>[<dim1,...>] = \{\{x,y\},\{f,g\}\};
- Multiplication:
*
- is element wise
- Declaration:
- Matrices:
- Declaration:
<type> <name>[<dim1,...>] = [<v>,<v>;...];
- Multiplication:
*
is matrix multiplication
- Declaration:
- Algorithms:
- start with keyword “algorithm”
- are the only place where traditional procedural command flow exists:
reinit(<var>,<new val>)
: reinitializes variable, useful in while loop