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

on the usage of pre()

on the usage of pre()

Hello,

I don't understand why it is possible to call pre() during integration time. With omc 1.9.1+dev (r18345) I can simulate equation

Code:


  Real x (start=0);
  x = pre(x) + 1;

where I observe that the growth of x depends on the numberOfIntervals parameter, which seems odd to me, I would expect the compiler to reject this program.

My other question is on the use of pre() in a discrete context. Does anyone know why equation

Code:


  Integer cpt (start=0);
  cpt = if time <= 10 then pre(cpt) + 1 else pre(cpt);

returns

Code:

ERROR: Too many event iterations.

?

Thank you,
Antoine

Edited by: antoinem - Mar-14-14 13:24:31

Re: on the usage of pre()

I've just tried both models in Wolfram System Modeler. Both simulations "work", but in both cases x respectively cpt jump instantly on 11 and don't change after that.
I've also tried in in an older Version of OM but both models didn't compile.
I often have trouble using the pre()-function as well, so I am looking forward to hearing an answer on this current/wink

Re: on the usage of pre()

The following model is not valid according to the specification:

Code:


model M
  Real x
equation
  x = pre(x) +1;
end M;

x is a continuos variable, so it's not allowed to use pre of x outside when.

The model:

Code:


model M
Integer cpt (start=0);
equation
  cpt = if time <= 10 then pre(cpt) + 1 else pre(cpt);
end M;

fails, since every time the tool execute the code pre(cpt) != cpt, so we need to perform an further event iteration.

Please, see Modelica Specification page 27 ff:
3.7.3
Event-Related Operators with Function Syntax

so long.
Willi

Re: on the usage of pre()

Ok I understand why the program with cpt is looping.

But why the omc compiler is accepting the first program? Should I report this bug?

Re: on the usage of pre()

Actually we should detect the error for the first model while compile time(I added a ticket therefor #2620.

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