T9: General N-Body problem (free-fall Collapse of a sphere)
Before the tutorials:
Do, think about, and research the following:
- Bring your own program to the level of the example given for the last tutorial,
so that you can start from a clean and working version.
- What is the free fall time of a hmogenious sphere ?
- If you have a homogeneous distribution of particles, how would you
setup a gravitational softening to avoid unwanted, numerical effects ?
During the tutorials:
Program it!
- Set up a sphere of homogeneous density of particles which are in rest.
Hint: just setup a regular grid of particles and cut out a sphere.
- Let the sphere collapse under it's own gravity and confirm that the free fall time is
t_ff = sqrt ( 3 * Pi / (32 * G * rho))
Hint: It might be also useful to not output every time-step and to use a small
softening to avoid 2-body collisions.
Example programs:
These are just examples.
- C/C++:
- F90:
- Simple version (this is sufficient for the moment, but it doesn’t hurt you to start improving it as suggested above):
T6.f90
(colorized),
Makefile
(colorized) (rename to “Makefile” or use with “make -f Makefile_gfortran”)
- More complex version:
(To be added later. We will reorganize the program structure when we get to multiple particles; think about how you would do this on your own.)
Discussion of the results:
Plot your results with gnuplot and plot the behaviour of the systems.
Can you explain what you see ?
Example plots:
Programming goals for T9:
Having many particles in our system and getting the program slow, we might think on a trivial
parallelization ?Think about:
- What independent within a independent loop ?
- What is the most time consuming loop where you should do something ?
- Which loop is difficult to be paralleled and why ?
If your computer has multiple cores, you can parallelize independent loops by adding
#pragma omp parallel for
in front of it. To tell the compiler to compile with OpenMP, you have to add
-openmp
to the options in the Makefile. You can control how may cores should be
used by the program by the setting the environment variable
export OMP_NUM_THREADS=4