Skip to content

[BUG] - swarm particles being lost across processors resulting in 'gaps' #175

Closed

Description

@bknight1

I am running a model with swarm particles but large gaps are appearing within the domain, which correlates to processor boundaries. I haven't got a basic script to replicate but can make one if required.

Activity

  1. bknight1 commented on May 7, 2026

    @bknight1
    MemberAuthor

    I should add this is when the particles are being advected around the domain

  2. bknight1 commented on May 8, 2026

    @bknight1
    MemberAuthor

    Reproduction script for np > 2:

    import underworld3 as uw
    import numpy as np
    from mpi4py import MPI
    
    mesh = uw.meshing.UnstructuredSimplexBox(
        minCoords=(0.0, 0.0),
        maxCoords=(1.0, 1.0),
        cellSize=0.1,
    )
    
    swarm = uw.swarm.Swarm(mesh)
    
    # Initialize a variable to track particles
    var = uw.swarm.SwarmVariable("test_var", swarm, 1)
    
    swarm.populate(fill_param=1)
    var.data[...] = uw.mpi.rank
    
    # Initial count
    comm = uw.mpi.comm
    initial_count = comm.allreduce(swarm.dm.getLocalSize(), op=MPI.SUM)
    if uw.mpi.rank == 0:
        print(f"Initial total particles: {initial_count}")
    
    # Define a constant velocity field to move particles from left to right
    # V = (1.0, 0.0)
    import sympy
    v_fn = sympy.Matrix([1.0, 0.0])
    
    # Advect for a bit
    dt = 0.6 # move 0.4 units, should cross x=0.5 if they start at x < 0.5
    swarm.advection(v_fn, dt, order=1)
    
    # Final count
    final_count = comm.allreduce(swarm.dm.getLocalSize(), op=MPI.SUM)
    if uw.mpi.rank == 0:
        print(f"Final total particles: {final_count}")
    
    if uw.mpi.rank == 0:
        if final_count < initial_count:
            print(f"FAILED: Lost {initial_count - final_count} particles!")
        else:
            print("PASSED: No particles lost.")
    

    Looks like the advection function is forced to use max_steps=1, causing issues. Seems a simple fix but will investigate further before finalising

  3. lmoresi commented on May 9, 2026

    @lmoresi
    Member
  4. lmoresi commented on May 10, 2026

    @lmoresi
    Member

    @bknight1 — your diagnosis was on the right track. The regression came from a max_its=1 argument on the end-of-advection self.migrate(...) call (introduced in bd209c4, looks like leftover debugging). With max_its=1 only the closest domain centroid is tried for each unclaimed particle, so anything whose owner is the 2nd-or-3rd closest rank — typical near processor cuts — failed points_in_domain and got dropped.

    PR #177 drops the override so the default max_its=10 retry is used. Your reproducer now reports zero loss on np=4. Could you give it a run at higher proc counts on the HPC when you get a chance?

  5. added a commit that references this issue on May 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions