@@ -112,13 +112,6 @@ class SwarmVariable(DimensionalityMixin, MathematicalMixin, Stateful, uw_object)
112112 Physical units for this variable (e.g., 'kelvin', 'Pa').
113113 Requires reference quantities to be set on the model.
114114
115- Attributes
116- ----------
117- data : numpy.ndarray
118- Direct access to variable values at particle locations.
119- sym : sympy.Matrix
120- Symbolic representation for use in expressions.
121-
122115 See Also
123116 --------
124117 MeshVariable : Variable supported by mesh nodes.
@@ -1975,11 +1968,6 @@ class IndexSwarmVariable(SwarmVariable):
19751968 proxy_continuous : bool
19761969 Whether mesh proxy is continuous (default True).
19771970
1978- Attributes
1979- ----------
1980- sym : list of sympy.Expr
1981- Symbolic mask expressions for each material index.
1982-
19831971 Examples
19841972 --------
19851973 >>> material = IndexSwarmVariable("M", swarm, indices=3)
@@ -2375,44 +2363,6 @@ class Swarm(Stateful, uw_object):
23752363 Enable verbose output for debugging and monitoring particle operations.
23762364 Default is False.
23772365
2378- Attributes
2379- ----------
2380- mesh : uw.discretisation.Mesh
2381- Reference to the associated mesh object.
2382- dim : int
2383- Spatial dimension of the mesh (2D or 3D).
2384- cdim : int
2385- Coordinate dimension of the mesh.
2386- data : numpy.ndarray
2387- Direct access to particle coordinate data.
2388- particle_coordinates : SwarmVariable
2389- SwarmVariable containing particle coordinate information.
2390- recycle_rate : int
2391- Current recycle rate for streak management.
2392- cycle : int
2393- Current cycle number for streak particles.
2394-
2395- Methods
2396- -------
2397- populate(fill_param=1)
2398- Populate the swarm with particles throughout the domain.
2399- migrate(remove_sent_points=True, delete_lost_points=True, max_its=10)
2400- Manually migrate particles across MPI processes after coordinate updates.
2401- add_particles_with_coordinates(coords)
2402- Add new particles at specified coordinate locations.
2403- add_particles_with_global_coordinates(coords)
2404- Add particles using global coordinate system.
2405- add_variable(name, size, dtype=float)
2406- Add a new variable to track additional particle properties.
2407- save(filename, meshUnits=1.0, swarmUnits=1.0, units="dimensionless")
2408- Save swarm data to file.
2409- read_timestep(filename, step_name, outputPath="./output/")
2410- Read swarm data from a specific timestep file.
2411- advection(V_fn, delta_t, evalf=False, corrector=True, restore_points_func=None)
2412- Advect particles using a velocity field.
2413- estimate_dt(V_fn, dt_min=1.0e-15, dt_max=1.0)
2414- Estimate appropriate timestep for particle advection.
2415-
24162366 Examples
24172367 --------
24182368 Create a basic swarm and populate with particles:
@@ -3360,27 +3310,26 @@ def _force_migration_after_mesh_change(self):
33603310
33613311 @timing .routine_timer_decorator
33623312 def add_particles_with_coordinates (self , coordinatesArray ) -> int :
3363- """
3364- Add particles to the swarm using particle coordinates provided
3365- using a numpy array.
3313+ """Add particles at given coordinates, keeping only locally-owned points.
33663314
3367- Note that particles with coordinates NOT local to the current processor will
3368- be rejected / ignored.
3315+ Each rank filters the input array and adds only the points that fall
3316+ within its local domain partition. Non-local points are silently
3317+ ignored, so it is safe to pass the same global coordinate array to
3318+ every rank — no duplicates will be created.
33693319
3370- Either include an array with all coordinates to all processors
3371- or an array with the local coordinates.
3320+ This is the recommended method for user code. For pre-partitioned
3321+ data where each rank already holds only its own points, this method
3322+ also works correctly.
33723323
33733324 Parameters
33743325 ----------
33753326 coordinatesArray : numpy.ndarray
3376- The numpy array containing the coordinate of the new particles. Array is
3377- expected to take shape n*dim, where n is the number of new particles, and
3378- dim is the dimensionality of the swarm's supporting mesh.
3327+ Coordinates of new particles, shape ``(n, dim)``.
33793328
33803329 Returns
33813330 --------
3382- npoints: int
3383- The number of points added to the local section of the swarm .
3331+ npoints : int
3332+ Number of points actually added on this rank .
33843333 """
33853334
33863335 if not isinstance (coordinatesArray , np .ndarray ):
@@ -3440,23 +3389,33 @@ def add_particles_with_global_coordinates(
34403389 migrate = True ,
34413390 delete_lost_points = True ,
34423391 ) -> int :
3443- """
3444- Add particles to the swarm using particle coordinates provided
3445- using a numpy array.
3392+ """Add particles on every rank, then migrate to correct owners.
3393+
3394+ Every rank inserts **all** supplied points into the local swarm, then
3395+ ``dm.migrate()`` moves each particle to the rank that owns its
3396+ spatial location. If the same array is passed on every rank, this
3397+ produces one copy of each point in the correct partition — but calling
3398+ it with *different* arrays per rank will accumulate all of them.
34463399
3447- global coordinates: particles will be appropriately migrated
3400+ This is primarily an internal method used by global-evaluation and
3401+ mesh-transfer utilities. For general use, prefer
3402+ :meth:`add_particles_with_coordinates`, which filters non-local
3403+ points automatically and never creates duplicates.
34483404
34493405 Parameters
34503406 ----------
34513407 globalCoordinatesArray : numpy.ndarray
3452- The numpy array containing the coordinate of the new particles. Array is
3453- expected to take shape n*dim, where n is the number of new particles, and
3454- dim is the dimensionality of the swarm's supporting mesh.
3408+ Coordinates of new particles, shape ``(n, dim)``.
3409+ migrate : bool
3410+ Run PETSc swarm migration after insertion (default True).
3411+ delete_lost_points : bool
3412+ Remove particles that fall outside any rank's domain
3413+ during migration (default True).
34553414
34563415 Returns
34573416 --------
3458- npoints: int
3459- The number of points added to the local section of the swarm .
3417+ npoints : int
3418+ Number of points added on this rank before migration .
34603419 """
34613420
34623421 if not isinstance (globalCoordinatesArray , np .ndarray ):
0 commit comments