User Tools

Site Tools



Simulations in the Natural Sciences II

ESC202:Spring 2020: Monday Lecture: 13:00-14:00 Exercises: 14:00-17:00 in Room 36 J 33

TAs: Stefan Schafroth (

Corona Virus Measures

Dear Students, I would like to keep the class going over the next few weeks. In order to adapt I will provide a video lecture from the 23. March onwards until lectures can take place again. Communication will take place via this web-site regarding all assignments as well. As the announcement about the closure of lectures was made on 13. March, it was not possible to provide a video lecture for the 16. March. I will however upload lecture notes for 16. March (today) and I ask you to complete the tree-code based simulation of the planetesimals orbiting the Sun. I hope that we can resume class meetings during the final 1/3 of the semester during the “project phase” of the course. Many thanks for your understanding!

Joachim Stadel

Video Lectures

Videos for the lectures can be found here (they are too large for my Wiki):

ESC202 Video downloads


17. Feb. 2020: Tree Structures and Dimensional Searching

2. Mar. 2020: Gravity Tree Walk

16./23. Mar. 2020: Introduction to SPH (Videos sph1.mp4 and sph2.mp4 see above link)

30. Mar. 2020: SPH Continued (Videos sph3.mp4 and sph4.mp4 see above link)

6. Apr. 2020: SPH Continued (Video sph5.mp4 see above link)

20. Apr. 2020: 2-d Ising Model (Video ising.mp4 see above link)

27. Apr. 2020: 2-d Traveling salesman problem (Video tsp.mp4 see above link)

3. May 2020: Start of group projects!


Should be handed in every Sunday night by 21:00 following the Monday lecture. Assignments should be individual and should be in python and provide a correct virtual environment!

For help getting started with virtual environments, please read carefully Python Virtual Environments for Pip and Python Virtual Environments for Conda.

You should email 3 things to Stefan (

  1. The working python source code
  2. The requirements.txt file for your virtual environment
  3. A .pdf or .png image or animation of the output of your program



Please add the names of the people you work together (if you do) to the comment section of your python scripts.

Create a virtual environment using


- run virtualenv yourenv_name to create a virtual environment

- run source yourenv_name/bin/activate to activate yourenv_name

- install necessary libraries that you want using pip install package_name

- work in that directory, get your outputs (*.pdf, *.png, *jpeg, *.mp4, etc…)

- run pip freeze > requirements.txt to get your list of libraries


- run conda create -n yourenvname python=x.x anaconda to create a virtual environment

- run source activate yourenvname to activate yourenv_name

- install necessary libraries that you want using conda install -n yourenv_name package_name

- work in that directory, get your outputs (*.pdf, *.png, *jpeg, *.mp4, etc…)

- run conda list –export > requirements.txt to get your list of libraries

List of assignments

1.k-Nearest Neighbors algorithm (you can set k=8 or other values to test). You should check the code via direct computation (O(N^2)). Solution is expected to include a priority queue over the 8 NN particles, but could also explore the use of a further prioq over the nearest cells during the treewalk as discussed in the lecture.

2. Extended to Sunday 22.03.2020: Gravity simulation using 2-D trees. Implement a 2-D gravity tree-code to solve the forces between the 12'095 planetesimals in the early solar system. While the data structure is 2-D, the forces and motions are actually 3-D. The data file below contains the planetesimals in the following format (one per line): <x y z vx vy vz m r> in unit of AU, AU/day, solar mass and AU. Recall these are the same units used in the ESC201 course for the solar system simulations. You will have to use the Gaussian gravitational constant k^2 instead of G.

esc202-planetesimals data file

3. SPH Density calculation using Kernel: You can use the data set from your planetesimals simulations to calculate the densities and make nice color density plots of the planetesimal disk. As discussed in the Zoom meeting: you should try to put uniform randomly distributed particles in a box from [0,1)x[0,1) (2-D) and calculate the density. You should see a bias that the density is too low at the edges. If you do this with a correctly working working periodic boundary condition density code you should no longer see this bias. Please think about how to efficiently calculate the density using nearest neighbors with periodic boundary conditions. Even better, implement it in your code and test it!

4. Sedov Taylor Explosion in SPH: Set up a uniform grid of SPH particles in a 2-D unit cell. Make it so that there are an odd number of particle on a side, such that you have a particle centered exactly in the center of the unit cell. All particle should have v = 0 and mass = 1/N, where N is the total number of particles such that the mass of the fluid in the unit cell is 1. If we use gamma=2, then for e=1 we have c=sqrt(2) for all particles and the SPH code should maintain the uniform density as everything should be in pressure equilibrium. Test this. Now set the specific internal energy of the central particle to e = 100! Now the gas should react by producing the Sedov-Taylor blast wave. You will have to think about the appropriate timestep for the simulation. Think back to the Courant Condition from the first semester, or simply experiment with different values (hint: you know the sound speed, but what is the grid speed? What defines a resolution length scale here? h? So could we regard h/delta_t as a “grid speed”?

5. 2-d Ising Model

6. 2-d Travelling Salesman Problem

spin/esc202_fs2020.txt · Last modified: 2020/05/04 08:12 by stadel