Beruflich Dokumente
Kultur Dokumente
1 The equations
1.1 The Kernel
2 3
3 r 3 r r
1 −
2 h 4 h ,
+ 0≤ ≤1
h
W (~r, h) = C 1 2 − r 3 , 1≤ ≤2r (1)
4 h h
0, r
>2
h
y 3yr
x 3xr z 3zr r
− 2 x̂ + − 2 ŷ + − 2 ẑ, 0≤ ≤1
3C h 4h 2 h
4h h
4h h
2 2
∇W (~r, h) = − x
2 − hr x̂ + 4r y
2 − hr ŷ + 4r z
2 − hr ẑ, 1 ≤ r
≤2 (2)
h
4r
r
h
0, >2
h
Clarification-
In this notation, we are measuring r,x,y,z from the center of the kernel’s location at the jth
particle. So, for both the kernel and the grad of the kernel, we should be using
x = (xi − xj )
y = (yi − yj )
z = (zi − zj )
q
r= (xi − xj )2 + (yi − yj )2 + (zi − zj )2
3
2h
, 1 dimension
10
C= 7πh2
, 2 dimension (3)
1
, 3 dimension
πh3
1.2.2 Momentum
q
d~vi XN
1 Pi Pj
=− mj 2 + Πij ▽ Wij (5)
dt j=1 2 ρi ρj
1
1.2.3 Energy
q
dui N
X 1 Pi Pj
=− m j 2 + Πij (~vj − ~vi ) · ▽Wij (6)
dt j=1 2 ρ i ρ j
hi + hj
hij =
2
ρi + ρj
rhoij =
2
ci + cj
cij =
2
For the constants, we typically use
α=1
β=2
ǫ = 0.1
P = (γ − 1)ρu (9)
Where γ is a constant. γ = 5/3 for an ideal gas and γ = 4/3 for air.
The sound speed is given by
s
γP
c= (10)
ρ
2
1.4 Leap Frog
vn+1/2 = vn−1/2 + an dt
rn+1 = rn + vn+1/2 dt
This is a second order accurate method that is easy to implement. If you need vn , you can use
1
vn = (vn+1/2 + vn−1/2 ) (11)
2
dui
ui+1 = ui + dt (12)
dt
Kh
dt = (13)
vs + vmax
where K is the courant number, c is the speed of sound and vmax is the maximum velocity difference
between the ith particle and other particles in its interaction list.
Typically, we pick K = 1/2 or slightly smaller K = 1/4.
We can simplify this process by calculating
Khi
dti = (14)
c(i) + 2v(i)
And then taking the minimum of all dti . This is only approximately correct, but it is sufficient
for this assignment.
1.8 Updating h
If we wish to update hi for each particle, we need to create a criteria for these updates. The simplest
thing to do is to track the total number of neighbors of a particle.
3
2 The SPH simulation steps
1. Initialize all the particles with positions, velocities, masses, h and internal energies
2. For all of the particles, find the interaction list of all particles that are within a distance of
hi + max(hj ). If all the h’s are equal, we can assume that this will be a distance of 2h.
3. Using use the interaction list for each particle and equations (4) and (1), find the density at
each particle.
4. Using the particle’s density ρ and it’s internal energy u, use the equation of state (9) to find
its pressure P .
5. At the same time, calculate the speed of sound for each particle using equation (10).
6. For each particle, use the following steps to calculate the changes in velocity and internal energy
(a) For each particle on the interaction list, calculate Πij using equations (7) and (8).
(b) Calculate the total d~v )i /dt for each particle using equations (5) and (2).
(c) Calculate the total dui /dt for each particle using equations (6) and (6).
7. Using equation (14), find the stepsize
8. Update the positions and velocities using a leap frog method (11.
9. Update the time using ti+1 = ti + dt
10. Update the internal energy using a forward Euler method (12).
11. IF we are updating the h values for each timestep, update the values of hi for each particle.
12. Output data if needed
13. Repeat steps (2) to (12) until the the code reaches the final time.
3 SPH Assignment
• Create an SPH code that will simulate a one dimensional shock tube
• Initialize the shock tube with n particles set up with positions between zero and 1.
• We will set the densities by setting the mass of the particles
• The velocities will initially be set to zero for all particles
• Internal energies will be initially set for all particles
• Set the initial values of hi to be 5 times the inter-particle spacing. Let all the particles between
[0, 0.05] and between [0.95, 1] to be boundary particles who’s properties are not updated.
• The problem we want to run is detailed in the next section.
4
sph - zalezak shock tube t=0.20
1.1
sph
1 exact
0.9
0.8
0.7
0.6
density
0.5
0.4
0.3
0.2
0.1
0
0 0.2 0.4 0.6 0.8 1
position [!h]
Figure 1: SPH Shock Tube Test - Density. The analytic and numerical solution for the “zalezak”
shock tube are shown at t=0.2. In this tube, ρleft = 1.0, Pleft = 1.0, and Vleft = 0.0 while ρright = 0.125,
Pright = 0.10, and Vleft = 0.0. There are 256 particles in the run.
5
sph - zalezak shock tube t=0.20
1.1
sph
1 exact
0.9
0.8
0.7
pressure
0.6
0.5
0.4
0.3
0.2
0.1
0
0 0.2 0.4 0.6 0.8 1
position [!h]
Figure 2: SPH Shock Tube Test - Pressure. The analytic and numerical solution for the “zalezak”
shock tube are shown at t=0.2. In this tube, ρleft = 1.0, Pleft = 1.0, and Vleft = 0.0 while ρright = 0.125,
Pright = 0.10, and Vleft = 0.0. There are 256 particles in the run.
0.8
0.7
0.6
0.5
velocity
0.4
0.3
0.2
0.1
-0.1
0 0.2 0.4 0.6 0.8 1
position [!h]
Figure 3: SPH Shock Tube Test - Velocity. The analytic and numerical solution for the “zalezak”
shock tube are shown at t=0.2. In this tube, ρleft = 1.0, Pleft = 1.0, and Vleft = 0.0 while ρright = 0.125,
Pright = 0.10, and Vleft = 0.0. There are 256 particles in the run.
6
sph - zalezak shock tube t=0.20
3
sph
exact
2.8
2.6
thermal energy
2.4
2.2
1.8
1.6
0 0.2 0.4 0.6 0.8 1
position [!h]
Figure 4: SPH Shock Tube Test - Thermal Energy. The analytic and numerical solution for the
“zalezak” shock tube are shown at t=0.2. In this tube, ρleft = 1.0, Pleft = 1.0, and Vleft = 0.0 while
ρright = 0.125, Pright = 0.10, and Vleft = 0.0. There are 256 particles in the run.
0.01
0.009
0.008
h
0.007
0.006
0.005
0.004
0 0.2 0.4 0.6 0.8 1
position [!h]
Figure 5: SPH Shock Tube Test - h. The numerical solution kernel size h is shown for the “zalezak”
shock tube t=0.2. In this tube, ρleft = 1.0, Pleft = 1.0, and Vleft = 0.0 while ρright = 0.125, Pright = 0.10,
and Vleft = 0.0. There are 256 particles in the run.