41
 Gravitational dynamics with AMUSE Simon Portegies Zwart Sterrewacht Leiden

Gravitational dynamics with AMUSEamusecode.org/raw-attachment/wiki/lecture_slides/L2AB_gravityin... · Java Fortran and Python ... Tree code (Barnes & Hut, Gadget) ... Could use any

Embed Size (px)

Citation preview

Page 1: Gravitational dynamics with AMUSEamusecode.org/raw-attachment/wiki/lecture_slides/L2AB_gravityin... · Java Fortran and Python ... Tree code (Barnes & Hut, Gadget) ... Could use any

   

Gravitational dynamics with AMUSE

Simon Portegies ZwartSterrewacht Leiden

Page 2: Gravitational dynamics with AMUSEamusecode.org/raw-attachment/wiki/lecture_slides/L2AB_gravityin... · Java Fortran and Python ... Tree code (Barnes & Hut, Gadget) ... Could use any

   

Gravitational dynamics with AMUSE

Simon Portegies ZwartSterrewacht Leiden

Page 3: Gravitational dynamics with AMUSEamusecode.org/raw-attachment/wiki/lecture_slides/L2AB_gravityin... · Java Fortran and Python ... Tree code (Barnes & Hut, Gadget) ... Could use any

   

Manager

Community module

AMUSE http://amusecode.org

C/C++ code Fortran Code

MPI

Parent­proxy pair

RTGD HD SE

Particles

Python Script

Units

● Layers having different roles

● Written in C/C++, Java Fortran and Python

Page 4: Gravitational dynamics with AMUSEamusecode.org/raw-attachment/wiki/lecture_slides/L2AB_gravityin... · Java Fortran and Python ... Tree code (Barnes & Hut, Gadget) ... Could use any

   

Initialize

Store data

Evolve

> from amuse.lab import *> bodies = Salpeter(N, Mmin, Mmax)> gravity = ph4()> gravity.add_particles(bodies)> gravity.evolve_model(t_end)> write_to_file(gravity, “bodies.hdf5”)

Page 5: Gravitational dynamics with AMUSEamusecode.org/raw-attachment/wiki/lecture_slides/L2AB_gravityin... · Java Fortran and Python ... Tree code (Barnes & Hut, Gadget) ... Could use any

   

N­body algorithms

Why N­body methods?• Free of assumptions• Allow one to study interesting problems• Physics is simple• Mathematics is simple • Computational methods are complex• Methods are applicable in other disciplines (e.g. 

plasma physics, molecular dynamics)

Page 6: Gravitational dynamics with AMUSEamusecode.org/raw-attachment/wiki/lecture_slides/L2AB_gravityin... · Java Fortran and Python ... Tree code (Barnes & Hut, Gadget) ... Could use any

   

1643­1727

F i=G m i∑ j=1

nm j

r i−r j

∣ri−r j∣3

Page 7: Gravitational dynamics with AMUSEamusecode.org/raw-attachment/wiki/lecture_slides/L2AB_gravityin... · Java Fortran and Python ... Tree code (Barnes & Hut, Gadget) ... Could use any

   

How are these results computed?

Motion of individual particles given by Newton’s Laws

Forces computed from Newton’s Law of Gravity

“Just” have to solve two coupled ODEs, plus evaluate forces.

Page 8: Gravitational dynamics with AMUSEamusecode.org/raw-attachment/wiki/lecture_slides/L2AB_gravityin... · Java Fortran and Python ... Tree code (Barnes & Hut, Gadget) ... Could use any

Modeling Cluster DynamicsContinuum methods

gas sphere  (Bettwieser & Sugimoto, Spurzem)direct Fokker­Planck (Cohn, Takahashi)

  Particle methods

N­body “brute force”(Aarseth; NBODY6++; Starlab, pGC)

Tree code (Barnes & Hut, Gadget)direct Monte­Carlo (Henon, Spitzer; Freitag, Giersz, Heggie, Rasio)hybrid Monte­Carlo  (Giersz & Spurzem)

Page 9: Gravitational dynamics with AMUSEamusecode.org/raw-attachment/wiki/lecture_slides/L2AB_gravityin... · Java Fortran and Python ... Tree code (Barnes & Hut, Gadget) ... Could use any

   

Page 10: Gravitational dynamics with AMUSEamusecode.org/raw-attachment/wiki/lecture_slides/L2AB_gravityin... · Java Fortran and Python ... Tree code (Barnes & Hut, Gadget) ... Could use any

   

