Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify dispatch of boundary models #300

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Comment on lines 10 to 16
Copy link
Collaborator

@LasNikas LasNikas Nov 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something like that would also work:

function interact!(dv, v_particle_system, u_particle_system,
                   v_neighbor_system, u_neighbor_system, neighborhood_search,
                   particle_system::BoundarySPHSystem{T},
                   neighbor_system::FluidSystem
                   ) where {T <: BoundaryModelDummyParticles{<:ContinuityDensity}}
end

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

T <: BoundaryModelDummyParticles{ContinuityDensity}, but yes.
The question is if this more complicated expression is worth it just to avoid a longer line (which, of course, looks terrible right now, but will look much nicer with the JuliaFormatter PR).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new JuliaFormatter PR will format code like this, right?
image

Then I think this is more readable IMHO:
Screenshot from 2023-11-28 18-00-28

Under the condition that it is not formatted as follows:
Screenshot from 2023-11-28 18-00-02

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the JuliaFormatter PR, I get the following options:
grafik

grafik Closing parenthesis in a new line is not allowed (not in the current JuliaFormatter version either).

(; 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