Search code examples
modelicadymola

Euler solver time step near events in Dymola


Near state events, the solver will take a shortened time step in order to align the step with the event. This can be beneficial for preserving accuracy near events; however, the time variable does not seem to update according to the step size causing an incorrect result from Dymola:

Incorrect result from Euler solver in Dymola

Here is the Modelica code to reproduce the problem:

model Unnamed
  Modelica.Blocks.Sources.Trapezoid ramp(
    period=1,
    rising=0.1,
    falling=0.1)
    annotation (Placement(transformation(extent={{-52,20},{-32,40}})));
  Modelica.Blocks.Continuous.FirstOrder firstOrder(T=0.001)
    annotation (Placement(transformation(extent={{-20,20},{0,40}})));
  Modelica.Blocks.Sources.Pulse pulse(period=0.1222)
    annotation (Placement(transformation(extent={{-40,-20},{-20,0}})));
equation 
  connect(firstOrder.u, ramp.y)
    annotation (Line(points={{-22,30},{-31,30}}, color={0,0,127}));
  annotation (uses(Modelica(version="3.2.2")), experiment(
      Interval=0.001,
      __Dymola_fixedstepsize=0.001,
      __Dymola_Algorithm="Euler"));
end Unnamed;

Is there a way to disable the event handling in Dymola and keep the Euler time step fixed? Or better, cause the time variable to properly update. Thanks


Solution

  • There are two parts:

    • Turning off this special handling for events (not only time events). There is no ideal way for this, but you can set a compiler-flag (in Dymola 2020x it is in Simulation>Setup>Compiler>Custom Options>Compiler) and set /DFindEvent_=0 for Visual Studio - I believe it should be-DFindEvent_=0 for gcc.
    • Unfortunately it does not seem possible to get the time-values adjusted for the time-axis as you want.

    However, in many cases this will cause less accurate handling of events, which will cause problems, e.g., clutches not fully locking in mechanical systems.