17 PetscFunctionBeginUser;
18 PetscCheck(node_like != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
19 "Classification output is required.");
20 PetscCheck(dim >= 0 && dim < 3, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE,
21 "Dimension must be 0, 1, or 2; got %" PetscInt_FMT
".", dim);
25 *node_like = PETSC_TRUE;
28 *node_like = PETSC_FALSE;
31 *node_like = (PetscBool)(dim == 0);
34 *node_like = (PetscBool)(dim == 1);
37 *node_like = (PetscBool)(dim == 2);
42 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE,
43 "Component-staggered layout has no single per-dimension classification.");
45 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE,
46 "Unknown field layout %d.", (
int)layout);
48 PetscFunctionReturn(0);
62 PetscInt *lo, PetscInt *hi_exclusive)
67 *lo = (node_like && !periodic) ? 0 : 1;
69 *hi_exclusive = size - 1;
80 const DMDALocalInfo *info = NULL;
82 PetscInt owned_start[3];
83 PetscInt owned_end[3];
84 PetscInt global_size[3];
85 PetscBool periodic[3];
87 PetscFunctionBeginUser;
88 PetscCheck(user != NULL && plan != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
89 "Block context and plan output are required.");
91 "Only the fluid mask is implemented.");
93 PetscCheck(simCtx != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE,
94 "Block context must carry a simulation context.");
98 PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE,
99 "Field '%s' is component-staggered; its components live on different face "
100 "families and cannot share one pointwise target domain.",
104 owned_start[0] = info->xs; owned_end[0] = info->xs + info->xm; global_size[0] = info->mx;
105 owned_start[1] = info->ys; owned_end[1] = info->ys + info->ym; global_size[1] = info->my;
106 owned_start[2] = info->zs; owned_end[2] = info->zs + info->zm; global_size[2] = info->mz;
110 periodic[0] = (PetscBool)(simCtx->
i_periodic != 0);
111 periodic[1] = (PetscBool)(simCtx->
j_periodic != 0);
112 periodic[2] = (PetscBool)(simCtx->
k_periodic != 0);
118 for (PetscInt dim = 0; dim < 3; ++dim) {
119 PetscBool node_like = PETSC_FALSE;
120 PetscInt layout_lo = 0;
121 PetscInt layout_hi = 0;
124 ResolveLayoutSpan(node_like, periodic[dim], global_size[dim], &layout_lo, &layout_hi);
129 plan->
start[dim] = PetscMax(owned_start[dim], layout_lo);
130 plan->
end[dim] = PetscMin(owned_end[dim], layout_hi);
133 PetscFunctionReturn(0);
144 PetscFunctionBeginUser;
145 PetscCheck(plan != NULL && count != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
146 "Plan and count output are required.");
147 for (PetscInt dim = 0; dim < 3; ++dim) {
148 const PetscInt extent = plan->
end[dim] - plan->
start[dim];
149 if (extent <= 0) { *count = 0; PetscFunctionReturn(0); }
153 PetscFunctionReturn(0);
164 PetscFunctionBeginUser;
165 PetscCheck(plan != NULL && count != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
166 "Plan and count output are required.");
168 PetscCallMPI(MPI_Allreduce(&local, count, 1, MPIU_INT, MPI_SUM, comm));
169 PetscFunctionReturn(0);
178 if (plan == NULL)
return PETSC_FALSE;
FieldLayout
Logical storage topology of a field.
@ FIELD_LAYOUT_CELL_CENTERED
@ FIELD_LAYOUT_COMPONENT_STAGGERED
@ FIELD_LAYOUT_NODE_CENTERED
const char * canonical_name
PetscErrorCode FieldGetDescriptor(FieldId field_id, const FieldDescriptor **descriptor)
Return immutable metadata for a valid field identifier.
FieldId
Compile-time identity for a catalogued Eulerian field.
Immutable metadata for one field identity.
PetscBool SpatialTargetPlanMaskAllows(const SpatialTargetPlan *plan, PetscReal nvert_value)
Implementation of SpatialTargetPlanMaskAllows().
static void ResolveLayoutSpan(PetscBool node_like, PetscBool periodic, PetscInt size, PetscInt *lo, PetscInt *hi_exclusive)
Internal helper: resolves the layout-valid index span for one dimension.
PetscErrorCode SpatialTargetPlanLocalPointCount(const SpatialTargetPlan *plan, PetscInt *count)
Implementation of SpatialTargetPlanLocalPointCount().
PetscErrorCode SpatialTargetPlanGlobalPointCount(const SpatialTargetPlan *plan, MPI_Comm comm, PetscInt *count)
Implementation of SpatialTargetPlanGlobalPointCount().
PetscErrorCode SpatialTargetPlanCreate(UserCtx *user, FieldId field_id, PicurvStatisticsMask mask, SpatialTargetPlan *plan)
Implementation of SpatialTargetPlanCreate().
PetscErrorCode PicurvLayoutDimensionIsNodeLike(FieldLayout layout, PetscInt dim, PetscBool *node_like)
Implementation of PicurvLayoutDimensionIsNodeLike().
Spatial target resolution for the field-statistics pipeline.
#define PICURV_STATISTICS_FLUID_THRESHOLD
Threshold below which a cell counts as fluid for the default mask.
PicurvTargetKind kind
Spatial mapping; always pointwise in Phase 2.
@ PICURV_TARGET_POINTWISE
PicurvStatisticsMask
Point-eligibility mask.
@ PICURV_STATISTICS_MASK_FLUID
PetscInt end[3]
Exclusive end per dimension (i, j, k).
PetscInt start[3]
Inclusive start per dimension (i, j, k).
const FieldDescriptor * descriptor
Catalog metadata for the targeted field.
PicurvStatisticsMask mask
Point-eligibility mask.
Resolved iteration domain for one field on one block.
SimCtx * simCtx
Back-pointer to the master simulation context.
The master context for the entire simulation.
User-defined context containing data specific to a single computational grid level.