ASTR 5540: 1-D Gravitational Particle-Mesh Code and Leap-Frog Integrator - Prof. Andrew J., Assignments of Astronomy

A problem set for astr 5540, a graduate-level astrophysics course, which involves writing a 1-dimensional gravitational particle-mesh (pm) code using functions such as a cloud-in-cell (cic) smoothing window, wavenumber of a fourier mode, mesh density given particle positions, fft of mesh density, potential given density in fourier space, acceleration given potential in fourier space, fft acceleration back on to the mesh, and acceleration at particle positions given mesh acceleration. The problem set also requires implementing a leap-frog integrator for the positions and velocities of particles and integrating and plotting the positions as a function of time.

Typology: Assignments

Pre 2010

Uploaded on 02/13/2009

koofers-user-8o7
koofers-user-8o7 🇺🇸

9 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ASTR 5540 Math Meth Fall 2008. Problem Set 9. Due Mon Nov 3
1. 1-D PM code
In the language of your choice (IDL, Mathematica, c, ...), write a 1-dimensional gravita-
tional Particle-Mesh (PM) code. Choose whatever units of length, mass, and time make
programming easiest.
(a) Functions
Your code should contain functions that implement the following:
1. A cloud-in-cell (CIC) smoothing window W(x);
2. Wavenumber of a Fourier mode;
3. Mesh density given particle positions;
4. FFT of mesh density;
5. Potential given density, in Fourier space;
6. Acceleration given potential, in Fourier space;
7. FFT acceleration back on to mesh;
8. Acceleration at particle positions given mesh acceleration.
[Hints: Function 2 depends on how the FFT you use stores the FT. In mathematica for exam-
ple, the FT is stored as a complex array {˜a0,˜a1,˜a2, ..., ˜a[N
2],˜a[N
2]+1N, ..., ˜a2,˜a1}, so that the
wavenumbers are {0,1,2, ..., [N
2],[N
2]+1N, ..., 2,1}. FFTs that input a real array typi-
cally return {˜a0,Re ˜a1,Im ˜a1, ..., Re ˜a[N
2]}, in which case the wavenumbers are {0,1,1, ..., [N
2]}.
Function 5 should set the zero’th Fourier mode of the potential to zero, ˜
φ0= 0. Function
6 should set the zero’th and [N
2]’th (for even N) Fourier mode of the acceleration to zero,
˜g0= ˜g[N
2]= 0. The sign of the acceleration ˜gin Fourier space depends on the phase con-
vention of the FFT; for example mathematica’s phase convention is minus the convention
adopted in class.]
(b) Leap-frog integrator
Implement a leap-frog integrator for the positions xand velocities vof particles:
vi+1
2=vi
1
2+git ,
xi+1 =xi+vi+1
2t , (1.1)
where tis a suitable time step.
(c) Integrate and plot
Choose a reasonable mesh-size N. Choose a small number of particles, say 2 to 4. Give
the particles random initial positions, and zero initial velocities. Choose a time step t.
Integrate for a sufficient number of steps, at least 100. Plot the positions of the particles as
a function of time t.
1

Partial preview of the text

Download ASTR 5540: 1-D Gravitational Particle-Mesh Code and Leap-Frog Integrator - Prof. Andrew J. and more Assignments Astronomy in PDF only on Docsity!

ASTR 5540 Math Meth Fall 2008. Problem Set 9. Due Mon Nov 3

  1. 1-D PM code

In the language of your choice (IDL, Mathematica, c, ...), write a 1-dimensional gravita- tional Particle-Mesh (PM) code. Choose whatever units of length, mass, and time make programming easiest.

(a) Functions

Your code should contain functions that implement the following:

  1. A cloud-in-cell (CIC) smoothing window W (x);
  2. Wavenumber of a Fourier mode;
  3. Mesh density given particle positions;
  4. FFT of mesh density;
  5. Potential given density, in Fourier space;
  6. Acceleration given potential, in Fourier space;
  7. FFT acceleration back on to mesh;
  8. Acceleration at particle positions given mesh acceleration. [Hints: Function 2 depends on how the FFT you use stores the FT. In mathematica for exam- ple, the FT is stored as a complex array {˜a 0 , a˜ 1 , a˜ 2 , ..., ˜a[ N 2 ], ˜a[ N 2 ]+1−N , ..., a˜− 2 , ˜a− 1 }, so that the

wavenumbers are { 0 , 1 , 2 , ..., [N 2 ], [N 2 ]+1−N, ..., − 2 , − 1 }. FFTs that input a real array typi- cally return {˜a 0 , Re ˜a 1 , Im ˜a 1 , ..., Re ˜a[ N 2 ]}, in which case the wavenumbers are { 0 , 1 , 1 , ..., [N 2 ]}.

Function 5 should set the zero’th Fourier mode of the potential to zero, φ˜ 0 = 0. Function 6 should set the zero’th and [N 2 ]’th (for even N ) Fourier mode of the acceleration to zero, ˜g 0 = ˜g[ N 2 ] = 0. The sign of the acceleration ˜g in Fourier space depends on the phase con-

vention of the FFT; for example mathematica’s phase convention is minus the convention adopted in class.]

(b) Leap-frog integrator

Implement a leap-frog integrator for the positions x and velocities v of particles:

vi+ 1 2 = vi− 1 2

  • gi ∆t , xi+1 = xi + vi+ 1 2 ∆t , (1.1)

where ∆t is a suitable time step.

(c) Integrate and plot

Choose a reasonable mesh-size N. Choose a small number of particles, say 2 to 4. Give the particles random initial positions, and zero initial velocities. Choose a time step ∆t. Integrate for a sufficient number of steps, at least 100. Plot the positions of the particles as a function of time t.