Smoothed Particle Hydrodynamics a meshfree particle method … · 2015-02-03 · One solution to...

23
Computational Astrophysics Lecture 1: Introduction to numerical methods Lecture 2: The SPH formulation Lecture 3: Construction of SPH smoothing functions Lecture 4: SPH for general dynamic flow Lecture 5: N-body techniques Lecture 6: Numerical Implementation Project Work (5-6 weeks) David Hobbs Lund Observatory ASTM22

Transcript of Smoothed Particle Hydrodynamics a meshfree particle method … · 2015-02-03 · One solution to...

Page 1: Smoothed Particle Hydrodynamics a meshfree particle method … · 2015-02-03 · One solution to these problems is to use a so called ‘leapfrog’ method, which is a simple predictor-corrector

Computational Astrophysics

Lecture 1: Introduction to numerical methodsLecture 2: The SPH formulation

Lecture 3: Construction of SPH smoothing functionsLecture 4: SPH for general dynamic flow

Lecture 5: N-body techniques Lecture 6: Numerical Implementation

Project Work (5-6 weeks)

David Hobbs

Lund ObservatoryASTM22

Page 2: Smoothed Particle Hydrodynamics a meshfree particle method … · 2015-02-03 · One solution to these problems is to use a so called ‘leapfrog’ method, which is a simple predictor-corrector

Collapse  of  a  Molecular  Cloud  Simulation & visualization by Matthew Bate, University of Exeter. Star cluster calculations showing the collapse and fragmentation of a 500 solar mass cloud. It is a simulation containing more than 1250 stars and brown dwarfs to allow comparison with clusters such as the Orion Trapezium Cluster.

Page 3: Smoothed Particle Hydrodynamics a meshfree particle method … · 2015-02-03 · One solution to these problems is to use a so called ‘leapfrog’ method, which is a simple predictor-corrector

N-body techniquesThe classical astrophysical N-body problem consists of each member of an aggregate of N (i=1,…,N) point masses, having masses mi, experiencing an acceleration from the gravitational attractions of all the other bodies in the system.

(1)

The description of the problem is completed by specifying the initial positions (xi at t = 0) and velocities (vi at t=0) for the N particles.

Solutions of this problem range from the orbit of the moon to the structure of the Kirkwood gaps in the asteroid belt and countless other phenomena.

This richness arises from strong nonlinearity in the equation as a slight change in initial conditions can lead to very different outcomes – chaos.

The N-body problem involves calculating

1. the force on each particle at a given time

2. determining the new position of the particle at a future time

Page 4: Smoothed Particle Hydrodynamics a meshfree particle method … · 2015-02-03 · One solution to these problems is to use a so called ‘leapfrog’ method, which is a simple predictor-corrector

Methods for force calculation:• Brute force

• Hierarchical tree method – efficient methods to search for NN’s

• Fast Fourier transforms – use convolution theorem to avoid computing sums (not covered here)

All these methods have problems with close encounters but this can be tackled by:

• Softening – low accuracy

• Regularization – high accuracy

Methods for advancing particle positions are discussed:• Euler – the simplest possible approach

• Runge-Kutta – standard for ordinary differential equation

• Bulirsch-Stoer – accurate but limited to few bodies – with Richardson extrapolation

• Symplectic map – accurate for very long integrations (no close encounters)

• Predictor-corrector – large numbers of particles with reasonable accuracy (Leapfrog)

Page 5: Smoothed Particle Hydrodynamics a meshfree particle method … · 2015-02-03 · One solution to these problems is to use a so called ‘leapfrog’ method, which is a simple predictor-corrector

Force Calculations – hierarchical tree method (1/3)

A simple solution of the N-body problem requires O(N2) operations to solve equation (1).However close by particles have a strong interaction while distant ones have little effect.Drastic speed improvements can be obtained by retaining only closely neighbouring particles exactly while treating distant bodies as simpler aggregates.

• Tree algorithms work by tessellating the volume into a hierarchy of nested cubic cells, with at least 1 particle.

• The aggregate of cells is called a tree and the finest subdivisions are leaves.• Gives an algorithm that requires O(Nlog(N)) operations to solve the N-body problem• A big saving for large N!

