1

Dear Modelica Users and Developers,

I am using the Standard Modelica.Fluid library to model a simple heat transfer problem with storages. After several unsuccessfull trials to set up a simple model I now tried to modify the examples until I am able to use it for my purpose.

Unfortunately if I start modifing and adappting things I often run into errors I am not able to solve.

My model is based on Modelica.Fluid.Examples.HeatingSystem. My aim is to build a model with two tanks, two pipes with heat exchange and two pumps which cycle the fluid. The two pumpes shell be controlled to regulate the mass flow in the pipes to provide a constant temperature to the fluid which is then stored in the tanks for further use. From my point of view this task should be a simple one using the Modelica.Fluid Library.

So first of all the question, if there are any good documentations to this Library (exept of the one which is officially, which I am already using). I am looking for some kind of FAQ or similar because my error messeages I get vary widely.

If I introduce a PI controler to meassure the temperature and controll the mass flow in the pipe, I often get following error message: (see also example below and 1)

Cannot reduce the DAE index and select states.
This is most likely due to non-differentiable functions.

Another message is concerning the use of modelicas homotrophy mode and a singular system:

Solving using global homotopy-method.
The following error was detected at time: 0
Error: Scalar system is always singular for pump.dp_pump = (homotopy(0.0, 0.0)-pump.W_single)/( -homotopy(1.25*pump.V_flow_single, 0.0)) = 0/-0
Error: Failed to start model.

Or I get somethin similar like this:

[...]abs(y0d) < 1E-015 or abs(y1d) < 1E-015
The following error was detected at time: 0
regFun3(): Derivatives at data points do not allow co-monotone interpolation, as both are non-zero, of opposite sign and have an absolute value larger than machine eps (y0d = -0.000690531, y1d = 0.999503). Please correct arguments.
The stack of functions is:
Modelica.Fluid.Utilities.regFun3
massFlowRate_dp_staticHead_Unique16
massFlowRate_dp_staticHead_Unique16(pipe1.flowModel.dps_fg[3], pipe1.flowModel.rhos[3], pipe1.flowModel.rhos[4], pipe1.flowModel.mus[3], pipe1.flowModel.mus[4], 0.25, pipe1.dimensions[2], 0.0, pipe1.crossAreas[2], pipe1.roughnesses[2], 0.3333333333333333*pipe1.flowModel.dp_small, 4000)
Non-linear solver will attempt to handle this problem.

ERROR: Failed to solve non-linear system using Newton solver.
To get more information: Turn on Simulation/Setup/Debug/Nonlinear solver diagnostics/Details
Solution to systems of equations not found at time = 0
   Nonlinear system of equations number = 1
   Infinity-norm of residue = 20
   Iteration is not making good progress.
   Accumulated number of residue       calc.: 1332
   Accumulated number of symbolic Jacobian calc.: 210
   Last values of solution vector:
pipe1.state_b.T = 300
   Last values of residual vector:
{ 20 }

Error: could not solve simplified initialization for homotopy method.
Error: could not solve simplified initialization for homotopy method.
Error: Failed to start model.

Since I would still call me a beginner to Modelica, I reached a "dead point" searching for solutions to this problems. Furthermore it is very hard to understand every model of the fluid library in detail. Maybe somebody could comment some of the error messages or give some advices on how to get into the Modelica Fluid Lib.

I would appreciate every kind of help for this issue. If you would like to get the model file to run it directly I could provide it to you to specifiy the problems.

I would be delighted if you can support me solving this issues.

Many thanks, Marius

To give one example: Here 1 is one of my current problems in detail (which is right now my biggest one). Without the controlled mass flow the model works perfectly. When I introduce the PI-Controller I get the error message:

Cannot reduce the DAE index and select states. This is most likely due to non-differentiable functions.

Cannot reduce the DAE index and select states. This is most likely due to non-differentiable functions.

Failed to reduce the DAE index.

The model is shown in Fig. (in comment) and the code is as follows:

