Skip to content

Commit

Permalink
Cleanup Viscosity/Boundary Model (#566)
Browse files Browse the repository at this point in the history
* extract changes from #564

* fix
  • Loading branch information
svchb authored Jun 28, 2024
1 parent ffe3663 commit 7796ac9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 60 deletions.
59 changes: 24 additions & 35 deletions src/schemes/boundary/dummy_particles/dummy_particles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,15 @@ function BoundaryModelDummyParticles(initial_density, hydrodynamic_mass,
pressure = initial_boundary_pressure(initial_density, density_calculator,
state_equation)
NDIMS = ndims(smoothing_kernel)

n_particles = length(initial_density)

cache = (; create_cache_model(viscosity, n_particles, NDIMS)...,
create_cache_model(initial_density, density_calculator)...)
cache = (; create_cache_model(correction, initial_density, NDIMS,
n_particles)..., cache...)
create_cache_model(initial_density, density_calculator)...,
create_cache_model(correction, initial_density, NDIMS, n_particles)...)

return BoundaryModelDummyParticles(pressure, hydrodynamic_mass,
state_equation, density_calculator,
smoothing_kernel, smoothing_length,
viscosity, correction, cache)
return BoundaryModelDummyParticles(pressure, hydrodynamic_mass, state_equation,
density_calculator, smoothing_kernel,
smoothing_length, viscosity, correction, cache)
end

@doc raw"""
Expand Down Expand Up @@ -105,7 +102,7 @@ struct PressureMirroring end
"""
struct PressureZeroing end

create_cache_model(correction, density, NDIMS, nparticles) = (;)
@inline create_cache_model(correction, density, NDIMS, nparticles) = (;)

function create_cache_model(::ShepardKernelCorrection, density, NDIMS, n_particles)
return (; kernel_correction_coefficient=similar(density))
Expand Down Expand Up @@ -135,9 +132,7 @@ function create_cache_model(initial_density,
return (; density)
end

function create_cache_model(initial_density, ::ContinuityDensity)
return (; initial_density)
end
@inline create_cache_model(initial_density, ::ContinuityDensity) = (; initial_density)

function create_cache_model(initial_density, ::AdamiPressureExtrapolation)
density = copy(initial_density)
Expand All @@ -146,9 +141,7 @@ function create_cache_model(initial_density, ::AdamiPressureExtrapolation)
return (; density, volume)
end

function create_cache_model(viscosity::Nothing, n_particles, n_dims)
return (;)
end
@inline create_cache_model(viscosity::Nothing, n_particles, n_dims) = (;)

function create_cache_model(viscosity, n_particles, n_dims)
ELTYPE = eltype(viscosity.epsilon)
Expand Down Expand Up @@ -306,10 +299,9 @@ end
boundary_model.pressure[particle] = max(boundary_model.state_equation(density), 0.0)
end

function compute_pressure!(boundary_model, ::AdamiPressureExtrapolation,
system, v, u, v_ode, u_ode, semi)
(; pressure, state_equation, cache, viscosity) = boundary_model
(; volume, density) = cache
function compute_pressure!(boundary_model, ::AdamiPressureExtrapolation, system, v, u,
v_ode, u_ode, semi)
(; pressure, cache, viscosity) = boundary_model

set_zero!(pressure)

Expand Down Expand Up @@ -386,6 +378,13 @@ function compute_pressure!(boundary_model, ::Union{PressureMirroring, PressureZe
return boundary_model
end

@inline function adami_pressure_extrapolation_neighbor!(boundary_model, system,
neighbor_system, system_coords,
neighbor_coords, v_neighbor_system,
neighborhood_search)
return boundary_model
end

@inline function adami_pressure_extrapolation_neighbor!(boundary_model, system,
neighbor_system::FluidSystem,
system_coords, neighbor_coords,
Expand All @@ -401,17 +400,15 @@ end
pos_diff, distance
# Since neighbor and particle are switched
pos_diff = -pos_diff
adami_pressure_inner!(boundary_model, system, neighbor_system::FluidSystem,
adami_pressure_inner!(boundary_model, system, neighbor_system,
v_neighbor_system, particle, neighbor, pos_diff,
distance, viscosity, cache, pressure)
end
end

@inline function adami_pressure_extrapolation_neighbor!(boundary_model, system,
neighbor_system,
system_coords, neighbor_coords,
v_neighbor_system,
neighborhood_search)
@inline function adami_pressure_extrapolation!(boundary_model, system, neighbor_system,
system_coords, neighbor_coords,
v_neighbor_system, neighborhood_search)
return boundary_model
end

Expand All @@ -433,14 +430,7 @@ end
end
end

@inline function adami_pressure_extrapolation!(boundary_model, system, neighbor_system,
system_coords, neighbor_coords,
v_neighbor_system, neighborhood_search)
return boundary_model
end

@inline function adami_pressure_inner!(boundary_model, system,
neighbor_system::FluidSystem,
@inline function adami_pressure_inner!(boundary_model, system, neighbor_system,
v_neighbor_system, particle, neighbor, pos_diff,
distance, viscosity, cache, pressure)
density_neighbor = particle_density(v_neighbor_system, neighbor_system, neighbor)
Expand Down Expand Up @@ -510,8 +500,7 @@ end
return density
end

@inline function smoothing_kernel_grad(system::BoundarySystem, pos_diff,
distance, particle)
@inline function smoothing_kernel_grad(system::BoundarySystem, pos_diff, distance, particle)
(; smoothing_kernel, smoothing_length, correction) = system.boundary_model

return corrected_kernel_grad(smoothing_kernel, pos_diff, distance,
Expand Down
28 changes: 3 additions & 25 deletions src/visualization/write2vtk.jl
Original file line number Diff line number Diff line change
Expand Up @@ -353,36 +353,14 @@ function write2vtk!(vtk, v, u, t, model::BoundaryModelDummyParticles, system;
vtk["smoothing_length"] = system.boundary_model.smoothing_length
vtk["density_calculator"] = type2string(system.boundary_model.density_calculator)
vtk["state_equation"] = type2string(system.boundary_model.state_equation)
vtk["viscosity_model"] = type2string(model.viscosity)
end

write2vtk!(vtk, v, u, t, model, model.viscosity, system,
write_meta_data=write_meta_data)
end

function write2vtk!(vtk, v, u, t, model::BoundaryModelDummyParticles, viscosity, system;
write_meta_data=true)
vtk["hydrodynamic_density"] = [particle_density(v, system, particle)
for particle in eachparticle(system)]
vtk["pressure"] = model.pressure

if write_meta_data
vtk["viscosity_model"] = type2string(viscosity)
if model.viscosity isa ViscosityAdami
vtk["wall_velocity"] = view(model.cache.wall_velocity, 1:ndims(system), :)
end

return vtk
end

function write2vtk!(vtk, v, u, t, model::BoundaryModelDummyParticles,
viscosity::ViscosityAdami, system;
write_meta_data=true)
vtk["hydrodynamic_density"] = [particle_density(v, system, particle)
for particle in eachparticle(system)]
vtk["pressure"] = model.pressure
vtk["wall_velocity"] = view(model.cache.wall_velocity, 1:ndims(system), :)

if write_meta_data
vtk["viscosity_model"] = type2string(viscosity)
end

return vtk
end

0 comments on commit 7796ac9

Please sign in to comment.