Page 6: Smoothed Particle Hydrodynamics a meshfree particle method … · 2015-02-03 · One solution to these problems is to use a so called ‘leapfrog’ method, which is a simple predictor-corrector

Barnes and Hut, Nature 324, 1986

A large cube is first drawn around the simulated volume.This is subdivided into eight sub-volumes (in 3-D but only 4 in 2-D)Those containing no particles are discarded.Those with particles are further subdivided. As the tree is constructed the total mass, centre-of-mass, mono- and quadrupole moment of gravitational potential are stored.

Force Calculations – hierarchical tree method (2/3)

pp

w

RThe tree is reconstructed after each time step.At each level in the tree, the width, W, of a box is compared to the distance R between the centre-of-mass and the particle p.

For long range interactions

W < δ*R

Page 7: Smoothed Particle Hydrodynamics a meshfree particle method … · 2015-02-03 · One solution to these problems is to use a so called ‘leapfrog’ method, which is a simple predictor-corrector

From the constructed tree the force on any particle p can be found recursively from the root cell.

If W < δ*R (δ is an accuracy parameter ~1). compute force between the stored data for the box and the current particleelse resolve the current cell into 8 sub-cells and recursively examine them - continue this until there is only 1 particle per cell.end

Force Calculations – hierarchical tree method (3/3)

The result is an algorithm with only NlogN computations for an N2 problem.For a million particles this amounts to a factor of 166,000 improvement.Other advantages: Rigorous error analysis is possible.

Page 8: Smoothed Particle Hydrodynamics a meshfree particle method … · 2015-02-03 · One solution to these problems is to use a so called ‘leapfrog’ method, which is a simple predictor-corrector

The Bulirsch-Stoer method (1/3)Integrating small numbers of bodies for hundreds of millions of orbits often arises in astronomy.Numerical accuracy, flexibility and speed are required.The basic scheme in Burlirsch-Stoer is a simple modified midpoint for advancing over a full time step H=Nh by stringing together N equal sub-steps.

xn are intermediate values at time t +nh.

The error in estimating x(t +H) can be expressed as an even power series. This special property means that successive refined estimates of x(t +H) can be combined in a weighted average to form a final accurate estimate with little computational effort. The procedure is• evaluate x(t +H), k times, with N=2,4,6,8,… • fit the results to a polynomial of order k-1• extrapolate to the value, , that would occur if the step size was zeroThis is known as Richardson extrapolation.

Page 9: Smoothed Particle Hydrodynamics a meshfree particle method … · 2015-02-03 · One solution to these problems is to use a so called ‘leapfrog’ method, which is a simple predictor-corrector

The polynomials are given by

and the coefficients a0…ak-1 can be extracted from Lagrange’s formula that gives the unique polynomial of degree k-1 passing through points h1 … hk with values xt+H(h1), xt+H(h2),…, xt+H(hk)

The Bulirsch-Stoer method (2/3)

Richardson extrapolation: a) function is integrated using 3

different subintervals h of H/4, H/8, H/16.

b) Values of x(t+H) as a function of h and extrapolated to h = 0

Once the coefficients are determined the polynomial is simply evaluated at h = 0 to obtain xt+H(0)

Page 10: Smoothed Particle Hydrodynamics a meshfree particle method … · 2015-02-03 · One solution to these problems is to use a so called ‘leapfrog’ method, which is a simple predictor-corrector

The Bulirsch-Stoer method (3/3)The final step is to determine numerical convergence.The procedure is redone with a different value of k.The two estimates of are then compared and if the difference is less than, e.g. 10-13, then its has converged.The convergence must be checked for every time step H, so each time step requires a large number of operations.

However, for a give accuracy Burlirsch-Stoer integration is several times faster than a fourth-order Runge-Kutta method.In practice, Lagrange’s formula can be replaced by a recursive formula, such as Neville’s algorithm (see Press et al. 1992)It is preferred for high accuracy orbital integrations with few bodies and can handle close encounters reasonable well.

Page 11: Smoothed Particle Hydrodynamics a meshfree particle method … · 2015-02-03 · One solution to these problems is to use a so called ‘leapfrog’ method, which is a simple predictor-corrector

