math.acos out of domain error when combined with backlash element The Next CEO of Stack OverflowModelica Frequency/Time Domain combined equationsPython - Modelica connection fails due to import errorModelicac: algorithm or function clause causes ErrorWhen .. elsewhen equations seems to be reversed in Wolfram SystemmodelerToo many equations for discrete state machine variables in when statements in ModelicaXcos superblock throws an unusual errorWhy are Modelica array elements automatically assigned to zero when any one element is assigned in an algorithm sectionJModelica combined with CasADi to get linearized models in PythonSingular inconsistent scalar system when connecting a pressure boundaryModelica and Matlab Coupling with Modelica Error

Should I tutor a student who I know has cheated on their homework?

What exact does MIB represent in SNMP? How is it different from OID?

Is it professional to write unrelated content in an almost-empty email?

How do I transpose the 1st and -1th levels of an arbitrarily nested array?

Why do we use the plural of movies in this phrase "We went to the movies last night."?

I believe this to be a fraud - hired, then asked to cash check and send cash as Bitcoin

Interfacing a button to MCU (and PC) with 50m long cable

Several mode to write the symbol of a vector

Is it my responsibility to learn a new technology in my own time my employer wants to implement?

How does the mv command work with external drives?

Different harmonic changes implied by a simple descending scale

MessageLevel in QGIS3

Why is the US ranked as #45 in Press Freedom ratings, despite its extremely permissive free speech laws?

Is "for causing autism in X" grammatical?

Make solar eclipses exceedingly rare, but still have new moons

Return the Closest Prime Number

How to avoid supervisors with prejudiced views?

Why didn't Khan get resurrected in the Genesis Explosion?

Why does the UK parliament need a vote on the political declaration?

Example of a Mathematician/Physicist whose Other Publications during their PhD eclipsed their PhD Thesis

Would this house-rule that treats advantage as a +1 to the roll instead (and disadvantage as -1) and allows them to stack be balanced?

sp_blitzCache results Memory grants

WOW air has ceased operation, can I get my tickets refunded?

Non-deterministic sum of floats



math.acos out of domain error when combined with backlash element



The Next CEO of Stack OverflowModelica Frequency/Time Domain combined equationsPython - Modelica connection fails due to import errorModelicac: algorithm or function clause causes ErrorWhen .. elsewhen equations seems to be reversed in Wolfram SystemmodelerToo many equations for discrete state machine variables in when statements in ModelicaXcos superblock throws an unusual errorWhy are Modelica array elements automatically assigned to zero when any one element is assigned in an algorithm sectionJModelica combined with CasADi to get linearized models in PythonSingular inconsistent scalar system when connecting a pressure boundaryModelica and Matlab Coupling with Modelica Error










2















i've run into a problem with out of domain error involving modelica trigonometric functions and i just dont know what i could do.

My model is that of a nonlinear rotational spring (torque dependant on geometric relations) + a hard stop (using standard backlash element).
Model schematic with elastogap - doesnt work

The error i get in OpenModelica is:
acos(variable) outside domain -1.0 <= -1 <= +1.0

That means the error appears to be in my custom spring model.
Now, the ordinary solution i thought should work is to limit the variable so acos stays in domain using if-conditions. I also followed the advice given here about the noEvent() operator. This did not work however. I even went overboard with the "safekeeping", to no avail.



For completions sake, this is the geometric relation of the spring. I'm positive that it is correct.

I use an input ramp from phi= -2° to 108°. The elastogap allows force-free movement from phi = 0° to 106°.
Without the backlash element my spring works as i expect . No issues with out of domain. Together with this backlash i get the domain issue, even though i added "domain-limits" before every trigonometric function in my custom spring model.



Does anyone have an idea what the issue could be/ what i could try?



I noticed that if i change the range of the backlash to have different limits (for example b=105.9*pi/180 ; phi_rel0=-52.95*pi/180) it also works without domain error, but i would like to get to the bottom of this issue.



The model (with the error):



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;









