PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
 
Loading...
Searching...
No Matches
Data Structures | Macros | Enumerations | Functions
statistics_target.h File Reference

Spatial target resolution for the field-statistics pipeline. More...

#include "variables.h"
#include "field_catalog.h"
Include dependency graph for statistics_target.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SpatialTargetPlan
 Resolved iteration domain for one field on one block. More...
 

Macros

#define PICURV_STATISTICS_FLUID_THRESHOLD   0.1
 Threshold below which a cell counts as fluid for the default mask.
 
#define PICURV_SPATIAL_AVERAGE_MAX_BUFFER   4000000
 Largest reduction buffer a directional average will allocate, in entries.
 

Enumerations

enum  PicurvTargetKind { PICURV_TARGET_POINTWISE = 0 }
 Spatial mapping kind. More...
 
enum  PicurvStatisticsMask { PICURV_STATISTICS_MASK_FLUID = 0 }
 Point-eligibility mask. More...
 

Functions

PetscErrorCode PicurvLayoutDimensionIsNodeLike (FieldLayout layout, PetscInt dim, PetscBool *node_like)
 Reports whether a layout is node-like in one dimension.
 
PetscErrorCode SpatialTargetPlanCreate (UserCtx *user, FieldId field_id, PicurvStatisticsMask mask, SpatialTargetPlan *plan)
 Resolves the iteration domain for one field on one block.
 
PetscErrorCode SpatialTargetPlanLocalPointCount (const SpatialTargetPlan *plan, PetscInt *count)
 Counts the points this rank contributes.
 
PetscErrorCode SpatialTargetPlanGlobalPointCount (const SpatialTargetPlan *plan, MPI_Comm comm, PetscInt *count)
 Counts the points contributed across a communicator.
 
PetscBool SpatialTargetPlanMaskAllows (const SpatialTargetPlan *plan, PetscReal nvert_value)
 Reports whether a point passes the plan's mask.
 
PetscErrorCode PicurvSpatialRatioAverage (UserCtx *user, const SpatialTargetPlan *plan, Vec numerator, Vec denominator, Vec inclusion, const PetscBool average_direction[3], MPI_Comm comm, Vec ratio, PetscReal *reduced)
 Averages two fields over a target domain and divides the results.
 

Detailed Description

Spatial target resolution for the field-statistics pipeline.

Implements the pointwise identity mapping described in 5. Spatial Target, Layout, and Mask. The abstraction exists with only that one mapping so later spatial bins, profiles, regions, and surfaces extend it rather than retrofit it; see Field Statistics Planned Extensions.

The central responsibility is producing an iteration domain that excludes two distinct categories which Field Identity and Layout Catalog section 4 warns must not be conflated:

  1. PETSc/MPI halo entries created by DMDA decomposition, and
  2. solver-layout boundary, dummy, or duplicate-periodic indices, which exist even on a single MPI rank.

Nothing here resolves field identity or layout metadata itself; that comes from the typed catalog through FieldGetDescriptor.

Definition in file statistics_target.h.


Data Structure Documentation

◆ SpatialTargetPlan

struct SpatialTargetPlan

Resolved iteration domain for one field on one block.

Bounds are half-open [start, end) in DMDA index order (i, j, k) and are already intersected with this rank's owned range, so iterating them touches neither halo storage nor layout boundary/dummy/duplicate-periodic indices. An empty domain on a rank is represented by end[d] <= start[d].

Definition at line 49 of file statistics_target.h.

Collaboration diagram for SpatialTargetPlan:
[legend]
Data Fields
PicurvTargetKind kind Spatial mapping; always pointwise.
PicurvStatisticsMask mask Point-eligibility mask.
const FieldDescriptor * descriptor Catalog metadata for the targeted field.
PetscInt start[3] Inclusive start per dimension (i, j, k).
PetscInt end[3] Exclusive end per dimension (i, j, k).

Macro Definition Documentation

◆ PICURV_STATISTICS_FLUID_THRESHOLD

#define PICURV_STATISTICS_FLUID_THRESHOLD   0.1

Threshold below which a cell counts as fluid for the default mask.

Definition at line 29 of file statistics_target.h.

◆ PICURV_SPATIAL_AVERAGE_MAX_BUFFER

#define PICURV_SPATIAL_AVERAGE_MAX_BUFFER   4000000

Largest reduction buffer a directional average will allocate, in entries.

