- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » How to constrain a number to be...
How to constrain a number to be positive and bigger than 273
How to constrain a number to be positive and bigger than 273
Hello to everyone,
I have an equation where the unknown variable is T a temperature. I don't know why but when I launch the simulation I have a negative solution
I have defined the variable in this way
Modelica.SIunits.Temperature T(start=Modelica.Constants.T_zero+20,min=273.15);
I'm wondering if this is this one is the right way to constrain a variable to belong to the range [273, [
Thanks a lot
the temperature type is defined in this way
type ThermodynamicTemperature = Real (
final quantity="ThermodynamicTemperature",
final unit="K",
min = 0,
displayUnit="degC")
Re: How to constrain a number to be positive and bigger than 273
Code:
final constant NonSI.Temperature_degC T_zero = -273.15 "Absolute zero temperature";
You need to use:
Code:
start=to_degC(Modelica.Constants.T_zero)
Anyway, if you want to enforce that the value is in the correct interval, you need to do that explicitly. The min attribute is only supposed to add an assertion equation:
assert(value >= min and value <= max, "Variable value out of limit");
OpenModelica does not add these equations. But min is only supposed to be a hint to the optimizing backend (e.g. if you state min=0, it means the value is always positive and you can make some assumptions).
- sjoelund.se
- 1700 Posts
- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » How to constrain a number to be...