Home

Awesome

vpython-projects

Toy projects with vpython for computational physics

Check out details about vpython https://vpython.org/

Basic Operation


Mass Spring System

<img src="./IMAGES/spring_network.gif" height="372" width="800">

Run spring_network.py

We implemented mass spring system, where each particles(masses) are connected with each other by spring. We mainly considered 3 forces to calculate each particle acceleration.

Currently, only box objects(where particles can collide. In the above gif the green thing is comprised of 3 boxes) are supported. But in request I will update other object type such as sphere. (Try sphere! It is easy to implement collision detection algorithm than box object.)

You can also add or remove box objects inside the code. Check line 157 through line 174 in spring_network.py

Simulating star with SPH(Smoothed Particle Hydrodynamics)

<img src="./IMAGES/SPH_star.gif" height="350" width="350">       <img src="./IMAGES/SPH_star2.gif" height="350" width="350">      

Run SPH.py

You can find what SPH is, and details about SPH in this paper Smoothed Particle Hydrodynamics.

And also consult philip-mocz.medium, which my code is heavily based on.

So what SPH is basically doing is that using smoothing-kernel we can map continuous field on to a series of discrete particles. Smoothing-kernel is the approximation to dirac-delta function and there are many differnet kinds of kernel, in this example we use Gaussian smoothing kernel.

(where x = r / h )


And the fluid equation of motion which we want to discretize is Euler equations with the inviscid fluid, given as follow.


With the SPH formalism, density at any given point can be easily approximated by particles comprising fluid. Details can be found at Smoothed Particle Hydrodynamics.


For the pressure, we assume pressure is given by polytropic equation of state. Polytrope

where k is constant and n is polytropic index. (n=1 for our project) We can easily calculate pressure at any given point by calculating density at that point.


For the external force, we consider gravity and drag force.

First term corresponds to gravity and second to drag force. Second term is needed to make steady state.


Finally, we can write Euler equation with the help of SPH formalism as follow. (It is actually just re-expressing -(1/rho) * grad P in terms of SPH formalism.)

<img src="./IMAGES/acc.png">

And we can calculate above equation with the pressure, density, external forces , kernel which we presented earlier. Using above equation, we can use explicit Euler method to calculate particles positions and velocity obeying Euler equation. Thus we can simulate fluid motion (or in this project, formation of the star)


References

https://philip-mocz.medium.com/create-your-own-spring-network-simulation-with-python-d9246e4091e5

https://philip-mocz.medium.com/create-your-own-smoothed-particle-hydrodynamics-simulation-with-python-76e1cec505f1

Smoothed Particle Hydrodynamics

Smoothed Particle Hydrodynamics: Theory, Implementation, and Application to Toy Stars