Definition at line 127 of file statistics_target.h.

Enumeration Type Documentation

◆ PicurvTargetKind

Spatial mapping kind.

Only the pointwise identity is implemented.

Enumerator
PICURV_TARGET_POINTWISE 

Definition at line 32 of file statistics_target.h.

32 {
PicurvTargetKind
Spatial mapping kind.
@ PICURV_TARGET_POINTWISE

◆ PicurvStatisticsMask

Point-eligibility mask.

Only the fluid mask is implemented.

Enumerator
PICURV_STATISTICS_MASK_FLUID 

Definition at line 37 of file statistics_target.h.

37 {
PicurvStatisticsMask
Point-eligibility mask.
@ PICURV_STATISTICS_MASK_FLUID

Function Documentation

◆ PicurvLayoutDimensionIsNodeLike()

PetscErrorCode PicurvLayoutDimensionIsNodeLike ( FieldLayout  layout,
PetscInt  dim,
PetscBool *  node_like 
)

Reports whether a layout is node-like in one dimension.

Node-like dimensions carry one more physical entry than cell-like dimensions, because they sit on grid lines rather than between them. I_FACE is node-like in i and cell-like in j and k, and correspondingly for the other face families.

Parameters
[in]layoutCatalog layout.
[in]dimDimension index: 0 for i, 1 for j, 2 for k.
[out]node_likeResolved classification.
Returns
Zero on success, or PETSC_ERR_ARG_OUTOFRANGE for an invalid dimension, or PETSC_ERR_ARG_WRONGSTATE for a component-staggered layout, whose components do not share one classification.

Reports whether a layout is node-like in one dimension.

See also
PicurvLayoutDimensionIsNodeLike()

Definition at line 16 of file statistics_target.c.

17{
18 PetscFunctionBeginUser;
20 PetscCheck(node_like != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
21 "Classification output is required.");
22 PetscCheck(dim >= 0 && dim < 3, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE,
23 "Dimension must be 0, 1, or 2; got %" PetscInt_FMT ".", dim);
24
25 switch (layout) {
27 *node_like = PETSC_TRUE;
28 break;
30 *node_like = PETSC_FALSE;
31 break;
33 *node_like = (PetscBool)(dim == 0);
34 break;
36 *node_like = (PetscBool)(dim == 1);
37 break;
39 *node_like = (PetscBool)(dim == 2);
40 break;
42 /* x, y, and z live on I-, J-, and K-faces respectively, so no single
43 * classification describes the packed vector. */
44 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE,
45 "Component-staggered layout has no single per-dimension classification.");
46 default:
47 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE,
48 "Unknown field layout %d.", (int)layout);
49 }
51 PetscFunctionReturn(0);
52}
@ FIELD_LAYOUT_K_FACE
@ FIELD_LAYOUT_I_FACE
@ FIELD_LAYOUT_CELL_CENTERED
@ FIELD_LAYOUT_COMPONENT_STAGGERED
@ FIELD_LAYOUT_NODE_CENTERED
@ FIELD_LAYOUT_J_FACE
#define PROFILE_FUNCTION_END
Marks the end of a profiled code block.
Definition logging.h:1029
#define PROFILE_FUNCTION_BEGIN
Marks the beginning of a profiled function: an always-on aggregate timer.
Definition logging.h:1000
Here is the caller graph for this function:

◆ SpatialTargetPlanCreate()

PetscErrorCode SpatialTargetPlanCreate ( UserCtx *  user,
FieldId  field_id,
PicurvStatisticsMask  mask,
SpatialTargetPlan *  plan 
)

Resolves the iteration domain for one field on one block.

Rejects component-staggered fields, whose x, y, and z components live on different face families and therefore cannot share a single pointwise domain. Configured statistics request only cell-centered fields, but the plan resolves node and face layouts correctly so later phases inherit a verified contract.

Parameters
[in]userBlock context supplying the DMDA layout and periodicity.
[in]field_idCatalogued field to target.
[in]maskPoint-eligibility mask.
[out]planResolved plan.
Returns
Zero on success, or a PETSc error for a null argument, an unknown field, or an unsupported layout.

Resolves the iteration domain for one field on one block.

See also
SpatialTargetPlanCreate()

Definition at line 81 of file statistics_target.c.