share|improve this question




























    2















    i've run into a problem with out of domain error involving modelica trigonometric functions and i just dont know what i could do.

    My model is that of a nonlinear rotational spring (torque dependant on geometric relations) + a hard stop (using standard backlash element).
    Model schematic with elastogap - doesnt work

    The error i get in OpenModelica is:
    acos(variable) outside domain -1.0 <= -1 <= +1.0

    That means the error appears to be in my custom spring model.
    Now, the ordinary solution i thought should work is to limit the variable so acos stays in domain using if-conditions. I also followed the advice given here about the noEvent() operator. This did not work however. I even went overboard with the "safekeeping", to no avail.



    For completions sake, this is the geometric relation of the spring. I'm positive that it is correct.

    I use an input ramp from phi= -2° to 108°. The elastogap allows force-free movement from phi = 0° to 106°.
    Without the backlash element my spring works as i expect . No issues with out of domain. Together with this backlash i get the domain issue, even though i added "domain-limits" before every trigonometric function in my custom spring model.



    Does anyone have an idea what the issue could be/ what i could try?



    I noticed that if i change the range of the backlash to have different limits (for example b=105.9*pi/180 ; phi_rel0=-52.95*pi/180) it also works without domain error, but i would like to get to the bottom of this issue.



    The model (with the error):



    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;









    share|improve this question


























      2












      2








      2








      i've run into a problem with out of domain error involving modelica trigonometric functions and i just dont know what i could do.

      My model is that of a nonlinear rotational spring (torque dependant on geometric relations) + a hard stop (using standard backlash element).
      Model schematic with elastogap - doesnt work

      The error i get in OpenModelica is:
      acos(variable) outside domain -1.0 <= -1 <= +1.0

      That means the error appears to be in my custom spring model.
      Now, the ordinary solution i thought should work is to limit the variable so acos stays in domain using if-conditions. I also followed the advice given here about the noEvent() operator. This did not work however. I even went overboard with the "safekeeping", to no avail.



      For completions sake, this is the geometric relation of the spring. I'm positive that it is correct.

      I use an input ramp from phi= -2° to 108°. The elastogap allows force-free movement from phi = 0° to 106°.
      Without the backlash element my spring works as i expect . No issues with out of domain. Together with this backlash i get the domain issue, even though i added "domain-limits" before every trigonometric function in my custom spring model.



      Does anyone have an idea what the issue could be/ what i could try?



      I noticed that if i change the range of the backlash to have different limits (for example b=105.9*pi/180 ; phi_rel0=-52.95*pi/180) it also works without domain error, but i would like to get to the bottom of this issue.



      The model (with the error):



      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;









      share|improve this question
















      i've run into a problem with out of domain error involving modelica trigonometric functions and i just dont know what i could do.

      My model is that of a nonlinear rotational spring (torque dependant on geometric relations) + a hard stop (using standard backlash element).
      Model schematic with elastogap - doesnt work

      The error i get in OpenModelica is:
      acos(variable) outside domain -1.0 <= -1 <= +1.0

      That means the error appears to be in my custom spring model.
      Now, the ordinary solution i thought should work is to limit the variable so acos stays in domain using if-conditions. I also followed the advice given here about the noEvent() operator. This did not work however. I even went overboard with the "safekeeping", to no avail.



      For completions sake, this is the geometric relation of the spring. I'm positive that it is correct.

      I use an input ramp from phi= -2° to 108°. The elastogap allows force-free movement from phi = 0° to 106°.
      Without the backlash element my spring works as i expect . No issues with out of domain. Together with this backlash i get the domain issue, even though i added "domain-limits" before every trigonometric function in my custom spring model.



      Does anyone have an idea what the issue could be/ what i could try?



      I noticed that if i change the range of the backlash to have different limits (for example b=105.9*pi/180 ; phi_rel0=-52.95*pi/180) it also works without domain error, but i would like to get to the bottom of this issue.



      The model (with the error):



      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;






      modelica openmodelica






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 8 at 14:13







      Etis

















      asked Mar 8 at 13:58









      EtisEtis

      113




      113






















          1 Answer
          1






          active

          oldest

          votes


















          0














          So of course it works fine on my machine, but from the code I know it is problematic and might fail randomly. The problem is that you have things like cos(beta) = cosbeta which is solved as beta = acos(cosbeta).



          But OpenModelica added a bad equation for common subexpression elimination someTmpVar = acos(cosbeta) which always runs regardless of the if-equations you use to guard this. The expansion seems to happen Feels like a bug to report to OpenModelica since it happens during code generation and just produces 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, which won't run faster than before and might produce domain errors.



          A probable workaround would be to use an algorithm section as it is not manipulated as heavily by OpenModelica.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55064752%2fmath-acos-out-of-domain-error-when-combined-with-backlash-element%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            So of course it works fine on my machine, but from the code I know it is problematic and might fail randomly. The problem is that you have things like cos(beta) = cosbeta which is solved as beta = acos(cosbeta).



            But OpenModelica added a bad equation for common subexpression elimination someTmpVar = acos(cosbeta) which always runs regardless of the if-equations you use to guard this. The expansion seems to happen Feels like a bug to report to OpenModelica since it happens during code generation and just produces 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, which won't run faster than before and might produce domain errors.



            A probable workaround would be to use an algorithm section as it is not manipulated as heavily by OpenModelica.






            share|improve this answer



























              0














              So of course it works fine on my machine, but from the code I know it is problematic and might fail randomly. The problem is that you have things like cos(beta) = cosbeta which is solved as beta = acos(cosbeta).



              But OpenModelica added a bad equation for common subexpression elimination someTmpVar = acos(cosbeta) which always runs regardless of the if-equations you use to guard this. The expansion seems to happen Feels like a bug to report to OpenModelica since it happens during code generation and just produces 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, which won't run faster than before and might produce domain errors.



              A probable workaround would be to use an algorithm section as it is not manipulated as heavily by OpenModelica.






              share|improve this answer

























                0












                0








                0







                So of course it works fine on my machine, but from the code I know it is problematic and might fail randomly. The problem is that you have things like cos(beta) = cosbeta which is solved as beta = acos(cosbeta).



                But OpenModelica added a bad equation for common subexpression elimination someTmpVar = acos(cosbeta) which always runs regardless of the if-equations you use to guard this. The expansion seems to happen Feels like a bug to report to OpenModelica since it happens during code generation and just produces 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, which won't run faster than before and might produce domain errors.



                A probable workaround would be to use an algorithm section as it is not manipulated as heavily by OpenModelica.






                share|improve this answer













                So of course it works fine on my machine, but from the code I know it is problematic and might fail randomly. The problem is that you have things like cos(beta) = cosbeta which is solved as beta = acos(cosbeta).



                But OpenModelica added a bad equation for common subexpression elimination someTmpVar = acos(cosbeta) which always runs regardless of the if-equations you use to guard this. The expansion seems to happen Feels like a bug to report to OpenModelica since it happens during code generation and just produces 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, which won't run faster than before and might produce domain errors.



                A probable workaround would be to use an algorithm section as it is not manipulated as heavily by OpenModelica.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 11 at 8:36









                sjoelund.sesjoelund.se

                2,005711




                2,005711





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55064752%2fmath-acos-out-of-domain-error-when-combined-with-backlash-element%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    How to get text form Clipboard with JavaScript in Firefox 56?How to validate an email address in JavaScript?How do JavaScript closures work?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I copy to the clipboard in JavaScript?How do I include a JavaScript file in another JavaScript file?Get the current URL with JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?

                    Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

                    List of MPs elected to the English parliament in 1640 (April) Contents List of constituencies and members See also Notes References Navigation menueNational Archives – The Glynde Place ArchivesCobbett's Parliamentary history of England, from the Norman Conquest in 1066 to the year 1803'Aldermen in Parliament', The Aldermen of the City of London: Temp. Henry III – 1912onepage&q&f&#61, false 229