-
Notifications
You must be signed in to change notification settings - Fork 169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MSL 4.1.0 Regressions: OpAmps/SignalGenerator #4485
base: master
Are you sure you want to change the base?
Conversation
…nalGenerator.mo set {opAmp1, opAmp2}.strict=true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately System Modeler has unrelated issues with this model, and therefore I cannot comment on the effect of this change.
Just to be sure - how do you know that those issues are unrelated? The limits combined with the (optional) events are creating non-linear systems that can be difficult to solve, which can cause various problems that may seem unrelated. |
Thanks for pushing back, I just trusted what our internal issue tracker said was true, which may no longer be the case. What I'm observing now, is that this PR makes no difference for System Modeler that I can see. Our results (which come after a huge amount of warnings from nonlinear system solving) are similar to the current reference, but "delayed". Example variable: If I decrease the interval size aggressively to |
Thanks for your feedback @maltelenz |
Digging a bit further, our heuristics for when events should be generated inside Maybe |
…/SignalGenerator.mo
The more advanced handling with The homotopy was introduced in 9d5bc99 referring to #2017 and #2270 |
I converted this to draft since it needs more investigation, and I'm afraid that there should be changes applied to the IdealizedOpAmpLimited - for sure not for that release. |
To me this indicates that we should have the opposite of
|
Yes @HansOlsson it is an issue in the IdealizedOpAmpLimited, and this needs some more investigation. There are 3 groups of examples:
The parameter strict = true performs saturation of the output with noEvent, i.e. the exact time when the output gets saturated is not properly defined. That is ok for the first group of examples. Enclosed you'll find a small library with an implementation of the OpAmp which allows to choose smooth and strict (noEvent) separately. Feel free to test different parameter combinations and give feedback. With Dymola and OM I can test myself, @maltelenz your test with SystemModeler is highly appreciated. |
I tested the SignalGenerator example from the above zip file, in System Modeler, using this test library:
with these results: Let me know if I should try something more. |
Sorry if I couldn't keep up with the discussion. Here are my 2 cents. Op-Amps can be used for two kinds of application: one is linera amplifiers, where you try as much as you can to steer clear of saturation, and one is signal generators, where the outputs are often saturated and there are very fast swings from Vcc to -Vcc and vice-versa. For the first category, using smooth and avoiding events could be a good idea; for the second, it is pretty obvious that simulations will be inaccurate in terms, e.g., of predicting the oscillator frequency. Which is not a marginal issue when analyzing such circuits. So, even though we are well past the deadline, I would be inclined to try to fix the problem by allowing both options in the OpAmp model, and setting up the example with the appropriate one. As others have already said, this is really a modelling issue, not a tool issue. I think this shouldn't take much effort. I'll look at @AHaumer's smal library ASAP. |
Thanks a lot @maltelenz. That's really a pity, none of the results is correct: |
Regarding smooth: I would more say that tools assume that a derivative using smooth is "smooth enough" for the solvers (so not only C0 but C5 or similarly as required by the theory underlying the ODE/DAE-solvers), and this isn't the case for those use-cases. Regarding zero-solutions, apart from the smooth-ness and events there's another important aspect of the SignalGenerator-example: it has a "state" in the non-linear solver. Specifically in Dymola (also when generating events for smooth) depending on the start-value for |
Since this issue seems to depend of event generation of the specific solver: |
@AHaumer The new version of the |
@maltelenz Dymola shows a correct result, OpenModelica shows the same result as SystemModeler. Enclosed the whole package Modelica.Electrical.Analog.Examples.OpAmps from MSL with an enhanced version, |
How is System Modeler solving the system of equations?
|
I think this conversation is becoming too inefficient. I'd prefer investigating this in an online meeting instead. |
Thank you @AHaumer for providing the new test implementation and the tests in your OpAmps package! As I wrote above, I think that if you want to use the OpAmps as triggers and you want a precise estimation of the oscillator period, events should be used, otherwise we are depending on how ODE solvers react to signals that are not smooth enough and/or on which specific strategy each solver uses to handle That said, I checked The initial voltage of the capacitor is zero. The first possible solution is the one found by OpenModelica and System Modeller: all node voltages are zero, the op-amp input voltages are both zero, so they are equal, so their output is zero, and the system is at equilibrium. We know this is an unstable equilibrium, so in the real system small fluctuations in the op-amp input voltages due to electronic noise fluctuations will drive the system out of this equilibrium onto a stable periodic trajectory. Unfortunately, this doesn't happen in a numerical simulation, which has no such random fluctuations. If you simulate: model Unstable
Real x(start = 0, fixed = true);
equation
der(x) = x;
end Unstable; which is obviously unstable, you get a nice x = 0 solution also with numerical solvers, because any integration formula will just compute a zero increment, add it to the zero state and obtain an exact zero. The other two valid initial solutions correspond to opAmp1 ouptut being saturated either at +15 or -15 Volt; they are not equilibrium solutions, so the oscillations start from there. BTW, the choice of the actual initial solution by the circuit is completely non-deterministic. In practice, if you switch on such a circuit in real life, whether the intial output voltage of opAmp2 will be positive or negative will be due to chance. This is actually a very instructive example if you want to learn the possible intricacies of Modelica models involving nonlinear equations. I am sure @dzimmer would love that. How we deal with this, we'll discuss in the meeting. |
Modelica/Electrical/Analog/Examples/OpAmps/SignalGenerator.mo set {opAmp1, opAmp2}.strict=true
see #4333