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

Add basic unit test for density #239

Merged
merged 13 commits into from
Oct 26, 2023
3 changes: 1 addition & 2 deletions src/general/density_calculators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ function summation_density!(system, system_index, semi, u, u_ode, density;
# Loop over all pairs of particles and neighbors within the kernel cutoff.
for_particle_neighbor(system, neighbor_system, system_coords, neighbor_coords,
neighborhood_search,
particles=particles) do particle,
neighbor, pos_diff, distance
particles=particles) do particle, neighbor, pos_diff, distance
mass = hydrodynamic_mass(neighbor_system, neighbor)
density[particle] += mass * smoothing_kernel(system, distance)
end
Expand Down
22 changes: 8 additions & 14 deletions test/general/density_calculator.jl
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
using OrdinaryDiffEq

# setup a single particle and calculate its density
# Setup a single particle and calculate its density
@testset verbose=true "DensityCalculators" begin
@testset verbose=true "SummationDensity" begin
water_density = 1000.0

# use reshape to create a matrix
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# use reshape to create a matrix

init = InitialCondition(reshape([0.0, 0.0], 2, 1), reshape([0.0, 0.0], 2, 1),
[water_density], [water_density])
initial_condition = InitialCondition(zeros(2, 1), zeros(2, 1), [water_density],
[water_density])

smoothing_length = 1.0
smoothing_kernel = SchoenbergCubicSplineKernel{2}()

state_equation = StateEquationCole(10, 7, water_density, 100000.0,
background_pressure=100000.0,
clip_negative_pressure=false)
background_pressure=100000.0)
viscosity = ArtificialViscosityMonaghan(0.02, 0.0)

fluid_system = WeaklyCompressibleSPHSystem(init, SummationDensity(), state_equation,
fluid_system = WeaklyCompressibleSPHSystem(initial_condition, SummationDensity(),
state_equation,
smoothing_kernel, smoothing_length,
viscosity=viscosity,
acceleration=(0.0, 0.0))
viscosity=viscosity)

(; cache) = fluid_system
(; density) = cache # Density is in the cache for SummationDensity
Expand All @@ -30,12 +29,7 @@ using OrdinaryDiffEq

tspan = (0.0, 0.01)
ode = semidiscretize(semi, tspan)

sol = solve(ode, RDPK3SpFSAL49(),
abstol=1e-5, # Default abstol is 1e-6 (may need to be tuned to prevent boundary penetration)
reltol=1e-3, # Default reltol is 1e-3 (may need to be tuned to prevent boundary penetration)
dtmax=1e-2, # Limit stepsize to prevent crashing
save_everystep=false)
TrixiParticles.update_systems_and_nhs(ode.u0.x..., semi, 0.0)

@test density[1] ===
water_density * TrixiParticles.kernel(smoothing_kernel, 0.0, smoothing_length)
Expand Down