Header file for particle location functions using the walking search algorithm. More...
#include <petsc.h>#include <stdbool.h>#include <math.h>#include "variables.h"#include "logging.h"#include "setup.h"Go to the source code of this file.
Functions | |
| PetscErrorCode | GetCellCharacteristicSize (const Cell *cell, PetscReal *cellSize) |
| Estimates a characteristic length of the cell for threshold scaling. | |
| PetscErrorCode | CalculateDistancesToCellFaces (const Cmpnts p, const Cell *cell, PetscReal *d, const PetscReal threshold, Cmpnts *normals) |
| Computes the signed distances from a point to each face of a cubic cell. | |
| PetscErrorCode | CalculateDistancesToCellFacePlanes (const Cmpnts p, const CellFacePlanes *planes, PetscReal *d, const PetscReal threshold, Cmpnts *normals) |
| Signed distances from a point to precomputed cell face planes. | |
| PetscErrorCode | DeterminePointPosition (PetscReal *d, PetscInt *result) |
| Classifies a point based on precomputed face distances. | |
| PetscErrorCode | InitializeTraversalParameters (UserCtx *user, Particle *particle, PetscInt *idx, PetscInt *idy, PetscInt *idz, PetscInt *traversal_steps) |
| Initializes traversal parameters for locating a particle. | |
| PetscErrorCode | CheckCellWithinLocalGrid (UserCtx *user, PetscInt idx, PetscInt idy, PetscInt idz, PetscBool *is_within) |
| Checks if the current cell indices are within the local grid boundaries. | |
| PetscErrorCode | RetrieveCurrentCell (UserCtx *user, PetscInt idx, PetscInt idy, PetscInt idz, Cell *cell) |
| Retrieves the coordinates of the eight vertices of the current cell. | |
| PetscErrorCode | EvaluateParticlePositionInPlanes (const CellFacePlanes *planes, PetscReal *d, const Cmpnts p, PetscInt *position, const PetscReal threshold) |
| Classifies a point against a cell's precomputed face planes. | |
| PetscErrorCode | FindOwnerOfCell (UserCtx *user, PetscInt i, PetscInt j, PetscInt k, PetscMPIInt *owner_rank) |
| Finds the MPI rank that owns a given global cell index. | |
| PetscErrorCode | ReflectParticleAcrossCellFace (const CellFacePlanes *planes, PetscInt face, Cmpnts *p) |
| Mirrors a point about the plane of one face of a cell. | |
| PetscErrorCode | PlaceParticleInsideCell (const Cell *cell, Cmpnts *p, PetscBool *placed) |
| Moves a point to just inside a cell along the segment toward the cell centroid. | |
| PetscErrorCode | LocateParticleOrFindMigrationTarget (UserCtx *user, const struct FacePlaneArrays *planes, Particle *particle, ParticleLocationStatus *status_out) |
| PetscErrorCode | UpdateCellIndicesBasedOnDistances (PetscReal d[NUM_FACES], PetscInt *idx, PetscInt *idy, PetscInt *idz) |
| Updates the cell indices based on the signed distances to each face. | |
Header file for particle location functions using the walking search algorithm.
This file contains declarations of functions that implement the walking search algorithm to locate particles within a computational grid. It includes functions for computing distances to cell faces, determining particle positions relative to cells, and updating traversal parameters.
Definition in file walkingsearch.h.
| PetscErrorCode GetCellCharacteristicSize | ( | const Cell * | cell, |
| PetscReal * | cellSize | ||
| ) |
Estimates a characteristic length of the cell for threshold scaling.
For a hexahedral cell with vertices cell->vertices[0..7], we approximate the cell size by some measure—e.g. average edge length or diagonal.
| [in] | cell | A pointer to the Cell structure |
| [out] | cellSize | A pointer to a PetscReal where the characteristic size is stored. |
Estimates a characteristic length of the cell for threshold scaling.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/walkingsearch.h.
Definition at line 30 of file walkingsearch.c.
| PetscErrorCode CalculateDistancesToCellFaces | ( | const Cmpnts | p, |
| const Cell * | cell, | ||
| PetscReal * | d, | ||
| const PetscReal | threshold, | ||
| Cmpnts * | normals | ||
| ) |
Computes the signed distances from a point to each face of a cubic cell.
This function calculates the signed distances from a specified point p to each of the six faces of a cubic cell. The cell is defined by its eight vertices, and the distances are stored in the memory location pointed to by d.
| [in] | p | The target point in 3D space. |
| [in] | cell | Pointer to a Cell structure that defines the cubic cell via its vertices. |
| [out] | d | A pointer to an array of six PetscReal values where the computed signed distances will be stored. |
| [in] | threshold | A PetscReal value that specifies the minimum distance below which a computed distance is considered to be zero. |
| [out] | normals | Optional, may be NULL: an array of six Cmpnts receiving each face plane's unit outward normal, in the same order as d. |
Computes the signed distances from a point to each face of a cubic cell.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/walkingsearch.h.
Definition at line 113 of file walkingsearch.c.
| PetscErrorCode CalculateDistancesToCellFacePlanes | ( | const Cmpnts | p, |
| const CellFacePlanes * | planes, | ||
| PetscReal * | d, | ||
| const PetscReal | threshold, | ||
| Cmpnts * | normals | ||
| ) |
Signed distances from a point to precomputed cell face planes.
| [in] | p | The target point. |
| [in] | planes | Face planes from MetricBuildCellFacePlanes(). |
| [out] | d | Six signed distances, positive inside, indexed by Face; below threshold set to 0. |
| [in] | threshold | Absolute distance below which a distance is zero. |
| [out] | normals | Optional, may be NULL: each face's unit outward normal, in the order of d. |
Signed distances from a point to precomputed cell face planes.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/walkingsearch.h.
Definition at line 88 of file walkingsearch.c.
| PetscErrorCode DeterminePointPosition | ( | PetscReal * | d, |
| PetscInt * | result | ||
| ) |
Classifies a point based on precomputed face distances.
Given an array of six distances d[NUM_FACES] from the point to each face of a hexahedral cell, this function determines: 0 => inside 1 => on a single face 2 => on an edge (2 faces = 0) 3 => on a corner (3+ faces = 0) -1 => outside
| [in] | d | Array of six face distances. |
| [out] | result | Pointer to an integer classification: {0,1,2,3,-1}. |
Classifies a point based on precomputed face distances.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/walkingsearch.h.
Definition at line 154 of file walkingsearch.c.
| PetscErrorCode InitializeTraversalParameters | ( | UserCtx * | user, |
| Particle * | particle, | ||
| PetscInt * | idx, | ||
| PetscInt * | idy, | ||
| PetscInt * | idz, | ||
| PetscInt * | traversal_steps | ||
| ) |
Initializes traversal parameters for locating a particle.
This function sets the initial cell indices based on the local grid boundaries and initializes the traversal step counter.
| [in] | user | Pointer to the user-defined context containing grid information. |
| [in] | particle | Pointer to the Particle structure containing its location. |
| [out] | idx | Pointer to store the initial i-index of the cell. |
| [out] | idy | Pointer to store the initial j-index of the cell. |
| [out] | idz | Pointer to store the initial k-index of the cell. |
| [out] | traversal_steps | Pointer to store the initial traversal step count. |
Initializes traversal parameters for locating a particle.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/walkingsearch.h.
Definition at line 214 of file walkingsearch.c.
| PetscErrorCode CheckCellWithinLocalGrid | ( | UserCtx * | user, |
| PetscInt | idx, | ||
| PetscInt | idy, | ||
| PetscInt | idz, | ||
| PetscBool * | is_within | ||
| ) |
Checks if the current cell indices are within the local grid boundaries.
| [in] | user | Pointer to the user-defined context containing grid information. |
| [in] | idx | The i-index of the current cell. |
| [in] | idy | The j-index of the current cell. |
| [in] | idz | The k-index of the current cell. |
| [out] | is_within | Pointer to a PetscBool that will be set to PETSC_TRUE if within bounds, else PETSC_FALSE. |
Checks if the current cell indices are within the local grid boundaries.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/walkingsearch.h.
Definition at line 346 of file walkingsearch.c.
| PetscErrorCode RetrieveCurrentCell | ( | UserCtx * | user, |
| PetscInt | idx, | ||
| PetscInt | idy, | ||
| PetscInt | idz, | ||
| Cell * | cell | ||
| ) |
Retrieves the coordinates of the eight vertices of the current cell.
Vertices 0 to 7 are the nodes (i,j,k), (i+1,j,k), (i+1,j+1,k), (i,j+1,k), (i,j+1,k+1), (i+1,j+1,k+1), (i+1,j,k+1) and (i,j,k+1) of cell (i,j,k) = (idx,idy,idz), the order MetricBuildCellFacePlanes() reads.
| [in] | user | Pointer to the user-defined context containing grid information. |
| [in] | idx | The i-index of the current cell. |
| [in] | idy | The j-index of the current cell. |
| [in] | idz | The k-index of the current cell. |
| [out] | cell | Pointer to a Cell structure to store the cell's vertices. |
Retrieves the coordinates of the eight vertices of the current cell.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/walkingsearch.h.
Definition at line 404 of file walkingsearch.c.
| PetscErrorCode EvaluateParticlePositionInPlanes | ( | const CellFacePlanes * | planes, |
| PetscReal * | d, | ||
| const Cmpnts | p, | ||
| PetscInt * | position, | ||
| const PetscReal | threshold | ||
| ) |
Classifies a point against a cell's precomputed face planes.
Computes the signed distances to the six face planes, zeroing those below threshold * planes->size, then classifies them with DeterminePointPosition().
| [in] | planes | Face planes with size set, e.g. from MetricGatherCellFacePlanes(). |
| [out] | d | Six signed face distances, thresholded at threshold * planes->size. |
| [in] | p | The particle position. |
| [out] | position | 0 inside, 1 to 3 on a face, edge or corner, -1 outside. |
| [in] | threshold | Base threshold, scaled by the cell size. |
Classifies a point against a cell's precomputed face planes.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/walkingsearch.h.
Definition at line 453 of file walkingsearch.c.
| PetscErrorCode FindOwnerOfCell | ( | UserCtx * | user, |
| PetscInt | i, | ||
| PetscInt | j, | ||
| PetscInt | k, | ||
| PetscMPIInt * | owner_rank | ||
| ) |
Finds the MPI rank that owns a given global cell index.
The DMDA decomposition is a tensor product of per-axis ranges, with rank i + m (j + n k) on process grid m x n x p, so the owner is found by a binary search of the range starts along each axis in the pre-computed decomposition map (user->RankCellInfoMap): O(log m + log n + log p), not O(ranks). It is the definitive method for resolving cell ownership in the "Walk and Handoff" migration algorithm.
If the provided indices are outside the range of any rank (e.g., negative or beyond the global domain), the function will not find an owner and owner_rank will be set to -1.
| [in] | user | Pointer to the UserCtx structure, which must contain the initialized RankCellInfoMap and num_ranks. |
| [in] | i | Global i-index of the cell to find. |
| [in] | j | Global j-index of the cell to find. |
| [in] | k | Global k-index of the cell to find. |
| [out] | owner_rank | Pointer to a PetscMPIInt where the resulting owner rank will be stored. It is set to -1 if no owner is found. |
Finds the MPI rank that owns a given global cell index.
Definition at line 538 of file walkingsearch.c.
| PetscErrorCode ReflectParticleAcrossCellFace | ( | const CellFacePlanes * | planes, |
| PetscInt | face, | ||
| Cmpnts * | p | ||
| ) |
Mirrors a point about the plane of one face of a cell.
The plane is the one the walking search tested the point against, so a point outside the face by |d| ends inside it by |d|: p' = p + 2 d n, with d < 0 outside. Only the position changes.
| [in] | planes | The cell's face planes (MetricGatherCellFacePlanes() or MetricBuildCellFacePlanes()). |
| [in] | face | The face index (LEFT, RIGHT, BOTTOM, TOP, FRONT or BACK). |
| [in,out] | p | The point to mirror. |
Mirrors a point about the plane of one face of a cell.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/walkingsearch.h.
Definition at line 589 of file walkingsearch.c.
Moves a point to just inside a cell along the segment toward the cell centroid.
The terminal action when reflections reach their cap. Plane distances are linear along the segment, so the entry parameter is the largest d_p / (d_p - d_c) over the faces the point is outside of; the point is placed a relative 1e-6 of the remaining segment beyond it.
| [in] | cell | The cell to place the point in. |
| [in,out] | p | The point; unchanged when it cannot be placed. |
| [out] | placed | PETSC_FALSE when the centroid is not inside every face plane the point is outside of (a cell warped that far), in which case p is unchanged. |
Moves a point to just inside a cell along the segment toward the cell centroid.
Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/walkingsearch.h.
Definition at line 617 of file walkingsearch.c.
| PetscErrorCode LocateParticleOrFindMigrationTarget | ( | UserCtx * | user, |
| const struct FacePlaneArrays * | planes, | ||
| Particle * | particle, | ||
| ParticleLocationStatus * | status_out | ||
| ) |
| PetscErrorCode UpdateCellIndicesBasedOnDistances | ( | PetscReal | d[NUM_FACES], |
| PetscInt * | idx, | ||
| PetscInt * | idy, | ||
| PetscInt * | idz | ||
| ) |
Updates the cell indices based on the signed distances to each face.
This function modifies the cell indices (idx, idy, idz) to move towards the direction where the particle is likely to be located, based on positive distances indicating that the particle is outside in that particular direction.
| [in] | d | An array of six PetscReal values representing the signed distances to each face:
|
| [out] | idx | Pointer to the i-index of the cell to be updated. |
| [out] | idy | Pointer to the j-index of the cell to be updated. |
| [out] | idz | Pointer to the k-index of the cell to be updated. |
Updates the cell indices based on the signed distances to each face.
Definition at line 472 of file walkingsearch.c.