- Index
- » Programming
- » Modelica Language
- » Convergence

Page Start Prev 1 Next End

Aug-14-19 14:05:41

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

Aug-18-19 08:08:41

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.

Aug-18-19 15:02:38

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.

Aug-18-19 22:05:59

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?

Aug-20-19 06:32:51

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.

Aug-20-19 21:24:07

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.

Aug-21-19 06:50:19

## 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.

Page Start Prev 1 Next End

- Index
- » Programming
- » Modelica Language
- » Convergence

There are 0 guests and 0 other users also viewing this topic