:orphan: # DMSwarmSortGetAccess Setups up a `DMSWARM` point sort context for efficient traversal of points within a cell ## Synopsis ``` PETSC_EXTERN PetscErrorCode DMSwarmSortGetAccess(DM dm) ``` Not Collective ## Input parameter - ***dm -*** a `DMSWARM` object ## Notes Calling `DMSwarmSortGetAccess()` creates a list which enables easy identification of all points contained in a given cell. This method does not explicitly sort the data within the `DMSWARM` based on the cell index associated with a `DMSWARM` point. The sort context is valid only for the `DMSWARM` points defined at the time when `DMSwarmSortGetAccess()` was called. For example, suppose the swarm contained NP points when `DMSwarmSortGetAccess()` was called. If the user subsequently adds 10 additional points to the swarm, the sort context is still valid, but only for the first NP points. The indices associated with the 10 new additional points will not be contained within the sort context. This means that the user can still safely perform queries via `DMSwarmSortGetPointsPerCell()` and `DMSwarmSortGetPointsPerCell()`, however the results return will be based on the first NP points. If any` DMSWARM` re-sizing method is called after `DMSwarmSortGetAccess()` which modifies any of the first NP entries in the `DMSWARM`, the sort context will become invalid. Currently there are no guards to prevent the user from invalidating the sort context. For this reason, we highly recommend you do not use `DMSwarmRemovePointAtIndex()` in between calls to `DMSwarmSortGetAccess()` and `DMSwarmSortRestoreAccess()`. To facilitate safe removal of points using the sort context, we suggest a "two pass" strategy in which the first pass "marks" points for removal, and the second pass actually removes the points from the `DMSWARM` You must call `DMSwarmSortGetAccess()` before you can call `DMSwarmSortGetPointsPerCell()` or `DMSwarmSortGetNumberOfPointsPerCell()` The sort context may become invalid if any re-sizing methods are applied which alter the first NP points within swarm at the time `DMSwarmSortGetAccess()` was called. You must call `DMSwarmSortRestoreAccess()` when you no longer need access to the sort context ## See Also `DMSWARM`, `DMSwarmSetType()`, `DMSwarmSortRestoreAccess()` ## Level advanced ## Location src/dm/impls/swarm/swarmpic_sort.c ## Examples src/dm/tutorials/ex20.c
src/ksp/ksp/tutorials/ex70.c
--- [Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/dm/impls/swarm/swarmpic_sort.c) [Index of all DMSwarm routines](index.md) [Table of Contents for all manual pages](/manualpages/index.md) [Index of all manual pages](/manualpages/singleindex.md)