Changeset 1941
- Timestamp:
- 12/03/2008 11:21:11 AM (5 weeks ago)
- Location:
- Modelica_Fluid/branches/StreamConnector/Modelica_Fluid
- Files:
-
- 4 modified
-
Junctions.mo (modified) (2 diffs)
-
Pipes.mo (modified) (12 diffs)
-
Test/TestCriticalCases.mo (modified) (1 diff)
-
Volumes.mo (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
Modelica_Fluid/branches/StreamConnector/Modelica_Fluid/Junctions.mo
r1940 r1941 43 43 "Splitting/joining component with static balances for a dynamic control volume" 44 44 extends BaseClasses.PartialTJunction; 45 extends Volumes.BaseClasses.PartialLumpedVolume ;45 extends Volumes.BaseClasses.PartialLumpedVolume(Qs_flow = 0); 46 46 47 47 parameter SI.Volume V "Mixing volume inside junction"; … … 100 100 + port_3.m_flow*actualStream(port_3.h_outflow); 101 101 Ws_flow = 0; 102 Qs_flow = 0;103 102 104 103 annotation (Documentation(info="<html> -
Modelica_Fluid/branches/StreamConnector/Modelica_Fluid/Pipes.mo
r1940 r1941 4 4 5 5 model StaticPipe "Basic pipe flow model without storage of mass or energy" 6 extends Modelica_Fluid.Pipes.BaseClasses.Partial Pipe(6 extends Modelica_Fluid.Pipes.BaseClasses.PartialTwoPortFlow( 7 7 redeclare model HeatTransfer = 8 8 BaseClasses.HeatTransfer.PipeHT_ideal, final … … 53 53 54 54 // Extend here to get right ordering in parameter box 55 extends Modelica_Fluid.Pipes.BaseClasses.Partial Pipe;55 extends Modelica_Fluid.Pipes.BaseClasses.PartialTwoPortFlow; 56 56 57 57 //Initialization … … 197 197 extends Modelica_Fluid.Pipes.BaseClasses.PartialDistributedFlow( 198 198 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,203 199 final port_a_exposesState = (modelStructure == ModelStructure.av_b) or (modelStructure == ModelStructure.avb), 204 200 final port_b_exposesState = (modelStructure == ModelStructure.a_vb) or (modelStructure == ModelStructure.avb)); … … 251 247 of the modeller. Use a Junctions.MultiPort. 252 248 "); 249 250 Ws_flow=zeros(n); 251 fluidVolume=ones(n)*V/n; 253 252 254 253 //Momentum Balance, dp contains contributions from acceleration, gravitational and friction effects … … 394 393 extends Modelica_Fluid.Pipes.BaseClasses.PartialDistributedFlow( 395 394 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,400 395 final port_a_exposesState = (modelStructure == ModelStructure.av_b) or (modelStructure == ModelStructure.avb), 401 396 final port_b_exposesState = (modelStructure == ModelStructure.a_vb) or (modelStructure == ModelStructure.avb)); … … 450 445 of the modeller. Use a Junctions.MultiPort. 451 446 "); 447 448 Ws_flow=zeros(n); 449 fluidVolume=ones(n)*V/n; 452 450 453 451 //Pressure drop and gravity … … 720 718 extends Modelica_Fluid.Icons.BaseClassLibrary; 721 719 722 partial model PartialPipe "Base class for one dimensional flow models" 720 partial model PartialTwoPortFlow 721 "Base class for one dimensional flow models" 723 722 extends Modelica_Fluid.Interfaces.PartialTwoPort; 724 723 … … 825 824 grid={1,1}), graphics)); 826 825 827 end Partial Pipe;826 end PartialTwoPortFlow; 828 827 829 828 partial model PartialDistributedFlow … … 831 830 import Modelica_Fluid.Types; 832 831 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; 836 834 837 835 //Discretization 838 836 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.SteadyState842 "= true, static balances, no mass or energy is stored"843 annotation(Dialog(tab="Assumptions"),Evaluate=true);844 845 //Initialization846 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 box850 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 else860 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 then866 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_default872 "Start value of mass fractions m_i/m"873 annotation (Dialog(tab="Initialization", enable=Medium.nXi > 0));874 837 875 838 //Advanced model options … … 877 840 "=true, port properties for pressure drop correlation are taken from neighboring control volume" 878 841 annotation(Dialog(tab="Advanced", group="Pressure loss"),Evaluate=true); 879 input SI.Volume[n] Vi "Discretized volume, determine in inheriting class ";880 881 //Total quantities882 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 886 842 //Flow quantities 887 843 Medium.MassFlowRate[n + 1] m_flow(each min=if allowFlowReversal then -Modelica.Constants.inf else … … 894 850 "Enthalpy flow rates of fluid across segment boundaries"; 895 851 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]));902 852 Medium.AbsolutePressure[n] p = medium.p "Pressure states"; 903 853 904 854 //Source terms, have to be set in inheriting class (to zero if not used) 905 855 protected 906 input Medium.MassFlowRate[n] ms_flow "Mass flow rate, source or sink";907 input Medium.MassFlowRate[n,Medium.nXi] msXi_flow908 "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.";911 856 SI.Density[n] d=if use_d_nominal then ones(n)*d_nominal else medium.d; 912 857 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))); … … 937 882 v[n + 1] = m_flow[n + 1]/(d[n] + d_b)*2/crossArea; 938 883 939 // Total quantities 884 //Mass and energy balances 885 //dynamic mass balances, n "thermal" states, n pressure states (if not singleState_hydraulic) 940 886 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, :]; 944 889 end for; 945 946 //Mass and energy balances947 if dynamicsType < Types.Dynamics.SteadyStateMass then948 //dynamic mass balances, n "thermal" states, n pressure states (if not singleState_hydraulic)949 for i in 1:n loop950 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 else954 //steady state mass balances, no numerical states, no flow reversal possible955 for i in 1:n loop956 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 then961 890 //dynamic energy balances, n "thermal" states, n pressure states (if not singleState_hydraulic) 962 for i in 1:n loop963 der(U[i]) = H_flow[i] - H_flow[i + 1] + Qs_flow[i];964 end for;965 else966 //steady state energy balances, no numerical states, no flow reversal possible967 for i in 1:n loop968 0 = H_flow[i] - H_flow[i + 1] + Qs_flow[i];969 end for;970 end if;971 891 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]; 973 893 end for; 974 894 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, 1019 896 -100},{100,100}}), 1020 897 graphics), -
Modelica_Fluid/branches/StreamConnector/Modelica_Fluid/Test/TestCriticalCases.mo
r1940 r1941 1850 1850 lineColor={0,0,255}, 1851 1851 textString= 1852 "a) Select WallFriction = \"No pipe wall friction\" and it works!?"), 1852 "a) Select WallFriction = \"No pipe wall friction\" and it works!?"), 1853 1853 1854 Text( 1854 1855 extent={{-90,-20},{36,-38}}, 1855 1856 lineColor={0,0,255}, 1856 1857 textString= 1857 "How to get correct result from steady-state initialization:"), 1858 "How to get correct result from steady-state initialization:"), 1859 1858 1860 Text( 1859 1861 extent={{-57,-64},{92,-72}}, -
Modelica_Fluid/branches/StreamConnector/Modelica_Fluid/Volumes.mo
r1940 r1941 657 657 lineColor={0,0,0}, 658 658 textString=DynamicSelect(" ", realString( 659 level, 660 1, 659 level, 660 1, 661 661 3))), 662 662 Line( … … 873 873 The following source terms are part of the energy balance and must be specified in an extending class: 874 874 <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> 877 877 </ul> 878 The component volume <tt>fluidVolume</tt> is a variable which needs to be set in the extending class to complete the model. 878 The 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> 879 880 Further source terms must be defined by an extending class for fluid flow across the segment boundary: 881 </p> 880 882 <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> 884 886 </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. 893 Moreover an input might mislead a tool to break equation systems, resulting in inefficient models for the treatment of flow reversal. 894 </p> 885 895 </html>"),Diagram(coordinateSystem(preserveAspectRatio=true, extent={{-100, 886 896 -100},{100,100}}), … … 1157 1167 extent={{-100,-100},{100,100}}), graphics), 1158 1168 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> 1169 Base class for <tt><b>n</b></tt> ideally mixed fluid volumes with the ability to store mass and energy. 1170 It is inteded to model a one-dimensional spatial discretization of fluid flow according to the finite volume method. 1171 The following source terms are part of the energy balance and must be specified in an extending class: 1164 1172 <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> 1168 1175 </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> 1176 The 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> 1178 Further source terms must be defined by an extending class for fluid flow across the segment boundary: 1179 </p> 1176 1180 <ul> 1177 <li><i>3 Dec 2008</i> 1178 by Rüdiger Franke:<br> 1179 Derived from PartialDistributedFlow by</li> 1180 <li><i>04 Mar 2006</i> 1181 by Katrin Prölß:<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> 1183 1184 </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. 1191 Moreover an input might mislead a tool to break equation systems, resulting in inefficient models for the treatment of flow reversal. 1192 </p> 1184 1193 </html>")); 1185 1194 end PartialDistributedVolume;
