Unit checking
Diokle checks the physical units of every equation, infers units for variables that have none, and shows each variable in the unit you choose. Findings are warnings, never errors, and the rules are tuned so that the Modelica Standard Library's own idioms stay quiet.
In plain terms: a unit says what a number measures, such as metres or seconds. The check catches slips such as adding a height to a flow, which are easy to miss in a long model. Inferring a unit means working out the unit of a variable that has none, from the equations it appears in.
Checking a model
daedalus units model.mo -m MyModel # every variable's unit, then the issues (--json, --all)
daedalus check model.mo -m MyModel --units # translate as usual and print unit issues as warnings
A tank drained through an orifice, with a mistake in the outflow equation:
model Tank "a tank drained through an orifice"
parameter Real A(unit = "m2") = 2 "tank cross-section";
parameter Real a(unit = "m2") = 0.01 "orifice area";
parameter Real q_in(unit = "m3/s") = 0.05 "inflow";
parameter Real g(unit = "m/s2") = 9.81;
Real h(unit = "m", start = 1, fixed = true) "level";
Real q_out(unit = "m3/s") "outflow";
Real v "outflow velocity";
equation
A * der(h) = q_in - q_out;
v = sqrt(2 * g * h);
q_out = a * v + h;
end Tank;
model Tank
A m2 declared
a m2 declared
q_in m3/s declared
g m/s2 declared
h m declared
q_out m3/s declared
v m/s inferred
1 unit issues; 6 declared, 1 inferred, 0 unknown; 7 equations, 3 passes, 0.1 ms
warning: unit mismatch (equation) in equation in Tank: `q_out` has unit m3/s but `h` has unit m; equation: q_out = h + v*a
The velocity v had no unit, and Diokle inferred m/s from sqrt(2 g h). The extra
+ h in the outflow equation adds a height to a flow, so the checker reports it.
In the workbench, Check lists the unit issues in the Messages panel.
The rules
unitstrings follow the grammar of the Modelica specification (section 19.1):"kg.m2","rad/s","W/(m2.K)","s-1"and SI prefixes. The checker also knowsdegC,bar,rpm,l,min,hand the Imperialft,in,lbf,psi,mph,hp,degFand more.- The terms of a sum, the two sides of an equation, the branches of an
if, the operands of a relation and the arguments ofminandmaxmust agree. In short, you can only add, compare or equate quantities of the same kind, such as two lengths. Metres and centimetres are compatible, so the checker ignores scale and compares the dimensions. Products combine units,der()divides by seconds andsqrthalves the exponents. The arguments ofsin,expand similar functions must be dimensionless. - Functions are checked through their inlined bodies, with the units of the actual arguments.
- Numeric literals take any unit (
x + 1,1.5*R), as do variables declaredunit = "1"such as gains. Each branch of an if-equation is checked on its own, andlogtakes any unit. - When a clash involves an inferred unit, the checker drops that inference rather than reporting it.
- Rotations count as dimensionless when checking, so
rad/sagrees withHz, but not when converting for display.
On the 550 example models of the MSL 4.1.0 and the Daedalus library that flatten, it
reports two issues, both real and both in the MSL's TestGlycol example. The other 549
are clean. It costs about 1 % of the flattening time.
Display units
A displayUnit is the unit a variable is shown in. It changes only how results look, not
how the model is simulated. Plots show each variable in its displayUnit. Without one, they use a Dymola-style
default: rpm, deg, bar, degC, l/min or kJ. The plot toolbar picks the unit of the x and y
axes from the units that convert. Imperial switches the defaults to ft, lbf, lbf.ft,
psi, mph, degF, hp, gal/min and similar units. Variables whose unit was inferred are
plotted with that unit too.
Parameter data imported from CSV is converted to the declared units the same way; see Libraries, packages and parameter data.
