加热流体为集中体积模式

时间:2018-02-16 21:27:49

标签: modelica dymola openmodelica

我很难找到一个简单的集总体积能量平衡的最佳方法,比如管道,流体流动和热流输出。我基本上只想在能量平衡中添加一个Q_loss术语来降低流过的任何流体的温度,但保持整体模型超级简单(没有摩擦,压力,对流损失等)。

我试着写一个简单的模型,但是我遇到了比我需要的更少的等式。有没有办法在不修复压力的情况下做到这一点?

我的代码(介质不是标准介质,可能需要重新声明):

model IdealLossPipe
   extends SolarTherm.Interfaces.Models.Pipe;
  Medium.BaseProperties medium;
  replaceable package Medium = SolarTherm.Media.MoltenSalt.MoltenSalt_base
    constrainedby Modelica.Media.Interfaces.PartialMedium
  Modelica.Fluid.Interfaces.FluidPort_a fluid_a(redeclare package Medium =
        Medium);
  Modelica.Fluid.Interfaces.FluidPort_b fluid_b(redeclare package Medium =
        Medium) annotation (Placement(transformation(extent={{110,-10},{90,10}}, rotation=0),
        iconTransformation(extent={{110,-10},{90,10}})));
    parameter Real Q_loss_spec(unit="W/m") = 284 "Heat loss per m of piping";
    SI.HeatFlowRate Q_loss;
    parameter SI.Length length = 13.1 annotation(Dialog(group="Length"));
    parameter SI.Length diameter = 0.052;

    SI.Energy U;
    SI.Mass m;
    SI.Volume V;

equation 
  V = length*(diameter/2)^2*Modelica.Constants.pi;
  m=V*medium.d;
  U=m*medium.u;
  fluid_a.p=medium.p;
  fluid_b.p=medium.p;
  (instream(fluid_a.h_outflow)+fluid_b.h_outflow)/2=medium.h;
  fluid_a.h_outflow=0;
  Q_loss=-length*Q_loss_spec;

  //Mass Balance
  fluid_a.m_flow+fluid_b.m_flow=der(m);

  //Energy Balance
  der(U)= fluid_a.m_flow*inStream(fluid_a.h_outflow) + fluid_b.m_flow*fluid_b.h_outflow + Q_loss;

end IdealLossPipe;

提前感谢您帮助我!!

编辑:在我的模型中删除了不必要的热门

1 个答案:

答案 0 :(得分:1)

我编辑了你的模型(见下文)。一些新增内容包括SELECT MIN(price), timestamp FROM [database] WHERE stock = 'appl' AND second(timestamp) = 0 GROUP BY timestamp ORDER BY timestamp 的初始化,如果对基本属性使用该方法,则需要初始化medium。仔细研究现有的开源流体库(例如,Modelica标准库,TRANSFORM或ThermoPower)来了解它们如何做或使用它们的组件将是有帮助的。

model IdealLossPipe
  import SI = Modelica.SIunits;

  replaceable package Medium = Modelica.Media.Water.StandardWater
    constrainedby Modelica.Media.Interfaces.PartialMedium annotation (
      choicesAllMatching=true);

  Medium.BaseProperties medium(
    each preferredMediumStates=true,
    p(start=p_start),
    T(start=T_start),
    h(start=Medium.specificEnthalpy(Medium.setState_pT(p_start, T_start))),
    d(start=Medium.density(Medium.setState_pT(p_start, T_start))),
    u(start=Medium.specificInternalEnergy(Medium.setState_pT(p_start, T_start))),
    Xi(start=X_start[1:Medium.nXi]),
    X(start=X_start));

  Modelica.Fluid.Interfaces.FluidPort_a fluid_a(redeclare package Medium =
        Medium) annotation (Placement(transformation(extent={{-90,-10},{-110,10}},
          rotation=0), iconTransformation(extent={{-90,-10},{-110,10}})));
  Modelica.Fluid.Interfaces.FluidPort_b fluid_b(redeclare package Medium =
        Medium) annotation (Placement(transformation(extent={{110,-10},{90,10}},
          rotation=0), iconTransformation(extent={{110,-10},{90,10}})));

  parameter Real Q_loss_spec(unit="W/m") = 284 "Heat loss per m of piping";
  parameter SI.Length length=13.1 annotation (Dialog(group="Length"));
  parameter SI.Length diameter=0.052;

  // Initialization
  parameter SI.Pressure p_start=1e5;
  parameter SI.Temperature T_start=293.15;
  parameter SI.MassFraction X_start[Medium.nX]=Medium.X_default "Mass fraction";

  SI.HeatFlowRate Q_loss;
  SI.Energy U;
  SI.Mass m;
  SI.Volume V;

equation 

  V = length*(diameter/2)^2*Modelica.Constants.pi;
  m = V*medium.d;
  U = m*medium.u;

  Q_loss = -length*Q_loss_spec;

  //Mass Balance
  fluid_a.m_flow + fluid_b.m_flow = der(m);

  //Energy Balance
  der(U) = fluid_a.m_flow*inStream(fluid_a.h_outflow) + fluid_b.m_flow*inStream(
     fluid_b.h_outflow) + Q_loss;

  // Port definitions
  fluid_a.h_outflow = medium.h;
  fluid_b.h_outflow = medium.h;
  fluid_a.p = medium.p;
  fluid_b.p = medium.p;
  fluid_a.Xi_outflow = medium.Xi;
  fluid_b.Xi_outflow = medium.Xi;
  fluid_a.C_outflow = inStream(fluid_b.C_outflow);
  fluid_b.C_outflow = inStream(fluid_a.C_outflow);
end IdealLossPipe;

要记住的一件事是模型的“流量与体积”或“非状态(流量)与状态(非流量/体积)”表示。暴露状态的端口设定连接器的状态变量的值(即,流体的压力),而非状态端口设定连接器的流量变量(即,流体的质量流量)。因此,对于流体,您需要确保不连接每个设置压力的端口(状态变量)。与质量流量相似,但求解者更倾向于宽容。

作为参考,您的模型设置状态变量(fluid_a.p = medium.pfluid_b.p = medium.p)。一个简单的模型示例希望将每个端口与设置质量流速的模型连接,例如fluid_a上的质量流量源和fluid_b上的压力边界后面的电阻元素。

model Example
  Unnamed pipe(redeclare package Medium = Modelica.Media.Water.StandardWater,
      Q_loss_spec=10000)
    annotation (Placement(transformation(extent={{-68,4},{-48,24}})));
  Modelica.Fluid.Sources.Boundary_pT boundary(
    nPorts=1,
    redeclare package Medium = Modelica.Media.Water.StandardWater,
    p=100000,
    T=293.15) annotation (Placement(transformation(extent={{34,2},{14,22}})));
  Modelica.Fluid.Sources.MassFlowSource_T boundary1(
    nPorts=1,
    redeclare package Medium = Modelica.Media.Water.StandardWater,
    m_flow=1,
    T=293.15)
    annotation (Placement(transformation(extent={{-124,2},{-104,22}})));
  Modelica.Fluid.Valves.ValveLinear valveLinear(
    redeclare package Medium = Modelica.Media.Water.StandardWater,
    dp_nominal=100000,
    m_flow_nominal=1)
    annotation (Placement(transformation(extent={{-30,4},{-10,24}})));
  Modelica.Blocks.Sources.Constant const(k=1)
    annotation (Placement(transformation(extent={{-52,30},{-32,50}})));
equation 
  connect(boundary1.ports[1], pipe.fluid_a) annotation (Line(points={{-104,12},{
          -86,12},{-86,14},{-68,14}}, color={0,127,255}));
  connect(pipe.fluid_b, valveLinear.port_a)
    annotation (Line(points={{-48,14},{-30,14}}, color={0,127,255}));
  connect(valveLinear.port_b, boundary.ports[1]) annotation (Line(points={{-10,14},
          {2,14},{2,12},{14,12}}, color={0,127,255}));
  connect(const.y, valveLinear.opening)
    annotation (Line(points={{-31,40},{-20,40},{-20,22}}, color={0,0,127}));

end Example;