Imported Upstream version 1.57.0
[platform/upstream/boost.git] / libs / numeric / odeint / doc / tutorial_solar_system.qbk
1 [/============================================================================
2   Boost.odeint
3
4   Copyright 2011-2012 Karsten Ahnert
5   Copyright 2011-2012 Mario Mulansky
6   Copyright 2012 Sylwester Arabas
7
8   Use, modification and distribution is subject to the Boost Software License,
9   Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
10   http://www.boost.org/LICENSE_1_0.txt)
11 =============================================================================/]
12
13
14
15 [section Solar system]
16
17 [section Gravitation and energy conservation]
18
19 The next example in this tutorial is a simulation of the outer solar system, consisting of the sun, Jupiter, Saturn, Uranus, Neptune and Pluto.
20
21 [$solar_system.jpg]
22
23 Each planet and of course the sun will be represented by mass points. The interaction force between each object is the gravitational force which can be written as
24
25 ['F[subl ij] = -__gamma m[subl i] m[subl j] ( q[subl i] - q[subl j] ) / | q[subl i] - q[subl j] | [super 3]]
26
27 where [' __gamma] is the gravitational constant, ['m[subl i]] and ['m[subl j]] are the masses and ['q[subl i]] and ['q[subl j]] are the locations of the two objects. The equations of motion are then
28
29 ['dq[subl i] / dt = p[subl i]]
30
31 ['dp[subl i] / dt = 1 / m[subl i] __Sigma[subl ji] F[subl ij]]
32
33 where ['p[subl i]] is the momenta of object ['i]. The equations of motion can also be derived from the Hamiltonian
34
35 ['H = __Sigma[subl i] p[subl i][super 2] / ( 2 m[subl i] ) + __Sigma[subl j] V( q[subl i] , q[subl j] )]
36
37 with the interaction potential ['V(q[subl i],q[subl j])]. The Hamiltonian equations give the
38 equations of motion
39
40 ['dq[subl i] / dt = dH / dp[subl i]]
41
42 ['dp[subl i] / dt = -dH / dq[subl i]]
43
44 In time independent Hamiltonian system the energy and the phase space volume
45 are conserved and special integration methods have to be applied in order to
46 ensure these conservation laws. The odeint library provides classes for
47 separable Hamiltonian systems, which can be written in the form ['H = __Sigma
48 p[subl i][super 2] / (2m[subl i]) + H[subl q](q)], where ['H[subl q](q)] only
49 depends on the coordinates. Although this functional form might look a bit
50 arbitrary, it covers nearly all classical mechanical systems with inertia and
51 without dissipation, or where the equations of motion can be written in the
52 form ['dq[subl i] / dt = p[subl i]] / m[subl i] , ['dp[subl i] / dt = f(
53 q[subl i] )].
54
55 [note A short physical note: While the two-body-problem is known to be
56 integrable, that means it can be solved with purely analytic techniques,
57 already the three-body-problem is not solvable. This was found in the end of the
58 19th century by H. Poincare which led to the whole new subject of
59 [@http://en.wikipedia.org/wiki/Chaos_theory Chaos Theory].]
60
61 [endsect]
62
63
64 [section Define the system function]
65
66 To implement this system we define a 3D point type which will represent the space as well as the velocity. Therefore, we use the operators from __boost_operators:
67
68 [import ../examples/point_type.hpp]
69 [point_type]
70
71
72 The next step is to define a container type storing the values of ['q] and ['p] and to define system functions. As container type we use `boost::array`
73
74 [import ../examples/solar_system.cpp]
75 [container_type_definition]
76
77 The `container_type` is different from the state type of the ODE. The state type of the ode is simply a `pair< container_type , container_type >` since it needs the information about the coordinates and the momenta.
78
79 Next we define the system's equations.
80 As we will use a stepper that accounts for the Hamiltonian (energy-preserving)
81 character of the system, we have to define the rhs different from the usual
82 case where it is just a single function.
83 The stepper will make use of the separable character, which means the system
84 will be defined by two objects representing ['f(p) = -dH/dq] and ['g(q) = dH/dp]:
85
86 [coordinate_function]
87
88 [momentum_function]
89
90 In general a three body-system is chaotic, hence we can not expect that arbitrary initial conditions of the system will lead to a solution comparable with the solar system dynamics. That is we have to define proper initial conditions, which are taken from the book of Hairer, Wannier, Lubich __hairer_geom_ref.
91
92 As mentioned above, we need to use some special integrators in order to
93 conserve phase space volume. There is a well known family of such integrators,
94 the so-called Runge-Kutta-Nystroem solvers, which we apply here in terms of a
95 `symplectic_rkn_sb3a_mclachlan` stepper:
96
97 [integration_solar_system]
98
99 These integration routine was used to produce the above sketch of the solar system. Note, that there are two particularities in this example. First, the state of the symplectic stepper is not `container_type` but a pair of `container_type`. Hence, we must pass such a pair to the integrate function. Since, we want to pass them as references we can simply pack them into __boost_ref. The second point is the observer, which is called with a state type, hence a pair of `container_type`. The reference wrapper is also passed, but this is not a problem at all:
100
101 [streaming_observer]
102
103 [tip You can use C++11 lambda to create the observers]
104
105 The full example can be found here: [github_link libs/numeric/odeint/examples/solar_system.cpp solar_system.cpp]
106
107 [endsect]
108
109 [endsect]