与反冲元素结合使用时math.acos出现域错误

时间:2019-03-08 13:58:39

标签: modelica openmodelica

我遇到了涉及modelica三角函数的域外错误,我只是不知道该怎么办。
我的模型是非线性旋转弹簧(取决于几何关系的扭矩)+硬挡块(使用标准齿隙元素)的模型。 Model schematic with elastogap - doesnt work
我在OpenModelica中得到的错误是: acos(variable) outside domain -1.0 <= -1 <= +1.0
这意味着错误似乎出在我的自定义弹簧模型中。 现在,我认为应该起作用的普通解决方案是限制变量,以便acos使用if条件保持在域中。我还遵循有关noEvent()运算符的建议given here。但是,这不起作用。我什至没有采取“保管措施”,但无济于事。

为完成起见,this是弹簧的几何关系。我肯定这是正确的。
我使用了从phi = -2°到108°的输入斜坡。弹性间隙允许从phi = 0°到106°的无力运动。
Without the backlash元素使我的春天如我所愿。域外没有问题。尽管我在自定义的弹簧模型中的每个三角函数之前都添加了“域限制”,但伴随着这种强烈反对,我遇到了域问题。

有人知道这个问题可能是什么/我可以尝试什么?

我注意到,如果我将反冲的范围更改为具有不同的限制(例如b = 105.9 * pi / 180; phi_rel0 = -52.95 * pi / 180),它也可以正常工作而不会出现域错误,但是我想深入了解这个问题。

模型(有错误):

package test  
  model LD_Abwickel_ZF_VAL  
     Modelica.Blocks.Sources.Ramp ramp2(duration = 1.24, height = 122, offset = -2);
     Modelica.Mechanics.Rotational.Components.ElastoBacklash2 elastoBacklash(b = 1.85005, c = 1e4, d = 1e2, phi_rel0 = -0.925025);
     Modelica.Mechanics.Rotational.Components.Fixed fixed2;
     Modelica.Mechanics.Rotational.Sources.Position position1(exact = true);
     Modelica.Blocks.Math.UnitConversions.From_deg from_deg1;
     test.LD_Pendelarm_ZugfederF2 lD_Pendelarm_ZugfederF21;
  equation
     connect(position1.flange, lD_Pendelarm_ZugfederF21.flange);
     connect(elastoBacklash.flange_a, lD_Pendelarm_ZugfederF21.flange);
     connect(ramp2.y, from_deg1.u);
     connect(from_deg1.y, position1.phi_ref);
     connect(elastoBacklash.flange_b, fixed2.flange);
  end LD_Abwickel_ZF_VAL;


    model LD_Pendelarm_ZugfederF2  
      Modelica.Mechanics.Rotational.Interfaces.Flange_a flange;
      .Modelica.SIunits.Angle phi(displayUnit = "deg");
      .Modelica.SIunits.Torque M;
      parameter .Modelica.SIunits.Length a(displayUnit = "mm") = 25.49e-3;
      parameter .Modelica.SIunits.Length b(displayUnit = "mm") = 23.38e-3;
      parameter .Modelica.SIunits.Length d(displayUnit = "mm") = 43.89e-3;
      parameter .Modelica.SIunits.Length L0(displayUnit = "mm") = 59.5e-3 "Ungespannte Laenge d. Feder";
      parameter .Modelica.SIunits.Length Lk(displayUnit = "mm") = 47.19e-3 "Laenge unbelasteter Federkörper";
      parameter .Modelica.SIunits.Force F0 = 4.1 "innere Vorspannkraft Feder";
      parameter .Modelica.SIunits.TranslationalSpringConstant R(displayUnit = "N/mm") = 0.868e+3 "Federkonstante";
      parameter Integer z = 2 "Anzahl Federn";
      .Modelica.SIunits.Length c(displayUnit = "mm");
      .Modelica.SIunits.Angle delta(displayUnit = "deg", min = -2 * .Modelica.Constants.pi, max = 2 * .Modelica.Constants.pi, nominal = 0);
      .Modelica.SIunits.Angle alpha(displayUnit = "deg", min = -2 * .Modelica.Constants.pi, max = 2 * .Modelica.Constants.pi, nominal = 0.5 * .Modelica.Constants.pi);
      .Modelica.SIunits.Angle beta(displayUnit = "deg", min = -4 * .Modelica.Constants.pi, max = 4 * .Modelica.Constants.pi, nominal = .Modelica.Constants.pi);
      .Modelica.SIunits.Angle psi(displayUnit = "deg", min = -4 * .Modelica.Constants.pi, max = 4 * .Modelica.Constants.pi, nominal = 0);
      .Modelica.SIunits.Length L_gerade(displayUnit = "mm");
      .Modelica.SIunits.Length L_bogen(displayUnit = "mm") = 46.1e-3;
      .Modelica.SIunits.Length L_c(displayUnit = "mm") "rel. Federlaenge (gesamt)";
      .Modelica.SIunits.Force F_c "Summe Federkraft";
      Real cosalpha(min = -1, max = 1, nominal = 0);
      Real cosdelta(min = -1, max = 1, nominal = 0);
      Real cosbeta(min = -1, max = 1, nominal = 0);
    equation
      flange.phi = phi;
      flange.tau = M;
      if noEvent(phi <= 0) then
         c = a - b;
         cosdelta = 1;
         delta = 0;
         L_gerade = sqrt(c ^ 2 + d ^ 2);
         cosalpha = -1;
         alpha = .Modelica.Constants.pi;
      else
         c = sqrt(a ^ 2 + b ^ 2 - 2 * a * b * cos(phi));
         cosdelta = (b ^ 2 - a ^ 2 - c ^ 2) / (-2 * a * c);
         if noEvent(cosdelta <= 0.999999 and cosdelta >= (-0.999999)) then
            cos(delta) = cosdelta;
         else
            delta = if noEvent(sign(cosdelta) > 0) then 0 else .Modelica.Constants.pi;
         end if;
         L_gerade = sqrt(c ^ 2 + d ^ 2 - 2 * c * d * cos(delta + .Modelica.Constants.pi * 0.5));
         cosalpha = (a ^ 2 - b ^ 2 - c ^ 2) / (-2 * b * c);
         if noEvent(cosalpha <= 0.999999 and cosalpha >= (-0.999999)) then
            cos(alpha) = cosalpha;
         else
            alpha = if noEvent(sign(cosalpha) > 0) then 0 else .Modelica.Constants.pi;
         end if;
      end if;
      cosbeta = (d ^ 2 - c ^ 2 - L_gerade ^ 2) / (-2 * c * L_gerade);
      if noEvent(cosbeta <= 0.999999 and cosbeta >= (-0.999999)) then
         cos(beta) = cosbeta;
      else
         beta = if noEvent(sign(cosbeta) > 0) then 0 else .Modelica.Constants.pi;
      end if;
      psi = alpha - beta;
      L_c = L_gerade + L_bogen - (L0 - Lk) - Lk;
      F_c = z * (R * L_c + F0);
      M = F_c * sin(psi);
    end LD_Pendelarm_ZugfederF2;
end test;

1 个答案:

答案 0 :(得分:0)

因此,它当然可以在我的机器上正常工作,但是从代码中我知道这是有问题的,并且可能会随机失败。问题是您有cos(beta) = cosbeta之类的东西,被解决为beta = acos(cosbeta)

但是OpenModelica为常见的子表达式消除someTmpVar = acos(cosbeta)添加了一个错误的方程式,无论您使用什么if方程来保护它,该方程式始终运行。扩展似乎发生了,就像bug那样向OpenModelica报告,因为它发生在代码生成过程中,并且只生成lD_Pendelarm_ZugfederF21._delta = if noEvent(from_deg1.y <= 0.0) then 0.0 else if noEvent(lD_Pendelarm_ZugfederF21.cosdelta <= 0.999999) and noEvent(lD_Pendelarm_ZugfederF21.cosdelta >= -0.999999) then if noEvent(abs($TMP$VAR$70$0x1$COS - $TMP$VAR$70$0PREX$COS) < abs($TMP$VAR$70$0x2$COS - $TMP$VAR$70$0PREX$COS)) then $TMP$VAR$70$0x1$COS else $TMP$VAR$70$0x2$COS else if noEvent(sign(lD_Pendelarm_ZugfederF21.cosdelta) > 0) then 0.0 else 3.141592653589793,它运行的速度不会比以前快,并且可能会产生域错误。

一种可能的解决方法是使用算法部分,因为它不会受到OpenModelica的大量操作。