-
Notifications
You must be signed in to change notification settings - Fork 43
Description
Added together with other unit-changes:
The units of parameters and constants may only be inferred from their binding equations.
Background:
Normally in unit-checking it makes sense to derive the unit for all variables without a specified unit.
However, for parameters and constants it does not make sense to derive them (except from their binding equations).
As a stupid example consider (yes, there's a bug):
model M1
Real radius(unit="m")=1;
Real area(unit="m2")=Modelica.Constants.pi*radius;
end M1;
model M2
Real radius(unit="m")=1;
Real area=Modelica.Constants.pi*radius^2;
end M2;
model M
M1 m1;
M2 m2;
end M;
If we do unit-checking mindlessly we get that Modelica.Constants.pi
has unit="m" and thus m2.area
has unit="m3".
Alternatives for improving:
- As a minimum we should not allow the unit of parameters and constants to be derived from anything but their binding equations.
- State that parameters and constants have unit="1", unless specified or derived from binding equations. (Can be seen as an optional addition.)
- (Explicitly adding unit="1" for pi seems counterintuitive and it will be missed for some constant. Additionally in many cases it should be unit="rad", but not in other cases.)
I believe it makes sense for all parameters and constants, but it is at least 100% clear for package constants - since they might be used in different models - giving quite unexpected results as above.
The example may seem contrived - but I saw something similar in Modelica.Mechanics.MultiBody.Visualizers.PipeWithScalarField.