2

一般问题:

我使用 OpenModelica 在 Modelica 上工作。我想在 Modelica 中编写自己的求解器以收敛到一个解决方案,因为我认为 OpenModelica 无法解决我的问题。可能吗?


具体案例:

我开发了一个流体动力学组件中的空气分离模型。我的模型基于一个数据表,该数据表根据组件中的速度和参数“截面”提供每个分支的压力损失系数。我的模型在我使用 MassFlow 源时效果很好,但在我只使用压力源时效果不佳。请参阅下面的图片以了解与我的组件的连接:

http://www.casimages.com/img.php?i=140620024048704083.png

http://www.casimages.com/img.php?i=140620024137384886.png

我的模型“分离”的代码是这样的:

model separation
 replaceable package Medium = Modelica.Media.Interfaces.PartialMedium "Medium in the component";
 Modelica.Fluid.Interfaces.FluidPort_a port_a(redeclare package Medium = Medium);
 Modelica.Fluid.Interfaces.FluidPort_b port_b2(redeclare package Medium = Medium);
 Modelica.Fluid.Interfaces.FluidPort_b port_b1(redeclare package Medium = Medium);
 Modelica.Blocks.Tables.CombiTable2D coeff_PDC1(table = [0, 0, 0.4, 0.5, 0.6, 0.7, 0.8, 1; 0, 1, 1, 1, 1, 1, 1, 1; 0.1, 0.81, 0.81, 0.81, 0.81, 0.81, 0.81, 0.81; 0.2, 0.64, 0.64, 0.64, 0.64, 0.64, 0.64, 0.64; 0.3, 0.5, 0.5, 0.52, 0.52, 0.5, 0.5, 0.5; 0.4, 0.36, 0.36, 0.4, 0.38, 0.37, 0.36, 0.36; 0.5, 0.25, 0.25, 0.3, 0.28, 0.26, 0.25, 0.25; 0.6, 0.16, 0.16, 0.23, 0.2, 0.18, 0.16, 0.16; 0.8, 0.04, 0.04, 0.16, 0.12, 0.07, 0.04, 0.04; 1, 0.001, 0.001, 0.2, 0.1, 0.05, 0.001, 0.001; 1.2, 0.07, 0.07, 0.36, 0.21, 0.14, 0.07, 0.07; 1.4, 0.39, 0.39, 0.78, 0.59, 0.49, 50, 50; 1.6, 0.9, 0.9, 1.36, 1.15, 50, 50, 50; 1.8, 1.78, 1.78, 2.43, 50, 50, 50, 50; 2, 3.2, 3.2, 4, 50, 50, 50, 50]);
 Modelica.Blocks.Tables.CombiTable1Ds coeff_PDC2( table = [0.1, 1; 0.2, 1; 0.3, 1; 0.4, 1; 0.5, 1; 0.6, 1; 0.8, 1; 1,1; 1.2, 1; 1.4, 1; 1.6, 1; 1.8, 1; 2, 1]);
 Real dp_b1 "en Pa, perte de charge entre les ports a1 et b";
 Real dp_b2 "en Pa, perte de charge entre les ports a2 et b";
 Modelica.SIunits.Velocity v_a(start = 0);
 Modelica.SIunits.Velocity v_b1(start = 0);
 Modelica.SIunits.Velocity v_b2(start = 0);
 parameter Real rho=1.2;
 parameter Modelica.SIunits.Area surface_b1 = 1;
 parameter Modelica.SIunits.Area surface_b2 = 1;
 parameter Modelica.SIunits.Area surface_a = 2;
equation 
 coeff_PDC1.u1 = if noEvent(abs(v_a) > 0) then v_b1/v_a else 1;
 coeff_PDC1.u2 = surface_b1/surface_a;
 coeff_PDC2.u = if noEvent(abs(v_a) > 0) then v_b2/v_a else 1;
 v_a = abs(port_a.m_flow)/rho/surface_a;
 v_b1 = abs(port_b1.m_flow)/rho/surface_b1;
 v_b2 = abs(port_b2.m_flow)/rho/surface_b2;
 port_b1.p - port_a.p = dp_b1;
 dp_b1 = 1/2*coeff_PDC1.y*port_b1.m_flow^2/surface_b1^2/rho;
 port_b2.p - port_a.p = dp_b2;
 dp_b2 = 1/2*coeff_PDC2.y[1]*port_b2.m_flow^2/surface_b2^2/rho;
 port_b1.m_flow + port_b2.m_flow + port_a.m_flow = 0;

 port_b1.Xi_outflow = inStream(port_a.Xi_outflow);
 port_b2.Xi_outflow = inStream(port_a.Xi_outflow);
 port_a.Xi_outflow = inStream(port_b1.Xi_outflow);
 port_b1.C_outflow = inStream(port_a.C_outflow);
 port_b2.C_outflow = inStream(port_a.C_outflow);
 port_a.C_outflow = inStream(port_b1.C_outflow);
 port_b1.h_outflow = inStream(port_a.h_outflow);
 port_b2.h_outflow = inStream(port_a.h_outflow);
 port_a.h_outflow = inStream(port_b1.h_outflow);
