Assignment #4
Particle Mesh Code -Part II
For Friday April 25, your assignment is to finish the
two dimensional particle mesh code you began in assignment 3.
This code will read in a distribution of particles, map
them on the grid, calculate the potential, calculate the
force, and then move the particles for a set of time steps.
You will also calculate the total energy at each time step.
The final step of the project will be to profile the code
and determine where it should be optimized.
Problem Description:
- Read in x, y, vx, vy, and mass from a datafile
- Initialize your Green's function and its FFT
- Map your particles on the grid using the NGP scheme
- convolve with the Green's function assignment #3 results
- use a centered finite different routine to calculate a force matrix (see
below)
- map these forces back to the particles using NGP
- calculate the potential and kinetic energies of the particles
- move the particles using a simple Euler's method routine (assignment #2)
- save particle positions to a data file at selected intervals
(Make sure to multiple the complex numbers correctly!!!!)
- save the energy data to a file every timestep
- profile the code
- describe the results in a 3-5 page short report with plots
of the run and energy conservation
- include a short 1 page summary of where you should optimize your code
Problem Parameters
- Use your assignment 3 code for this project! This means:
- Solve the problem on a 64 by 64 grid. All the mass
should be in a one 32 by 32 corner of this grid.
- The Green's function should be of the form
1/sqrt(r*r + eps*eps) where eps is a softening length
for the POTENTIAL. This is slightly different from a
softening length for FORCE, but behaves in much the same way.
- You may beg, borrow, or share the FFT routines from
"Numerical Recipes" or other platform independent libraries.
- You can work in a group of two, if you like.
- The file format for the input and output data files should
be the same. One record per line ascii format, with
x, y, vx, vy, mass
delimited by spaces.
- Energy output should be
time, Total energy, kinetic energy , potential energy
again, one record per line, space delimited, ascii format.
- Assume that the particles will be located with positions
between 0 and 32 initially. For our test case, generate
a file with 256 particles with zero initial velocities and random
positions. Assume they all have masses of 1.
- Make sure to keep the particles inside the grid (32x32 active region).
If they move outside the grid, you may map them to the other
grid wall. (Ie. if a particle's position is less than 0, move it
to 32 + current position.)
- To calculate the forces, it is usually easer to apply finite
different technques on the ENTIRE grid at one time. You will produce
a Force-X grid and a Force-Y grid. This is slightly inefficient
with both memory, and may be inefficent with computation.
However, to interpolate the forces, you need only find the force
associated with a particular particles cell.
- Remember the tricks about calculating the potential.
Multiple the mass and potential matrix elements together, sum them,
subtract self-force, then divide by two.
- You should provide output of the evolution of the
system over a few hundred timesteps. What step size? YOU have
to figure that out yourself. The system should at least go
through a full collapse and re-expansion. It should also probably
go through a second collapse to really test the code.
- Create some images of the initial and final states, as well
as the evolution. Also, a plot of the energy - total, ke, pe,
is essential for the run.
- Profiling the code is pretty easy. Take a look at the
profil, gprof, and prof commands. The idea is to track preformance.
YOU DO NOT HAVE TO OPTIMIZE YOUR CODE IN THIS PROJECT! ANALYSIS OF THE
CODE IS SUFFICIENT! You should discuss what should be done
and suggest what things you would do to speed things up.
- Don't for get to write a report about the project and
the tests you use to make it work.
Graphics Output:
You need to produce some graphical output to document
the successfulness of your tests. You don't have to
do all the test cases.
Assignment requirements:
1. You must write this program in C, C++, or Fortran.
It must compile and run on a Sparc 10 workstation with
either the gnu C and g++ compilers or the standard
ANSI Fortran. If it compiles on the SGI machines,
it should compile on my workstation.
2. You can create an on-line version of the project which
is accessable through the Web. This is the easiest way
for me to grade your projects.
3. You should include instructions on how to compile this
code. A "Makefile" would be nice, especially if you
have multiple files and subprograms.
4. Graphics output may be created on any machine using
any graphics package, and turned into a postscript file.
You can also create Web pages and give me the URL.
5. You should write a short 3-5 page report documenting
the code and your results. This doesn't have to be fancy,
but it should summarize your work.
6. When you have completed the project, use the Unix
tar command to create a single file which contains:
documentation file (postscript, html, or text)
C, C++, or fortran program
Makefile and/or compilation instructions
graphics output file (postscript)
A short README file explaining what each file contains.
Hint: To create the tar file, put all your files into a single
directory on a unix machine. Go one level above this
directory and type:
tar -cvf username.tar directory
The file username.tar is the name of the newly created tar file.
The tar file names should be your email account with a number
indicating the assignment number. To extract the file,
type
tar -xvf username.tar
THE NAME OF YOUR FILE SHOULD BE YOUR USER ID FOLLOWED
BY THE ASSIGNMENT NUMBER!
6. Use anonymous ftp to leave the file in the
pub/nbody directory of
galileo.gmu.edu