用modelica用两流体六方程模型模拟一个自然循环过程
时间: 2023-05-31 16:06:33 浏览: 202
2维流体模拟程序
下面是一个用Modelica的两流体六方程模型模拟自然循环过程的示例代码:
```Modelica
model NaturalCirculation
// Fluid properties
Modelica.Media.Interfaces.PartialMedium air(redeclare package Medium = Modelica.Media.Air.StandardAtmospere);
Modelica.Media.Interfaces.PartialMedium water(redeclare package Medium = Modelica.Media.Water.ConstantPropertyLiquidWater);
// Parameters
parameter Real L = 10 "Length of the loop [m]";
parameter Real H = 1 "Height difference between the two ends of the loop [m]";
parameter Real D = 0.02 "Diameter of the loop [m]";
parameter Real rho_w = Modelica.Media.Water.IF97.d(T=293.15, p=101325) "Density of water [kg/m3]";
parameter Real g = 9.81 "Gravity acceleration [m/s2]";
// Variables
Real T_air "Temperature of the air [K]";
Real T_water "Temperature of the water [K]";
Real p_air "Pressure of the air [Pa]";
Real p_water "Pressure of the water [Pa]";
Real u_air "Velocity of the air [m/s]";
Real u_water "Velocity of the water [m/s]";
// Initial values
initial equation
T_air = 293.15;
T_water = 293.15;
p_air = 101325;
p_water = 101325;
u_air = 0;
u_water = 0;
// Equations
equation
// Mass conservation
m_flow_air*u_air*Modelica.Media.Air.StandardAtmosphere.rho(T=T_air, p=p_air)*Modelica.Constants.pi*D^2/4 =
m_flow_water*u_water*rho_w*Modelica.Constants.pi*D^2/4;
// Energy conservation
m_flow_air*Modelica.Media.Air.StandardAtmosphere.cp(T=T_air)*T_air*u_air*Modelica.Media.Air.StandardAtmosphere.rho(T=T_air, p=p_air)*Modelica.Constants.pi*D^2/4 +
m_flow_water*rho_w*Modelica.Media.Water.IF97.cp(T=T_water)*T_water*u_water*Modelica.Constants.pi*D^2/4 =
m_flow_air*Modelica.Media.Air.StandardAtmosphere.cp(T=T_air)*T_air*u_air*Modelica.Media.Air.StandardAtmosphere.rho(T=T_air, p=p_air)*Modelica.Constants.pi*D^2/4 +
m_flow_water*rho_w*Modelica.Media.Water.IF97.cp(T=T_water)*T_water*u_water*Modelica.Constants.pi*D^2/4 +
(m_flow_air*Modelica.Media.Air.StandardAtmosphere.rho(T=T_air, p=p_air)*Modelica.Constants.pi*D^2/4 +
m_flow_water*rho_w*Modelica.Constants.pi*D^2/4)*g*H;
// Pressure drop
p_air - p_water = Modelica.Fluid.Pipes.DynamicPressureLoss(m_flow_air, u_air, Modelica.Media.Air.StandardAtmosphere.mu(T=T_air), D, Modelica.Media.Air.StandardAtmosphere.rho(T=T_air, p=p_air)) -
Modelica.Fluid.Pipes.DynamicPressureLoss(m_flow_water, u_water, Modelica.Media.Air.StandardAtmosphere.mu(T=T_water), D, rho_w);
// Temperature difference
T_air - T_water = 0.5*(Modelica.Media.Air.StandardAtmosphere.cp(T=T_air)*u_air^2 - Modelica.Media.Water.IF97.cp(T=T_water)*u_water^2)/(m_flow_air*Modelica.Media.Air.StandardAtmosphere.rho(T=T_air, p=p_air) + m_flow_water*rho_w);
// Connections
Modelica.Fluid.Vessels.OpenTank tank1(nPorts=1, crossArea=Modelica.Constants.pi*D^2/4, height=H/2, redeclare package Medium=air) "Tank 1";
Modelica.Fluid.Vessels.OpenTank tank2(nPorts=1, crossArea=Modelica.Constants.pi*D^2/4, height=H/2, redeclare package Medium=water) "Tank 2";
Modelica.Fluid.Pipes.DynamicPipe pipe1(length=L/2, diameter=D, redeclare package Medium=air) "Pipe 1";
Modelica.Fluid.Pipes.DynamicPipe pipe2(length=L/2, diameter=D, redeclare package Medium=water) "Pipe 2";
connect(tank1.ports[1], pipe1.port_a);
connect(pipe1.port_b, tank2.ports[1]);
connect(tank2.ports[1], pipe2.port_a);
connect(pipe2.port_b, tank1.ports[1]);
// Mass flow rates
Modelica.Blocks.Continuous.MassFlowRate massFlowRate_air(m_flow=m_flow_air, redeclare package Medium=air) "Mass flow rate of air";
Modelica.Blocks.Continuous.MassFlowRate massFlowRate_water(m_flow=m_flow_water, redeclare package Medium=water) "Mass flow rate of water";
connect(massFlowRate_air.y, pipe1.m_flow);
connect(massFlowRate_air.y, pipe2.m_flow);
connect(massFlowRate_water.y, pipe1.m_flow);
connect(massFlowRate_water.y, pipe2.m_flow);
end NaturalCirculation;
```
该模型中定义了两个物质(空气和水)的流体属性和参数,以及系统的几何和工艺参数。通过质量守恒、能量守恒、压力变化和温度差等方程,模拟了两个开放式储罐和两个动态管道之间的自然对流过程。最后,将质量流量连通到管道的输入端口,以控制系统的质量流量。
阅读全文