end separation;

当我将此模型连接到 3 个压力组件(源设置为 Patm +10000Pa,接收器设置为 Patm)时,这是一个“非线性系统”错误。该模型适用于 MassFlow 接收器。为什么?我应该开发自己的求解器来解决它吗?如果是怎么办?

4

3 回答 3

2

你的问题并不完全清楚。但是,我想你要问的是,如果给定一个 dp 的值,modelica 可以在任何时候求解 v,当有一个表来表示 K 和 v 的关系时?如果我正确理解了您的变量,则应该这样做:

model test5
  Real v "fluid velocity";
  Real K "Pressure loss coefficient";
  Real dp =0.5 "Pressure drop"; //Example value
  Real rho = 1.0 "density" ;
  Modelica.Blocks.Tables.CombiTable2D coeff_PDC1(table = [0, 0, 0.4, 0.5, 0.6, 0.7, 0.8, 1; 0, 1, 1, 1, 1, 1, 1, 1; 0.1, 0.81, 0.81, 0.81, 0.81, 0.81, 0.81, 0.81; 0.2, 0.64, 0.64, 0.64, 0.64, 0.64, 0.64, 0.64; 0.3, 0.5, 0.5, 0.52, 0.52, 0.5, 0.5, 0.5; 0.4, 0.36, 0.36, 0.4, 0.38, 0.37, 0.36, 0.36; 0.5, 0.25, 0.25, 0.3, 0.28, 0.26, 0.25, 0.25; 0.6, 0.16, 0.16, 0.23, 0.2, 0.18, 0.16, 0.16; 0.8, 0.04, 0.04, 0.16, 0.12, 0.07, 0.04, 0.04; 1, 0, 0, 0.2, 0.1, 0.05, 0, 0; 1.2, 0.07, 0.07, 0.36, 0.21, 0.14, 0.07, 0.07; 1.4, 0.39, 0.39, 0.78, 0.59, 0.49, 50, 50; 1.6, 0.9, 0.9, 1.36, 1.15, 50, 50, 50; 1.8, 1.78, 1.78, 2.43, 50, 50, 50, 50; 2, 3.2, 3.2, 4, 50, 50, 50, 50]);
equation

  coeff_PDC1.u2 = 0.5;
  dp = 0.5 * K * rho * v ^ 2;
  v = coeff_PDC1.u1;
  K = coeff_PDC1.y;

end test5;

当我运行它时,它会求解 v,给定 dp 的值。那是你要的吗?

于 2014-06-19T13:31:50.503 回答
1

OpenModelica 提示原始模型不好:

Error: Initialization problem is structurally singular, error found sorting equations 
  1: algorithm
    v := 0.0;
  2: algorithm
    K := 1.0;
    while v > 0.01 + $PRE.v loop
      v := (10.0 / K) ^ 0.5;
      K := 1.0 + v ^ 2.0;
    end while;

v 在初始算法和算法部分都定义。初始算法只应该用于参数或状态(两者都der(x)需要x在初始步骤中指定)。幸运的是,您可以指定v(start=0),并且 v 将在分配给 v 的算法部分的开头被初始化为 0。

解决后,模型编译和模拟。尽管正如其他人所说,算法部分很丑陋,在 Modelica 中应该不惜一切代价避免使用。

于 2014-06-19T11:39:06.600 回答
0

我不确定我是否 100% 理解这个问题。你说你无法分析地表达它。K但是你能把和之间的关系表达v为 Modelica 函数吗?如果是这样,您可以使用逆注释来提供逆函数。这样,该工具将使用最有效的函数版本,并且可以避免进行任何非线性迭代。但这假设您可以制定反函数。根据您的解释,我不清楚您是否可以。

于 2014-06-19T03:21:25.767 回答