|
| 1 | +@testset verbose=true "Deactivate Out of Bounds Particles" begin |
| 2 | + struct MockSystemOutOfBounds <: TrixiParticles.AbstractSystem{2} |
| 3 | + buffer::TrixiParticles.SystemBuffer |
| 4 | + end |
| 5 | + |
| 6 | + TrixiParticles.nparticles(system::MockSystemOutOfBounds) = length(system.buffer.active_particle) |
| 7 | + Base.eltype(system::MockSystemOutOfBounds) = Float64 |
| 8 | + |
| 9 | + @testset "Particles Inside Bounds" begin |
| 10 | + # Setup: 5 particles, all inside bounds |
| 11 | + buffer = TrixiParticles.SystemBuffer(5, 0) |
| 12 | + system = MockSystemOutOfBounds(buffer) |
| 13 | + |
| 14 | + u = [-0.5 0.0 0.5 -0.8 0.8 |
| 15 | + -0.5 -0.5 0.0 0.5 0.5] |
| 16 | + |
| 17 | + cell_list = TrixiParticles.FullGridCellList(; min_corner=(-1.0, -1.0), |
| 18 | + max_corner=(1.0, 1.0), |
| 19 | + search_radius=0.1) |
| 20 | + dummy_nhs = (; cell_size=0.1, periodic_box=nothing, cell_list) |
| 21 | + semi = DummySemidiscretization() |
| 22 | + |
| 23 | + # All particles should remain active |
| 24 | + initial_count = count(buffer.active_particle) |
| 25 | + TrixiParticles.deactivate_out_of_bounds_particles!(system, buffer, dummy_nhs, |
| 26 | + cell_list, u, u, semi) |
| 27 | + @test count(buffer.active_particle) == initial_count |
| 28 | + end |
| 29 | + |
| 30 | + @testset "Particles Outside Bounds" begin |
| 31 | + # Setup: 5 particles, some outside bounds |
| 32 | + buffer = TrixiParticles.SystemBuffer(5, 0) |
| 33 | + system = MockSystemOutOfBounds(buffer) |
| 34 | + |
| 35 | + # Particles 3 and 5 are outside the bounds |
| 36 | + u = [-0.5 0.0 2.0 -0.8 -2.0 |
| 37 | + -0.5 -0.5 0.0 0.5 0.5] |
| 38 | + |
| 39 | + cell_list = TrixiParticles.FullGridCellList(; min_corner=(-1.0, -1.0), |
| 40 | + max_corner=(1.0, 1.0), |
| 41 | + search_radius=0.1) |
| 42 | + dummy_nhs = (; cell_size=0.1, periodic_box=nothing, cell_list) |
| 43 | + semi = DummySemidiscretization() |
| 44 | + |
| 45 | + TrixiParticles.deactivate_out_of_bounds_particles!(system, buffer, dummy_nhs, |
| 46 | + cell_list, u, u, semi) |
| 47 | + |
| 48 | + # Particles 3 and 5 should be deactivated |
| 49 | + @test buffer.active_particle[3] == false |
| 50 | + @test buffer.active_particle[5] == false |
| 51 | + # Others should still be active |
| 52 | + @test buffer.active_particle[1] == true |
| 53 | + @test buffer.active_particle[2] == true |
| 54 | + @test buffer.active_particle[4] == true |
| 55 | + |
| 56 | + @test TrixiParticles.each_active_particle(system, buffer) == [1, 2, 4] |
| 57 | + end |
| 58 | + |
| 59 | + @testset "Edge Cases" begin |
| 60 | + # Test the 1001//1000 padding logic |
| 61 | + buffer = TrixiParticles.SystemBuffer(3, 0) |
| 62 | + system = MockSystemOutOfBounds(buffer) |
| 63 | + |
| 64 | + # Particles directly at the boundaries (should remain active) |
| 65 | + u = [-1.0 1.0 0.0 |
| 66 | + -1.0 1.0 0.0] |
| 67 | + |
| 68 | + cell_list = TrixiParticles.FullGridCellList(; min_corner=(-1.0, -1.0), |
| 69 | + max_corner=(1.0, 1.0), |
| 70 | + search_radius=0.1) |
| 71 | + dummy_nhs = (; cell_size=0.1, periodic_box=nothing, cell_list) |
| 72 | + semi = DummySemidiscretization() |
| 73 | + |
| 74 | + TrixiParticles.deactivate_out_of_bounds_particles!(system, buffer, dummy_nhs, |
| 75 | + cell_list, u, u, semi) |
| 76 | + |
| 77 | + # All should still be active |
| 78 | + @test all(buffer.active_particle) |
| 79 | + end |
| 80 | +end |
0 commit comments