来自管道

时间:2016-02-11 22:58:34

标签: modelica openmodelica

我一直在尝试通过一个管道建模流程,该管道可以部分填满,或者在modelica中完全填满并在OpenModelica中运行。我最后将示例缩小为基本上只使用圆的区域,并且在它满了之前没有流出,然后完全流出。但是,我仍然会遇到错误。我尝试了几种不同的方式。第一种方法在管道“填满”后给出了解决非线性系统的错误。相反,我希望它切换:

   model SimplePipe1
  Modelica.SIunits.Area A;
  Modelica.SIunits.Mass mass;
  Modelica.SIunits.Height level(start = 0.5, fixed = true, min = 0.0, max = 2 * R) "Liquid level (m)";
  parameter Modelica.SIunits.Radius R = 1.0 "pipe inner radius (m)";
  parameter Real flow_in = 1.0;
  Real flow_out;
  Modelica.SIunits.Angle phi(start = 3.1, min = 0.0, max = 7.2832) "Angle from center to surface level";
  Modelica.SIunits.Area A;
  Modelica.SIunits.Mass mass;
  Modelica.SIunits.Height level(start = 0.5, fixed = true, min = 0.0, max = 2 * R) "Liquid level (m)";
  parameter Modelica.SIunits.Radius R = 1.0 "pipe inner radius (m)";
  parameter Real flow_in = 1.0;
  Real flow_out;
  Modelica.SIunits.Angle phi(start = 3.1, min = 0.0, max = 7.2832) "Angle from center to surface level";
equation
  mass = A;
  //Assume unit length pipe and unit density
  flow_in + flow_out = der(mass);
  A = 0.5 * R ^ 2 * (phi - sin(phi));
  //    phi = if noEvent(level <= 0) then 0 elseif noEvent(level >= 2 * R) then 2 * Modelica.Constants.pi else 2 * acos((R - level) / R);
  if noEvent(level <= 0) then
    phi = 0;
    flow_out = 0;
  elseif noEvent(level >= 2 * R) then
    phi = 2 * Modelica.Constants.pi;
    flow_out = -flow_in;
  else
    flow_out = 0;
    //Partially full pipe has no out outflow
    phi = 2 * acos((R - level) / R);
  end if;
  annotation(Icon, Diagram, experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-06, Interval = 0.02));
end SimplePipe1;

这个版本似乎给出了更接近我想要的结果,但它仍然不起作用。在这种情况下,问题是phi应该被限制在2 * pi。相反,它不断增加。同时,我实际上并没有看到flowmode的变化。我确实看到一个循环的流出量为负值,然后它会跳回零。我不明白将流量模式从通道更改为完整的是什么,因为没有相应的“何时”将其更改回来。

model SimplePipe2
  type modetype = enumeration(empty, full, channel);
  modetype flowmode(start = modetype.channel);
  Modelica.SIunits.Area A;
  Modelica.SIunits.Mass mass;
  Modelica.SIunits.Height level(start = 0.5, fixed = true, min = 0.0, max = 2 * R) "Liquid level (m)";
  Modelica.SIunits.Height level_limit;
  parameter Modelica.SIunits.Radius R = 1.0 "pipe inner radius (m)";
  parameter Real flow_in = 1.0;
  Real flow_out;
  Modelica.SIunits.Angle phi(start = 3.1, min = 0.0, max = 7.2832) "Angle from center to surface level";
  Real flow_out;
initial equation
  flowmode = modetype.channel;
equation
  mass = A;
  //Assume unit length pipe and unit density
  flow_in + flow_out = der(mass);
  A = 0.5 * R ^ 2 * (phi - sin(phi));
  cos(phi / 2) = (R - level) / R;
  if flowmode == modetype.empty then
    flow_out = 0;
  elseif flowmode == modetype.full then
    flow_out = -flow_in;
  else
    flow_out = 0;
    //Partially full pipe has no out outflow
  end if;
  when noEvent(phi >= 2 * Modelica.Constants.pi) then
    reinit(flow_out, -flow_in);
    reinit(level, 2 * R);
    flowmode = modetype.full;
  end when;
  annotation(Icon, Diagram, experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-06, Interval = 0.02));
end SimplePipe2;
我问的

This question与解决同样的问题有关,但没有圆/圆柱的问题。而且,我上面的第二个例子基于this question 我正在使用最新的OpenModelica测试版。我的完整模型将具有其他任何一个示例中未包含的其他功能。但是,希望如果我能够使这个简单的版本工作,我可以从那里扩展。

1 个答案:

答案 0 :(得分:2)

您的代码以phi的非线性方程结束(在level_limit之后,从模型中删除了一个flow_out)。

0 = 0.5 * R ^ 2.0 * (phi - sin(phi)) - mass

OM解决了这个问题而没有为变量phi添加约束。在找到解决方案后,将检查断言。如果在OpenModelica中使用非线性求解器= kinsol,则将约束添加到非线性方程中,但在这种情况下它没有帮助。我还有点不确定when noEvent()是否会触发。