Smoothed Particle Hydrodynamics a meshfree particle method ... · Introduction to numerical methods...

34
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 ... · Introduction to numerical methods...

Page 1: Smoothed Particle Hydrodynamics a meshfree particle method ... · Introduction to numerical methods Introduction Observations of astrophysical phenomena on every scale imply that

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 ... · Introduction to numerical methods Introduction Observations of astrophysical phenomena on every scale imply that

Computational Astrophysics MarksProject 1 Trojans and Integrator 20% (Due Feb 8th)Project 2 SPH in 1-D with shock tube 30%Project 3 SPH in 3-D with planet collisions 20%Homework – see lectures: L1, L2, L3, and L5 15%Presentation on projects 15%

100%

Course Marks

Homework is expected one week after it is given out!

Presentation will be given for 15 minutes on your chosen topic and must be closely related to astrophysical simulations

Page 3: Smoothed Particle Hydrodynamics a meshfree particle method ... · Introduction to numerical methods Introduction Observations of astrophysical phenomena on every scale imply that

Project 1: (See Lecture 1 – 20%)

Make a simulation to solve the N-body problem and investigate the time evolution of the Trojan satellites of Jupiter for 300 years using an initial time step of 0.01 years. Implement a 4th order Runge Kutta numerical integrator.

Project 2: (See Lectures 2-6 – 30%)

Write your own 1D SPH simulation to solve the Navier-Stokes equations of hydrodynamics for the shock tube problem. This is a standard test for SPH to show your code works. Use the Runge Kutta numerical integrator developed in project 1 for time integration.

Project 3: (See Lectures 2-6 – 20%)

Do a simulation to colliding two Jupiter like planets using a 3D version of your SPH program. Investigate different impact trajectories.This means you generalize your 1D SPH simulation to 3D to collide the two Jupiter like planets. Add gravitation to this simulation, note this is not trivial to get working well!

Projects

Page 4: Smoothed Particle Hydrodynamics a meshfree particle method ... · Introduction to numerical methods Introduction Observations of astrophysical phenomena on every scale imply that

Galaxy  collision  

Authors:  Volker  Springel,  et  al.

Simula;on  Tool:  Gadget  (SPH)

The merger of two spiral galaxies, a process that leads to the inflow of gas into the galaxy centres, causing rapid growth of the central supermassive black holes. The energy input associated with the gas accretion eventually expels a lot of the gas in a quasar-driven wind, terminating the black hole growth and greatly reducing residual star formation in the formed elliptical galaxy. (Reference publication: Springel et al.)

Page 5: Smoothed Particle Hydrodynamics a meshfree particle method ... · Introduction to numerical methods Introduction Observations of astrophysical phenomena on every scale imply that
Page 6: Smoothed Particle Hydrodynamics a meshfree particle method ... · Introduction to numerical methods Introduction Observations of astrophysical phenomena on every scale imply that

H0 = 100h [kms�1Mpc�1]

so h = 0.73 today

and H0 = 73 [kms�1Mpc�1]

Flight through a high resolution simulation of a galaxy cluster. Visible are prominent structures within the hot plasma. Some structures are able to maintain a self-bound atmosphere (shown in light blue). More than a thousand of individual galaxies can be identified within the cluster, even forming new stars in their centers (shown in dark blue). Only a small number of them are still maintaining their own, hot, self-bound atmosphere.

Galaxy  cluster

Authors:  Klaus Dolag

Simula;on  Tool:  Gadget  2  (SPH)

Visualiza;on  Tool:  Splotch

Page 7: Smoothed Particle Hydrodynamics a meshfree particle method ... · Introduction to numerical methods Introduction Observations of astrophysical phenomena on every scale imply that
Page 8: Smoothed Particle Hydrodynamics a meshfree particle method ... · Introduction to numerical methods Introduction Observations of astrophysical phenomena on every scale imply that

Introduction to numerical methods

IntroductionObservations of astrophysical phenomena on every scale imply that hydrodynamical flow and orbital mechanics are vital to understand the universe.

! dynamics of Saturn’s rings! dynamics of planets around nearby stars! supernovae explosions! colliding galaxies, stars, planets! the Big Bang

Also the theory of radiation flow, which links our instruments to these events, is a third important element in the interpretation of physical phenomena.

