I have a question regarding event handling in OpenModelica and Dymola. The following model limits the input signal to a certain threshold. This is needed to avoid a negative argument of log(). Therefor an event is created and the variable of the argument 'l' is changed as the event becomes true.
As far as I understood, the DASSL solver should recognize the event and adapt its step size automatically to resolve the event correctly. The given number of intervals is only used to define the number of points saved to the output.
Solving the model ‘CompleteModel’ with DASSL in Dymola for 10 seconds and with a number of intervals of 100 works fine and variable ‘l’ is limited to 0.05. Solving the model with only 10 intervals fails. Strangely enough DASSL in OpenModelica solves the model correct, independent from the given number of intervals.
Can this behavior be expected? Are there big differences between the DASSL solvers of Dymola and OpenModelica? In my opinion, the correct solution of the model with DASSL should be independent from the number of (saved) intervals (as it is in OpenModelica).
package EventHandling
model LimitSignal
Real l;
Real lmin(start = 1, fixed = true);
Real x;
Boolean Event(start = false, fixed = true);
input Real InputSignal;
algorithm
when InputSignal <= 0.05 then
Event := true;
lmin := pre(InputSignal);
end when;
equation
l = if Event then lmin else InputSignal;
x = log(l);
end LimitSignal;
model RampSignal
parameter Real start = 1;
parameter Real height = 2;
parameter Real Time = 10;
output Real y;
equation
y = 1 - (height/Time)*time;
end RampSignal;
model CompleteModel
LimitSignal EventHandling(InputSignal = Signal.y);
RampSignal Signal;
end CompleteModel;
end EventHandling;
The DASSL solvers are different. OpenModelica has a variety of different DASSL solvers, so even OpenModelica is different from itself. The OpenModelica dassl code is based on daskr (previously, it was ddasl). Options include things like:
dasslJacobian=[coloredNumerical (default)|numerical|internalNumerical|coloredSymbolical|symbolical]
dasslnoRootFinding
dasslnoRestart
maxStepSize
maxIntegrationOrder
Event handling is done separate to the numerical integrator, so it is also done differently in different tools. OpenModelica also behaves differently if you change the output interval because it is used as a heuristic to determine some nominal step size/epsilon values/etc.
But yes, you should be able to get the correct solution with a variable-step solver.
Note: I tried it in OpenModelica and stopTime=10, numberOfIntervals=10 fails with dassl there as well. It just plots the value until the time of the assertion. So it gets to time=4.5, tries to step to time=5.0 (assertion triggers), tries time=6.0 (assertion triggers), tries time=5.25 (assertion triggers), gives up. The reason OpenModelica gives up early is that it triggers assertions and not convergence errors or the event. Probably is a bug.