为 heatPort 开关建模

Modelling a heatPort switch

我正在尝试对一个开关建模以在 prescribedHeatFlowprescribedTemperature 之间交换。因此,我尝试了以下模型:

model HeatSwitch
  extends Modelica.Blocks.Interfaces.partialBooleanBlockIcon;


  Modelica.Blocks.Interfaces.RealInput Q_flow_in(unit="W")
    "Connector of first Real input signal"
    annotation (Placement(transformation(extent={{-140,60},{-100,100}})));
  Modelica.Blocks.Interfaces.BooleanInput u2 "If true use Q_flow_in, else T_in"
    annotation (Placement(transformation(extent={{-140,-20},{-100,20}})));
  Modelica.Blocks.Interfaces.RealInput T_in(unit="K", displayUnit="degC")
    "Connector of second Real input signal"
    annotation (Placement(transformation(extent={{-140,-100},{-100,-60}})));

  Modelica.Thermal.HeatTransfer.Interfaces.HeatPort_b port
    annotation (Placement(transformation(extent={{82,-18},{116,16}})));

equation 
  if u2 then
    port.Q_flow = -Q_flow_in;
  else
    port.T = T_in;
  end if;

  annotation (
    Diagram(coordinateSystem(preserveAspectRatio=false, extent={{-100,-80},{100,
            80}})),
    Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,-80},{100,80}}),
        graphics={
        Line(points={{12.0,0.0},{100.0,0.0}}, color={191,0,0}),
        Line(points={{-100.0,0.0},{-40.0,0.0}}, color={255,0,255}),
        Line(points={{-100.0,-80.0},{-40.0,-80.0},{-40.0,-80.0}}, color={191,0,0}),
        Line(points={{-40.0,12.0},{-40.0,-12.0}}, color={255,0,255}),
        Line(points={{-100.0,80.0},{-38.0,80.0}}, color={191,0,0}),
        Line(
          points={{-38.0,80.0},{6.0,2.0}},
          color={191,0,0},
          thickness=1.0),
        Ellipse(
          lineColor={0,0,255},
          pattern=LinePattern.None,
          fillPattern=FillPattern.Solid,
          extent={{2.0,-8.0},{18.0,8.0}})}),
    Documentation(info="<html>
 </html>", revisions="<html>
 </html>"));

end HeatSwitch;

下面的测试模型是一个小例子: 型号 TestHeatFlowSwitch

  Modelica.Blocks.Sources.Constant constHeatFlow(k=0)
    annotation (Placement(transformation(extent={{-72,16},{-56,32}})));
  HeatSwitch prescribedHeatSwitch
    annotation (Placement(transformation(extent={{-38,-10},{-26,0}})));
  Modelica.Blocks.Sources.Constant constTemp(k=293.15)
    annotation (Placement(transformation(extent={{-74,-54},{-54,-34}})));
  Modelica.Blocks.Sources.BooleanExpression boolForSwitch(y=time > 0.5)
    annotation (Placement(transformation(extent={{-74,-22},{-54,-2}})));
  Modelica.Thermal.HeatTransfer.Components.HeatCapacitor heatCapacitor(C=10000)
    annotation (Placement(transformation(extent={{10,2},{30,22}})));
equation 
  connect(constHeatFlow.y, prescribedHeatSwitch.Q_flow_in) annotation (Line(
        points={{-55.2,24},{-48,24},{-48,0},{-39.2,0}}, color={0,0,127}));
  connect(constTemp.y, prescribedHeatSwitch.T_in) annotation (Line(points={{-53,
          -44},{-44,-44},{-44,-10},{-39.2,-10}}, color={0,0,127}));
  connect(boolForSwitch.y, prescribedHeatSwitch.u2) annotation (Line(points={{-53,
          -12},{-48,-12},{-48,-5},{-39.2,-5}}, color={255,0,255}));
  connect(prescribedHeatSwitch.port, heatCapacitor.port) annotation (Line(
        points={{-26.06,-5.0625},{20,-5.0625},{20,2}}, color={191,0,0}));
  annotation (uses(Modelica(version="3.2.2")));
end TestHeatFlowSwitch;

由于输入的离散变化,在模拟过程中会抛出错误。 主要是,我想用这个例子表达我的问题。现在我正在寻找一种聪明的方法来实现这样的模型。

非常感谢您提供任何有用的答案。

在当前的 Modelica (3.2.2) 中,无法在模拟期间将输入从交叉变量更改为流变量。在这种情况下,当分配的因果关系发生变化时,必须再次转换基本方程组。如果您渴望阅读有关此主题的更多信息:https://www.inf.ethz.ch/personal/cellier/PhD/zimmer_phd.pdf
在我看来Dymola竟然还要模拟模型,其实有点奇怪...

我认为从功率流切换到温度输入的最简单解决方案是向温度源添加 "thermal switch"。然后将开关和电源连接到热容量。开关本身可能类似于 MSL (Modelica.Electrical.Analog.Ideal.IdealOpeningSwitch) 中的电开关,在关闭时具有非常高的电阻,在打开时具有非常低的电阻。当开关处于关断状态时,几乎全部功率将转移到电容,如果它具有低电阻,则功率将转移到温度源并且容量将具有接近源之一的温度。