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
  • » xazhi
  • » Profile

Posts

Posts

Greetings,

I would like to have some information about the may the regStep function works.
The documentation states the following:


This function is used to approximate the equation

    y = if x > 0 then y1 else y2;

by a smooth characteristic, so that the expression is continuous and differentiable:

    y = smooth(1, if x >  x_small then y1 else
                  if x < -x_small then y2 else f(y1, y2));

In the region -x_small < x < x_small a 2nd order polynomial is used for a smooth transition from y1 to y2.

Therefore, I understand that the f function has the following conditions to keep the fucntion continuous and differentiable:
f(x_small) = y1(x_small)
f'(x_small) = y1'(x_small)
f(-x_small) = y2(-x_small)
f'(-x_small) = y2'(-x_small)
The documentation states that f would be a second degree polynomial. However, a second degree polynomial has only three parameters (a, b and c in case of ax2 +bx + c) and therefore we would have a set of four equations woth only three unknowns that may be unsolvable (e.g. you can take y1(x) = -x+1, y2(x) = 0 and x_small = 1).
I would therefore like to understand how this function actually works and if I made a mistake in my understanding of this function.
Thanks

Thank you for your answer. Yes I have seen the BouncingBall example, that's why I attempted to use the when and reinit directives.
The model is very complex (I did not develop it) as it contains many rooms and connexions between rooms, and the aim is to calculate the water height in each room.
The main equation in the room is :

Code:


rho * S * der(h) = flow

where rho and S are constants, h the calculated height and flow is the sum of incoming and outgoing water flows, that depend on the water heights in the other rooms.
In most cases the model works perfectly well, however sometimes the water drains from the room to other rooms so quickly that negative water heights can be obtained. This is why I try to impose the positivity of variable h.

Greetings,

I would like to solve a set of differential equations with OpenModelica and I would like to impose a condition on one of my variables: it is a water height so it should be always positive physically, however sometimes I get negative heights because of large gradients and I cannot afford to refine the time mesh.

I attempted to add a when directive in the equation part as follows:

Code:

 when h<0 then

reinit(h,0);
end when;

This seems to have no effect. Therefore I attempted the following:

Code:

 when pre(h)<0 then

reinit(h,0);
end when;

This has a weird behaviour as the variable is punctually set to 0 but its overall behaviour is unchanged.
Does anybody know how to impose a h>0 condition in the set of equations?

Thanks in advance

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