83{
84 const FieldDescriptor *descriptor = NULL;
85 const DMDALocalInfo *info = NULL;
86 SimCtx *simCtx = NULL;
87 PetscInt owned_start[3];
88 PetscInt owned_end[3];
89 PetscInt global_size[3];
90 PetscBool periodic[3];
91
92 PetscFunctionBeginUser;
94 PetscCheck(user != NULL && plan != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
95 "Block context and plan output are required.");
96 PetscCheck(mask == PICURV_STATISTICS_MASK_FLUID, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE,
97 "Only the fluid mask is implemented.");
98 simCtx = user->simCtx;
99 PetscCheck(simCtx != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE,
100 "Block context must carry a simulation context.");
101
102 PetscCall(FieldGetDescriptor(field_id, &descriptor));
103 PetscCheck(descriptor->layout != FIELD_LAYOUT_COMPONENT_STAGGERED,
104 PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE,
105 "Field '%s' is component-staggered; its components live on different face "
106 "families and cannot share one pointwise target domain.",
107 descriptor->canonical_name);
108
109 info = &user->info;
110 owned_start[0] = info->xs; owned_end[0] = info->xs + info->xm; global_size[0] = info->mx;
111 owned_start[1] = info->ys; owned_end[1] = info->ys + info->ym; global_size[1] = info->my;
112 owned_start[2] = info->zs; owned_end[2] = info->zs + info->zm; global_size[2] = info->mz;
113 GetPeriodicAxes(simCtx, periodic);
114
116 plan->mask = mask;
117 plan->descriptor = descriptor;
118
119 for (PetscInt dim = 0; dim < 3; ++dim) {
120 PetscBool node_like = PETSC_FALSE;
121 PetscInt layout_lo = 0;
122 PetscInt layout_hi = 0;
123
124 PetscCall(PicurvLayoutDimensionIsNodeLike(descriptor->layout, dim, &node_like));
125 ResolveLayoutSpan(node_like, periodic[dim], global_size[dim], &layout_lo, &layout_hi);
126
127 /* Intersect the layout-valid span with this rank's owned range: the
128 * first exclusion removes solver-layout indices, the second removes
129 * PETSc halo storage. */
130 plan->start[dim] = PetscMax(owned_start[dim], layout_lo);
131 plan->end[dim] = PetscMin(owned_end[dim], layout_hi);
132 if (plan->end[dim] < plan->start[dim]) plan->end[dim] = plan->start[dim];
133 }
135 PetscFunctionReturn(0);
136}
FieldLayout layout
const char * canonical_name
PetscErrorCode FieldGetDescriptor(FieldId field_id, const FieldDescriptor **descriptor)
Return immutable metadata for a valid field identifier.
Immutable metadata for one field identity.
static void GetPeriodicAxes(const SimCtx *simCtx, PetscBool periodic[3])
Which grid axes are periodic.
Definition setup.h:361
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 PicurvLayoutDimensionIsNodeLike(FieldLayout layout, PetscInt dim, PetscBool *node_like)
Implementation of PicurvLayoutDimensionIsNodeLike().
PicurvTargetKind kind
Spatial mapping; always pointwise.
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.
SimCtx * simCtx
Back-pointer to the master simulation context.
Definition variables.h:1160
DMDALocalInfo info
Definition variables.h:1169
The master context for the entire simulation.
Definition variables.h:916
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SpatialTargetPlanLocalPointCount()

PetscErrorCode SpatialTargetPlanLocalPointCount ( const SpatialTargetPlan *  plan,
PetscInt *  count 
)

Counts the points this rank contributes.

Parameters
[in]planResolved plan.
[out]countLocal point count; zero for an empty domain.
Returns
Zero on success, or PETSC_ERR_ARG_NULL for a null argument.

Counts the points this rank contributes.

See also
SpatialTargetPlanLocalPointCount()

Definition at line 142 of file statistics_target.c.

143{
144 PetscInt total = 1;
145
146 PetscFunctionBeginUser;
148 PetscCheck(plan != NULL && count != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
149 "Plan and count output are required.");
150 for (PetscInt dim = 0; dim < 3; ++dim) {
151 const PetscInt extent = plan->end[dim] - plan->start[dim];
152 if (extent <= 0) { *count = 0; PROFILE_FUNCTION_END; PetscFunctionReturn(0); }
153 total *= extent;
154 }
155 *count = total;
157 PetscFunctionReturn(0);
158}
Here is the caller graph for this function:

