首页 > 解决方案 > 为 heatPort 开关建模

问题描述

我正在尝试对开关进行建模以在 aprescribedHeatFlow和 a之间进行交换prescribedTemperature。因此,我尝试了以下模型:

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;

下面的测试模型是一个小例子:model 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

解决方案


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

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


推荐阅读