20
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 ASTM17

ComputationalAstrophysicsL6.pdf

Embed Size (px)

Citation preview

  • 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 ObservatoryASTM17

  • IntroductionThe SPH formulation in the form of the Navier-Stokes equations was covered in previous lectures.

    We have ordinary differential equations (ODE's) with respect to time which can be numerically integrated.

    A number of implementation issues are important for realistic simulations

    Variable smoothing length

    Symmetrization of particle interactions

    Zero-energy mode

    Solid boundary treatment

    Particle interactions

    Numerical Implementation

  • ProjectsThis section will show how to develop a 3-D SPH code and will be applied to a simple 1-D problem, the shock tube and 3-D planet collisions.

    Projects 1-3:

    Implement an N-body integrator to study the Trojan satellites of Jupiter.

    Implement a simple 1-D SPH code to reproduce the results of the one dimensional shock wave.

    Implement a basic 3-D SPH simulation tool to make collisions between two Jovian type planets.

  • Variable smoothing length

    The smoothing length h has a direct impact on the accuracy of the solution and the size of the support domain h.We should have about 5, 21 or 57 particles in the support domain in 1-, 2- and 3-D respectively. The smoothing length may need to be adapted in both space and time so h can evolve dynamically.A simple approach is to update the smoothing length, in D-dimensions, according to the average density as

  • Symmetrization of particle interactions

    If each particle has its own smoothing length, hi is not equal to hj. Therefore particle i could exert a force on particle j but not vise versa, which would violate Newton's third law. To overcome this one can use averages or geometric means of smoothing lengths for pairs of interacting particles. Two examples are:

  • Zero-energy mode

    When evaluating derivatives for regular particle distributions the derivative at the particle can be zero and the derivative between neighboring particles can be anti-symmetric. This can result in no strain and is generally undesirable. This can be solved by staggering the particles, solving for velocity at one point and stress at another.

    This problem is not so great in SPH as we generally have irregular particles and it never arises.It could be a problem in, for example, simulating atoms on a regular crystalline lattice.

  • Solid BoundariesFor particles near or on the boundary only particles inside the boundary contribute to the integral. This is know as particle deficiency. This gives incorrect solutions.To solve this problem ghost or virtual particles can be introduced at the boundary to prevent unphysical effects.Type I: On boundary, contribute to kernel and particle approximations for real particlesType II: Outside boundary, exert repulsive force to prevent interior particles from penetrating

  • Nearest neighborsIn SPH, the smoothing function has compact support so only nearest neighboring particles (NNP) interact. To find them NNP searching algorithms must be used. Three common types include:

    All-pair search - compare each interaction length with h to find neighbors - simple but inefficient

    Linked list algorithm - maintain a one off list of neighbors - efficient but not dynamic and requires a large list

    Tree search algorithm - use a subdividing tree search algorithm - efficient and dynamic but more complex

    Particle interactions

    Canup, 2004, Icarus 168:433

  • Pairwise interactionPairwise interaction can be used to avoid having to use double loops when, for example, calculating summation density.When searching for nearest neighbor particles also generate lists containing W and dW/dr for each interacting pair together with lists containing the particle indices.The final calculation of density can then be carried out using a single loop and the lists of data which is very efficient.However, this has a drawback of requiring large storage for the lists.

    Particle interactions

    Canup, 2004, Icarus 168:433

  • Implementing SPH computer code

    The figure shows a typical procedure for SPH simulations.Initialization input of problem geometry input of standard parametersMain SPH process - time integration by leapfrog, predictor corrector or Runge-Kutta.

    All sub-functions are called inside the main loop.Output - save updated data to files, for making videos this could be called at each video output step.

  • Shock tube in 1-D is a common problem for people starting in SPH simulations. The equations are listed without viscous stress and heat.Long straight tube filled with gas, which is separated by a membrane in two parts with different pressures and densities but are individually in thermodynamic equilibrium.When the membrane is taken away the following are produced

    a shock wave - moves into region of lower density

    a rarefaction wave (reduction in density) - moves into region of high density

    a contact discontinuity - forms in center and travels into low density region behind the shock

    Project 2: The Shock Tube Problem

  • Problem: The shock tubeIn this example we use

    where , p, e and v are the density, pressure, internal energy, and velocity respectively. x is the particle spacing. With 400 particles of the same mass mi=0.001875.

    320 particles evenly distributed in the high density region [-0.6,0.0] and 80 in the low density region [0.0,0.6].

    |

  • We use the equation of state for the ideal gas

    and the speed of sound is

    = Cp / Cv = 1.4 is the ratio of heat capacity

    Set the time step to 0.005 and run the simulation for 40 time steps.

    No special treatment is used for the boundary as the shock wave has not yet reached it.

    Problem: Equation of State

    Heat capacity the amount of heat required to change a substance's temperature by a given amount

  • Project assignment Implement an SPH code from scratch in matlab to solve the shock wave problem (don't

    include artificial viscosity yet).

    Help is available from me!

    Input data files are also available

    Speed of sound

    1. Extend the basic implementation to include artificial viscosity of Monaghan ref. [5]. (=1, =1 and = 0.1hij to avoid divergence):

    Reproduce similar results shown for , p, e and v. Write a project report describing, theory, implementation,

    results.

  • Hints and help for projectYour code should do something like the following

    Single Step

    SPH

    Input Time Integration Output

    Kernel

    Internal ForceDensity Direct Find Art Viscosity Ext Force, etc.

    EOS

    Call all subfunctions and sum the results

    Runga Kutta - calls Single Step

    Search for NN pairs

    Calculate W and W'

    Calculate dv/dt and de/dt Add as many extra modules

    as needed

    Calculate the equation of state for p

    Calculate the artificial viscosity

  • The smoothing function (kernel) and its derivativeUse the cubic spline form

    where d is 1/h, 15/(7h2), and 3/(2h3) and =2 in 1-, 2-, and 3-D respectively. If we take the derivative of this we have

    W (R,h) =

    d 2+32

    R

    dxh2

    0 R < 1

    d 122 R( )2 dx

    hr1 R < 2

    0 R 2

    and

  • Nearest neighboring search algorithmsUse a search algorithm like the following:

    After storing the PAIR arraysW and DWDX the summations can be done in a single loop as shown below

  • Project 3: Colliding Jupiter like Planets

    First, generalize your code to 3D, x and v become vectors and kernel needs additions.

    Implement a gravitational potential in a self consistent manner.

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

  • Gravitational PotentialUse the following equations from the thesis: (P. Cossins, Chapter 3, Smoothed Particle Hydrodynamics, Ph.D. Thesis, Leicester 2010) (Note notation, they use x we use R)

  • Advanced SPH code There are some free advanced versions of SPH available on the internet which have been developed for astronomy purposes.These codes are state of the art and require some effort to install and use.The following link will take you to a complete list of tools but not all have SPH included:http://www.itp.uzh.ch/astrosim/code/doku.php?id=home:code:nbody:multipurposeA widely used SPH tool is Gadget-2 which is a massively parallel cosmological code: http://www.mpa-garching.mpg.de/gadget/I can probably give some advice about its installation

    ConclusionsHopefully, this has given you a well rounded introduction into the main components of N-body and SPH techniques.

    http://www.itp.uzh.ch/astrosim/code/doku.php?id=home:code:nbody:multipurposehttp://www.itp.uzh.ch/astrosim/code/doku.php?id=home:code:nbody:multipurposehttp://www.mpa-garching.mpg.de/gadget/http://www.mpa-garching.mpg.de/gadget/http://www.mpa-garching.mpg.de/gadget/http://www.mpa-garching.mpg.de/gadget/