diff --git a/NEWS.md b/NEWS.md index 65418f36a9..26f04ac19b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -14,6 +14,10 @@ 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). +- A `BoundaryModelDummyParticles` with `SummationDensity` is no longer accepted for a + `TotalLagrangianSPHSystem` or `RigidBodySystem`. The boundary density was never computed + for structures, so this combination behaved like `PressureZeroing`, which can be used + instead (#1341). - The `correction` of a `BoundaryModelDummyParticles` of a `TotalLagrangianSPHSystem` or `RigidBodySystem` must now be `nothing`. Previously, it was ignored or caused an error (#1342). @@ -32,6 +36,14 @@ used in the Julia ecosystem. Notable changes will be documented in this file for ### Important Bugfixes +- Fixed pressure mirroring for TLSPH and rigid-body neighbors and for EDAC momentum, + pressure diffusion, and average-pressure reduction at walls and structures. + With a boundary viscosity, `PressureMirroring` now computes the wall velocity of the + no-slip condition, which was zero before (#1341). +- Fixed the advection prediction of `ImplicitIncompressibleSPHSystem` depending on the + order of the systems in the `Semidiscretization`. The densities and predicted velocities + of systems that are updated later in the same step were taken from the previous update. + This affected `PressureBoundaries` and simulations with multiple IISPH systems (#1341). - 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 diff --git a/docs/src/systems/boundary.md b/docs/src/systems/boundary.md index cc583121f2..978e9c801e 100644 --- a/docs/src/systems/boundary.md +++ b/docs/src/systems/boundary.md @@ -69,6 +69,8 @@ We provide six options to compute the boundary density and pressure, determined penetrations. 3. With [`SummationDensity`](@ref), the density is calculated by summation over the neighboring particles, and the pressure is computed from the density with the state equation. + This option is not supported for the boundary models of a [`TotalLagrangianSPHSystem`](@ref) + or a [`RigidBodySystem`](@ref). 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). @@ -86,6 +88,9 @@ We provide six options to compute the boundary density and pressure, determined momentum equation. This option is not recommended due to stability issues. See [`PressureMirroring`](@ref) for more details. + In EDAC, the mirrored pressure is used in the momentum equation, + the pressure evolution equation, and the average-pressure reduction. + Mirroring makes the pressure diffusion contribution from a fluid-boundary pair zero. #### 1. [`AdamiPressureExtrapolation`](@ref) diff --git a/src/general/semidiscretization.jl b/src/general/semidiscretization.jl index d046fde1c7..6610586591 100644 --- a/src/general/semidiscretization.jl +++ b/src/general/semidiscretization.jl @@ -510,7 +510,7 @@ end return reshape(view(array, range), Int.(size)) end -function check_configuration(systems, +function check_configuration(systems::Union{Tuple, AbstractVector}, nhs::Union{Nothing, AbstractNeighborhoodSearch}) foreach_system(systems) do system check_configuration(system, systems, nhs) diff --git a/src/schemes/boundary/open_boundary/rhs.jl b/src/schemes/boundary/open_boundary/rhs.jl index 1385023c3f..8ad6c5d382 100644 --- a/src/schemes/boundary/open_boundary/rhs.jl +++ b/src/schemes/boundary/open_boundary/rhs.jl @@ -42,7 +42,10 @@ function interact!(dv, v_particle_system, u_particle_system, m_b = @inbounds hydrodynamic_mass(neighbor_system, neighbor) p_a = @inbounds current_pressure(v_particle_system, particle_system, particle) - p_b = @inbounds current_pressure(v_neighbor_system, neighbor_system, neighbor) + # Equivalent to `current_pressure(v_neighbor_system, neighbor_system, neighbor)`, + # but returns `p_a` for boundaries and structures using `PressureMirroring`. + p_b = @inbounds neighbor_pressure(v_neighbor_system, neighbor_system, + neighbor, p_a) dv_pressure = pressure_acceleration(particle_system, neighbor_system, particle, neighbor, diff --git a/src/schemes/boundary/wall_boundary/dummy_particles.jl b/src/schemes/boundary/wall_boundary/dummy_particles.jl index 8a6812f6e9..f32bbfcf8b 100644 --- a/src/schemes/boundary/wall_boundary/dummy_particles.jl +++ b/src/schemes/boundary/wall_boundary/dummy_particles.jl @@ -106,6 +106,12 @@ function BoundaryModelDummyParticles(initial_density, hydrodynamic_mass, create_cache_model(initial_density, density_calculator, NDIMS)..., create_cache_correction(correction, initial_density, NDIMS, n_particles)...) + # The pressure extrapolation already provides the sum of the kernel weights to interpolate + # the fluid velocity for the no-slip condition. Other density calculators need it as well. + if !isnothing(viscosity) && !haskey(cache, :volume) + cache = (; cache..., volume=similar(cache.wall_velocity, n_particles)) + end + # If the `reference_density_spacing` is set calculate the `ideal_neighbor_count` if reference_particle_spacing > 0 # `reference_particle_spacing` has to be set for surface normals to be determined @@ -490,8 +496,6 @@ function compute_density!(boundary_model, ::PressureBoundaries, system, v, u, v_ (; density) = cache # Density is in the cache for `SummationDensity` summation_density!(system, semi, u, u_ode, density; particles=eachparticle(system)) - - predict_advection!(system, v, u, v_ode, u_ode, semi) end function compute_pressure!(boundary_model, ::Union{SummationDensity, ContinuityDensity}, @@ -615,6 +619,50 @@ function compute_pressure!(boundary_model, return boundary_model end +# The wall velocity for `AdamiPressureExtrapolation` and `BernoulliPressureExtrapolation` +# is computed later in the pressure extrapolation. +@inline function interpolate_wall_velocity!(boundary_model, system, v, u, v_ode, u_ode, + semi) + return boundary_model +end + +function interpolate_wall_velocity!(boundary_model::BoundaryModelDummyParticles{PressureMirroring}, + system, v, u, v_ode, u_ode, semi) + (; cache, viscosity) = boundary_model + + # Without a viscosity model, the wall velocity is not used. + isnothing(viscosity) && return boundary_model + + # For the no-slip condition, interpolate the fluid velocity like the pressure extrapolation + # of `AdamiPressureExtrapolation`, but without extrapolating the pressure. + # Set `volume` and `wall_velocity` to zero. + reset_cache!(cache, viscosity) + + system_coords = current_coordinates(u, system) + + foreach_system(semi) do neighbor_system + has_system_interaction(system, neighbor_system, semi) || return + + v_neighbor_system = wrap_v(v_ode, neighbor_system, semi) + u_neighbor_system = wrap_u(u_ode, neighbor_system, semi) + neighbor_coords = current_coordinates(u_neighbor_system, neighbor_system) + + boundary_pressure_extrapolation!(Val(true), boundary_model, system, + neighbor_system, system_coords, neighbor_coords, + v, v_neighbor_system, semi) + end + + @threaded semi for particle in eachparticle(system) + # The volume stays zero for boundary particles without fluid neighbors, + # whose wall velocity is not used. + if cache.volume[particle] > eps() + compute_wall_velocity!(viscosity, system, v, particle) + end + end + + return boundary_model +end + @inline function boundary_pressure_extrapolation!(parallel, boundary_model, system, neighbor_system, system_coords, neighbor_coords, v, v_neighbor_system, @@ -629,7 +677,6 @@ end system_coords, neighbor_coords, v, v_neighbor_system, semi) (; pressure, cache, viscosity, density_calculator) = boundary_model - (; pressure_offset) = density_calculator @boundscheck checkbounds(pressure, eachparticle(system)) @@ -640,7 +687,7 @@ end @inbounds boundary_pressure_inner!(boundary_model, density_calculator, system, neighbor_system, v, v_neighbor_system, particle, neighbor, pos_diff, distance, - viscosity, cache, pressure, pressure_offset) + viscosity, cache, pressure) end end @@ -655,7 +702,6 @@ end system_coords, neighbor_coords, v, v_neighbor_system, semi) (; pressure, cache, viscosity, density_calculator) = boundary_model - (; pressure_offset) = density_calculator @boundscheck checkbounds(pressure, eachparticle(system)) @@ -669,7 +715,7 @@ end @inbounds boundary_pressure_inner!(boundary_model, density_calculator, system, neighbor_system, v, v_neighbor_system, particle, neighbor, pos_diff, distance, - viscosity, cache, pressure, pressure_offset) + viscosity, cache, pressure) end end @@ -679,8 +725,9 @@ end OpenBoundarySystem{<:BoundaryModelDynamicalPressureZhang}}, v, v_neighbor_system, particle, neighbor, pos_diff, distance, - viscosity, cache, pressure, - pressure_offset) + viscosity, cache, pressure) + (; pressure_offset) = boundary_density_calculator + density_neighbor = current_density(v_neighbor_system, neighbor_system, neighbor) # Fluid pressure term @@ -710,6 +757,22 @@ end kernel_weight, particle, neighbor) end +# With `PressureMirroring`, the fluid pressure is used directly in the pair interaction. +# Only the fluid velocity is interpolated to the boundary particles for the no-slip condition. +@propagate_inbounds function boundary_pressure_inner!(boundary_model, ::PressureMirroring, + system, + neighbor_system::Union{AbstractFluidSystem, + OpenBoundarySystem{<:BoundaryModelDynamicalPressureZhang}}, + v, v_neighbor_system, particle, + neighbor, pos_diff, distance, + viscosity, cache, pressure) + kernel_weight = smoothing_kernel(boundary_model, distance, particle) + + cache.volume[particle] += kernel_weight + interpolate_fluid_velocity!(cache, viscosity, neighbor_system, v_neighbor_system, + kernel_weight, particle, neighbor) +end + @inline function dynamic_pressure(boundary_density_calculator, v, v_neighbor_system, system, neighbor_system, particle, neighbor, pos_diff, distance, density_neighbor) diff --git a/src/schemes/boundary/wall_boundary/system.jl b/src/schemes/boundary/wall_boundary/system.jl index f9864ecc05..3a83fc1958 100644 --- a/src/schemes/boundary/wall_boundary/system.jl +++ b/src/schemes/boundary/wall_boundary/system.jl @@ -215,6 +215,8 @@ function update_quantities!(system::WallBoundarySystem, v, u, v_ode, u_ode, semi update_density!(boundary_model, system, v, u, v_ode, u_ode, semi) + interpolate_wall_velocity!(boundary_model, system, v, u, v_ode, u_ode, semi) + return system end diff --git a/src/schemes/fluid/entropically_damped_sph/rhs.jl b/src/schemes/fluid/entropically_damped_sph/rhs.jl index 2f6aee2c3b..75f37ac8ee 100644 --- a/src/schemes/fluid/entropically_damped_sph/rhs.jl +++ b/src/schemes/fluid/entropically_damped_sph/rhs.jl @@ -37,7 +37,7 @@ function interact!(dv, v_particle_system, u_particle_system, v_b = @inbounds current_velocity(v_neighbor_system, neighbor_system, neighbor) p_a = @inbounds current_pressure(v_particle_system, particle_system, particle) - p_b = @inbounds current_pressure(v_neighbor_system, neighbor_system, neighbor) + p_b = @inbounds neighbor_pressure(v_neighbor_system, neighbor_system, neighbor, p_a) m_a = @inbounds hydrodynamic_mass(particle_system, particle) m_b = @inbounds hydrodynamic_mass(neighbor_system, neighbor) diff --git a/src/schemes/fluid/entropically_damped_sph/system.jl b/src/schemes/fluid/entropically_damped_sph/system.jl index 426e79e537..8ae17c4ea0 100644 --- a/src/schemes/fluid/entropically_damped_sph/system.jl +++ b/src/schemes/fluid/entropically_damped_sph/system.jl @@ -332,6 +332,7 @@ function update_average_pressure!(system, ::Val{true}, v_ode, u_ode, semi) set_zero!(pressure_average) set_zero!(neighbor_counter) + v = wrap_v(v_ode, system, semi) u = wrap_u(u_ode, system, semi) # Use enabled neighbor systems for the average pressure. @@ -354,8 +355,10 @@ function update_average_pressure!(system, ::Val{true}, v_ode, u_ode, semi) neighbor, pos_diff, distance - pressure_average[particle] += current_pressure(v_neighbor_system, - neighbor_system, neighbor) + p_a = current_pressure(v, system, particle) + pressure_average[particle] += neighbor_pressure(v_neighbor_system, + neighbor_system, neighbor, + p_a) neighbor_counter[particle] += 1 end end diff --git a/src/schemes/fluid/implicit_incompressible_sph/system.jl b/src/schemes/fluid/implicit_incompressible_sph/system.jl index 6bf1aba763..d9a7a94b76 100644 --- a/src/schemes/fluid/implicit_incompressible_sph/system.jl +++ b/src/schemes/fluid/implicit_incompressible_sph/system.jl @@ -204,7 +204,7 @@ end @inline density_calculator(system::ImplicitIncompressibleSPHSystem) = nothing -# Calculates the pressure values by solving a linear system with a relaxed Jacobi scheme +# Compute density before the prediction and pressure solve in `update_implicit_sph!`. function update_quantities!(system::ImplicitIncompressibleSPHSystem, v, u, v_ode, u_ode, semi, t) (; density) = system @@ -212,8 +212,7 @@ function update_quantities!(system::ImplicitIncompressibleSPHSystem, v, u, # Compute density by kernel summation summation_density!(system, semi, u, u_ode, density) - @trixi_timeit timer() "predict advection" predict_advection!(system, v, u, v_ode, u_ode, - semi) + return system end function update_implicit_sph!(semi, v_ode, u_ode, t) @@ -222,21 +221,24 @@ function update_implicit_sph!(semi, v_ode, u_ode, t) return semi end + # All densities and mirrored wall velocities are ready after `update_quantities!`. + # Predict every fluid velocity before computing coefficients that use neighboring + # predictions, including those of `PressureBoundaries`, regardless of system order. + @trixi_timeit timer() "predict advection" begin + foreach_system_wrapped(semi, v_ode, u_ode) do system, v, u + calculate_predicted_velocity_and_d_ii_values!(system, v, u, v_ode, u_ode, semi) + end + foreach_system_wrapped(semi, v_ode, u_ode) do system, v, u + calculate_diagonal_elements_and_predicted_density!(system, v, u, v_ode, u_ode, + semi) + end + end + @trixi_timeit timer() "pressure solver" pressure_solve!(semi, v_ode, u_ode) return semi end -function predict_advection!(system::Union{ImplicitIncompressibleSPHSystem, - WallBoundarySystem{<:BoundaryModelDummyParticles{<:PressureBoundaries}}}, - v, u, v_ode, u_ode, semi) - calculate_predicted_velocity_and_d_ii_values!(system, v, u, v_ode, u_ode, semi) - - calculate_diagonal_elements_and_predicted_density!(system, v, u, v_ode, u_ode, semi) - - return system -end - function calculate_predicted_velocity_and_d_ii_values!(system, v, u, v_ode, u_ode, semi) return system end diff --git a/src/schemes/fluid/weakly_compressible_sph/rhs.jl b/src/schemes/fluid/weakly_compressible_sph/rhs.jl index bd4e10b0db..e9f6adada6 100644 --- a/src/schemes/fluid/weakly_compressible_sph/rhs.jl +++ b/src/schemes/fluid/weakly_compressible_sph/rhs.jl @@ -65,9 +65,8 @@ function interact!(dv, v_particle_system, u_particle_system, # The following call is equivalent to # `p_b = current_pressure(v_neighbor_system, neighbor_system, neighbor)` - # Only when the neighbor system is a `WallBoundarySystem` - # or a `TotalLagrangianSPHSystem` with the boundary model `PressureMirroring`, - # this will return `p_b = p_a`, which is the pressure of the fluid particle. + # For boundaries and structures using `PressureMirroring`, this returns + # `p_b = p_a`, which is the pressure of the fluid particle. p_b = @inbounds neighbor_pressure(v_neighbor_system, neighbor_system, neighbor, p_a) @@ -179,7 +178,9 @@ end end @inline function neighbor_pressure(v_neighbor_system, - neighbor_system::WallBoundarySystem{<:BoundaryModelDummyParticles{PressureMirroring}}, + neighbor_system::Union{WallBoundarySystem{<:BoundaryModelDummyParticles{PressureMirroring}}, + TotalLagrangianSPHSystem{<:BoundaryModelDummyParticles{PressureMirroring}}, + RigidBodySystem{<:BoundaryModelDummyParticles{PressureMirroring}}}, neighbor, p_a) return p_a end diff --git a/src/schemes/structure/rigid_body/system.jl b/src/schemes/structure/rigid_body/system.jl index b0cb233625..128eb1db76 100644 --- a/src/schemes/structure/rigid_body/system.jl +++ b/src/schemes/structure/rigid_body/system.jl @@ -20,9 +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. + For [`BoundaryModelDummyParticles`](@ref), [`SummationDensity`](@ref) + is not supported and `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. @@ -376,6 +376,9 @@ end function update_boundary_interpolation!(boundary_model, system::RigidBodySystem, v, u, v_ode, u_ode, semi, t) + @trixi_timeit timer() "interpolate wall velocity" begin + interpolate_wall_velocity!(boundary_model, system, v, u, v_ode, u_ode, semi) + end update_pressure!(boundary_model, system, v, u, v_ode, u_ode, semi) return system end @@ -627,6 +630,7 @@ function check_configuration(system::RigidBodySystem, systems, nhs) end end + check_boundary_model_density(system, boundary_model) check_boundary_model_correction(system, boundary_model) foreach_system(systems) do neighbor diff --git a/src/schemes/structure/structure.jl b/src/schemes/structure/structure.jl index f17a0bc1ee..9939a2adc9 100644 --- a/src/schemes/structure/structure.jl +++ b/src/schemes/structure/structure.jl @@ -100,6 +100,20 @@ end check_smoothing_kernel_fsi(system, boundary_model, neighbor_system) = system +# Dummy-particle pressure and density are separate from the TLSPH material state. +# Adami extrapolation already uses the current fluid neighborhood. Summation density +# additionally needs current boundary/structure neighbors and the boundary model's kernel; +# the reference-configuration TLSPH self-search cannot supply those neighbors. +# There is currently no NHS to find current structure neighbors with the boundary model's kernel. +function check_boundary_model_density(system, + ::BoundaryModelDummyParticles{SummationDensity}) + throw(ArgumentError("`BoundaryModelDummyParticles` with density calculator " * + "`SummationDensity` is not supported for a " * + "`$(nameof(typeof(system)))`")) +end + +check_boundary_model_density(system, boundary_model) = 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 @@ -167,8 +181,12 @@ function interact_structure_fluid!(dv, v_particle_system, u_particle_system, # In fluid-structure interaction, use the "hydrodynamic pressure" of the structure # particles corresponding to the chosen boundary model. - p_a = current_pressure(v_particle_system, particle_system, particle) + # The following call is equivalent to + # `p_a = current_pressure(v_particle_system, particle_system, particle)` + # except for structures using `PressureMirroring`, where this returns `p_a = p_b`, which is + # the pressure of the fluid particle, mirroring the fluid-structure interaction. p_b = current_pressure(v_neighbor_system, neighbor_system, neighbor) + p_a = neighbor_pressure(v_particle_system, particle_system, particle, p_b) # 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 diff --git a/src/schemes/structure/total_lagrangian_sph/system.jl b/src/schemes/structure/total_lagrangian_sph/system.jl index f68c35963f..f9ebcfc4ea 100644 --- a/src/schemes/structure/total_lagrangian_sph/system.jl +++ b/src/schemes/structure/total_lagrangian_sph/system.jl @@ -33,9 +33,10 @@ 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. + For [`BoundaryModelDummyParticles`](@ref), [`SummationDensity`](@ref) + and [`ContinuityDensity`](@ref) are 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. @@ -124,6 +125,10 @@ function TotalLagrangianSPHSystem(initial_condition; smoothing_kernel, smoothing throw(ArgumentError("smoothing kernel dimensionality must be $NDIMS for a $(NDIMS)D problem")) end + # `ContinuityDensity` requires integrating the boundary density of all particles, + # including clamped ones. The ODE state only contains `n_integrated_particles`, with + # `v_nvariables` variables per particle. Increasing `v_nvariables` therefore does not + # provide density unknowns for clamped particles, whose motion must remain prescribed. if boundary_model isa BoundaryModelDummyParticles{ContinuityDensity} throw(ArgumentError("`BoundaryModelDummyParticles` with density calculator " * "`ContinuityDensity` is not supported for a `TotalLagrangianSPHSystem`")) @@ -504,7 +509,12 @@ function update_boundary_interpolation!(system::TotalLagrangianSPHSystem, v, u, v_ode, u_ode, semi, t) (; boundary_model) = system - # Only update boundary model + # Only update the boundary model. This cannot be in `update_quantities!`, + # which the `SplitIntegrationCallback` also calls + # without any fluid systems to interpolate the wall velocity from. + @trixi_timeit timer() "interpolate wall velocity" begin + interpolate_wall_velocity!(boundary_model, system, v, u, v_ode, u_ode, semi) + end update_pressure!(boundary_model, system, v, u, v_ode, u_ode, semi) end @@ -848,6 +858,7 @@ function check_configuration(system::TotalLagrangianSPHSystem, systems, nhs) end end + check_boundary_model_density(system, boundary_model) check_boundary_model_correction(system, boundary_model) foreach_system(systems) do neighbor diff --git a/test/general/semidiscretization.jl b/test/general/semidiscretization.jl index 026fe1992f..0c6fd45e8e 100644 --- a/test/general/semidiscretization.jl +++ b/test/general/semidiscretization.jl @@ -169,6 +169,7 @@ # Missing boundary model. structure = create_structure_system(structure_type, nothing) + @test_nowarn Semidiscretization(structure; neighborhood_search=nothing) error_str = "a boundary model for `$structure_type` must be specified " * "when simulating a fluid-structure interaction." @test_throws ArgumentError(error_str) Semidiscretization(fluid_system, @@ -188,6 +189,31 @@ fluid_system; neighborhood_search=nothing) + # Summation density is unsupported for both structure types. + boundary_model = BoundaryModelDummyParticles(ic.density, ic.mass, + SummationDensity(), + smoothing_kernel, + smoothing_length; + state_equation) + structure = create_structure_system(structure_type, boundary_model) + error_str = "`BoundaryModelDummyParticles` with density calculator " * + "`SummationDensity` is not supported for a `$structure_type`" + @test_throws ArgumentError(error_str) Semidiscretization(structure; + neighborhood_search=nothing) + for systems in ((structure, fluid_system), (fluid_system, structure)) + # The boundary model is unsupported even with FSI disabled. + for interaction_matrix in ([true false; false true], + [true true; false true], + [true false; true true]) + @test_throws ArgumentError(error_str) Semidiscretization(systems...; + neighborhood_search=nothing, + interaction_matrix) + end + end + @test_throws ArgumentError(error_str) Semidiscretization(structure, + fluid_system; + neighborhood_search=nothing) + @testset "$name" for (name, boundary_kernel, boundary_length, compatible) in boundary_configurations @@ -334,7 +360,7 @@ particle_spacing=1.0) boundary_model = BoundaryModelDummyParticles(structure_ic.density, structure_ic.mass, - SummationDensity(), kernel, + PressureZeroing(), kernel, smoothing_length; state_equation, correction=nothing) diff --git a/test/schemes/boundary/open_boundary/dynamical_pressure.jl b/test/schemes/boundary/open_boundary/dynamical_pressure.jl index bd325eb690..1153067cae 100644 --- a/test/schemes/boundary/open_boundary/dynamical_pressure.jl +++ b/test/schemes/boundary/open_boundary/dynamical_pressure.jl @@ -168,4 +168,57 @@ # Integrated: velocity + pressure + density (`BoundaryModelDynamicalPressureZhang` always uses `ContinuityDensity`) @test TrixiParticles.v_nvariables(open_boundary_edac_2) == n_dims + 2 end + + # The open boundary particles are part of the fluid. Like all fluid particles, they see their + # own pressure at a wall with `PressureMirroring`, and not the (unused) pressure + # stored in the wall. + @testset verbose=true "Mirrored Wall Neighbor" begin + particle_spacing = 0.1 + smoothing_kernel = SchoenbergCubicSplineKernel{2}() + smoothing_length = 1.2 * particle_spacing + state_equation = StateEquationCole(; sound_speed=20.0, exponent=1, + reference_density=1000.0) + + # A buffer particle and a wall particle within the kernel support + buffer_ic = InitialCondition(; coordinates=zeros(2, 1), density=1020.0, + particle_spacing) + wall_ic = InitialCondition(; coordinates=reshape([0.0, -particle_spacing], 2, 1), + density=1000.0, particle_spacing) + + fluid = WeaklyCompressibleSPHSystem(buffer_ic; smoothing_kernel, smoothing_length, + state_equation, + density_calculator=ContinuityDensity()) + zone = BoundaryZone(; initial_condition=buffer_ic, boundary_type=InFlow(), + boundary_face=([0.5particle_spacing, -1.0], + [0.5particle_spacing, 1.0]), + face_normal=[1.0, 0.0], open_boundary_layers=3, density=1020.0, + particle_spacing, reference_velocity=[0.0, 0.0]) + open_boundary = OpenBoundarySystem(zone; fluid_system=fluid, buffer_size=0, + boundary_model=BoundaryModelDynamicalPressureZhang()) + wall_model = BoundaryModelDummyParticles(wall_ic.density, wall_ic.mass, + PressureMirroring(), smoothing_kernel, + smoothing_length; state_equation) + wall = WallBoundarySystem(wall_ic, wall_model) + + # Overwrite the pressure of the buffer particle because we skip the update step + p_buffer = 8000.0 + open_boundary.cache.pressure .= p_buffer + v_open = vcat(buffer_ic.velocity, buffer_ic.density') + + function interact_buffer_wall(wall_pressure) + wall.boundary_model.pressure .= wall_pressure + dv = zero(v_open) + TrixiParticles.interact!(dv, v_open, buffer_ic.coordinates, nothing, + wall_ic.coordinates, open_boundary, wall, + DummySemidiscretization()) + return dv + end + + # The result is the same as for a wall particle with the pressure of the buffer + # particle, independent of the pressure stored in the wall. + dv = interact_buffer_wall(0.0) + @test !iszero(dv) + @test dv ≈ interact_buffer_wall(p_buffer) + @test dv ≈ interact_buffer_wall(2 * p_buffer) + end end diff --git a/test/schemes/fluid/rhs.jl b/test/schemes/fluid/rhs.jl index fc4c568da2..40353e3711 100644 --- a/test/schemes/fluid/rhs.jl +++ b/test/schemes/fluid/rhs.jl @@ -279,6 +279,7 @@ sound_speed = 10.0 state_equation = StateEquationCole(; sound_speed, reference_density=fluid_density, exponent=1) + pair_gradient = SVector(15 / (56pi), 0.0) # Cubic-spline ∇W at (1.5h, 0) function create_fluid_system(scheme, velocity, density, viscosity; shifting_technique=nothing, correction=nothing, @@ -295,6 +296,11 @@ density_calculator=ContinuityDensity(), viscosity, shifting_technique, correction) + elseif scheme == "IISPH" + return ImplicitIncompressibleSPHSystem(fluid; smoothing_kernel, + smoothing_length, viscosity, + reference_density=fluid_density, + time_step=1e-3) end # Note that the average pressure reduction is enabled by default @@ -311,12 +317,13 @@ boundary_correction=nothing, boundary_initial_density=fluid_density, clamped=false, + velocity=(0.0, 0.0), 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. structure = InitialCondition(; coordinates=reshape([1.5, 0.0], 2, 1), - velocity=zeros(2, 1), + velocity=reshape(collect(velocity), 2, 1), mass=[2 * fluid_density * particle_spacing^2], density=[2 * fluid_density], particle_spacing) boundary_model = BoundaryModelDummyParticles([boundary_initial_density], @@ -328,7 +335,11 @@ state_equation, viscosity, correction=boundary_correction) - if structure_type === TotalLagrangianSPHSystem + if structure_type === WallBoundarySystem + motion = PrescribedMotion((x, t) -> x + SVector(velocity) * t, t -> true) + return WallBoundarySystem(structure, boundary_model; + prescribed_motion=motion) + elseif structure_type === TotalLagrangianSPHSystem return TotalLagrangianSPHSystem(structure; smoothing_kernel=structure_smoothing_kernel, smoothing_length=structure_smoothing_length, @@ -343,22 +354,26 @@ # Run the regular update step to compute the boundary pressure, the wall velocity # for the viscosity, and the average pressure of EDAC. Return the systems # stored in the semidiscretization and the wrapped arrays. - function initialize(fluid_system, structure_system) + function initialize(fluid_system, structure_system; boundary_first=false) + systems = boundary_first ? (structure_system, fluid_system) : + (fluid_system, structure_system) semi = if structure_system isa TotalLagrangianSPHSystem @test_logs (:info, r"^To create the self-interaction neighborhood search of a `TotalLagrangianSPHSystem`") begin - Semidiscretization(fluid_system, structure_system; + Semidiscretization(systems...; parallelization_backend=SerialBackend()) end else - @test_logs Semidiscretization(fluid_system, structure_system; + @test_logs Semidiscretization(systems...; parallelization_backend=SerialBackend()) end ode = semidiscretize(semi, (0.0, 0.01)) v_ode, u_ode = ode.u0.x TrixiParticles.update_systems_and_nhs(v_ode, u_ode, ode.p.semi, 0.0) - fluid, structure = ode.p.semi.systems + (fluid, + structure) = boundary_first ? reverse(ode.p.semi.systems) : + ode.p.semi.systems semi = ode.p.semi arrays = (TrixiParticles.wrap_v(v_ode, fluid, semi), TrixiParticles.wrap_u(u_ode, fluid, semi), @@ -458,11 +473,13 @@ structure_configurations # TLSPH does not support `ContinuityDensity` boundaries. + # Structures don't support `SummationDensity` boundaries. boundary_densities = if structure_type === TotalLagrangianSPHSystem - (AdamiPressureExtrapolation(), SummationDensity()) + (AdamiPressureExtrapolation(), PressureZeroing(), + PressureMirroring()) else - (AdamiPressureExtrapolation(), SummationDensity(), - ContinuityDensity()) + (AdamiPressureExtrapolation(), PressureZeroing(), + ContinuityDensity(), PressureMirroring()) end @testset "Boundary `$(nameof(typeof(boundary_density)))`" for boundary_density in @@ -524,6 +541,8 @@ end elseif isnothing(viscosity) if scheme == "EDAC with average pressure reduction" + # `PressureMirroring` leaves the cache at its + # initial value, so only compare for Adami. if boundary_density isa AdamiPressureExtrapolation @test TrixiParticles.current_pressure(v_fluid, fluid, @@ -531,6 +550,9 @@ structure.boundary_model.pressure[1] @test isapprox(force_structure, zeros(2), atol=sqrt(eps())) + elseif boundary_density isa PressureMirroring + @test isapprox(force_structure, zeros(2), + atol=sqrt(eps())) else # The boundary pressure stays zero, so subtracting # the fluid's average pressure makes it attractive. @@ -562,6 +584,34 @@ # from this RHS evaluation rather than the earlier pair call. dv_fluid = TrixiParticles.wrap_v(dv_ode, fluid, semi) force_fluid_rhs = fluid.mass[1] * dv_fluid[1:2, 1] + if scheme != "WCSPH" && boundary_density isa PressureMirroring + # Row 3 is the EDAC pressure derivative. Mirroring gives + # p_b = p_a, so pressure diffusion vanishes. With the + # boundary at rest, only rho_a * c^2 * V_b * v_a ⋅ ∇W_ab remains. + # The boundary's hydrodynamic mass is rho_b * particle_spacing^2. + boundary_volume = particle_spacing^2 + expected_pressure_rate = state.density * sound_speed^2 * + boundary_volume * + dot(SVector(state.velocity), + pair_gradient) + @test dv_fluid[3, 1] ≈ expected_pressure_rate + if isnothing(viscosity) + # Equal mirrored pressures reduce the density-weighted + # pressure average to p_a - p_avg. Multiplying the + # acceleration by m_a gives F_a = -(V_a^2 + V_b^2) * + # (p_a - p_avg) * ∇W_ab. + fluid_volume = fluid.mass[1] / state.density + effective_pressure = TrixiParticles.current_pressure(v_fluid, + fluid, + 1) - + TrixiParticles.average_pressure(fluid, + 1) + expected_force = -(fluid_volume^2 + boundary_volume^2) * + effective_pressure * pair_gradient + @test isapprox(force_fluid_rhs, expected_force, + atol=sqrt(eps())) + end + end dv_structure = TrixiParticles.wrap_v(dv_ode, structure, semi) if structure isa RigidBodySystem @test isapprox(structure.resultant_force[], @@ -578,6 +628,93 @@ end end + # For fluid at rest, the no-slip ghost velocity is 2 * v_boundary. + # Check that a moving mirrored-pressure boundary drags the fluid along. + # For IISPH, check that the predictor and RHS use the same viscous force, + # including after a fluid-velocity change and for both system orderings. + no_slip_configurations = (("WCSPH", WallBoundarySystem, false), + ("WCSPH", TotalLagrangianSPHSystem, false), + ("WCSPH", RigidBodySystem, false), + ("IISPH", WallBoundarySystem, false), + ("IISPH", WallBoundarySystem, true)) + @testset "Mirrored no-slip velocity: $scheme, $boundary_type, boundary_first=$boundary_first" for (scheme, + boundary_type, + boundary_first) in + no_slip_configurations + + viscosity = ViscosityAdami(nu=0.1) + velocity = SVector(1.0, 0.5) + fluid_system = create_fluid_system(scheme, (0.0, 0.0), fluid_density, + viscosity) + boundary = create_structure_system(boundary_type, viscosity; + boundary_density=PressureMirroring(), + velocity) + fluid, boundary, arrays, semi, + ode = initialize(fluid_system, boundary; + boundary_first) + v, u, v_boundary, u_boundary = arrays + @test boundary.boundary_model.cache.wall_velocity[:, 1] ≈ 2 * velocity + dv = zero(v) + TrixiParticles.interact!(dv, v, u, v_boundary, u_boundary, fluid, boundary, + semi) + @test dot(dv[1:2, 1], velocity) > 0 # Moving boundary drags fluid at rest. + if scheme == "IISPH" + # The pressure predictor must use the same no-slip force as the RHS, + # both initially and after changing the fluid velocity. + # Pressure is zero in this one-pair setup, isolating viscosity. + @test fluid.advection_velocity[:, 1] ≈ + v[1:2, 1] + fluid.time_step * dv[1:2, 1] + v[1:2, 1] .= velocity / 2 + TrixiParticles.update_systems_and_nhs(ode.u0.x..., semi, 0.0) + @test boundary.boundary_model.cache.wall_velocity[:, 1] ≈ + 2 * velocity - v[1:2, 1] + fill!(dv, 0) + TrixiParticles.interact!(dv, v, u, v_boundary, u_boundary, fluid, boundary, + semi) + @test fluid.advection_velocity[:, 1] ≈ + v[1:2, 1] + fluid.time_step * dv[1:2, 1] + end + end + + # The `SplitIntegrationCallback` updates the structure in a semidiscretization + # without fluid. This must not reset the wall velocity of the no-slip condition. + @testset "Mirrored no-slip velocity: update without fluid" begin + viscosity = ViscosityAdami(nu=0.1) + fluid_system = create_fluid_system("WCSPH", (0.0, 0.0), fluid_density, + viscosity) + structure = create_structure_system(TotalLagrangianSPHSystem, viscosity; + boundary_density=PressureMirroring(), + velocity=SVector(1.0, 0.5)) + _, structure, _, _, _ = initialize(fluid_system, structure) + wall_velocity = copy(structure.boundary_model.cache.wall_velocity) + @test !iszero(wall_velocity) + + semi_split = Semidiscretization(structure; + parallelization_backend=SerialBackend()) + v_ode, u_ode = semidiscretize(semi_split, (0.0, 1.0)).u0.x + TrixiParticles.update_systems_split!(semi_split, v_ode, u_ode, 0.0) + @test structure.boundary_model.cache.wall_velocity == wall_velocity + end + + # Check mirrored wall pressure in EDAC's acceleration and pressure derivative, + # both with and without average-pressure reduction. Since p_b = p_a, pressure + # diffusion vanishes and the pressure force uses p_a - p_avg on both sides. + @testset "Mirrored EDAC wall: $scheme" for scheme in + ("EDAC", + "EDAC with average pressure reduction") + fluid_system = create_fluid_system(scheme, (1.0, 0.5), 1005.0, nothing) + wall = create_structure_system(WallBoundarySystem, nothing; + boundary_density=PressureMirroring()) + fluid, wall, arrays, semi, _ = initialize(fluid_system, wall) + v, u, v_wall, u_wall = arrays + dv = zero(v) + TrixiParticles.interact!(dv, v, u, v_wall, u_wall, fluid, wall, semi) + p = 500.0 - TrixiParticles.average_pressure(fluid, 1) + expected = -((fluid.mass[1] / 1005.0)^2 + 1) * p * pair_gradient / fluid.mass[1] + @test isapprox(dv[1:2, 1], expected, atol=sqrt(eps())) + @test dv[3, 1] ≈ 1005.0 * sound_speed^2 * dot(SVector(1.0, 0.5), pair_gradient) + end + # `ShepardKernelCorrection` requires `SummationDensity` for the fluid, # so it cannot be tested with the prescribed fluid densities above. shepard_configurations = ((TotalLagrangianSPHSystem, AdamiPressureExtrapolation()), diff --git a/test/systems/edac_system.jl b/test/systems/edac_system.jl index dd7dda04fe..3a93b4141f 100644 --- a/test/systems/edac_system.jl +++ b/test/systems/edac_system.jl @@ -219,15 +219,24 @@ smoothing_length = 1.6particle_spacing fluid = rectangular_patch(particle_spacing, (3, 3), seed=1) + wall = InitialCondition(; coordinates=zeros(2, 1), density=1000.0, particle_spacing) + model = BoundaryModelDummyParticles(wall.density, wall.mass, PressureMirroring(), + smoothing_kernel, smoothing_length) + wall_system = WallBoundarySystem(wall, model) transport_velocity = [nothing, TransportVelocityAdami(background_pressure=10000.0)] names = ["No TVF", "TransportVelocityAdami"] - @testset "$(names[i])" for i in eachindex(transport_velocity) + @testset "$(names[i]), mirrored wall=$mirrored_wall" for i in + eachindex(transport_velocity), + mirrored_wall in + (false, true) + system = EntropicallyDampedSPHSystem(fluid; smoothing_kernel, smoothing_length, sound_speed=0.0, shifting_technique=transport_velocity[i], average_pressure_reduction=true) - semi = Semidiscretization(system) + semi = mirrored_wall ? Semidiscretization(system, wall_system) : + Semidiscretization(system) TrixiParticles.initialize_neighborhood_searches!(semi) @@ -238,10 +247,14 @@ system.average_pressure_reduction, v_ode, u_ode, semi) - @test all(i -> system.cache.neighbor_counter[i] == nparticles(system), - nparticles(system)) - @test all(i -> isapprox(system.cache.pressure_average[i], -50.968532955185964), - nparticles(system)) + # Every particle has all particles (including itself) and the wall as neighbors + n_neighbors = nparticles(system) + mirrored_wall + @test all(==(n_neighbors), system.cache.neighbor_counter) + # The wall contributes each fluid particle's own pressure, not its zero cache. + expected = mirrored_wall ? + (sum(fluid.pressure) .+ fluid.pressure) / n_neighbors : + fill(-50.968532955185964, nparticles(system)) + @test system.cache.pressure_average ≈ expected end end diff --git a/test/systems/rigid_system.jl b/test/systems/rigid_system.jl index d549363d9d..8b46546af5 100644 --- a/test/systems/rigid_system.jl +++ b/test/systems/rigid_system.jl @@ -11,7 +11,7 @@ smoothing_kernel = SchoenbergCubicSplineKernel{2}() smoothing_length = 0.12 boundary_model = BoundaryModelDummyParticles(material_densities, mass, - SummationDensity(), + PressureZeroing(), smoothing_kernel, smoothing_length) @@ -459,7 +459,7 @@ @test_throws ArgumentError Semidiscretization(fluid_system, rigid_system) rigid_boundary_model = BoundaryModelDummyParticles(density, mass, - SummationDensity(), + PressureZeroing(), smoothing_kernel, smoothing_length) rigid_system_with_dummy = RigidBodySystem(rigid_ic;