OpenModelica


Forgot password? | Forgot username? | Register

Convergence

Convergence

Hi guys,
i'm trying to ha a convergence at a certain value of mass flow with a valve changing Cv. I use this formula to create a valve block:

Cv = m /sqrt(2*rho*(p1-p2))

where :
m--> mass flow
rho--> inlet density
p1--> inlet pressure
p2-->outlet pressure

p1,p2, rho are external parameters, Cv is the only parameter that can i change between one simulation to the other. I shoul liked to write an automatic loop like this :

given Cv at t = 0 and m in rated condition:
if m<m_rated then Cv = Cv+delta
if m>m_rated then Cv = Cv-delta

where delta is a parameter that can i decide every time.

Can i use some block in Modelica Library to obtain this behaviour?

Tnks everybody who will answered

Edited by: Ingrasciotta - Aug-14-19 14:06:24
Administrator has disabled public posting. Please login or register in order to proceed.

Re: Convergence

Are you looking for some thing like the attached file?


Administrator has disabled public posting. Please login or register in order to proceed.

Re: Convergence

I tried with a code like this but it doesn't work with large models, the simulation compiles well and starts but it doesn't go over a few percent.
To avoid the chattering i use noEvent in cicle if.

Edited by: Ingrasciotta - Aug-18-19 08:08:57
Administrator has disabled public posting. Please login or register in order to proceed.

Re: Convergence

I actually use this code but it doesn't work:

  m = u1*Cv * Modelica.Fluid.Utilities.regRoot(2 * rho1 * (p1 - p2), 45);
when u1>=1 then
  if noEvent(m-m_r>0.001) then
  der(Cv) = -0.001;
  elseif noEvent(m-m_r<-0.001) then
  der(Cv) = 0.001;
  else
  der(Cv) = 0;
  end if;
elsewhen u1<1 then
der(Cv)=0;
end when ;

u1 is an external signal that is =1 at rated condition and it goes from 1 to 0 when an event occcurs. I want that Cv is constat when u1<1 so when the event occurs.

Administrator has disabled public posting. Please login or register in order to proceed.

Re: Convergence

Well, I'm not sure about the correctness of using der(Cv) inside when equations, at least OpenModelica 1.13.2 doesn't allow me. It seems easier to use:
  if u1 >= 1 then
    if noEvent(m - m_r > 0.001) then
      der(Cv) = -0.001;
    elseif noEvent(m - m_r < (-0.001)) then
      der(Cv) = 0.001;
    else
      der(Cv) = 0.0;
    end if;
  else
    der(Cv) = 0.0;
  end if;
The second point is about the variables. rho1, p1 and p2 are constant or parameters, or are they variables? And u1 is  Boolean, Integer or Real?

Administrator has disabled public posting. Please login or register in order to proceed.

Re: Convergence

p1,p2 and rho1 are variables that the valve element obtains through flowports. u1 is a real variable this value can be insert by a real port and it goes from 1 to 0, if the port is not connected u1 = 1.

The code you write to me works correctly but the simulation is extremly slow.

Administrator has disabled public posting. Please login or register in order to proceed.

Re: Convergence

Well I would use something like this:
model CvO3
  parameter Real rho1 = 1000.0, p1 = 600.0, p2 = 200.0;
  parameter Real m_r = 1.2;
  Real Cv(start = 0.001), m;
  Real u1;
equation
  u1 = if time > 0.5 then 0.0 else 1.0;
  if u1 >= 1 then
    m = Cv * (2 * rho1 * (p1 - p2))^0.5;
    if (m - m_r > 0.001) then
      der(Cv) = -0.001;
    elseif (m - m_r < (-0.001)) then
      der(Cv) = 0.001;
    else
      der(Cv) = 0;
    end if;
  else
    m=0;
    der(Cv) = 0;
  end if;
end CvO3;
I have configured u1 as a time event, and the variables as parameters, for testing. Probably the use of noEvent is not necessary, and is slowing the simulation. My question regarding mainly p1 and p2 was due to the fact that when u1 becames 0, the equation becames: m=0 and breaks any connection between p1 and p2 (any value of p1 and p2 will fulfill the equation), so their value must be completely determined outside the exposed code. This beccomes clearer in my code, but is also applicable for yours. But if the code is working its means that there is no problem due to this point.

Administrator has disabled public posting. Please login or register in order to proceed.

Re: Convergence

CTG wrote:

My question regarding mainly p1 and p2 was due to the fact that when u1 becames 0, the equation becames: m=0 and breaks any connection between p1 and p2 (any value of p1 and p2 will fulfill the equation), so their value must be completely determined outside the exposed code.

Yes it does. When u1 comes to zero the valve is closed and the mass flow m drop to zero. Any type of connection between p1,p2 is losses but it's permitted by the block connected to the valve where the variables p1 and p2 are determinated.

Administrator has disabled public posting. Please login or register in order to proceed.
There are 0 guests and 0 other users also viewing this topic
You are here: