Assignment 2

A Particle-Particle Code

For Tuesday March 4, your assignment is to create a 3-dimensional PP code. PP codes are relatively simple to construct, and contain many of the essential elements contained in all types of particle codes. When you are writing this code, please remember to keep organized using modular subroutines. This code will be the basis of future extensions and modifications.


Problem Description:

Your program should have the following elements:

1. Initialize variables, read the data and parameter files

2. Calculate the force for each particle by direct summation. Using the PP method, this calculation can will take order of N^2 calculations. Use a softened force of the form F = GMm/(R^2 + eps^2) where eps is a fixed softening length. We will always use a small but finite softening length in these simulations. Assume G=1 for these calculations! Initial timesteps should be about 0.01.

3. Move the particles using a numerical integrator. A simple leap frog technique is satisfactory for this program. (Step v then step x.)

4. Calculate the total kinetic, potential and total energy for the system. Make sure you use a potential energy equation which corresponds to the softened point mass.

5. Calculate the change in the total energy of the system from the last time step. (Delta-E)

6. The program should be able to change timesteps based on changes in the systems total energy. Let FDE = ( abs(Delta-E)/abs(KE), abs(Delta-E)/abs(PE) ) This is an estimate of the fractional energy change of the system. We use the maximum of the two terms to prevent problems when the total energy is near zero. You do not have to consider changing the timestep for each particle

7. If FDE > delta-E-max, lower the time step by 1/2 and repeat the step.

8. If FDE < delta-E-min, raise the time step by 1.2 and continue with the program. The next step should be 20% larger.

9. You should be able to set the time step constant for each step also!!!!

10. update time, positions, and velocity using the numerical integrator.

11. Determine if you should output the data to a file. The data should be output at an interval delta-T-output. That is, the particle positions and velocites should be recorded at uniform TIME intervals.

12. Jump back to step 2 unless the number of interactions is greater than Nmax.


Parameter file:

This file will be ascii and have the following order for the parameters. eps : softening length
fixed step flag: 1 if you keep the step size the same, 0 if it changes
delta-E-min : the minimum energy before increasing the timestep
delta-E-max : the maximum energy before decreasing the timestep
delta-T-initial: the initial time step
Nmax : the maximum number of iterations
delta-T-output : the output time interval
eps : the softening length for the force

Input Datafile:

The datafile will be ascii with approximately 20 particles. You should terminate the read at the end of the data rather than specifying the number of particles.

The format for the data file will be

(1x,710.3) with the variables
x, y, z, vx, vy, vz, mass

Output Datafile:

You may use any form for the output datafile. However, you must record particle positions and velocities, along with the total, kinetic and potential energies as a function of time. You may use two files for the particle and system information.

Graphics Output:

For this assignment, you will need to produce two graphics files.

1. You should plot the positions of the particles projected into the XY plane. Particles should be plotted with different symbols and plotted from the output data file at delta-T-output time intervals. You may use a series of plots for representing each time step OR plot particle trajectories on the x-y plane.

2. The total, kinetic, and potental energy should be plotted as a function of time for the simulation. This plot is an excellent debugging tool.

3. Graphics should NOT be built into the simulation code.


Analysis of the Code

After you have completed the code and can analyze its output with graphics, you should determine the following things and discuss them in a one or two page write up.
1. How do the energy conservation graphs change as you vary the time step for the same initial conditions? Summarize the results you obtain from at least 4 runs.
2. How does softening length affect conservation of energy? If all other conditions are the same, does softening length really improve the code?
3. Is conservation of energy a good indicator of the true accuracy of the code? Look at the difference in the final position of the particles with differences in step size, and compare them to the conservation of energy results.
4. How does a variable step size affect conservation of energy and accuracy? Does it save signicant amounts of time?

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 should include instructions on how to compile this code. A "Makefile" would be nice, especially if you have multiple files and subprograms.

3. Graphics output may be created on any machine using any graphics package, and turned into a postscript file.

4. Written description and documentation may be created using any word processor or text formating program, and turned into a postscript file. Latex and TeX are also acceptable formats for documentation, as long as all auxilary files are included.

5. When you have completed the project, use the Unix tar command to create a single file which contains:

  • documentation file (postscript)
  • 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 jwallin1.tar directory The file jwallin1.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 jwallin1.tar

    6. Use anonymous ftp to leave the file in the pub/nbody directory of

    galileo.gmu.edu

    jwallin@gmu.edu