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

Initialisation of Parameters with OpenModelica 1.92 in comparison to 1

Initialisation of Parameters with OpenModelica 1.92 in comparison to 1


Hi,

Is someBody can explain me why the new version of openModelica compiler  in comparison to the previous one add an additional state variable to my own model
during the step of parameter initialization ? 

why the compiler changes ther priority order  of the present parameters ?
where I  can find the definitron of the $_initialGuess function ?

My model is this one and the parameter p1 is the master of the parameters :  what happens in the generated file nammed TestParameterInit_06inz.c ?

model TestParameterInit
parameter Real p1(fixed=false);
parameter Real p11 = 100.0;
parameter Real p12(start=33.,fixed=true);

parameter Real p2 = if p1 > 0 then p11 else p12;
parameter Real p3 = 3*p1^2;
Real x(start=-1, fixed=true);
equation
  der(x) = p3 *x^2 - p2 *x;
end TestParameterInit;

Thanks in advance for your help ane your explantion

Best regards

ALIAN_2

Re: Initialisation of Parameters with OpenModelica 1.92 in comparison to 1

You specified p1(fixed=false), but provided no initial equation for it (so the model tries to invent an equation for p1 from p3 since p3 has a binding and p1 does not). And p12 does not have a binding (should be p12 = 33). The following should be the model you specify and follows the specification:

Code:

model TestParameterInit

parameter Real p1 = 0;
parameter Real p11 = 100.0;
parameter Real p12 = 33;

parameter Real p2 = if p1 > 0 then p11 else p12;
parameter Real p3 = 3*p1^2;
Real x(start=-1, fixed=true);
equation
  der(x) = p3 *x^2 - p2 *x;
end TestParameterInit;

If you get warnings during initialization, results will vary between Modelica tools and versions.

Re: Initialisation of Parameters with OpenModelica 1.92 in comparison to 1

Thanks for your quick answer. I understand your explanations

I  wrote the second test where I give of a value of p1 master parameter , the compiler works correctly

but really if I compil my first test alone , the results of the compiler (version 1.9.2)  disturb me !!

Best regards

ALAIN_2


class TestParameterInit
parameter Real p1(fixed=false);
parameter Real p11 = 100.0;
parameter Real p12(start=33.,fixed=true);

parameter Real p2 = if p1 > 0 then p11 else p12;
parameter Real p3 = 3*p1^2;
end TestParameterInit;

model TestParameterInit2
extends TestParameterInit(p1=2,p11=1000.);
Real x(start=-1, fixed=true);
equation
  der(x) = p3 *x^2 - p2 *x;
end TestParameterInit2;

Re: Initialisation of Parameters with OpenModelica 1.92 in comparison to 1

maybe here someone can help me..
in my model i need to initialize a Real variable with initial value =0
but this value has to change during the equation procedure

model EX
   Real a = 0;
equation
   a = a+1;
end EX

why it doesn't work??

Re: Initialisation of Parameters with OpenModelica 1.92 in comparison to 1

Your code is equivalent to saying

Code:

a = 0;

a = 1;

So it has one equation too many. To create things like counters, check some examples at: http://book.xogeny.com/behavior/discrete/sampling/

Re: Initialisation of Parameters with OpenModelica 1.92 in comparison to 1

so how can i increase the value of "a" by one?

Re: Initialisation of Parameters with OpenModelica 1.92 in comparison to 1

How  about something like that:

[code]
model EX
   Real a, b;
equation
  a = if initial() then 0 else 1;
  when initial() then
   b = a;
  end when;
end EX;
[\code]
Variable b is just there to see that variable a is really in initial point in time 0.

so long.
Willi

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