-
Notifications
You must be signed in to change notification settings - Fork 44
Description
Follow-up to #3645
The basic idea is that for temperature variables one can use absoluteValue-annotation, but one can also infer it in many cases and it would be good to have them listed. This has been test-implemented in Dymola.
Specifically I see the following rules:
For equality, and function calls propagating unit for first or second argument, and function argument with declared absoluteValue, the absoluteValue should be the same. (If we add a magic "discrete difference operator" we'll have to make an exception.)
Simple inference rules for terms where X is either absolute or difference:
- ±Difference->Difference
- X±Difference->X
- Difference+X->X
- Absolute-Absolute->Difference
- (Possibly something for relational operators.)
If we agree on this as a suggestion I can make a PR (it can be non-normative if desired; just so that there's a clear guide-line.)
These are all of the rules, note in particular that:
- Other uses are allowed - but without any inference
- Incomplete inference is not seen as an issue
- The only error case is having an absolute temperature equal to a temperature difference
This covers about 98% of the cases in MSL, and most of them are absolute temperatures (as expected - I'm pretty sure that temperatures in physical connectors should always be absolute temperatures). Some of the remaining cases could either be handled by even more rules, but even simpler by just adding the annotation for relevant variables.
However, there are cases that cannot be handled - meaning that I don't see any realistic way of handling them:
- Clear ambiguities as below
Modelica.Clocked.Examples.Systems.Utilities.ComponentsMixingUnit.MixingUnit
has
parameter Real weps = eps*T0; gamma = c*wk0*exp( -weps/T);
whereweps
has unit "K" but is neither an absolute temperature nor a difference- If you want to compute the average of two temperatures you can do
0.5*T1+0.5*T2
or(T1+T2)/2
, where0.5*T1
and (T1+T2) have unit "K" but are neither absolute temperature nor a difference (not that this is for the sub-expressions whereas deducing that(T1+T2)/2
is an absolute temperature if bothT1
andT2
are absolute temperatures would be possible, but I believe it is too esoteric).
Clear ambiguity:
model M
parameter Real T1(unit="K");
parameter Real T2(unit="K");
parameter Modelica.Units.SI.Temperature T=T1+T2;
end M;
It's very likely that one of T1
and T2
is absolute temperature and one is a difference, but we don't have enough information to say which is which. (Or similarly using blocks.) Obviously absoluteValue-annotations can resolve the ambiguity.