Closed DaluS closed 2 years ago
Will try to investigate this in a few weeks (mid-December probably) if the problem is still there by then :-)
Yes ! I'll focus on using the rk8 from scipy for the moment :)
I coded a Lorenz system to check the qualitative system, for the moment both the rk2-scipy and the homemade rk4 are wrong :) (converging toward one of the point instead of being a strange attractor)
For both cases, a fork of the cockpit to test them will be joined to the next pull request
I went a bit further on the subject :
testConvergence_DampOsc
and both Rk1/Rk4 are not power-law which imply that either the convergence test is wrong or that the problem is somewhere else testConvergence_DampOsc
is showing that the first slope estimation is wrong, it might give insight on the problem The way I see it : The initial condition on the first derivative is not respected, even if well noted in get_summary
.
Maybe there is an error in the order of resolution ?
So I had a look using the DampOscillator
with Perfect
preset (because it is easy to see any problem) and it appears to me that the homemade rk4 behaves correctly if the time step is fine enough.
Below I compare:
erk4-scipy
(variable time step optimized by scipy)erk4-homemade
for dt
= 0.01 s, 0.001 s and 0.0001 sWe can see that the homemade output converges towards the scipy result as dt decreases.
I put the code so you can reproduce it ( I reduce Tmax
to avoid very large computations).
In [79]: hub = pgm.Hub(model='DampOscillator', preset='Perfect', verb=False)
In [80]: hub.set_dparam(key='Tmax', value=4, verb=False)
In [81]: hub.run(solver='eRK4-scipy')
In [82]: dax = hub.plot(key='Energy', color='k')
In [83]: hub.run(solver='eRK4-homemade')
In [84]: dax = hub.plot(key='Energy', color='r', dax=dax)
In [85]: hub.set_dparam(key='dt', value=0.001, verb=False)
In [86]: hub.run(solver='eRK4-homemade')
In [87]: dax = hub.plot(key='Energy', color='b', dax=dax)
In [88]: hub.set_dparam(key='dt', value=0.0001, verb=False)
In [89]: hub.run(solver='eRK4-homemade')
In [90]: dax = hub.plot(key='Energy', color='g', dax=dax)
This is an aspect that we had already discussed here, in PR #95 On my opinion, it shows that we should:
eRK4-scipy
by defaulteRK4-homemade
eRK4-homemade
without doing a convergence study with respect to the time step sizeI am still not sure why eRK8-scipy
gives wrong results though
Solved, see PR #130
I m closing this issue as it was solved
I had trouble with the homemade rk4, and decided to verify if our solvers were working well. In consequence, I coded a very simple couple ODE (dampened harmonic oscillator) and compared results with its analytical solution.
The Homemade RK4 still have a weird behavior. Here is a difference between the numeric and theoric value :
The slope is 1/2, it should be 4, this system surprisingly behave as a system of order 1/2.
It seems to me that the code is right, so I do not know why it is not working https://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods