Reputation: 363
I'm trying to get temperature differences quantities to report the correct result when displayed in non-absolute temperature scales. See the following example:
model tempDiffTest
Modelica.Blocks.Interfaces.RealOutput test1(quantity="ThermodynamicTemperature", unit="K") = 1 annotation(absoluteValue=false);
Real test2(quantity="ThermodynamicTemperature", unit="K") = 2 annotation(absoluteValue=false);
Modelica.SIunits.TemperatureDifference test3 = 3;
end tempDiffTest;
Note that
type TemperatureDifference = Real (
final quantity="ThermodynamicTemperature",
final unit="K") annotation(absoluteValue=false);
which is what drove the modifications I made to the test1 and test2 variables.
Now, the expectation is that when I display my results in degrees celsius they should be 1, 2, and 3 for test1, test2, and test3, respectively. The actual results are shown below from Dymola:
Therefore, only test3 was apparently successful (note that none of the results were successful in OpenModelica). Now, my question is how do I achieve what I'm after for test1 and test2?
Upvotes: 1
Views: 168
Reputation: 6645
Dymola does not support the usage of the absoluteValue
annotation in the declaration of test1
and test2
.
If you enable the annotation check in Dymola with
Advanced.EnableAnnotationCheck=true
Dymola reports during check
In class tempDiffTest component test1, the annotation 'absoluteValue' is unknown.
Looking at the Modelica spec, we note that it tells
A simple type or component of a simple type may have: annotation(absoluteValue=false);
In my opinion, this is a bit vague and your code should work (as test2
is a component of the predefined type Real
). But Dymola accepts the annotation only in class definitions.
So to solve your problem, you simply have to declare a connector and a type to be able to use this annotation.
package tempDiffTest
connector Test1 = Modelica.Blocks.Interfaces.RealOutput (quantity="ThermodynamicTemperature", unit="K") annotation(absoluteValue=false);
type Test2 = Real(quantity="ThermodynamicTemperature", unit="K") annotation(absoluteValue=false);
model Example
Test1 test1 = 1;
Test2 test2 = 2;
Modelica.SIunits.TemperatureDifference test3 = 3;
end Example;
end tempDiffTest;
Upvotes: 2
Reputation: 7500
From the Modelica Language Specification:
A simple type or component of a simple type may have:
annotation(absoluteValue=false);
If
false
, then the variable defines a relative quantity, and if true an absolute quantity. [When converting between units (in the user-interface for plotting and entering parameters), the offset must be ignored, for a variable defined with annotation absoluteValue = false. This annotation is used in the Modelica Standard Library for example in Modelica.SIunits for the type definition TemperatureDifference.]
Therefore the annotation only makes a difference when converting from the actual unit
to a displayUnit
with an offset defined for that operation. If annotation(absoluteValue=false)
is added, this is offset ignored. This makes sense for a difference in temperature as it is the same number for e.g. Celsius or Kelvin.
Regarding your code: What it does, is assigning a temperature in Kelvin to test1
and test2
and then showing it in °C. Therefore what is shown is correct.
For this, it is important to know that in Modelica values are always assigned in the unit that the variable has, which is Kelvin in your case. This is then recomputed to Celsius for showing it in the UI. You need to assign 274.15K to get 1°C. As this is a pretty common re-computation there is a function for it in the MSL: Modelica.SIunits.Conversions.from_degC
So I would suggest to modify your code to something like:
model tempDiffTest
import Modelica.SIunits.Conversions.from_degC;
Modelica.Blocks.Interfaces.RealOutput test1(quantity="Temperature", unit="K", displayUnit="degC") = from_degC(1);
Modelica.SIunits.Temperature test2 = from_degC(2) annotation(absoluteValue=false);
Modelica.SIunits.TemperatureDifference test3 = 3;
Modelica.SIunits.TemperatureDifference test4 = test1-test2;
end tempDiffTest;
This results in:
or
Upvotes: 1