Search code examples
fluidmodelicaopenmodelica

Model of a fluid through a pipe can't run on openmodelica


I'm trying to simulate on OpenModelica, a fluid (here water) that flowh through a pipe with an inlet pressure and temperature. I want to take into account the convective exchange between the wall of the pipe and the fluid, the convective exchange between the wall, the ambient and the conductive exchange in the wall and the properties of the medium that vary in function of the temperature... The check of the model is ok but when I run the simulation I have an error.

Here is my code :

model Water_flow

  replaceable package Medium=Modelica.Media.Water.StandardWater constrainedby
    Modelica.Media.Interfaces.PartialMedium;
    
  output Modelica.SIunits.MassFlowRate mass_flow_rate=abs(pipe.port_b.m_flow);
     
     
  
  Modelica.Fluid.Sources.Boundary_pT boundary(redeclare package Medium = Medium, T = 318.45, nPorts = 1, p = 14.6e5) annotation(
    Placement(visible = true, transformation(origin = {-24, -80}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  
  Modelica.Fluid.Sources.Boundary_pT boundary1(redeclare package Medium = Medium, T = 328.15, nPorts = 1, p = 14e5) annotation(
    Placement(visible = true, transformation(origin = {60, -80}, extent = {{-10, -10}, {10, 10}}, rotation = 180)));
  
  Modelica.Fluid.Pipes.DynamicPipe pipe(redeclare package Medium = Medium, redeclare model HeatTransfer=Modelica.Fluid.Pipes.BaseClasses.HeatTransfer.LocalPipeFlowHeatTransfer, T_start = 318.15, allowFlowReversal = false, diameter = 13e-3, energyDynamics = Modelica.Fluid.Types.Dynamics.SteadyStateInitial, height_ab = 0, length = 15, massDynamics = Modelica.Fluid.Types.Dynamics.SteadyStateInitial, momentumDynamics = Modelica.Fluid.Types.Dynamics.SteadyStateInitial, nNodes = 5, use_HeatTransfer = true)  annotation(
    Placement(visible = true, transformation(origin = {18, -80}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  
  inner Modelica.Fluid.System system(T_ambient = 290.15, energyDynamics = Modelica.Fluid.Types.Dynamics.SteadyStateInitial, massDynamics = Modelica.Fluid.Types.Dynamics.SteadyStateInitial, momentumDynamics = Modelica.Fluid.Types.Dynamics.SteadyStateInitial)  annotation(
    Placement(visible = true, transformation(origin = {-84, 84}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  
  Modelica.Thermal.HeatTransfer.Components.Convection convection annotation(
    Placement(visible = true, transformation(origin = {-50, -2}, extent = {{-10, -10}, {10, 10}}, rotation = 90)));
  Modelica.Blocks.Sources.Constant const(k = 358)  annotation(
    Placement(visible = true, transformation(origin = {-88, -2}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Thermal.HeatTransfer.Sources.FixedTemperature fixedTemperature(T = 328.15)  annotation(
    Placement(visible = true, transformation(origin = {-50, 44}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Thermal.HeatTransfer.Components.Convection convection1 annotation(
    Placement(visible = true, transformation(origin = {-16, -2}, extent = {{-10, -10}, {10, 10}}, rotation = 90)));
  Modelica.Thermal.HeatTransfer.Sources.FixedTemperature fixedTemperature1(T = 328.15) annotation(
    Placement(visible = true, transformation(origin = {-16, 44}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  
  Modelica.Fluid.Examples.HeatExchanger.BaseClasses.WallConstProps wallConstProps(T_start = 318.15, area_h = 0.9, c_wall = 420, dT = 283.15, energyDynamics = Modelica.Fluid.Types.Dynamics.SteadyStateInitial, k_wall = 60.5, n = 5, rho_wall = 7850, s = 6e-3) annotation(
    Placement(visible = true, transformation(origin = {18, -44}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Thermal.HeatTransfer.Components.Convection convection2 annotation(
    Placement(visible = true, transformation(origin = {18, -2}, extent = {{-10, -10}, {10, 10}}, rotation = 90)));
  
  Modelica.Thermal.HeatTransfer.Sources.FixedTemperature fixedTemperature2(T = 328.15)  annotation(
    Placement(visible = true, transformation(origin = {18, 44}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Thermal.HeatTransfer.Sources.FixedTemperature fixedTemperature3(T = 328.15)  annotation(
    Placement(visible = true, transformation(origin = {50, 44}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Thermal.HeatTransfer.Sources.FixedTemperature fixedTemperature4(T = 328.15)  annotation(
    Placement(visible = true, transformation(origin = {82, 44}, extent = {{-10, -10}, {10, 10}}, rotation = -90)));
  Modelica.Thermal.HeatTransfer.Components.Convection convection3 annotation(
    Placement(visible = true, transformation(origin = {50, -2}, extent = {{-10, -10}, {10, 10}}, rotation = 90)));
  Modelica.Thermal.HeatTransfer.Components.Convection convection4 annotation(
    Placement(visible = true, transformation(origin = {82, -2}, extent = {{-10, -10}, {10, 10}}, rotation = 90)));

equation
  connect(boundary.ports[1], pipe.port_a) annotation(
    Line(points = {{-14, -80}, {8, -80}}, color = {0, 127, 255}));
  connect(pipe.port_b, boundary1.ports[1]) annotation(
    Line(points = {{28, -80}, {50, -80}}, color = {0, 127, 255}));
  connect(const.y, convection.Gc) annotation(
    Line(points = {{-77, -2}, {-60, -2}}, color = {0, 0, 127}));
  connect(fixedTemperature.port, convection.fluid) annotation(
    Line(points = {{-50, 34}, {-50, 8}}, color = {191, 0, 0}));
  connect(fixedTemperature.port, convection.fluid) annotation(
    Line(points = {{-50, 34}, {-50, 8}}, color = {191, 0, 0}));
  connect(fixedTemperature1.port, convection1.fluid) annotation(
    Line(points = {{-16, 34}, {-16, 8}}, color = {191, 0, 0}));
  connect(const.y, convection1.Gc) annotation(
    Line(points = {{-77, -2}, {-26, -2}}, color = {0, 0, 127}));
  connect(convection.solid, wallConstProps.heatPort_a[1]) annotation(
    Line(points = {{-50, -12}, {-50, -24}, {18, -24}, {18, -39}}, color = {191, 0, 0}));
  connect(fixedTemperature2.port, convection2.fluid) annotation(
    Line(points = {{18, 34}, {18, 8}}, color = {191, 0, 0}));
  connect(convection2.solid, wallConstProps.heatPort_a[3]) annotation(
    Line(points = {{18, -12}, {18, -39}}, color = {191, 0, 0}));
  connect(const.y, convection2.Gc) annotation(
    Line(points = {{-77, -2}, {8, -2}}, color = {0, 0, 127}));
  connect(const.y, convection3.Gc) annotation(
    Line(points = {{-76, -2}, {40, -2}, {40, -2}, {40, -2}}, color = {0, 0, 127}));
  connect(const.y, convection4.Gc) annotation(
    Line(points = {{-76, -2}, {72, -2}, {72, -2}, {72, -2}}, color = {0, 0, 127}));
  connect(convection3.solid, wallConstProps.heatPort_a[4]) annotation(
    Line(points = {{50, -12}, {50, -24}, {18, -24}, {18, -39}}, color = {191, 0, 0}));
  connect(convection4.solid, wallConstProps.heatPort_a[5]) annotation(
    Line(points = {{82, -12}, {82, -24}, {18, -24}, {18, -39}}, color = {191, 0, 0}));
  connect(convection1.solid, wallConstProps.heatPort_a[2]) annotation(
    Line(points = {{-16, -12}, {-16, -24}, {18, -24}, {18, -39}}, color = {191, 0, 0}));
  connect(wallConstProps.heatPort_b, pipe.heatPorts) annotation(
    Line(points = {{18, -49}, {18, -76}}, color = {191, 0, 0}, thickness = 0.5));
  connect(fixedTemperature3.port, convection3.fluid) annotation(
    Line(points = {{50, 34}, {50, 8}}, color = {191, 0, 0}));
  connect(fixedTemperature4.port, convection4.fluid) annotation(
    Line(points = {{82, 34}, {82, 34}, {82, 8}, {82, 8}}, color = {191, 0, 0}));
  annotation(
    uses(Modelica(version = "3.2.3")),
    Diagram);
end Water_flow;

The error message is in the image.

enter image description here

If anyone has an idea of what's wrong with the model.

Thanks and have a great day, Maxime


Solution

  • In Dymola your code runs but with a lot of warnings. Initializing the pipe pressures makes it run without warnings — for example, pipe.p_a_start=1460000 and pipe.p_b_start=1400000.

    Another thing, you could declare the convective elements and fixed temperatures as an array like this:

    Modelica.Thermal.HeatTransfer.Components.Convection[pipe.nNodes]  convection
    Modelica.Thermal.HeatTransfer.Sources.FixedTemperature[pipe.nNodes] fixedTemperature(each T = 328.15)
    

    That will make your model easier to maintain if you choose another discretization, e.g. pipe.nNodes=10.