Page 9: Smoothed Particle Hydrodynamics a meshfree particle method ... · Introduction to numerical methods Introduction Observations of astrophysical phenomena on every scale imply that

ObjectivesThis first lecture focuses on the basic concepts of numerical hydrodynamics.This introductory lecture will discuss:

• General numerical simulations

• Grid based methods• Eulerian approach

• Lagrangian approach• Meshfree methods• Meshfree particle methods

• Smoothed Particle HydrodynamicsSubsequent lectures will discuss numerical details of SPH and N-body techniques, with a focus on numerical implementation and examples.

Page 10: Smoothed Particle Hydrodynamics a meshfree particle method ... · Introduction to numerical methods Introduction Observations of astrophysical phenomena on every scale imply that

General numerical simulationsIn general, numerical simulations follow a basic procedure as illustrated below.

From the observed physical phenomena, simplified mathematical models constructed.

The models generally have governing equations with boundary conditions and/or initial conditions.

To solve them, the geometry of the problem domain needs to be divided into discrete components.

Numerical discretization means changing the integral or derivative operations in continuous form to discrete form.

Coding and implementation need to account for computer language, speed and storage requirements.

When all these factors are combined in a suitable system, together with the conservations laws the simulation can be carried out.

Page 11: Smoothed Particle Hydrodynamics a meshfree particle method ... · Introduction to numerical methods Introduction Observations of astrophysical phenomena on every scale imply that

Fundamental FramesThere are two fundamental frames for describing the physical governing equations

• the Eulerian is a spatial description, typically used in finite difference methods (FDM).

• the Lagrangian is a material description, typically used in the finite element methods (FEM).

If viscosity, heat conduction and external forces are neglected, the conservations equations in PDE form in the two methods are very different:

FDM uses expressions of the form f(x + b) − f(x + a). If a finite difference is divided by b − a, one gets a difference quotient which gives an approximate numerical solution of differential equations

FEM is used for finding approximate solutions of PDE’s and integral equations. The solution approach is to eliminate the differential equation completely

The mass conservation law is also known as the continuity equation.

In the equations p, ρ, e, v and x are pressure, density, internal energy, velocity and position vectors respectively.

The Greek subscripts α and β are the coordinate directions (e.g. x,y,z) and summation is implied over repeated indices.

Page 12: Smoothed Particle Hydrodynamics a meshfree particle method ... · Introduction to numerical methods Introduction Observations of astrophysical phenomena on every scale imply that

Eulerian versus LagrangianThe conservation equations are derived using conservation of mass, momentum and energy in the Boltzmann transport equation (BTE).

BTE describes the statistical flow through position and velocity phase space, subject to forces.

• The Euler equations describe the evolution of the state of the medium at a fixed location in space.

✴ We have V0 at t=0 and X → Vt at t=t and x.

• The Lagrangian equations employ a co-moving spatial coordinate of a fluid element and the property of the particle is traced as a function of time. D/Dt describes changes within the element such as its state and location.

✴ At t=0 we have V0 and X → at t=t we have Vt and x.

The derivation of both sets of equations can be found in ref. [1] and [4].

Page 13: Smoothed Particle Hydrodynamics a meshfree particle method ... · Introduction to numerical methods Introduction Observations of astrophysical phenomena on every scale imply that

Significance of the time derivativesThe differences between the two sets of equations comes from the definition of the total time derivative which consists of a local and a convective derivative:

• D/Dt is the total time derivative (substantial, material or global derivative) and is physically the time rate of change following a moving Lagrangian fluid element.

• ∂/∂t is the local derivative that is the time rate of change at a fixed point.

• vα∂/∂vα is the convective derivative: physical change due to the movement of the fluid element from one location to another.

Page 14: Smoothed Particle Hydrodynamics a meshfree particle method ... · Introduction to numerical methods Introduction Observations of astrophysical phenomena on every scale imply that

Leonhard Paul Euler (15 April 1707 – 18 September 1783)

was a pioneering Swiss mathematician and physicist who spent most of his life in Russia and Germany. He is renowned for his work in mathematics, mechanics, fluid dynamics optics and astronomy.

was an Italian/French mathematician and astronomer, making significant contributions to many fields. On the recommendation of Euler and D'Alembert, in 1766 he succeeded Euler as the director of mathematics at the Prussian Academy.

