Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

OpenModelica doesn't follow the discrete logic as expected

OpenModelica doesn't follow the discrete logic as expected

Following this and this questions, I'm trying to simulation the below model in OpenModelica:

Code:


package friction1D

  function coulombFriction
    input Real relVel;
    input Real shearForce;
    input Real normalForce;
    input Real statfricco;
    input Real kinfricco;
    input Real inertia;
    input Real relAcc;
    output Real fricForce;
  algorithm
    if (relVel == 0) and (abs(shearForce - inertia * relAcc) < statfricco * normalForce) then
      fricForce := shearForce - inertia * relAcc;
    else
      fricForce := kinfricco * normalForce * sign(relVel);
    end if;
  end coulombFriction;

  model fricexample_1
    //parameters
    parameter Real kco = 0.3;
    parameter Real sco = 0.4;
    parameter Real nfo = 1.0;
    parameter Real mass = 1.0;

    Real sfo;
    Real ffo;
    Real x;
    Real v;

  initial equation
    x = 0;
    v = 0;

  algorithm
    sfo := 0.7 * sin(time);
    ffo := coulombFriction(relVel = v, shearForce = sfo, normalForce = nfo, statfricco = sco, kinfricco = kco, inertia = mass, relAcc = der(v));

  equation
    v = der(x);
    mass * der(v) = sfo - ffo;

  annotation(
      experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-8, Interval = 0.02),
      __OpenModelica_simulationFlags(lv = "LOG_STATS", outputFormat = "mat", s = "dassl"));
     
  end fricexample_1;

end friction1D;

apart from the warning:


Translation Warning
Iteration variables with default zero start attribute in torn nonlinear equation system:
         $DER.v:VARIABLE()  type: Real

The results don't make sense.

https://i.imgur.com/Fsq9mIP.png

I expect the ffo to rise till 0.4 and then fall to 0.3 at point 1, but it shows weird behavior, which I can't explain at points 2 and 3. I would appreciate it if you could help me understand what is happening here and why I'm not getting the behavior I expect?


P.S. I post this question here on Modelica language Discord group and well as here on Reddit.

Edited by: foadsf - Oct-04-19 08:35:20

Re: OpenModelica doesn't follow the discrete logic as expected

I changed the code to :

Code:


package friction1D

  final constant Real eps=1.e-15 "Biggest number such that 1.0 + eps = 1.0";

  function coulombFriction
    input Real relVel;
    input Real shearForce;
    input Real normalForce;
    input Real statfricco;
    input Real kinfricco;
    input Real inertia;
    input Real relAcc;
    output Real fricForce;
  algorithm
    //if (relVel < eps) and (abs(shearForce - inertia * relAcc) < statfricco * normalForce) then
      //fricForce := shearForce - inertia * relAcc;
      if (relVel < eps) and (abs(shearForce) < statfricco * normalForce) then
        fricForce := shearForce;
    else
      fricForce := kinfricco * normalForce * sign(relVel);
    end if;
  end coulombFriction;

  model fricexample_1
    //parameters
    parameter Real kco = 0.3;
    parameter Real sco = 0.4;
    parameter Real nfo = 1.0;
    parameter Real mass = 1.0;

    Real sfo;
    Real ffo;
    Real x;
    Real v;

  initial equation
    x = 0;
    v = 0;

  algorithm
    sfo := 0.7 * sin(time);
    ffo := coulombFriction(relVel = v, shearForce = sfo, normalForce = nfo, statfricco = sco, kinfricco = kco, inertia = mass, relAcc = der(v));

  equation
    v = der(x);
    mass * der(v) = sfo - ffo;

  annotation(
      experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-8, Interval = 0.02),
      __OpenModelica_simulationFlags(lv = "LOG_STATS", outputFormat = "mat", s = "dassl"));
     
  end fricexample_1;

end friction1D;

and now the first issue is solved:

https://i.imgur.com/ccjUiRa.png

and it makes sense at point 1, but then from point 2 to 3 where ffo simply should be -0.3 it is following the sfo!

Re: OpenModelica doesn't follow the discrete logic as expected

Does

Code:

if (abs(relVel) < eps)

solve it?

Re: OpenModelica doesn't follow the discrete logic as expected

sjoelund.se wrote:


Does

Code:

if (abs(relVel) < eps)

solve it?

came to say exactly how I solved this, but you were faster ? thanks a lot

There are 0 guests and 0 other users also viewing this topic
You are here: