Check out details about vpython https://vpython.org/
- Rotating the camera view:
ctrl + drag left mouse buttonordrag right mouse button - Zoom in and out:
scroll wheeloralt + drag left mouse button - Pan(move up, down, left, right):
shift + drag left mouse button
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.
- Spring force
- Gravity
- Damping force
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
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.
- 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.
- Euler equations of motion in the case of inviscid fluid
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.
- Density approximation using SPH
For the pressure, we assume pressure is given by polytropic equation of state. Polytrope
- Pressure
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.
- External Forces
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.)
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)
https://philip-mocz.medium.com/create-your-own-spring-network-simulation-with-python-d9246e4091e5
Smoothed Particle Hydrodynamics
Smoothed Particle Hydrodynamics: Theory, Implementation, and Application to Toy Stars








