-
Notifications
You must be signed in to change notification settings - Fork 116
3d-n-body-pendulum made a bit nicer. Should fix #534 #544
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
base: master
Are you sure you want to change the base?
Conversation
docs/examples/3d-n-body-pendulum.rst
Outdated
|
|
||
| t_span = (0., intervall) | ||
|
|
||
| def gradient(t, y, args): |
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.
This gradient function should not be needed. generate_ode_function creates the gradient function.
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.
This may not work:
- the signature of
solve_ivpis not the same asgenerate_ode_function(I believe generate_ode_function has the signature of odeit.) - If in solve_ivp a method other than RK45 is used, the
yis not C contiguous, soy = np.ascontiguousarray(y)is needed.
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.
Doing solve_ivp(lambda t, x: rhs(x, t) should be sufficient. If there is some issue with RK4 and y not being contiguous, this sounds like a new bug. That has never been required in the past.
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.
I must admit, I am not goot with these lambda functions.
Yes, there is an issue if e.g. method='Radau' in solve_ivp: I raised issue # 23657 with scipy, so
``y = np.ascontiguousarray(y) is needed, best I can tell.
This is also needed, where I calculate the reaction forces.
|
I tried to move more comments into text between code blocks. |
|
Moved more explanationd from code to text. |
docs/examples/3d-n-body-pendulum.rst
Outdated
| Objectives | ||
| ---------- | ||
|
|
||
| - Show how to use *generate_ode_function* as an alternative to *lambdify* |
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.
There are several instances of variables that need to be in double backticks throughout the page. Fixed width font in ReST is via double backticks.
docs/examples/3d-n-body-pendulum.rst
Outdated
|
|
||
| resultat1 = solve_ivp(gradient, t_span, y0, t_eval = times, args=(pL_vals,), method='Radau') | ||
| resultat1 = solve_ivp(gradient, t_span, y0, t_eval=times, args=(pL_vals,), | ||
| method='RK45', |
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.
RK45 is likely not appropriate choice for a model with collision (i.e. it is a stiff system).
If you use odeint() then you don't need the gradient function and it uses LSODA as the integrator by default which switches to a stiff integrator when needed.
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.
scipy discourages the use of odeint for new code: https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.odeint.html
I could try 'Radau', which is for stiff systems.
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.
PyDy uses odeint by default. So, until PyDy changes that I don't think we need to abide by SciPy's statement.
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.
You can run LSODA with odeint or solve_ivp, btw.
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.
That's what I assumed, given the signature of generate_ode_function.
Of course I can switch to odeint, just thought that given scipy's recommendation it may be good to show how to use it with generate_ode_function. Mostly this np.ascontiguousarray(..) was not trivial for me.
Radau works fine.
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.
However, if rhs_gen was generated with 'cython' 'and is used to, say, calculate the accelerations needed for the reaction forces still np.ascontiguousarray(..) is needed.
You'll need a minimal example to show this.
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.
The example is pushed shows this:
.. jupyter-execute::
RHS = np.empty((resultat.shape))
#pl_vals = np.ascontiguousarray(pL_vals)
for i in range(resultat.shape[0]):
#res = np.ascontiguousarray(resultat[i])
res = resultat[i]
RHS[i] = rhs_gen(res, 0.0, np.array(pL_vals))
If the np.ascontiguousarray(..) are blanked out like above, it will raise an error.
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.
However, if rhs_gen was generated with 'cython' 'and is used to, say, calculate the accelerations needed for the reaction forces still np.ascontiguousarray(..) is needed.
You'll need a minimal example to show this.
I made a minimum simulation and could NOT repeat this problem!
- I had failed to convert my constants from list into an np.array
- Strangely, when I use resultat[i] as given from solve_ivp, it does not work with generator='cython'. (it works with generator='symjit'). If I put resultat[i] = np.array(resultat[i]) it works with generator='cython'
Le me know if I should send you this minimum example.
I played around some more and found that somehow applying np.array(x) to an np.array x seems to 'heal' to non C contiguous issue.
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.
Interesting!
You can always report a new issue. The best is to include a minimal reproducing example that I can copy/paste from the issue.
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.
Interesting!
You can always report a new issue. The best is to include a minimal reproducing example that I can copy/paste from the issue.
I raised issue #547 with code showing it.
| kd.append(me.dot(rot[i] - rot1[i], uv)) | ||
|
|
||
| # Kanes's equations | ||
| Kanes's Equations |
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.
Many of these non-sentences are likely meant to be section headers.
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.
Will change accordingly.
Thanks! |
Looks to me, that the unsuccessful check may be due to the documentation with (3.9), may not allow 'symjit' |
generate_ode_functioninstead of lambdifyPyDY Visualizationto create the 3D animationI could not find a simple way to check the conformity using flake8. The original ipynb files were checked so I hope most is o.k.