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

pre() operator

pre() operator

Hi!
I am pretty new to the Modelica language and I have some general questions about the usage of the pre() operator. I have a continuous Real variable h and I need to use the previous value of that variable in an equation.

Code:

WFd = Fd*(h-pre(h))

When doing so i OMEdit (r19853), the model work but when I run it in Dymola it gives the following error message:

Code:

Error: It is not allowed to use pre for a continuous time variable outside a when clause:

  pre(h)
Error detected in
  WFd = Fd*(h-pre(h));

As far as I know pre() can only be used if all of the following three condition are fulfilled.


• The variable y has one of the basic types Boolean, Integer, Real, or String, a subtype of
those, or an array type of one of those basic types or subtypes.
• The variable y is a discrete-time variable.
• The operator is not used within a function.

Is there a way to use the pre() operator without using a when clause or is a when clause the safest way?

About the error message, is this a bug in OMEdit?

Re: pre() operator

JoakimSandin wrote:

I have a continuous Real variable h and I need to use the previous value of that variable in an equation.

It does not have any such value unless you declare the variable "discrete Real". But those cannot change continuously (cannot be a state, etc).

Re: pre() operator

Thanks for the reply. I manage to solve the problem without using pre but I am still a little confused about the pre operator.

I have this equation:
W=m*Cp*(t0-t1)
Where t0 is the previous value of t1.

I have build up this model in Excel as well and using the pre(t) in OpenModelica will give the exact same result as in Excel. Even though variable t is a continuous Real variable.
Compiling this model in Dymola gives the error message described in my previous post.
Does someone have an idea why it works in OpenModelica?

Re: pre() operator

how did you exactly stored the pre(y) into t0?
I am also trying to use pre() function to model collision but I have the error below:

Code:


Translation Error
[/build/openmodelica-xkbOOS/openmodelica-1.11.0/OMCompiler/Compiler/SimCode/SimCodeUtil.mo: 552:5-552:146]: Internal error function createSimCode failed [Transformation from optimised DAE to simulation code structure fail

Re: pre() operator

foadsf, can you send us your model so we can debug what's the problem with it?
If is not public you can send it via email to OpenModelica@ida.liu.se and we'll delete it after debugging the issue.
If is public, just go to:
https://trac.openmodelica.org/OpenModelica/
click on New Ticket, create the ticket and attach your model to it.

Re: pre() operator

JoakimSandin wrote:


I have a continuous Real variable h and I need to use the previous value of that variable in an equation.
[...]
Is there a way to use the pre() operator without using a when clause or is a when clause the safest way?

A previous values exist only at event point. Basically the pre() operator request the left limit of a variable, while
the variable represents the right limit. The values are different only at event point and an event iteration is performed
until the values are equal. So this is the reason why you are only allowed you pre inside of
discrete-time expression, and not in continuous-time expression.

JoakimSandin wrote:


About the error message, is this a bug in OMEdit?

Actually, we have already a ticket related to this issue, see:
https://trac.openmodelica.org/OpenModelica/ticket/4158

so long.
Willi

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