@@ -82,7 +82,7 @@ function OpenBoundarySystem(boundary_zones::Union{BoundaryZone, Nothing}...;
8282 mass = copy (initial_conditions. mass)
8383 volume = similar (initial_conditions. density)
8484
85- cache = (;
85+ cache = (; neighbor_counter = zeros (Int, nparticles (initial_conditions)),
8686 create_cache_shifting (initial_conditions, shifting_technique)... ,
8787 create_cache_open_boundary (boundary_model, fluid_system, initial_conditions,
8888 boundary_zones_)... )
@@ -305,6 +305,8 @@ function update_open_boundary_eachstep!(system::OpenBoundarySystem, v_ode, u_ode
305305 u = wrap_u (u_ode, system, semi)
306306 v = wrap_v (v_ode, system, semi)
307307
308+ deactivate_lost_particles! (system, shifting_technique (system), u, semi)
309+
308310 @trixi_timeit timer () " check domain" check_domain! (system, v, u, v_ode, u_ode, semi)
309311
310312 update_pressure_model! (system, v, u, semi, integrator. dt)
551553
552554 return system
553555end
556+
557+ @inline deactivate_lost_particles! (system, :: Nothing , u, semi) = system
558+
559+ @inline function deactivate_lost_particles! (system, :: AbstractShiftingTechnique , u, semi)
560+ (; neighbor_counter) = system. cache
561+
562+ set_zero! (neighbor_counter)
563+
564+ # Loop over all pairs of particles and neighbors within the kernel cutoff.
565+ system_coords = current_coordinates (u, system)
566+ foreach_point_neighbor (system, system, system_coords, system_coords, semi;
567+ points= each_integrated_particle (system)) do particle,
568+ neighbor,
569+ pos_diff,
570+ distance
571+ (particle == neighbor) && return
572+ neighbor_counter[particle] += 1
573+ end
574+
575+ @threaded semi for particle in each_integrated_particle (system)
576+ # Deactivate particles that have three or fewer neighbors.
577+ # The threshold of 3 also accounts for possible clustered pairs.
578+ if neighbor_counter[particle] <= 3
579+ @warn " deactivate particle $particle "
580+ deactivate_particle! (system, particle, u)
581+ end
582+ end
583+
584+ update_system_buffer! (system. buffer, semi)
585+
586+ return system
587+ end
0 commit comments