-
-
Notifications
You must be signed in to change notification settings - Fork 125
Update solar system #535
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
Merged
Merged
Update solar system #535
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e17230d
Update solar system
YingboMa 8bc44ea
Update 05-outer_solar_system.jmd
ChrisRackauckas 89b12d1
update to v1.7?
ChrisRackauckas ba7c71d
Merge remote-tracking branch 'origin/myb/solar' into myb/solar
ChrisRackauckas 7f668f9
match scimlbenchmarks?
ChrisRackauckas 3a45989
v1.8?
ChrisRackauckas b96cae1
Update run_tutorial.yml
staticfloat fa698b2
Update test_sciml.yml
staticfloat 0919c2b
Up
YingboMa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| --- | ||
| title: The Outer Solar System | ||
| author: Yingbo Ma, Chris Rackauckas | ||
| --- | ||
|
|
||
| ## Data | ||
|
|
||
|
|
||
| The chosen units are: masses relative to the sun, so that the sun has mass $1$. We have taken $m_0 = 1.00000597682$ to take account of the inner planets. Distances are in astronomical units , times in earth days, and the gravitational constant is thus $G = 2.95912208286 \cdot 10^{-4}$. | ||
|
|
||
| | planet | mass | initial position | initial velocity | | ||
| | --- | --- | --- | --- | | ||
| | Jupiter | $m_1 = 0.000954786104043$ | <ul><li>-3.5023653</li><li>-3.8169847</li><li>-1.5507963</li></ul> | <ul><li>0.00565429</li><li>-0.00412490</li><li>-0.00190589</li></ul> | ||
| | Saturn | $m_2 = 0.000285583733151$ | <ul><li>9.0755314</li><li>-3.0458353</li><li>-1.6483708</li></ul> | <ul><li>0.00168318</li><li>0.00483525</li><li>0.00192462</li></ul> | ||
| | Uranus | $m_3 = 0.0000437273164546$ | <ul><li>8.3101420</li><li>-16.2901086</li><li>-7.2521278</li></ul> | <ul><li>0.00354178</li><li>0.00137102</li><li>0.00055029</li></ul> | ||
| | Neptune | $m_4 = 0.0000517759138449$ | <ul><li>11.4707666</li><li>-25.7294829</li><li>-10.8169456</li></ul> | <ul><li>0.00288930</li><li>0.00114527</li><li>0.00039677</li></ul> | ||
| | Pluto | $ m_5 = 1/(1.3 \cdot 10^8 )$ | <ul><li>-15.5387357</li><li>-25.2225594</li><li>-3.1902382</li></ul> | <ul><li>0.00276725</li><li>-0.00170702</li><li>-0.00136504</li></ul> | ||
|
|
||
| The data is taken from the book "Geometric Numerical Integration" by E. Hairer, C. Lubich and G. Wanner. | ||
|
|
||
| ```julia | ||
| using Plots, OrdinaryDiffEq, ModelingToolkit | ||
| gr() | ||
|
|
||
| G = 2.95912208286e-4 | ||
| M = [1.00000597682, 0.000954786104043, 0.000285583733151, 0.0000437273164546, 0.0000517759138449, 1/1.3e8] | ||
| planets = ["Sun", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto"] | ||
|
|
||
| pos = [0.0 -3.5023653 9.0755314 8.310142 11.4707666 -15.5387357 | ||
| 0.0 -3.8169847 -3.0458353 -16.2901086 -25.7294829 -25.2225594 | ||
| 0.0 -1.5507963 -1.6483708 -7.2521278 -10.8169456 -3.1902382] | ||
| vel = [0.0 0.00565429 0.00168318 0.00354178 0.0028893 0.00276725 | ||
| 0.0 -0.0041249 0.00483525 0.00137102 0.00114527 -0.00170702 | ||
| 0.0 -0.00190589 0.00192462 0.00055029 0.00039677 -0.00136504] | ||
| tspan = (0.0, 200_000.0) | ||
| ``` | ||
|
|
||
| The N-body problem's Hamiltonian is | ||
|
|
||
| $$H(p,q) = \frac{1}{2}\sum_{i=0}^{N}\frac{p_{i}^{T}p_{i}}{m_{i}} - G\sum_{i=1}^{N}\sum_{j=0}^{i-1}\frac{m_{i}m_{j}}{\left\lVert q_{i}-q_{j} \right\rVert}$$ | ||
|
|
||
| Here, we want to solve for the motion of the five outer planets relative to the sun, namely, Jupiter, Saturn, Uranus, Neptune and Pluto. | ||
|
|
||
| ```julia | ||
| const ∑ = sum | ||
| const N = 6 | ||
| @variables t u(t)[1:3, 1:N] | ||
| u = collect(u) | ||
| D = Differential(t) | ||
| potential = -G*∑(i->∑(j->(M[i]*M[j])/√(∑(k->(u[k, i]-u[k, j])^2, 1:3)), 1:i-1), 2:N) | ||
| ``` | ||
|
|
||
| ## Hamiltonian System | ||
|
|
||
| `NBodyProblem` constructs a second order ODE problem under the hood. We know that a Hamiltonian system has the form of | ||
|
|
||
| $$\dot{p} = -H_{q}(p,q)\quad \dot{q}=H_{p}(p,q)$$ | ||
|
|
||
| For an N-body system, we can symplify this as: | ||
|
|
||
| $$\dot{p} = -\nabla{V}(q)\quad \dot{q}=M^{-1}p.$$ | ||
|
|
||
| Thus $\dot{q}$ is defined by the masses. We only need to define $\dot{p}$, and this is done internally by taking the gradient of $V$. Therefore, we only need to pass the potential function and the rest is taken care of. | ||
|
|
||
| ```julia | ||
| eqs = vec(@. D(D(u))) .~ .- ModelingToolkit.gradient(potential, vec(u)) ./ repeat(M, inner=3) | ||
| @named sys = ODESystem(eqs, t) | ||
| ss = structural_simplify(sys) | ||
| prob = ODEProblem(ss, [vec(u .=> pos); vec(D.(u) .=> vel)], tspan) | ||
| sol = solve(prob, Tsit5()); | ||
| ``` | ||
|
|
||
| ```julia | ||
| plt = plot() | ||
| for i in 1:N | ||
| plot!(plt, sol, idxs=(u[:, i]...,), lab = planets[i]) | ||
| end | ||
| plot!(plt; xlab = "x", ylab = "y", zlab = "z", title = "Outer solar system") | ||
| ``` | ||
|
|
||
| ```julia, echo = false, skip="notebook" | ||
| using SciMLTutorials | ||
| SciMLTutorials.tutorial_footer(WEAVE_ARGS[:folder],WEAVE_ARGS[:file]) | ||
| ``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 link doesn’t seem to work.
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 HTMLs aren't built anymore.
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.
It should build to https://tutorials.sciml.ai/dev/ soon