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

Bidirectional flow valve Model

Bidirectional flow valve Model

Here is a  Valve model that is giving me problem when I try if equations in it to allow  reverse flows. I am aware concepts related to flow reversals have been covered extensively in many of Modelica presentations that explain Streams. This is my attempt to understand them through simple examples.

When I try to use this model "omc" complains that the system is under determined .... needing two more equations. But I am unable to see what other eqns. are needed here.

The model works fine if I replaced the conditional equations with the equations that are in the (deltaP>0) case.  (as long as I don't get into reverse flow conditions and that is what I expected).

My aim is to make the valve work in both flow directions. 



[model Valve
  // A simple Valve (that permits bidirectional flow)
 
  replaceable package Medium = PartialSimpleIdealGasMedium ;

FluidPort     inlet (redeclare package Medium = Medium)  ;
  FluidPort     outlet (redeclare package Medium = Medium)  ;

  parameter Real   cv = 1.0 / sqrt(1e5)     ;   
Medium.ThermodynamicState    state ;
 

  equation
    // No change in Enthalpy in the Valve

     inlet.h_outflow = inStream(outlet.h_outflow) ;  // when flow from out to in
     outlet.h_outflow = inStream(inlet.h_outflow) ;  //      inlet to outlet
     inlet.Xi_outflow = inStream(outlet.Xi_outflow) ;  // pass composition un_altered
     outlet.Xi_outflow = inStream(inlet.Xi_outflow) ;  //     

  // Mass balance
     inlet.m_flow + outlet.m_flow = 0  ;

    // Pressure difference drives the flow
    if ( inlet.p > outlet.p ) then
        state = Medium.setState_phX(inlet.p, inStream(inlet.h_outflow), inStream(inlet.Xi_outflow)) ;
        inlet.m_flow =  Medium.density(state)  * cv * sqrt(inlet.p - outlet.p) ;
    else
        state = Medium.setState_phX(outlet.p, inStream(outlet.h_outflow), inStream(outlet.Xi_outflow)) ;
        outlet.m_flow =  Medium.density(state)  * cv * sqrt(outlet.p - inlet.p) ; // Typical valve behaviour
     end if ;
end Valve;

Re: Bidirectional flow valve Model

I think I figured out what the problem is. Looks as though if equations  work only on variables with variability of  "parameter". For dynamic variables, one need to resort to if expressions. When I modified the above code with these lines the model compiled and worked fine.


Code:


     state = if (inlet.p > outlet.p) then Medium.setState_phX(inlet.p, inStream(inlet.h_outflow), inStream(inlet.Xi_outflow))
                                                     else Medium.setState_phX(outlet.p, inStream(outlet.h_outflow), inStream(outlet.Xi_outflow));
 
    inlet.m_flow = if (inlet.p > outlet.p)  then  Medium.density(state)  * cv * sqrt(inlet.p - outlet.p)
                                                                 else  - Medium.density(state)  * cv * sqrt(outlet.p - inlet.p);

I am not sure if this was made clear in the manuals.   Would appreciate if Modelica experts confirm my observation. It would have been more appropriate for omc to  spew out an error message explicitly stating that it is ignoring the if eqns. when conditional variable has higher variability than "parameter".

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