Skip to content

Commit 3b2cb2e

Browse files
author
LasNikas
committed
Merge branch 'more-robust-obc-II' into fsi-aorta
2 parents fe71099 + 4e4f5a9 commit 3b2cb2e

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

src/schemes/boundary/open_boundary/system.jl

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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)
@@ -564,3 +566,39 @@ end
564566

565567
return system
566568
end
569+
570+
@inline deactivate_lost_particles!(system, ::Nothing, u, semi) = system
571+
572+
@inline function deactivate_lost_particles!(system, ::AbstractShiftingTechnique, u, semi)
573+
(; particle_spacing) = system.initial_condition
574+
(; neighbor_counter) = system.cache
575+
576+
set_zero!(neighbor_counter)
577+
578+
# Loop over all pairs of particles and neighbors within the kernel cutoff.
579+
system_coords = current_coordinates(u, system)
580+
foreach_point_neighbor(system, system, system_coords, system_coords, semi;
581+
points=each_integrated_particle(system)) do particle,
582+
neighbor,
583+
pos_diff,
584+
distance
585+
(particle == neighbor) && return
586+
neighbor_counter[particle] += 1
587+
end
588+
589+
# Set 20% of the ideal neighbor count as threshold
590+
min_neighbors = ideal_neighbor_count(Val(ndims(system)), particle_spacing,
591+
compact_support(system, system)) / 5
592+
593+
@threaded semi for particle in each_integrated_particle(system)
594+
# Deactivate particles that have too few neighbors
595+
if neighbor_counter[particle] < min_neighbors
596+
@warn "deactivate particle $particle"
597+
deactivate_particle!(system, particle, u)
598+
end
599+
end
600+
601+
update_system_buffer!(system.buffer, semi)
602+
603+
return system
604+
end

0 commit comments

Comments
 (0)