model HeatingSystem_modified "Simple model of a heatstorage system"
  extends Modelica.Icons.Example;
   replaceable package Medium =
      CSP.Components.Media.linearMoltenSalt
     constrainedby Modelica.Media.Interfaces.PartialMedium;

  Modelica.Fluid.Vessels.OpenTank tank(
    redeclare package Medium = Medium,
    height=2,
    level_start=1,
    massDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    use_HeatTransfer=true,
    redeclare model HeatTransfer =
        Modelica.Fluid.Vessels.BaseClasses.HeatTransfer.IdealHeatTransfer (k=10),
    ports(each p(start=1e5)),
    T_start=Modelica.SIunits.Conversions.from_degC(20),
    portsData={Modelica.Fluid.Vessels.BaseClasses.VesselPortsData(diameter=0.01),
        Modelica.Fluid.Vessels.BaseClasses.VesselPortsData(diameter=0.01)},
    crossArea=1,
    nPorts=2) annotation (Placement(transformation(extent={{-40,64},{-20,84}},
          rotation=0)));
  Modelica.Fluid.Machines.ControlledPump pump(
    redeclare package Medium = Medium,
    N_nominal=1500,
    use_T_start=true,
    T_start=Modelica.SIunits.Conversions.from_degC(40),
    m_flow_start=0.01,
    m_flow_nominal=0.01,
    allowFlowReversal=false,
    use_m_flow_set=false,
    p_a_start=110000,
    p_b_start=130000,
    p_a_nominal=110000,
    p_b_nominal=130000,
    control_m_flow=true) annotation (Placement(transformation(extent={{20,50},{40,
            70}},     rotation=0)));
public 
  Modelica.Thermal.HeatTransfer.Sources.FixedHeatFlow burner(
    alpha=-0.5,
    Q_flow=1.6e4,
    T_ref=343.15)
    annotation (Placement(transformation(extent={{-122,-10},{-102,10}},
                                                                   rotation=0)));
  inner Modelica.Fluid.System system(
      m_flow_small=1e-4, energyDynamics=Modelica.Fluid.Types.Dynamics.SteadyStateInitial)
                        annotation (Placement(transformation(extent={{80,80},{100,
            100}},      rotation=0)));

protected 
  Modelica.Blocks.Interfaces.RealOutput T_forward
    annotation (Placement(transformation(extent={{114,-46},{126,-34}},
                                                                     rotation=
           0)));
public 
  Modelica.Fluid.Sensors.Temperature sensor_T_cold(redeclare package Medium =
        Medium) annotation (Placement(transformation(extent={{92,-50},{112,-30}},
          rotation=0)));
  Modelica.Fluid.Sensors.Temperature sensor_T_hot(redeclare package Medium =
        Medium) annotation (Placement(transformation(extent={{-72,10},{-52,30}},
          rotation=0)));

  Modelica.Fluid.Vessels.OpenTank tank1(
    redeclare package Medium = Medium,
    height=2,
    level_start=1,
    massDynamics=Modelica.Fluid.Types.Dynamics.FixedInitial,
    use_HeatTransfer=true,
    redeclare model HeatTransfer =
        Modelica.Fluid.Vessels.BaseClasses.HeatTransfer.IdealHeatTransfer (k=10),
    ports(each p(start=1e5)),
    T_start=Modelica.SIunits.Conversions.from_degC(20),
    portsData={Modelica.Fluid.Vessels.BaseClasses.VesselPortsData(diameter=0.01),
        Modelica.Fluid.Vessels.BaseClasses.VesselPortsData(diameter=0.01)},
    crossArea=1,
    nPorts=2) annotation (Placement(transformation(extent={{20,-48},{40,-28}},
          rotation=0)));
  Modelica.Fluid.Machines.ControlledPump pump1(
    redeclare package Medium = Medium,
    N_nominal=1500,
    use_T_start=true,
    T_start=Modelica.SIunits.Conversions.from_degC(40),
    m_flow_start=0.01,
    allowFlowReversal=false,
    m_flow_nominal=0.1,
    control_m_flow=true,
    p_a_start=110000,
    p_b_start=130000,
    p_a_nominal=110000,
    p_b_nominal=130000,
    use_m_flow_set=true)
                        annotation (Placement(transformation(extent={{-20,-62},{
            -40,-42}},
                     rotation=0)));
  Modelica.Fluid.Pipes.DynamicPipe radiator(
    use_T_start=true,
    redeclare package Medium = Medium,
    length=10,
    T_start=Modelica.SIunits.Conversions.from_degC(40),
    redeclare model HeatTransfer =
        Modelica.Fluid.Pipes.BaseClasses.HeatTransfer.IdealFlowHeatTransfer,
    diameter=0.01,
    nNodes=1,
    redeclare model FlowModel =
        Modelica.Fluid.Pipes.BaseClasses.FlowModels.DetailedPipeFlow,
    use_HeatTransfer=true,
    modelStructure=Modelica.Fluid.Types.ModelStructure.a_v_b,
    p_a_start=110000) annotation (Placement(transformation(extent={{10,10},{-10,
            -10}},
          rotation=90,
        origin={76,0})));
  Modelica.Thermal.HeatTransfer.Sources.FixedTemperature T_ambient(T=system.T_ambient)
    annotation (Placement(transformation(extent={{-7,-7},{7,7}},     rotation=180,
        origin={127,0})));
  Modelica.Thermal.HeatTransfer.Components.ThermalConductor wall(G=1.6e3/20)
    annotation (Placement(transformation(
        origin={102,0},
        extent={{8,-10},{-8,10}},
        rotation=180)));
  Modelica.Fluid.Pipes.DynamicPipe heater(
    redeclare package Medium = Medium,
    use_T_start=true,
    T_start=Modelica.SIunits.Conversions.from_degC(80),
    length=2,
    redeclare model HeatTransfer =
        Modelica.Fluid.Pipes.BaseClasses.HeatTransfer.IdealFlowHeatTransfer,
    diameter=0.01,
    nNodes=1,
    redeclare model FlowModel =
        Modelica.Fluid.Pipes.BaseClasses.FlowModels.DetailedPipeFlow,
    use_HeatTransfer=true,
    modelStructure=Modelica.Fluid.Types.ModelStructure.a_v_b,
    p_a_start=130000) annotation (Placement(transformation(extent={{-10,-10},{10,
            10}},
          rotation=90,
        origin={-80,0})));
  Modelica.Blocks.Sources.RealExpression realExpression(y=90)
    annotation (Placement(transformation(extent={{-72,36},{-52,56}})));
  Modelica.Blocks.Math.Add add(k1=-1, k2=+1)
    annotation (Placement(transformation(extent={{-26,16},{-6,36}})));
  Modelica.Blocks.Continuous.PI PI(
    k=2,
    T=1,
    x_start=0,
    initType=Modelica.Blocks.Types.Init.NoInit)
    annotation (Placement(transformation(extent={{2,16},{22,36}})));