Joseph-Louis Lagrange,(25 January 1736 – 10 April 1813)

Page 15: Smoothed Particle Hydrodynamics a meshfree particle method ... · Introduction to numerical methods Introduction Observations of astrophysical phenomena on every scale imply that

Grid-based methodsThe two fundamental frames in grid methods

• the Eulerian description is a spatial description• the Lagrangian description is a material description

Eulerian grid

The object moves across the fixed grid.

The grid is also fixed in time.

The flux of mass, momentum and energy across the cell boundaries must be simulated

Lagrangian gridIs attached to the material and moves with it.

Results in expansion, compression and deformation of mesh.

Mass, momentum and energy are transported with mesh cells.

Mass is fixed so no mass crosses cell boundaries.

Page 16: Smoothed Particle Hydrodynamics a meshfree particle method ... · Introduction to numerical methods Introduction Observations of astrophysical phenomena on every scale imply that

A comparison

By combining the complementary features of both methods, the advantages can be maximized.

Done in Coupled Eulerian Lagrangian (CEL) and Arbitrary Eulerian Lagrangian (AEL) methods.

They can be more stable but also require complicated mapping between the two types of mesh.

Page 17: Smoothed Particle Hydrodynamics a meshfree particle method ... · Introduction to numerical methods Introduction Observations of astrophysical phenomena on every scale imply that

Mesh generation is a problem

Grid-based methods are widely used but have inherent difficulties which limit their application.

• In Eulerian grid methods constructing regular grids for irregular geometry is complex and time consuming.

• In Lagrangian grid methods computing the mesh for the object is time consuming.• Treating large deformations usually requires rezoning techniques, which are tedious,

error prone and time consuming.

Example of Lagrangian Monte Carlo particles on Unstructured Eulerian grid points.National Center for Hypersonic Combined Cycle Propulsion

Page 18: Smoothed Particle Hydrodynamics a meshfree particle method ... · Introduction to numerical methods Introduction Observations of astrophysical phenomena on every scale imply that

Limitations of grid-based methods

Grid based methods are not so suitable for simulating explosions, high velocity impacts because of the large deformations, inhomogeneities, moving material interfaces, etc.Grid based methods are not suitable for discrete physical particles, e.g.

• the interaction of stars in astrophysics• movement of millions of atoms• dynamical behavior of molecules

Hence, there is a strong interest in the equivalent meshfree methods.

Eulerian Contact for Versatile Collision Processing

François Faure, Jérémie Allard, Matthieu Nesme

Page 19: Smoothed Particle Hydrodynamics a meshfree particle method ... · Introduction to numerical methods Introduction Observations of astrophysical phenomena on every scale imply that

Meshfree methods

The key idea is to provide accurate and stable numerical solutions to PDE's or integral equations with all kinds of possible boundary conditions

-using a set of arbitrarily distributed particles (or nodes) without any mesh.

Early work modified the internal structure of the grid-based methods to make them more adaptive, versatile and robust.

Droplet impact and splashingSimulation of a splash performed by Pascal Ray.

Page 20: Smoothed Particle Hydrodynamics a meshfree particle method ... · Introduction to numerical methods Introduction Observations of astrophysical phenomena on every scale imply that

Basic types of meshfree methods • Strong form formulation - simple, efficient and completely meshfree. But they have

proved numerically unstable and less accurate.

• Weak form formulation - not 'truly' mesh free as they require a background mesh to describe interactions. However, the results were very stable and accurate.

• Particle methods - a finite number of particles represent the state of the system and to record the movement of the system.

SPH is a meshfree particle method and was one of the earliest to be developed.

SPH simulation of flow over a cylinder with vortex sheddingMesh-free computational fluid dynamics, NUI Galway.

Page 21: Smoothed Particle Hydrodynamics a meshfree particle method ... · Introduction to numerical methods Introduction Observations of astrophysical phenomena on every scale imply that

Meshfree particle methods (MPM)Each particle is either directly associated with one physical object or represents part of the continuum problem domain.

Particles can range in sizes from nano- to micro- to meso- to macro- to astronomical-scales.

Depending on the problem the particles posses a set of field variables such as velocity, momentum, energy, position, etc.

Evolution of the system depends on conservation of mass, momentum and energy

Spiral Galaxy FormationT. Ize and E. D’Onghia

