In this section guidelines on creating Modelica code are provided.
Extends from Modelica.Icons.Information (Icon for general information packages).
Name | Description |
---|---|
Format | Format |
Naming | Naming convention |
ParameterDefaults | Parameter defaults |
Comments and annotations should start with a capital letter, for example:
parameter Real a = 1 "Arbitrary factor";
.
For Boolean parameters, the description string should start with "= true, …", for example:
parameter Boolean useHeatPort = false "= true, if heatPort is enabled";
.
Extends from Modelica.Icons.Information (Icon for general information packages).
T
for a temperature variable)._a
, _b
or _p
, _n
, e.g., Flange_a
, Flange_b
,
HeatPort_a
, HeatPort_b
.In the following table typical variable names are listed. This list should be completed.
Variable | Quantity |
---|---|
a | acceleration |
A | area |
C | capacitance |
d | damping, density, diameter |
dp | pressureDrop |
e | specificEntropy |
E | energy, entropy |
eta | efficiency |
f | force, frequency |
G | conductance |
h | height, specificEnthalpy |
H | enthalpy |
HFlow | enthalpyFlow |
i | current |
J | inertia |
l | length |
L | Inductance |
m | mass |
M | mutualInductance |
mFlow | massFlow |
p | pressure |
P | power |
Q | heat |
Qflow | heatFlow |
r | radius |
R | radius, resistance |
t | time |
T | temperature |
tau | torque |
U | internalEnergy |
v | electricPotential, specificVolume, velocity, voltage |
V | volume |
w | angularVelocity |
X | reactance |
Z | impedance |
Extends from Modelica.Icons.Information (Icon for general information packages).
In this section the convention is summarized how default parameters are handled in the Modelica Standard Library (since version 3.0).
Many models in this library have parameter declarations to define constants of a model that might be changed before simulation starts. Example:
model SpringDamper parameter Real c(final unit="N.m/rad") = 1e5 "Spring constant"; parameter Real d(final unit="N.m.s/rad") = 0 "Damping constant"; parameter Modelica.Units.SI.Angle phi_rel0 = 0 "Unstretched spring angle"; ... end SpringDamper;
In Modelica it is possible to define a default value of a parameter in the parameter declaration. In the example above, this is performed for all parameters. Providing default values for all parameters can lead to errors that are difficult to detect, since a modeler may have forgotten to provide a meaningful value (the model simulates but gives wrong results due to wrong parameter values). In general the following basic situations are present:
To handle the conflicting goals of (1) and (3), the Modelica Standard Library uses two approaches to define default parameters, as demonstrated with the following example:
model SpringDamper parameter Real c(final unit="N.m/rad" , start = 1e5) "Spring constant"; parameter Real d(final unit="N.m.s/rad", start = 0) "Damping constant"; parameter Modelica.Units.SI.Angle phi_rel0 = 0 "Unstretched spring angle"; ... end SpringDamper; SpringDamper sp1; // warning for "c" and "d" SpringDamper sp2(c=1e4, d=0); // fine, no warning
Both definition forms, using a "start" value (for "c" and "d") and providing a declaration equation (for "phi_rel0"), are valid Modelica and define the value of the parameter. By convention, it is expected that Modelica translators will trigger a warning message for parameters that are not defined by a declaration equation, by a modifier equation or in an initial equation/algorithm section. A Modelica translator might have options to change this behavior, especially, that no messages are printed in such cases and/or that an error is triggered instead of a warning.
Extends from Modelica.Icons.Information (Icon for general information packages).
Automatically generated Thu Oct 1 16:07:32 2020.