Search code examples
modelicaopenmodelica

Why does the CPU time increase significantly even though I use the noEvent operator in OpenModelica?


When I simulate the following model, the CPU time increases unexpectedly:

model WithoutChatter
  Real x;
initial equation
  x = 2;
equation
  der(x) = if noEvent(x>=1) then -1 else 1;
end WithoutChatter;

With the noEvent operator, the CPU time should not go up noticeably, like it is explained here, from where I copied the example code: Modelica by Example

I am new to OpenModelica and just did a Windows installation. For the simulation I used default settings. The result is this. CPU time increases


Solution

  • Using noEvent to reduce chattering is not a good idea. Depending on the solver it can slow down the simulation even more (or have no impact).

    The reason is that the solvers assume that the model is sufficiently continuous. Breaking that once in a while as for if x>=0 then sqrt(x) else 0 is sort of ok - but breaking it every nano-second (or even more often) with x>=0 then -1 else 1 is not.

    The only good solution is to rewrite the model - that's why friction models have three states: forward sliding, backward sliding, and stuck.

    The exact impact on performance will depend on the solver (including its error estimator).