Algorithms For Uniform Particle Initialization in Domains
Algorithms For Uniform Particle Initialization in Domains
a
Department of Aerospace Engineering, Indian Institute of Technology Bombay, Powai,
Mumbai 400076
Abstract
Accurate mesh-free simulation of fluid flows involving complex boundaries
requires that the boundaries be captured accurately in terms of particles.
In the context of incompressible/weakly-compressible fluid flow, the SPH
method is more accurate when the particle distribution is uniform. Hence,
for the time accurate simulation of flow in the presence of complex bound-
aries, one must have both an accurate boundary discretization as well as a
uniform distribution of particles to initialize the simulation. This process
of obtaining an initial uniform distribution of particles is called “particle
packing”. In this paper, various particle packing algorithms present in the
literature are implemented and compared. An improved SPH-based algo-
rithm is proposed which produces uniform particle distributions of both the
fluid and solid domains in two and three dimensions. Some challenging ge-
ometries are constructed to demonstrate the accuracy of the new algorithm.
The implementation of the algorithm is open source and the manuscript is
fully reproducible.
Keywords: Particle packing, complex geometry, pre-processing, smoothed
particle hydrodynamics
Program summary
Program title: SPHGeom
∗
Corresponding author
Email addresses: [email protected] (Pawan Negi),
[email protected] (Prabhu Ramachandran)
1. Introduction
Smoothed Particle Hydrodynamics (SPH) is a mesh-free numerical method
used for the simulation of continuum mechanics problems. It was first pro-
posed by Gingold and Monaghan [1] and Lucy [2]. Unlike mesh-based meth-
ods, the SPH method discretizes the domain into particles that carry physical
properties. The SPH method has been employed to study a wide variety of
problems. A comprehensive list of schemes can be found in Liu and Liu [3],
Violeau [4], and Ye et al. [5].
The SPH method approximates functions and derivatives by using a con-
volution with a smooth kernel function
Z
f (x) = f (x̃)W (x − x̃, h)dx̃ + O(h2 ), (1)
Ω
2
is discretized into particles carrying the required properties. This integral is
then discretized as
X mj
f (x) ≈ f (xj )W (x − xj , h) , (2)
j
ρ j
m
where xj is the position of the j th particle and Vj = ρjj is the volume asso-
ciated with the particle with mass mj and density ρj . This approximation
is most accurate when the underlying particle distribution is uniform [7, 8].
For example, the particles could be placed on a uniform Cartesian mesh with
constant spacing. However, the SPH method is Lagrangian and the parti-
cles move with the local velocity field. Many recent developments in SPH
involve the use of Particle Shifting Techniques (PST)[9, 10, 11] which shift
the particles towards a uniform distribution. Thus, it is important to have a
uniform distribution of particles.
Consider the case of the two-dimensional flow past a simple non-Cartesian
solid shape like a circular cylinder. The fluid flow occurs outside of the
cylinder. In the SPH method, the fluid is discretized using (fluid) particles.
The circular cylinder is also discretized with (solid) particles. These solid
particles are not merely on the surface of the cylinder but also on its interior
for accuracy of the method. When the simulation starts, we require a uniform
distribution of both fluid and solid particles which capture the geometry
accurately. Clearly, one cannot use a Cartesian mesh of particles and still
describe the cylinder surface accurately.
We must therefore define the term “uniform” distribution of particles in
the context of the SPH method. This has been discussed by Colagrossi et al.
[12] and Litvinov et al. [13]. They explain that a non-uniform distribution
would generate a spurious force among the particles leading to a “resettle-
ment” of their spatial distribution.
As discussed in [12], for particles having the same mass and density, we
can estimate the non-uniformity using either,
X mj
Γi = W (xi − xj , h) , (3)
j
ρj
3
where ∇W is the gradient of the kernel function with respect to xi . If Γi = 1
or ∇Γi = 0, then the particle distribution may be considered uniform. For
example, for particles placed on an infinite Cartesian mesh Γi ≈ 1, ∇Γi ≈ 0
for all particles. In this paper, particle distributions that satisfy this re-
quirement are referred to as uniform, homogeneous, or regular distributions
interchangeably. The term “particle packing” is used in the literature as the
process of generating such a homogeneous distribution of particles.
There are many higher-order SPH schemes like [14, 15, 16, 17] which em-
ploy corrected kernel functions such that Γi = 1 and ∇Γi = 0 by construction
regardless of the underlying particle distribution. In such cases it may be
argued that there is no requirement for a uniform/homogeneous distribution
of particles. However, these methods do not always ensure the conservation
of linear and angular momentum. On the other hand, the uncorrected ker-
nels when used with a suitable formulation do conserve linear and angular
momentum as discussed in [17]. Therefore, even with a higher-order SPH
method, it is usually desirable to have a reasonably uniform distribution of
fluid and solid particles to improve conservation [8].
Many problems involving complex geometries have been solved in the SPH
literature. For example, the flow around blades of mixing devices [18] and
industrial automotive problems [19]. In order to simulate such problems, the
initial particle distribution must capture important features of the geometry
accurately while maintaining a uniform spatial distribution.
There have been some earlier attempts to do this in the context of SPH.
Colagrossi et al. [12] devised a particle packing algorithm which uses the
kernel gradient to distribute the particles in two-dimensions around a solid
body such that the simulation starts smoothly. In order to generate the two-
dimensional solid, the method proposed by Marrone et al. [20] was employed.
The method constructs solid boundaries using piecewise linear curves (PLC).
These are translated along the normal and discretized into equispaced parti-
cles according to the desired particle spacing, ∆s, up to the required number
of layers. Xiao et al. [21] proposed an algorithm to divide the two-dimensional
domain of interest into square-shaped sub-domains. The sub-domains having
an area equal to the desired area (∆s2 ) are directly converted to particles.
Other particles near the boundary are given partial mass iteratively. None
of these approaches consider three-dimensional geometries. Domı́nguez et al.
[22] constructs geometries by clipping the grid with the boundary of the ge-
ometry, and this necessitates using a much higher resolution to capture the
features better. Akinci et al. [23] proposed a scheme to place particles over
4
triangles of length greater then the particle spacing. This approach provides
a good density distribution and has been employed to simulate flow for graph-
ics applications in three dimensions. In a different context, Jiang et al. [24]
used the SPH method for packing particles in order to sample blue noise.
This method focuses on packing the particles inside and on the surface of
the body. The method does not generate any particles outside the body. In
order to obtain a uniform particle distribution, a kernel gradient along with
a cohesive force proposed by Akinci et al. [23] is used. It balances the extra
force on the particles near the surface.
In this paper, the methods proposed by Colagrossi et al. [12] and Jiang
et al. [24] are implemented. The method of Jiang et al. [24] does not by
default generate particles in the exterior of the boundary. A modification
of the algorithm is proposed so that it generates the desired particles in
the interior and exterior. A novel SPH-based method to construct two and
three-dimensional geometries, at a given resolution, keeping the features of
the geometry as detailed possible, is proposed. The following nomenclature
is used henceforth to refer to the methods implemented:
• Coupled : The interior (solid) and exterior (fluid) are created separately
using the method proposed by Jiang et al. [24]. Once these converge,
the interior and exterior interact using the method of [12].
• Hybrid : The proposed new method which combines features from the
above two approaches.
The hybrid method uses the kernel gradient to move the particles as
proposed by Colagrossi et al. [12] along with a strong repulsion force, which
comes into effect only when two particles are closer than the particle spacing.
The particles on the boundary are allowed to move over the surface only as
done in [24]. Particles that are not on the boundary, are allowed to move in
and out of the boundary surface. Particles are projected on the boundary
which introduces disorder causing the other particles to adjust accordingly.
It is important to note that the proposed algorithm can be applied in the
context of any general-purpose SPH framework. This makes the approach
5
relatively easy to integrate into SPH codes. The present implementation
uses the open-source PySPH framework [25, 26]. The particle distributions
generated using the above methods are compared for different geometries.
The accuracy of the proposed method is demonstrated by performing an
SPH function and derivative approximation for a known function.
The paper is divided into four sections. The next section briefly discusses
the SPH method. The section 3 describes the algorithms implemented in
detail. In section 4, different geometries are constructed using the algorithms
implemented. In the interest of reproducibility, the implementation of the
algorithms is open source and all the results are fully reproducible.
where Wij = W (xi −xj , h), mj is the mass of ith particle and N is the number
of neighbors in the kernel support. We can see that if all particles have the
same density ρi = 1, then, eq. (6) becomes the same as eq. (3) and eq. (4).
We therefore assume that all particles have a unit density henceforth.
For a uniform distribution of particles, the value of Γi = 1 and ∇Γi = 0
accurate to the order O(h2 ). Furthermore, as discussed in Kiara et al. [8], the
kernel and its gradient can be corrected such that the condition in eq. (3) and
eq. (4) are satisfied even for a non-uniform distribution of particles. However,
using a corrected kernel introduces issues in momentum conservation when
6
the particles are non-uniform. Therefore, it is important to have a uniform
particle distribution.
In the weakly compressible SPH scheme, the dynamics of the fluid flow
is governed by
dρ
= −ρ∇ · u, (7)
dt
du ∇p
=− + ν∇2 u, (8)
dt ρ
p = p(ρ, ρ0 , c0 ) (9)
7
Free particle
Frozen particle
Boundary surface
Boundary node
Boundary particle
Figure 1: Schematic of the initial distribution of particles and the different kinds of par-
ticles.
• Boundary node: These are points that discretize the boundary surface,
they also store the local surface normals of the boundary surface. These
are depicted as black dashes. We note that these are called nodes
because they do not exert any forces on particles and only serve to
provide information on the position and orientation of the boundary
surface.
8
During the algorithm, free particles (blue) may be converted to boundary
particles (red) if they are close to the boundary surface. Once the proposed
algorithm completes, the red boundary particles must conform to the bound-
ary represented by the dashed black line. The blue particles inside the dashed
boundary will be considered as solid (dummy) particles and those outside as
fluid particles.
Initialize boundary
nodes
Compute acceleration
Move particles
Yes
Project free particles
on boundary surface
Initial
projection
Any particles No
projected?
No
Converged?
Yes
Figure 2: Flowchart of the particle packing algorithm. The box outlined in dashed red
lines is the initial projection phase.
The overall flow of the algorithm is shown in fig. 2. The algorithm re-
quires two inputs, the geometry information, and the desired particle spacing.
These are to be provided by the user. Given the geometry surface, we first
estimate the number of particles that should lie on this surface, Ns , using
9
the desired spacing of particles and either the length in 2D or the surface
area in 3D.
Initially, the frozen particles are created on the periphery of the domain
as shown in fig. 1 and placed on a rectangular lattice. Free particles are then
placed inside this on a regular lattice. At this stage, no boundary particles
are identified. The boundary nodes are initialized using the information
provided by the user.
The acceleration on the free particles and any boundary particles (that
are identified later) is computed using a local density gradient, and a repul-
sive force. This corresponds to the green block in fig. 2. The particles are
moved using the computed accelerations. As the free particles move, they
are converted to boundary particles if they are close enough to the bound-
ary surface. They are then projected to the nearest point on the boundary
surface. These boundary particles are constrained to move only along the
boundary surface. The free particles are iteratively converted to boundary
particles until no free particle is sufficiently close to the boundary.
During the initial projection phase (denoted by the red dashed line in
the fig. 2), the particles are regularly projected onto the boundary surface.
This is done until the number of boundary particles have reached Ns and
remains there for a few consecutive iterations. The algorithm then proceeds
to settle the particles into a uniform distribution until the displacement of
the particles is less than a user-defined tolerance. This is denoted as the
“Converged” block in fig. 2. Once convergence is attained, the boundary and
free particles inside and outside the surface are packed as desired. Since the
boundary surface is known, free particles can be easily identified as solid and
fluid particles.
This packed collection of free and boundary particles may be placed into a
larger regular mesh of particles for a simulation. For example, see fig. 3 where
the dashed region is where the packed particles could be placed. The exterior
of this region (shown in green) can be represented as a regular mesh of the
same spacing. This approach is convenient to use in the context of fluid flow
past solid bodies as done for internal flows [30] and free surface flows [31]. The
algorithm described above is explained in detail in the subsequent sections.
10
Inlet Outlet
Figure 3: The preprocessed patch (dashed) of particles placed in the appropriate location
of a typical simulation. The blue particles denote the free particles identified as fluid
particles, the red represents the solid particles identified by the packing process. The
green particles are generated from a fixed mesh of points.
by λ, and points on the curve may be specified as x = C(λ) and λ ∈ [0, 1].
This curve is discretized such that xi = C(λi ). The spacing between points
must be such that |xi+1 − xi ))| < ∆s. The boundary node coordinates are
initialized using these points. The outward normals nx , ny for any node i are
calculated using
yi+1 − yi yi − yi−1
nx,i = 0.5 +
di+1,i di,i−1
(10)
xi+1 − xi xi − xi−1
ny,i = −0.5 +
di+1,i di,i−1
where di,j is the length of the segment joining node at (xi , yi ) and (xj , yj ).
The resulting normal is then normalized. The eq. (10) ensures that sharp
corners of the curve have smooth normals. For a three-dimensional case, a
triangulation of the surface with outward normals is necessary. The centroid
of each triangle and its normal is used to initialize the boundary nodes.
In SPH, the actual boundary surface is exactly in between solid and fluid
particles. Thus, both in two and three dimensions, given a particle spacing
of ∆s, the boundary nodes are shifted by ∆s/2 inside the actual boundary to
11
correctly implement the solid boundary conditions as discussed in Marrone
et al. [20]. In order to move the nodes inwards, the following translation is
performed on each boundary node given by,
∆s
x=x− n̂, (11)
2
where, x is the position of the node and n̂ is its unit normal pointing out-
wards. It must be noted that this is optional and one can provide a pre-shifted
surface and avoid eq. (11).
i+4 i+4
i+3 i+3
∆s/2
i+2
Corner-node i+2
i+4 i+4
i+3
Figure 4: Shifting of the boundary near a sharp edged boundary. The boundary nodes
are depicted in red with normals. On the left is the boundary surface after the initial
shifting shown as black dashed lines. On the right is the final geometry after removal of
the intersecting edges which are shown as dashed red lines. The annular blue free particle
is the candidate to be placed on the corner and held fixed.
Care must be taken when there are sharp changes in the features of the
geometry. Consider an airfoil trailing edge in fig. 4 shown as a black line.
These sharp corners are marked as “corner nodes”, and in this case, it is the
ith node. When the nodes on this surface are shifted, the boundary surface
tends to self-intersect itself. This is shown by the red nodes connected using
a black dashed line. In order to remove the intersection of the boundary
surface near the corner node, the points i − 3 to i − 1 are replaced by the
points on the line joining i−4 and i with equal spacing shown by black points.
Similarly the points i + 1 to i + 3 are also replaced to lie along the line joining
points i and i + 4. This results in a non-intersecting surface as shown by the
red dashed line in the right side of fig. 4. Once the intersection is resolved,
the nearest free particle near the corner node (annular blue particle) is placed
12
on it and converted to a fixed boundary particle. The position of these fixed
boundary particles do not change in the entire simulation.
In the case of a three-dimensional object, one has to make sure that the
surface does not intersect after applying eq. (11) or use a pre-shifted surface
as an input.
where Vi = mρii is the volume of the ith particle, ρi is the density, Wij is the
kernel function chosen for the SPH discretization. The summation is over
all the neighbors of ith particle. Since all SPH kernels satisfy eq. (5), any
suitable SPH kernel discussed in section 2 can be employed. In this paper,
the quintic spline kernel is used given by,
σ (3 − q)5 − 6(2 − q)5 + 15(1 − q)5
for 0 ≤ q ≤ 1,
5 5
σ (3 − q) − 6(2 − q) for 1 < q ≤ 2,
W (q) = 5 (14)
σ (3 − q) for 2 < q ≤ 3,
0 for q > 3,
13
similar to the gradient of the Lennard Jones potential (LJP) is used. The
new repulsion force potential (φRF ) is given by
2
c c
φRF = 12 kr − (15)
r3 r2
where eij = xij /rij . Note that the acceleration is continuous at rij = ∆s/2.
We find that using a value of α = 0.95 works well for the algorithm.
It is clear from eq. (16) that this force is active only when particles come
closer than the desired particle spacing. This prevents particle pairing, which
may happen due to the use of some kernels like cubic spline for large time
steps [32]. In fig. 5, the comparison between the force due to LJP and RF is
shown. The LJP repulsion force increases rapidly compared to our suggested
repulsion force. This allows us to use a larger time step during integration.
Moreover, unlike the force due to LJP, the new force does not introduce
inter-particle attraction.
As discussed in [12], for stability, a damping force is used to reduce the
energy of the system. The acceleration due to damping for the ith particle is
given by
ad,i = −ζui (17)
where ζ is the damping constant and ui is the velocity of the ith . The value
of the damping constant ζ is discussed in section 3.1.6. Thus, the equation
governing the dynamics of the system is given by
du ∇pb
=− − ∇φRF − ζu (18)
dt ρ
The above equation can be converted into SPH form using eqs. (13), (16)
and (17). It must be noted that the combination of background pressure force
14
Figure 5: Force due to LJ potential and the gradient of eq. (15) as a function of distance,
r and α = 1.
and the repulsion force produces repulsion only when particles are disordered.
This can also be accomplished by using the particle shifting techniques (PST)
first proposed by [10].
On using eq. (18) the velocities and new positions are calculated using a
semi-implicit Euler integration given by,
ui (t + ∆t) = ui (t) + ∆tai (t)
(19)
ri (t + ∆t) = ri (t) + ∆t ui (t + ∆t)
In the case of boundary particles, the velocities are corrected to constrain
them to move along the surface (discussed in section 3.1.4). It should be
noted that the packing algorithm only ensures that particle distributions
are regular and therefore using a higher order integrator would not promise
better results.
15
The stability of the method in a two and three-dimensional domain for
finite perturbation under the action of forces described above is studied. A
domain of size 1 unit along each coordinate direction is considered. Particles
are placed with a spacing of ∆s = 0.05. Fixed particles are placed outside
this unit box suitably. The value of pb , ζ, kr and ∆t are set as discussed in
section 3.1.6. A single particle close to the center is perturbed by ∆s/2 in
each direction. The particles are moved using eq. (18) and eq. (19) for 15000
iterations. The stability of the following initial distribution of particles is
considered:
16
lattices settle into an equilibrium configuration with a much larger density
difference. Therefore the rectangular lattice in 3D is an unstable equilibrium.
In contrast, the hexagonal packing in 3D is in a stable equilibrium.
This behavior in 3D can be understood from the total potential energy of
the particles. It can bePseen that eq. (3) for Γi is the potential energy of the
ith particle and hence i Γi is the total potential energy of the system. The
acceleration of a particle given in eq. (12) is the negative of the gradient of
its potential energy. We have numerically found that a small perturbation
of a particle at a given site reduces the total potential energy in the case
of the rectangular lattice whereas, the same perturbation results in higher
potential energy in the case of the hexagonal packing. This suggests that the
hexagonal packing is stable in 3D unlike the rectangular lattice. A careful
analysis on the stability is outside the scope of the present work. Due to the
stability of hexagonal packing shown in fig. 6b, it is used in all our test cases.
(a) 2D (b) 3D
17
Figure 8: Error in ∇Γi for domain with unit radius cylinder with different projection
frequency.
18
Algorithm 1: Pseudo-code for free particle projection.
Input: proj_freq, ds=∆s
Result: List of free particles to be projected
iteration = 0;
empty_count = 0;
while not converged do
...;
if iteration % proj_freq == 0 then
if empty_count < 4 then
p_list = FindParticlesNearBoundary(maxdist=0.5*ds);
if len(p_list) > 0 then
ConvertParticles();
empty_count = 0;
else
empty_count++;
end
else
p_list = FindParticlesNearBoundary(maxdist=0.65*ds);
ConvertParticles();
end
ProjectToBoundary();
...;
end
iteration++;
end
find the nearest boundary node uses the existing neighbors generated when
computing the accelerations discussed in section 3.1.2.
The empty_count variable stores the number of consecutive passes
for which the p_list was empty. The free particles having a distance
to the boundary node less than 0.5∆s are converted to boundary par-
ticles in ConvertParticles and projected to the boundary surface in
ProjectToBoundary. However, if the empty_count exceeds 3, the distance
threshold is increased to 0.65∆s. This threshold is increased to handle the
19
corner cases where free particle are just outside 0.5∆s distance1 . This iter-
ative conversion of free particles to boundary particles is necessary in order
to capture the surface accurately.
2 1
boundary node
3 ~u
4 boundary particle
5
Figure 9: Motion of boundary particle along the geometry.
1
This value was found based on numerical experiments. Too small a value like 0.55∆s
produces poor results in coarse resolutions and too large a value (0.75∆s) produced poor
distributions with finer resolutions.
20
node, J is determined by
xm+1
p = xm m+1
p + (up · x̂m m
r )x̂r ∆t, (22)
where m is the time step.
21
In order to ensure stability, the damping constant has a form similar to
the one suggested by Colagrossi et al. [12] given by ζ = Cζ /∆s, where Cζ is
set in the range 0.2 − 0.5 resulting in an underdamped system.
The time step, ∆t is set as in Adami et al. [11] given by,
h
∆tpb = 0.1
p
s b
h (25)
∆tζ = 0.1
ζui
∆t = min(∆tpb , ∆tζ )
where ui is the velocity magnitude of the ith particle. We note that we have
used a pb = 1 for all our simulations.
3.1.8. Implementation
The algorithm is implemented using the open-source package PySPH [25].
The pseudo-code of the proposed hybrid method is shown in algorithm 2. The
22
nearest neighbor particle search (NNPS) algorithm implemented in PySPH
[25] is not a part of the current algorithm.
The algorithm first reads the input using ReadInput and initialize the
particles in CreateParticles as discussed in section 3.1.1. The constants
and time step are set in SetConstantAndTimeStep. The first iteration starts
with UpdateNeighbors where the neighbor list for every particle is created.
This is followed by acceleration computation in ComputeAccelerations and
integration in IntegrateParticles as discussed in section 3.1.2 and sec-
tion 3.1.4. Nearest free particles are converted and projected to the surface in
ProjectParticles as discussed in section 3.1.3. This procedure updates the
empty_count variable. The iterations continues until convergence condition is
true in CheckConvergence as discussed in section 3.1.5. Finally, the particles
are separated into internal and external particles in SeparateParticles as
discussed in section 3.1.7.
23
3.1.9. Obtaining faster convergence
The algorithm discussed above is the basic form, which adds particles
slowly to the boundary. In case when the boundary surface is smooth and
does not have sharp changes (as discussed in section 3.1.1), the following
approaches can be taken to speed up the packing process:
• Using surface point prediction: When the boundary is smooth one may
project 0.9Ns immediately at the start. This perturbs the distribution
of the particles significantly. If required more particles are projected to
the boundary while settling the system to an equilibrium.
• Filter layers near the boundary surface: Conforming particles to the
boundary surface requires that only some of the particles be moved.
Thus, one could filter the free particles near the boundary surface and
freeze the other particles.
• Reduce projection frequency: One can reduce it slowly once the initial
projection is complete.
• Reduce the convergence tolerance: One can potentially reduce the toler-
ance to increase the performance of the algorithm, although this would
reduce the quality of the distribution of particles.
Doing these can potentially reduce the computations by up to a factor of
two. However, we have not performed any of these in the results presented
here.
24
et al. [12] is used to pack particles around the fixed solid particles. In order
to initialize the particle position, a grid of evenly distributed particles is con-
sidered and only the particles outside (defined by the direction of normal)
the boundary surface represented by the PLC are retained. The particles
are packed using the number density gradient. It must be noted that since
only the number density gradient is used as a repulsion force amongst the
particles, they are prone to clumping [33, 34]. The particles are subjected to
a damping force to dissipate the energy of the system. Hence the force on
any particle is governed by
du ∇pb
=− − ζu, (26)
dt ρ
The value of pb and ζ is set directly as described in section 3.1.6. The same
SPH discretization is used as done in equation eq. (13) and eq. (17). The
convergence criteria remain the same as discussed in section 3.1.5.
25
Then, accelerations are computed in ComputeAccelerations using eq. (26)
and integrated in IntegrateParticles using eq. (19). The iteration continues
until the criteria described in section 3.1.5 is satisfied in CheckConvergence.
26
If one were to only use eq. (27), it would result in more number of par-
ticles pushed towards the boundary. In order to counteract the force on the
particles near the boundary, Jiang et al. [24] used a cohesion force proposed
by Akinci et al. [35]. The acceleration due to this force in SPH form is given
by X
ac,i = −mi γ mj kij Cij n̂ij (28)
j
where kij = 2ρo /(ρi + ρj ), n̂ij = xij /rij and Cij is the spline kernel in [35]
given by
(1 − q)3 q 3 0.5 < q < 1
32 3 3 1
C(q) = 2(1 − q) q − 64
0 < q < 0.5 (29)
πhd
0 otherwise
Domain 1 External
Domain 2
boundary boundary
Domain 2
Domain 1 Interface
boundary
Figure 10: Schematic for the coupled packing algorithm. The external region is marked
as domain 2 and the internal region is marked as domain 1.
Jiang et al. [24] have not specified a way to choose the value of the con-
stants in eq. (27) and eq. (28). The values of γ = 20, pb = 10 and h = ∆s
are heuristically chosen for all the simulations.
It must be noted that there is no exterior defined in [24]. In this work,
the exterior is also packed in the same manner as the interior by moving the
boundary surface by ∆s/2 and −∆s/2 for exterior and interior respectively.
In fig. 10, the interior domain (domain 1) is enclosed within a thick dashed
line and the exterior is within a thin dashed line (domain 2). Each domain is
represented with a different pattern. Domain 2 having an external boundary
has frozen particles outside it. The solid line represents the boundary surface.
27
Algorithm 5: Coupled particle packing algorithm.
Result: Coordinates of solids and fluids
ReadInput();
DivideDomain();
CreateParticles();
SetConstantAndTimeStep();
Algorithm4(domain1, 5000);
Algorithm4(domain2, 5000);
iteration = 0;
converged = False;
while not converged do
UpdateNeighbors(domain1 + domain2);
ComputeAccelerations();
IntegrateParticles();
converged = CheckConvergence();
iteration++;
end
SeparateParticles();
2
The predetermined iterations is chosen as 5000 currently based on the test cases
considered.
28
all particles are sorted as either interior or exterior and have an interface
which they cannot cross i.e. the dashed lines.
In the second pass, when the projection is complete, the particles on
the interior surface i.e. the thick dashed line are constrained to move
along it. All other particles are allowed to freely move using eq. (27) in
ComputeAccelerations and IntegrateParticles. The iteration continues un-
til the convergence criteria in CheckConvergence as discussed in section 3.1.5
is satisfied. The presence of exterior particles eliminates the need for the co-
hesion force and is not added once domains 1 and 2 start interacting. Using
this approach, a uniform distribution is obtained both inside and outside the
surface. It is noted that the original implementation was used to sample blue
noise and does not require external particles.
The proposed algorithms are implemented in the open-source SPH frame-
work, PySPH [25]. The present implementation is open source and freely
available with this manuscript at https://gitlab.com/pypr/sph_geom. All
the results shown in the next section are fully reproducible using a simple
automation framework [36].
29
Figure 11: Solid (Red) and fluid (Blue) particles for a circular cylinder for ∆s = 0.1.
Figure 12: Density distribution of the packed particles for the circular cylinder geometry
for ∆s = 0.1.
30
(a) Function (b) Derivative
Figure 13: L2 error for SPH approximation of function and its derivative for the circular
cylinder geometry.
coupled method, a large number of particles near the wall surface is seen.
The standard method seems to have uniform particles owing to its construc-
tion. In order to investigate this further, the density distribution is plotted as
shown in fig. 12. The density distribution is obtained using the well-known
summation density. Clearly, the coupled method shows high density near
the surface and the standard method shows a low density on the solid since
∆s particle distance is assumed over a curved surface. The total density
variation is 8%, 16%, and 2% for the standard, coupled and hybrid meth-
ods respectively. Thus, it is clear that the proposed hybrid method shows
excellent distribution with a maximum variation of 2%.
The improvement is studied quantitatively by interpolating a C∞ function
over the packed particles given by
31
and X mj
< fx (x) >= f (xj )Wij,x (32)
j
ρj
respectively. The L2 error in the approximation is evaluated using
qP
2
j (f (x) − fo (x))
L2 (f − fo ) = (33)
N
where, fo is the SPH function approximation on a regular mesh of points.
The value of the function is set as per the position of each particle as f (xi ).
This is then interpolated onto a regular mesh using eqs. (31) and (32). The
same is done for the regular points themselves to obtain the reference fo
value at each point. The value of h is varied in order to get convergence. A
value of h/∆s = 1.0 is taken for ∆s = 0.1 and linearly varied to h/∆s = 1.5
for ∆s = 0.02. The quintic spline kernel is used for the interpolation. When
comparing the derivatives, only the x derivative is considered. In fig. 13a and
fig. 13b, L2 (f − fo ) and L2 (f 0 − fo0 ) are shown. In these plots the errors near
the center of the cylinder are not evaluated as they do not affect the flow
and the standard method performs poorly in this region. This change allows
for a fair comparison. Hence, the L2 norm is evaluated only over the points
where r > 0.45 D. It is clear that the hybrid method shows a significant
order of magnitude improvement compared to both coupled and standard
methods. The coupled method is slightly better than the standard method.
The standard method shows large error due to the way in which the surface
is represented.
32
Figure 14: Solids (Red) and fluids (Blue) for the zig-zag wall for ∆s = 0.05.
Figure 15: Density distribution for the zig-zag wall for ∆s = 0.05.
In fig. 14, the solid and fluid particles packed with ∆s = 0.05 using
different algorithms are shown. It is difficult to conclude which of these is
better. However on looking at the density distribution computed using the
summation density as shown in fig. 15 one can clearly see that the proposed
method has much less deviation from the desired density. In the case of
the coupled method, higher density is observed at the concave corner. This
occurs since the particles from both sides push towards the interface at the
first pass of the coupled algorithm as discussed in section 3.3. The standard
method shows an uneven variation of density near the sharp edges which is
not desirable. The total density variation is 10%, 30% and 3% for standard,
coupled and hybrid methods respectively. It clearly shows that the hybrid
33
(a) Function Approximation (b) Derivative Approximation
Figure 16: L2 error for SPH approximation of function and its derivative for the zig-zag
wall.
34
Figure 17: Density distribution at different resolutions for an arbitrary shaped object.
35
Tolerance Iterations L∞ (ρi )
2.5e-05 19641 0.011
5.0e-05 6291 0.019
1.0e-04 1191 0.028
Table 1: The table shows the effect of the change in tolerance for convergence on the
number of iterations and the L∞ error in the density.
Figure 18: The density distribution for a symmetric airfoil with particle spacing, ∆s = 0.02
and convergence tolerance, = 2.5e−5 .
36
(a) Hybrid (b) Coupled
Figure 19: Density distribution on the surface of the ellipsoid for ∆s = 0.1.
Figure 20: L2 error for SPH approximation of function and its derivative for the ellipsoid.
lower range of the scale. This is due to the fact that unlike the hybrid method,
the coupled method does not project the required number of particles on the
surface. In order to perform a quantitative analysis, again the comparison of
the function and derivative approximation used earlier is adopted. In fig. 20a
and fig. 20b, L2 error in SPH approximation of function and its derivative is
plotted respectively. As can be seen, the proposed method produces much
37
lower errors at lower resolutions.
Figure 21: Different views showing particles (colored with density values) over the Stanford
bunny.
38
5. Conclusions
This paper proposes an improved particle packing algorithm for the sim-
ulation of flows involving complex geometries in two and three dimensions.
Three different methods for packing particles around an arbitrary shaped ob-
ject are implemented and compared. The standard method which is proposed
by Colagrossi et al. [12] along with the solid object construction proposed
by Marrone et al. [20]. A modified version of that proposed by Jiang et al.
[24] which handles both the interior and exterior of the body. A new method
that combines the best features of these methods is proposed. The proposed
method provides an excellent density distribution as a result of evenly dis-
tributed particles. The method is applicable to both 2D and 3D domains.
Unlike the coupled method, no estimation of particles inside and outside is
required. Several benchmark cases are shown which highlight the accuracy
of the proposed algorithm in two and three dimensions. An open-source
implementation of the manuscript is provided and the manuscript is fully
reproducible.
The SPH method is being applied to a wide variety of problem domains
involving complex geometries. While mesh-free particle methods do not re-
quire a mesh, one must still capture the boundaries accurately. However,
there are not many tools to create good quality initial particle distributions.
This is necessary for accurate simulation of incompressible fluid flows with
the SPH. The proposed method is largely automatic and offers researchers
the ability to easily discretize complex geometries using particles in two and
three dimensions. Since the proposed algorithm is based on the SPH, it
should be easy to incorporate into an SPH solver. The code is also open
source and hence researchers could also choose to use our implementation.
In the future, we would like to make it easier to use and integrate with
the main PySPH package. We have only demonstrated our implementation
on the CPU. However, PySPH supports execution on a GPU and we propose
to make the necessary modifications for efficient execution on the GPU. The
method currently works best for a fixed resolution. In the future it would be
useful to explore this in the context of adaptive resolution.
39
References
References
1. Gingold, R.A., Monaghan, J.J.. Smoothed particle hydrodynam-
ics: Theory and application to non-spherical stars. Monthly Notices of
the Royal Astronomical Society 1977;181:375–389. doi:10.1093/mnras/
181.3.375.
4. Violeau, D.. Fluid mechanics and the SPH method: theory and ap-
plications. 1st ed ed.; Oxford University Press; 2012. ISBN 978-0-19-
965552-6. OCLC: ocn776772541.
5. Ye, T., Pan, D., Huang, C., Liu, M.. Smoothed particle hydrodynam-
ics (SPH) for complex fluid flows: Recent developments in methodology
and applications. Physics of Fluids 2019;31(1):011301.
8. Kiara, A., Hendrickson, K., Yue, D.K.. SPH for incompressible free-
surface flows. Part I: Error analysis of the basic assumptions. Computers
& Fluids 2013;86:611–624. URL: https://linkinghub.elsevier.com/
retrieve/pii/S0045793013002181. doi:10.1016/j.compfluid.2013.
05.023.
9. Lind, S., Xu, R., Stansby, P., Rogers, B.. Incompressible smoothed
particle hydrodynamics for free-surface flows: A generalised diffusion-
based algorithm for stability and validations for impulsive flows and
40
propagating waves. Journal of Computational Physics 2012;231(4):1499
– 1523. doi:10.1016/j.jcp.2011.10.027.
10. Xu, R., Stansby, P., Laurence, D.. Accuracy and stability in in-
compressible SPH (ISPH) based on the projection method and a new
approach. Journal of computational Physics 2009;228(18):6703–6725.
doi:https://doi.org/10.1016/j.jcp.2009.05.032.
11. Adami, S., Hu, X., Adams, N.. A transport-velocity formulation for
smoothed particle hydrodynamics. Journal of Computational Physics
2013;241:292–307. doi:10.1016/j.jcp.2013.01.043.
12. Colagrossi, A., Bouscasse, B., Antuono, M., Marrone, S.. Parti-
cle packing algorithm for SPH schemes. Computer Physics Communi-
cations 2012;183(8):1641–1653. doi:https://doi.org/10.1016/j.cpc.
2012.02.032.
16. Bonet, J., Lok, T.S.. Variational and momentum preservation aspects
of smooth particle hydrodynamic formulations. Computer Methods in
Applied Mechanics and Engineering 1999;180(1):97 – 115. doi:10.1016/
S0045-7825(99)00051-1.
41
18. Eitzlmayr, A., Koscher, G., Khinast, J.. A novel method for mod-
eling of complex wall geometries in smoothed particle hydrodynamics.
Computer physics communications 2014;185(10):2436–2448.
19. Chiron, L., De Leffe, M., Oger, G., Le Touzé, D.. Fast and accurate
SPH modelling of 3d complex wall boundaries in viscous and non viscous
flows. Computer Physics Communications 2019;234:93–111.
20. Marrone, S., Antuono, M., Colagrossi, A., Colicchio, G., Le Touzé, D.,
Graziani, G.. δ-SPH model for simulating violent impact flows. Com-
puter Methods in Applied Mechanics and Engineering 2011;200:1526–
1542. doi:10.1016/j.cma.2010.12.016.
21. Xiao, Y., Dong, H., Zhan, H., Gu, Y.. A new particle generation
method for arbitrary 2D geometries in SPH modeling. International
Journal of Computational Methods 2017;14(03):1750023. doi:https://
doi.org/10.1142/S0219876217500232.
22. Domı́nguez, J., Crespo, A., Barreiro, A., Gómez-Gesteira, M.,
Mayrhofer, A.. Development of a new pre-processing tool for SPH mod-
els with complex geometries. In: 6th International SPHERIC workshop.
2011:117–124.
23. Akinci, N., Cornelis, J., Akinci, G., Teschner, M.. Coupling elastic
solids with smoothed particle hydrodynamics fluids. Computer Anima-
tion and Virtual Worlds 2013;24(3-4):195–203. doi:https://doi.org/
10.1002/cav.1499.
24. Jiang, M., Zhou, Y., Wang, R., Southern, R., Zhang, J.J.. Blue noise
sampling using an SPH-based method. ACM Transactions on Graph-
ics (TOG) 2015;34(6):1–11. doi:https://doi.org/10.1145/2816795.
2818102.
25. Ramachandran, P., Puri, K., Bhosale, A., Dinesh, A., Muta, A., Negi,
P., Govind, R., Sanka, S., Pandey, P., Kaushik, C., et al. PySPH: a
Python-based framework for smoothed particle hydrodynamics. arXiv
preprint arXiv:190904504 2019;URL: https://arxiv.org/abs/1909.
04504.
26. Ramachandran, P.. PySPH: a reproducible and high-performance
framework for smoothed particle hydrodynamics. In: Benthall, S.,
42
Rostrup, S., eds. Proceedings of the 15th Python in Science Conference.
2016:127 – 135.
27. Monaghan, J.J.. Simulating free surface flows with SPH. Journal of
Computational Physics 1994;110:399–406.
29. Adami, S., Hu, X., Adams, N.. A generalized wall boundary condition
for smoothed particle hydrodynamics. Journal of Computational Physics
2012;231(21):7057–7075. doi:10.1016/j.jcp.2012.05.005.
31. Tafuni, A., Domı́nguez, J., Vacondio, R., Crespo, A.J.C.. A ver-
satile algorithm for the treatment of of open boundary conditions in
smoothed particle hydrodynamics GPU models. Computer methods in
applied mechanical engineering 2018;342:604–624. doi:10.1016/j.cma.
2018.08.004.
33. Swegle, J., Hicks, D., Attaway, S.. Smoothed particle hydrodynamics
stability analysis. Journal of computational physics 1995;116(1):123–
134. doi:https://doi.org/10.1006/jcph.1995.1010.
35. Akinci, N., Akinci, G., Teschner, M.. Versatile surface tension
and adhesion for SPH fluids. ACM Transactions on Graphics (TOG)
2013;32(6):1–8. doi:https://doi.org/10.1145/2508363.2508395.
43
36. Ramachandran, P.. automan: A python-based automation frame-
work for numerical computing. Computing in Science & Engineering
2018;20(5):81–97. doi:10.1109/MCSE.2018.05329818.
44