Skip to content

Commit

Permalink
fix minor
Browse files Browse the repository at this point in the history
  • Loading branch information
LasNikas committed Nov 22, 2024
1 parent 36468f6 commit 7e74779
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
26 changes: 18 additions & 8 deletions examples/fluid/particle_refinement_2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,33 @@ gravity = 9.81
tspan = (0.0, 1.0)

# Boundary geometry and initial fluid particle positions
initial_fluid_size = (1.0, 1.0)
tank_size = (1.0, 1.0)
initial_fluid_size = (2.0, 2.0)
tank_size = (2.0, 2.0)

fluid_density = 1000.0
sound_speed = 10.0
state_equation = StateEquationCole(; sound_speed, reference_density=fluid_density,
exponent=7, clip_negative_pressure=false)

tank = RectangularTank(fluid_particle_spacing, initial_fluid_size, tank_size, fluid_density,
n_layers=boundary_layers, acceleration=(0.0, -gravity),
state_equation=state_equation)
n_layers=boundary_layers, spacing_ratio=2.0)

sphere = SphereShape(0.5 * fluid_particle_spacing, 0.3, (1.0, 1.0),
fluid_density, sphere_type=RoundSphere())
# ==========================================================================================
# ==== Fluid

fluid = setdiff(tank.fluid, sphere)

smoothing_length = 1.2 * fluid_particle_spacing
smoothing_kernel = SchoenbergQuarticSplineKernel{2}()
smoothing_kernel = SchoenbergQuinticSplineKernel{2}()

fluid_density_calculator = ContinuityDensity()
pressure = 1000.0
particle_refinement = ParticleRefinement(;
refinement_pattern=TrixiParticles.HexagonalSplitting(),
max_spacing_ratio=1.2)
fluid_system = EntropicallyDampedSPHSystem(tank.fluid, smoothing_kernel, smoothing_length,
fluid_system = EntropicallyDampedSPHSystem(fluid, smoothing_kernel, smoothing_length,
sound_speed; viscosity=ViscosityAdami(; nu=1e-4),
particle_refinement=particle_refinement,
transport_velocity=TransportVelocityAdami(pressure),
Expand All @@ -57,9 +60,15 @@ boundary_model = BoundaryModelDummyParticles(tank.boundary.density, tank.boundar
viscosity=viscosity_wall)
boundary_system = BoundarySPHSystem(tank.boundary, boundary_model, movement=nothing)

boundary_model_sphere = BoundaryModelDummyParticles(sphere.density, sphere.mass,
boundary_density_calculator,
smoothing_kernel, smoothing_length,
viscosity=viscosity_wall)
boundary_system_sphere = BoundarySPHSystem(sphere, boundary_model_sphere, movement=nothing)

# ==========================================================================================
# ==== Simulation
semi = Semidiscretization(fluid_system, boundary_system)
semi = Semidiscretization(fluid_system, boundary_system, boundary_system_sphere)
ode = semidiscretize(semi, tspan)

info_callback = InfoCallback(interval=50)
Expand All @@ -70,7 +79,8 @@ extra_callback = nothing

refinement_callback = ParticleRefinementCallback(interval=1)

callbacks = CallbackSet(info_callback, saving_callback, extra_callback, UpdateCallback(), refinement_callback)
callbacks = CallbackSet(info_callback, saving_callback, extra_callback, UpdateCallback(),
refinement_callback)

# Use a Runge-Kutta method with automatic (error based) time step size control
sol = solve(ode, RDPK3SpFSAL35(), save_everystep=false, callback=callbacks);
2 changes: 1 addition & 1 deletion src/refinement/refinement.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function upate_smoothing_lengths!(system::FluidSystem, refinement, semi, u)

PointNeighbors.foreach_neighbor(system_coords, system_coords, neighborhood_search,
particle) do particle, neighbor, pos_diff, distance
mass_avg += system.mass[neighbor]
mass_avg += hydrodynamic_mass(system, neighbor)

counter_neighbors += 1
end
Expand Down
2 changes: 1 addition & 1 deletion src/refinement/refinement_criteria.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ end
# Only consider particles with a distance > 0.
distance < sqrt(eps()) && return

dp_particle = particle_spacing(particle_system, particle)
dp_neighbor = particle_spacing(neighbor_system, neighbor)
dp_particle = smoothing_length[particle] / smoothing_length_factor

smoothing_length[particle] = smoothing_length_factor * min(dp_neighbor, dp_particle)
end
Expand Down
7 changes: 3 additions & 4 deletions src/refinement/resize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ function Base.deleteat!(system::FluidSystem, refinement, v, u)
delete_counter = 0

for particle in eachparticle(system)
if !iszero(delete_candidates[particle])
if delete_candidates[particle]
# swap particles (keep -> delete)
dump_id = nparticles(system) - delete_counter

Expand All @@ -148,9 +148,8 @@ function Base.deleteat!(system::FluidSystem, refinement, v, u)
mass_keep = hydrodynamic_mass(system, dump_id)
density_keep = particle_density(v, system, dump_id)
pressure_keep = particle_pressure(v, system, dump_id)
#TODO
# smoothing_length_keep = smoothing_length(system, dump_id)
# system.cache.smoothing_length[particle] = smoothing_length_keep

system.cache.smoothing_length[particle] = smoothing_length(system, dump_id)

system.mass[particle] = mass_keep

Expand Down

0 comments on commit 7e74779

Please sign in to comment.