diff --git a/NEWS.md b/NEWS.md index 72c453d2b5..65418f36a9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 @@ -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 diff --git a/docs/src/systems/boundary.md b/docs/src/systems/boundary.md index 195f1ae857..cc583121f2 100644 --- a/docs/src/systems/boundary.md +++ b/docs/src/systems/boundary.md @@ -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 @@ -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)). diff --git a/docs/src/systems/fluid.md b/docs/src/systems/fluid.md index 805c22b38e..8010745712 100644 --- a/docs/src/systems/fluid.md +++ b/docs/src/systems/fluid.md @@ -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")] diff --git a/docs/src/systems/rigid_body.md b/docs/src/systems/rigid_body.md index 27928499ce..6051358404 100644 --- a/docs/src/systems/rigid_body.md +++ b/docs/src/systems/rigid_body.md @@ -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 diff --git a/docs/src/systems/total_lagrangian_sph.md b/docs/src/systems/total_lagrangian_sph.md index b41db20ba8..2fa4d1c32a 100644 --- a/docs/src/systems/total_lagrangian_sph.md +++ b/docs/src/systems/total_lagrangian_sph.md @@ -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")] diff --git a/src/general/abstract_system.jl b/src/general/abstract_system.jl index 1871d5779e..2c8a4647e0 100644 --- a/src/general/abstract_system.jl +++ b/src/general/abstract_system.jl @@ -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. diff --git a/src/general/corrections.jl b/src/general/corrections.jl index 47973e6934..28824aa614 100644 --- a/src/general/corrections.jl +++ b/src/general/corrections.jl @@ -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. @@ -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 @@ -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) @@ -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 @@ -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] @@ -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) @@ -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, @@ -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) diff --git a/src/general/smoothing_kernels.jl b/src/general/smoothing_kernels.jl index 46de7246e4..ebf035297f 100644 --- a/src/general/smoothing_kernels.jl +++ b/src/general/smoothing_kernels.jl @@ -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) diff --git a/src/schemes/boundary/wall_boundary/dummy_particles.jl b/src/schemes/boundary/wall_boundary/dummy_particles.jl index b8dd014f3a..8a6812f6e9 100644 --- a/src/schemes/boundary/wall_boundary/dummy_particles.jl +++ b/src/schemes/boundary/wall_boundary/dummy_particles.jl @@ -24,7 +24,14 @@ Boundary model for [`WallBoundarySystem`](@ref). # Keywords - `state_equation`: This should be the same as for the adjacent fluid system (see e.g. [`StateEquationCole`](@ref)). -- `correction`: Correction method of the adjacent fluid system (see [Corrections](@ref corrections)). +- `correction`: Correction method at the boundary particles (default: `nothing`, + see [Corrections](@ref corrections)). + It determines the kernel gradient at the boundary particles when the fluid + uses a correction with an asymmetric kernel gradient + (see [Corrections](@ref boundary_corrections)). + For a [`TotalLagrangianSPHSystem`](@ref) or a [`RigidBodySystem`](@ref), + it must be `nothing`, since corrections at the boundary particles + of structures are not supported yet. - `viscosity`: Slip (default) or no-slip condition. See description below for further information. - `clip_negative_pressure=false`: Clip negative boundary pressures to avoid sticking @@ -93,9 +100,11 @@ function BoundaryModelDummyParticles(initial_density, hydrodynamic_mass, @assert length(initial_density) == length(hydrodynamic_mass) n_particles = length(initial_density) + # The correction values use the same element type as the fluid's correction values, + # so that the kernel gradients at the boundary particles don't change the precision. cache = (; create_cache_model(viscosity, n_particles, NDIMS)..., create_cache_model(initial_density, density_calculator, NDIMS)..., - create_cache_model(correction, initial_density, NDIMS, n_particles)...) + create_cache_correction(correction, initial_density, NDIMS, n_particles)...) # If the `reference_density_spacing` is set calculate the `ideal_neighbor_count` if reference_particle_spacing > 0 @@ -117,6 +126,28 @@ end return ndims(boundary_model.smoothing_kernel) end +# The fluid-structure interaction calls `smoothing_kernel_grad(boundary_model, ...)` to +# compute the kernel gradient at the boundary particles of a structure, e.g., in the +# asymmetric pressure acceleration of a fluid with a corrected kernel gradient and in the +# continuity equation of the boundary particles. Like for a system, `smoothing_kernel_grad` +# and `smoothing_kernel_grad_unsafe` then use the smoothing kernel, smoothing length and +# correction of the boundary model together with the correction values below. +# A `TotalLagrangianSPHSystem` has its own kernel and correction matrix for solid mechanics. +@inline system_correction(model::BoundaryModelDummyParticles) = model.correction + +@propagate_inbounds function kernel_correction_coefficient(model::BoundaryModelDummyParticles, + particle) + return model.cache.kernel_correction_coefficient[particle] +end + +@propagate_inbounds function dw_gamma(model::BoundaryModelDummyParticles, particle) + return extract_svector(model.cache.dw_gamma, Val(ndims(model)), particle) +end + +@propagate_inbounds function correction_matrix(model::BoundaryModelDummyParticles, particle) + return extract_smatrix(model.cache.correction_matrix, Val(ndims(model)), particle) +end + @inline function clip_negative_pressure(::BoundaryModelDummyParticles{<:Any, <:Any, CLIP}) where {CLIP} return CLIP end @@ -234,29 +265,6 @@ struct PressureBoundaries{ELTYPE} return new{eltype(time_step)}(time_step, omega) end end -@inline create_cache_model(correction, density, NDIMS, nparticles) = (;) - -function create_cache_model(::ShepardKernelCorrection, density, NDIMS, n_particles) - return (; kernel_correction_coefficient=similar(density)) -end - -function create_cache_model(::KernelCorrection, density, NDIMS, n_particles) - dw_gamma = Array{Float64}(undef, NDIMS, n_particles) - return (; kernel_correction_coefficient=similar(density), dw_gamma) -end - -function create_cache_model(::Union{GradientCorrection, BlendedGradientCorrection}, density, - NDIMS, n_particles) - correction_matrix = Array{Float64, 3}(undef, NDIMS, NDIMS, n_particles) - return (; correction_matrix) -end - -function create_cache_model(::MixedKernelGradientCorrection, density, NDIMS, n_particles) - dw_gamma = Array{Float64}(undef, NDIMS, n_particles) - correction_matrix = Array{Float64, 3}(undef, NDIMS, NDIMS, n_particles) - return (; kernel_correction_coefficient=similar(density), dw_gamma, correction_matrix) -end - function create_cache_model(initial_density::AbstractVector, ::Union{SummationDensity, PressureMirroring, PressureZeroing}, NDIMS) @@ -402,7 +410,7 @@ end compute_pressure!(boundary_model, density_calculator, system, v, u, v_ode, u_ode, semi) # These are only computed when using corrections - compute_correction_values!(system, correction, u, v_ode, u_ode, semi) + compute_correction_values!(boundary_model, system, correction, u, v_ode, u_ode, semi) compute_gradient_correction_matrix!(correction, boundary_model, system, u, v_ode, u_ode, semi) # `kernel_correct_density!` only performed for `SummationDensity` @@ -412,6 +420,32 @@ end return boundary_model end +# Use the system for the coordinates and the neighbor search, and the boundary model for +# the kernel, the smoothing length and the correction values. +function compute_correction_values!(boundary_model::BoundaryModelDummyParticles, system, + correction, u, v_ode, u_ode, semi) + return system +end + +function compute_correction_values!(boundary_model::BoundaryModelDummyParticles, system, + ::ShepardKernelCorrection, u, v_ode, u_ode, semi) + (; cache) = boundary_model + return compute_shepard_coeff!(system, current_coordinates(u, system), v_ode, u_ode, + semi, cache.kernel_correction_coefficient; + kernel_data=boundary_model) +end + +function compute_correction_values!(boundary_model::BoundaryModelDummyParticles, system, + correction::Union{KernelCorrection, + MixedKernelGradientCorrection}, u, + v_ode, u_ode, semi) + (; cache) = boundary_model + return compute_correction_values!(system, correction, current_coordinates(u, system), + v_ode, u_ode, semi, + cache.kernel_correction_coefficient, + cache.dw_gamma; kernel_data=boundary_model) +end + function kernel_correct_density!(boundary_model, v, u, v_ode, u_ode, semi, correction, density_calculator) return boundary_model @@ -432,13 +466,14 @@ function compute_gradient_correction_matrix!(corr::Union{GradientCorrection, MixedKernelGradientCorrection}, boundary_model, system, u, v_ode, u_ode, semi) - (; cache, correction, smoothing_kernel) = boundary_model + (; cache, correction) = boundary_model (; correction_matrix) = cache system_coords = current_coordinates(u, system) compute_gradient_correction_matrix!(correction_matrix, system, system_coords, - v_ode, u_ode, semi, correction, smoothing_kernel) + v_ode, u_ode, semi, correction; + kernel_data=boundary_model) end function compute_density!(boundary_model, ::SummationDensity, system, v, u, v_ode, u_ode, diff --git a/src/schemes/fluid/entropically_damped_sph/rhs.jl b/src/schemes/fluid/entropically_damped_sph/rhs.jl index 9350d7f354..2f6aee2c3b 100644 --- a/src/schemes/fluid/entropically_damped_sph/rhs.jl +++ b/src/schemes/fluid/entropically_damped_sph/rhs.jl @@ -97,13 +97,16 @@ end # Note that this function is also used for the structure-fluid interaction to compute # the exact opposite pair force. When adding new terms here, make sure that they are # also valid for structure neighbors. +# `grad_kernel_neighbor` is the kernel gradient of the neighbor for the asymmetric pressure +# acceleration if it has already been computed, or `nothing` (see `pressure_acceleration`). @propagate_inbounds function add_momentum_equation(dv_particle, particle_system::EntropicallyDampedSPHSystem, neighbor_system, v_particle_system, v_neighbor_system, particle, neighbor, pos_diff, distance, grad_kernel, sound_speed, m_a, m_b, - p_a, p_b, rho_a, rho_b, v_a, v_b) + p_a, p_b, rho_a, rho_b, v_a, v_b, + grad_kernel_neighbor=nothing) (; correction) = particle_system surface_tension_a = surface_tension_model(particle_system) @@ -121,7 +124,7 @@ end particle, neighbor, m_a, m_b, p_a - p_avg, p_b - p_avg, rho_a, rho_b, pos_diff, distance, grad_kernel, - correction) + correction, grad_kernel_neighbor) dv_particle = add_dv_viscosity(dv_particle, particle_system, neighbor_system, v_particle_system, v_neighbor_system, diff --git a/src/schemes/fluid/implicit_incompressible_sph/rhs.jl b/src/schemes/fluid/implicit_incompressible_sph/rhs.jl index 21feadd4c8..e0bd256240 100644 --- a/src/schemes/fluid/implicit_incompressible_sph/rhs.jl +++ b/src/schemes/fluid/implicit_incompressible_sph/rhs.jl @@ -71,13 +71,16 @@ end # Note that this function is also used for the structure-fluid interaction to compute # the exact opposite pair force. When adding new terms here, make sure that they are # also valid for structure neighbors. +# `grad_kernel_neighbor` is only used by systems with an asymmetric kernel gradient +# (see `pressure_acceleration`). @propagate_inbounds function add_momentum_equation(dv_particle, particle_system::ImplicitIncompressibleSPHSystem, neighbor_system, v_particle_system, v_neighbor_system, particle, neighbor, pos_diff, distance, grad_kernel, sound_speed, m_a, m_b, - p_a, p_b, rho_a, rho_b, v_a, v_b) + p_a, p_b, rho_a, rho_b, v_a, v_b, + grad_kernel_neighbor=nothing) dv_particle += pressure_acceleration(particle_system, neighbor_system, particle, neighbor, m_a, m_b, p_a, p_b, rho_a, rho_b, pos_diff, diff --git a/src/schemes/fluid/pressure_acceleration.jl b/src/schemes/fluid/pressure_acceleration.jl index b6114c0bc1..185bdcbe30 100644 --- a/src/schemes/fluid/pressure_acceleration.jl +++ b/src/schemes/fluid/pressure_acceleration.jl @@ -168,3 +168,13 @@ end return pressure_acceleration_formulation(particle_system)(m_a, m_b, rho_a, rho_b, p_a, p_b, W_a, W_b) end + +# The last argument is the kernel gradient `W_b` of the neighbor if it has already been +# computed (see `interact_structure_fluid!`), or `nothing` to compute it when required. +@inline function pressure_acceleration(particle_system, neighbor_system, particle, neighbor, + m_a, m_b, p_a, p_b, rho_a, rho_b, pos_diff, + distance, W_a, correction, W_b::Nothing) + return pressure_acceleration(particle_system, neighbor_system, particle, neighbor, + m_a, m_b, p_a, p_b, rho_a, rho_b, pos_diff, distance, + W_a, correction) +end diff --git a/src/schemes/fluid/weakly_compressible_sph/density_diffusion.jl b/src/schemes/fluid/weakly_compressible_sph/density_diffusion.jl index 281f6372f5..83acc368e3 100644 --- a/src/schemes/fluid/weakly_compressible_sph/density_diffusion.jl +++ b/src/schemes/fluid/weakly_compressible_sph/density_diffusion.jl @@ -193,7 +193,10 @@ function update!(density_diffusion::DensityDiffusionAntuono, v, u, system, semi) rho_a = @inbounds current_density(v, system, particle) rho_b = @inbounds current_density(v, system, neighbor) - grad_kernel = smoothing_kernel_grad(system, pos_diff, distance, particle) + # The renormalized density gradient uses the uncorrected kernel gradient, + # like the matrix `L` above (see the docstring of `DensityDiffusionAntuono`). + grad_kernel = kernel_grad(system_smoothing_kernel(system), pos_diff, distance, + smoothing_length(system, particle)) L = @inbounds extract_smatrix(density_diffusion_correction_matrix, system, particle) diff --git a/src/schemes/fluid/weakly_compressible_sph/rhs.jl b/src/schemes/fluid/weakly_compressible_sph/rhs.jl index 068001228b..bd4e10b0db 100644 --- a/src/schemes/fluid/weakly_compressible_sph/rhs.jl +++ b/src/schemes/fluid/weakly_compressible_sph/rhs.jl @@ -124,13 +124,16 @@ end # Note that this function is also used for the structure-fluid interaction to compute # the exact opposite pair force. When adding new terms here, make sure that they are # also valid for structure neighbors. +# `grad_kernel_neighbor` is the kernel gradient of the neighbor for the asymmetric pressure +# acceleration if it has already been computed, or `nothing` (see `pressure_acceleration`). @propagate_inbounds function add_momentum_equation(dv_particle, particle_system::WeaklyCompressibleSPHSystem, neighbor_system, v_particle_system, v_neighbor_system, particle, neighbor, pos_diff, distance, grad_kernel, sound_speed, m_a, m_b, - p_a, p_b, rho_a, rho_b, v_a, v_b) + p_a, p_b, rho_a, rho_b, v_a, v_b, + grad_kernel_neighbor=nothing) (; correction) = particle_system surface_tension_a = surface_tension_model(particle_system) @@ -147,7 +150,8 @@ end dv_pressure = pressure_acceleration(particle_system, neighbor_system, particle, neighbor, m_a, m_b, p_a, p_b, rho_a, rho_b, pos_diff, - distance, grad_kernel, correction) + distance, grad_kernel, correction, + grad_kernel_neighbor) dv_particle += dv_pressure * pressure_correction dv_particle = add_dv_viscosity(dv_particle, particle_system, neighbor_system, diff --git a/src/schemes/fluid/weakly_compressible_sph/system.jl b/src/schemes/fluid/weakly_compressible_sph/system.jl index eea0607d7d..67905baa0a 100644 --- a/src/schemes/fluid/weakly_compressible_sph/system.jl +++ b/src/schemes/fluid/weakly_compressible_sph/system.jl @@ -369,13 +369,13 @@ function compute_gradient_correction_matrix!(corr::Union{GradientCorrection, MixedKernelGradientCorrection}, system::WeaklyCompressibleSPHSystem, u, v_ode, u_ode, semi) - (; cache, correction, smoothing_kernel) = system + (; cache, correction) = system (; correction_matrix) = cache system_coords = current_coordinates(u, system) compute_gradient_correction_matrix!(correction_matrix, system, system_coords, - v_ode, u_ode, semi, correction, smoothing_kernel) + v_ode, u_ode, semi, correction) end function reinit_density!(vu_ode, semi) diff --git a/src/schemes/structure/rigid_body/system.jl b/src/schemes/structure/rigid_body/system.jl index 74222d7970..b0cb233625 100644 --- a/src/schemes/structure/rigid_body/system.jl +++ b/src/schemes/structure/rigid_body/system.jl @@ -20,6 +20,9 @@ torque and applied consistently to all rigid particles. # Keywords - `boundary_model`: Boundary model for fluid-structure interaction (see [Boundary Models](@ref boundary_models)). + For [`BoundaryModelDummyParticles`](@ref), `correction` must be `nothing`, + since corrections at the boundary particles of structures are not + supported yet. - `contact_model`: Optional rigid contact model. If specified, rigid-wall and rigid-rigid collisions are enabled. - `acceleration`: Global acceleration vector applied to all rigid particles. @@ -624,6 +627,8 @@ function check_configuration(system::RigidBodySystem, systems, nhs) end end + check_boundary_model_correction(system, boundary_model) + foreach_system(systems) do neighbor if neighbor isa AbstractFluidSystem && boundary_model === nothing throw(ArgumentError("a boundary model for `RigidBodySystem` must be specified " * diff --git a/src/schemes/structure/structure.jl b/src/schemes/structure/structure.jl index df3d2a2375..f17a0bc1ee 100644 --- a/src/schemes/structure/structure.jl +++ b/src/schemes/structure/structure.jl @@ -17,6 +17,65 @@ end end end +@inline function pressure_acceleration(particle_system, + neighbor_system::Union{TotalLagrangianSPHSystem{<:BoundaryModelDummyParticles}, + RigidBodySystem{<:BoundaryModelDummyParticles}}, + particle, neighbor, m_a, m_b, p_a, p_b, rho_a, rho_b, + pos_diff, distance, W_a, + correction::Union{KernelCorrection, + GradientCorrection, + BlendedGradientCorrection, + MixedKernelGradientCorrection}) + # `W_a` is the kernel gradient at the fluid particle (kernel and correction of the + # fluid). `W_b` is the kernel gradient at the structure particle, which uses the + # kernel, smoothing length and correction of the boundary model of the structure + # and not the smoothing kernel of the `TotalLagrangianSPHSystem` for solid mechanics. + W_b = smoothing_kernel_grad(neighbor_system.boundary_model, -pos_diff, distance, + neighbor) + + return pressure_acceleration(particle_system, neighbor_system, particle, neighbor, + m_a, m_b, p_a, p_b, rho_a, rho_b, pos_diff, distance, + W_a, correction, W_b) +end + +# Same as above, but with the kernel gradient `W_b` at the structure particle already +# computed. The structure-fluid interaction computes it once for the pressure acceleration +# and the continuity equation of the boundary particles. +@inline function pressure_acceleration(particle_system, + neighbor_system::Union{TotalLagrangianSPHSystem{<:BoundaryModelDummyParticles}, + RigidBodySystem{<:BoundaryModelDummyParticles}}, + particle, neighbor, m_a, m_b, p_a, p_b, rho_a, rho_b, + pos_diff, distance, W_a, + correction::Union{KernelCorrection, + GradientCorrection, + BlendedGradientCorrection, + MixedKernelGradientCorrection}, + W_b::AbstractVector) + # With correction, the kernel gradient is not necessarily symmetric, so call the + # asymmetric version of the pressure acceleration formulation. + return pressure_acceleration_formulation(particle_system)(m_a, m_b, rho_a, rho_b, + p_a, p_b, W_a, W_b) +end + +# Kernel gradient at the structure particle that is required by the pressure acceleration +# of a fluid with an asymmetric corrected kernel gradient (see above). +# It is `nothing` when the pressure acceleration doesn't require it. +@inline function boundary_pressure_kernel_grad(fluid_correction, particle_system, + pos_diff, distance, particle) + return nothing +end + +@inline function boundary_pressure_kernel_grad(::Union{KernelCorrection, + GradientCorrection, + BlendedGradientCorrection, + MixedKernelGradientCorrection}, + particle_system::Union{TotalLagrangianSPHSystem{<:BoundaryModelDummyParticles}, + RigidBodySystem{<:BoundaryModelDummyParticles}}, + pos_diff, distance, particle) + return smoothing_kernel_grad(particle_system.boundary_model, pos_diff, distance, + particle) +end + # Both FSI directions must find the same particle pairs and use matching boundary and # fluid kernels. The TLSPH kernel for solid mechanics may differ. # Note that this is only a restriction for `BoundaryModelDummyParticles`, since @@ -41,6 +100,26 @@ end check_smoothing_kernel_fsi(system, boundary_model, neighbor_system) = system +# The correction values of a boundary particle are sums over its complete hydrodynamic +# neighborhood in the current configuration, including the particles of its own structure +# within the compact support of the boundary model. The neighborhood searches of structures +# don't provide this neighborhood (the TLSPH self-interaction uses the TLSPH kernel in the +# initial configuration and rigid bodies only search for contact), so corrections of the +# boundary model of a structure are not supported yet. +# Without correction, the kernel gradient of the boundary model also vanishes at zero +# distance (see `interact_structure_fluid!`). +function check_boundary_model_correction(system, + boundary_model::BoundaryModelDummyParticles) + if !isnothing(boundary_model.correction) + throw(ArgumentError("the boundary model of a `$(nameof(typeof(system)))` does " * + "not support corrections yet. Use `correction=nothing`.")) + end + + return system +end + +check_boundary_model_correction(system, boundary_model) = system + function interact_structure_fluid!(dv, v_particle_system, u_particle_system, v_neighbor_system, u_neighbor_system, particle_system, @@ -56,13 +135,16 @@ function interact_structure_fluid!(dv, v_particle_system, u_particle_system, foreach_point_neighbor(particle_system, neighbor_system, system_coords, neighbor_coords, semi; points=eachparticle) do particle, neighbor, pos_diff, distance - # Skip neighbors with (almost) the same position because the kernel gradient - # is zero, but computing it would divide by zero (see `almostzero`). + # Skip neighbors with (almost) the same position if the fluid gradient vanishes, + # because computing it would divide by zero (see `almostzero`). The boundary + # gradient also vanishes in this case (see `check_boundary_model_correction`). # Note that `return` only exits the closure, i.e., skips the current neighbor. - skip_zero_distance(neighbor_system) && distance < almostzero(h) && return + if skip_zero_distance(neighbor_system) && 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. + # Now we can safely call the unsafe version of the kernel gradient to avoid + # redundant zero checks. # Evaluate the gradient exactly as in the fluid-structure interaction, i.e., # with the fluid particle's kernel and correction and the fluid-first displacement. # Note that we cannot just flip the sign of the structure-first gradient, since @@ -88,6 +170,16 @@ function interact_structure_fluid!(dv, v_particle_system, u_particle_system, p_a = current_pressure(v_particle_system, particle_system, particle) p_b = current_pressure(v_neighbor_system, neighbor_system, neighbor) + # The kernel gradient of the boundary model at the structure particle is required + # by the pressure acceleration of a fluid with an asymmetric corrected kernel + # gradient and by the continuity equation of the boundary particles. + # When the pressure acceleration requires it, compute it only once for both. + # Here `pos_diff` is `x_structure - x_fluid`, matching the displacement + # passed to the boundary model in the fluid-structure interaction. + grad_kernel_boundary = boundary_pressure_kernel_grad(system_correction(neighbor_system), + particle_system, pos_diff, + distance, particle) + # Compute the acceleration of the fluid particle due to the structure particle # with the exact same function as in the fluid-structure interaction. # Particle and neighbor (and the corresponding systems and particle quantities) @@ -103,7 +195,7 @@ function interact_structure_fluid!(dv, v_particle_system, u_particle_system, v_neighbor_system, v_particle_system, neighbor, particle, -pos_diff, distance, grad_kernel_fluid, sound_speed, m_b, m_a, p_b, p_a, - rho_b, rho_a, v_b, v_a) + rho_b, rho_a, v_b, v_a, grad_kernel_boundary) dv_particle = -dv_fluid accumulate_structure_fluid_pair!(dv, dv_particle, particle_system, particle, m_b) @@ -112,7 +204,7 @@ function interact_structure_fluid!(dv, v_particle_system, u_particle_system, particle_system, neighbor_system, particle, neighbor, pos_diff, distance, m_b, rho_a, rho_b, v_a, v_b, - grad_kernel_fluid) + grad_kernel_fluid, grad_kernel_boundary) @inbounds write_drho_particle!(dv, particle_system, drho_particle, particle) end @@ -124,60 +216,37 @@ end particle_system::AbstractStructureSystem, neighbor_system::AbstractFluidSystem, particle, neighbor, pos_diff, distance, - m_b, rho_a, rho_b, v_a, v_b, grad_kernel_fluid) + m_b, rho_a, rho_b, v_a, v_b, grad_kernel_fluid, + grad_kernel_boundary) return drho_particle end +# `grad_kernel_boundary` is the kernel gradient of the boundary model at the structure +# particle if it has already been computed for the pressure acceleration, or `nothing`. @inline function add_continuity_equation(drho_particle, - particle_system::Union{RigidBodySystem{<:BoundaryModelDummyParticles{ContinuityDensity}}, - TotalLagrangianSPHSystem{<:BoundaryModelDummyParticles{ContinuityDensity}}}, + particle_system::RigidBodySystem{<:BoundaryModelDummyParticles{ContinuityDensity}}, neighbor_system::AbstractFluidSystem, particle, neighbor, pos_diff, distance, - m_b, rho_a, rho_b, v_a, v_b, grad_kernel_fluid) - (; boundary_model) = particle_system - - # As for a `WallBoundarySystem`, the density of the boundary particles evolves with - # the boundary model's kernel gradient and not with the corrected fluid gradient. - grad_kernel = boundary_continuity_kernel_grad(system_correction(neighbor_system), - boundary_model.correction, - boundary_model, pos_diff, distance, - particle, grad_kernel_fluid) + m_b, rho_a, rho_b, v_a, v_b, grad_kernel_fluid, + grad_kernel_boundary) + # The boundary model is uncorrected and its kernel and smoothing length match the + # fluid's (see `check_boundary_model_correction` and `check_smoothing_kernel_fsi`). + # If the fluid uses an asymmetric corrected gradient, reuse the boundary gradient + # computed for the pressure acceleration. Otherwise, reverse the fluid gradient. + grad_kernel = isnothing(grad_kernel_boundary) ? -grad_kernel_fluid : + grad_kernel_boundary return add_continuity_equation(drho_particle, density_calculator(neighbor_system), m_b, rho_a, rho_b, v_a, v_b, grad_kernel, particle) end -@inline function boundary_continuity_kernel_grad(fluid_correction, boundary_correction, - boundary_model, pos_diff, distance, - particle, grad_kernel_fluid) - # Use the boundary model's kernel and smoothing length, which may differ from - # the TLSPH kernel for solid mechanics. - # The safe version also returns zero for coincident particles. - return smoothing_kernel_grad(boundary_model, pos_diff, distance, particle) -end - -@inline function boundary_continuity_kernel_grad(::Union{Nothing, - AkinciFreeSurfaceCorrection, - ShepardKernelCorrection}, - ::Union{Nothing, - AkinciFreeSurfaceCorrection, - ShepardKernelCorrection}, - boundary_model, pos_diff, distance, - particle, grad_kernel_fluid) - # Neither correction changes the gradient, and the boundary model's kernel and - # smoothing length match the fluid's (see `check_smoothing_kernel_fsi`). - # Reversing the displacement only flips the sign of the uncorrected gradient. - return -grad_kernel_fluid -end - @inline function write_drho_particle!(dv, ::AbstractSystem, drho_particle, particle) return dv end @propagate_inbounds function write_drho_particle!(dv, - ::Union{RigidBodySystem{<:BoundaryModelDummyParticles{ContinuityDensity}}, - TotalLagrangianSPHSystem{<:BoundaryModelDummyParticles{ContinuityDensity}}}, + ::RigidBodySystem{<:BoundaryModelDummyParticles{ContinuityDensity}}, drho_particle, particle) dv[end, particle] += drho_particle diff --git a/src/schemes/structure/total_lagrangian_sph/rhs.jl b/src/schemes/structure/total_lagrangian_sph/rhs.jl index 49f29db990..1b882f763d 100644 --- a/src/schemes/structure/total_lagrangian_sph/rhs.jl +++ b/src/schemes/structure/total_lagrangian_sph/rhs.jl @@ -93,8 +93,6 @@ end for i in 1:ndims(system) @inbounds dv[i, particle] += dv_particle_[i] end - - # TODO continuity equation for boundary model with `ContinuityDensity`? end return dv @@ -117,6 +115,5 @@ function interact!(dv, v_particle_system, u_particle_system, particle_system::TotalLagrangianSPHSystem, neighbor_system::Union{WallBoundarySystem, OpenBoundarySystem}, semi; eachparticle=each_integrated_particle(particle_system)) - # TODO continuity equation? return dv end diff --git a/src/schemes/structure/total_lagrangian_sph/system.jl b/src/schemes/structure/total_lagrangian_sph/system.jl index 9a345c96ca..f68c35963f 100644 --- a/src/schemes/structure/total_lagrangian_sph/system.jl +++ b/src/schemes/structure/total_lagrangian_sph/system.jl @@ -33,6 +33,9 @@ See [Total Lagrangian SPH](@ref tlsph) for more details on the method. See [`PrescribedMotion`](@ref) for details. - `boundary_model`: Boundary model to compute the hydrodynamic density and pressure for fluid-structure interaction (see [Boundary Models](@ref boundary_models)). + For [`BoundaryModelDummyParticles`](@ref), [`ContinuityDensity`](@ref) + is not supported and `correction` must be `nothing`, since corrections + at the boundary particles of structures are not supported yet. - `penalty_force`: Penalty force to ensure regular particle position under large deformations (see [`PenaltyForceGanzenmueller`](@ref)). - `viscosity`: Artificial viscosity model to stabilize both the TLSPH and the FSI. @@ -121,6 +124,11 @@ function TotalLagrangianSPHSystem(initial_condition; smoothing_kernel, smoothing throw(ArgumentError("smoothing kernel dimensionality must be $NDIMS for a $(NDIMS)D problem")) end + if boundary_model isa BoundaryModelDummyParticles{ContinuityDensity} + throw(ArgumentError("`BoundaryModelDummyParticles` with density calculator " * + "`ContinuityDensity` is not supported for a `TotalLagrangianSPHSystem`")) + end + # Make acceleration an SVector acceleration_ = SVector(acceleration...) if length(acceleration_) != NDIMS @@ -294,10 +302,6 @@ end return ndims(system) end -@inline function v_nvariables(system::TotalLagrangianSPHSystem{<:BoundaryModelDummyParticles{ContinuityDensity}}) - return ndims(system) + 1 -end - @inline function n_integrated_particles(system::TotalLagrangianSPHSystem) system.n_integrated_particles end @@ -628,31 +632,12 @@ function write_u0!(u0, system::TotalLagrangianSPHSystem) end function write_v0!(v0, system::TotalLagrangianSPHSystem) - (; initial_condition, boundary_model) = system + (; initial_condition) = system # This is as fast as a loop with `@inbounds`, but it's GPU-compatible indices = CartesianIndices((ndims(system), each_integrated_particle(system))) copyto!(v0, indices, initial_condition.velocity, indices) - write_v0!(v0, boundary_model, system) - - return v0 -end - -function write_v0!(v0, model, system::TotalLagrangianSPHSystem) - return v0 -end - -function write_v0!(v0, ::BoundaryModelDummyParticles{ContinuityDensity}, - system::TotalLagrangianSPHSystem) - (; cache) = system.boundary_model - (; initial_density) = cache - - for particle in each_integrated_particle(system) - # Set particle densities - v0[ndims(system) + 1, particle] = initial_density[particle] - end - return v0 end @@ -863,11 +848,7 @@ function check_configuration(system::TotalLagrangianSPHSystem, systems, nhs) end end - if boundary_model isa BoundaryModelDummyParticles && - boundary_model.density_calculator isa ContinuityDensity - throw(ArgumentError("`BoundaryModelDummyParticles` with density calculator " * - "`ContinuityDensity` is not yet supported for a `TotalLagrangianSPHSystem`")) - end + check_boundary_model_correction(system, boundary_model) foreach_system(systems) do neighbor check_smoothing_kernel_fsi(system, boundary_model, neighbor) diff --git a/test/general/corrections.jl b/test/general/corrections.jl new file mode 100644 index 0000000000..eebeb0332d --- /dev/null +++ b/test/general/corrections.jl @@ -0,0 +1,91 @@ +@testset verbose=true "Corrections" begin + @testset "Gradient correction matrix of a fluid system" begin + kernel = SchoenbergCubicSplineKernel{2}() + state_equation = StateEquationCole(; sound_speed=10.0, reference_density=1000.0, + exponent=1.0) + + # Independent formulas of the cubic spline kernel for ``h = 1`` (compact support 2) + W(r) = 10 / (7pi) * (r < 1 ? 1 - 1.5r^2 + 0.75r^3 : r < 2 ? 0.25(2 - r)^3 : 0.0) + function grad_W(pos_diff) + r = norm(pos_diff) + (iszero(r) || r >= 2) && return zero(pos_diff) + derivative = 10 / (7pi) * (r < 1 ? -3r + 2.25r^2 : -0.75(2 - r)^2) + return derivative / r * pos_diff + end + + # Irregular neighborhoods, so that the correction matrices are far from the identity. + # The first and the last particle are outside of the support of each other. + coordinates = [0.0 0.8 1.7 0.3 1.1 2.1; 0.0 0.1 0.2 0.9 1.0 1.2] + mass = [1.0, 1.1, 0.9, 1.2, 1.0, 0.8] + density = [1000.0, 1010.0, 990.0, 1005.0, 995.0, 1000.0] + volumes = mass ./ density + positions = [SVector{2}(coordinates[:, i]) for i in axes(coordinates, 2)] + + # Gradient of the kernel correction of particle `a` at displacement `pos_diff` + # to particle `b` (`k` is the kernel correction coefficient and `gamma` the vector + # ``\sum_b V_b \nabla W_b / k``). + function reference(a) + pos_diffs = [positions[a] - x for x in positions] + kernel_values = W.(norm.(pos_diffs)) + gradients = grad_W.(pos_diffs) + k = dot(volumes, kernel_values) + gamma = sum(volumes .* gradients) / k + kernel_corrected = [(g - w * gamma) / k + for (g, w) in zip(gradients, kernel_values)] + return (; pos_diffs, kernel_values, gradients, k, gamma, kernel_corrected) + end + + # ``L = (-\sum_b V_b \nabla W_b \otimes r_{ab})^{-1}`` + function inverse_moment(volumes, gradients, pos_diffs) + return inv(-sum(v * g * transpose(d) + for (v, g, d) in zip(volumes, gradients, pos_diffs))) + end + + @testset "$(nameof(typeof(correction)))" for correction in + (GradientCorrection(), + BlendedGradientCorrection(0.3), + MixedKernelGradientCorrection()) + ic = InitialCondition(; coordinates, mass, density, particle_spacing=1.0) + system = WeaklyCompressibleSPHSystem(ic; smoothing_kernel=kernel, + smoothing_length=1.0, state_equation, + density_calculator=ContinuityDensity(), + correction) + semi = Semidiscretization(system; parallelization_backend=SerialBackend()) + ode = semidiscretize(semi, (0.0, 0.01)) + v_ode, u_ode = ode.u0.x + TrixiParticles.update_systems_and_nhs(v_ode, u_ode, semi, 0.0) + + for a in axes(coordinates, 2) + (; pos_diffs, gradients, kernel_corrected) = reference(a) + + # The matrix is assembled from the gradient without gradient correction, + # but with kernel correction for `MixedKernelGradientCorrection`. + matrix_gradients = correction isa MixedKernelGradientCorrection ? + kernel_corrected : gradients + L = inverse_moment(volumes, matrix_gradients, pos_diffs) + + # The matrix must not be the identity matrix + @test !isapprox(L, I(2), atol=0.1) + @test isapprox(system.cache.correction_matrix[:, :, a], L, + rtol=1e-14, atol=eps()) + end + + # Corrected kernel gradient of particle 1 with respect to particle 2 + (; gradients, kernel_corrected) = reference(1) + L = system.cache.correction_matrix[:, :, 1] + grad_kernel = TrixiParticles.smoothing_kernel_grad(system, + positions[1] - + positions[2], + norm(positions[1] - + positions[2]), 1) + expected = if correction isa GradientCorrection + L * gradients[2] + elseif correction isa BlendedGradientCorrection + 0.7 * gradients[2] + 0.3 * L * gradients[2] + else + L * kernel_corrected[2] + end + @test isapprox(grad_kernel, expected, rtol=1e-14, atol=eps()) + end + end +end diff --git a/test/general/general.jl b/test/general/general.jl index 64d129da3c..e6e96b248e 100644 --- a/test/general/general.jl +++ b/test/general/general.jl @@ -1,5 +1,6 @@ include("initial_condition.jl") include("smoothing_kernels.jl") +include("corrections.jl") include("density_calculator.jl") include("semidiscretization.jl") include("interpolation.jl") diff --git a/test/general/semidiscretization.jl b/test/general/semidiscretization.jl index fe829bf405..026fe1992f 100644 --- a/test/general/semidiscretization.jl +++ b/test/general/semidiscretization.jl @@ -188,19 +188,6 @@ fluid_system; neighborhood_search=nothing) - if structure_type === TotalLagrangianSPHSystem - boundary_model = BoundaryModelDummyParticles(ic.density, ic.mass, - ContinuityDensity(), - smoothing_kernel, - smoothing_length) - structure = create_structure_system(structure_type, boundary_model) - error_str = "`BoundaryModelDummyParticles` with density calculator " * - "`ContinuityDensity` is not yet supported for a `TotalLagrangianSPHSystem`" - @test_throws ArgumentError(error_str) Semidiscretization(structure, - fluid_system; - neighborhood_search=nothing) - end - @testset "$name" for (name, boundary_kernel, boundary_length, compatible) in boundary_configurations @@ -223,6 +210,47 @@ end end end + + # Corrections at the boundary particles of structures are not supported yet, + # independently of the fluid correction and of whether a fluid is present. + boundary_corrections = (ShepardKernelCorrection(), + AkinciFreeSurfaceCorrection(1000.0), + KernelCorrection(), GradientCorrection(), + BlendedGradientCorrection(0.3), + MixedKernelGradientCorrection()) + @testset "Corrections, $structure_type" for structure_type in + (TotalLagrangianSPHSystem, + RigidBodySystem) + fluid = WeaklyCompressibleSPHSystem(ic; smoothing_kernel, + smoothing_length, state_equation, + density_calculator=ContinuityDensity(), + correction=KernelCorrection()) + boundary_model = BoundaryModelDummyParticles(ic.density, ic.mass, + AdamiPressureExtrapolation(), + smoothing_kernel, + smoothing_length; + state_equation) + structure = create_structure_system(structure_type, boundary_model) + @test_nowarn Semidiscretization(fluid, structure; + neighborhood_search=nothing) + + error_str = "the boundary model of a `$structure_type` does not " * + "support corrections yet. Use `correction=nothing`." + for boundary_correction in boundary_corrections + boundary_model = BoundaryModelDummyParticles(ic.density, ic.mass, + AdamiPressureExtrapolation(), + smoothing_kernel, + smoothing_length; + state_equation, + correction=boundary_correction) + structure = create_structure_system(structure_type, boundary_model) + @test_throws ArgumentError(error_str) Semidiscretization(fluid, + structure; + neighborhood_search=nothing) + @test_throws ArgumentError(error_str) Semidiscretization(structure; + neighborhood_search=nothing) + end + end end @testset verbose=true "WCSPH-Boundary Interaction" begin diff --git a/test/schemes/boundary/dummy_particles/dummy_particles.jl b/test/schemes/boundary/dummy_particles/dummy_particles.jl index ef997a1ed6..b781668323 100644 --- a/test/schemes/boundary/dummy_particles/dummy_particles.jl +++ b/test/schemes/boundary/dummy_particles/dummy_particles.jl @@ -67,6 +67,34 @@ @test boundary_model_adami_no_clip.pressure[1] == -1 end + # The correction values must have the element type of the density. Otherwise, the + # kernel gradients at the boundary particles would change the precision of the + # pressure acceleration of a `Float32` simulation, e.g., on GPUs. + @testset "Correction Cache Element Type `$(nameof(typeof(correction)))`" for correction in + (ShepardKernelCorrection(), + KernelCorrection(), + GradientCorrection(), + BlendedGradientCorrection(0.5f0), + MixedKernelGradientCorrection()) + smoothing_kernel = SchoenbergCubicSplineKernel{2}() + boundary_model = BoundaryModelDummyParticles([1000.0f0, 1000.0f0], [1.0f0, 1.0f0], + AdamiPressureExtrapolation(), + smoothing_kernel, 0.1f0; correction) + (; cache) = boundary_model + + for field in (:kernel_correction_coefficient, :dw_gamma, :correction_matrix) + haskey(cache, field) || continue + @test eltype(getproperty(cache, field)) == Float32 + fill!(getproperty(cache, field), 1) + end + + pos_diff = SVector(0.05f0, 0.02f0) + grad_kernel = TrixiParticles.smoothing_kernel_grad(boundary_model, pos_diff, + norm(pos_diff), 1) + @test eltype(grad_kernel) == Float32 + @test !iszero(grad_kernel) + end + @testset "Bernoulli dynamic pressure" begin smoothing_kernel = SchoenbergCubicSplineKernel{2}() smoothing_length = 1.0 diff --git a/test/schemes/boundary/dummy_particles/rhs.jl b/test/schemes/boundary/dummy_particles/rhs.jl index 02816e489a..c848e1533e 100644 --- a/test/schemes/boundary/dummy_particles/rhs.jl +++ b/test/schemes/boundary/dummy_particles/rhs.jl @@ -76,14 +76,13 @@ v_boundary_continuity = copy(initial_condition.density') - # TLSPH system - structure_system = TotalLagrangianSPHSystem(initial_condition; smoothing_kernel, - smoothing_length, young_modulus=0.0, - poisson_ratio=0.0, - boundary_model=boundary_model_continuity) - - # Positions of the structure particles are not used here - u_structure = zeros(0, TrixiParticles.nparticles(structure_system)) + # Rigid body. A `TotalLagrangianSPHSystem` doesn't support `ContinuityDensity` + # for its boundary model. + structure_system = RigidBodySystem(initial_condition; + boundary_model=boundary_model_continuity) + + # The coordinates of a rigid body are stored in `u` + u_structure = copy(initial_condition.coordinates) v_structure = vcat(initial_condition.velocity, initial_condition.density') @@ -91,7 +90,7 @@ "Fluid-Fluid" => second_fluid_system, "Fluid-BoundaryDummyPressureZeroing" => boundary_system_zeroing, "Fluid-BoundaryDummyContinuityDensity" => boundary_system_continuity, - "Fluid-TLSPH" => structure_system + "Fluid-RigidBody" => structure_system ) if density_calculator isa SummationDensity @@ -106,7 +105,7 @@ "Fluid-BoundaryDummyContinuityDensity" => (v_boundary_continuity, u_boundary), "Fluid-BoundaryDummySummationDensity" => (v_boundary, u_boundary), - "Fluid-TLSPH" => (v_structure, u_structure) + "Fluid-RigidBody" => (v_structure, u_structure) ) return systems, vu @@ -197,6 +196,15 @@ TrixiParticles.interact!(dv_neighbor, v_neighbor, u_neighbor, v, u, neighbor_system, fluid_system, semi) + if neighbor_system isa RigidBodySystem + # A rigid body accumulates the forces on its particles instead of + # their accelerations + (; force_per_particle, boundary_model) = neighbor_system + NDIMS = ndims(neighbor_system) + mass = boundary_model.hydrodynamic_mass + dv_neighbor[1:NDIMS, :] .= force_per_particle ./ mass' + end + if neighbor_system isa WeaklyCompressibleSPHSystem # If both are fluids, neighbor-neighbor interaction is necessary # for energy preservation. diff --git a/test/schemes/fluid/rhs.jl b/test/schemes/fluid/rhs.jl index cad35f838d..fc4c568da2 100644 --- a/test/schemes/fluid/rhs.jl +++ b/test/schemes/fluid/rhs.jl @@ -281,8 +281,9 @@ exponent=1) function create_fluid_system(scheme, velocity, density, viscosity; - shifting_technique=nothing, correction=nothing) - fluid = InitialCondition(; coordinates=zeros(2, 1), + shifting_technique=nothing, correction=nothing, + coordinates=zeros(2, 1)) + fluid = InitialCondition(; coordinates, velocity=reshape(collect(velocity), 2, 1), mass=[fluid_density * particle_spacing^2], density=[density], pressure=state_equation(density), @@ -308,7 +309,9 @@ function create_structure_system(structure_type, viscosity; boundary_density=AdamiPressureExtrapolation(), boundary_correction=nothing, + boundary_initial_density=fluid_density, clamped=false, + structure_smoothing_kernel=smoothing_kernel, structure_smoothing_length=smoothing_length) # The material mass is twice the hydrodynamic mass, so using the wrong mass # to convert the force on the structure to an acceleration fails the test. @@ -316,7 +319,7 @@ velocity=zeros(2, 1), mass=[2 * fluid_density * particle_spacing^2], density=[2 * fluid_density], particle_spacing) - boundary_model = BoundaryModelDummyParticles([fluid_density], + boundary_model = BoundaryModelDummyParticles([boundary_initial_density], [fluid_density * particle_spacing^2], boundary_density, @@ -326,7 +329,8 @@ correction=boundary_correction) if structure_type === TotalLagrangianSPHSystem - return TotalLagrangianSPHSystem(structure; smoothing_kernel, + return TotalLagrangianSPHSystem(structure; + smoothing_kernel=structure_smoothing_kernel, smoothing_length=structure_smoothing_length, young_modulus=1e5, poisson_ratio=0.3, boundary_model, @@ -453,7 +457,7 @@ structure_smoothing_length) in structure_configurations - # TLSPH does not yet support `ContinuityDensity` boundaries. + # TLSPH does not support `ContinuityDensity` boundaries. boundary_densities = if structure_type === TotalLagrangianSPHSystem (AdamiPressureExtrapolation(), SummationDensity()) else @@ -615,74 +619,152 @@ end end - # Without a fluid correction, the pair force only uses the fluid's kernel, - # so a correction of the structure's boundary model must not change it. - # The continuity equation of the boundary particles must use the boundary model. - boundary_corrections = (AkinciFreeSurfaceCorrection(fluid_density), - KernelCorrection()) - - @testset "Boundary Model Correction `$(nameof(typeof(boundary_correction)))`" for boundary_correction in - boundary_corrections - - viscosity = ViscosityAdami(nu=0.1) - velocity = (1.0, 0.5) - density = 1005.0 - forces = map((nothing, boundary_correction)) do boundary_correction_ - fluid_system = create_fluid_system("WCSPH", velocity, density, viscosity) - structure_system = create_structure_system(RigidBodySystem, viscosity; - boundary_density=ContinuityDensity(), - boundary_correction=boundary_correction_) - (fluid, structure, arrays, - semi, _) = initialize(fluid_system, structure_system) - - return (pair_forces(fluid, structure, arrays, semi)..., fluid, structure) + # Check that FSI pressure forces use the kernel and smoothing length of the boundary + # model at the structure particles. Place three fluid particles inside the support + # of the boundary kernel but outside the support of the TLSPH kernel. Using the + # TLSPH kernel would give zero boundary gradients for all three neighbors. + # + # The particles are not on a line. Compare the fluid force and the structure's total + # reaction force with an independent calculation using cubic-spline values. + # Set the fluid correction data explicitly, so that this comparison only checks + # the gradient of the boundary model, which is uncorrected. + @testset "Boundary kernel in pressure acceleration with corrected gradients" begin + coordinates = [0.0 1.5 2.4; 0.0 -1.0 1.2] + kernel_values = (5 / (112pi), 5 / (14pi), 5 / (112pi)) + # Kernel gradients at the structure particle for the displacements + # `(1.5, 0)`, `(0, 1)` and `(-0.9, -1.2)` to the three fluid particles + gradients = (SVector(-15 / (56pi), 0.0), SVector(0.0, -15 / (14pi)), + SVector(9 / (56pi), 12 / (56pi))) + volume = fluid_density / 1005.0 + + for structure_type in structure_types, + correction in (KernelCorrection(), GradientCorrection(), + BlendedGradientCorrection(0.3), MixedKernelGradientCorrection()) + + kernel_correction = correction isa Union{KernelCorrection, + MixedKernelGradientCorrection} + + fluid_ic = InitialCondition(; coordinates, density=1005.0, + mass=fill(fluid_density, 3), particle_spacing) + fluid_system = WeaklyCompressibleSPHSystem(fluid_ic; smoothing_kernel, + smoothing_length, state_equation, + density_calculator=ContinuityDensity(), + correction) + # All three fluid neighbors are inside the compact support of the boundary + # model (2) and outside the compact support of the smoothing kernel of the + # `TotalLagrangianSPHSystem` (2 * 0.4). + structure_system = create_structure_system(structure_type, nothing; + structure_smoothing_kernel=WendlandC2Kernel{2}(), + structure_smoothing_length=0.4) + fluid, structure, arrays, semi, + _ = initialize(fluid_system, structure_system) + + # Prescribe fluid correction data to isolate the boundary gradient + fluid_coefficient = 2.0 + fluid_dw_gamma = SVector(0.2, -0.3) + fluid_matrix = [2.0 0.3; 0.4 1.5] + if kernel_correction + fluid.cache.kernel_correction_coefficient .= fluid_coefficient + fluid.cache.dw_gamma .= fluid_dw_gamma + end + if haskey(fluid.cache, :correction_matrix) + for particle in eachparticle(fluid) + fluid.cache.correction_matrix[:, :, particle] .= fluid_matrix + end + end + force_fluid, force_structure = pair_forces(fluid, structure, arrays, semi) + + # Independent pressure forces from the cubic-spline values above. + # The boundary gradient is uncorrected, the fluid gradient is corrected. + expected_forces = map(gradients, kernel_values) do gradient, value + fluid_gradient = kernel_correction ? + (-gradient - value * fluid_dw_gamma) / + fluid_coefficient : -gradient + if correction isa Union{GradientCorrection, + MixedKernelGradientCorrection} + fluid_gradient = fluid_matrix * fluid_gradient + elseif correction isa BlendedGradientCorrection + lambda = correction.blending_factor + fluid_gradient = (1 - lambda) * fluid_gradient + + lambda * fluid_matrix * fluid_gradient + end + 500.0 * volume^2 * (gradient - fluid_gradient) + end + @test force_fluid ≈ first(expected_forces) + @test force_structure ≈ -sum(expected_forces) + + # The kernel gradient of the boundary model vanishes outside of its compact + # support (2), which is larger than the one of the TLSPH kernel (0.8). + @test iszero(TrixiParticles.smoothing_kernel_grad(structure.boundary_model, + SVector(2.5, 0.0), 2.5, + 1)) end - force_fluid_uncorrected = forces[1][1] - (force_fluid, force_structure, dv_structure, fluid, structure) = forces[2] - - @test force_fluid == force_fluid_uncorrected - @test isapprox(force_structure, -force_fluid, - rtol=sqrt(eps()), atol=sqrt(eps())) - - grad_kernel = TrixiParticles.smoothing_kernel_grad(structure.boundary_model, - SVector(1.5, 0.0), 1.5, 1) - expected_density_rate = -fluid_density / density * fluid.mass[1] * - velocity[1] * grad_kernel[1] - @test dv_structure[end, 1] ≈ expected_density_rate end - # TLSPH does not support `ContinuityDensity` boundaries yet. However, the continuity - # equation of structure boundaries must already use the kernel of the boundary - # model and not the TLSPH kernel for solid mechanics, which has a smaller support. - @testset "TLSPH Continuity Equation with Correction `$(nameof(typeof(correction)))`" for correction in - (nothing, - GradientCorrection()) - velocity = (1.0, 0.5) + # Check the pressure forces when a fluid particle and a structure particle are + # at the same position (coincident particles), or less than `almostzero(h)` apart. + # + # The uncorrected kernel gradient is treated as zero at these distances, which + # includes the gradient of the boundary model of the structure. With + # `KernelCorrection`, the fluid gradient can still be nonzero. Prescribe fluid + # correction data with a nonzero gradient at zero distance. The fluid and structure + # must then experience equal and opposite forces. For the other configurations + # tested here, pairs at the same position are skipped and both forces must be zero. + # + # For rigid bodies, use `ContinuityDensity` and also check that the boundary-density + # derivative, which uses the uncorrected gradient of the boundary model, vanishes. + @testset "Coincident FSI pressure and boundary continuity" begin + velocity = SVector(1.0, -0.5) density = 1005.0 - structure = create_structure_system(TotalLagrangianSPHSystem, nothing; - boundary_density=ContinuityDensity(), - structure_smoothing_length=0.5 * - smoothing_length) - fluid = create_fluid_system("WCSPH", velocity, density, nothing; correction) - if haskey(fluid.cache, :correction_matrix) - fluid.cache.correction_matrix[:, :, 1] .= [2.0 0.3; 0.4 1.5] + volume = fluid_density / density + kernel_zero = 10 / (7pi) + coefficient = 2.0 + dw_gamma = SVector(-0.5, -0.5) + # Kernel-corrected fluid gradient `(∇W - W γ) / c` at zero distance + fluid_gradient = -kernel_zero * dw_gamma / coefficient + near_zero_configurations = (("WCSPH", KernelCorrection()), + ("WCSPH", GradientCorrection()), + ("WCSPH", BlendedGradientCorrection(0.3)), + ("WCSPH", nothing), + ("EDAC", nothing), + ("EDAC with average pressure reduction", nothing)) + almostzero = TrixiParticles.almostzero(smoothing_length) + distances = (0.0, almostzero / 2) + + for (structure_type, (scheme, correction), distance) in + Iterators.product(structure_types, near_zero_configurations, distances) + fluid_coordinates = reshape([1.5 + distance, 0.0], 2, 1) + fluid_system = create_fluid_system(scheme, velocity, density, nothing; + correction, + coordinates=fluid_coordinates) + boundary_density = structure_type === RigidBodySystem ? + ContinuityDensity() : AdamiPressureExtrapolation() + structure_system = create_structure_system(structure_type, nothing; + boundary_density, + boundary_initial_density=density) + fluid, structure, arrays, semi, + _ = initialize(fluid_system, structure_system) + + if correction isa KernelCorrection + fluid.cache.kernel_correction_coefficient .= coefficient + fluid.cache.dw_gamma .= dw_gamma + end + (force_fluid, force_structure, + dv_structure) = pair_forces(fluid, structure, arrays, semi) + + # Use the EOS value to account for rounding in the initial pressure. + # With a vanishing boundary gradient, the pair force on the fluid is + # `-m_a m_b / (ρ_a ρ_b) p_a ∇W_a`. + pressure = state_equation(density) + expected = correction isa KernelCorrection ? + -pressure * volume^2 * fluid_gradient : zero(fluid_gradient) + @test isapprox(force_fluid, expected, rtol=1e-14, atol=1e-14) + @test isapprox(force_structure, -expected, rtol=1e-14, atol=1e-14) + + if structure isa RigidBodySystem + @test iszero(dv_structure[end, 1]) + end end - - pos_diff = SVector(1.5, 0.0) - grad_kernel_fluid = TrixiParticles.smoothing_kernel_grad_unsafe(fluid, - -pos_diff, - 1.5, 1) - drho = TrixiParticles.add_continuity_equation(0.0, structure, fluid, 1, 1, - pos_diff, 1.5, fluid.mass[1], - fluid_density, density, - SVector(0.0, 0.0), - SVector(velocity), - grad_kernel_fluid) - - kernel_derivative = -0.75 * (2 - 1.5)^2 * 10 / (7pi) - expected_density_rate = -fluid_density / density * fluid.mass[1] * - velocity[1] * kernel_derivative - @test drho ≈ expected_density_rate end # The extra terms of the shifting techniques in the momentum equation act on the diff --git a/test/schemes/fluid/weakly_compressible_sph/density_diffusion.jl b/test/schemes/fluid/weakly_compressible_sph/density_diffusion.jl index 7dafc0377e..80aca25d61 100644 --- a/test/schemes/fluid/weakly_compressible_sph/density_diffusion.jl +++ b/test/schemes/fluid/weakly_compressible_sph/density_diffusion.jl @@ -6,5 +6,63 @@ @test repr(density_diffusion) == "DensityDiffusionAntuono(0.1)" end + + # The renormalized density gradient is defined with the uncorrected kernel gradient. + # It must neither depend on the correction of the fluid nor on its correction + # values, which are only computed after the density diffusion in each update. + @trixi_testset "Uncorrected Kernel Gradient" begin + # Irregular particle positions with a nonlinear density field + coordinates = [0.0 0.8 1.7 0.3 1.1 2.1 0.6; 0.0 0.1 0.2 0.9 1.0 1.2 1.8] + density = [1000.0, 1010.0, 990.0, 1005.0, 995.0, 1000.0, 1002.0] + initial_condition = InitialCondition(; coordinates, density, mass=1.0, + particle_spacing=1.0) + state_equation = StateEquationCole(; sound_speed=10.0, + reference_density=1000.0, exponent=1) + density_diffusion = DensityDiffusionAntuono(delta=0.1) + + corrections = (nothing, KernelCorrection(), GradientCorrection(), + BlendedGradientCorrection(0.3), MixedKernelGradientCorrection()) + results = map(corrections) do correction + system = WeaklyCompressibleSPHSystem(initial_condition; + smoothing_kernel=SchoenbergCubicSplineKernel{2}(), + smoothing_length=1.0, state_equation, + density_calculator=ContinuityDensity(), + density_diffusion, correction) + ode = semidiscretize(Semidiscretization(system; + parallelization_backend=SerialBackend()), + (0.0, 0.01)) + semi = ode.p.semi + system = semi.systems[1] + v_ode, u_ode = ode.u0.x + + # The correction values of the fluid must not be used + for field in (:kernel_correction_coefficient, :dw_gamma, + :correction_matrix) + haskey(system.cache, field) || continue + fill!(getproperty(system.cache, field), NaN) + end + + TrixiParticles.update!(density_diffusion, + TrixiParticles.wrap_v(v_ode, system, semi), + TrixiParticles.wrap_u(u_ode, system, semi), + system, semi) + + return (copy(system.cache.density_diffusion_correction_matrix), + copy(system.cache.density_diffusion_normalized_density_gradient)) + end + + matrix, normalized_gradient = first(results) + @test all(isfinite, matrix) + @test all(isfinite, normalized_gradient) + @test !iszero(normalized_gradient) + + @testset "$(nameof(typeof(correction)))" for (correction, + result) in + zip(corrections[2:end], + results[2:end]) + @test result[1] == matrix + @test result[2] == normalized_gradient + end + end end end diff --git a/test/systems/tlsph_system.jl b/test/systems/tlsph_system.jl index b39f0a6b2a..e346380ccc 100644 --- a/test/systems/tlsph_system.jl +++ b/test/systems/tlsph_system.jl @@ -43,6 +43,19 @@ @test TrixiParticles.initial_smoothing_length(system) == smoothing_length @test system.acceleration == [0.0 for _ in 1:NDIMS] @test system.boundary_model == boundary_model + + boundary_model = BoundaryModelDummyParticles(material_densities, mass, + ContinuityDensity(), + SchoenbergCubicSplineKernel{NDIMS}(), + smoothing_length) + error_str = "`BoundaryModelDummyParticles` with density calculator " * + "`ContinuityDensity` is not supported for a `TotalLagrangianSPHSystem`" + @test_throws ArgumentError(error_str) TotalLagrangianSPHSystem(initial_condition; + smoothing_kernel, + smoothing_length, + young_modulus=E, + poisson_ratio=nu, + boundary_model) end end