Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

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).

There are 0 guests and 0 other users also viewing this topic
You are here: