====== Simulations in the Natural Sciences II ====== {{combined.jpg?800x100|}} **ESC202:** Spring 2022: Monday Lecture: 13:00-14:00 Exercises: 14:00-17:00 in Y36-J-33 **TAs:** Stefan Schafroth and Sebastian Schulz (sebastian.schulz@uzh.ch) ====== Lectures ====== 21. Feb. 2022: {{ :spin:sins2-01.pdf |Tree Structures and Dimensional Searching}} 28. Feb. 2022: {{ :spin:nearestneighboursearching.pdf |Nearest Neighbour Searching}} 7. Mar. 2022: {{ :spin:nearestneighboursearching2.pdf |Nearest Neighbour Searching - Part 2}} 14. Mar. 2022: {{ :spin:sphkernels.pdf | SPH - Equations and Kernels}} 21. Mar. 2022: {{ :spin:sphmainequations.pdf | SPH - Main numerical equations}} 28. Mar. 2022: {{ :spin:sphwindtunnel.pdf |SPH - Wind Tunnel}} 4. Apr. 2022: {{ :spin:2-disingmodel.pdf |2-D Ising Model}} 11. Apr. 2022: {{ :spin:travelling_salesperson.pdf |Traveling Salesperson}} ====== Assignments ====== In order to **qualify** for the final semester project and a passing grade you will need to hand in **80% satisfactory assignments** (to the satisfaction of the TAs). 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 [[https://towardsdatascience.com/all-you-need-to-know-about-python-virtual-environments-9b4aae690f97|Python Virtual Environments for Pip]] and [[https://uoa-eresearch.github.io/eresearch-cookbook/recipe/2014/11/20/conda/|Python Virtual Environments for Conda]]. You should email 3 things to Sebastian (**sebastian.schulz@uzh.ch**): - The working **python source code** - The **requirements.txt** file for your virtual environment - A **.pdf** or **.png** image or animation of the output of your program Template: {{template.zip}} ** Instructions: ** 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 Pip - 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 Conda - 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. Build a partitioning function of particles like we introduced it in class. The hard part is making sure your partition function is really **bomb proof**, check all "edge cases" (e.g., no particles in the cell, all particles on one side or other of the partition, already partitioned data, particles in the inverted order of the partition, etc...). **(Hand in by Feb 27 2022)**. 2. Implement a binary tree of cells which contain at most 8 particles each (see pseudo-code in the Teams Kursmaterialien folder). Then, implement the ballwalk algorithm as introduced in the lecture (making use of the dist2 function) to calculate the number of particles within a distance to a point in the box. **(Hand in by March 6 2022)** 3. For each particle calculate the “top-hat” density from the 32 nearest neighbors and plot it using a colormap. Use a priority queue with a heap algorithm to implement “replace” and “max” functions (you can make use of the heapq library for python). We will need the density to implement SPH so it needs to be well tested. Also, make sure it can work with periodic boundary conditions! **(Hand in by March 13 2022)** 4. Now, calculate the density using the Monaghan kernel defined in the lecture. Plot and compare to the density you get from the “top-hat” kernel (the Monaghan result should be a little smoother). **(Hand in by March 20 2022)** 5. Implement the SPH code introduced in the lecture to simulate the movement of the particles in the box, following the laws of hydrodynamics. You can start with a random particle distribution, or even simulate a "blast" with initial conditions where a particle somewhere has a high energy. **(Hand in by March 27 2022)** 6. 2D Ising Model: Using the Metropolis algorithm, plot the mean magnetization of a N by N grid of spins (+1 and -1) depending on the temperature. Visualise the spin state of the grid at different temperatures **(due April 11th)**! 7. Metropolis algorithm II: Implement the traveling merchant problem **(due April 17th)**! Have a look at some of the data found at http://comopt.ifi.uni-heidelberg.de/software/TSPLIB95/tsp/ to test your algorithm!