◆ SpatialTargetPlanGlobalPointCount()

PetscErrorCode SpatialTargetPlanGlobalPointCount ( const SpatialTargetPlan *  plan,
MPI_Comm  comm,
PetscInt *  count 
)

Counts the points contributed across a communicator.

The result is decomposition independent: it depends only on the layout, global dimensions, and periodicity, never on how ranks divide the domain.

Parameters
[in]planResolved plan.
[in]commCommunicator to reduce over.
[out]countGlobal point count.
Returns
Zero on success, or PETSC_ERR_ARG_NULL for a null argument.

Counts the points contributed across a communicator.

See also
SpatialTargetPlanGlobalPointCount()

Definition at line 164 of file statistics_target.c.

165{
166 PetscInt local = 0;
167
168 PetscFunctionBeginUser;
170 PetscCheck(plan != NULL && count != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
171 "Plan and count output are required.");
172 PetscCall(SpatialTargetPlanLocalPointCount(plan, &local));
173 PetscCallMPI(MPI_Allreduce(&local, count, 1, MPIU_INT, MPI_SUM, comm));
175 PetscFunctionReturn(0);
176}
PetscErrorCode SpatialTargetPlanLocalPointCount(const SpatialTargetPlan *plan, PetscInt *count)
Implementation of SpatialTargetPlanLocalPointCount().
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SpatialTargetPlanMaskAllows()

PetscBool SpatialTargetPlanMaskAllows ( const SpatialTargetPlan *  plan,
PetscReal  nvert_value 
)

Reports whether a point passes the plan's mask.

Because Nvert changes when immersed bodies move, the mask is treated as potentially moving: callers accumulate a per-point valid count and weight rather than assuming a point contributes to every accepted state.

Parameters
[in]planResolved plan.
[in]nvert_valueNode-blanking value at the point.
Returns
PETSC_TRUE when the point is eligible.

Reports whether a point passes the plan's mask.

See also
SpatialTargetPlanMaskAllows()

Definition at line 182 of file statistics_target.c.

183{
184 if (plan == NULL) return PETSC_FALSE;
185 return (PetscBool)(nvert_value < PICURV_STATISTICS_FLUID_THRESHOLD);
186}
#define PICURV_STATISTICS_FLUID_THRESHOLD
Threshold below which a cell counts as fluid for the default mask.
Here is the caller graph for this function:

◆ PicurvSpatialRatioAverage()

PetscErrorCode PicurvSpatialRatioAverage ( UserCtx *  user,
const SpatialTargetPlan *  plan,
Vec  numerator,
Vec  denominator,
Vec  inclusion,
const PetscBool  average_direction[3],
MPI_Comm  comm,
Vec  ratio,
PetscReal *  reduced 
)

Averages two fields over a target domain and divides the results.

Computes ratio = <numerator> / <denominator>, where each average is taken separately over the points the plan admits, and then divides. The order matters: the mean of the pointwise quotients is a different number from the quotient of the means, and several callers need the second one. The LES dynamic procedure is one, because Lilly's least-squares closure is defined that way.

average_direction selects which logical directions collapse into the average. Selecting none makes the operation pointwise, which lets a caller express a local and an averaged formulation through one code path rather than two. Selecting all three yields one number for the whole domain. Selecting a subset retains a profile along the directions left out — averaging over xi and zeta on a plane channel, for example, leaves a wall-normal profile.

Weighting is the caller's, not this function's: scale numerator and denominator by whatever weight the average should carry before calling. A caller wanting a volume-weighted average multiplies both by the cell volume; a caller wanting each admitted point to count once passes them unscaled.

The reduction runs over comm, so a result is independent of how the domain is decomposed across ranks. The plan already excludes PETSc halo storage and the solver's boundary, dummy, and duplicate-periodic indices, so no physical point is counted twice.

Parameters
[in]userBlock context supplying the DMDA and the solid mask.
[in]planResolved iteration domain, from SpatialTargetPlanCreate().
[in]numeratorField to average in the numerator, ghosted local or global, on any DMDA sharing the block's layout. Its components are averaged independently against the one scalar denominator, so a vector or a symmetric tensor reduces in one call.
[in]denominatorGhosted local field to average in the denominator, or NULL to divide by the number of admitted points.
[in]inclusionOptional second mask: points where this field is not positive are skipped. Use it to exclude points that hold a zero meaning "never measured" rather than a measurement. NULL applies the plan's mask alone.
[in]average_directionDirections to average over, in (xi, eta, zeta) order.
[in]commCommunicator to reduce over.
[out]ratioField on the numerator's DM receiving the quotient at every admitted point, or NULL when only reduced is wanted. Zero wherever the averaged denominator underflows.
[out]reducedReceives the quotient of every retained slot, or NULL. The same on every rank of comm. Holds dof entries per slot, slot i + mx (j + my k) over the retained global indices with an averaged direction's index taken as zero and its extent as one: one value when every direction is averaged, a profile when some are not. Slots no admitted point reached hold zero.
Returns
Zero on success, PETSC_ERR_ARG_OUTOFRANGE when the retained directions would need an unreasonably large reduction buffer, or PETSC_ERR_ARG_WRONGSTATE when reduced is requested from a pointwise operation, which has no reduced form.

Averages two fields over a target domain and divides the results.

See also
PicurvSpatialRatioAverage()

Definition at line 207 of file statistics_target.c.

