Search code examples
modelica

Modelling a heatPort switch


I am trying to model a switch to swap between a prescribedHeatFlow and a prescribedTemperature. Therefore, I tried the following model:

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;

The following test model is a small example: 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;

Due to discrete changes in the input, errors are thrown during the simulation. Mainly, I would like to express my problem with this example. Now I am looking for a smart way to implement such a model.

Thanks a lot in advance for any helpful answer.


Solution

  • In current Modelica (3.2.2) not possible to change the input from an across to a flow variable during simulation. In this case the underlying system of equations would have to be translated again as the causality of the assignments change. If you are eager to read more on this topic: https://www.inf.ethz.ch/personal/cellier/PhD/zimmer_phd.pdf
    It is actually a bit strange that Dymola even tries to simulate the model in my opinion...

    I think the easiest solution to switch from a power flow to a temperature input, would be to add a "thermal switch" to the source of temperature. Then connect the switch and the source of power-flow to the thermal capacity. The switch itself could be similar to the electric switch in the MSL (Modelica.Electrical.Analog.Ideal.IdealOpeningSwitch) having a very high resistance when turned off or very low resistance when turned on. When the switch is in off state nearly the full power would be transferred to the capacity, if it has low resistance, the power is transferred to the source of temperature and the capacity would have a temperature close to the one of the source.