Page 11: Gravitational dynamics with AMUSEamusecode.org/raw-attachment/wiki/lecture_slides/L2AB_gravityin... · Java Fortran and Python ... Tree code (Barnes & Hut, Gadget) ... Could use any

   

Page 12: Gravitational dynamics with AMUSEamusecode.org/raw-attachment/wiki/lecture_slides/L2AB_gravityin... · Java Fortran and Python ... Tree code (Barnes & Hut, Gadget) ... Could use any

   

Introduction to mathematics of the N­body problem.

We will use numerical methods to get solutions to the equations of motion.  Useful to understand mathematical properties of solutions.

For N=2, solution can be computed analytically (two­body problem).

Total momentum  p = m1v1 + m2v2 Rate of change of p:   dp/dt = m1dv1/dt + m2dv2/dt = F1 + F2

  But F1 = ­F2,            ­­>  dp/dt = 0  ­­>  p = const.

So particles move around a common point (the Center of Mass), which moves at a constant velocity.

Page 13: Gravitational dynamics with AMUSEamusecode.org/raw-attachment/wiki/lecture_slides/L2AB_gravityin... · Java Fortran and Python ... Tree code (Barnes & Hut, Gadget) ... Could use any

   

Two­body problem (continued)

C of M

R

Can show motion of particles follows Kepler’s Third Law

R = distance between particlesP = period of orbit

Page 14: Gravitational dynamics with AMUSEamusecode.org/raw-attachment/wiki/lecture_slides/L2AB_gravityin... · Java Fortran and Python ... Tree code (Barnes & Hut, Gadget) ... Could use any

   

For N=3, no general analytic solution

Example of orbits in a 3­body encounter

Page 15: Gravitational dynamics with AMUSEamusecode.org/raw-attachment/wiki/lecture_slides/L2AB_gravityin... · Java Fortran and Python ... Tree code (Barnes & Hut, Gadget) ... Could use any

   

For N=3, no general analytic solutionApproximate solutions are possible in certain limiting 

cases, e.g. when one particle is much less massive than other two.

BUT, certain constraints still apply:Total energy conserved

Angular momentum conserved

Total momentum conserved, so center of mass moves at constant velocity (providing 6 more constraints).

Page 16: Gravitational dynamics with AMUSEamusecode.org/raw-attachment/wiki/lecture_slides/L2AB_gravityin... · Java Fortran and Python ... Tree code (Barnes & Hut, Gadget) ... Could use any

   

For                  continuum approximations apply.

Rather than solving for the position of each particle individually, instead compute the evolution of the phase space density:  f (x, v, t)

At any instant in time, each particle is represented by a point in the 6­dimensional space (x, v).  There are so many particles, this space is filled with points.  f represents the density of points in this space, and it evolves in time according to the Boltzmann equation:

Hard part is evaluating the collision term.  Common to use the Fokker­Planck approximation.  ●Continuum methods work well for dense stellar systems, but not when single particle interactions (binaries) are important.

Page 17: Gravitational dynamics with AMUSEamusecode.org/raw-attachment/wiki/lecture_slides/L2AB_gravityin... · Java Fortran and Python ... Tree code (Barnes & Hut, Gadget) ... Could use any

   

Timescales in N­body problems.The Crossing timeConsider a star cluster of radius R which contains N stars of 

mass m

By the virial theorem, for a system in equilibrium, the sum of kinetic and potential energies for a single star is:

So

For N=104, m = 0.5 solar masses, R = 4 pc, tcross = 5 million years

But age of cluster is about 10 billion years >> tcross

In addition, orbital time of binaries in cluster can be << tcross

Multi­timescale problem

Page 18: Gravitational dynamics with AMUSEamusecode.org/raw-attachment/wiki/lecture_slides/L2AB_gravityin... · Java Fortran and Python ... Tree code (Barnes & Hut, Gadget) ... Could use any

   

2. Computing Forces between particles.

Magnitude of force on ith particle

This diverges as distance between particles ­­> 0Can cause very small time steps.Solution is to use a softened potential

                  ε = softening parameter

Physically, this eliminates the formation of binaries with r < ε

Hard binaries (very small separation) are an important source of energy in clusters; this means ε should be as small as possible

Page 19: Gravitational dynamics with AMUSEamusecode.org/raw-attachment/wiki/lecture_slides/L2AB_gravityin... · Java Fortran and Python ... Tree code (Barnes & Hut, Gadget) ... Could use any

   

Direct summation is most straightforward method of evaluating F

