Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ used in the Julia ecosystem. Notable changes will be documented in this file for
- The smoothing kernel and smoothing length of a `BoundaryModelDummyParticles` of a
`TotalLagrangianSPHSystem` or `RigidBodySystem` must now be the same as those of all
fluid systems in the simulation (#1338, #1348).
- The `correction` of a `BoundaryModelDummyParticles` of a `TotalLagrangianSPHSystem` or
`RigidBodySystem` must now be `nothing`. Previously, it was ignored or caused an error
(#1342).

### Features

Expand All @@ -29,6 +32,14 @@ used in the Julia ecosystem. Notable changes will be documented in this file for

### Important Bugfixes

- Fixed the fluid–structure pressure acceleration of fluids with `KernelCorrection`,
`GradientCorrection`, `BlendedGradientCorrection` or `MixedKernelGradientCorrection` to use
the smoothing kernel and smoothing length of the boundary model at the structure particles
instead of those of the `TotalLagrangianSPHSystem`. Also fixed the assembly of the
correction matrix, which made `GradientCorrection` have no effect and
`BlendedGradientCorrection` depend on the order of the neighbors, so results with these
corrections change. `DensityDiffusionAntuono` now always uses the uncorrected kernel
gradient (#1342).
- Fixed structure-fluid reaction forces with asymmetric corrected fluid kernel
gradients by evaluating the fluid-first gradient directly. The continuity equation
of `RigidBodySystem` boundaries with `ContinuityDensity` now uses the kernel gradient
Expand Down
30 changes: 30 additions & 0 deletions docs/src/systems/boundary.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ We provide six options to compute the boundary density and pressure, determined
and the pressure is computed from the density with the state equation.
4. With [`ContinuityDensity`](@ref), the density is integrated from the continuity equation,
and the pressure is computed from the density with the state equation.
This option is not supported for a [`TotalLagrangianSPHSystem`](@ref).
Note that this causes a gap between fluid and boundary where the boundary is initialized
without any contact to the fluid. This is due to overestimation of the boundary density
as soon as the fluid comes in contact with boundary particles that initially did not have
Expand Down Expand Up @@ -177,6 +178,35 @@ condition is applied.
The viscosity model [`ArtificialViscosityMonaghan`](@ref) for [`BoundaryModelDummyParticles`](@ref)
has not been verified yet.

### [Corrections](@id boundary_corrections)

When the adjacent fluid system uses a [correction](@ref corrections) with a kernel gradient
that is not antisymmetric, i.e., [`KernelCorrection`](@ref), [`GradientCorrection`](@ref),
[`BlendedGradientCorrection`](@ref) or [`MixedKernelGradientCorrection`](@ref),
the pressure acceleration cannot use
``\nabla_{r_b} W(\Vert r_b - r_a \Vert, h) = -\nabla_{r_a} W(\Vert r_a - r_b \Vert, h)``.
Instead, each of the two particles uses its own corrected kernel gradient, e.g.,
for [`ContinuityDensity`](@ref),
```math
\bm{f}_{ab}^{p}
= -\frac{m_a m_b}{\rho_a \rho_b}
\left( p_a \tilde{\nabla}_{r_a} W_{ab} - p_b \tilde{\nabla}_{r_b} W_{ba} \right),
```
where ``\tilde{\nabla}_{r_a} W_{ab}`` is the corrected kernel gradient of the fluid particle ``a``
and ``\tilde{\nabla}_{r_b} W_{ba}`` is the corrected kernel gradient of the boundary particle ``b``.
The latter is computed with the `correction` of the boundary model. With `correction=nothing`,
the boundary gradient is uncorrected, even when the fluid uses a correction.
With [`ContinuityDensity`](@ref), the density of the boundary particles also evolves with the
corrected kernel gradient of the boundary particles.

For a [`TotalLagrangianSPHSystem`](@ref) or a [`RigidBodySystem`](@ref), the kernel gradient
at each boundary particle uses the smoothing kernel and smoothing length of the boundary
model, which must match those of the fluid systems. The smoothing kernel of the
[`TotalLagrangianSPHSystem`](@ref) is used for solid mechanics instead.
Corrections at the boundary particles of these structures are not supported yet,
so the boundary model's `correction` must be `nothing`.
These requirements are checked when constructing the [`Semidiscretization`](@ref).

## Repulsive Particles

Boundaries modeled as boundary particles which exert forces on the fluid particles ([Monaghan, Kajtar, 2009](@cite Monaghan2009)).
Expand Down
5 changes: 5 additions & 0 deletions docs/src/systems/fluid.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@ Pages = [joinpath("schemes", "fluid", "viscosity.jl")]

## [Corrections](@id corrections)

For fluid-structure interaction with a [`TotalLagrangianSPHSystem`](@ref) or a
[`RigidBodySystem`](@ref), the structure's [`BoundaryModelDummyParticles`](@ref) must use
`correction=nothing`. See [Boundary Corrections](@ref boundary_corrections) for how
the corrected fluid gradient and the boundary gradient enter the pressure acceleration.

```@autodocs
Modules = [TrixiParticles]
Pages = [joinpath("general", "corrections.jl")]
Expand Down
5 changes: 5 additions & 0 deletions docs/src/systems/rigid_body.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Rigid bodies in TrixiParticles.jl are represented by particles whose motion is e
with rigid-body translation and rotation. This allows fluid-structure interaction while
keeping the structure kinematics rigid.

Fluid-structure interaction is configured through `boundary_model`. When using
[`BoundaryModelDummyParticles`](@ref), its smoothing kernel and smoothing length must match
those of every fluid system. Its `correction` must be `nothing`
(see [Boundary Corrections](@ref boundary_corrections)).

## API

```@autodocs
Expand Down
11 changes: 11 additions & 0 deletions docs/src/systems/total_lagrangian_sph.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ are the Lamé coefficients, where ``E`` is the Young's modulus and ``\nu`` is th

The term ``\bm{f}_a^{PF}`` is an optional penalty force. See e.g. [`PenaltyForceGanzenmueller`](@ref).

The smoothing kernel, the smoothing length and the correction matrix ``\bm{L}_{0a}`` above
are used for the solid mechanics of the structure.
The pressure forces between fluid and structure are computed with the `boundary_model`
(see [Boundary Models](@ref boundary_models)).
When using [`BoundaryModelDummyParticles`](@ref), its smoothing kernel and smoothing length
are used for the kernel gradients at the structure particles and must match those of every
fluid system. Its `correction` must be `nothing`
(see [Boundary Corrections](@ref boundary_corrections)).
[`ContinuityDensity`](@ref) is not supported for the boundary model of a
[`TotalLagrangianSPHSystem`](@ref).

```@autodocs
Modules = [TrixiParticles]
Pages = [joinpath("schemes", "structure", "total_lagrangian_sph", "system.jl")]
Expand Down
13 changes: 3 additions & 10 deletions src/general/abstract_system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,9 @@ end
# Robust/safe version of the function below. In performance-critical code, manually check
# the kernel support, call `skip_zero_distance` and then `smoothing_kernel_grad_unsafe`.
@inline function smoothing_kernel_grad(system, pos_diff, distance, particle)
h = smoothing_length(system, particle)
compact_support_ = compact_support(system_smoothing_kernel(system), h)

# See `almostzero` for an explanation of the zero distance check
if distance >= compact_support_ ||
(skip_zero_distance(system) && distance < almostzero(h))
return zero(pos_diff)
end

return smoothing_kernel_grad_unsafe(system, pos_diff, distance, particle)
return corrected_kernel_grad(system_smoothing_kernel(system), pos_diff, distance,
smoothing_length(system, particle),
system_correction(system), system, particle)
end

# Skip the zero distance and compact support checks for maximum performance.
Expand Down
95 changes: 33 additions & 62 deletions src/general/corrections.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,11 @@ function compute_correction_values!(system, ::ShepardKernelCorrection, u, v_ode,
system.cache.kernel_correction_coefficient)
end

function compute_correction_values!(system::AbstractBoundarySystem,
::ShepardKernelCorrection, u,
v_ode, u_ode, semi)
return compute_shepard_coeff!(system, current_coordinates(u, system), v_ode, u_ode,
semi,
system.boundary_model.cache.kernel_correction_coefficient)
end

# The correction-assembly helpers use `system` for the particles and the neighbor search.
# The `kernel_data` keyword supplies the kernel, smoothing length and any existing correction
# values needed for assembly. It defaults to `system`; boundary-model callers pass their model.
function compute_shepard_coeff!(system, system_coords, v_ode, u_ode, semi,
kernel_correction_coefficient)
kernel_correction_coefficient; kernel_data=system)
set_zero!(kernel_correction_coefficient)

# Use enabled neighbor systems for the correction value.
Expand All @@ -159,7 +154,7 @@ function compute_shepard_coeff!(system, system_coords, v_ode, u_ode, semi,
volume = m_b / rho_b

kernel_correction_coefficient[particle] += volume *
smoothing_kernel(system,
smoothing_kernel(kernel_data,
distance,
particle)
end
Expand Down Expand Up @@ -187,21 +182,14 @@ function compute_correction_values!(system::AbstractFluidSystem,
system.cache.dw_gamma)
end

function compute_correction_values!(system::AbstractBoundarySystem,
correction::Union{KernelCorrection,
MixedKernelGradientCorrection}, u,
v_ode, u_ode, semi)
compute_correction_values!(system, correction, current_coordinates(u, system), v_ode,
u_ode, semi,
system.boundary_model.cache.kernel_correction_coefficient,
system.boundary_model.cache.dw_gamma)
end

function compute_correction_values!(system,
::Union{KernelCorrection,
MixedKernelGradientCorrection}, system_coords,
v_ode,
u_ode, semi, kernel_correction_coefficient, dw_gamma)
u_ode, semi, kernel_correction_coefficient, dw_gamma;
kernel_data=system)
smoothing_kernel = system_smoothing_kernel(kernel_data)

set_zero!(kernel_correction_coefficient)
set_zero!(dw_gamma)

Expand All @@ -217,18 +205,18 @@ function compute_correction_values!(system,

neighbor_coords = current_coordinates(u_neighbor_system, neighbor_system)

h = initial_smoothing_length(system)

# Loop over all pairs of particles and neighbors within the kernel cutoff
foreach_point_neighbor(system, neighbor_system, system_coords, neighbor_coords,
semi) do particle, neighbor, pos_diff, distance
h = smoothing_length(kernel_data, particle)
distance >= compact_support(smoothing_kernel, h) && return

rho_b = current_density(v_neighbor_system, neighbor_system, neighbor)
m_b = hydrodynamic_mass(neighbor_system, neighbor)
volume = m_b / rho_b

# Use uncorrected kernel to compute correction coefficients
W = kernel(system_smoothing_kernel(system), distance,
smoothing_length(system, particle))
W = kernel_unsafe(smoothing_kernel, distance, h)

kernel_correction_coefficient[particle] += volume * W

Expand All @@ -237,9 +225,7 @@ function compute_correction_values!(system,
if distance >= almostzero(h)
# Now that we know that `distance` is not zero, we can safely call the
# unsafe version of the kernel gradient to avoid redundant zero checks.
grad_W = kernel_grad_unsafe(system_smoothing_kernel(system), pos_diff,
distance,
smoothing_length(system, particle))
grad_W = kernel_grad_unsafe(smoothing_kernel, pos_diff, distance, h)
tmp = volume * grad_W
for i in axes(dw_gamma, 1)
dw_gamma[i, particle] += tmp[i]
Expand Down Expand Up @@ -329,7 +315,11 @@ function compute_gradient_correction_matrix!(corr_matrix, system, coordinates, d
# Loop over all pairs of particles and neighbors within the kernel cutoff
foreach_point_neighbor(system, system, coordinates, coordinates,
semi) do particle, neighbor, pos_diff, distance
grad_kernel = smoothing_kernel_grad(system, pos_diff, distance, particle)
# Assemble the matrix from the uncorrected kernel gradient. The corrected gradient
# of a fluid would use correction values of the fluid that are computed later
# in the update and are therefore not yet available.
grad_kernel = kernel_grad(system_smoothing_kernel(system), pos_diff, distance,
smoothing_length(system, particle))
iszero(grad_kernel) && return

volume = @inbounds mass[neighbor] / density_fun(neighbor)
Expand All @@ -350,9 +340,17 @@ end

function compute_gradient_correction_matrix!(corr_matrix::AbstractArray, system,
coordinates, v_ode, u_ode, semi,
correction, smoothing_kernel)
correction; kernel_data=system)
smoothing_kernel = system_smoothing_kernel(kernel_data)

set_zero!(corr_matrix)

# The matrix is assembled from kernel gradients without gradient correction, since the
# gradient-correction matrix is not available before the assembly is finished.
# `MixedKernelGradientCorrection` assembles it from the kernel-corrected gradients.
kernel_correction = correction isa MixedKernelGradientCorrection ? KernelCorrection() :
nothing

# Loop over all pairs of particles and neighbors within the kernel cutoff
@trixi_timeit timer() "compute correction matrix" begin
foreach_system_wrapped(semi, v_ode,
Expand All @@ -364,40 +362,13 @@ function compute_gradient_correction_matrix!(corr_matrix::AbstractArray, system,
end

neighbor_coords = current_coordinates(u_neighbor_system, neighbor_system)
h = initial_smoothing_length(system)

foreach_point_neighbor(system, neighbor_system, coordinates, neighbor_coords,
semi) do particle, neighbor, pos_diff, distance
function kernel_grad_local(correction, smoothing_kernel, pos_diff, distance,
smoothing_length_, system, particle)
return smoothing_kernel_grad_unsafe(system, pos_diff, distance,
particle)
end

# Compute gradient of corrected kernel
function kernel_grad_local(correction::MixedKernelGradientCorrection,
smoothing_kernel, pos_diff, distance,
smoothing_length_, system, particle)
return corrected_kernel_grad_unsafe(smoothing_kernel, pos_diff,
distance,
smoothing_length_,
KernelCorrection(), system,
particle)
end

# Skip neighbors with (almost) the same position because the kernel gradient
# is zero, but computing it would divide by zero (see `almostzero`).
# Note that `return` only exits the closure, i.e., skips the current neighbor.
if skip_zero_distance(correction) && distance < almostzero(h)
return
end

# Now that we know that `distance` is not zero, we can safely call the unsafe
# version of the kernel gradient to avoid redundant zero checks.
smoothing_length_ = smoothing_length(system, particle)
grad_kernel = kernel_grad_local(correction, smoothing_kernel, pos_diff,
distance, smoothing_length_, system,
particle)
grad_kernel = corrected_kernel_grad(smoothing_kernel, pos_diff, distance,
smoothing_length(kernel_data, particle),
kernel_correction, kernel_data,
particle)
iszero(grad_kernel) && return

volume = hydrodynamic_mass(neighbor_system, neighbor) /
current_density(v_neighbor_system, neighbor_system, neighbor)
Expand Down
16 changes: 16 additions & 0 deletions src/general/smoothing_kernels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ end
return false
end

# Safe kernel gradient with an explicit kernel and smoothing length `h`.
# `system` stores the correction values of `particle` (a system or a boundary model).
@inline function corrected_kernel_grad(kernel, pos_diff, distance, h, correction,
system, particle)
compact_support_ = compact_support(kernel, h)

# See `almostzero` for an explanation of the zero distance check
if distance >= compact_support_ ||
(skip_zero_distance(correction) && distance < almostzero(h))
return zero(pos_diff)
end

return corrected_kernel_grad_unsafe(kernel, pos_diff, distance, h, correction,
system, particle)
end

@inline function corrected_kernel_grad_unsafe(kernel, pos_diff, distance, h, correction,
system, particle)
return kernel_grad_unsafe(kernel, pos_diff, distance, h)
Expand Down
Loading
Loading