PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
 
Loading...
Searching...
No Matches
postprocessing_kernels.h
Go to the documentation of this file.
1#ifndef POSTPROCESSING_KERNELS_H
2#define POSTPROCESSING_KERNELS_H
3
4#include "variables.h"
5#include "logging.h"
6#include "io.h" // For the UpdateLocalGhosts function prototype
7
8// Function prototypes for post-processing kernels
9
10/**
11 * @brief Interpolates a cell-centered field to nodal locations using local stencil averaging.
12 *
13 * The kernel reads the input field by name, computes nodal values, and stores the
14 * output in the named destination field. Both fields must already exist in the
15 * current `UserCtx`.
16 *
17 * @param[in,out] user Block-level context that owns the source and destination vectors.
18 * @param[in] in_field_name Name of the input field to sample.
19 * @param[in] out_field_name Name of the output field to populate.
20 * @return PetscErrorCode 0 on success.
21 */
22PetscErrorCode ComputeNodalAverage(UserCtx* user, const char* in_field_name, const char* out_field_name);
23
24/**
25 * @brief Computes the Q-criterion diagnostic from the local velocity-gradient tensor.
26 *
27 * This kernel evaluates rotational versus strain-rate dominance and writes the
28 * result into the configured Q-criterion output vector for visualization and flow
29 * feature identification.
30 *
31 * @param[in,out] user Block-level context containing velocity fields and target output storage.
32 * @return PetscErrorCode 0 on success.
33 */
34PetscErrorCode ComputeQCriterion(UserCtx* user);
35
36/**
37 * @brief Normalizes pressure using the value at the configured logical grid point.
38 *
39 * The owning rank reads the reference value, shares it collectively, and every
40 * rank subtracts it in-place from its distributed portion of the field.
41 *
42 * @param[in,out] user Block-level context containing pressure and reference configuration.
43 * @param[in] relative_field_name Name of the field to normalize.
44 * @return PetscErrorCode 0 on success.
45 */
46PetscErrorCode NormalizeRelativeField(UserCtx* user, const char* relative_field_name);
47
48// Add more post-processing kernel prototypes as needed
49// =========================================================================
50// Dimensionalization Kernels
51// =========================================================================
52/**
53 * @brief Scales a specified field from non-dimensional to dimensional units in-place.
54 *
55 * Resolves the name in the Eulerian field catalog, then the particle field catalog,
56 * and scales the field's storage (its global Vec, the DM coordinates, or its DMSwarm
57 * field) by the reference scale of the dimension recorded on its catalog entry.
58 *
59 * @param[in,out] user The UserCtx whose storage is modified.
60 * @param[in] field_name Case-insensitive catalogued name or alias, e.g. "Ucat",
61 * "Nu_t", "Coordinates", "ParticlePosition".
62 * @return Zero on success; `PETSC_ERR_ARG_UNKNOWN_TYPE` for a name in neither catalog,
63 * and `PETSC_ERR_ARG_WRONGSTATE` for a field without a fixed dimension or without
64 * storage in this run.
65 */
66PetscErrorCode DimensionalizeField(UserCtx *user, const char *field_name);
67
68// ===========================================================================
69// Particle Post-Processing Kernels
70// ===========================================================================
71
72
73/**
74 * @brief Computes the specific kinetic energy (KE per unit mass) for each particle.
75 *
76 * This kernel calculates SKE = 0.5 * |velocity|^2. It requires that the
77 * velocity field exists and will populate the specific kinetic energy field.
78 * The output field must be registered before this kernel is called.
79 *
80 * @param user The UserCtx containing the DMSwarm.
81 * @param velocity_field The name of the input vector field for particle velocity.
82 * @param ske_field The name of the output scalar field to store specific KE.
83 * @return PetscErrorCode
84 */
85PetscErrorCode ComputeSpecificKE(UserCtx* user, const char* velocity_field, const char* ske_field);
86
87/**
88 * @brief Computes the displacement magnitude |r_i - r_0| for each particle (per-particle VTK kernel).
89 *
90 * Reference point r_0 = (simCtx->psrc_x, psrc_y, psrc_z). Writes the scalar displacement to
91 * post_swarm[disp_field]. This is a visualisation kernel only — use ComputeParticleMSD from
92 * particle_statistics.h for quantitative global statistics.
93 *
94 * @param user The UserCtx containing the DMSwarms.
95 * @param disp_field Name of the output scalar field in post_swarm.
96 * @return PetscErrorCode
97 */
98PetscErrorCode ComputeDisplacement(UserCtx *user, const char *disp_field);
99
100/**
101 * @brief Derives one accumulated statistic and converts it to nodal values.
102 *
103 * The counterpart of ComputeNodalAverage() for accumulated window state: it takes an
104 * index into a window's requested output set, normalizes the centered state behind
105 * it, and leaves the result in the shared post-processing staging field ready for
106 * output. The staging vectors are reused between calls, so a caller must consume the
107 * result before requesting the next one.
108 *
109 * With `global_operations.dimensionalize` set, the result carries physical units: the
110 * source field's reference scale raised to the power the derived kind carries: a mean
111 * and an RMS are linear in it, a Reynolds stress and a turbulent kinetic energy
112 * quadratic. A co-moment flux relates two possibly different fields, so its factor is
113 * the product of their scales rather than one squared. That is what the per-field
114 * scaling table alone cannot express, and why one blanket velocity factor would have
115 * been wrong for three of the five kinds.
116 *
117 * @param[in] user Block context holding the accumulators and staging fields.
118 * @param[in] window_index Window whose state is derived.
119 * @param[in] outputs Comma-separated output kinds the recipe requested.
120 * @param[in] output_index Index into that output set.
121 * @param[out] out_name Name of the derived field, window qualified.
122 * @param[in] name_size Capacity of @p out_name.
123 * @param[out] out_vec Nodal vector holding the result; borrowed, not owned.
124 * @param[out] out_components Component count of the result.
125 * @return Zero on success, or a PETSc error.
126 */
127PetscErrorCode ComputeWindowStatisticNodal(UserCtx *user, PetscInt window_index,
128 const char *outputs, PetscInt output_index,
129 char *out_name, size_t name_size,
130 Vec *out_vec, PetscInt *out_components);
131
132/**
133 * @brief Appends one convergence row for an accumulated window to its CSV history.
134 *
135 * The counterpart of ComputeParticleMSD() for Eulerian window state: it reduces the
136 * window to the few numbers that answer whether it has run long enough — sample
137 * count, total weight, represented time, the per-point valid-fraction range, and the
138 * mean turbulent kinetic energy — and appends them as one row per processed step.
139 * No single field snapshot can answer that question, which is why the history exists
140 * beside the field output rather than instead of it.
141 *
142 * The mean is taken over the fluid cells the window actually sampled. Cells outside
143 * the target domain, and cells a moving mask excluded, hold zeros that mean "never
144 * measured"; averaging over them would scale the result down by the fraction of the
145 * grid the window never covered.
146 *
147 * @param[in] user Block context holding the accumulators and staging fields.
148 * @param[in] window_index Window to summarize.
149 * @param[in] output_prefix Output path prefix; the window name and `.csv` are appended.
150 * @param[in] ti Step being processed, recorded as the row's key.
151 * @return Zero on success, or a PETSc error.
152 */
153PetscErrorCode ComputeWindowStatisticsSummary(UserCtx *user, PetscInt window_index,
154 const char *output_prefix, PetscInt ti);
155
156#endif // POSTPROCESSING_KERNELS_H
Public interface for data input/output routines.
Logging utilities and macros for PETSc-based applications.
PetscErrorCode ComputeQCriterion(UserCtx *user)
Computes the Q-criterion diagnostic from the local velocity-gradient tensor.
PetscErrorCode ComputeSpecificKE(UserCtx *user, const char *velocity_field, const char *ske_field)
Computes the specific kinetic energy (KE per unit mass) for each particle.
PetscErrorCode ComputeDisplacement(UserCtx *user, const char *disp_field)
Computes the displacement magnitude |r_i - r_0| for each particle (per-particle VTK kernel).
PetscErrorCode NormalizeRelativeField(UserCtx *user, const char *relative_field_name)
Normalizes pressure using the value at the configured logical grid point.
PetscErrorCode ComputeWindowStatisticsSummary(UserCtx *user, PetscInt window_index, const char *output_prefix, PetscInt ti)
Appends one convergence row for an accumulated window to its CSV history.
PetscErrorCode DimensionalizeField(UserCtx *user, const char *field_name)
Scales a specified field from non-dimensional to dimensional units in-place.
PetscErrorCode ComputeNodalAverage(UserCtx *user, const char *in_field_name, const char *out_field_name)
Interpolates a cell-centered field to nodal locations using local stencil averaging.
PetscErrorCode ComputeWindowStatisticNodal(UserCtx *user, PetscInt window_index, const char *outputs, PetscInt output_index, char *out_name, size_t name_size, Vec *out_vec, PetscInt *out_components)
Derives one accumulated statistic and converts it to nodal values.
Main header file for a complex fluid dynamics solver.
User-defined context containing data specific to a single computational grid level.
Definition variables.h:1074