我有一个坦克模型,我正在创建如下:
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";
Real pressure(start=static_pressure) "Pressure inside the tank";
initial equation
level = initial_level;
/* Pressure */
equation
pressure = vol * 0.01; // Add correct factor here to get from volume to pressure change (based on height and head)
for i in 1:num_ports loop
ports[i].pressure = static_pressure + pressure;
end for;
/* Volume Flow */
equation
der(vol) = sum(ports.m_flow); // Add density factor to get form mass flow to Volume Flow
level = vol * 100 / volume;
end Tank;
我怎样才能做到这一点,当水平< = 0时,水箱不允许任何具有负值的流量(没有流体可以让流体离开,但流体仍然可以进入)?我觉得我错过了一些微不足道的东西,但似乎找不到方法而没有太多的方程式(过度确定的系统)。
由于
答案 0 :(得分:1)
您可以尝试使用when等式:
when level < 0 then
reinit(level, 0)
end when;