- Index
- » Programming
- » Modelica Language
- » on the usage of pre()
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
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
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
- wbraun
- 75 Posts
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.
- wbraun
- 75 Posts
- Index
- » Programming
- » Modelica Language
- » on the usage of pre()