Skip to content

Commit 930aa3c

Browse files
author
LasNikas
committed
Merge branch 'main' into oriented-bbox
2 parents 12e7818 + eed6e2c commit 930aa3c

File tree

25 files changed

+684
-192
lines changed

25 files changed

+684
-192
lines changed

.github/workflows/SpellCheck.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ jobs:
1010
- name: Checkout Actions Repository
1111
uses: actions/checkout@v5
1212
- name: Check spelling
13-
uses: crate-ci/typos@v1.37.0
13+
uses: crate-ci/typos@v1.39.0

.github/workflows/TriggerGPUTests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- name: Trigger Buildkite Pipeline
14-
uses: "buildkite/trigger-pipeline-action@v2.3.0"
14+
uses: "buildkite/trigger-pipeline-action@v2.4.0"
1515
with:
1616
buildkite_api_access_token: ${{ secrets.TRIGGER_BK_BUILD_TOKEN }}
1717
pipeline: "julialang/trixiparticles"

docs/src/refs.bib

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ @Article{Balsara1995
111111
publisher = {Elsevier {BV}},
112112
}
113113

114-
@Article{Band2018,
114+
@Article{Band2018a,
115115
author = {Band, Stefan and Gissler, Christoph and Peer, Andreas and Teschner, Matthias},
116116
title = {{{MLS}} pressure boundaries for divergence-free and viscous {SPH} fluids},
117117
journal = {Computers \& Graphics},
@@ -124,6 +124,17 @@ @Article{Band2018
124124
publisher = {Elsevier {BV}},
125125
}
126126

127+
@Article{Band2018b,
128+
author = {Band, Stefan and Gissler, Christoph and Ihmsen, Markus and Cornelis, Jens and Peer, Andreas and Teschner, Matthias},
129+
title = {Pressure Boundaries for Implicit Incompressible SPH},
130+
year = {2018},
131+
volume = {37},
132+
number = {2},
133+
doi = {10.1145/3180486},
134+
journal = {ACM Transactions on Graphics},
135+
month = feb,
136+
}
137+
127138
@Article{Basa2008,
128139
author = {Basa, Mihai and Quinlan, Nathan J. and Lastiwka, Martin},
129140
title = {Robustness and accuracy of {SPH} formulations for viscous flow},

docs/src/systems/boundary.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ The momentum equation therefore becomes
138138
where the first sum is over all fluid particles and the second over all boundary particles.
139139

140140
This approach was first mentioned by [Akinci et al. (2012)](@cite Akinci2012) and written down in this form
141-
by [Band et al. (2018)](@cite Band2018).
141+
by [Band et al. (2018)](@cite Band2018a).
142142
```@docs
143143
PressureMirroring
144144
```

docs/src/systems/implicit_incompressible_sph.md

Lines changed: 115 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ is achieved:
3838
\frac{\rho_i(t + \Delta t) - \rho_i(t)}{\Delta t} = \sum_j m_j \bm{v}_{ij}(t+\Delta t) \nabla W_{ij}.
3939
```
4040

41+
Note that the linear system is only solved for fluid particles, so ``i`` always represents
42+
a fluid particle, and ``j`` represents all neighboring particles of ``i``.
43+
4144
The right-hand side contains the unknown velocities ``\bm{v}_{ij}(t + \Delta t)`` at the
4245
next time step, making it an implicit formulation.
4346

@@ -54,7 +57,7 @@ Note that the IISPH is an incompressible method, which means that the density of
5457
fluid remain constant over time. By assuming a fixed reference density ``\rho_0`` for all
5558
fluid particle over the whole time of the simulation, the density value at the next time
5659
step ``\rho_i(t + \Delta t)`` also has to be this rest density. So ``\rho_0`` can be plugged in
57-
for ``\rho_i(t + \Delta t)`` in the formula above.
60+
for ``\rho_i(t + \Delta t)`` in the equation above.
5861

5962
The goal is to compute the pressure values required to obtain the pressure acceleration that
6063
ensures each particle reaches the rest density in the next time step. At the moment these
@@ -169,6 +172,10 @@ the smoothing length, each particle's pressure ``p_i`` depends only on its own v
169172
nearby particles.
170173
Consequently, the matrix ``A`` is sparse (most entries are zero).
171174

175+
Note that this expression is not completely correct yet, since ``j`` represents all neighboring
176+
particles of ``i`` and some values like ``d_{jj}`` are not defined for boundary particles.
177+
The boundary handling is being explained in more detail later.
178+
172179
The diagonal elements ``a_{ii}`` get computed and stored at the beginning of the simulation step
173180
and remain unchanged throughout the relaxed Jacobi iterations. The same applies for the
174181
``d_{ii}``. The coefficients ``d_{ij}`` are computed, but not stored, as part of the calculation
@@ -201,19 +208,19 @@ as only isolated or almost isolated particles are affected.
201208

202209
## Boundary Handling
203210

204-
The previously introduced formulation only considered interactions between fluid particles
205-
and neglected interactions between fluid and boundary particles. To account for boundary
206-
interactions, a few modifications to the previous equations are required.
211+
The previously introduced formulation did not distinguish between fluid and boundary
212+
particles. To account boundary interactions correctly, a few modifications to the previous
213+
equations are required.
207214

208215
First, the discretized form of the continuity equation must be adapted for the case in which
209216
a neighboring particle is a boundary particle. From now on, we distinguish between
210-
neighboring fluid particles (indexed by ``j``) and neighboring boundary particles (indexed by
211-
``b``).
217+
neighboring fluid particles (indexed by ``f``) and neighboring boundary particles (indexed by
218+
``b``). We continue to use the index ``j`` if we want to refer to all neighboring particles.
212219

213220
The updated discretized continuity equation becomes:
214221

215222
```math
216-
\frac{\rho_i(t + \Delta t) - \rho_i(t)}{\Delta t} = \sum_j m_j \bm{v}_{ij}(t+\Delta t) \nabla W_{ij} + \sum_b m_b \bm{v}_{ib}(t+\Delta t) \nabla W_{ib}.
223+
\frac{\rho_i(t + \Delta t) - \rho_i(t)}{\Delta t} = \sum_f m_f \bm{v}_{if}(t+\Delta t) \nabla W_{if} + \sum_b m_b \bm{v}_{ib}(t+\Delta t) \nabla W_{ib}.
217224
```
218225

219226
Since boundary particles have zero velocity, the difference between the fluid
@@ -222,21 +229,22 @@ particle's velocity ``\bm{v}_{ib}(t+\Delta t) = \bm{v}_{i}(t+\Delta t)``.
222229
Accordingly, the predicted density ``\rho^{\text{adv}}`` becomes:
223230

224231
```math
225-
\rho_i^{\text{adv}} = \rho_i (t) + \Delta t \sum_j m_j \bm{v}_{ij}^{\text{adv}} \nabla W_{ij}(t) + \Delta t \sum_b m_b \bm{v}_{i}^{\text{adv}} \nabla W_{ib}(t).
232+
\rho_i^{\text{adv}} = \rho_i (t) + \Delta t \sum_f m_f \bm{v}_{if}^{\text{adv}} \nabla W_{if}(t) + \Delta t \sum_b m_b \bm{v}_{i}^{\text{adv}} \nabla W_{ib}(t).
226233
```
227234

228235
This leads to the following updated formulation of the linear system:
229236

230237
```math
231-
\Delta t^2 \sum_j m_j \left( \frac{\bm{F}_i^p(t)}{m_i} - \frac{\bm{F}_j^p(t)}{m_j} \right) \nabla W_{ij} + \Delta t^2 \sum_b m_b \frac{\bm{F}_i^p(t)}{m_i} \nabla W_{ib} = \rho_0 - \rho_i^{\text{adv}}.
238+
\Delta t^2 \sum_f m_f \left( \frac{\bm{F}_i^p(t)}{m_i} - \frac{\bm{F}_f^p(t)}{m_f} \right) \nabla W_{if} + \Delta t^2 \sum_b m_b \frac{\bm{F}_i^p(t)}{m_i} \nabla W_{ib} = \rho_0 - \rho_i^{\text{adv}}.
232239
```
233240

234-
Note that, since boundary particles are fixed, the force ``F_b^p`` is zero and does not appear in this equation.
241+
Note that, since boundary particles are fixed, the force ``F_b^p`` is zero and does not appear
242+
in this equation.
235243

236244
The pressure force acting on a fluid particle is computed as:
237245

238246
```math
239-
\bm{F}_i^p(t) = -\sum_j m_j \left( \frac{p_i(t)}{\rho_i^2(t)} + \frac{p_j(t)}{\rho_j^2(t)} \right) \nabla W_{ij}(t) - \sum_b m_b \left( \frac{p_i(t)}{\rho_i^2(t)} + \frac{p_b(t)}{\rho_b^2(t)} \right) \nabla W_{ib}(t).
247+
\bm{F}_i^p(t) = -\sum_f m_f \left( \frac{p_i(t)}{\rho_i^2(t)} + \frac{p_f(t)}{\rho_f^2(t)} \right) \nabla W_{if}(t) - \sum_b m_b \left( \frac{p_i(t)}{\rho_i^2(t)} + \frac{p_b(t)}{\rho_b^2(t)} \right) \nabla W_{ib}(t).
240248
```
241249

242250
This also leads to an updated version of the equation for the diagonal elements:
@@ -259,16 +267,16 @@ pressure value ``p_i`` ​must also include contributions from boundary particle
259267
the equation for calculating the coefficient ``d_{ii}`` must be adjusted as follows:
260268

261269
```math
262-
d_{ii} = -\Delta t^2 \sum_j \frac{m_j}{\rho_i^2} \nabla W_{ij} - \Delta t^2 \sum_b \frac{m_b}{\rho_i^2} \nabla W_{ib}.
270+
d_{ii} = -\Delta t^2 \sum_f \frac{m_f}{\rho_i^2} \nabla W_{if} - \Delta t^2 \sum_b \frac{m_b}{\rho_i^2} \nabla W_{ib}.
263271
```
264272

265273
The corresponding relaxed Jacobi iteration for pressure mirroring then becomes:
266274

267275
```math
268276
\begin{align*}
269277
p_i^{l+1} = (1 - \omega) p_i^l + \omega \frac{1}{a_{ii}} &\left( \rho_0 - \rho_i^{\text{adv}}
270-
- \sum_j m_j \left( \sum_k d_{ik} p_k^l - d_{jj}p_j^l - \sum_{k \neq i} d_{jk} p_k^l \right) \nabla W_{ij} \right. \\
271-
& \quad - \left. \sum_b m_b \sum_j d_{ij} p_j^l \nabla W_{ib} \right).
278+
- \sum_f m_f \left( \sum_k d_{ik} p_k^l - d_{ff}p_f^l - \sum_{k \neq i} d_{fk} p_k^l \right) \nabla W_{if} \right. \\
279+
& \quad - \left. \sum_b m_b \sum_f d_{if} p_f^l \nabla W_{ib} \right).
272280
\end{align*}
273281
```
274282

@@ -279,7 +287,7 @@ forces acting on fluid particles.
279287
In this case, the computation of the coefficient ``d_{ii}`` remains unchanged and is given by:
280288

281289
```math
282-
d_{ii} = -\Delta t^2 \sum_j \frac{m_j}{\rho_i^2} \nabla W_{ij}.
290+
d_{ii} = -\Delta t^2 \sum_f \frac{m_f}{\rho_i^2} \nabla W_{if}.
283291
```
284292

285293
The equation for the relaxed Jacobi iteration remains the same as in the pressure mirroring
@@ -289,7 +297,97 @@ pressure:
289297
```math
290298
\begin{align*}
291299
p_i^{l+1} = (1 - \omega) p_i^l + \omega \frac{1}{a_{ii}} &\left( \rho_0 - \rho_i^{\text{adv}}
292-
- \sum_j m_j \left( \sum_k d_{ik} p_k^l - d_{jj}p_j^l - \sum_{k \neq i} d_{jk} p_k^l \right) \nabla W_{ij} \right. \\
293-
& \quad - \left. \sum_b m_b \sum_j d_{ij} p_j^l \nabla W_{ib} \right).
300+
- \sum_f m_f \left( \sum_k d_{ik} p_k^l - d_{ff}p_f^l - \sum_{k \neq i} d_{fk} p_k^l \right) \nabla W_{if} \right. \\
301+
& \quad - \left. \sum_b m_b \sum_j d_{if} p_f^l \nabla W_{ib} \right).
294302
\end{align*}
303+
```
304+
305+
### Pressure Extrapolation
306+
The density calculators [`AdamiPressureExtrapolation`](@ref) and [`BernoulliPressureExtrapolation`](@ref)
307+
can also be used with IISPH.
308+
When using one of these pressure extrapolation methods the calculation of the PPE is exactly
309+
the same as when using pressure zeroing.
310+
So within the linear systems the pressure values are equal to zero (``p_b=0``) and therefore
311+
are not considered in the calculations. Only in the pressure acceleration, the extrapolated
312+
pressure values are used for the boundary particles. For more information on these two methods,
313+
refer to the docs for the [boundary models](@ref boundary_models).
314+
315+
### Pressure Boundaries
316+
The [`PressureBoundaries`](@ref) density calculator was introduced by
317+
[Band et al. (2008)](@cite Band2018b) specifically for IISPH fluid systems and can therefore
318+
only be used with IISPH.
319+
In the standard IISPH method the PPE is solved only for fluid particles. The
320+
pressure values for the boundary particles are then approximated, for example by using
321+
pressure mirroing.
322+
With `PressureBoundaries`, however, the linear system is extended to
323+
include the boundary particles as well. This means that the pressure values of both the fluid
324+
and the boundary particles are computed directly by solving the PPE.
325+
The main advantage of this method is that boundary pressures emerge naturally from the
326+
solution of the PPE, leading to a consistent pressure distribution across fluid and boundary
327+
domains. This avoids artificial constraints such as forcing ``p_{b}=0`` or ``p_{b}=p_{f}``,
328+
and results in more accurate handling of fluid-boundary interactions.
329+
330+
The key difference is that the pressure values of the boundary particles now have their own
331+
PPE within the linear system. In other words, the boundary particle pressure ``p_b`` is
332+
also solved as part of the linear system.
333+
This leads to the following condition for the boundary particles ``b``:
334+
335+
```math
336+
\Delta t^2 \sum_f m_f \left( \frac{\bm{F}_i^p(t)}{m_i} - \frac{\bm{F}_f^p(t)}{m_f} \right) \nabla W_{if} + \Delta t^2 \sum_b m_b \left( \frac{\bm{F}_i^p(t)}{m_i} - \frac{\bm{F}_b^p(t)}{m_b} \right) \nabla W_{ib} = \rho_0 - \rho_i^{\text{adv}}.
337+
```
338+
339+
Note that in this case ``i`` is a boundary particle,``f`` are its fluid neighbors, and ``b``
340+
its boundary neighbors.
341+
342+
Since the pressure force for boundary particles is zero (as mentioned before), and because
343+
in this case ``i`` and ``b`` are both boundary particles, the PPE simplifies to
344+
345+
```math
346+
\Delta t^2 \sum_f m_f - \frac{\bm{F}_f^p(t)}{m_f} \nabla W_{if} = \rho_0 - \rho_i^{\text{adv}}.
347+
```
348+
If we substitute the definition of the pressure force from above, we obtain
349+
350+
```math
351+
\Delta t^2 \sum_f m_f \left( \sum_k m_k \left( \frac{p_f(t)}{\rho_j^2(t)} + \frac{p_k(t)}{\rho_k^2(t)} \right) \nabla W_{fk}\right) \nabla W_{if} = \rho_0 - \rho_i^{\text{adv}}.
352+
```
353+
354+
where ``k`` represents all neighboring particles (fluid and boundary) of fluid particle ``f``.
355+
356+
Because the boundary particles do not directly contribute to their own pressure force (only
357+
indirectly as neighbors of fluid particles), their ``d_{ii}`` values are zero. Therefore the
358+
diagonal elements simplify to
359+
360+
```math
361+
a_{ii} = \sum_f \left( -d_{fi}\right) \nabla W_{if}.
362+
```
363+
364+
The off-diagonal term ``\sum_{j \neq i} a_{ij} p_j`` in the relaxed Jacobi iteration for boundary
365+
particles takes the following form
366+
367+
```math
368+
\sum_{j \neq i} a_{ij} p_j = \sum_f m_f \left( d_{ff} - \sum_{f_j} d_{ff_j}p_{f_j}\right) \nabla W_{if}.
369+
```
370+
371+
But not only the addition of the boundary particles to the linear system changes when using
372+
pressure boundaries, also the PPE for the fluid particles is changing slightly.
373+
374+
Since the boundary particles have now their own pressure values, ``p_b`` is no longer
375+
eliminated (as in pressure zeroing or pressure extrapolation with ``p_b=0``) nor simply
376+
replaced by the fluid particle's pressure (as in pressure mirroring with ``p_b=p_i``).
377+
Instead, ``p_b``remains part of the PPE.
378+
379+
This has no effect on the diagonal elements ``a_{ii}``, which are identical to those of the
380+
other density calculators. The ``d_{ii}`` values are also computed in the same way as for
381+
pressure zeroing or pressure extrapolation.
382+
However, the off-diagonal term ``\sum_{j \neq i} a_{ij} p_j`` in the relaxed Jacobi iteration
383+
changes slightly.
384+
For pressure boundaries it takes the form
385+
```math
386+
\sum_{j \neq i} a_{ij} p_j = \sum_f m_f \left( \sum_k d_{ik} p_k - d_{ff} p_f - \sum_{k \neq f} d_{fk} p_k \right) \nabla W_{if} \\
387+
+ \sum_b m_b \left( \sum_k d_{ik} p_k \right) \nabla W_{ib},
388+
```
389+
where ``k``represents all neighboring particles of ``i`` (both fluid and boundary).
390+
391+
```@docs
392+
PressureBoundaries
295393
```

examples/fluid/dam_break_2d_iisph.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# 2D dam break simulation using implicit incompressible SPH (IISPH)
22
using TrixiParticles
33

4-
fluid_particle_spacing = 0.015
4+
fluid_particle_spacing = 0.6 / 40
55

66
# Load setup from dam break example
77
trixi_include(@__MODULE__,
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# 2D dam break simulation using implicit incompressible SPH (IISPH) with pressure boundaries
2+
using TrixiParticles
3+
4+
# Load setup from dam break example
5+
trixi_include(@__MODULE__,
6+
joinpath(examples_dir(), "fluid", "dam_break_2d.jl"),
7+
sol=nothing, ode=nothing)
8+
9+
# Change smoothing kernel and length
10+
smoothing_length = 1.2 * fluid_particle_spacing
11+
smoothing_kernel = SchoenbergCubicSplineKernel{2}()
12+
13+
# Calculate kinematic viscosity for the viscosity model
14+
nu = 0.02 * smoothing_length * sound_speed / 8
15+
viscosity = ViscosityAdami(; nu)
16+
17+
# Use IISPH as fluid system
18+
time_step = 1e-3
19+
# Reduce omega when using pressure boundaries to ensure numerical stability
20+
omega = 0.4
21+
22+
iisph_system = ImplicitIncompressibleSPHSystem(tank.fluid, smoothing_kernel,
23+
smoothing_length, fluid_density,
24+
viscosity=ViscosityAdami(nu=nu),
25+
acceleration=(0.0, -gravity),
26+
min_iterations=2,
27+
max_iterations=30,
28+
omega=omega,
29+
time_step=time_step)
30+
31+
# Run the dam break simulation with these changes
32+
trixi_include(@__MODULE__,
33+
joinpath(examples_dir(), "fluid", "dam_break_2d.jl"),
34+
viscosity_fluid=ViscosityAdami(nu=nu),
35+
smoothing_kernel=smoothing_kernel,
36+
smoothing_length=smoothing_length,
37+
fluid_system=iisph_system,
38+
boundary_density_calculator=PressureBoundaries(; time_step=time_step,
39+
omega=omega),
40+
tspan=tspan,
41+
state_equation=nothing,
42+
callbacks=CallbackSet(info_callback, saving_callback),
43+
time_integration_scheme=SymplecticEuler(), dt=time_step)

src/TrixiParticles.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export tensile_instability_control
8686
export BoundaryModelMonaghanKajtar, BoundaryModelDummyParticles, AdamiPressureExtrapolation,
8787
PressureMirroring, PressureZeroing, BoundaryModelCharacteristicsLastiwka,
8888
BoundaryModelMirroringTafuni, BoundaryModelDynamicalPressureZhang,
89-
BernoulliPressureExtrapolation
89+
BernoulliPressureExtrapolation, PressureBoundaries
9090
export FirstOrderMirroring, ZerothOrderMirroring, SimpleMirroring
9191
export HertzContactModel, LinearContactModel
9292
export PrescribedMotion, OscillatingMotion2D

src/callbacks/update.jl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ function (update_callback!::UpdateCallback)(integrator)
7474
semi = integrator.p
7575
v_ode, u_ode = integrator.u.x
7676

77+
# Tell OrdinaryDiffEq that `integrator.u` has NOT been modified.
78+
# This will be set to `true` in any of the update functions below that modify
79+
# either `v_ode` or `u_ode`.
80+
u_modified!(integrator, false)
81+
7782
@trixi_timeit timer() "update callback" begin
7883
# Update quantities that are stored in the systems. These quantities (e.g. pressure)
7984
# still have the values from the last stage of the previous step if not updated here.
@@ -84,7 +89,7 @@ function (update_callback!::UpdateCallback)(integrator)
8489

8590
# Update open boundaries first, since particles might be activated or deactivated
8691
@trixi_timeit timer() "update open boundary" foreach_system(semi) do system
87-
update_open_boundary_eachstep!(system, v_ode, u_ode, semi, t)
92+
update_open_boundary_eachstep!(system, v_ode, u_ode, semi, t, integrator)
8893
end
8994

9095
@trixi_timeit timer() "update particle packing" foreach_system(semi) do system
@@ -93,18 +98,15 @@ function (update_callback!::UpdateCallback)(integrator)
9398

9499
# This is only used by the particle packing system and should be removed in the future
95100
@trixi_timeit timer() "update TVF" foreach_system(semi) do system
96-
update_transport_velocity!(system, v_ode, semi)
101+
update_transport_velocity!(system, v_ode, semi, integrator)
97102
end
98103

99104
@trixi_timeit timer() "particle shifting" foreach_system(semi) do system
100105
particle_shifting_from_callback!(u_ode, shifting_technique(system), system,
101-
v_ode, semi, integrator.dt)
106+
v_ode, semi, integrator)
102107
end
103108
end
104109

105-
# Tell OrdinaryDiffEq that `u` has been modified
106-
u_modified!(integrator, true)
107-
108110
return integrator
109111
end
110112

0 commit comments

Comments
 (0)