我正在尝试使用Modelica解决我认为应该是一个简单的稳态组件分段问题,但我很难找到解决方案。
我准备了一个带有两个并联泵的示例案例,这些泵必须向系统提供目标总流量(vTotal)。一个泵是一个变频泵,输出与指令频率(fPump1)成比例的流量(v1),它可以在0和fMax之间变化。另一台泵是定速泵,每当它运行时输出一个固定的流量(v2IfRunning),当它没有运行时输出零流量。
目标是解决正在运行的泵的数量和变速泵频率。变速泵始终在运行,而定速泵仅在变速泵需要以大于fMax的频率运行时使用。我的示例代码如下:
model TwoPumpCode
// Pump 1
Modelica.SIunits.Frequency fPump1 "pump 1 frequency";
Modelica.SIunits.Frequency fMax = 50 "maximum frequency";
Modelica.SIunits.VolumeFlowRate v1;
// Pump 2
// Boolean runPump2(start=false) "true if pump 2 should run";
Modelica.SIunits.VolumeFlowRate v2IfRunning = 30;
Modelica.SIunits.VolumeFlowRate v2
"actual flow through pump 2";
Integer nPumpsRunning(start = 1) "number of pumps running";
// Total flow
Modelica.SIunits.VolumeFlowRate vTotal = 70;
equation
// Calculate the flow through pump 1 as a function of frequency
v1 = fPump1;
// Calculate the flow through pump 2 based upon running state
if fPump1 > fMax then
nPumpsRunning = 2;
v2 = v2IfRunning;
else
nPumpsRunning = 1;
v2 = 0;
end if;
// Calculate the total flow
vTotal = v1 + v2;
end TwoPumpCode;
同样,这是一个稳态模型。我已经尝试过使用if,when,reinit,用于pumpRunning状态的布尔变量,运行泵数量的整数变量等等,我仍然无法得到稳态解决方案来解决。
任何建议都将不胜感激。
谢谢, 贾斯汀
答案 0 :(得分:1)
我现在明白了。问题是我们需要分离变量。
model TwoPumpCode
Modelica.SIunits.VolumeFlowRate vTotal = 70-40*time;
model TwoPumpSimple
// Pump 1
Modelica.SIunits.Frequency fPump1 "pump 1 frequency";
Modelica.SIunits.Frequency fMax = 50 "maximum frequency";
Modelica.SIunits.VolumeFlowRate v1;
// Pump 2
// Boolean runPump2(start=false) "true if pump 2 should run";
Modelica.SIunits.VolumeFlowRate v2IfRunning = 30;
Modelica.SIunits.VolumeFlowRate v2
"actual flow through pump 2";
Integer nPumpsRunning(start = 1) "number of pumps running";
// Total flow
input Modelica.SIunits.VolumeFlowRate vTotal;
input Boolean activeSecond;
equation
// Calculate the flow through pump 1 as a function of frequency
v1 = fPump1;
// Calculate the flow through pump 2 based upon running state
if activeSecond then
nPumpsRunning = 2;
v2 = v2IfRunning;
else
nPumpsRunning = 1;
v2 = 0;
end if;
// Calculate the total flow
vTotal = v1 + v2;
end TwoPumpSimple;
//TwoPumpSimple first(vTotal=vTotal,activeSecond=first.fPump1>first.fMax);
TwoPumpSimple first(vTotal=vTotal,activeSecond=false);
TwoPumpSimple second(vTotal=vTotal,activeSecond=first.fPump1>first.fMax);
end TwoPumpCode;
超出评论的行与第一个解决方案相同,并将其更改为离散问题 - 但该问题有时缺乏解决方案。
新版本执行以下操作: 1没有第二台泵需要多高的频率?
2我们应该激活第二台泵吗?
3计算新频率 - 基于此。
在决定中添加一些滞后将产生类似的效果。
答案 1 :(得分:1)
根据matth的反馈,我能够使用基于Modelica.Blocks.Logical.OnOffController的示例的pre()运算符。功能代码如下所示,以供参考。
model TwoPumpCode_matth
// Pump 1
Modelica.SIunits.Frequency fPump1 "pump 1 frequency";
Modelica.SIunits.Frequency fMax = 50 "maximum frequency";
Modelica.SIunits.VolumeFlowRate v1;
// Pump 2
parameter Boolean runPump2InitialValue = false;
Boolean runPump2(start=runPump2InitialValue) "true if pump 2 should run";
Modelica.SIunits.VolumeFlowRate v2IfRunning = 30;
Modelica.SIunits.VolumeFlowRate v2 "actual flow through pump 2";
// Total flow
Modelica.SIunits.VolumeFlowRate vTotal = 70;
initial equation
pre(runPump2) = runPump2InitialValue;
equation
// Calculate the flow through pump 1 as a function of frequency
v1 = fPump1;
// Calculate the flow through pump 2 based upon running state
runPump2 = pre(runPump2) or (fPump1 > fMax);
if runPump2 then
v2 = v2IfRunning;
else
v2 = 0;
end if;
// Calculate the total flow
vTotal = v1 + v2;
end TwoPumpCode_matth;