Skip to content

Commit

Permalink
Simplify dispatch of boundary models (#300)
Browse files Browse the repository at this point in the history
  • Loading branch information
efaulhaber authored Nov 28, 2023
1 parent 5fc8916 commit 504b406
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 84 deletions.
6 changes: 3 additions & 3 deletions src/schemes/boundary/dummy_particles/dummy_particles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ We provide five options to compute the boundary density and pressure, determined
In: Computers, Materials and Continua 5 (2007), pages 173-184.
[doi: 10.3970/cmc.2007.005.173](https://doi.org/10.3970/cmc.2007.005.173)
"""
struct BoundaryModelDummyParticles{ELTYPE <: Real, SE, DC, K, V, C}
struct BoundaryModelDummyParticles{DC, ELTYPE <: Real, SE, K, V, C}
pressure :: Vector{ELTYPE}
hydrodynamic_mass :: Vector{ELTYPE}
state_equation :: SE
Expand All @@ -96,8 +96,8 @@ struct BoundaryModelDummyParticles{ELTYPE <: Real, SE, DC, K, V, C}
cache = (; create_cache_model(viscosity, n_particles, ndims(smoothing_kernel))...,
create_cache_model(initial_density, density_calculator)...)

new{eltype(initial_density), typeof(state_equation),
typeof(density_calculator), typeof(smoothing_kernel), typeof(viscosity),
new{typeof(density_calculator), eltype(initial_density),
typeof(state_equation), typeof(smoothing_kernel), typeof(viscosity),
typeof(cache)}(pressure, hydrodynamic_mass, state_equation, density_calculator,
smoothing_kernel, smoothing_length, viscosity, cache)
end
Expand Down
27 changes: 6 additions & 21 deletions src/schemes/boundary/rhs.jl
Original file line number Diff line number Diff line change
@@ -1,34 +1,19 @@
# Interaction of boundary with other systems
function interact!(dv, v_particle_system, u_particle_system,
v_neighbor_system, u_neighbor_system, neighborhood_search,
particle_system::BoundarySPHSystem,
neighbor_system)
particle_system::BoundarySPHSystem, neighbor_system)
# TODO Solids and moving boundaries should be considered in the continuity equation
return dv
end

# Boundary-fluid interaction with dummy particles model
# For dummy particles with `ContinuityDensity`, solve the continuity equation
function interact!(dv, v_particle_system, u_particle_system,
v_neighbor_system, u_neighbor_system, neighborhood_search,
particle_system::BoundarySPHSystem{<:BoundaryModelDummyParticles},
particle_system::BoundarySPHSystem{
<:BoundaryModelDummyParticles{
ContinuityDensity
}},
neighbor_system::FluidSystem)
(; density_calculator) = particle_system.boundary_model

interact!(dv, v_particle_system, u_particle_system,
v_neighbor_system, u_neighbor_system, neighborhood_search,
particle_system, neighbor_system, density_calculator)
end

function interact!(dv, v_particle_system, u_particle_system,
v_neighbor_system, u_neighbor_system, neighborhood_search,
particle_system::BoundarySPHSystem, neighbor_system, density_calculator)
return dv
end

# With `ContinuityDensity` solve the continuity equation
function interact!(dv, v_particle_system, u_particle_system,
v_neighbor_system, u_neighbor_system, neighborhood_search,
particle_system::BoundarySPHSystem, neighbor_system, ::ContinuityDensity)
(; boundary_model) = particle_system

system_coords = current_coordinates(u_particle_system, particle_system)
Expand Down
52 changes: 16 additions & 36 deletions src/schemes/boundary/system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,23 +133,17 @@ end
end

# No particle positions are advanced for boundary systems,
# except when using BoundaryModelDummyParticles with ContinuityDensity.
# except when using `BoundaryModelDummyParticles` with `ContinuityDensity`.
@inline function n_moving_particles(system::BoundarySPHSystem)
return 0
end

@inline function n_moving_particles(system::BoundarySPHSystem{
<:BoundaryModelDummyParticles
<:BoundaryModelDummyParticles{
ContinuityDensity
}
})
return n_moving_particles(system, system.boundary_model.density_calculator)
end

@inline function n_moving_particles(system::BoundarySPHSystem, density_calculator)
return 0
end

@inline function n_moving_particles(system::BoundarySPHSystem, ::ContinuityDensity)
nparticles(system)
return nparticles(system)
end

@inline u_nvariables(system::BoundarySPHSystem) = 0
Expand Down Expand Up @@ -239,21 +233,15 @@ function write_u0!(u0, system::BoundarySPHSystem)
return u0
end

function write_v0!(v0, system::BoundarySPHSystem{<:BoundaryModelMonaghanKajtar})
return v0
end

function write_v0!(v0, system::BoundarySPHSystem{<:BoundaryModelDummyParticles})
(; density_calculator) = system.boundary_model

write_v0!(v0, density_calculator, system)
end

function write_v0!(v0, density_calculator, system::BoundarySPHSystem)
function write_v0!(v0, system::BoundarySPHSystem)
return v0
end

function write_v0!(v0, ::ContinuityDensity, system::BoundarySPHSystem)
function write_v0!(v0,
system::BoundarySPHSystem{
<:BoundaryModelDummyParticles{ContinuityDensity
}
})
(; cache) = system.boundary_model
(; initial_density) = cache

Expand All @@ -266,22 +254,14 @@ function write_v0!(v0, ::ContinuityDensity, system::BoundarySPHSystem)
end

function restart_with!(system::BoundarySPHSystem, v, u)
restart_with!(system, system.boundary_model, v, u)
end

function restart_with!(system, ::BoundaryModelMonaghanKajtar, v, u)
return system
end

function restart_with!(system, model::BoundaryModelDummyParticles, v, u)
restart_with!(system, model, model.density_calculator, v, u)
end

function restart_with!(system, model, density_calculator, v, u)
return system
end

function restart_with!(system, model, ::ContinuityDensity, v, u)
function restart_with!(system::BoundarySPHSystem{
<:BoundaryModelDummyParticles{
ContinuityDensity
}},
v, u)
(; initial_density) = model.cache

for particle in eachparticle(system)
Expand Down
31 changes: 7 additions & 24 deletions src/schemes/solid/total_lagrangian_sph/system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -180,23 +180,15 @@ end

timer_name(::TotalLagrangianSPHSystem) = "solid"

@inline function v_nvariables(system::TotalLagrangianSPHSystem{
<:BoundaryModelMonaghanKajtar
})
@inline function v_nvariables(system::TotalLagrangianSPHSystem)
return ndims(system)
end

@inline function v_nvariables(system::TotalLagrangianSPHSystem{
<:BoundaryModelDummyParticles
<:BoundaryModelDummyParticles{
ContinuityDensity
}
})
return v_nvariables(system, system.boundary_model.density_calculator)
end

@inline function v_nvariables(system::TotalLagrangianSPHSystem, density_calculator)
return ndims(system)
end

@inline function v_nvariables(system::TotalLagrangianSPHSystem, ::ContinuityDensity)
return ndims(system) + 1
end

Expand Down Expand Up @@ -386,21 +378,12 @@ function write_v0!(v0, system::TotalLagrangianSPHSystem)
return v0
end

function write_v0!(v0, ::BoundaryModelMonaghanKajtar, system::TotalLagrangianSPHSystem)
return v0
end

function write_v0!(v0, ::BoundaryModelDummyParticles, system::TotalLagrangianSPHSystem)
(; density_calculator) = system.boundary_model

write_v0!(v0, density_calculator, system)
end

function write_v0!(v0, density_calculator, system::TotalLagrangianSPHSystem)
function write_v0!(v0, model, system::TotalLagrangianSPHSystem)
return v0
end

function write_v0!(v0, ::ContinuityDensity, system::TotalLagrangianSPHSystem)
function write_v0!(v0, ::BoundaryModelDummyParticles{ContinuityDensity},
system::TotalLagrangianSPHSystem)
(; cache) = system.boundary_model
(; initial_density) = cache

Expand Down

0 comments on commit 504b406

Please sign in to comment.