For the Bulirsch-Stoer method work through by hand an example using Langrange’s polynomial and Richardson extrapolation.

Hint: Use a simple function like sine or cosine, etc.

Problem

Page 12: Smoothed Particle Hydrodynamics a meshfree particle method … · 2015-02-03 · One solution to these problems is to use a so called ‘leapfrog’ method, which is a simple predictor-corrector

Symplectic map algorithms use the properties of Keplerian motion.The motion of a planet is divided into a Keplerian and a non-Keplerian perturbation part resulting from the interaction of other bodies in the system. The Keplerian part has an analytical solution so much computer time can be saved.The algorithm uses the Hamiltonian formulation of Newton’s laws. The time evolution of the positions ri and the momenta pi of the particles is written as a set of coupled first-order differential equations. as p=mv

where H is the Hamiltonian for the N-body problem (3)

H is the total energy and is conserved. The idea of the symplectic map is to separate the total Hamiltonian into parts

The Symplectic map method (1/5)

f i =dpidt

= −∂H∂ri

vi =dridt

=∂H∂pi

Page 13: Smoothed Particle Hydrodynamics a meshfree particle method … · 2015-02-03 · One solution to these problems is to use a so called ‘leapfrog’ method, which is a simple predictor-corrector

A Keplerian Hamiltonian for two bodies is one that can be written in the form

The momenta in the N-body Hamiltonian refer to the centre of mass, but for N >2 the particles are not executing Keplerian motion about the centre of mass.

The Symplectic map method (2/5)

If the motion of the bodies is cast in Jacobi coordinates – a set of Keplerian Hamiltonians can be extracted from H.• The system consists of a heavy mass m0 and N-1 light masses mi orbiting it.

• The centre of mass of the entire system is taken to be the first Jacobi coordinate.• The second Jacobi coordinate is the separation vector between the first planet and the

central mass. • Subsequent coordinates are the separation vectors of the ith body relative to the centre of

mass of the preceding i-1 bodies.

Page 14: Smoothed Particle Hydrodynamics a meshfree particle method … · 2015-02-03 · One solution to these problems is to use a so called ‘leapfrog’ method, which is a simple predictor-corrector

Cartesian coordinates Jacobi coordinates

Simple expressions can be formed relating r and r-tilde in the two coordinate systemsRi are the position vectors of the centers of mass

Differentiating these expressions gives the corresponding momenta

Page 15: Smoothed Particle Hydrodynamics a meshfree particle method … · 2015-02-03 · One solution to these problems is to use a so called ‘leapfrog’ method, which is a simple predictor-corrector

The Symplectic map method (3/5)To first order, orbits in multi-planet systems are Keplerian in Jacobi coordinates. The full N-body problem can then be written as (Murray and Dermott, 1999)

where

and

where the tilde indicates Jacobi coordinates.The Hamiltonian represents a map that allows the system to step from an initial state at t=t0 to an evolved state at t=t0+Δt.

Page 16: Smoothed Particle Hydrodynamics a meshfree particle method … · 2015-02-03 · One solution to these problems is to use a so called ‘leapfrog’ method, which is a simple predictor-corrector

Solution - step 1Firstly, the Jacobi coordinates of the planets are advanced through the Keplerian portion of their trajectories using Gauss’ f and g functions

discovered by Gauss in 1801 while studying the asteroid Ceres.

The Symplectic map method (4/5)

The positions and velocities are then obtained from

The eccentric anomaly, E, is the solution of Kepler’s equation

solved with Newton-Raphson root finding algorithm

Page 17: Smoothed Particle Hydrodynamics a meshfree particle method … · 2015-02-03 · One solution to these problems is to use a so called ‘leapfrog’ method, which is a simple predictor-corrector

The Symplectic map method (5/5)Solution – step 2Secondly, the interaction Hamiltonian are used to update the Jacobian velocities using

to correct for the interactions. This then completes the time step.

