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
  • Index
  • » Users
  • » JoakimSandin
  • » Profile

Posts

Posts

Jun-11-14 17:31:01
Result of a variable as a start value in the next simulation.
Category: Programming

I must admit that I have had some hard time to overcome the the way of think in classic programing and maby I just need to reboot my brain current/big_smile

This is how I´m thinging:
dropletTemperature(first time step) = dewPointTemperature(last time step)

When the compiler is about to calculate the first time step, how can it know the value of the dew-point variable in the last time step?

Jun-09-14 15:34:43
Result of a variable as a start value in the next simulation.
Category: Programming

I have created a model that will simulate evaporation from water droplets and I want the droplet temperature of the last time step to be the start value for the droplet temperature in the first time step on the next simulation. A kind of iteration. The droplet temperature in the first time step shall be equal to the dew-point of the gas (that surrounds the droplet) in the last time step.

This could be done manually by making a guess of the final temperature and then simulate over and over again, till the difference between the guessed value and the result is small enough.

Is there a way to use the value of a variable in the last time step to be the start value for the next simulation, by writing code or by using some of the components in MSL?

Thanks in advance.

Jun-03-14 17:27:10
Category: Programming

Thanks for the reply.
No, it is not an expandable connection.
I manage somehow to solve the problem but I am not quite sure what I really did to solve it. With a little help from Dymola I manage to locate where the problem might have meen located and then I took away some of the start values and also some of the if-statements I described above and now it works just fine current/smile

May-28-14 11:41:24
Category: Programming

I discovered something in the debugger.
There are four components in my model:

    dropVelocity
    X
    evaporation
    gasTemp


A picture from the debugger window.
https://dl.dropboxusercontent.com/u/22026291/debugger.PNG

Does anyone know what the variable evaporgastionemp1.evapMass marked with red and gren in the picture above means? EvapMass don´t exist in such component. I am confused about this and don´t really know what it means.

May-27-14 14:57:51
Category: Programming

Hi

I am building a model containing 4 different components connected to each other, and I have some problem with division by zero at time=0.

I have manage to solve a couple of errors of this kind but when I put on more components, another error of this kind will appear.

I have tried to give some start values for the variable that become zero using the following code.

Code:

parameter Real START = 1 * 10 ^ (-6);

Real evapMass(start = START);

Or

Code:

Real evapMass(start = START, fixed = true);

I have also tried to force the variable to be non-zero by writing, including other variables as well:

Code:

if time > 0 then

    evapMass = waterUse / 60;
  else
    evapMass = START;
  end if;

I have tried to go to the bottom with this by following and controlling every superior variable that is included in this variable and make sure that they are non-zero at time=0.

The error message from the last simulation:

Code:

C:/Users/ninawe/AppData/Local/Temp/OpenModelica/OMEdit/Evap_kyln.Examples.EvaporativeCooler.exe -port=2066 -logFormat=xml -w -lv=LOG_STATS

assert        | debug     | division by zero at time 0, (a=-1e-006) / (b=0), where divisor b expression is: if time > 0.0 then 0.01666666666666667 else 0.0 Debug more
Process crashed
Simulation process exited with code -1

Now to the question:
I might of course have missed something in my model that will cause this error but is there other ways to get rid of the “division by zero” errors in the initialization process, others than those I already have tried, or does someone have any tips on how to get around it?

Apr-29-14 11:08:31
Category: Programming

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?

Apr-09-14 15:16:12
Category: Programming

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?

Apr-07-14 09:51:56
Category: Programming

Thanks! This solution works just fine.

Apr-02-14 12:10:18
Category: Programming

I want to calculate the change in potential energy as a water droplet is falling towards the ground and I also want to be able to change the start heignt of the drop in an easy way. To know where the droplet is I have defined the position of the droplet as

Code:

x=time;

. But to calculate the potential energy I have to know the distance to the ground as well.

What I want to do, is something like this:

Code:

Distance=(StopTime-x);

I have tried to use the code

Code:

annotation(experiment(StartTime = 0.0, StopTime = 6.0, Tolerance = 1e-006)…);

and then use StopTime as both a variable and or parameter without success.
I could just type in the start height of the falling drop and then choose the same stop time before simulate.
Is there an easier way to solve this?
/Joakim

Apr-01-14 11:41:32
Category: Programming

I am not sure if the solution is this simple , but if I save the "model Const" after changing parameter A, variable C is changing as it should do.

Mar-12-14 16:07:25
Category: Programming

Thanks! A ticket was sent and a few minutes later the 1.9.1 Beta2 (r19422) was uploaded and the problem was solved current/big_smile

Mar-11-14 13:59:34
Category: Programming

Hi
I have some problems with parentheses/brackets in some of my equations. This just a simple exampel and I hope the comments in the code will explain the problem.

model Testar
  constant Real A = 2;
  constant Real B = 3;
  constant Real C = 5;
  // I wish to whrite equation G as: G = 10 / ((A+B)/2) * C; which is equal to 20
  //
  Real G;
  Real H;
  Real I;
  //
equation
  // When I save the model, OpenModelica choose to read the equation as in equation G below, without parentheses outside (A+B)/2.
  G = 10 / (A + B) / 2 * C;     // G = 5
  //
  // If i split up equation G in I and H as follows below, I will get the correct answer, which is 20.
  I = (A + B) / 2;     // I = 2.5
  H = 10 / I * C;     // H = 20
  //
end Testar;

When it is just constants I am calculating I could do parts of the calculation outside the equation.
But, is there a way to solve equation G without split it up in several equations?

  • Index
  • » Users
  • » JoakimSandin
  • » Profile
You are here: