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

Can't limit values in model

Can't limit values in model

I am modeling a pipe that can be either full, empty or partially full.  I am trying to use the following code segment, but I keep getting errors.

Code:

if level <= 0 then

  //empty pipe
      phi = 0.0;
  fitting_in.P = fitting_out.P;
    //Full pipe
elseif level >= 2 * R then
  //full pipe
      phi = 2 * Modelica.Constants.pi;
  fitting_in.q = -fitting_out.q;
else
  //partially full pipe
  phi = 2 * acos((R - level) / R);
  fitting_in.P = fitting_out.P;
end if;
    A = 0.5 * R ^ 2 * (phi - m.sin(phi));

And when I run my simulation, I get the following errors:
assert | warning | The following assertion has been violated at time 35.327627
assert | debug | Model error: Argument of acos(DIVISION(pipeArray1.pipeSegment[2].R - pipeArray1.levels[2]) / pipeArray1.pipeSegment[2].R) outside the domain -1.0 <= -1.0017 <= 1.0

In this simulation, the level should be going up, until the pipe is full. 
level represents the height from the bottom of the pipe and R is a parameter.  What I am trying to do is if the level ever rises to, or above, the top of the pipe, the phi, the angle fro the center of the pipe to the fill level, should be fixed at 2pi.  But, during my simulation, the above error shows that the //full pipe calculation is not being used, and instead it is still using the acos calculation. 
From above, the acos should only be used when level is < 2*R, so (R-level)/R) should be >-1. 

Essentially, I am trying to have three different modes of operation, and using one to protect against acos of an out of range number.  But, for some reason the simulation is calculating into this "illegal" range and giving me an error. 
Any guidance about how to handle this kind of situation would be very helpful.

Re: Can't limit values in model

To answer my own question, I believe that this is an event problem and the answer is to use noEvent on the conditionals.

Re: Can't limit values in model

I am really no pro, but it seems to me that the "acos"-functions causes the Problem.
As the message tells, the argument becomes out of range. I guess that "R" is a fixed (positive) value?! Might it be possible, that "Level" becomes negative?

Re: Can't limit values in model

Just to further explain my question, Zwieback answer and my own.
Yes, Zwieback, you are correct that R is a parameter.  But, if you look at my code, the intention was that the acos equation could only occur when level is between 0 and 2R, due to the if and elseif conditionals. 
R is the radius of a pipe and level is the level of fluid in the pipe.  So, level can either be <0 or (pipe is empty), over 2R (the pipe is full) or between them (pipe is partially full).  The acos equation should only happen when the pipe is partially full, in which case the acos should always be valid. 
However, the "gotcha" in the above is about events.  The conditionals are only tested with events, as I now understand.  And during the simulation it is possible to have the acos equation be valid, when level exceeds 2R. 
The answer was to replace conditionals with if noEvent(level <0) and elseif noEvent (level >=2*R)

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