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

Final parameters and if expressions

Final parameters and if expressions

Hello,

I have a simple model (see below) which conditionally assigns a value to a parameter. If this parameter is final the its value is always 0.

Furthermore if the right hand side is a final parameter value, the result also is 0, wheter or not the left hand side is a final parameter.

Code:


type CondEnum = enumeration(a, b);

model Test
  final parameter CondEnum cond = CondEnum.b;
        parameter Real val = 1.0;
  final parameter Real final_value = 1.0;

        parameter Real value1 = if cond == CondEnum.a then val         else -val;
  final parameter Real value2 = if cond == CondEnum.a then val         else -val;
        parameter Real value3 = if cond == CondEnum.a then final_value else -final_value;                                 

  Real result1; 
  Real result2;
  Real result3;

equation
  result1 = value1; // ok    (==-val)
  result2 = value2; // error (==0)
  result3 = value3; // error (==0)
end Test;

Model checking and simulation proceeds without errors.

Best regards,

Michael

Re: Final parameters and if expressions

The SimCode contains the following:

Code:

    simple equation: result1 = value1

    simple equation: result2 = if CondEnum.b == CondEnum.a then 1.0 else -1.0
    simple equation: result3 = if CondEnum.b == CondEnum.a then 1.0 else -1.0

But the equations are actually not put in the generated code. I'll open up a bug for it (http://openmodelica.org:8080/cb/issue/1 … tion=true)

Re: Final parameters and if expressions

Fixed with revision 10629

now result1=result2=result3=-1

result1 = value1
result2 = -1.0
result3 = -1.0

value3 is replace with -1 because it is a bound parameter and the bound expression is final.

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