Skip to content

Commit 377545b

Browse files
Merge pull request #535 from SciML/myb/solar
Update solar system
2 parents d8ef8ee + 0919c2b commit 377545b

File tree

7 files changed

+1244
-621
lines changed

7 files changed

+1244
-621
lines changed

.buildkite/run_tutorial.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
agents:
22
queue: "juliaecosystem"
33
sandbox.jl: true
4+
arch: "x86_64"
45

56
# This is a pipeline that weaves a tutorial, then uploads the resultant
67
# .PDF and other reports as (buildkite, not Julia) artifacts. The `coppermind`
@@ -18,7 +19,7 @@ steps:
1819
- BUILDKITE_S3_SECRET_ACCESS_KEY="U2FsdGVkX1+SPF81nkK7KQ64DsafSl0qq2iG7BsQs1xlTYEtZV3MqQl3l/NWaiocaEywZZFbAB5zpnKPD0xHTQ=="
1920
- BUILDKITE_S3_DEFAULT_REGION="U2FsdGVkX1/cORlxhXcxhja2JkqC0f8RmaGYxvGBbEg="
2021
- JuliaCI/julia#v1:
21-
version: 1.6
22+
version: 1.8
2223
- staticfloat/sandbox:
2324
rootfs_url: "https://jc-rootfs-images.s3.amazonaws.com/aws_uploader-2021-11-12.x86_64.tar.gz"
2425
rootfs_treehash: "986217e5b36efd3b3b91ed90df8e36d628cf543f"
@@ -63,7 +64,7 @@ steps:
6364
files:
6465
- .buildkite/ssh_deploy.key
6566
- JuliaCI/julia#v1:
66-
version: 1.7
67+
version: 1.8
6768
- staticfloat/sandbox:
6869
rootfs_url: "https://jc-rootfs-images.s3.amazonaws.com/aws_uploader-2021-11-12.x86_64.tar.gz"
6970
rootfs_treehash: "986217e5b36efd3b3b91ed90df8e36d628cf543f"

.buildkite/test_sciml.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
agents:
22
queue: "juliaecosystem"
3+
arch: "x86_64"
34

