Computational Astrophysics I: Introduction and Basic Concepts
Total Page:16
File Type:pdf, Size:1020Kb
Computational Astrophysics I: Introduction and basic concepts Helge Todt Astrophysics Institute of Physics and Astronomy University of Potsdam SoSe 2021, 3.6.2021 H. Todt (UP) Computational Astrophysics SoSe 2021, 3.6.2021 1 / 52 The (special) three-body problem H. Todt (UP) Computational Astrophysics SoSe 2021, 3.6.2021 2 / 52 The (special)y three-body problemI We will not solve the general case of the three-body problem, but consider only the following configuration (m1; m2 < M): y 2 d ~r1 GMm1 m2 m1 2 = − 3 ~r1 r dt r1 21 m1 Gm1m2 + 3 ~r21 (1) r21 r r 2 1 2 d ~r2 GMm2 m2 2 = − 3 ~r2 dt r2 Gm1m2 − 3 ~r21 (2) r21 M x y not to confuse with the restricted three-body problem, where m1 ≈ m2 m3 ! Lagrangian points, e.g, L1 for SOHO, L2 for JWST H. Todt (UP) Computational Astrophysics SoSe 2021, 3.6.2021 3 / 52 The (special)y three-body problemII It is useful to divide the Eqn. (1) & (2) each by m1 and m2 respectively: 2 d ~r1 GM Gm2 2 = − 3 ~r1 + 3 ~r21 (3) dt r1 r21 2 d ~r2 GM Gm1 2 = − 3 ~r2 − 3 ~r21 (4) dt r2 r21 Moreover we can set – using astronomical units – again: GM = 4π2 (5) The terms Gm2 Gm1 + 3 ~r21 & − 3 ~r21 (6) r21 r21 can be written with help of mass ratios m m 2 & − 1 (7) M M H. Todt (UP) Computational Astrophysics SoSe 2021, 3.6.2021 4 / 52 The (special)y three-body problem III so that m m ratio[0] = 2 GM & ratio[1] = − 1 GM (8) M M The accelerations are then calculated like this: dx = x[1] - x[0] ... dr3 = pow(dx * dx + dy * dy , 3./2. ) ... ax = -GM * x[i] / r3 + ratio[i] * dx / dr3 ay = -GM * y[i] / r3 + ratio[i] * dy / dr3 H. Todt (UP) Computational Astrophysics SoSe 2021, 3.6.2021 5 / 52 Methods for solving the Newtonian equations of motion H. Todt (UP) Computational Astrophysics SoSe 2021, 3.6.2021 6 / 52 Numerical IntegrationI Review ! Newtonian equations of motion dv = a(t) (9) dt dx = v(t) (10) dt Numerical solution from Taylor expansion: 2 vn+1 = vn + an ∆t + O((∆t) ) (11) 1 x = x + v ∆t + a (∆t)2 + O((∆t)3) (12) n+1 n n 2 n Euler method: account only for O(∆t) (for ∆t ! 0): vn+1 = vn + an ∆t (13) xn+1 = xn + vn ∆t (14) therefore, only having O(∆t): H. Todt (UP) Computational Astrophysics SoSe 2021, 3.6.2021 7 / 52 Numerical IntegrationII ! local truncation error in one time step: ∼ (∆t)2 t 1 ! global error over t: ∼ (∆t), because n steps with n = ∆t ∼ ∆t , so order of global error 1 reduced by ∆t A method is of n th order, if the global error is of the order of (∆t)n. The Euler method is of of 1st order. Note, the Euler-Cromer method (semi-implicit Euler method) is also of 1st order, but conserves energy (symplectic integrator): vn+1 = vn + an(xn)∆t (15) xn+1 = xn + vn+1∆t (16) but there is also a 2nd variant of the (semi-implicit) Euler method xn+1 = xn + vn∆t (17) vn+1 = vn + an+1(xn+1)∆t (18) H. Todt (UP) Computational Astrophysics SoSe 2021, 3.6.2021 8 / 52 Numerical Integration III Possible improvement: use velocity from the midpoint of the interval cf. Heun’s method (Karl Heun, 1859-1929) xn+1 (vn+1 ) vn+1 = vn + an∆t (as for Euler) (19) xn+1 1 xn+1 (vn ) x = x + (v + v )∆t (20) n+1 n 2 n n+1 1 2 x = x + v ∆t + a ∆t (21) n n n 2 n tn tn+1 t ! accuracy of position is of 2nd order and velocity is of 1st order (only good for constant acceleration, not more accurate than Euler, as error increases with each time step) H. Todt (UP) Computational Astrophysics SoSe 2021, 3.6.2021 9 / 52 Numerical IntegrationIV Better (stable for oscillatory motions with const. ∆t ≤ 2=!, therefore common, error bounded): Halfstep method / Leapfrog integration v 1 = v 1 + an∆t (22) n+ 2 n− 2 xn+1 = xn + v 1 ∆t (23) n+ 2 v1/2 v3/2 ... vn/2 vn/2+1 x0 x1 ... xn xn+1 t0 t1 ... tn tn+1 H. Todt (UP) Computational Astrophysics SoSe 2021, 3.6.2021 10 / 52 Numerical IntegrationV ! 2nd order with same number of steps as Euler (1st order) But: not self starting, i.e. from Eq. (22) 9 v 1 2 therefore Euler method for the first half step: 1 v 1 = v0 + a0∆t (24) 2 2 Moreover, velocity steps can be eliminated by using Eq. (22) & (23): (xn+1 − xn) − (xn − xn−1) = (v 1 − v 1 )∆t (25) n+ 2 n− 2 xn+1 − 2xn + xn−1 = an∆t (26) 2 xn+1 = 2xn − xn−1 + an∆t (27) 1 2 with start values x0; x1 = x0 + v0 + 2 a0∆t (so v0 is still required!) H. Todt (UP) Computational Astrophysics SoSe 2021, 3.6.2021 11 / 52 Numerical IntegrationVI Or, by interpolation of intermediate values as combination of symplectic, semi-implicit Euler methods (Eq. (15)-(18)) 1 ) 1 ) v 1 = vn + an ∆t xn+1 = x 1 + v 1 ∆t n+ 2 2 n+ 2 n+ 2 2 1 (28) 1 (29) x 1 = xn + v 1 ∆t vn+1 = v 1 + an+1 ∆t n+ 2 n+ 2 2 n+ 2 2 by substituting system (28) into system (29) one obtains Leapfrog with integer steps: 1 x = x + v ∆t + a ∆t2 (30) n+1 n n 2 n 1 v = v + (a + a )∆t (31) n+1 n 2 n n+1 ! so-called Verlet integration (see next slides) H. Todt (UP) Computational Astrophysics SoSe 2021, 3.6.2021 12 / 52 Numerical Integration VII Higher order methods for that purpose: Taylor expansion of xn−1 (negative time step): 1 x = x − v ∆t + a (∆t)2 − O((∆t)3) (32) n−1 n n 2 n 1 + x = x + v ∆t + a (∆t)2 + O((∆t)3) (33) n+1 n n 2 n 2 4 = xn+1 + xn−1 = 2xn + an(∆t) + O((∆t) ) (34) 2 ) xn+1 = 2xn − xn−1 + an(∆t) (35) Analogously: 1 x = x + v ∆t + a (∆t)2 + O((∆t)3) (36) n+1 n n 2 n 1 − (x = x − v ∆t + a (∆t)2 − O((∆t)3)) (37) n−1 n n 2 n 3 = xn+1 − xn−1 = 2vn∆t + O((∆t) ) (38) x − x ) v = n+1 n−1 (Verlet) (39) n 2∆t H. Todt (UP) Computational Astrophysics SoSe 2021, 3.6.2021 13 / 52 Numerical Integration VIII ! method of 2nd order in v and 3rd order in x But: 1 2 not self starting (needs start values x0; x1 = x0 + v0 + 2 a0∆t , see above) Eq. (39) contains differences of two values of same order of magnitude and expected ∆x x ! round-off errors possible (subtractive cancelation) Therefore, from Eq. (39) xn−1 = xn+1 − 2vn∆t insert in Eq. (35): (40) 2 xn+1 = 2xn − xn+1 + 2vn∆t + an(∆t) (41) Solve for xn+1, yields: Velocity Verlet 1 x = x + v ∆t + a (∆t)2 (42) n+1 n n 2 n 1 v = v + (a + a )∆t (43) n+1 n 2 n+1 n H. Todt (UP) Computational Astrophysics SoSe 2021, 3.6.2021 14 / 52 Numerical IntegrationIX ! self-starting ! minimizes round-off errors (no differences) ! 4th order in x (why? ! Eq. (36) & (37)) Eq. (43) results from Eq. (39) for vn+1: x − x v = n+2 n (44) n+1 2∆t 2 and xn+2 = 2xn+1 − xn + an+1(∆t) from Eq. (35) (45) 2x − x + a (∆t)2 − x ) v = n+1 n n+1 n (46) n+1 2∆t x − x 1 = n+1 n + a (∆t)2 & x from Eq. (42) ∆t 2 n+1 n+1 1 2 xn + vn∆t + an(∆t) − xn 1 = 2 + a ∆t (47) ∆t 2 n+1 1 = v + (a + a )∆t (48) n 2 n+1 n H. Todt (UP) Computational Astrophysics SoSe 2021, 3.6.2021 15 / 52 Numerical IntegrationX Alternatively: (developed for liquid particles in a Lennard-Jones potential) Beeman method (Schofield 1973; Beeman 1976) 1 x = x + v ∆t + (4a − a )(∆t)2 (49) n+1 n n 6 n n−1 1 v = v + (2a + 5a − a )∆t (50) n+1 n 6 n+1 n n−1 ! not self-starting ! locally: O(∆t)4 in x and O(∆t)3 in v, globally O(∆t)3 ! better energy conservation than for Verlet, but more calculation steps even better: ! Runge-Kutta method of 4th order H. Todt (UP) Computational Astrophysics SoSe 2021, 3.6.2021 16 / 52 The Runge-Kutta method H. Todt (UP) Computational Astrophysics SoSe 2021, 3.6.2021 17 / 52 Runge-Kutta method of 4th orderI Remember: Euler-Richardson method (Euler-halfstep method) an = F (xn; vn; tn)=m (51) 1 v = v + a ∆t (52) M n n 2 1 x = x + v ∆t (53) M n n 2 1 a = F x ; v ; t + ∆t =m (54) M M M n 2 vn+1 = vn + aM∆t (55) xn+1 = xn + vM∆t (56) ! calculation of F or a, respectively, for the whole step at the “midpoint” of the interval, instead of using the values from the beginning ≡ Runge-Kutta method 2nd order H.