Changeset 1941

Show
Ignore:
Timestamp:
12/03/2008 11:21:11 AM (5 weeks ago)
Author:
rfranke
Message:

Factor mass and energy balances out of pipe models, use new Volumes/BaseClasses/PartialDistributedVolume instead.

Location:
Modelica_Fluid/branches/StreamConnector/Modelica_Fluid
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • Modelica_Fluid/branches/StreamConnector/Modelica_Fluid/Junctions.mo

    r1940 r1941  
    4343    "Splitting/joining component with static balances for a dynamic control volume" 
    4444    extends BaseClasses.PartialTJunction; 
    45     extends Volumes.BaseClasses.PartialLumpedVolume; 
     45    extends Volumes.BaseClasses.PartialLumpedVolume(Qs_flow = 0); 
    4646 
    4747    parameter SI.Volume V "Mixing volume inside junction"; 
     
    100100              + port_3.m_flow*actualStream(port_3.h_outflow); 
    101101    Ws_flow = 0; 
    102     Qs_flow = 0; 
    103102 
    104103    annotation (Documentation(info="<html> 
  • Modelica_Fluid/branches/StreamConnector/Modelica_Fluid/Pipes.mo

    r1940 r1941  
    44 
    55  model StaticPipe "Basic pipe flow model without storage of mass or energy" 
    6     extends Modelica_Fluid.Pipes.BaseClasses.PartialPipe( 
     6    extends Modelica_Fluid.Pipes.BaseClasses.PartialTwoPortFlow( 
    77                                           redeclare model HeatTransfer =  
    88          BaseClasses.HeatTransfer.PipeHT_ideal,                                                               final 
     
    5353 
    5454    // Extend here to get right ordering in parameter box 
    55     extends Modelica_Fluid.Pipes.BaseClasses.PartialPipe; 
     55    extends Modelica_Fluid.Pipes.BaseClasses.PartialTwoPortFlow; 
    5656 
    5757     //Initialization 
     
    197197   extends Modelica_Fluid.Pipes.BaseClasses.PartialDistributedFlow( 
    198198     Qs_flow=heatTransfer.Q_flow, 
    199      Ws_flow=zeros(n), 
    200      ms_flow=zeros(n), 
    201      msXi_flow=zeros(n, Medium.nXi), 
    202      Vi=ones(n)*V/n, 
    203199     final port_a_exposesState = (modelStructure == ModelStructure.av_b) or (modelStructure == ModelStructure.avb), 
    204200     final port_b_exposesState = (modelStructure == ModelStructure.a_vb) or (modelStructure == ModelStructure.avb)); 
     
    251247of the modeller. Use a Junctions.MultiPort. 
    252248"); 
     249 
     250   Ws_flow=zeros(n); 
     251   fluidVolume=ones(n)*V/n; 
    253252 
    254253   //Momentum Balance, dp contains contributions from acceleration, gravitational and friction effects 
     
    394393  extends Modelica_Fluid.Pipes.BaseClasses.PartialDistributedFlow( 
    395394    Qs_flow=heatTransfer.Q_flow, 
    396     Ws_flow=zeros(n), 
    397     ms_flow=zeros(n), 
    398     msXi_flow=zeros(n, Medium.nXi), 
    399     Vi=ones(n)*V/n, 
    400395    final port_a_exposesState = (modelStructure == ModelStructure.av_b) or (modelStructure == ModelStructure.avb), 
    401396    final port_b_exposesState = (modelStructure == ModelStructure.a_vb) or (modelStructure == ModelStructure.avb)); 
     
    450445of the modeller. Use a Junctions.MultiPort. 
    451446"); 
     447 
     448    Ws_flow=zeros(n); 
     449    fluidVolume=ones(n)*V/n; 
    452450 
    453451    //Pressure drop and gravity 
     
    720718    extends Modelica_Fluid.Icons.BaseClassLibrary; 
    721719 
    722     partial model PartialPipe "Base class for one dimensional flow models" 
     720    partial model PartialTwoPortFlow 
     721      "Base class for one dimensional flow models" 
    723722      extends Modelica_Fluid.Interfaces.PartialTwoPort; 
    724723 
     
    825824            grid={1,1}), graphics)); 
    826825 
    827     end PartialPipe; 
     826    end PartialTwoPortFlow; 
    828827 
    829828  partial model PartialDistributedFlow 
     
    831830      import Modelica_Fluid.Types; 
    832831 
    833     parameter Modelica_Fluid.Types.Dynamics dynamicsType=system.dynamicsType 
    834         "Dynamics option"  
    835       annotation(Evaluate=true, Dialog(tab = "Assumptions")); 
     832    extends Modelica_Fluid.Volumes.BaseClasses.PartialDistributedVolume(final n = nNodes); 
     833    extends Modelica_Fluid.Pipes.BaseClasses.PartialTwoPortFlow; 
    836834 
    837835  //Discretization 
    838836    parameter Integer nNodes(min=1)=1 "Number of discrete flow volumes"; 
    839     final parameter Integer n = nNodes; 
    840  
    841     final parameter Boolean static = dynamicsType == Types.Dynamics.SteadyState 
    842         "= true, static balances, no mass or energy is stored"  
    843                                   annotation(Dialog(tab="Assumptions"),Evaluate=true); 
    844  
    845   //Initialization 
    846     parameter Types.Init initType=system.initType "Initialization option"  
    847         annotation(Evaluate=true, Dialog(tab = "Initialization")); 
    848  
    849     // Extend here to get right ordering in parameter box 
    850     extends Modelica_Fluid.Pipes.BaseClasses.PartialPipe; 
    851  
    852     final parameter Medium.AbsolutePressure[n] p_start=if n > 1 then linspace( 
    853           p_a_start - (p_a_start - p_b_start)/(2*n), 
    854           p_b_start + (p_a_start - p_b_start)/(2*n), 
    855           n) else {(p_a_start + p_b_start)/2} "Start value of pressure"; 
    856  
    857     parameter Boolean use_T_start=true "Use T_start if true, otherwise h_start" 
    858        annotation(Evaluate=true, Dialog(tab = "Initialization")); 
    859     parameter Medium.Temperature T_start=if use_T_start then system.T_start else  
    860                 Medium.temperature_phX( 
    861           (p_a_start + p_b_start)/2, 
    862           h_start, 
    863           X_start) "Start value of temperature"  
    864       annotation(Evaluate=true, Dialog(tab = "Initialization", enable = use_T_start)); 
    865     parameter Medium.SpecificEnthalpy h_start=if use_T_start then  
    866           Medium.specificEnthalpy_pTX( 
    867           (p_a_start + p_b_start)/2, 
    868           T_start, 
    869           X_start) else Medium.h_default "Start value of specific enthalpy"  
    870       annotation(Evaluate=true, Dialog(tab = "Initialization", enable = not use_T_start)); 
    871     parameter Medium.MassFraction X_start[Medium.nX]=Medium.X_default 
    872         "Start value of mass fractions m_i/m"  
    873       annotation (Dialog(tab="Initialization", enable=Medium.nXi > 0)); 
    874837 
    875838  //Advanced model options 
     
    877840        "=true, port properties for pressure drop correlation are taken from neighboring control volume" 
    878841                                                                                                       annotation(Dialog(tab="Advanced", group="Pressure loss"),Evaluate=true); 
    879     input SI.Volume[n] Vi "Discretized volume, determine in inheriting class "; 
    880  
    881   //Total quantities 
    882     SI.Energy[n] U "Internal energy of fluid"; 
    883     SI.Mass[n] m "Fluid mass"; 
    884     SI.Mass[n,Medium.nXi] mXi "Substance mass"; 
    885  
    886842  //Flow quantities 
    887843    Medium.MassFlowRate[n + 1] m_flow(each min=if allowFlowReversal then -Modelica.Constants.inf else  
     
    894850        "Enthalpy flow rates of fluid across segment boundaries"; 
    895851 
    896     Medium.BaseProperties[n] medium( 
    897       each preferredMediumStates=if static then false else true, 
    898       p(start=p_start), 
    899       each h(start=h_start), 
    900       each T(start=T_start), 
    901       each Xi(start=X_start[1:Medium.nXi])); 
    902852    Medium.AbsolutePressure[n] p = medium.p "Pressure states"; 
    903853 
    904854    //Source terms, have to be set in inheriting class (to zero if not used) 
    905855    protected 
    906     input Medium.MassFlowRate[n] ms_flow "Mass flow rate, source or sink"; 
    907     input Medium.MassFlowRate[n,Medium.nXi] msXi_flow 
    908         "Independent mass flow rates, source or sink"; 
    909     input SI.HeatFlowRate[n] Qs_flow "Heat flow rate, source or sink"; 
    910     input SI.Power[n] Ws_flow "Mechanical power, p*der(V) etc."; 
    911856    SI.Density[n] d=if use_d_nominal then ones(n)*d_nominal else medium.d; 
    912857    SI.Density d_a=if use_d_nominal then d_nominal else (if use_approxPortProperties then d[1] else Medium.density_phX(port_a.p, inStream(port_a.h_outflow), inStream(port_a.Xi_outflow))); 
     
    937882    v[n + 1] = m_flow[n + 1]/(d[n] + d_b)*2/crossArea; 
    938883 
    939     // Total quantities 
     884    //Mass and energy balances 
     885    //dynamic mass balances, n "thermal" states, n pressure states (if not singleState_hydraulic) 
    940886    for i in 1:n loop 
    941       m[i] =Vi[i]*medium[i].d; 
    942       mXi[i, :] = m[i]*medium[i].Xi; 
    943       U[i] = m[i]*medium[i].u; 
     887      ms_flow[i] = m_flow[i] - m_flow[i + 1]; 
     888      msXi_flow[i, :] = mXi_flow[i, :] - mXi_flow[i + 1, :]; 
    944889    end for; 
    945  
    946     //Mass and energy balances 
    947     if dynamicsType < Types.Dynamics.SteadyStateMass then 
    948     //dynamic mass balances, n "thermal" states, n pressure states (if not singleState_hydraulic) 
    949       for i in 1:n loop 
    950         der(m[i]) = m_flow[i] - m_flow[i + 1] + ms_flow[i]; 
    951         der(mXi[i, :]) = mXi_flow[i, :] - mXi_flow[i + 1, :] + msXi_flow[i, :]; 
    952       end for; 
    953     else 
    954     //steady state mass balances, no numerical states, no flow reversal possible 
    955       for i in 1:n loop 
    956         0 = m_flow[i] - m_flow[i + 1] + ms_flow[i]; 
    957         zeros(Medium.nXi) = mXi_flow[i, :] - mXi_flow[i + 1, :] + msXi_flow[i, :]; 
    958       end for; 
    959     end if; 
    960     if dynamicsType < Types.Dynamics.SteadyState then 
    961890    //dynamic energy balances, n "thermal" states, n pressure states (if not singleState_hydraulic) 
    962       for i in 1:n loop 
    963         der(U[i]) = H_flow[i] - H_flow[i + 1] + Qs_flow[i]; 
    964       end for; 
    965     else 
    966     //steady state energy balances, no numerical states, no flow reversal possible 
    967       for i in 1:n loop 
    968         0 = H_flow[i] - H_flow[i + 1] + Qs_flow[i]; 
    969       end for; 
    970     end if; 
    971891    for i in 1:n loop 
    972       assert((allowFlowReversal and not static) or (m_flow[i] >= 0), "Flow reversal not allowed in distributed pipe"); 
     892      Hs_flow[i] = H_flow[i] - H_flow[i + 1]; 
    973893    end for; 
    974894 
    975   initial equation 
    976     // Initial conditions 
    977     if not static then 
    978       if initType == Types.Init.NoInit then 
    979       // no initial equations 
    980       elseif initType == Types.Init.SteadyState then 
    981       //steady state initialization 
    982         if use_T_start then 
    983           der(medium.T) = zeros(n); 
    984         else 
    985           der(medium.h) = zeros(n); 
    986         end if; 
    987         if not (Medium.singleState) then 
    988           der(medium.p) = zeros(n); 
    989         end if; 
    990         for i in 1:n loop 
    991           der(medium[i].Xi) = zeros(Medium.nXi); 
    992         end for; 
    993       elseif initType == Types.Init.InitialValues then 
    994       //Initialization with initial values 
    995         if use_T_start then 
    996           medium.T = ones(n)*T_start; 
    997         else 
    998           medium.h = ones(n)*h_start; 
    999         end if; 
    1000         if not Medium.singleState then 
    1001            medium.p=p_start; 
    1002         end if; 
    1003       elseif initType == Types.Init.SteadyStateHydraulic then 
    1004       //Steady state initialization for hydraulic states (p) 
    1005         if use_T_start then 
    1006           medium.T = ones(n)*T_start; 
    1007         else 
    1008           medium.h = ones(n)*h_start; 
    1009         end if; 
    1010         if not Medium.singleState then 
    1011           der(medium.p) = zeros(n); 
    1012         end if; 
    1013       else 
    1014         assert(false, "Unsupported initialization option"); 
    1015       end if; 
    1016     end if; 
    1017  
    1018      annotation (Diagram(coordinateSystem(preserveAspectRatio=true,  extent={{-100, 
     895    annotation (Diagram(coordinateSystem(preserveAspectRatio=true,  extent={{-100, 
    1019896                -100},{100,100}}), 
    1020897                         graphics), 
  • Modelica_Fluid/branches/StreamConnector/Modelica_Fluid/Test/TestCriticalCases.mo

    r1940 r1941  
    18501850            lineColor={0,0,255}, 
    18511851            textString= 
    1852                 "a) Select WallFriction = \"No pipe wall friction\" and it works!?"), 
     1852                "a) Select WallFriction = \"No pipe wall friction\" and it works!?"),  
     1853 
    18531854          Text( 
    18541855            extent={{-90,-20},{36,-38}}, 
    18551856            lineColor={0,0,255}, 
    18561857            textString= 
    1857                 "How to get correct result from steady-state initialization:"), 
     1858                "How to get correct result from steady-state initialization:"),  
     1859 
    18581860          Text( 
    18591861            extent={{-57,-64},{92,-72}}, 
  • Modelica_Fluid/branches/StreamConnector/Modelica_Fluid/Volumes.mo

    r1940 r1941  
    657657            lineColor={0,0,0}, 
    658658            textString=DynamicSelect(" ", realString( 
    659                 level, 
    660                 1, 
     659                level,  
     660                1,  
    661661                3))), 
    662662          Line( 
     
    873873The following source terms are part of the energy balance and must be specified in an extending class: 
    874874<ul> 
    875 <li><tt>Qs_flow</tt>, e.g. convective or latent heat flow rate across segment boundary, and</li>  
    876 <li><tt>Ws_flow</tt>, work term, e.g. p*der(fluidVolume) if the volume is not constant.</li> 
     875<li><tt><b>input Qs_flow</b></tt>, e.g. convective or latent heat flow rate across segment boundary, and</li>  
     876<li><tt><b>Ws_flow</b></tt>, work term, e.g. p*der(fluidVolume) if the volume is not constant.</li> 
    877877</ul> 
    878 The component volume <tt>fluidVolume</tt> is a variable which needs to be set in the extending class to complete the model. 
     878The component volume <tt><b>fluidVolume</b></tt> is a variable which needs to be set in the extending class to complete the model. 
     879<p> 
    879880Further source terms must be defined by an extending class for fluid flow across the segment boundary: 
     881</p> 
    880882<ul> 
    881 <li><tt>Hs_flow</tt>, enthalpy flow,</li>  
    882 <li><tt>ms_flow</tt>, mass flow, and</li>  
    883 <li><tt>msXi_flow</tt>, substance mass flow.</li>  
     883<li><tt><b>Hs_flow</b></tt>, enthalpy flow,</li>  
     884<li><tt><b>ms_flow</b></tt>, mass flow, and</li>  
     885<li><tt><b>msXi_flow</b></tt>, substance mass flow.</li>  
    884886</ul> 
     887<b>Note:</b> 
     888<p> 
     889<tt>Qs_flow</tt> is defined as input allowing its definition and modification by extending classes, e.g. to add a HeatPort to an existing model. 
     890</p> 
     891<p> 
     892<tt>Hs_flow</tt> is not defined as input as it needs to be defined carefully together with <tt>ms_flow</tt> and modifications can easily lead to bad models.  
     893Moreover an input might mislead a tool to break equation systems, resulting in inefficient models for the treatment of flow reversal.  
     894</p> 
    885895</html>"),Diagram(coordinateSystem(preserveAspectRatio=true,  extent={{-100, 
    886896                -100},{100,100}}), 
     
    11571167              extent={{-100,-100},{100,100}}), graphics), 
    11581168        Documentation(info="<html> 
    1159 <p>The model <b>PartialDistributedVolume</b> provides a one-dimensional spatial discretization according to the finite volume method. 
    1160 The total volume is divided into <tt><b>n</b></tt> segments.</p> 
    1161   
    1162 <p><b>Mass and energy balances</b></p> 
    1163 <p>One total mass and one energy balance is formed across each segment. If the medium contains more than one component, substance mass balances are added. Changes in potential and kinetic energy are neglected in the energy balance. The following source (or sink) terms are used in the balances and must be specified in extending models to complete this partial class:</p> 
     1169Base class for <tt><b>n</b></tt> ideally mixed fluid volumes with the ability to store mass and energy. 
     1170It is inteded to model a one-dimensional spatial discretization of fluid flow according to the finite volume method.  
     1171The following source terms are part of the energy balance and must be specified in an extending class: 
    11641172<ul> 
    1165 <li>Energy balance: <tt><b>Qs_flow</b></tt>, e.g. convective or latent heat flow rate across segment boundary, and <tt><b>Ws_flow</b></tt>, e.g. mechanical power</li> 
    1166 <li>Total mass balance: <tt><b>ms_flow</b></tt>, e.g. condensing mass flow of negligible volume such as water in moist air</li> 
    1167 <li>Substance mass balance: <tt><b>msXi_flow</b></tt>, as above</li> 
     1173<li><tt><b>input Qs_flow[n]</b></tt>, e.g. convective or latent heat flow rate across segment boundary, and</li>  
     1174<li><tt><b>Ws_flow[n]</b></tt>, work term, e.g. p*der(fluidVolume) if the volume is not constant.</li> 
    11681175</ul> 
    1169 If the <tt>dynamicsType</tt> is <b>DynamicsType.SteadyState</b> then no mass or energy is stored in the component and the mass and energy balances are reduced to a quasi steady-state formulation. It should be noted that dynamic balances are required if flow reversal should be allowed. 
    1170 <p>An extending class shall define volume vector <tt><b>fluidVolume</b></tt>, which specifies the volume of each segment, and the mass flow rates <tt><b>m_flow</b></tt> through a mementum balance. 
    1171   
    1172 <p><b>Momentum balance</b></p> 
    1173 <p>The momentum balance needs to be defined by an extending class.</p>  
    1174   
    1175 </html>",   revisions="<html> 
     1176The component volume <tt><b>fluidVolume[n]</b></tt> is a variable which needs to be set in the extending class to complete the model. 
     1177<p> 
     1178Further source terms must be defined by an extending class for fluid flow across the segment boundary: 
     1179</p> 
    11761180<ul> 
    1177 <li><i>3 Dec 2008</i> 
    1178     by R&uuml;diger Franke:<br> 
    1179        Derived from PartialDistributedFlow by</li> 
    1180 <li><i>04 Mar 2006</i> 
    1181     by Katrin Pr&ouml;l&szlig;:<br> 
    1182        Model added to the Fluid library</li> 
     1181<li><tt><b>Hs_flow[n]</b></tt>, enthalpy flow,</li>  
     1182<li><tt><b>ms_flow[n]</b></tt>, mass flow, and</li>  
     1183<li><tt><b>msXi_flow[n]</b></tt>, substance mass flow.</li>  
    11831184</ul> 
     1185<b>Note:</b> 
     1186<p> 
     1187<tt>Qs_flow</tt> is defined as input allowing its definition and modification by extending classes, e.g. to add a HeatPort to an existing model. 
     1188</p> 
     1189<p> 
     1190<tt>Hs_flow</tt> is not defined as input as it needs to be defined carefully together with <tt>ms_flow</tt> and modifications can easily lead to bad models.  
     1191Moreover an input might mislead a tool to break equation systems, resulting in inefficient models for the treatment of flow reversal.  
     1192</p> 
    11841193</html>")); 
    11851194  end PartialDistributedVolume;