But, number of operations scales as N(N­1)/2 

 this limits the number of particles, usually N < 104

Motivates finding more efficient techniques 

Page 20: Gravitational dynamics with AMUSEamusecode.org/raw-attachment/wiki/lecture_slides/L2AB_gravityin... · Java Fortran and Python ... Tree code (Barnes & Hut, Gadget) ... Could use any

   

3. Evolve positions using ODE solver

Could use any ODE solver (e.g. Runge­Kutta, Burlisch­Stoer, Hermite, leapfrog, …)

Must balance accuracy versus efficiency

Need many particles to capture dynamics correctly, which can be just as important as the accuracy of any one particle orbit (except for planetary orbits, when N small).

Page 21: Gravitational dynamics with AMUSEamusecode.org/raw-attachment/wiki/lecture_slides/L2AB_gravityin... · Java Fortran and Python ... Tree code (Barnes & Hut, Gadget) ... Could use any

   

Leap­frog schemeDefine positions (x) and forces (F) at time level n            velocities (v)                        at time level n+1/2Then, for ith particle

n­1       n­1/2        n          n+1/2       n+1                          timex, F         v           x, F          v           x, F

Page 22: Gravitational dynamics with AMUSEamusecode.org/raw-attachment/wiki/lecture_slides/L2AB_gravityin... · Java Fortran and Python ... Tree code (Barnes & Hut, Gadget) ... Could use any

   

Start MESAStart Mikkola

Start GadgetStart Bonsai

Generate NFW profile Read mass

pos and vel

Evolve stars to 1Myr

windmass

Evolve stars 

Integrate S stars + SMBH

Integrate Central cluster

Evolve Hydro

Windmass

Update Pos, vel

Updatemass

Collisions SupernovaWrite diagnostics

Updatemass

Page 23: Gravitational dynamics with AMUSEamusecode.org/raw-attachment/wiki/lecture_slides/L2AB_gravityin... · Java Fortran and Python ... Tree code (Barnes & Hut, Gadget) ... Could use any

   

Page 24: Gravitational dynamics with AMUSEamusecode.org/raw-attachment/wiki/lecture_slides/L2AB_gravityin... · Java Fortran and Python ... Tree code (Barnes & Hut, Gadget) ... Could use any

   

Page 25: Gravitational dynamics with AMUSEamusecode.org/raw-attachment/wiki/lecture_slides/L2AB_gravityin... · Java Fortran and Python ... Tree code (Barnes & Hut, Gadget) ... Could use any

   

Page 26: Gravitational dynamics with AMUSEamusecode.org/raw-attachment/wiki/lecture_slides/L2AB_gravityin... · Java Fortran and Python ... Tree code (Barnes & Hut, Gadget) ... Could use any

   

Page 27: Gravitational dynamics with AMUSEamusecode.org/raw-attachment/wiki/lecture_slides/L2AB_gravityin... · Java Fortran and Python ... Tree code (Barnes & Hut, Gadget) ... Could use any

   

Page 28: Gravitational dynamics with AMUSEamusecode.org/raw-attachment/wiki/lecture_slides/L2AB_gravityin... · Java Fortran and Python ... Tree code (Barnes & Hut, Gadget) ... Could use any

   

M55, ~200,000 stars.

Page 29: Gravitational dynamics with AMUSEamusecode.org/raw-attachment/wiki/lecture_slides/L2AB_gravityin... · Java Fortran and Python ... Tree code (Barnes & Hut, Gadget) ... Could use any

   

Evolution of the universe

Page 30: Gravitational dynamics with AMUSEamusecode.org/raw-attachment/wiki/lecture_slides/L2AB_gravityin... · Java Fortran and Python ... Tree code (Barnes & Hut, Gadget) ... Could use any

   

Page 31: Gravitational dynamics with AMUSEamusecode.org/raw-attachment/wiki/lecture_slides/L2AB_gravityin... · Java Fortran and Python ... Tree code (Barnes & Hut, Gadget) ... Could use any

   

● All later divide and conquer algorithms use same intuition

● Consider computing force on earth due to all celestial bodies

– Look at night sky, # terms in force sum >= number of visible stars

– Oops! One “star” is really the Andromeda galaxy, which contains billions of real stars

● Seems like a lot more work than we thought … 

● Don’t worry, ok to approximate all stars in Andromeda by a single point at its center of mass (CM) with same total mass

– D = size of box containing Andromeda , r = distance of CM to Earth

– Require that D/r be “small enough”

