10#define MAX_TRAVERSAL 1000
11#define DISTANCE_THRESHOLD 1e-11
12#define REPEAT_COUNT_THRESHOLD 5
27 PetscErrorCode ierr = 0;
28 if (!cell || !cellSize) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
29 "GetCellCharacteristicSize: Null pointer(s).");
36 PetscInt edges[12][2] = {
37 {0,1},{1,2},{2,3},{3,0},
38 {4,5},{5,6},{6,7},{7,4},
39 {0,7},{1,6},{2,5},{3,4}
42 PetscReal totalEdgeLen = 0.0;
43 for (PetscInt i=0; i<12; i++) {
44 PetscInt vA = edges[i][0];
45 PetscInt vB = edges[i][1];
48 PetscReal dx = B.
x - A.
x;
49 PetscReal dy = B.
y - A.
y;
50 PetscReal dz = B.
z - A.
z;
51 PetscReal edgeLen = sqrt(dx*dx + dy*dy + dz*dz);
52 totalEdgeLen += edgeLen;
56 *cellSize = totalEdgeLen / 12.0;
104 PetscReal *d_signed,
const PetscReal threshold)
106 PetscErrorCode ierr = 0;
109 PetscFunctionBeginUser;
111 if (d_signed == NULL) {
112 ierr = MPI_Comm_rank(MPI_COMM_WORLD, &rank); CHKERRQ(ierr);
113 LOG_ALLOW(
LOCAL,
LOG_ERROR,
"ComputeSignedDistanceToPlane - Output pointer 'd_signed' is NULL on rank %d.\n", rank);
114 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"Output pointer 'd_signed' must not be NULL.");
117 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
"ComputeSignedDistanceToPlane - Target point: (%.6e, %.6e, %.6e)\n", p_target.
x, p_target.
y, p_target.
z);
126 PetscReal edge1_x = v2.
x - v1.
x;
127 PetscReal edge1_y = v2.
y - v1.
y;
128 PetscReal edge1_z = v2.
z - v1.
z;
130 PetscReal edge2_x = v4.
x - v1.
x;
131 PetscReal edge2_y = v4.
y - v1.
y;
132 PetscReal edge2_z = v4.
z - v1.
z;
137 PetscReal normal_x_initial = edge1_y * edge2_z - edge1_z * edge2_y;
138 PetscReal normal_y_initial = edge1_z * edge2_x - edge1_x * edge2_z;
139 PetscReal normal_z_initial = edge1_x * edge2_y - edge1_y * edge2_x;
140 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
" Initial Raw Normal (edge1 x edge2): (%.6e, %.6e, %.6e)\n", normal_x_initial, normal_y_initial, normal_z_initial);
142 PetscReal normal_magnitude = sqrt(normal_x_initial * normal_x_initial +
143 normal_y_initial * normal_y_initial +
144 normal_z_initial * normal_z_initial);
147 if (normal_magnitude < 1.0e-12) {
148 ierr = MPI_Comm_rank(MPI_COMM_WORLD, &rank); CHKERRQ(ierr);
150 "ComputeSignedDistanceToPlane - Degenerate plane detected on rank %d. Normal magnitude (%.3e) is too small.\n",
151 rank, normal_magnitude);
152 LOG_ALLOW(
LOCAL,
LOG_ERROR,
" Offending vertices for normal: v1(%.3e,%.3e,%.3e), v2(%.3e,%.3e,%.3e), v4(%.3e,%.3e,%.3e)\n",
153 v1.
x,v1.
y,v1.
z, v2.
x,v2.
y,v2.
z, v4.
x,v4.
y,v4.
z);
154 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_USER,
"Degenerate plane detected (normal vector is near zero).");
158 PetscReal face_centroid_x = 0.25 * (v1.
x + v2.
x + v3.
x + v4.
x);
159 PetscReal face_centroid_y = 0.25 * (v1.
y + v2.
y + v3.
y + v4.
y);
160 PetscReal face_centroid_z = 0.25 * (v1.
z + v2.
z + v3.
z + v4.
z);
161 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
" Face Centroid: (%.6e, %.6e, %.6e)\n", face_centroid_x, face_centroid_y, face_centroid_z);
165 PetscReal vec_fc_to_cc_x = cell_centroid.
x - face_centroid_x;
166 PetscReal vec_fc_to_cc_y = cell_centroid.
y - face_centroid_y;
167 PetscReal vec_fc_to_cc_z = cell_centroid.
z - face_centroid_z;
168 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
" Vec (FaceCentroid -> CellCentroid): (%.6e, %.6e, %.6e)\n", vec_fc_to_cc_x, vec_fc_to_cc_y, vec_fc_to_cc_z);
171 PetscReal dot_prod_orientation = normal_x_initial * vec_fc_to_cc_x +
172 normal_y_initial * vec_fc_to_cc_y +
173 normal_z_initial * vec_fc_to_cc_z;
174 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
" Dot Product for Orientation (N_initial . Vec_FC_to_CC): %.6e\n", dot_prod_orientation);
176 PetscReal normal_x = normal_x_initial;
177 PetscReal normal_y = normal_y_initial;
178 PetscReal normal_z = normal_z_initial;
181 if (dot_prod_orientation > 1.0e-9) {
182 normal_x = -normal_x_initial;
183 normal_y = -normal_y_initial;
184 normal_z = -normal_z_initial;
186 }
else if (dot_prod_orientation == 0.0 && normal_magnitude > 1e-12) {
191 ierr = MPI_Comm_rank(MPI_COMM_WORLD, &rank); CHKERRQ(ierr);
192 LOG_ALLOW(
LOCAL,
LOG_WARNING,
"ComputeSignedDistanceToPlane - Rank %d: Dot product for normal orientation is zero. Normal direction might be ambiguous. Keeping initial normal direction from (v2-v1)x(v4-v1).\n", rank);
200 normal_x /= normal_magnitude;
201 normal_y /= normal_magnitude;
202 normal_z /= normal_magnitude;
207 PetscReal vec_p_to_fc_x = face_centroid_x - p_target.
x;
208 PetscReal vec_p_to_fc_y = face_centroid_y - p_target.
y;
209 PetscReal vec_p_to_fc_z = face_centroid_z - p_target.
z;
212 *d_signed = vec_p_to_fc_x * normal_x +
213 vec_p_to_fc_y * normal_y +
214 vec_p_to_fc_z * normal_z;
219 if (fabs(*d_signed) < threshold) {
220 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
" Distance %.15e is less than threshold %.1e. Setting to 0.0.\n", *d_signed, threshold);
226 PetscFunctionReturn(0);
277 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"CalculateDistancesToCellFaces - 'cell' is NULL.");
283 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"CalculateDistancesToCellFaces - 'd' is NULL.");
287 Cmpnts cell_centroid = {0.0, 0.0, 0.0};
288 for (
int i = 0; i < 8; ++i) {
293 cell_centroid.
x /= 8.0;
294 cell_centroid.
y /= 8.0;
295 cell_centroid.
z /= 8.0;
298 cell_centroid.
x, cell_centroid.
y, cell_centroid.
z);
380 "d[LEFT=%d]=%.3e, d[RIGHT=%d]=%.3e, d[BOTTOM=%d]=%.3e, "
381 "d[TOP=%d]=%.3e, d[FRONT=%d]=%.3e, d[BACK=%d]=%.3e\n",
385 "[%.3e, %.3e, %.3e, %.3e, %.3e, %.3e]\n",
386 d[0], d[1], d[2], d[3], d[4], d[5]);
414 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"DeterminePointPosition - Input parameter 'd' is NULL.");
416 if (result == NULL) {
418 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"DeterminePointPosition - Output parameter 'result' is NULL.");
422 PetscBool isInside = PETSC_TRUE;
423 PetscBool isOnBoundary = PETSC_FALSE;
424 PetscInt IntersectionCount = 0;
429 isInside = PETSC_FALSE;
432 isOnBoundary = PETSC_TRUE;
442 else if(isOnBoundary) {
443 if(IntersectionCount == 1){
447 else if(IntersectionCount == 2){
451 else if(IntersectionCount >= 3){
528 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"GetCellVerticesFromGrid - Input array 'coor' is NULL.");
532 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"GetCellVerticesFromGrid - Output parameter 'cell' is NULL.");
537 cell->
vertices[0] = coor[idz][idy][idx];
538 cell->
vertices[1] = coor[idz][idy][idx+1];
539 cell->
vertices[2] = coor[idz][idy+1][idx+1];
540 cell->
vertices[3] = coor[idz][idy+1][idx];
541 cell->
vertices[4] = coor[idz+1][idy+1][idx];
542 cell->
vertices[5] = coor[idz+1][idy+1][idx+1];
543 cell->
vertices[6] = coor[idz+1][idy][idx+1];
544 cell->
vertices[7] = coor[idz+1][idy][idx];
546 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
"GetCellVerticesFromGrid - Retrieved vertices for cell (%d, %d, %d).\n", idx, idy, idz);
577 if (user == NULL || particle == NULL || idx == NULL || idy == NULL || idz == NULL || traversal_steps == NULL) {
579 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"InitializeTraversalParameters - One or more input pointers are NULL.");
583 ierr = DMDAGetLocalInfo(user->
da, &info); CHKERRQ(ierr);
587 if (particle->
cell[0] >= 0 && particle->
cell[1] >= 0 && particle->
cell[2] >= 0) {
591 PetscBool is_handoff_cell_valid;
594 if (is_handoff_cell_valid) {
596 *idx = particle->
cell[0];
597 *idy = particle->
cell[1];
598 *idz = particle->
cell[2];
600 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
"InitializeTraversalParameters - Particle %lld has previous cell (%d, %d, %d). Starting search there.\n",
601 (
long long)particle->
PID, *idx, *idy, *idz);
617 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
"InitializeTraversalParameters - Particle %lld has no valid previous cell. Starting search at local corner (%d, %d, %d).\n",
618 (
long long)particle->
PID, *idx, *idy, *idz);
622 *traversal_steps = 0;
625 LOG_ALLOW(
LOCAL,
LOG_INFO,
"InitializeTraversalParameters - Traversal for particle %lld initialized to start at cell (%d, %d, %d).\n",
626 (
long long)particle->
PID, *idx, *idy, *idz);
653 DMDALocalInfo info_nodes;
655 PetscFunctionBeginUser;
658 if (user == NULL || is_within == NULL) {
660 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"Input pointer is NULL in CheckCellWithinLocalGrid.");
662 if (user->
fda == NULL) {
664 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE,
"user->fda is NULL. Cannot get ghost info.");
668 ierr = DMDAGetLocalInfo(user->
fda, &info_nodes); CHKERRQ(ierr);
675 PetscInt gxs_cell_global_start = info_nodes.gxs;
676 PetscInt gys_cell_global_start = info_nodes.gys;
677 PetscInt gzs_cell_global_start = info_nodes.gzs;
681 PetscInt gxm_cell_local_count = (info_nodes.gxm > 0) ? info_nodes.gxm - 1 : 0;
682 PetscInt gym_cell_local_count = (info_nodes.gym > 0) ? info_nodes.gym - 1 : 0;
683 PetscInt gzm_cell_local_count = (info_nodes.gzm > 0) ? info_nodes.gzm - 1 : 0;
686 PetscInt gxe_cell_global_end_exclusive = gxs_cell_global_start + gxm_cell_local_count;
687 PetscInt gye_cell_global_end_exclusive = gys_cell_global_start + gym_cell_local_count;
688 PetscInt gze_cell_global_end_exclusive = gzs_cell_global_start + gzm_cell_local_count;
693 if (idx >= gxs_cell_global_start && idx < gxe_cell_global_end_exclusive &&
694 idy >= gys_cell_global_start && idy < gye_cell_global_end_exclusive &&
695 idz >= gzs_cell_global_start && idz < gze_cell_global_end_exclusive) {
696 *is_within = PETSC_TRUE;
698 *is_within = PETSC_FALSE;
701 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
"Cell (origin node glob idx) (%d, %d, %d) is %s the ghosted local grid (covered cell origins x:[%d..%d), y:[%d..%d), z:[%d..%d)).\n",
702 idx, idy, idz, (*is_within) ?
"within" :
"outside",
703 gxs_cell_global_start, gxe_cell_global_end_exclusive,
704 gys_cell_global_start, gye_cell_global_end_exclusive,
705 gzs_cell_global_start, gze_cell_global_end_exclusive);
707 PetscFunctionReturn(0);
728 DMDALocalInfo info_nodes;
731 if (user == NULL || cell == NULL) {
733 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"RetrieveCurrentCell - One or more input pointers are NULL.");
737 ierr = DMGetCoordinatesLocal(user->
da, &Coor); CHKERRQ(ierr);
738 ierr = DMDAVecGetArrayRead(user->
fda, Coor, &coor_array); CHKERRQ(ierr);
742 ierr = DMDAGetLocalInfo(user->
fda, &info_nodes); CHKERRQ(ierr);
744 PetscInt idx_local = idx;
745 PetscInt idy_local = idy;
746 PetscInt idz_local = idz;
748 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
" [Rank %d] Getting vertex coordinates for cell: %d,%d,%d whose local coordinates are %d,%d,%d.\n",rank,idx,idy,idz,idx_local,idy_local,idz_local);
754 ierr = DMDAVecRestoreArrayRead(user->
fda, Coor, &coor_array); CHKERRQ(ierr);
757 ierr = MPI_Comm_rank(PETSC_COMM_WORLD, &rank); CHKERRQ(ierr);
815 PetscReal cellThreshold;
818 if (cell == NULL || position == NULL) {
820 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"EvaluateParticlePosition - One or more input pointers are NULL.");
827 cellThreshold = threshold*cellSize;
836 if (ierr == PETSC_ERR_USER) {
838 "EvaluateParticlePosition - Skipping cell due to degenerate face.\n");
907 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"UpdateCellIndicesBasedOnDistances - Input array 'd' is NULL.");
909 if (idx == NULL || idy == NULL || idz == NULL) {
911 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"UpdateCellIndicesBasedOnDistances - One or more index pointers are NULL.");
919 if (d[
FRONT] < 0.0) {
920 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
"UpdateCellIndicesBasedOnDistances - Condition met: d[FRONT] < 0.0, incrementing idz.\n");
923 else if(d[
BACK] < 0.0){
924 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
"UpdateCellIndicesBasedOnDistances - Condition met: d[BACK] < 0.0, decrementing idz.\n");
930 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
"UpdateCellIndicesBasedOnDistances - Condition met: d[LEFT] < 0.0, decrementing idx.\n");
933 else if (d[
RIGHT] < 0.0) {
934 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
"UpdateCellIndicesBasedOnDistances - Condition met: d[RIGHT] < 0.0, incrementing idx.\n");
940 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
"UpdateCellIndicesBasedOnDistances - Condition met: d[BOTTOM] < 0.0, decrementing idy.\n");
943 else if (d[
TOP] < 0.0) {
944 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
"UpdateCellIndicesBasedOnDistances - Condition met: d[TOP] < 0.0, incrementing idy.\n");
956 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
"UpdateCellIndicesBasedOnDistances - Updated Indices - idx, idy, idz: %d, %d, %d\n", *idx, *idy, *idz);
980 if (user == NULL || particle == NULL) {
982 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"FinalizeTraversal - One or more input pointers are NULL.");
986 LOG_ALLOW(
LOCAL,
LOG_INFO,
"FinalizeTraversal - Particle located in cell (%d, %d, %d) after %d traversal steps.\n",
987 idx, idy, idz, traversal_steps);
990 LOG_ALLOW(
LOCAL,
LOG_WARNING,
"FinalizeTraversal - Particle could not be located within the grid after %d traversal steps.\n", (PetscInt)traversal_steps);
991 particle->
cell[0] = -1;
992 particle->
cell[1] = -1;
993 particle->
cell[2] = -1;
1028 PetscErrorCode ierr;
1031 PetscFunctionBeginUser;
1033 ierr = MPI_Comm_size(PETSC_COMM_WORLD,&size); CHKERRQ(ierr);
1037 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE,
"UserCtx or RankCellInfoMap is not initialized in FindOwnerOfCell.");
1040 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"Output pointer owner_rank is NULL in FindOwnerOfCell.");
1048 for (PetscMPIInt r = 0; r < size; ++r) {
1064 if (*owner_rank == -1) {
1065 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
"FindOwnerOfCell: No owner found for global cell (%d, %d, %d). It is likely outside the domain.\n", i, j, k);
1067 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
"FindOwnerOfCell: Owner of cell (%d, %d, %d) is Rank %d.\n", i, j, k, *owner_rank);
1070 PetscFunctionReturn(0);
1098 PetscErrorCode ierr;
1102 PetscInt idx, idy, idz;
1103 PetscInt traversal_steps;
1104 PetscBool search_concluded = PETSC_FALSE;
1107 PetscInt repeatedIndexCount = 0;
1108 PetscInt prevIdx = PETSC_MIN_INT, prevIdy = PETSC_MIN_INT, prevIdz = PETSC_MIN_INT;
1109 PetscInt last_position_result = -999;
1111 PetscFunctionBeginUser;
1112 ierr = MPI_Comm_rank(PETSC_COMM_WORLD, &rank); CHKERRQ(ierr);
1120 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
" [PID %lld]Traversal Initiated at : i = %d, j = %d, k = %d.\n",(
long long)particle->
PID,idx,idy,idz);
1123 while (!search_concluded && traversal_steps <
MAX_TRAVERSAL) {
1127 if (idx < 0 || idx >= (user->
IM - 1) || idy < 0 || idy >= (user->
JM - 1) || idz < 0 || idz >= (user->
KM - 1)) {
1128 LOG_ALLOW(
LOCAL,
LOG_WARNING,
"[PID %lld]: Walked outside GLOBAL domain boundaries to invalid cell (%d,%d,%d). Search fails.\n",
1129 (
long long)particle->
PID, idx, idy, idz);
1136 PetscBool is_cell_local;
1138 if (!is_cell_local) {
1142 LOG_ALLOW(
LOCAL,
LOG_INFO,
"[PID %lld]: Walked outside local ghost region to cell (%d,%d,%d). Concluding search for handoff.\n",
1143 (
long long)particle->
PID, idx, idy, idz);
1144 search_concluded = PETSC_TRUE;
1149 if (idx == prevIdx && idy == prevIdy && idz == prevIdz) {
1150 repeatedIndexCount++;
1153 if (last_position_result >= 1) {
1154 LOG_ALLOW(
LOCAL,
LOG_WARNING,
"LocateOrMigrate [PID %lld]: Stuck on boundary of cell (%d,%d,%d) for %d steps. Applying enhanced tie-breaker.\n",
1155 (
long long)particle->
PID, idx, idy, idz, repeatedIndexCount);
1160 PetscInt final_position;
1167 search_concluded = PETSC_TRUE;
1169 LOG_ALLOW(
LOCAL,
LOG_ERROR,
"[PID %lld]: Tie-breaker failed during final evaluation at cell (%d,%d,%d). Search fails.\n",
1170 (
long long)particle->
PID, idx, idy, idz);
1172 search_concluded = PETSC_TRUE;
1175 LOG_ALLOW(
LOCAL,
LOG_ERROR,
"[PID %lld]: Search is stuck at cell (%d,%d,%d) but not on a boundary. This indicates a logic error. Failing search.\n",
1176 (
long long)particle->
PID, idx, idy, idz);
1178 search_concluded = PETSC_TRUE;
1180 if(search_concluded)
continue;
1183 repeatedIndexCount = 0;
1185 prevIdx = idx; prevIdy = idy; prevIdz = idz;
1190 PetscInt position_in_cell;
1194 last_position_result = position_in_cell;
1197 if (position_in_cell >= 0) {
1198 search_concluded = PETSC_TRUE;
1206 if (idx == -1 || (!search_concluded && traversal_steps >=
MAX_TRAVERSAL)) {
1212 particle->
cell[0] = -1; particle->
cell[1] = -1; particle->
cell[2] = -1;
1215 PetscMPIInt owner_rank;
1216 ierr =
FindOwnerOfCell(user, idx, idy, idz, &owner_rank); CHKERRQ(ierr);
1221 particle->
cell[0] = idx; particle->
cell[1] = idy; particle->
cell[2] = idz;
1223 if (owner_rank == rank) {
1225 }
else if (owner_rank != -1) {
1231 particle->
cell[0] = -1; particle->
cell[1] = -1; particle->
cell[2] = -1;
1241 PetscFunctionReturn(0);
1249 PetscInt traversal_steps)
1251 PetscFunctionBeginUser;
1254 LOG_ALLOW(
LOCAL,
LOG_INFO,
"Search SUCCESS [PID %lld]: Located in global cell (%d, %d, %d) after %d steps.\n",
1255 (
long long)particle->
PID, particle->
cell[0], particle->
cell[1], particle->
cell[2], traversal_steps);
1258 LOG_ALLOW(
LOCAL,
LOG_INFO,
"Search SUCCESS [PID %lld]: Identified for migration to Rank %d. Handoff cell is (%d, %d, %d) after %d steps.\n",
1263 (
long long)particle->
PID, traversal_steps);
1269 PetscFunctionReturn(0);
PetscErrorCode UpdateParticleWeights(PetscReal *d, Particle *particle)
Updates a particle's interpolation weights based on distances to cell faces.
Logging utilities and macros for PETSc-based applications.
PetscBool is_function_allowed(const char *functionName)
Checks if a given function is in the allow-list.
#define LOCAL
Logging scope definitions for controlling message output.
#define LOG_ALLOW(scope, level, fmt,...)
Logging macro that checks both the log level and whether the calling function is in the allowed-funct...
#define LOG_FUNC_TIMER_END_EVENT(eventID, scope)
Ends timing a function by:
PetscLogEvent EVENT_IndividualLocation
#define LOG_FUNC_TIMER_BEGIN_EVENT(eventID, scope)
Begins timing a function by:
LogLevel get_log_level()
Retrieves the current logging level from the environment variable LOG_LEVEL.
PetscErrorCode LOG_FACE_DISTANCES(PetscReal *d)
Prints the signed distances to each face of the cell.
@ LOG_ERROR
Critical errors that may halt the program.
@ LOG_INFO
Informational messages about program execution.
@ LOG_WARNING
Non-critical issues that warrant attention.
@ LOG_DEBUG
Detailed debugging information.
PetscErrorCode LOG_CELL_VERTICES(const Cell *cell, PetscMPIInt rank)
Prints the coordinates of a cell's vertices.
ParticleLocationStatus
Defines the state of a particle with respect to its location and migration status during the iterativ...
PetscMPIInt destination_rank
RankCellInfo * RankCellInfoMap
Cmpnts vertices[8]
Coordinates of the eight vertices of the cell.
Defines the vertices of a single hexahedral grid cell.
A 3D point or vector with PetscScalar components.
Defines a particle's core properties for Lagrangian tracking.
A lean struct to hold the global cell ownership range for a single MPI rank.
User-defined context containing data specific to a single computational grid level.
#define DISTANCE_THRESHOLD
PetscErrorCode LocateParticleOrFindMigrationTarget_TEST(UserCtx *user, Particle *particle, ParticleLocationStatus *status_out)
Locates a particle's host cell or identifies its migration target using a robust walk search.
PetscErrorCode FinalizeTraversal(UserCtx *user, Particle *particle, PetscInt traversal_steps, PetscBool cell_found, PetscInt idx, PetscInt idy, PetscInt idz)
Finalizes the traversal by reporting the results.
PetscErrorCode GetCellCharacteristicSize(const Cell *cell, PetscReal *cellSize)
Estimates a characteristic length of the cell for threshold scaling.
PetscErrorCode EvaluateParticlePosition(const Cell *cell, PetscReal *d, const Cmpnts p, PetscInt *position, const PetscReal threshold)
Determines the spatial relationship of a particle relative to a cubic cell.
PetscErrorCode ComputeSignedDistanceToPlane(const Cmpnts v1, const Cmpnts v2, const Cmpnts v3, const Cmpnts v4, const Cmpnts cell_centroid, const Cmpnts p_target, PetscReal *d_signed, const PetscReal threshold)
Computes the signed distance from a point to the plane approximating a quadrilateral face.
PetscErrorCode ReportSearchOutcome(const Particle *particle, ParticleLocationStatus status, PetscInt traversal_steps)
Logs the final outcome of the particle location search.
#define REPEAT_COUNT_THRESHOLD
PetscErrorCode CalculateDistancesToCellFaces(const Cmpnts p, const Cell *cell, PetscReal *d, const PetscReal threshold)
Computes the signed distances from a point to each face of a cubic cell.
PetscErrorCode DeterminePointPosition(PetscReal *d, PetscInt *result)
Classifies a point based on precomputed face distances.
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 RetrieveCurrentCell(UserCtx *user, PetscInt idx, PetscInt idy, PetscInt idz, Cell *cell)
Retrieves the coordinates of the eight vertices of the current cell.
PetscErrorCode GetCellVerticesFromGrid(Cmpnts ***coor, PetscInt idx, PetscInt idy, PetscInt idz, Cell *cell)
Retrieves the coordinates of the eight vertices of a cell based on grid indices.
PetscErrorCode UpdateCellIndicesBasedOnDistancesTEST(PetscReal d[NUM_FACES], PetscInt *idx, PetscInt *idy, PetscInt *idz)
Updates the cell indices based on the signed distances to each face.
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 GLOBAL CELL indices are within the LOCAL GHOSTED grid boundaries accessible by ...
Header file for particle location functions using the walking search algorithm.