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
472 stars 169 forks source link

Chaotic behavior: Modelica.Electrical.Analog.Examples.ChuaCircuit #4477

Open AHaumer opened 3 days ago

AHaumer commented 3 days ago

I wonder whether the results of the above mentioned example can be compared between different simulators. The default parameter settings lead to chaotic behavior. The results are extremely sensitive not only to parameters and initial conditions but also to tolerance and details of the solver. Choosing other parameter settings would either lead to periodic behavior or to a fix point. The parameters are extremely unrealistic and can't be validated with a real circuit: Who can get an inductance of 18 H and capacitances of 100 F and 10 F? @casella mentioned another chaotic oscillator in another discussion (#4771). Inspired by that, I implemented a few chaotic circuits with realistic parameters. They are even of didactic interest, I wonder whether we should:

I'm pretty sure that examples with chaotic behavior are nice demos but a very bad base for comparing results between different tools. @casella @HansOlsson @christiankral What's your opinion?

AHaumer commented 2 days ago

You can test my models at https://github.com/AHaumer/ChaoticCircuits

AHaumer commented 2 days ago

To demonstrate what I mean by "compared between different simulators" here we have a comparison between OpenModelica v1.23.1 and Dymola 2024x of the mentioned example, both simulations with tolerance = 1e-6: ChuaCircuit For a rather short time span both results are (nearly) the same, then they begin to drift apart. For periodic results, the difference between the two results also starts to grow but is less than 1 % during the simulation time.

casella commented 16 hours ago

@AHaumer, the Chua circuit is design on purpose to produce chaotic behaviour. There is nothing wrong with that, in fact, it was a fundamental discovery of 20th-century mathematics that you could get such kind of pseudo-random behaviour out of fully deterministic behavioural descriptions of systems dynamics. Of course the default experiment annotation should allow to actually see that.

And, BTW, it would be interesting not only to look at time plots of individual variables, but also to phase plots that allow to see the strange attractor that characterizes this system: immagine It is interesting to note that the time plot is highly sensitive to initial conditions and precision, but the shape of the strange attactor isn't.

I'm not worried at all by the sensitivity of the solution to the solver parameters etc., because that's the whole point of this system. The only thing we should be careful about is to avoid using such chaotic motion for regression testing and cross-tool checking. For that, we need to use a much shorter simulation interval, over which the trajectory instability does not have enough time to develop.

casella commented 16 hours ago

Regarding the values of the parameters, I checked the reference cited in the documentation. Indeed, the values of the parameters are:

As a consequence, the simulation interval should be a few ms, rather than 50,000 s.

I'm not sure why the circuit parameter were scaled that way, we should probably ask @christophclauss. Since we have a proper reference to a published paper, we should use the same parameters that are given there.

AHaumer commented 5 hours ago

I am rather sure about the parameters (maybe not 100% those from the paper but they work). R.R=1900 leads to periodic behavior, R.R=1800 to chaotic behavior. The interesting fact about that zoo of circuits is the dependence on parameters: Changing a certain parameter you may obtain a fixed point, periodic behavior or chaotic behavior. With a script you might even produce a bifurcation diagram. For comparison the periodic behavior is much better suited, for demonstration change the parameter to see chaotic behavior. For these parameters you get standard electronic components. Chua's diode you may implement with one or two operational amplifiers; see the solution in my repo https://github.com/AHaumer/ChaoticCircuits ChuaCircuit.zip

AHaumer commented 4 hours ago

See discussion in the language group #3473 about verificationExperiment annotation.