Sie sind auf Seite 1von 7

CSI 761- Fall 2008 - SPH Guide

November 10, 2008

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 The Euler Equations


1.2.1 Summation Density
N
X
ρi = mj Wij (4)
j=1

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

1.3 Artificial Viscosity and the Equation of State


1.3.1 Artificial Viscosity

−αcij µij +βµ2ij

, if (~vi − ~vj ) · (~ri −~rj ) > 0
Πij =  ρij (7)
0, otherwise
where
hij (~vi − ~vj ) · (~ri − ~rj )
µij = (8)
|~ri − ~rj |2 + ǫh2ij
and cij , ρij , and hij are respectively the average sound speed, density and smoothing length of
particles i and j. Specifically,

hi + hj
hij =
2

ρi + ρj
rhoij =
2

ci + cj
cij =
2
For the constants, we typically use

α=1
β=2
ǫ = 0.1

1.3.2 Equation of State

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

1.5 Forward Euler

dui
ui+1 = ui + dt (12)
dt

1.6 Timestep Size - the Courant Condition

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.7 Simple Boundary Conditions


The easiest way to make boundary conditions is to set a few particles up that do not have velocity
updates. We do not need to update any of the properties of these particle. However, we must include
them in the summation for particles at the end of the domain.

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.

3.1 SPH Shock Tube


The basic idea of a Riemann shock tubes is to see how well a code or method can integrate the Euler
equations across an initial discontintinuity. Generally, this is done as a one-dimensional test. One
of the nice features about this problem is there is a strong theoretical background and analytical
solutions for the cases.
In the Riemann problem, the densities, pressures, and velocities of the gas are defined on left and
right side of a barrier. At t=0, the barrier is removed and the gas is allowed to move through the
system.
For most “standard” Riemann test problems, the velocity on both sides is set to zero. This
reduced the problem to a ratio of the pressures and densities on the left and right sides.

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.

sph - zalezak shock tube t=0.20


1
sph
0.9 exact

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.

sph - zalezak shock tube t=0.20


0.011

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.

Das könnte Ihnen auch gefallen