The method can be made second order accurate by using Δt/2 for the first and last time steps and Δt for all other steps.The symplectic technique works well for near Keplerian orbits.It is 10 times faster than Bulirsch-Stoer.If the planets get too close the method becomes inaccurate and breaks down – Regularization or Bulirsch-Stoer is then preferable.

Page 18: Smoothed Particle Hydrodynamics a meshfree particle method … · 2015-02-03 · One solution to these problems is to use a so called ‘leapfrog’ method, which is a simple predictor-corrector

Johann Carl Friedrich Gauss (Gauß)(30 April 1777 – 23 February 1855) was a German mathematician and scientist who contributed significantly to many fields, including number theory, statistics, analysis, differential geometry, geodesy, geophysics, electrostatics, astronomy and optics. Gauss had a remarkable influence in many fields of mathematics and science and is ranked as one of history's most influential mathematicians. He referred to mathematics as "the queen of sciences.”

Gauss was a child prodigy. There are many anecdotes pertaining to his precocity while a toddler, and he made his first ground-breaking mathematical discoveries while still a teenager. He completed Disquisitiones Arithmeticae, his magnum opus, in 1798 at the age of 21, though it would not be published until 1801. This work was fundamental in consolidating number theory as a discipline and has shaped the field to the present day.

Page 19: Smoothed Particle Hydrodynamics a meshfree particle method … · 2015-02-03 · One solution to these problems is to use a so called ‘leapfrog’ method, which is a simple predictor-corrector

The Predictor-corrector method (1/2)So far, methods suitable for a small number of bodies with high accuracy were discussed.In astronomy we often want to study large systems (e.g. a galaxy with >100G objects).It takes the Sun 250 Myr to orbit the Galaxy so it has only orbited ~18 times.

Additionally, there are multiple time scales, e.g. star clusters need small time steps.One solution to these problems is to use a so called ‘leapfrog’ method, which is a simple predictor-corrector method, with time step halving.

The largest time step can be estimated from

where ai is the acceleration of the ith particle and η is a small factor.

Page 20: Smoothed Particle Hydrodynamics a meshfree particle method … · 2015-02-03 · One solution to these problems is to use a so called ‘leapfrog’ method, which is a simple predictor-corrector

The leapfrog method is a simple second-order integration to advance positions and velocities defined in intervals separated by Δti/2.

The integration can be initialized, preserving second order accuracy, by

Here position is advanced at half time-steps and velocity at full time.Additionally, more sophisticated versions can be made. These are known more generally as as predictor corrector methods.Note: Leapfrog (above) and predictor-corrector (half-step corrections) are often mixed names

The Predictor-corrector method (2/2)

Page 21: Smoothed Particle Hydrodynamics a meshfree particle method … · 2015-02-03 · One solution to these problems is to use a so called ‘leapfrog’ method, which is a simple predictor-corrector

Close encounters – softening (1/3)During close encounters between point masses the terms 1/r2

ij can become arbitrarily large leading to large accelerations and small time steps which build up truncation error.The simplest but least accurate, useful way to overcome this is to include a softening term in the 1/r2

ij dependence. Writing the force between i and j as

then the gravitational acceleration saturates at a maximum

which occurs when the particles reach a separation of This avoids the problem but will not give the correct motion of a tight binary.If ε is larger than the physical size of the particles then the details of the encounter will be wrong.

Page 22: Smoothed Particle Hydrodynamics a meshfree particle method … · 2015-02-03 · One solution to these problems is to use a so called ‘leapfrog’ method, which is a simple predictor-corrector

Close encounters – regularization (2/3)For small clusters of stars encounters are common and one wants to trace the orbits accurately.Regularization introduces a coordinate transformation which replaces physical time with regularized time.Acceleration of two particles with separation R is

where F12=F1-F2 is the net external force per unit mass from other bodies.

Regularization transforms both the time and space coordinates.

See Galactic Dynamics 2nd ed. P208

Time transformation: regularized time, τ, is related to ordinary time, t, by

so that

The equation of motion then becomes

For n=1, the R-2 singularity is gone but R/R still diverges.

Page 23: Smoothed Particle Hydrodynamics a meshfree particle method … · 2015-02-03 · One solution to these problems is to use a so called ‘leapfrog’ method, which is a simple predictor-corrector