-
Notifications
You must be signed in to change notification settings - Fork 44
Open
Labels
MCP0027Unit checkingUnit checking
Description
As part of unit-checking #3491 various ways of attaching units to Reals are proposed including withUnit(...) and 1 'm'. After additional internal discussion we have found a simpler proposal that voids most of the pitfalls.
The simple proposal is that Real (and any type derived from Real) can be called as follows:
function Real
input Real _v;
input String unit;
input String displayUnit=unit;
output Real y(unit=unit, displayUnit=displayUnit)=_v;
end Real;
Benefits:
- No, new syntax or reserved words needed.
- Close to the syntax of component declarations, and with the same semantics.
- Would allow replacing
parameter Real p(unit="m", displayUnit="mm")=0.001;
byparameter Real p=Real(0.001, unit="m", displayUnit="mm");
- with the same semantics, in particular we make it easy to avoid non-base-units in equations. - Possible to vectorize (at least in the first argument)
Including types derived from Real would allow something like the following in the IdealDiode:
v = (s * SI.Current(1) ) * (if off then 1 else Ron) + Vknee;
i = (s * SI.Voltage(1) ) * (if off then Goff else 1) + Goff*Vknee;
Metadata
Metadata
Assignees
Labels
MCP0027Unit checkingUnit checking