Skip to content

Commit 393f9dc

Browse files
committed
Make average pressure reduction for EDAC independent of TVF
1 parent 52554f9 commit 393f9dc

5 files changed

Lines changed: 67 additions & 47 deletions

File tree

src/schemes/fluid/entropically_damped_sph/rhs.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ function interact!(dv, v_particle_system, u_particle_system,
2727
p_a = current_pressure(v_particle_system, particle_system, particle)
2828
p_b = current_pressure(v_neighbor_system, neighbor_system, neighbor)
2929

30-
# This technique is for a more robust `pressure_acceleration` but only with TVF.
31-
# It results only in significant improvement for EDAC and not for WCSPH.
32-
# See Ramachandran (2019) p. 582
33-
# Note that the return value is zero when not using EDAC with TVF.
30+
# This technique by Basa et al. 2017 (10.1002/fld.1927) aims to reduce numerical
31+
# errors due to large pressures by subtracting the average pressure of neighboring
32+
# particles.
33+
# It results in significant improvement for EDAC, especially with TVF,
34+
# but not for WCSPH, according to Ramachandran & Puri (2019), Section 3.2.
35+
# Note that the return value is zero when not using average pressure reduction.
3436
p_avg = average_pressure(particle_system, particle)
3537

3638
m_a = hydrodynamic_mass(particle_system, particle)

src/schemes/fluid/entropically_damped_sph/system.jl

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ See [Entropically Damped Artificial Compressibility for SPH](@ref edac) for more
3030
When set to `nothing`, the pressure acceleration formulation for the
3131
corresponding [density calculator](@ref density_calculator) is chosen.
3232
- `density_calculator`: [Density calculator](@ref density_calculator) (default: [`SummationDensity`](@ref))
33-
- `transport_velocity`: [Transport Velocity Formulation (TVF)](@ref transport_velocity_formulation). Default is no TVF.
33+
- `transport_velocity`: [Transport Velocity Formulation (TVF)](@ref transport_velocity_formulation).
34+
Default is no TVF.
35+
- `average_pressure_reduction`: Whether to subtract the average pressure of neighboring particles
36+
from the local pressure (default: `true` when using TVF, `false` otherwise).
3437
- `buffer_size`: Number of buffer particles.
3538
This is needed when simulating with [`OpenBoundarySPHSystem`](@ref).
3639
- `correction`: Correction method used for this system. (default: no correction, see [Corrections](@ref corrections))
@@ -53,7 +56,7 @@ See [Entropically Damped Artificial Compressibility for SPH](@ref edac) for more
5356
5457
"""
5558
struct EntropicallyDampedSPHSystem{NDIMS, ELTYPE <: Real, IC, M, DC, K, V, COR, PF, TV,
56-
ST, SRFT, SRFN, B, PR, C} <: FluidSystem{NDIMS}
59+
AVGP, ST, SRFT, SRFN, B, PR, C} <: FluidSystem{NDIMS}
5760
initial_condition :: IC
5861
mass :: M # Vector{ELTYPE}: [particle]
5962
density_calculator :: DC
@@ -65,6 +68,7 @@ struct EntropicallyDampedSPHSystem{NDIMS, ELTYPE <: Real, IC, M, DC, K, V, COR,
6568
correction :: COR
6669
pressure_acceleration_formulation :: PF
6770
transport_velocity :: TV
71+
average_pressure_reduction :: AVGP
6872
source_terms :: ST
6973
surface_tension :: SRFT
7074
surface_normal_method :: SRFN
@@ -80,6 +84,7 @@ function EntropicallyDampedSPHSystem(initial_condition, smoothing_kernel,
8084
pressure_acceleration=inter_particle_averaged_pressure,
8185
density_calculator=SummationDensity(),
8286
transport_velocity=nothing,
87+
average_pressure_reduction=!isnothing(transport_velocity),
8388
alpha=0.5, viscosity=nothing,
8489
acceleration=ntuple(_ -> 0.0,
8590
ndims(smoothing_kernel)),
@@ -127,10 +132,14 @@ function EntropicallyDampedSPHSystem(initial_condition, smoothing_kernel,
127132
NDIMS, ELTYPE,
128133
correction)
129134

135+
avg_pressure_reduction = Val(average_pressure_reduction)
136+
130137
nu_edac = (alpha * smoothing_length * sound_speed) / 8
131138

132139
cache = (; create_cache_density(initial_condition, density_calculator)...,
133-
create_cache_tvf_edac(initial_condition, transport_velocity)...,
140+
create_cache_tvf(initial_condition, transport_velocity)...,
141+
create_cache_avg_pressure_reduction(initial_condition,
142+
avg_pressure_reduction)...,
134143
create_cache_surface_normal(surface_normal_method, ELTYPE, NDIMS,
135144
n_particles)...,
136145
create_cache_surface_tension(surface_tension, ELTYPE, NDIMS,
@@ -152,19 +161,29 @@ function EntropicallyDampedSPHSystem(initial_condition, smoothing_kernel,
152161
EntropicallyDampedSPHSystem{NDIMS, ELTYPE, typeof(initial_condition), typeof(mass),
153162
typeof(density_calculator), typeof(smoothing_kernel),
154163
typeof(viscosity), typeof(correction),
155-
typeof(pressure_acceleration),
156-
typeof(transport_velocity), typeof(source_terms),
164+
typeof(pressure_acceleration), typeof(transport_velocity),
165+
typeof(avg_pressure_reduction), typeof(source_terms),
157166
typeof(surface_tension), typeof(surface_normal_method),
158167
typeof(buffer), Nothing,
159168
typeof(cache)}(initial_condition, mass, density_calculator,
160169
smoothing_kernel, sound_speed, viscosity,
161170
nu_edac, acceleration_, correction,
162171
pressure_acceleration, transport_velocity,
172+
avg_pressure_reduction,
163173
source_terms, surface_tension,
164174
surface_normal_method, buffer,
165175
particle_refinement, cache)
166176
end
167177

178+
create_cache_avg_pressure_reduction(initial_condition, ::Val{false}) = (;)
179+
180+
function create_cache_avg_pressure_reduction(initial_condition, ::Val{true})
181+
pressure_average = copy(initial_condition.pressure)
182+
neighbor_counter = Vector{Int}(undef, nparticles(initial_condition))
183+
184+
return (; pressure_average, neighbor_counter)
185+
end
186+
168187
function Base.show(io::IO, system::EntropicallyDampedSPHSystem)
169188
@nospecialize system # reduce precompilation time
170189

@@ -201,6 +220,8 @@ function Base.show(io::IO, ::MIME"text/plain", system::EntropicallyDampedSPHSyst
201220
summary_line(io, "smoothing kernel", system.smoothing_kernel |> typeof |> nameof)
202221
summary_line(io, "tansport velocity formulation",
203222
system.transport_velocity |> typeof |> nameof)
223+
summary_line(io, "average pressure reduction",
224+
typeof(system.average_pressure_reduction).parameters[1] ? "yes" : "no")
204225
summary_line(io, "acceleration", system.acceleration)
205226
summary_line(io, "surface tension", system.surface_tension)
206227
summary_line(io, "surface normal method", system.surface_normal_method)
@@ -252,17 +273,15 @@ end
252273

253274
@inline transport_velocity(system::EntropicallyDampedSPHSystem) = system.transport_velocity
254275

255-
@inline average_pressure(system, particle) = zero(eltype(system))
256-
257276
@inline function average_pressure(system::EntropicallyDampedSPHSystem, particle)
258-
average_pressure(system, transport_velocity(system), particle)
277+
average_pressure(system, system.average_pressure_reduction, particle)
259278
end
260279

261-
@inline function average_pressure(system, ::TransportVelocityAdami, particle)
280+
@inline function average_pressure(system, ::Val{true}, particle)
262281
return system.cache.pressure_average[particle]
263282
end
264283

265-
@inline average_pressure(system, ::Nothing, particle) = zero(eltype(system))
284+
@inline average_pressure(system, ::Val{false}, particle) = zero(eltype(system))
266285

267286
@inline function current_density(v, system::EntropicallyDampedSPHSystem)
268287
return current_density(v, system.density_calculator, system)
@@ -301,18 +320,21 @@ function update_final!(system::EntropicallyDampedSPHSystem, v, u, v_ode, u_ode,
301320
# Surface normal of neighbor and boundary needs to have been calculated already
302321
compute_curvature!(system, surface_tension, v, u, v_ode, u_ode, semi, t)
303322
compute_stress_tensors!(system, surface_tension, v, u, v_ode, u_ode, semi, t)
304-
update_average_pressure!(system, transport_velocity(system), v_ode, u_ode, semi)
323+
update_average_pressure!(system, system.average_pressure_reduction, v_ode, u_ode, semi)
305324
update_tvf!(system, transport_velocity(system), v, u, v_ode, u_ode, semi, t)
306325
end
307326

308-
function update_average_pressure!(system, ::Nothing, v_ode, u_ode, semi)
327+
# No average pressure reduction is used
328+
function update_average_pressure!(system, ::Val{false}, v_ode, u_ode, semi)
309329
return system
310330
end
311331

312-
# This technique is for a more robust `pressure_acceleration` but only with TVF.
313-
# It results only in significant improvement for EDAC and not for WCSPH.
314-
# See Ramachandran (2019) p. 582.
315-
function update_average_pressure!(system, ::TransportVelocityAdami, v_ode, u_ode, semi)
332+
# This technique by Basa et al. 2017 (10.1002/fld.1927) aims to reduce numerical errors
333+
# due to large pressures by subtracting the average pressure of neighboring particles.
334+
# It results in significant improvement for EDAC, especially with TVF,
335+
# but not for WCSPH, according to Ramachandran & Puri (2019), Section 3.2.
336+
# See eq. 16 and 17 in Ramachandran & Puri (2019) for an explanation of the technique.
337+
function update_average_pressure!(system, ::Val{true}, v_ode, u_ode, semi)
316338
(; cache) = system
317339
(; pressure_average, neighbor_counter) = cache
318340

src/schemes/fluid/transport_velocity.jl

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,15 @@ end
1616
# No TVF for a system by default
1717
@inline transport_velocity(system) = nothing
1818

19-
create_cache_tvf_wcsph(initial_condition, ::Nothing) = (;)
19+
create_cache_tvf(initial_condition, ::Nothing) = (;)
2020

21-
function create_cache_tvf_wcsph(initial_condition, ::TransportVelocityAdami)
21+
function create_cache_tvf(initial_condition, ::TransportVelocityAdami)
2222
delta_v = zeros(eltype(initial_condition), ndims(initial_condition),
2323
nparticles(initial_condition))
2424

2525
return (; delta_v)
2626
end
2727

28-
create_cache_tvf_edac(initial_condition, ::Nothing) = (;)
29-
30-
function create_cache_tvf_edac(initial_condition, ::TransportVelocityAdami)
31-
delta_v = zeros(eltype(initial_condition), ndims(initial_condition),
32-
nparticles(initial_condition))
33-
pressure_average = copy(initial_condition.pressure)
34-
neighbor_counter = Vector{Int}(undef, nparticles(initial_condition))
35-
36-
return (; delta_v, pressure_average, neighbor_counter)
37-
end
38-
3928
# `δv` is the correction to the particle velocity due to the TVF.
4029
# Particles are advected with the velocity `v + δv`.
4130
@propagate_inbounds function delta_v(system, particle)

src/schemes/fluid/weakly_compressible_sph/system.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ function WeaklyCompressibleSPHSystem(initial_condition,
147147
n_particles)...,
148148
create_cache_refinement(initial_condition, particle_refinement,
149149
smoothing_length)...,
150-
create_cache_tvf_wcsph(initial_condition, transport_velocity)...,
150+
create_cache_tvf(initial_condition, transport_velocity)...,
151151
color=Int(color_value))
152152

153153
# If the `reference_density_spacing` is set calculate the `ideal_neighbor_count`

test/systems/edac_system.jl

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
│ ν₍EDAC₎: ………………………………………………………… ≈ 0.226 │
142142
│ smoothing kernel: ………………………………… Val │
143143
│ tansport velocity formulation: Nothing │
144+
│ average pressure reduction: ……… no │
144145
│ acceleration: …………………………………………… [0.0, 0.0] │
145146
│ surface tension: …………………………………… nothing │
146147
│ surface normal method: …………………… nothing │
@@ -220,22 +221,28 @@
220221

221222
fluid = rectangular_patch(particle_spacing, (3, 3), seed=1)
222223

223-
system = EntropicallyDampedSPHSystem(fluid, smoothing_kernel,
224-
transport_velocity=TransportVelocityAdami(0.0),
225-
smoothing_length, 0.0)
226-
semi = Semidiscretization(system)
224+
transport_velocity = [nothing, TransportVelocityAdami(10000.0)]
225+
names = ["No TVF", "TransportVelocityAdami"]
226+
@testset "$(names[i])" for i in eachindex(transport_velocity)
227+
system = EntropicallyDampedSPHSystem(fluid, smoothing_kernel,
228+
transport_velocity=transport_velocity[i],
229+
average_pressure_reduction=true,
230+
smoothing_length, 0.0)
231+
semi = Semidiscretization(system)
227232

228-
TrixiParticles.initialize_neighborhood_searches!(semi)
233+
TrixiParticles.initialize_neighborhood_searches!(semi)
229234

230-
u_ode = vec(fluid.coordinates)
231-
v_ode = vec(vcat(fluid.velocity, fluid.pressure'))
235+
u_ode = vec(fluid.coordinates)
236+
v_ode = vec(vcat(fluid.velocity, fluid.pressure'))
232237

233-
TrixiParticles.update_average_pressure!(system, system.transport_velocity, v_ode,
234-
u_ode, semi)
238+
TrixiParticles.update_average_pressure!(system,
239+
system.average_pressure_reduction,
240+
v_ode, u_ode, semi)
235241

236-
@test all(i -> system.cache.neighbor_counter[i] == nparticles(system),
237-
nparticles(system))
238-
@test all(i -> isapprox(system.cache.pressure_average[i], -50.968532955185964),
239-
nparticles(system))
242+
@test all(i -> system.cache.neighbor_counter[i] == nparticles(system),
243+
nparticles(system))
244+
@test all(i -> isapprox(system.cache.pressure_average[i], -50.968532955185964),
245+
nparticles(system))
246+
end
240247
end
241248
end

0 commit comments

Comments
 (0)