@@ -3311,27 +3311,26 @@ def _force_migration_after_mesh_change(self):
33113311
33123312 @timing .routine_timer_decorator
33133313 def add_particles_with_coordinates (self , coordinatesArray ) -> int :
3314- """
3315- Add particles to the swarm using particle coordinates provided
3316- using a numpy array.
3314+ """Add particles at given coordinates, keeping only locally-owned points.
33173315
3318- Note that particles with coordinates NOT local to the current processor will
3319- be rejected / ignored.
3316+ Each rank filters the input array and adds only the points that fall
3317+ within its local domain partition. Non-local points are silently
3318+ ignored, so it is safe to pass the same global coordinate array to
3319+ every rank — no duplicates will be created.
33203320
3321- Either include an array with all coordinates to all processors
3322- or an array with the local coordinates.
3321+ This is the recommended method for user code. For pre-partitioned
3322+ data where each rank already holds only its own points, this method
3323+ also works correctly.
33233324
33243325 Parameters
33253326 ----------
33263327 coordinatesArray : numpy.ndarray
3327- The numpy array containing the coordinate of the new particles. Array is
3328- expected to take shape n*dim, where n is the number of new particles, and
3329- dim is the dimensionality of the swarm's supporting mesh.
3328+ Coordinates of new particles, shape ``(n, dim)``.
33303329
33313330 Returns
33323331 --------
3333- npoints: int
3334- The number of points added to the local section of the swarm .
3332+ npoints : int
3333+ Number of points actually added on this rank .
33353334 """
33363335
33373336 if not isinstance (coordinatesArray , np .ndarray ):
@@ -3391,23 +3390,33 @@ def add_particles_with_global_coordinates(
33913390 migrate = True ,
33923391 delete_lost_points = True ,
33933392 ) -> int :
3394- """
3395- Add particles to the swarm using particle coordinates provided
3396- using a numpy array.
3393+ """Add particles on every rank, then migrate to correct owners.
3394+
3395+ Every rank inserts **all** supplied points into the local swarm, then
3396+ ``dm.migrate()`` moves each particle to the rank that owns its
3397+ spatial location. If the same array is passed on every rank, this
3398+ produces one copy of each point in the correct partition — but calling
3399+ it with *different* arrays per rank will accumulate all of them.
33973400
3398- global coordinates: particles will be appropriately migrated
3401+ This is primarily an internal method used by global-evaluation and
3402+ mesh-transfer utilities. For general use, prefer
3403+ :meth:`add_particles_with_coordinates`, which filters non-local
3404+ points automatically and never creates duplicates.
33993405
34003406 Parameters
34013407 ----------
34023408 globalCoordinatesArray : numpy.ndarray
3403- The numpy array containing the coordinate of the new particles. Array is
3404- expected to take shape n*dim, where n is the number of new particles, and
3405- dim is the dimensionality of the swarm's supporting mesh.
3409+ Coordinates of new particles, shape ``(n, dim)``.
3410+ migrate : bool
3411+ Run PETSc swarm migration after insertion (default True).
3412+ delete_lost_points : bool
3413+ Remove particles that fall outside any rank's domain
3414+ during migration (default True).
34063415
34073416 Returns
34083417 --------
3409- npoints: int
3410- The number of points added to the local section of the swarm .
3418+ npoints : int
3419+ Number of points added on this rank before migration .
34113420 """
34123421
34133422 if not isinstance (globalCoordinatesArray , np .ndarray ):
0 commit comments