45
steps:
5-
- label: ":julia: Run tests on 1.7"
6+
- label: ":julia: Run tests on 1.8"
67
plugins:
78
- JuliaCI/julia#v1:
8-
version: 1.7
9+
version: 1.8
910
- JuliaCI/julia-test#v1:
1011
timeout_in_minutes: 20
1112
artifact_paths:

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ SciMLTutorials.open_notebooks()
5252
- [Tutorial on using spatial SSAs in DiffEqJump](http://tutorials.sciml.ai/html/jumps/spatial.html)
5353
- [Kepler Problem Orbit](http://tutorials.sciml.ai/html/models/05-kepler_problem.html)
5454
- [Spiking Neural Systems](http://tutorials.sciml.ai/html/models/08-spiking_neural_systems.html)
55+
- [Outer Solar System](http://tutorials.sciml.ai/html/models/05-outer_solar_system.html)
5556
- Advanced ODE Features
5657
- [Feagin's Order 10, 12, and 14 Methods](http://tutorials.sciml.ai/html/ode_extras/01-feagin.html)
5758
- [Finding Maxima and Minima of DiffEq Solutions](http://tutorials.sciml.ai/html/ode_extras/02-ode_minmax.html)

src/SciMLTutorials.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ latexfile = joinpath(@__DIR__, "..", "templates", "julia_tex.tpl")
88
default_builds = (:script,:github)
99

1010
function weave_file(folder,file,build_list=default_builds)
11-
target = joinpath(repo_directory, "tutorials", folder, file)
11+
target = joinpath(folder, file)
1212
@info("Weaving $(target)")
1313

14-
if isfile(joinpath(repo_directory, "tutorials", folder, "Project.toml"))
14+
if isfile(joinpath(folder, "Project.toml"))
1515
@info("Instantiating", folder)
16-
Pkg.activate(joinpath(repo_directory,"tutorials", folder))
16+
Pkg.activate(joinpath(folder))
1717
Pkg.instantiate()
1818
Pkg.build()
1919

@@ -66,7 +66,7 @@ function weave_all(build_list=default_builds)
6666
end
6767

6868
function weave_folder(folder,build_list=default_builds)
69-
for file in readdir(joinpath(repo_directory,"tutorials",folder))
69+
for file in readdir(joinpath(folder))
7070
# Skip non-`.jmd` files
7171
if !endswith(file, ".jmd")
7272
continue
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
---
2+
title: The Outer Solar System
3+
author: Yingbo Ma, Chris Rackauckas
4+
---
5+
6+
## Data
7+
8+
9+
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}$.
10+
11+
| planet | mass | initial position | initial velocity |
12+
| --- | --- | --- | --- |
13+
| 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>
14+
| 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>
15+
| 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>
16+
| 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>
17+
| 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>
18+
19+
The data is taken from the book "Geometric Numerical Integration" by E. Hairer, C. Lubich and G. Wanner.
20+
21+
```julia
22+
using Plots, OrdinaryDiffEq, ModelingToolkit
23+
gr()
24+
25+
G = 2.95912208286e-4
26+
M = [1.00000597682, 0.000954786104043, 0.000285583733151, 0.0000437273164546, 0.0000517759138449, 1/1.3e8]
27+
planets = ["Sun", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto"]
28+
29+
pos = [0.0 -3.5023653 9.0755314 8.310142 11.4707666 -15.5387357
30+
0.0 -3.8169847 -3.0458353 -16.2901086 -25.7294829 -25.2225594
31+
0.0 -1.5507963 -1.6483708 -7.2521278 -10.8169456 -3.1902382]
32+
vel = [0.0 0.00565429 0.00168318 0.00354178 0.0028893 0.00276725
33+
0.0 -0.0041249 0.00483525 0.00137102 0.00114527 -0.00170702
34+
0.0 -0.00190589 0.00192462 0.00055029 0.00039677 -0.00136504]
35+
tspan = (0.0, 200_000.0)
36+
```
37+
38+
The N-body problem's Hamiltonian is
39+
40+
$$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}$$
41+
42+
Here, we want to solve for the motion of the five outer planets relative to the sun, namely, Jupiter, Saturn, Uranus, Neptune and Pluto.
43+
44+
```julia
45+
const ∑ = sum
46+
const N = 6
47+
@variables t u(t)[1:3, 1:N]
48+
u = collect(u)
49+
D = Differential(t)
50+
potential = -G*∑(i->∑(j->(M[i]*M[j])/√(∑(k->(u[k, i]-u[k, j])^2, 1:3)), 1:i-1), 2:N)
51+
```
52+
53+
## Hamiltonian System
54+
55+
`NBodyProblem` constructs a second order ODE problem under the hood. We know that a Hamiltonian system has the form of
56+
57+
$$\dot{p} = -H_{q}(p,q)\quad \dot{q}=H_{p}(p,q)$$
58+
59+
For an N-body system, we can symplify this as:
60+
61+
$$\dot{p} = -\nabla{V}(q)\quad \dot{q}=M^{-1}p.$$
62+
63+
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.
64+
65+
```julia
66+
eqs = vec(@. D(D(u))) .~ .- ModelingToolkit.gradient(potential, vec(u)) ./ repeat(M, inner=3)
67+
@named sys = ODESystem(eqs, t)
68+
ss = structural_simplify(sys)
69+
prob = ODEProblem(ss, [vec(u .=> pos); vec(D.(u) .=> vel)], tspan)
70+
sol = solve(prob, Tsit5());
71+
```
72+
73+
```julia
74+
plt = plot()
75+
for i in 1:N
76+
plot!(plt, sol, idxs=(u[:, i]...,), lab = planets[i])
77+
end
78+
plot!(plt; xlab = "x", ylab = "y", zlab = "z", title = "Outer solar system")
79+
```
80+
81+
```julia, echo = false, skip="notebook"
82+
using SciMLTutorials
83+
SciMLTutorials.tutorial_footer(WEAVE_ARGS[:folder],WEAVE_ARGS[:file])
84+
```

0 commit comments

Comments
 (0)