Computational Astrophysics I: Introduction and Basic Concepts

Total Page:16

File Type:pdf, Size:1020Kb

Computational Astrophysics I: Introduction and Basic Concepts 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.
Recommended publications
  • A Spectral Deferred Correction Method Applied to the Shallow Water Equations on a Sphere
    OCTOBER 2013 J I A E T A L . 3435 A Spectral Deferred Correction Method Applied to the Shallow Water Equations on a Sphere JUN JIA,JUDITH C. HILL,KATHERINE J. EVANS, AND GEORGE I. FANN Oak Ridge National Laboratory, Oak Ridge, Tennessee MARK A. TAYLOR Sandia National Laboratories, Albuquerque, New Mexico (Manuscript received 13 February 2012, in final form 7 December 2012) ABSTRACT Although significant gains have been made in achieving high-order spatial accuracy in global climate modeling, less attention has been given to the impact imposed by low-order temporal discretizations. For long-time simulations, the error accumulation can be significant, indicating a need for higher-order temporal accuracy. A spectral deferred correction (SDC) method is demonstrated of even order, with second- to eighth-order accuracy and A-stability for the temporal discretization of the shallow water equations within the spectral-element High-Order Methods Modeling Environment (HOMME). Because this method is stable and of high order, larger time-step sizes can be taken while still yielding accurate long-time simulations. The spectral deferred correction method has been tested on a suite of popular benchmark problems for the shallow water equations, and when compared to the explicit leapfrog, five-stage Runge–Kutta, and fully implicit (FI) second-order backward differentiation formula (BDF2) time-integration methods, it achieves higher accuracy for the same or larger time-step sizes. One of the benchmark problems, the linear advection of a Gaussian bell height anomaly, is extended to run for longer time periods to mimic climate-length simula- tions, and the leapfrog integration method exhibited visible degradation for climate length simulations whereas the second-order and higher methods did not.
    [Show full text]
  • Simulation Methods in Physics 1
    ...script in development... Simulation Methods in Physics 1 Prof. Dr. Christian Holm Institute for Computational Physics University of Stuttgart WS 2012/2013 Contents 1 Introduction 3 1.1 Computer Science . 3 1.1.1 Historical developments . 3 1.1.2 TOP 500 Supercomputer list . 4 1.1.3 Moore's law (1970) . 5 1.2 Computer Simulations in Physics . 6 1.2.1 The New Trinity of Physics . 6 1.2.2 Optimization of simulation performance . 8 1.2.3 Optimization of simulation algorithms . 8 1.2.4 Computational approaches for different length scales . 9 2 Molecular Dynamics integrators 11 2.1 Principles of Molecular Dynamics . 11 2.1.1 Ergodicity . 11 2.2 Integration of equations of motion . 12 2.2.1 Algorithms . 12 2.2.2 Estimation of time step . 13 2.2.3 Verlet Algorithm . 13 2.2.4 Velocity Verlet Algorithm . 14 2.2.5 Leapfrog method . 15 2.2.6 Runge-Kutta method . 16 2.2.7 Predictor-Corrector methods . 17 2.2.8 Ljapunov-Characteristics . 17 3 Statistical mechanics - Quick & Dirty 20 3.1 Microstates . 20 3.1.1 Distribution functions . 20 3.1.2 Average values and thermodynamic limit . 22 3.2 Definition of Entropy and Temperature . 23 3.3 Boltzmann distribution . 24 3.3.1 Total energy and free energy . 25 3.4 Quantum mechanics and classcal partition functions . 26 3.5 Ensemble averages . 26 2 1 Introduction 1.1 Computer Science 1.1.1 Historical developments • The first calculating tool for performing arithmetic processes, the Abacus is used ∼ 1000 b.C.
    [Show full text]
  • Numerical Integration
    Game Physics Game and Media Technology Master Program - Utrecht University Dr. Nicolas Pronost Numerical Integration Updating position • Recall that 퐹푂푅퐶퐸 = 푀퐴푆푆 × 퐴퐶퐶퐸퐿퐸푅퐴푇퐼푂푁 – If we assume that the mass is constant then 퐹 푝표, 푡 = 푚 ∗ 푎(푝표, 푡) ′ ′ – We know that 푣 푡 = 푎(푡) and 푝표 푡 = 푣(푡) ′′ – So we have 퐹 푝표, 푡 = 푚 ∗ 푝표 (푡) • This is a differential equation – Well studied branch of mathematics – Often difficult to solve in real-time applications Game Physics 3 Taylor series • Taylor expansion series of a function can be applied on 푝0 at t + ∆푡 푝표 푡 + ∆푡 ∆푡2 = 푝 푡 + ∆t ∗ 푝 ′ 푡 + 푝 ′′ 푡 + ⋯ 표 표 2 표 ∆푡푛 + 푝 푛 푡 푛! 표 • But of course we don’t know the values of the entire infinite series, at best we have 푝표 푡 and the first two derivatives Game Physics 4 First order approximation • Hopefully, if ∆푡 is small enough, we can use an approximation ′ 푝표 푡 + ∆푡 ≈ 푝표 푡 + ∆t ∗ 푝표 푡 • Separating out position and velocity gives 퐹(푡) 푣 푡 + ∆푡 = 푣 푡 + 푎 푡 ∆푡 = 푣 푡 + ∆푡 푚 푝표(푡 + ∆푡) = 푝표(푡) + 푣(푡)∆푡 Game Physics 5 Euler’s method 5.1 • This is known as Euler’s method 푣 푡 + ∆푡 = 푣 푡 + 푎 푡 ∆푡 푝표(푡 + ∆푡) = 푝표(푡) + 푣(푡)∆푡 푣(푡 − ∆푡) 푡 푎(푡 − ∆푡) 푣(푡) 푡 + ∆푡 푣(푡) 푣(푡 + ∆푡) 푎(푡) Game Physics 6 Euler’s method • So by assuming the velocity is constant for the time ∆푡 elapsed between two frames – We compute the acceleration of the object from the net force applied on it 푎 푡 = 퐹(푡)/푚 – We compute the velocity from the acceleration 푣 푡 + ∆푡 = 푣 푡 + 푎 푡 ∆푡 – We compute the position from the velocity 푝표 푡 + ∆푡 = 푝표 푡 + 푣(푡)∆푡 Game Physics 7 Issues with linear dynamics • We only look at a sequence of instants without meaning – E.g.
    [Show full text]
  • Numerical Methods for Fluid Dynamics
    Texts in Applied Mathematics 32 Editors J.E. Marsden L. Sirovich S.S. Antman Advisors G. Iooss P. Holmes D. Barkley M. Dellnitz P. Newton For other titles published in this series, go to http://www.springer.com/series/1214 Dale R. Durran Numerical Methods for Fluid Dynamics With Applications to Geophysics Second Edition ABC Dale R. Durran University of Washington Department of Atmospheric Sciences Box 341640 Seattle, WA 98195-1640 USA [email protected] Series Editors J.E. Marsden L. Sirovich Control and Dynamical Systems, 107-81 Division of Applied Mathematics California Institute of Technology Brown University Pasadena, CA 91125 Providence, RI 02912 USA USA [email protected] [email protected] S.S. Antman Department of Mathematics and Institute for Physical Science and Technology University of Maryland College Park, MD 20742-4015 USA [email protected] ISSN 0939-2475 ISBN 978-1-4419-6411-3 e-ISBN 978-1-4419-6412-0 DOI 10.1007/978-1-4419-6412-0 Springer New York Dordrecht Heidelberg London Library of Congress Control Number: 2010934663 Mathematics Subject Classification (2010): 65-01, 65L04, 65L05, 65L06, 65L12, 65L20, 65M06, 65M08, 65M12, 65T50, 76-01, 76M10, 76M12, 76M22, 76M29, 86-01, 86-08 c Springer Science+Business Media, LLC 1999, 2010 All rights reserved. This work may not be translated or copied in whole or in part without the written permission of the publisher (Springer Science+Business Media, LLC, 233 Spring Street, New York, NY 10013, USA), except for brief excerpts in connection with reviews or scholarly analysis. Use in connection with any form of information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed is forbidden.
    [Show full text]
  • A General Linear Method Approach to the Design and Optimization of Efficient, Accurate, and Easily Implemented Time-Stepping Methods in CFD
    A general linear method approach to the design and optimization of efficient, accurate, and easily implemented time-stepping methods in CFD Victor DeCariaa,1,∗, Sigal Gottliebb, Zachary J. Granta,1, William J. Laytonc aOak Ridge National Laboratory, Computational and Applied Mathematics Group bMathematics Department, University of Massachusetts Dartmouth cDepartment of Mathematics, University of Pittsburgh Abstract In simulations of fluid motion time accuracy has proven to be elusive. We seek highly accurate methods with strong enough stability properties to deal with the richness of scales of many flows. These methods must also be easy to implement within current complex, possibly legacy codes. Herein we develop, analyze and test new time stepping methods addressing these two issues with the goal of accelerating the development of time accurate methods addressing the needs of applications. The new methods are created by introducing inexpensive pre-filtering and post-filtering steps to popular methods which have been implemented and tested within existing codes. We show that pre-filtering and post-filtering a multistep or multi-stage method results in new methods which have both multiple steps and stages: these are general linear methods (GLMs). We utilize the well studied properties of ∗Corresponding author Email addresses: [email protected] (Victor DeCaria), [email protected] (Sigal Gottlieb), [email protected] (Zachary J. Grant), [email protected] (William J. arXiv:2010.06360v1 [math.NA] 13 Oct 2020 Layton) 1This manuscript has been authored by UT-Battelle, LLC, under contract DE-AC05- 00OR22725 with the US Department of Energy (DOE). The US government retains and the publisher, by accepting the article for publication, acknowledges that the US govern- ment retains a nonexclusive, paid-up, irrevocable, worldwide license to publish or repro- duce the published form of this manuscript, or allow others to do so, for US government purposes.
    [Show full text]
  • Revision of Odes for Compphys
    Revision of ODEs for CompPhys E July 16, 2013 Odinary Differential Equations ODEs are quite easy. Numerical Solutions thereto Solving ODEs numerically is necessarily a matter of approximation, since computers are not continuous machines but use discrete numbers, and they additionally cannot deal with arbitrary-precision numbers1 and so the whole integral has to be discretized. Both of these effects have a role to play in the deviation of the algorithm from the true value of the integral. We only need study 1st order ODEs We can decompose an arbitrarily high order differential equation into a system of first order ODEs to solve using the algorithms to follow. For example (n) (k) y = f(fy gk=0;:::;n−1; x) (1) can be manipulated into a series of first order equations by defining 0 0 y0 = y ; yk = yk+1; k = 0; :::; n − 2 (2) which gives us 0 y0 = y1 0 y1 = y2 ::: = ::: 0 yn−2 = yn−1 0 yn−1 = f(fykgk=0;:::;n−1; x) (3) In vector form, this is just y0 = f(y; x). Integration Algorithms Euler Method Euler's method is pretty dumb, but it gets the job done.2 1Well they obviously can if you want them to but the libraries are so slow they may as well not. 2Actually it doesn't. 1 Solution of y0 = −2:3y computed with the Euler method with step size h = 1 (blue squares) and h = 0:7 (red circles). The black curve shows the exact solution. The Euler method first order, which means that the local error (error per step) is proportional to the square of the step size, and the global error (error at a given time) is proportional to the step size.
    [Show full text]