equation 

  connect(radiator.heatPorts[1], wall.port_a) annotation (Line(points={{80.4,-0.1},
          {88,-0.1},{88,9.99201e-016},{94,9.99201e-016},{94,0}}, color={127,0,0}));
  connect(wall.port_b, T_ambient.port) annotation (Line(points={{110,-9.99201e-016},
          {116,-9.99201e-016},{116,0},{120,0}}, color={191,0,0}));
  connect(heater.heatPorts[1], burner.port) annotation (Line(points={{-84.4,0.1},
          {-94,0.1},{-94,0},{-102,0}}, color={127,0,0}));
  connect(pump.port_b, radiator.port_a)
    annotation (Line(points={{40,60},{76,60},{76,10}}, color={0,127,255}));
  connect(pump1.port_a, tank1.ports[1])
    annotation (Line(points={{-20,-52},{28,-52},{28,-48}}, color={0,127,255}));
  connect(pump1.port_b, heater.port_a) annotation (Line(points={{-40,-52},{-80,-52},
          {-80,-10}},           color={0,127,255}));
  connect(sensor_T_cold.T, T_forward)
    annotation (Line(points={{109,-40},{120,-40}}, color={0,0,127}));
  connect(sensor_T_hot.port, heater.port_b)
    annotation (Line(points={{-62,10},{-62,10},{-80,10}}, color={0,127,255}));
  connect(sensor_T_cold.port, radiator.port_b) annotation (Line(points={{102,-50},
          {82,-50},{82,-10},{76,-10}}, color={0,127,255}));
  connect(heater.port_b, tank.ports[1]) annotation (Line(points={{-80,10},{-80,10},
          {-80,56},{-80,60},{-32,60},{-32,64}}, color={0,127,255}));
  connect(pump.port_a, tank.ports[2]) annotation (Line(points={{20,60},{-6,60},{
          -28,60},{-28,64}}, color={0,127,255}));
  connect(add.y, PI.u)
    annotation (Line(points={{-5,26},{-5,26},{0,26}}, color={0,0,127}));
  connect(PI.y, pump1.m_flow_set) annotation (Line(points={{23,26},{30,26},{30,-20},
          {-25,-20},{-25,-43.8}}, color={0,0,127}));
  connect(sensor_T_hot.T, add.u2)
    annotation (Line(points={{-55,20},{-28,20}}, color={0,0,127}));
  connect(realExpression.y, add.u1) annotation (Line(points={{-51,46},{-46,46},{
          -46,32},{-28,32}}, color={0,0,127}));
  connect(radiator.port_b, tank1.ports[2]) annotation (Line(points={{76,-10},{76,
          -10},{76,-34},{76,-50},{76,-52},{32,-52},{32,-48}}, color={0,127,255}));
  annotation (                             Documentation(info="<html>
<p>
Simple heating system with a closed flow cycle.
After 2000s of simulation time the valve fully opens. A simple idealized control is embedded
into the respective components, so that the heating system can be regulated with the valve:
the pump controls the pressure, the burner controls the temperature.
</p>
<p>
One can investigate the temperatures and flows for different settings of <code>system.energyDynamics</code>
(see Assumptions tab of the system object).</p>
<ul>
<li>With <code>system.energyDynamics==Types.Dynamics.FixedInitial</code> the states need to find their steady values during the simulation.</li>
<li>With <code>system.energyDynamics==Types.Dynamics.SteadyStateInitial</code> (default setting) the simulation starts in steady-state.</li>
<li>With <code>system.energyDynamics==Types.Dynamics.SteadyState</code> all but one dynamic states are eliminated.
    The left state <code>tank.m</code> is to account for the closed flow cycle. It is constant as outflow and inflow are equal
    in a steady-state simulation.</li>
</ul>
<p>
Note that a closed flow cycle generally causes circular equalities for the mass flow rates and leaves the pressure undefined.
This is why the tank.massDynamics, i.e., the tank level determining the port pressure, is modified locally to Types.Dynamics.FixedInitial.
</p>
<p>
Also note that the tank is thermally isolated against its ambient. This way the temperature of the tank is also
well defined for zero flow rate in the heating system, e.g., for valveOpening.offset=0 at the beginning of a simulation.
The pipe however is assumed to be perfectly isolated.
If steady-state values shall be obtained with the valve fully closed, then a thermal
coupling between the pipe and its ambient should be defined as well.
</p>
<p>
Moreover it is worth noting that the idealized direct connection between the heater and the pipe, resulting in equal port pressures,
is treated as high-index DAE, as opposed to a nonlinear equation system for connected pressure loss correlations. A pressure loss correlation
could be additionally introduced to model the fitting between the heater and the pipe, e.g., to adapt different diameters.
</p>

<img src=\"modelica://Modelica/Resources/Images/Fluid/Examples/HeatingSystem.png\" border=\"1\"
     alt=\"HeatingSystem.png\">
</html>"), experiment(StopTime=6000),
    __Dymola_Commands(file(ensureSimulated=true)=
        "modelica://Modelica/Resources/Scripts/Dymola/Fluid/HeatingSystem/plotResults.mos" 
        "plotResults"));
end HeatingSystem_modified;
Oliver Hader
  • 4,093
  • 1
  • 25
  • 47
  • You are only showing the error messages. Is there a minimal, complete and verifiable example you can give that causes these errors? And if these errors don't all occur under the same circumstances, they should probably be separate questions. – Cobus Kruger Jun 08 '16 at 08:58
  • I think you should provide a link to your model. That will give us the possibility to check for staggered-grid issues (connection of flow/volume models), closed-loop initialization issues and other things that cannot be seen from the image. – Rene Just Nielsen Jun 08 '16 at 09:16
  • For documentation of thermo-fluid modelling in Modelica I would advise you to look at http://simulationresearch.lbl.gov/modelica/userGuide/bestPractice.html and http://simulationresearch.lbl.gov/modelica/releases/latest/help/Buildings_Fluid_Sensors_UsersGuide.html#Buildings.Fluid.Sensors.UsersGuide Also, I would recommend that you break the loop various places (including the output from the controller) and insert Modelica.Fluid.Sources in order to isolate the components that don't work. For instance, remove the tanks and pump1 and add pressure boundaries instead. – Rene Just Nielsen Jun 08 '16 at 09:20
  • Already thanks a lot for your comments! I will check the links - thanks for those. I edited my Question and added an example for one problem that occurs introducing a PI-Controller to handle the mass flow to specifiy one of the errors. Right now, I am going to isolate just the controlled part using boundaries. Hopefully I will find some hints that solve the problem. – user6439226 Jun 08 '16 at 09:36
  • Unfortunately, some how I can not include a screenshot of the model, due to restrictions of stackoverflow. (Tried to delete the old one and upload the new one, right links are still limited to 1 per post) – user6439226 Jun 08 '16 at 09:38
  • Ok. thanks to the links I now figured out that for controlling mass flow I have to use the Two Port Temperature sensor. Unfortunatley, doing this in my models does not solve my problems yet. I will try to solve it. If it is not possible I will give an update here. Thanks. – user6439226 Jun 08 '16 at 10:10
  • A few hints to begin with: convert the temperature set point to Kelvin. In pump1 set 'use_m_flow_set' to false to debug your model without the controller. In the controller, set the initial output to something else than zero, e.g. 0.1 kg/s. – Rene Just Nielsen Jun 08 '16 at 10:38

0 Answers0