modelica / ModelicaStandardLibrary

Free (standard conforming) library to model mechanical (1D/3D), electrical (analog, digital, machines), magnetic, thermal, fluid, control systems and hierarchical state machines. Also numerical functions and functions for strings, files and streams are included.
https://doc.modelica.org
BSD 3-Clause "New" or "Revised" License
481 stars 169 forks source link

Unnecessary event generation in Modelica.Electrical.Analog.Examples.OpAmps.SignalGenerator #3417

Open modelonrobinandersson opened 4 years ago

modelonrobinandersson commented 4 years ago

In the BTL of the model Modelica.Electrical.Analog.Examples.OpAmps.SignalGenerator we have the following equation block:

Torn variables:
0     r1.v
1     opAmp1.v_in
2     r2.v
3     opAmp1.v_out

Iteration variables:
0     r2.i (start=Vps / r2.R)

Torn equations:
0     r1.v := r1.R_actual * (- r2.i)
1     opAmp1.v_in := r1.v + opAmp2.v_out
2     r2.v := r2.R_actual * r2.i
3     opAmp1.v_out := smooth(0, if opAmp1.V0 * opAmp1.v_in > opAmp1.Vps then opAmp1.Vps elseif opAmp1.V0 * opAmp1.v_in < Vns then Vns else opAmp1.V0 * opAmp1.v_in)

Residual equations:
0     r2.v = opAmp1.v_in - opAmp1.v_out

According to the Modelica language specification, there is no guarantee that the smooth-operator does not generate any events. When this model is simulated with Optimica Compiler Toolkit, the event generation resulting from torn equation 3 with the smooth-operator causes an infinite loop in the event iteration, and this is due to minor numerical noise. There is no reason to have event generation here since r2.i varies to such a small degree. Therefore we suggest setting the parameter "strict" on the components opAmp1 and opAmp2, equal to "true" instead of the current value "false", using the more appropriate noEvent branch instead.

beutlich commented 4 years ago

See https://github.com/modelica/ModelicaStandardLibrary/pull/3432#issuecomment-590191439.