11#define MAX_TRAVERSAL 1000
12#define DISTANCE_THRESHOLD 1e-11
13#define REPEAT_COUNT_THRESHOLD 5
16#define BLOCKED_WALK_GUARD_CELLS 3.0
18#define REFLECTION_CAP 4
32 PetscErrorCode ierr = 0;
33 PetscFunctionBeginUser;
35 if (!cell || !cellSize) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
36 "GetCellCharacteristicSize: Null pointer(s).");
43 PetscInt edges[12][2] = {
44 {0,1},{1,2},{2,3},{3,0},
45 {4,5},{5,6},{6,7},{7,4},
46 {0,7},{1,6},{2,5},{3,4}
49 PetscReal totalEdgeLen = 0.0;
50 for (PetscInt i=0; i<12; i++) {
51 PetscInt vA = edges[i][0];
52 PetscInt vB = edges[i][1];
55 PetscReal dx = B.
x - A.
x;
56 PetscReal dy = B.
y - A.
y;
57 PetscReal dz = B.
z - A.
z;
58 PetscReal edgeLen = sqrt(dx*dx + dy*dy + dz*dz);
59 totalEdgeLen += edgeLen;
63 *cellSize = totalEdgeLen / 12.0;
66 PetscFunctionReturn(ierr);
75 const PetscReal vec_p_to_fc_x = plane->
centroid.
x - p.
x;
76 const PetscReal vec_p_to_fc_y = plane->
centroid.
y - p.
y;
77 const PetscReal vec_p_to_fc_z = plane->
centroid.
z - p.
z;
78 const PetscReal d = vec_p_to_fc_x * plane->
normal.
x + vec_p_to_fc_y * plane->
normal.
y + vec_p_to_fc_z * plane->
normal.
z;
79 return (fabs(d) < threshold) ? 0.0 : d;
89 const PetscReal threshold,
Cmpnts *normals)
94 PetscFunctionBeginUser;
97 if (((PetscInt)planes->
degenerate >> order[n]) & 1) {
98 LOG_ALLOW(
LOCAL,
LOG_ERROR,
"Degenerate plane detected on face %d (normal magnitude below 1e-12).\n", order[n]);
99 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_USER,
"Degenerate plane detected (normal vector is near zero).");
102 if (normals) normals[order[n]] = plane->
normal;
104 PetscFunctionReturn(0);
116 PetscFunctionBeginUser;
122 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"'cell' is NULL.");
128 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"'d' is NULL.");
136 "d[LEFT=%d]=%.3e, d[RIGHT=%d]=%.3e, d[BOTTOM=%d]=%.3e, "
137 "d[TOP=%d]=%.3e, d[FRONT=%d]=%.3e, d[BACK=%d]=%.3e\n",
141 "[%.3e, %.3e, %.3e, %.3e, %.3e, %.3e]\n",
142 d[0], d[1], d[2], d[3], d[4], d[5]);
145 PetscFunctionReturn(0);
157 PetscFunctionBeginUser;
162 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"Input parameter 'd' is NULL.");
164 if (result == NULL) {
166 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"Output parameter 'result' is NULL.");
170 PetscBool isInside = PETSC_TRUE;
171 PetscBool isOnBoundary = PETSC_FALSE;
172 PetscInt IntersectionCount = 0;
177 isInside = PETSC_FALSE;
180 isOnBoundary = PETSC_TRUE;
186 if(isInside && isOnBoundary) {
187 if(IntersectionCount == 1){
190 else if(IntersectionCount == 2){
193 else if(IntersectionCount >= 3){
205 PetscFunctionReturn(0);
217 const DMDALocalInfo *info;
219 PetscFunctionBeginUser;
223 if (user == NULL || particle == NULL || idx == NULL || idy == NULL || idz == NULL || traversal_steps == NULL) {
225 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"One or more input pointers are NULL.");
233 if (particle->
cell[0] >= 0 && particle->
cell[1] >= 0 && particle->
cell[2] >= 0) {
237 PetscBool is_handoff_cell_valid;
240 if (is_handoff_cell_valid) {
242 *idx = particle->
cell[0];
243 *idy = particle->
cell[1];
244 *idz = particle->
cell[2];
262 ierr = DMDAVecGetArrayRead(user->
fda, user->
lCent, ¢); CHKERRQ(ierr);
265 PetscInt candidates[7][3];
266 const char* candidate_names[7] = {
"X-min face",
"X-max face",
"Y-min face",
267 "Y-max face",
"Z-min face",
"Z-max face",
"Volume center"};
270 PetscInt mid_i = info->xs + (info->xm - 1) / 2;
271 PetscInt mid_j = info->ys + (info->ym - 1) / 2;
272 PetscInt mid_k = info->zs + (info->zm - 1) / 2;
273 PetscInt max_i = info->xs + info->xm - 2;
274 PetscInt max_j = info->ys + info->ym - 2;
275 PetscInt max_k = info->zs + info->zm - 2;
278 if (max_i < info->xs) max_i = info->xs;
279 if (max_j < info->ys) max_j = info->ys;
280 if (max_k < info->zs) max_k = info->zs;
283 candidates[0][0] = info->xs; candidates[0][1] = mid_j; candidates[0][2] = mid_k;
285 candidates[1][0] = max_i; candidates[1][1] = mid_j; candidates[1][2] = mid_k;
287 candidates[2][0] = mid_i; candidates[2][1] = info->ys; candidates[2][2] = mid_k;
289 candidates[3][0] = mid_i; candidates[3][1] = max_j; candidates[3][2] = mid_k;
291 candidates[4][0] = mid_i; candidates[4][1] = mid_j; candidates[4][2] = info->zs;
293 candidates[5][0] = mid_i; candidates[5][1] = mid_j; candidates[5][2] = max_k;
295 candidates[6][0] = mid_i; candidates[6][1] = mid_j; candidates[6][2] = mid_k;
298 PetscReal min_distance = PETSC_MAX_REAL;
299 PetscInt best_candidate = 6;
301 for (PetscInt i = 0; i < 7; i++) {
302 PetscInt ci = candidates[i][0];
303 PetscInt cj = candidates[i][1];
304 PetscInt ck = candidates[i][2];
307 Cmpnts cell_center = cent[ck+1][cj+1][ci+1];
310 PetscReal dx = particle->
loc.
x - cell_center.
x;
311 PetscReal dy = particle->
loc.
y - cell_center.
y;
312 PetscReal dz = particle->
loc.
z - cell_center.
z;
313 PetscReal distance = sqrt(dx*dx + dy*dy + dz*dz);
315 if (distance < min_distance) {
316 min_distance = distance;
325 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lCent, ¢); CHKERRQ(ierr);
328 "no prior cell: walk starts at the %s seed cell (%" PetscInt_FMT
",%" PetscInt_FMT
",%" PetscInt_FMT
"), %.3e from the particle\n",
329 candidate_names[best_candidate], *idx, *idy, *idz, min_distance);
333 *traversal_steps = 0;
336 PetscFunctionReturn(0);
348 const DMDALocalInfo *info_nodes;
350 PetscFunctionBeginUser;
354 if (user == NULL || is_within == NULL) {
356 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"Input pointer is NULL in CheckCellWithinLocalGrid.");
361 info_nodes = &user->
info;
368 PetscInt gxs_cell_global_start = info_nodes->gxs;
369 PetscInt gys_cell_global_start = info_nodes->gys;
370 PetscInt gzs_cell_global_start = info_nodes->gzs;
374 PetscInt gxm_cell_local_count = (info_nodes->gxm > 0) ? info_nodes->gxm - 1 : 0;
375 PetscInt gym_cell_local_count = (info_nodes->gym > 0) ? info_nodes->gym - 1 : 0;
376 PetscInt gzm_cell_local_count = (info_nodes->gzm > 0) ? info_nodes->gzm - 1 : 0;
379 PetscInt gxe_cell_global_end_exclusive = gxs_cell_global_start + gxm_cell_local_count;
380 PetscInt gye_cell_global_end_exclusive = gys_cell_global_start + gym_cell_local_count;
381 PetscInt gze_cell_global_end_exclusive = gzs_cell_global_start + gzm_cell_local_count;
386 if (idx >= gxs_cell_global_start && idx < gxe_cell_global_end_exclusive &&
387 idy >= gys_cell_global_start && idy < gye_cell_global_end_exclusive &&
388 idz >= gzs_cell_global_start && idz < gze_cell_global_end_exclusive) {
389 *is_within = PETSC_TRUE;
391 *is_within = PETSC_FALSE;
395 PetscFunctionReturn(0);
408 const PetscScalar *coor_flat;
409 PetscInt gxs, gys, gzs, gxm, gym;
411 PetscFunctionBeginUser;
415 if (user == NULL || cell == NULL) {
417 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"One or more input pointers are NULL.");
424 gxs = user->
info.gxs; gys = user->
info.gys; gzs = user->
info.gzs;
425 gxm = user->
info.gxm; gym = user->
info.gym;
426 ierr = VecGetArrayRead(Coor, &coor_flat); CHKERRQ(ierr);
429#define PICURV_NODE(i, j, k) coor[(((k) - gzs) * gym + ((j) - gys)) * gxm + ((i) - gxs)]
441 ierr = VecRestoreArrayRead(Coor, &coor_flat); CHKERRQ(ierr);
444 PetscFunctionReturn(0);
454 PetscInt *position,
const PetscReal threshold)
458 PetscFunctionBeginUser;
465 PetscFunctionReturn(0);
475 PetscFunctionBeginUser;
490 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"Input array 'd' is NULL.");
492 if (idx == NULL || idy == NULL || idz == NULL) {
494 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"One or more index pointers are NULL.");
498 if (d[
FRONT] < 0.0) {
501 else if(d[
BACK] < 0.0){
509 else if (d[
RIGHT] < 0.0) {
517 else if (d[
TOP] < 0.0) {
530 PetscFunctionReturn(0);
540 PetscFunctionBeginUser;
546 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE,
"UserCtx or RankCellInfoMap is not initialized in FindOwnerOfCell.");
549 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"Output pointer owner_rank is NULL in FindOwnerOfCell.");
556 const PetscInt cell[3] = {i, j, k};
557 const PetscInt stride[3] = {1, procs[0], procs[0] * procs[1]};
561 for (PetscInt a = 0; a < 3; ++a) {
562 PetscInt lo = 0, hi = procs[a] - 1;
564 const PetscInt mid = (lo + hi + 1) / 2;
571 const PetscInt r = slot[0] + procs[0] * (slot[1] + procs[1] * slot[2]);
575 if ((i >= info->xs_cell && i < info->xs_cell + info->xm_cell) &&
576 (j >= info->ys_cell && j < info->ys_cell + info->ym_cell) &&
577 (k >= info->zs_cell && k < info->zs_cell + info->zm_cell)) *owner_rank = (PetscMPIInt)r;
580 PetscFunctionReturn(0);
595 PetscFunctionBeginUser;
597 if (!planes || !p) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"Planes and point must not be NULL.");
598 if (face < 0 || face >=
NUM_FACES) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE,
"Face %" PetscInt_FMT
" is not a cell face.", face);
602 LOG_ALLOW(
LOCAL,
LOG_VERBOSE,
"Mirror about face %" PetscInt_FMT
": d = %.6e, n = (%.6e, %.6e, %.6e).\n", face, d[face], n[face].x, n[face].y, n[face].z);
603 p->
x += 2.0 * d[face] * n[face].
x;
604 p->
y += 2.0 * d[face] * n[face].
y;
605 p->
z += 2.0 * d[face] * n[face].
z;
608 PetscFunctionReturn(0);
621 Cmpnts c = {0.0, 0.0, 0.0};
624 PetscFunctionBeginUser;
626 if (!cell || !p || !placed) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"Cell, point and output flag must not be NULL.");
627 *placed = PETSC_FALSE;
628 for (
int v = 0; v < 8; ++v) {
638 for (PetscInt f = 0; f <
NUM_FACES; ++f) {
639 if (dp[f] >= 0.0)
continue;
641 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
"Cell centroid is not inside face %" PetscInt_FMT
"'s plane (d = %.3e); cannot place the particle.\n", f, dc[f]);
643 PetscFunctionReturn(0);
645 t = PetscMax(t, dp[f] / (dp[f] - dc[f]));
647 t += 1.0e-6 * (1.0 - t);
649 p->
x += t * (c.
x - p->
x);
650 p->
y += t * (c.
y - p->
y);
651 p->
z += t * (c.
z - p->
z);
652 *placed = PETSC_TRUE;
655 PetscFunctionReturn(0);
663static inline void ResetStuckDetection(PetscInt *repeated, PetscInt *prev_i, PetscInt *prev_j, PetscInt *prev_k)
666 *prev_i = PETSC_MIN_INT; *prev_j = PETSC_MIN_INT; *prev_k = PETSC_MIN_INT;
684 PetscInt idx, idy, idz;
685 PetscInt traversal_steps;
686 PetscBool search_concluded = PETSC_FALSE;
687 PetscBool exited = PETSC_FALSE;
688 PetscBool blocked = PETSC_FALSE;
691 PetscInt repeatedIndexCount = 0;
692 PetscInt prevIdx = PETSC_MIN_INT, prevIdy = PETSC_MIN_INT, prevIdz = PETSC_MIN_INT;
693 PetscInt last_position_result = -999;
694 PetscInt reflections = 0;
696 PetscFunctionBeginUser;
713 plane_arrays = &own_arrays;
715 PetscCheck(!plane_arrays->
dual, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG,
"The walk needs the primal face planes, not the dual ones.");
717 const PetscInt start_cell[3] = {idx, idy, idz};
720 while (!search_concluded && traversal_steps <
MAX_TRAVERSAL) {
727 PetscBool hit_boundary = PETSC_FALSE;
730 hit_boundary = PETSC_TRUE;
733 if (idx >= (user->
IM - 1)) {
735 hit_boundary = PETSC_TRUE;
740 hit_boundary = PETSC_TRUE;
743 if (idy >= (user->
JM - 1)) {
745 hit_boundary = PETSC_TRUE;
750 hit_boundary = PETSC_TRUE;
753 if (idz >= (user->
KM - 1)) {
755 hit_boundary = PETSC_TRUE;
760 LOG_PARTICLE(user->
simCtx, particle->
PID,
"locate",
"walk clamped to boundary cell (%" PetscInt_FMT
",%" PetscInt_FMT
",%" PetscInt_FMT
")\n",
766 PetscBool is_cell_local;
768 if (!is_cell_local) {
772 LOG_PARTICLE(user->
simCtx, particle->
PID,
"locate",
"walk left this rank's ghost region at cell (%" PetscInt_FMT
",%" PetscInt_FMT
",%" PetscInt_FMT
"): handoff\n",
774 search_concluded = PETSC_TRUE;
779 if (idx == prevIdx && idy == prevIdy && idz == prevIdz) {
780 repeatedIndexCount++;
783 if (last_position_result >= 1) {
786 LOG_PARTICLE(user->
simCtx, particle->
PID,
"locate",
"stuck on the boundary of cell (%" PetscInt_FMT
",%" PetscInt_FMT
",%" PetscInt_FMT
") for %" PetscInt_FMT
" steps: tie-break accepts it\n",
787 idx, idy, idz, repeatedIndexCount);
791 PetscInt final_position;
799 search_concluded = PETSC_TRUE;
801 LOG_ALLOW(
LOCAL,
LOG_ERROR,
"[PID %lld]: Tie-breaker failed during final evaluation at cell (%" PetscInt_FMT
",%" PetscInt_FMT
",%" PetscInt_FMT
"). Search fails.\n",
802 (
long long)particle->
PID, idx, idy, idz);
804 search_concluded = PETSC_TRUE;
807 LOG_ALLOW(
LOCAL,
LOG_ERROR,
"[PID %lld]: Search is stuck at cell (%" PetscInt_FMT
",%" PetscInt_FMT
",%" PetscInt_FMT
") but not on a boundary. This indicates a logic error. Failing search.\n",
808 (
long long)particle->
PID, idx, idy, idz);
810 search_concluded = PETSC_TRUE;
812 if(search_concluded)
continue;
815 repeatedIndexCount = 0;
817 prevIdx = idx; prevIdy = idy; prevIdz = idz;
824 PetscInt position_in_cell;
827 last_position_result = position_in_cell;
829 "walk step %" PetscInt_FMT
" cell (%" PetscInt_FMT
",%" PetscInt_FMT
",%" PetscInt_FMT
") at (%.6e, %.6e, %.6e): position %" PetscInt_FMT
" (0 inside, >0 on a face/edge/corner, -1 outside), d L %.3e R %.3e B %.3e T %.3e F %.3e K %.3e\n",
830 traversal_steps, idx, idy, idz, particle->
loc.
x, particle->
loc.
y, particle->
loc.
z, position_in_cell,
834 if (position_in_cell >= 0) {
835 search_concluded = PETSC_TRUE;
839 const PetscBool on_domain_face[
NUM_FACES] = {idx == 0, idx == user->
IM - 2, idy == 0, idy == user->
JM - 2,
840 idz == user->
KM - 2, idz == 0};
841 PetscInt crossed = -1;
842 for (PetscInt f = 0; f <
NUM_FACES; ++f) {
843 if (distances[f] >= 0.0)
continue;
844 if (!on_domain_face[f]) { crossed = -1;
break; }
845 if (crossed < 0 || distances[f] < distances[crossed]) crossed = f;
852 PetscBool reflect = PETSC_TRUE;
853 PetscBool wrap = PETSC_FALSE;
854 for (PetscInt f = 0; f <
NUM_FACES; ++f) {
855 if (distances[f] >= 0.0)
continue;
860 cell_size = current_planes->
size;
865 for (PetscInt f = 0; f <
NUM_FACES; ++f) {
868 const PetscInt axis = (PetscInt)face / 2;
869 const PetscReal sign = ((PetscInt)face % 2 == 0) ? 1.0 : -1.0;
872 "Particle wrap on axis %d needs the validated seam translation.", (
int)axis);
873 particle->
loc.
x += sign * T.
x;
874 particle->
loc.
y += sign * T.
y;
875 particle->
loc.
z += sign * T.
z;
876 if (axis == 0) idx = (sign > 0.0) ? user->
IM - 2 : 0;
877 if (axis == 1) idy = (sign > 0.0) ? user->
JM - 2 : 0;
878 if (axis == 2) idz = (sign > 0.0) ? user->
KM - 2 : 0;
880 LOG_PARTICLE(user->
simCtx, particle->
PID,
"locate",
"wrapped through %s to (%.6e, %.6e, %.6e), cell (%" PetscInt_FMT
",%" PetscInt_FMT
",%" PetscInt_FMT
")\n",
885 blocked = PETSC_TRUE;
886 search_concluded = PETSC_TRUE;
887 LOG_PARTICLE(user->
simCtx, particle->
PID,
"locate",
"%.3e beyond boundary face %" PetscInt_FMT
" of cell (%" PetscInt_FMT
",%" PetscInt_FMT
",%" PetscInt_FMT
"), above the %.1f-cell guard: walk treated as blocked\n",
889 }
else if (!reflect) {
891 search_concluded = PETSC_TRUE;
892 LOG_PARTICLE(user->
simCtx, particle->
PID,
"locate",
"left the domain through boundary face %" PetscInt_FMT
" of cell (%" PetscInt_FMT
",%" PetscInt_FMT
",%" PetscInt_FMT
"), %.3e beyond it\n",
893 crossed, idx, idy, idz, -distances[crossed]);
901 LOG_PARTICLE(user->
simCtx, particle->
PID,
"locate",
"reflected about boundary face %" PetscInt_FMT
" of cell (%" PetscInt_FMT
",%" PetscInt_FMT
",%" PetscInt_FMT
") to (%.6e, %.6e, %.6e)\n",
902 crossed, idx, idy, idz, particle->
loc.
x, particle->
loc.
y, particle->
loc.
z);
911 LOG_PARTICLE(user->
simCtx, particle->
PID,
"locate",
"reflection cap %d reached: placed just inside cell (%" PetscInt_FMT
",%" PetscInt_FMT
",%" PetscInt_FMT
")\n",
915 search_concluded = PETSC_TRUE;
931 particle->
cell[0] = -1; particle->
cell[1] = -1; particle->
cell[2] = -1;
934 particle->
cell[0] = -1; particle->
cell[1] = -1; particle->
cell[2] = -1;
935 }
else if (idx == -1 || (!search_concluded && traversal_steps >=
MAX_TRAVERSAL)) {
942 particle->
cell[0] = -1; particle->
cell[1] = -1; particle->
cell[2] = -1;
945 PetscMPIInt owner_rank;
946 ierr =
FindOwnerOfCell(user, idx, idy, idz, &owner_rank); CHKERRQ(ierr);
949 particle->
cell[0] = idx; particle->
cell[1] = idy; particle->
cell[2] = idz;
951 if (owner_rank == rank) {
953 }
else if (owner_rank != -1) {
959 particle->
cell[0] = -1; particle->
cell[1] = -1; particle->
cell[2] = -1;
965 "%s from cell (%" PetscInt_FMT
",%" PetscInt_FMT
",%" PetscInt_FMT
") to (%" PetscInt_FMT
",%" PetscInt_FMT
",%" PetscInt_FMT
") in %" PetscInt_FMT
" step(s), %" PetscInt_FMT
" reflection(s) | weights (%.6f, %.6f, %.6f) | at (%.6e, %.6e, %.6e) | destination rank %d\n",
967 particle->
cell[0], particle->
cell[1], particle->
cell[2], traversal_steps, reflections,
973 PetscFunctionReturn(0);
PetscErrorCode MetricRestoreFacePlaneArrays(UserCtx *user, FacePlaneArrays *arrays)
Closes arrays opened by MetricGetFacePlaneArrays().
void MetricGatherCellFacePlanes(const FacePlaneArrays *arrays, const DMDALocalInfo *info, PetscInt i, PetscInt j, PetscInt k, CellFacePlanes *planes)
Assembles one cell's six outward face planes from the shared per-face planes.
PetscErrorCode MetricGetFacePlaneArrays(UserCtx *user, PetscBool dual, FacePlaneArrays *arrays)
Opens a family's face-plane arrays for reading; MetricComputeFacePlanes() must have run.
void MetricBuildCellFacePlanes(const Cell *cell, CellFacePlanes *planes)
Builds the six face planes of a hexahedron, as the particle search tests them.
PetscBool dual
Dual-cell planes (from lCent) rather than grid-cell planes.
Read-only flat arrays of one family of face planes (grid cells or dual cells).
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.
#define LOG_PARTICLE(simCtx, pid, stage, fmt,...)
Reports one particle at one stage of a step: the consolidated per-particle line.
#define LOCAL
Logging scope definitions for controlling message output.
const char * BCFaceToString(BCFace face)
Returns the canonical log token for a boundary-face enum value.
#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 PROFILE_HELPER_BEGIN
Marks the beginning of a profiled helper: timed only when enabled by name.
#define PROFILE_HELPER_END
Alias of PROFILE_FUNCTION_END for a function that began with PROFILE_HELPER_BEGIN.
const char * ParticleLocationStatusToString(ParticleLocationStatus level)
A function that outputs the name of the current level in the ParticleLocation enum.
@ LOG_ERROR
Critical errors that may halt the program.
@ LOG_DEBUG
Detailed debugging information.
@ LOG_VERBOSE
Extremely detailed logs, typically for development use only.
Cmpnts normal
Unit outward normal of (v2 - v1) x (v4 - v1); unnormalised when degenerate.
BoundaryFaceConfig boundary_faces[6]
PetscInt64 reflectionCount
Cmpnts centroid
Mean of the face's four vertices.
SimCtx * simCtx
Back-pointer to the master simulation context.
ParticleLocationStatus
Defines the state of a particle with respect to its location and migration status during the iterativ...
@ LOST
The search failed for a particle believed to be inside the domain.
@ EXITED
The particle crossed a domain-boundary face whose particle policy removes it.
PetscInt64 boundaryClampCount
ParticleBoundaryPolicy
What happens to a particle that crosses a domain-boundary face.
@ PARTICLE_BOUNDARY_REFLECT
The particle is mirrored about the face plane and stays.
@ PARTICLE_BOUNDARY_WRAP
Periodic faces: the particle re-enters through the paired face.
PetscInt64 traversalStepsSum
PetscInt currentSettlementPass
PetscInt RankCellInfoProcs[3]
DMDA process grid (m, n, p) of RankCellInfoMap: rank i + m (j + n k).
PetscReal size
Mean edge length (GetCellCharacteristicSize()); 0 where unused.
PetscMPIInt destination_rank
RankCellInfo * RankCellInfoMap
PetscInt64 maxTraversalSteps
ParticleBoundaryPolicy particle_policy
What a particle crossing this face becomes (BC param particle_policy).
PetscInt degenerate
Bit f set when face f's normal magnitude is below 1e-12.
SearchMetricsState searchMetrics
Cmpnts periodic_translation[3]
PetscBool periodic_translation_valid[3]
PetscInt64 searchAttempts
FacePlane face[NUM_FACES]
Face planes in LEFT..BACK order.
PetscInt64 reflectionFallbackCount
PetscInt64 blockedWalkRetryCount
PetscInt64 maxTraversalFailCount
Cmpnts vertices[8]
Coordinates of the eight vertices of the cell.
BCFace
Identifies the six logical faces of a structured computational block.
Defines the vertices of a single hexahedral grid cell.
The six face planes of one hexahedron, indexed by Face, and its characteristic size.
A 3D point or vector with PetscScalar components.
One cell face as the particle search tests against it: a plane through the vertex mean.
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 CalculateDistancesToCellFacePlanes(const Cmpnts p, const CellFacePlanes *planes, PetscReal *d, const PetscReal threshold, Cmpnts *normals)
Implementation of CalculateDistancesToCellFacePlanes().
PetscErrorCode EvaluateParticlePositionInPlanes(const CellFacePlanes *planes, PetscReal *d, const Cmpnts p, PetscInt *position, const PetscReal threshold)
Implementation of EvaluateParticlePositionInPlanes().
#define BLOCKED_WALK_GUARD_CELLS
PetscErrorCode CalculateDistancesToCellFaces(const Cmpnts p, const Cell *cell, PetscReal *d, const PetscReal threshold, Cmpnts *normals)
Implementation of CalculateDistancesToCellFaces().
PetscErrorCode GetCellCharacteristicSize(const Cell *cell, PetscReal *cellSize)
Implementation of GetCellCharacteristicSize().
PetscErrorCode ReflectParticleAcrossCellFace(const CellFacePlanes *planes, PetscInt face, Cmpnts *p)
Implementation of ReflectParticleAcrossCellFace().
static PetscReal FacePlaneDistance(const FacePlane *plane, const Cmpnts p, const PetscReal threshold)
Signed distance from p to a face plane, positive on the cell side, zeroed below threshold.
PetscErrorCode PlaceParticleInsideCell(const Cell *cell, Cmpnts *p, PetscBool *placed)
Implementation of PlaceParticleInsideCell().
PetscErrorCode LocateParticleOrFindMigrationTarget(UserCtx *user, const FacePlaneArrays *planes, Particle *particle, ParticleLocationStatus *status_out)
Implementation of LocateParticleOrFindMigrationTarget().
#define REPEAT_COUNT_THRESHOLD
PetscErrorCode DeterminePointPosition(PetscReal *d, PetscInt *result)
Implementation of DeterminePointPosition().
PetscErrorCode UpdateCellIndicesBasedOnDistances(PetscReal d[NUM_FACES], PetscInt *idx, PetscInt *idy, PetscInt *idz)
Implementation of UpdateCellIndicesBasedOnDistances().
PetscErrorCode FindOwnerOfCell(UserCtx *user, PetscInt i, PetscInt j, PetscInt k, PetscMPIInt *owner_rank)
Implementation of FindOwnerOfCell().
#define PICURV_NODE(i, j, k)
PetscErrorCode RetrieveCurrentCell(UserCtx *user, PetscInt idx, PetscInt idy, PetscInt idz, Cell *cell)
Implementation of RetrieveCurrentCell().
static const BCFace kCellFaceDomainFace[NUM_FACES]
static void ResetStuckDetection(PetscInt *repeated, PetscInt *prev_i, PetscInt *prev_j, PetscInt *prev_k)
Forget the cell the stuck-walk detector compared against, after the particle moved without the walk s...
PetscErrorCode InitializeTraversalParameters(UserCtx *user, Particle *particle, PetscInt *idx, PetscInt *idy, PetscInt *idz, PetscInt *traversal_steps)
Implementation of InitializeTraversalParameters().
PetscErrorCode CheckCellWithinLocalGrid(UserCtx *user, PetscInt idx, PetscInt idy, PetscInt idz, PetscBool *is_within)
Implementation of CheckCellWithinLocalGrid().
Header file for particle location functions using the walking search algorithm.