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 a relative scalar field using the configured reference pressure scale.
38 *
39 * This is primarily used for pressure-normalized outputs in post-processing.
40 * The operation is in-place on the selected field.
41 *
42 * @param[in,out] user Block-level context containing scaling information.
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 * This function acts as a dispatcher. It takes the string name of a field,
56 * identifies the corresponding PETSc Vec object and the correct physical
57 * scaling factor (e.g., U_ref for velocity, P_ref for pressure), and then
58 * performs an in-place VecScale operation. It correctly handles the different
59 * physical dimensions of Cartesian velocity vs. contravariant volume flux.
60 *
61 * @param[in,out] user The UserCtx containing the PETSc Vecs to be modified.
62 * @param[in] field_name The case-insensitive string name of the field to dimensionalize
63 * (e.g., "Ucat", "P", "Ucont", "Coordinates", "ParticlePosition", "ParticleVelocity").
64 * @return PetscErrorCode
65 */
66PetscErrorCode DimensionalizeField(UserCtx *user, const char *field_name);
67
68/**
69 * @brief Orchestrates the dimensionalization of all relevant fields loaded from a file.
70 *
71 * This function is intended to be called in the post-processor immediately after
72 * all solver output has been read into memory. It calls DimensionalizeField() for each of the core
73 * physical quantities to convert the entire loaded state from non-dimensional to
74 * dimensional units, preparing it for analysis and visualization.
75 *
76 * @param[in,out] user The UserCtx containing all the fields to be dimensionalized.
77 * @return PetscErrorCode
78 */
79PetscErrorCode DimensionalizeAllLoadedFields(UserCtx *user);
80
81// ===========================================================================
82// Particle Post-Processing Kernels
83// ===========================================================================
84
85
86/**
87 * @brief Computes the specific kinetic energy (KE per unit mass) for each particle.
88 *
89 * This kernel calculates SKE = 0.5 * |velocity|^2. It requires that the
90 * velocity field exists and will populate the specific kinetic energy field.
91 * The output field must be registered before this kernel is called.
92 *
93 * @param user The UserCtx containing the DMSwarm.
94 * @param velocity_field The name of the input vector field for particle velocity.
95 * @param ske_field The name of the output scalar field to store specific KE.
96 * @return PetscErrorCode
97 */
98PetscErrorCode ComputeSpecificKE(UserCtx* user, const char* velocity_field, const char* ske_field);
99
100/**
101 * @brief Computes the displacement magnitude |r_i - r_0| for each particle (per-particle VTK kernel).
102 *
103 * Reference point r_0 = (simCtx->psrc_x, psrc_y, psrc_z). Writes the scalar displacement to
104 * post_swarm[disp_field]. This is a visualisation kernel only — use ComputeParticleMSD from
105 * particle_statistics.h for quantitative global statistics.
106 *
107 * @param user The UserCtx containing the DMSwarms.
108 * @param disp_field Name of the output scalar field in post_swarm.
109 * @return PetscErrorCode
110 */
111PetscErrorCode ComputeDisplacement(UserCtx *user, const char *disp_field);
112
113#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 a relative scalar field using the configured reference pressure scale.
PetscErrorCode DimensionalizeField(UserCtx *user, const char *field_name)
Scales a specified field from non-dimensional to dimensional units in-place.
PetscErrorCode DimensionalizeAllLoadedFields(UserCtx *user)
Orchestrates the dimensionalization of all relevant fields loaded from a file.
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.
Main header file for a complex fluid dynamics solver.
User-defined context containing data specific to a single computational grid level.
Definition variables.h:811