Example of a leapfrog integrator for a van der waals force.
Plot over the Virial ratio Kinetic/Potential over time for a gravitational system
You can download a .zip file of this project, unzip it onto some directory in the imac, and type "make" to run all the commands in the file "makefile". This will compile the simulation, run the simulation, run the python file, and then run convert to make the output animation. "make clean" will delete all of the output files.
Some comments:
- For a Plummer sphere simulation, you would have to make this into a 3-dimensional code
- vdwAcceleration() can be modified to provide a gravitational force instead
- Later, we'll go over the Aarseth code. If you're not comfortable with creating your own n-body simulation, you can use the Aarseth code to do n-body calculations without writing your own for partial credit. You still have to code in C, but it's easier.
- Molecular dynamics simulations like these are fun! This simulation is my favorite. This gravitational collision simulation has long-distance attraction, short-range repulsion, and friction. More sophisticated simulations to model galaxy formation use techniques like smoothed particle hydrodynamics to model the interaction of gases.
To make mpeg files on the imac, first run the following so that we can find the command "mpeg_encode" from the terminal.
export PATH="/software/physics/mpeg_encode:$PATH"
This will allow us to find "mpeg_encode" in our LOCAL terminal (so if you close terminal and open it up again, you will have to run "export" again.)
Next, call mpeg_encode mpgparams
. This creates an mpeg file using the parameters in the text file mpgparams.
A description of mpgparams can be found at this link https://davidphys.github.io/vdw-example/makempeg_manual.html.
Note that you have to have .jpg files! Additional (but outdated) information is at https://courses.physics.ucsd.edu/2016/Winter/physics141/Labs/Lab3/Lab3.html.