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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/general/abstract_system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ end

@inline system_smoothing_kernel(system) = system.smoothing_kernel
@inline system_correction(system) = nothing
@inline system_correction_configuration(system) = nothing

# Boundary model of systems that interact with fluids via dummy particles
# (`WallBoundarySystem`, `TotalLagrangianSPHSystem`, `RigidBodySystem`), `nothing` otherwise
Expand Down
8 changes: 8 additions & 0 deletions src/general/neighborhood_search.jl
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,14 @@ function update_nhs!(neighborhood_search,
return neighborhood_search
end

# Repulsive wall systems do not update TLSPH systems; both only interact with the fluid.
function update_nhs!(neighborhood_search,
system::WallBoundarySystem{<:BoundaryModelMonaghanKajtar},
neighbor::TotalLagrangianSPHSystem,
u_system, u_neighbor, semi)
return neighborhood_search
end

# -- Wall / wall interactions
function update_nhs!(neighborhood_search,
system::WallBoundarySystem{<:BoundaryModelDummyParticles},
Expand Down
3 changes: 2 additions & 1 deletion src/general/restart.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ end
# Compute a new `tspan` based on the restart files
function time_span(tspan, restart_with::Tuple{Vararg{String}})
# Read restart times from all files
restart_times = [vtk2trixi(file).time for file in restart_with]
restart_times = [vtk2trixi(file; create_initial_condition=false).time
for file in restart_with]
t_restart = convert(eltype(tspan), first(restart_times))

# Check if all restart files have the same time
Expand Down
2 changes: 1 addition & 1 deletion src/io/read_vtk.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function vtk2trixi(file; element_type=nothing, coordinates_eltype=nothing,
elseif "material_density" in keys(point_data)
eltype(first(ReadVTK.get_data(point_data["material_density"])))
else
error("neither 'pressure' nor 'material_density' field found in VTK file")
eltype(point_coords)
end
end

Expand Down
25 changes: 15 additions & 10 deletions src/schemes/boundary/wall_boundary/dummy_particles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,18 @@ end
initial_density=initial_condition.density,
hydrodynamic_mass=initial_condition.mass,
boundary_density_calculator=AdamiPressureExtrapolation(),
smoothing_kernel=system_smoothing_kernel(fluid_system),
smoothing_length=initial_smoothing_length(fluid_system),
viscosity=nothing,
state_equation=system_state_equation(fluid_system),
correction=system_correction(fluid_system),
clip_negative_pressure=false,
reference_particle_spacing=default_reference_particle_spacing(fluid_system))
smoothing_kernel=system_smoothing_kernel(fluid_system),
smoothing_length=initial_smoothing_length(fluid_system),
viscosity=nothing,
state_equation=system_state_equation(fluid_system),
density_correction=correction_density(system_correction_configuration(fluid_system)),
gradient_correction=correction_gradient(system_correction_configuration(fluid_system)),
force_correction=correction_force(system_correction_configuration(fluid_system)),
clip_negative_pressure=false,
reference_particle_spacing=default_reference_particle_spacing(fluid_system))

High-level convenience constructor for dummy-particle wall models that infers the kernel,
smoothing length, correction, and equation-of-state-related settings from the adjacent
smoothing length, corrections, and equation-of-state-related settings from the adjacent
`fluid_system`.
"""
function BoundaryModelDummyParticles(initial_condition;
Expand All @@ -106,13 +108,16 @@ function BoundaryModelDummyParticles(initial_condition;
smoothing_length=initial_smoothing_length(fluid_system),
viscosity=nothing,
state_equation=system_state_equation(fluid_system),
correction=system_correction(fluid_system),
density_correction=correction_density(system_correction_configuration(fluid_system)),
gradient_correction=correction_gradient(system_correction_configuration(fluid_system)),
force_correction=correction_force(system_correction_configuration(fluid_system)),
clip_negative_pressure=false,
reference_particle_spacing=default_reference_particle_spacing(fluid_system))
return BoundaryModelDummyParticles(initial_density, hydrodynamic_mass,
boundary_density_calculator, smoothing_kernel,
smoothing_length;
viscosity, state_equation, correction,
viscosity, state_equation, density_correction,
gradient_correction, force_correction,
clip_negative_pressure,
reference_particle_spacing)
end
Expand Down
20 changes: 14 additions & 6 deletions src/schemes/boundary/wall_boundary/monaghan_kajtar.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@doc raw"""
BoundaryModelMonaghanKajtar(K, beta, boundary_particle_spacing, mass;
viscosity=nothing)
viscosity=nothing, minimum_distance_ratio=0.01)

Boundary model for [`WallBoundarySystem`](@ref).

Expand All @@ -12,23 +12,30 @@ Boundary model for [`WallBoundarySystem`](@ref).

# Keywords
- `viscosity`: Free-slip (default) or no-slip condition. See description above for further
information.
information.
- `minimum_distance_ratio`: Lower bound for the distance from the force singularity,
relative to the boundary particle spacing (default: 0.01).
"""
struct BoundaryModelMonaghanKajtar{ELTYPE <: Real, VECTOR, V}
K :: ELTYPE
beta :: ELTYPE
boundary_particle_spacing :: ELTYPE
minimum_distance_ratio :: ELTYPE
hydrodynamic_mass :: VECTOR # Vector{ELTYPE}
viscosity :: V
end

# The default constructor needs to be accessible for Adapt.jl to work with this struct.
# See the comments in general/gpu.jl for more details.
function BoundaryModelMonaghanKajtar(K, beta, boundary_particle_spacing, mass;
viscosity=nothing)
viscosity=nothing, minimum_distance_ratio=0.01)
minimum_distance_ratio_ = convert(typeof(K), minimum_distance_ratio)
0 < minimum_distance_ratio_ <= 1 ||
throw(ArgumentError("`minimum_distance_ratio` must be in (0, 1]"))

return BoundaryModelMonaghanKajtar(K, convert(typeof(K), beta),
boundary_particle_spacing,
mass, viscosity)
minimum_distance_ratio_, mass, viscosity)
end

function Base.show(io::IO, model::BoundaryModelMonaghanKajtar)
Expand All @@ -52,7 +59,8 @@ end
TotalLagrangianSPHSystem{<:BoundaryModelMonaghanKajtar}},
particle, neighbor, m_a, m_b, p_a, p_b, rho_a, rho_b,
pos_diff, distance, grad_kernel, correction)
(; K, beta, boundary_particle_spacing) = neighbor_system.boundary_model
(; K, beta, boundary_particle_spacing,
minimum_distance_ratio) = neighbor_system.boundary_model

# This is `distance - boundary_particle_spacing` in the paper. This factor makes
# the force grow infinitely close to the boundary, with a singularity where
Expand All @@ -63,7 +71,7 @@ end
# In order to avoid this, we clip the force at a "large" value, large enough to prevent
# penetration when a reasonable `K` is used, but small enough to not cause instabilites
# or super small time steps.
distance_from_singularity = max(boundary_particle_spacing / 100,
distance_from_singularity = max(boundary_particle_spacing * minimum_distance_ratio,
distance - boundary_particle_spacing)

return K / beta^(ndims(particle_system) - 1) * pos_diff /
Expand Down
4 changes: 4 additions & 0 deletions src/schemes/fluid/entropically_damped_sph/system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,10 @@ function system_correction(system::EntropicallyDampedSPHSystem)
correction_gradient(system.correction)
end

@inline function system_correction_configuration(system::EntropicallyDampedSPHSystem)
return system.correction
end

@inline function current_velocity(v, system::EntropicallyDampedSPHSystem)
return view(v, 1:ndims(system), :)
end
Expand Down
4 changes: 4 additions & 0 deletions src/schemes/fluid/weakly_compressible_sph/system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ function system_correction(system::WeaklyCompressibleSPHSystem)
correction_gradient(system.correction)
end

@inline function system_correction_configuration(system::WeaklyCompressibleSPHSystem)
return system.correction
end

@propagate_inbounds function current_velocity(v, system::WeaklyCompressibleSPHSystem)
return current_velocity(v, system.density_calculator, system)
end
Expand Down
3 changes: 2 additions & 1 deletion test/examples/gpu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ end
boundary_model = BoundaryModelDummyParticles(boundary_initial.density,
boundary_initial.mass,
SummationDensity(), smoothing_kernel,
2spacing; state_equation, correction)
2spacing; state_equation,
gradient_correction=correction)
boundary = WallBoundarySystem(boundary_initial, boundary_model)
semi = Semidiscretization(fluid, boundary; neighborhood_search=nothing,
parallelization_backend=backend)
Expand Down
31 changes: 19 additions & 12 deletions test/general/corrections/lifecycle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
smoothing_length,
sound_speed=10.0,
density_calculator=SummationDensity(),
correction=ShepardKernelCorrection())
density_correction=ShepardKernelCorrection())
end

state_equation = StateEquationCole(; sound_speed=10.0,
Expand All @@ -136,7 +136,7 @@
smoothing_length,
state_equation,
density_calculator=SummationDensity(),
correction=ShepardKernelCorrection())
density_correction=ShepardKernelCorrection())
end

systems = reverse_order ? (make_system(initial_b), make_system(initial_a)) :
Expand Down Expand Up @@ -223,10 +223,13 @@ end
reference_density=density, exponent=1)

function structure_setup(correction)
density_correction = TrixiParticles.correction_density(correction)
gradient_correction = TrixiParticles.correction_gradient(correction)
boundary_model = BoundaryModelDummyParticles(particles.density, particles.mass,
SummationDensity(), smoothing_kernel,
smoothing_length;
state_equation, correction)
state_equation, density_correction,
gradient_correction)
system = TotalLagrangianSPHSystem(particles; smoothing_kernel, smoothing_length,
young_modulus=1.0e6, poisson_ratio=0.3,
boundary_model)
Expand Down Expand Up @@ -265,7 +268,7 @@ end
smoothing_kernel, smoothing_length,
state_equation,
density_calculator=SummationDensity(),
correction=ShepardKernelCorrection())
density_correction=ShepardKernelCorrection())

structure_particles = RectangularShape(particle_spacing, (3, 2), (0.0, -0.15);
density=1200.0)
Expand All @@ -278,7 +281,7 @@ end
SummationDensity(), smoothing_kernel,
smoothing_length;
state_equation,
correction=ShepardKernelCorrection())
density_correction=ShepardKernelCorrection())
structure = TotalLagrangianSPHSystem(structure_particles;
smoothing_kernel, smoothing_length,
young_modulus=1.0e6, poisson_ratio=0.3,
Expand Down Expand Up @@ -342,16 +345,20 @@ end
particle) ≈ raw_gradient
@test hydrodynamic_gradient ≈ correction_matrix * raw_gradient

# Rigid-body correction caches are not implemented. Reject both density and gradient
# corrections at construction instead of allowing a later crash or stale normalization.
error_message = "corrections in `BoundaryModelDummyParticles` are not supported " *
"for `RigidBodySystem`"
# Rigid bodies use the same hydrodynamic boundary correction caches. Ensure that both
# correction roles survive construction independently.
for correction in (ShepardKernelCorrection(), GradientCorrection())
density_correction = TrixiParticles.correction_density(correction)
gradient_correction = TrixiParticles.correction_gradient(correction)
boundary_model = BoundaryModelDummyParticles(particles.density, particles.mass,
SummationDensity(), smoothing_kernel,
smoothing_length;
state_equation, correction)
@test_throws ArgumentError(error_message) RigidBodySystem(particles;
boundary_model)
state_equation, density_correction,
gradient_correction)
rigid = RigidBodySystem(particles; boundary_model)
@test TrixiParticles.correction_density(rigid.boundary_model.correction) ===
density_correction
@test TrixiParticles.correction_gradient(rigid.boundary_model.correction) ===
gradient_correction
end
end
48 changes: 45 additions & 3 deletions test/schemes/boundary/monaghan_kajtar/monaghan_kajtar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@

show_compact = "BoundaryModelMonaghanKajtar(10.0, 3.0, Nothing)"
@test repr(boundary_model) == show_compact
@test boundary_model.minimum_distance_ratio == 0.01

regularized_model = BoundaryModelMonaghanKajtar(10.0, 3.0, 0.1, [1.0];
minimum_distance_ratio=0.001)
@test regularized_model.minimum_distance_ratio == 0.001
@test_throws ArgumentError BoundaryModelMonaghanKajtar(10.0, 3.0, 0.1, [1.0];
minimum_distance_ratio=0.0)
end

@testset "RHS" begin
particle_spacing = 0.1

# The state equation is only needed to unpack `sound_speed`, so we can mock
# it by using a `NamedTuple`.
state_equation = (; sound_speed=0.0)
state_equation = StateEquationCole(; sound_speed=1.0, reference_density=1000.0,
exponent=7)
smoothing_kernel = SchoenbergCubicSplineKernel{2}()
smoothing_length = 1.2particle_spacing
search_radius = TrixiParticles.compact_support(smoothing_kernel, smoothing_length)
Expand Down Expand Up @@ -65,5 +71,41 @@

# The middle column of fluid particles should experience weaker accelerations
@test isapprox(dv[1, [2, 5, 8]], [-26.052449, -95.162888, -26.052449])

structure_model = BoundaryModelMonaghanKajtar(K, 1.0, particle_spacing,
fluid.mass)
structure_system = TotalLagrangianSPHSystem(fluid; smoothing_kernel,
smoothing_length,
young_modulus=1.0e6,
poisson_ratio=0.3,
boundary_model=structure_model)
semi_coupled = Semidiscretization(fluid_system, boundary_system, structure_system;
parallelization_backend=SerialBackend())
ode = semidiscretize(semi_coupled, (0.0, 0.1))
@test_nowarn TrixiParticles.update_nhs!(semi_coupled, ode.u0.x[2])

function structure_marker(system, dv_ode, du_ode, v_ode, u_ode, semi, t)
system isa TotalLagrangianSPHSystem || return nothing
coordinates = TrixiParticles.initial_coordinates(system)
return fill(Int32(7), size(coordinates, 2))
end

mktempdir() do output_directory
@test_nowarn trixi2vtk(ode.u0, semi_coupled, 0.0; output_directory,
structure_marker)
data = vtk2trixi(joinpath(output_directory, "structure_1_current.vtu"))
@test data.structure_marker == fill(Int32(7),
TrixiParticles.nparticles(structure_system))

boundary_data = vtk2trixi(joinpath(output_directory,
"boundary_1_current.vtu");
create_initial_condition=false)
@test size(boundary_data.coordinates, 2) ==
TrixiParticles.nparticles(boundary_system)
@test TrixiParticles.time_span((0.0, 0.1),
(joinpath(output_directory,
"boundary_1_current.vtu"),)) ==
(0.0, 0.1)
end
end
end
Loading
Loading