我正在尝试创建流组件的模块化模拟(起初不使用标准 Modelica.Fluid,以方便学习和简化)。我决定从只担心质量流量(而不是温度/焓)开始,并创建了一个Stream
如下所示的连接器:
connector Stream
Real pressure;
flow Real m_flow;
end Stream;
使用此连接器,我想跟踪整个简单系统的压力和流量:
flow source >> valve >> tank >> pump >> flow sink
我为这些组件创建了以下模型:
model FlowSource "Flow Source can be used as a starting point of a flow"
parameter Real pressure = 1.0 "Pressure of the source";
Stream outlet;
equation
outlet.pressure = pressure;
end FlowSource;
model Valve
parameter Real Cv "Valve Coefficient, Cv";
Real setpoint(min=0,max=1) "Valve setpoint";
Real dp(start=1) "Pressure drop across the valve";
Real m(start=Cv) "Flow through the valve";
Real f(min=0,max=1) "Valve Characteristic f(setpoint)";
Stream inlet, outlet;
equation
inlet.m_flow + outlet.m_flow= 0.0; // Conservation of mass
dp = inlet.pressure - outlet.pressure; // Pressure drop calculation
f = setpoint; // linear valve
m = inlet.m_flow;
m = if(dp >= 0) then Cv*f*sqrt(dp) else -Cv*f*sqrt(-dp);
end Valve;
model Tank "Simple model of a tank"
parameter Real volume=1 "tank volume (m^3)";
parameter Integer num_ports=1 "Number of ports";
parameter Real static_pressure=1 "Internal Tank Pressure";
parameter Real initial_level = 0;
Stream[num_ports] ports "Stream Connectors";
Real level "Level in % 0-100";
protected
Real vol "Volume of medium in the tank";
initial equation
level = initial_level;
equation
for i in 1:num_ports loop
ports[i].pressure = static_pressure;
end for;
der(vol) = sum(ports.m_flow); // need to add density conversion
level = vol * 100 / volume;
end Tank;
model Pump "Simple model of a Pump"
Real setpoint(min=0,max=1) "setpoint of the pump (0.0 to 1.0)";
Stream inlet, outlet;
protected
Real dp "Pressure differential across the pump";
Real f "flow rate inside pump";
equation
inlet.m_flow+ outlet.m_flow= 0.0;
dp = outlet.pressure - inlet.pressure;
f = inlet.m_flow;
dp = (100-400*(f^2)); // insert better pump char. curve here
end Pump;
model FlowSource "Flow Source can be used as a starting point of a flow"
parameter Real pressure = 1.0 "Pressure of the source";
Stream outlet;
equation
outlet.pressure = pressure;
end FlowSource;
我可以创建这些模型的实例并将它们连接到一个单独的模型中。但是,我遇到了一个我认为是边界条件的问题。我想指定输入流体源的压力。然后,当流量流向油箱时,阀门将产生压降。这是由罐内标称压力和流体源之间的差异决定的,应该可以正常工作。
问题是当泵遇到流体槽时(或者如果我有一个泵直接进入水箱)。设置流体槽的压力会导致我的泵出现问题,因为它也会设置泵出口的压力(它们已连接)。泵的压力需要是入口压力和流量的函数(它应该给系统增加一些压力),并且水槽的压力应该基于此计算。然而,在计算 dp 时也需要这种压力......所以我最终绕了一圈。
我做错了什么,有没有更好的方法来实现这样的系统?
谢谢!
编辑:我忘了提到设定点(泵尚未实现)是在使用这些模型和方程的主模型中设置的。所以我所有的模型都是平衡的。(请参阅我对下面答案的评论)。