211{
212 DM da = NULL, numerator_dm = NULL;
213 DMDALocalInfo info;
214 PetscInt retained_extent[3];
215 PetscInt buffer_size = 1;
216 PetscInt averaged_count = 0;
217 PetscInt dof = 1;
218 PetscReal ***den = NULL, ***inc = NULL, ***nvert = NULL;
219 PetscScalar ****num = NULL, ****out = NULL;
220 PetscReal *num_sum = NULL, *den_sum = NULL;
221
222 PetscFunctionBeginUser;
224 PetscCheck(user != NULL && plan != NULL && numerator != NULL && average_direction != NULL,
225 PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
226 "Context, plan, numerator, and direction selector are required.");
227
228 da = user->da;
229 info = user->info;
230 /* The numerator's own DM supplies its component count; every component shares the
231 * scalar denominator, inclusion mask and solid mask. */
232 PetscCall(VecGetDM(numerator, &numerator_dm));
233 PetscCheck(numerator_dm != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG,
234 "The numerator must carry the DMDA it was created from.");
235 PetscCall(DMDAGetInfo(numerator_dm, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &dof,
236 NULL, NULL, NULL, NULL, NULL));
237
238 retained_extent[0] = average_direction[0] ? 1 : info.mx;
239 retained_extent[1] = average_direction[1] ? 1 : info.my;
240 retained_extent[2] = average_direction[2] ? 1 : info.mz;
241 for (PetscInt axis = 0; axis < 3; axis++) {
242 if (average_direction[axis]) averaged_count++;
243 buffer_size *= retained_extent[axis];
244 }
245 PetscCheck(reduced == NULL || averaged_count > 0, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE,
246 "Reduced values exist only when at least one direction is averaged over.");
247
248 PetscCall(DMDAVecGetArrayDOFRead(numerator_dm, numerator, &num));
249 if (denominator) PetscCall(DMDAVecGetArrayRead(da, denominator, &den));
250 if (inclusion) PetscCall(DMDAVecGetArrayRead(da, inclusion, &inc));
251 if (ratio) PetscCall(DMDAVecGetArrayDOF(numerator_dm, ratio, &out));
252 PetscCall(DMDAVecGetArrayRead(da, user->lNvert, &nvert));
253
254 if (averaged_count == 0) {
255 /* Pointwise: the empty averaging set, which is a legitimate request rather
256 * than a degenerate one. It is what a local formulation asks for. The masks
257 * mean the same thing here as they do for an averaged set - a point they
258 * exclude contributes nothing and receives nothing - so that a caller can
259 * switch between the two without its exclusions quietly changing meaning. */
260 for (PetscInt k = plan->start[2]; k < plan->end[2]; k++)
261 for (PetscInt j = plan->start[1]; j < plan->end[1]; j++)
262 for (PetscInt i = plan->start[0]; i < plan->end[0]; i++) {
263 const PetscReal divisor = denominator ? den[k][j][i] : 1.0;
264 const PetscBool admitted = (PetscBool)(SpatialTargetPlanMaskAllows(plan, nvert[k][j][i]) &&
265 !(inc && inc[k][j][i] <= 0.0));
266
267 for (PetscInt c = 0; c < dof; c++) {
268 out[k][j][i][c] = (admitted && PetscAbsReal(divisor) > 0.0)
269 ? (num[k][j][i][c] / divisor) : 0.0;
270 }
271 }
272 } else {
273 PetscCheck(buffer_size * dof <= PICURV_SPATIAL_AVERAGE_MAX_BUFFER, PETSC_COMM_SELF,
274 PETSC_ERR_ARG_OUTOFRANGE,
275 "Averaging over %" PetscInt_FMT " direction(s) would need a reduction buffer "
276 "of %" PetscInt_FMT " entries, above the %d entry limit. Average over more "
277 "directions.", averaged_count, buffer_size * dof, PICURV_SPATIAL_AVERAGE_MAX_BUFFER);
278
279 PetscCall(PetscCalloc2(buffer_size * dof, &num_sum, buffer_size, &den_sum));
280
281 for (PetscInt k = plan->start[2]; k < plan->end[2]; k++)
282 for (PetscInt j = plan->start[1]; j < plan->end[1]; j++)
283 for (PetscInt i = plan->start[0]; i < plan->end[0]; i++) {
284 PetscInt slot;
285
286 if (!SpatialTargetPlanMaskAllows(plan, nvert[k][j][i])) continue;
287 /* A point the caller marks unmeasured holds a zero that means absence, not
288 * a measurement; counting it would scale the answer toward zero. */
289 if (inc && inc[k][j][i] <= 0.0) continue;
290
291 slot = SpatialAverageSlot(average_direction, retained_extent, i, j, k);
292 for (PetscInt c = 0; c < dof; c++) num_sum[slot * dof + c] += num[k][j][i][c];
293 den_sum[slot] += denominator ? den[k][j][i] : 1.0;
294 }
295
296 PetscCallMPI(MPI_Allreduce(MPI_IN_PLACE, num_sum, (PetscMPIInt)(buffer_size * dof),
297 MPIU_REAL, MPI_SUM, comm));
298 PetscCallMPI(MPI_Allreduce(MPI_IN_PLACE, den_sum, (PetscMPIInt)buffer_size,
299 MPIU_REAL, MPI_SUM, comm));
300 for (PetscInt slot = 0; slot < buffer_size; slot++) {
301 for (PetscInt c = 0; c < dof; c++) {
302 num_sum[slot * dof + c] = (PetscAbsReal(den_sum[slot]) > 0.0)
303 ? (num_sum[slot * dof + c] / den_sum[slot]) : 0.0;
304 }
305 }
306
307 if (out) {
308 for (PetscInt k = plan->start[2]; k < plan->end[2]; k++)
309 for (PetscInt j = plan->start[1]; j < plan->end[1]; j++)
310 for (PetscInt i = plan->start[0]; i < plan->end[0]; i++) {
311 const PetscInt slot = SpatialAverageSlot(average_direction, retained_extent, i, j, k);
312
313 for (PetscInt c = 0; c < dof; c++) out[k][j][i][c] = num_sum[slot * dof + c];
314 }
315 }
316 if (reduced) PetscCall(PetscArraycpy(reduced, num_sum, buffer_size * dof));
317
318 PetscCall(PetscFree2(num_sum, den_sum));
319 }
320
321 PetscCall(DMDAVecRestoreArrayDOFRead(numerator_dm, numerator, &num));
322 if (denominator) PetscCall(DMDAVecRestoreArrayRead(da, denominator, &den));
323 if (inclusion) PetscCall(DMDAVecRestoreArrayRead(da, inclusion, &inc));
324 if (ratio) PetscCall(DMDAVecRestoreArrayDOF(numerator_dm, ratio, &out));
325 PetscCall(DMDAVecRestoreArrayRead(da, user->lNvert, &nvert));
326
328 PetscFunctionReturn(0);
329}
PetscBool SpatialTargetPlanMaskAllows(const SpatialTargetPlan *plan, PetscReal nvert_value)
Implementation of SpatialTargetPlanMaskAllows().
static PetscInt SpatialAverageSlot(const PetscBool average_direction[3], const PetscInt retained_extent[3], PetscInt i, PetscInt j, PetscInt k)
Flattens the retained global indices of one point into a reduction slot.
#define PICURV_SPATIAL_AVERAGE_MAX_BUFFER
Largest reduction buffer a directional average will allocate, in entries.
Vec lNvert
Definition variables.h:1197
Here is the call graph for this function:
Here is the caller graph for this function: