Skip to content

Commit

Permalink
qualify create_cache functions (#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
LasNikas authored Nov 13, 2023
1 parent a0be24d commit 12383a8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
16 changes: 8 additions & 8 deletions src/schemes/boundary/dummy_particles/dummy_particles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ struct BoundaryModelDummyParticles{ELTYPE <: Real, SE, DC, K, V, C}

n_particles = length(initial_density)

cache = (; create_cache(viscosity, n_particles, ndims(smoothing_kernel))...,
create_cache(initial_density, density_calculator)...)
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),
Expand Down Expand Up @@ -298,29 +298,29 @@ end
grad_kernel
end

function create_cache(initial_density,
::Union{SummationDensity, PressureMirroring, PressureZeroing})
function create_cache_model(initial_density,
::Union{SummationDensity, PressureMirroring, PressureZeroing})
density = copy(initial_density)

return (; density)
end

function create_cache(initial_density, ::ContinuityDensity)
function create_cache_model(initial_density, ::ContinuityDensity)
return (; initial_density)
end

function create_cache(initial_density, ::AdamiPressureExtrapolation)
function create_cache_model(initial_density, ::AdamiPressureExtrapolation)
density = copy(initial_density)
volume = similar(initial_density)

return (; density, volume)
end

function create_cache(viscosity::NoViscosity, n_particles, n_dims)
function create_cache_model(viscosity::NoViscosity, n_particles, n_dims)
return (;)
end

function create_cache(viscosity::ViscosityAdami, n_particles, n_dims)
function create_cache_model(viscosity::ViscosityAdami, n_particles, n_dims)
ELTYPE = eltype(viscosity.nu)

wall_velocity = zeros(ELTYPE, n_dims, n_particles)
Expand Down
6 changes: 3 additions & 3 deletions src/schemes/boundary/system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct BoundarySPHSystem{BM, NDIMS, ELTYPE <: Real, M, C} <: System{NDIMS}
NDIMS = size(coordinates, 1)
ismoving = zeros(Bool, 1)

cache = create_cache(movement, inititial_condition)
cache = create_cache_boundary(movement, inititial_condition)

return new{typeof(model), NDIMS, eltype(coordinates), typeof(movement),
typeof(cache)}(coordinates, model, movement,
Expand Down Expand Up @@ -58,9 +58,9 @@ struct BoundaryMovement{MF, IM}
end
end

create_cache(::Nothing, inititial_condition) = (;)
create_cache_boundary(::Nothing, inititial_condition) = (;)

function create_cache(::BoundaryMovement, inititial_condition)
function create_cache_boundary(::BoundaryMovement, inititial_condition)
initial_coordinates = copy(inititial_condition.coordinates)
velocity = similar(inititial_condition.velocity)
acceleration = similar(inititial_condition.velocity)
Expand Down
16 changes: 8 additions & 8 deletions src/schemes/fluid/weakly_compressible_sph/system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ struct WeaklyCompressibleSPHSystem{NDIMS, ELTYPE <: Real, DC, SE, K, V, COR, C}
throw(ArgumentError("`ShepardKernelCorrection` cannot be used with `ContinuityDensity`"))
end

cache = create_cache(n_particles, ELTYPE, density_calculator)
cache = create_cache_wcsph(n_particles, ELTYPE, density_calculator)
cache = (;
create_cache(correction, initial_condition.density, NDIMS, n_particles)...,
cache...)
create_cache_wcsph(correction, initial_condition.density, NDIMS,
n_particles)..., cache...)

return new{NDIMS, ELTYPE, typeof(density_calculator), typeof(state_equation),
typeof(smoothing_kernel), typeof(viscosity),
Expand All @@ -83,24 +83,24 @@ struct WeaklyCompressibleSPHSystem{NDIMS, ELTYPE <: Real, DC, SE, K, V, COR, C}
end
end

create_cache(correction, density, NDIMS, nparticles) = (;)
create_cache_wcsph(correction, density, NDIMS, nparticles) = (;)

function create_cache(::ShepardKernelCorrection, density, NDIMS, n_particles)
function create_cache_wcsph(::ShepardKernelCorrection, density, NDIMS, n_particles)
(; kernel_correction_coefficient=similar(density))
end

function create_cache(::KernelGradientCorrection, density, NDIMS, n_particles)
function create_cache_wcsph(::KernelGradientCorrection, density, NDIMS, n_particles)
dw_gamma = Array{Float64}(undef, NDIMS, n_particles)
(; kernel_correction_coefficient=similar(density), dw_gamma)
end

function create_cache(n_particles, ELTYPE, ::SummationDensity)
function create_cache_wcsph(n_particles, ELTYPE, ::SummationDensity)
density = Vector{ELTYPE}(undef, n_particles)

return (; density)
end

function create_cache(n_particles, ELTYPE, ::ContinuityDensity)
function create_cache_wcsph(n_particles, ELTYPE, ::ContinuityDensity)
# Density in this case is added to the end of 'v' and allocated by modifying 'v_nvariables'.
return (;)
end
Expand Down

0 comments on commit 12383a8

Please sign in to comment.