Page 22: Smoothed Particle Hydrodynamics a meshfree particle method ... · Introduction to numerical methods Introduction Observations of astrophysical phenomena on every scale imply that

Most meshfree particle methods are inherently Lagrangian methods in which the particles represent the physical system moving in the Lagrangian frame according to internal interactions and external forces (e.g. gravity).

Advantages: Discretized with particles with no fixed connectivity (good for large deformations)Complex geometry is simpleEasy to obtain large scale features by tracing the motion of the particlesThe time history of all particles is available

M. Kelager, Department of Computer Science, University of Copenhagen, DIKU

Page 23: Smoothed Particle Hydrodynamics a meshfree particle method ... · Introduction to numerical methods Introduction Observations of astrophysical phenomena on every scale imply that

Solution strategy of meshfree particle methods (MPM's)

Mesh-free computational fluid dynamics, NUI Galway.

Smoothing function in support domainApproximate the functions - derivatives and integrals - using the information from neighboring particles in an area of influence within the support domain.

E.g. the velocity v of a particle at r is:

Where N is the number of particles, vi is the velocity at particle i, Wi is a smoothing function at the i-th particle.

Velocity, v, is a weighted sum over neighboring particles.

v(r) =NX

i=1

vi(r)W (r)

Page 24: Smoothed Particle Hydrodynamics a meshfree particle method ... · Introduction to numerical methods Introduction Observations of astrophysical phenomena on every scale imply that

Smoothed particle hydrodynamics (SPH)

SPH, as a meshfree, Lagrangian, particle method has certain characteristics.Advantages include:

• Adaptive nature - achieved at an early stage at each time step, based on the current local set of arbitrarily distributed particles. Natural way to handle large deformations.

• No predefined mesh to provide connectivity between particles• Particle approximations – material is free to move due to external forces and internal

interactions.

Some astrophysical applications of SPH have included (see ref. [3]):• Binary stars or planetary collisions• Supernova Type II• Formation of galaxies• Coalescence of black holes with neutron stars• Single and multiple detonation of white dwarfs• Evolution of the Universe

In the coming lectures we will delve into the detailed formalism of standard SPH required before one can begin implementing the method in computer code.

Page 25: Smoothed Particle Hydrodynamics a meshfree particle method ... · Introduction to numerical methods Introduction Observations of astrophysical phenomena on every scale imply that

Problems: Numerical methods1. Explain the Boltzmann transport equation

2. How are the conservation equations derived in Lagrangian form

3. Write a short discussion on Eulerian and Lagrangian methods, comparing them in terms of application and respective advantages

4. Discuss grid based and mesh free methods

Note: These exercises are designed to make your think about this first lecture, only a paragraph or two is required on each (although longer responses are welcome too) and feel free to use the internet and the reference books to find extra information.

Page 26: Smoothed Particle Hydrodynamics a meshfree particle method ... · Introduction to numerical methods Introduction Observations of astrophysical phenomena on every scale imply that

References[1] Bodenheimer P., Laughlin G.P., Rozczka M. and Yorke H.W., Numerical Methods in Astrophysics, Taylor & Francis, (2007).[2] Aarseth S., Tout C. and Mardling R, The Cambridge N-Body Lectures (Lecture Notes in Physics)

[3] Liu G.R. and Liu M.B., Smoothed Particle Hydrodynamics: a meshfree particle method, World Scientific, (2007)

[4] Shu f., The Physics of Astrophysics, vol. I & II, Mill Valley, CA: University Science Books, (1991 & 1992)

[5] Monaghan J.J., Smoothed Particle Hydrodynamics, Annual Review of Astronomy and Astrophysics, 30:543-574, (1992)

[6] Benz W., Smoothed Particle Hydrodynamics: a review, NATO workshop, Les; Arcs, France, (1989)

[7] Lucy L.B., Numerical approach to testing the fission hypothesis, Astronomical Journal, 82:1013-1024, (1977)

[8] P. Cossins, Chapter 3, Smoothed Particle Hydrodynamics, Ph.D. Thesis, Leicester (2010)

Page 27: Smoothed Particle Hydrodynamics a meshfree particle method ... · Introduction to numerical methods Introduction Observations of astrophysical phenomena on every scale imply that

Computational Astrophysics

Lecture 1: Introduction to N-body techniques

David Hobbs

Lund ObservatoryASTM22

Page 28: Smoothed Particle Hydrodynamics a meshfree particle method ... · Introduction to numerical methods Introduction Observations of astrophysical phenomena on every scale imply that

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 29: Smoothed Particle Hydrodynamics a meshfree particle method ... · Introduction to numerical methods Introduction Observations of astrophysical phenomena on every scale imply that

Solving second order differential equationsSolving second order differential equations like equation (1) is done by reformulating the N second-order equations as a set of 2N coupled first-order equations. Any ordinary second-order differential equation of the form

can be rewritten as a pair of first-order differential equations.

If wi = [xi, vi] represents the 6-D phase space coordinates of particle i, then the state of the N-body system is described by a 6N vector

Evolution of the system in (2) takes the form

where the 6N functions gl are given by the right hand sides of (2). When the equations are in this form a single integration routine can be used to solve the system.

Using this equation (1) becomes

(2)

Page 30: Smoothed Particle Hydrodynamics a meshfree particle method ... · Introduction to numerical methods Introduction Observations of astrophysical phenomena on every scale imply that

Numerical IntegrationDifferential equations like those shown in equation (1) describe a continuous sequence of changes in response to an independent variable, t.

We need to specify 6N conditions (x and v) to solve our initial value problem.

The simplest solution to the N-body problem comes from specifying a finite difference of the differential equation over an interval

as

where the update variables, Wln+1, are calculated from information available at tn.

By repeatedly applying this formula the position and velocity of the particles can be propagated into the future in time steps of h. This is know as Euler’s method.

In practice this is not sufficiently stable for long integrations so more sophisticated methods are used but this simple form illustrates the basic principle well.

Page 31: Smoothed Particle Hydrodynamics a meshfree particle method ... · Introduction to numerical methods Introduction Observations of astrophysical phenomena on every scale imply that

The error in Euler’s methodEuler’s method is not good because of error accumulation. The exact equation is given by a Taylor series expansion.

Euler’s method is just the first two terms – it’s a first order method.The rest of the terms sum to give the total error.Euler’s method is asymmetry as the increment is based on the value of W at the beginning of the interval h.

Any non-linearity in g will result in inaccuracy in the updated values.The key to improving Euler’s method is to realize that g can be computed at any trial values (t, W) so more refined estimates over h can be made.One can construct weighted sums with k estimates of g and tuning the weights provides cancellation of error terms in the Taylor series up to order k+1.Implementations such as this are known as Runge-Kutta methods.

Page 32: Smoothed Particle Hydrodynamics a meshfree particle method ... · Introduction to numerical methods Introduction Observations of astrophysical phenomena on every scale imply that

The simplest Runge-Kutta scheme uses the Euler method to estimate values W(tn+h/2) at the halfway point.

The values Wb provide a more accurate estimate of the slope in the interval h.

A 4th order Runge-Kutta method is commonly used:

The Runge-Kutta method

A single iteration evaluates•the initial slope at the start•two midpoint slopes•the slope at the endThe four slopes are then combined with weights

to produce a weighted average slope which accurately spans the interval h.

2nd order

Page 33: Smoothed Particle Hydrodynamics a meshfree particle method ... · Introduction to numerical methods Introduction Observations of astrophysical phenomena on every scale imply that

Make a simulation to solve the N-body problem and investigate the time evolution of the Trojan satellites of Jupiter for 300 years using an initial time step of 0.01 years. Implement the 4th order Runge Kutta numerical integrator. Plot and/or show video of the results relative to the common centre of gravity of the system. Consider the use of adaptive time steps to minimize numerical error drift and extend the basic simulation to generate interesting results for your report.

Detailed input: Initial parameters for Jupiter Trojans

Project 1

Page 34: Smoothed Particle Hydrodynamics a meshfree particle method ... · Introduction to numerical methods Introduction Observations of astrophysical phenomena on every scale imply that

Keep the Sun at the origin by subtracting from every body the forces exerted by all other bodies on the Sun. Use units of solar mass and AU and 1 year for time so velocity is in AU year-1. Then the gravitational constant G=4π2

The diagram shows the geometry.ST = R

and SC=MJR/(MJ+MS)

E.g. If α=30° SCT = 120-30=90°or180°=60°+α+120°-α

Hints