– Idea not new: Newton approximated earth and falling apple by CMs

Page 32: Gravitational dynamics with AMUSEamusecode.org/raw-attachment/wiki/lecture_slides/L2AB_gravityin... · Java Fortran and Python ... Tree code (Barnes & Hut, Gadget) ... Could use any

   

● From Andromeda’s point of view, Milky Way is also a point mass

● Within Andromeda, picture repeats itself

– As long as D1/r1 is small enough, stars inside smaller box can be replaced by their CM to compute the force on Vulcan

– Boxes nest in boxes recursively

Page 33: Gravitational dynamics with AMUSEamusecode.org/raw-attachment/wiki/lecture_slides/L2AB_gravityin... · Java Fortran and Python ... Tree code (Barnes & Hut, Gadget) ... Could use any

   

Bedorf etal 2012

N=3M Plummer run on GPUwith BH­treecode

Host: Multipole momentsGPU: Force, treewalk, integration

Page 34: Gravitational dynamics with AMUSEamusecode.org/raw-attachment/wiki/lecture_slides/L2AB_gravityin... · Java Fortran and Python ... Tree code (Barnes & Hut, Gadget) ... Could use any

   

● Data structure to subdivide the plane

– Nodes can contain coordinates of center of box, side length

– Eventually also coordinates of CM, total mass, etc.

● In a complete quad tree, each nonleaf node has 4 children

Page 35: Gravitational dynamics with AMUSEamusecode.org/raw-attachment/wiki/lecture_slides/L2AB_gravityin... · Java Fortran and Python ... Tree code (Barnes & Hut, Gadget) ... Could use any

   

● Similar Data Structure to subdivide space

Page 36: Gravitational dynamics with AMUSEamusecode.org/raw-attachment/wiki/lecture_slides/L2AB_gravityin... · Java Fortran and Python ... Tree code (Barnes & Hut, Gadget) ... Could use any

   

Example of an Adaptive Quad Tree

Child nodes enumerated counterclockwisefrom SW corner, empty ones excluded

Page 37: Gravitational dynamics with AMUSEamusecode.org/raw-attachment/wiki/lecture_slides/L2AB_gravityin... · Java Fortran and Python ... Tree code (Barnes & Hut, Gadget) ... Could use any

   

● Correctness follows from recursive accumulation of force from each subtree– Each particle is accounted for exactly once, whether it is in a leaf or other 

node

● Complexity analysis– Cost of TreeForce( k, root )  = O(depth in QuadTree of leaf containing k)

– Proof by Example (for θ>1): 

– For each undivided node = square, 

      (except one containing k), D/r < 1 < θ

– There are 3 nodes at each level of

      the QuadTree

– There is O(1) work per node

– Cost = O(level of k)

• Total cost = O(Σk level of k) = O(N log N) 

- Strongly depends on θ

k

Page 38: Gravitational dynamics with AMUSEamusecode.org/raw-attachment/wiki/lecture_slides/L2AB_gravityin... · Java Fortran and Python ... Tree code (Barnes & Hut, Gadget) ... Could use any

   

Load Balancing Scheme 2: Costzones

● Called Costzones for Shared Memory– PhD thesis, J.P. Singh, Stanford, 1993

● Called “Hashed Oct Tree” for Distributed Memory– Warren and Salmon, Supercomputing 93

● We will use the name Costzones for both; also in Pbody

● Idea: partition QuadTree instead of space– Estimate work for each node, call total work W

– Arrange nodes of QuadTree in some linear order (lots of choices)– Assign contiguous blocks of nodes with work W/p to processors

– Works well in 3D

Page 39: Gravitational dynamics with AMUSEamusecode.org/raw-attachment/wiki/lecture_slides/L2AB_gravityin... · Java Fortran and Python ... Tree code (Barnes & Hut, Gadget) ... Could use any

M80

Arches

Quintplet

R136

NGC 3603

30 pc

~1 000 000 Msun

Trapezium

Westerlund1

MG

11

5pc

Pleiades

Page 40: Gravitational dynamics with AMUSEamusecode.org/raw-attachment/wiki/lecture_slides/L2AB_gravityin... · Java Fortran and Python ... Tree code (Barnes & Hut, Gadget) ... Could use any

   

Page 41: Gravitational dynamics with AMUSEamusecode.org/raw-attachment/wiki/lecture_slides/L2AB_gravityin... · Java Fortran and Python ... Tree code (Barnes & Hut, Gadget) ... Could use any

   

But they are not point masses...