PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
 
Loading...
Searching...
No Matches
postprocessor.h
Go to the documentation of this file.
1#ifndef POSTPROCESSOR_H
2#define POSTPROCESSOR_H
3
4#include "io.h"
5#include "variables.h"
6#include "logging.h"
7#include "ParticleSwarm.h"
8#include "interpolation.h"
9#include "grid.h"
10#include "setup.h"
11#include "Metric.h"
13#include "vtk_io.h"
14#include "particle_statistics.h"
15#include "ParticleMotion.h"
16/* --------------------------------------------------------------------
17 postprocessor.h
18
19 This header declares the interface for the post-processing executable
20 or library. Typically, you'd have a function that runs your main
21 post-processing routine, or you might declare other helper functions.
22
23 Here, we declare a single function: PostprocessMain,
24 which could be your main entry point if you want to call it from
25 another place (or you might just put main() in postprocess.c).
26
27*/
28
29/**
30 * @brief Creates a new, dedicated DMSwarm for post-processing tasks.
31 *
32 * This function is called once at startup. It creates an empty DMSwarm and
33 * associates it with the same grid DM as the primary swarm and registers all the required fields.
34 * @param user The UserCtx where user->post_swarm will be created.
35 * @param pps The PostProcessParams containing the particle_pipeline string for field registration.
36 * @return PetscErrorCode
37 */
38PetscErrorCode SetupPostProcessSwarm(UserCtx* user, PostProcessParams* pps);
39
40/**
41 * @brief Orchestrates the writing of a combined, multi-field VTK file for a single time step.
42 *
43 * This function is the primary driver for generating output. It performs these steps:
44 * 1. Prepares the subsampled coordinate array required for the legacy grid format.
45 * 2. Parses the user-requested list of fields from the configuration.
46 * 3. For each field, prepares a corresponding subsampled data array.
47 * 4. Assembles all prepared arrays into a single VTKMetaData struct.
48 * 5. Calls the low-level VTK writer to generate the final .vts file.
49 * 6. Frees all temporary memory allocated during the preparation phase.
50 *
51 * @param user The UserCtx for the finest grid level.
52 * @param pps The post-processing configuration struct.
53 * @param ti The current time step index.
54 * @return PetscErrorCode
55 */
56PetscErrorCode WriteEulerianFile(UserCtx* user, PostProcessParams* pps, PetscInt ti);
57
58/**
59 * @brief Parses the processing pipeline string and executes the requested kernels.
60 * @param user The UserCtx containing the data to be transformed.
61 * @param pps The PostProcessParams containing the pipeline string.
62 * @return PetscErrorCode
63 */
65
66
67/**
68 * @brief Parses and executes the particle pipeline using a robust two-pass approach.
69 *
70 * This function ensures correctness and efficiency by separating field registration
71 * from kernel execution.
72 *
73 * PASS 1 (Registration): The pipeline string is parsed to identify all new fields
74 * that will be created. These fields are registered with the DMSwarm.
75 *
76 * Finalize: After Pass 1, DMSwarmFinalizeFieldRegister is called exactly once if
77 * any new fields were added, preparing the swarm's memory layout.
78 *
79 * PASS 2 (Execution): The pipeline string is parsed again, and this time the
80 * actual compute kernels are executed, filling the now-valid fields.
81 *
82 * @param user The UserCtx containing the DMSwarm.
83 * @param pps The PostProcessParams struct containing the particle_pipeline string.
84 * @return PetscErrorCode
85 */
87
88/**
89 * @brief Writes particle data to a VTP file using the Prepare-Write-Cleanup pattern.
90 *
91 * @param user Primary `UserCtx` input for the operation.
92 * @param pps Post-processing configuration for the operation.
93 * @param ti Source timestep written into the VTP filename and metadata.
94 * @return PetscErrorCode 0 on success.
95 */
96PetscErrorCode WriteParticleFile(UserCtx* user, PostProcessParams* pps, PetscInt ti);
97
98/**
99 * @brief Executes the global statistics pipeline, computing aggregate reductions over all particles.
100 *
101 * Parses the semicolon-delimited `pps->statistics_pipeline` string and dispatches to the
102 * appropriate kernel (e.g. ComputeParticleMSD). Each kernel appends one row to its own CSV
103 * file and logs a summary via LOG_INFO. All MPI reductions happen inside each kernel.
104 * This pipeline is independent of the per-particle VTK pipeline; it produces no .vtp output.
105 *
106 * @param user The UserCtx containing the primary DMSwarm (user->swarm).
107 * @param pps The PostProcessParams containing statistics_pipeline and statistics_output_prefix.
108 * @param ti Current time-step index (passed through to kernels for time computation).
109 * @return PetscErrorCode
110 */
111PetscErrorCode GlobalStatisticsPipeline(UserCtx *user, PostProcessParams *pps, PetscInt ti);
112
113/**
114 * @brief Resolve the ordered steps one post-processing run processes.
115 * @details A step list file, written by the conductor when a job starts, names exactly
116 * the steps whose output is missing or stale; without one the time controls
117 * define an evenly spaced window. Rank 0 reads the file and broadcasts it, so
118 * every rank iterates the same steps.
119 * @param[in] pps Post-processing settings holding the time controls and list file.
120 * @param[out] steps Newly allocated array of steps; the caller frees it with PetscFree().
121 * @param[out] count Number of entries in `steps`.
122 * @return PetscErrorCode 0 on success; an error when the list file cannot be read.
123 */
124PetscErrorCode ResolvePostProcessingSteps(PostProcessParams *pps, PetscInt **steps, PetscInt *count);
125
126/**
127 * @brief Derives and writes field statistics for the windows a recipe requests.
128 *
129 * Runs once per processed step, beside the particle statistics pipeline, because a
130 * window's accumulated state is a property of the bundle at that step. A recipe
131 * spanning several steps therefore produces a convergence history rather than the
132 * same picture repeated; pinning `field_statistics_source_step` collapses it back to
133 * a single bundle.
134 *
135 * Each window is written to its own file. The VTK point-data cap is per file, and one
136 * window carrying every output already fills most of it.
137 *
138 * Does nothing when no window is requested. A window the run does not configure is
139 * fatal; a window that has not yet accumulated a sample is skipped with a note, since
140 * a recipe covering a whole run legitimately reaches bundles from before it began.
141 *
142 * @param[in] user Finest-level block context holding accumulators and staging fields.
143 * @param[in] pps Post-processing recipe naming the windows, outputs, and formats.
144 * @param[in] ti Step being processed; names the output and selects the bundle.
145 * @return Zero on success, or a PETSc error.
146 */
147PetscErrorCode FieldStatisticsPipeline(UserCtx *user, PostProcessParams *pps, PetscInt ti);
148
149#endif /* POSTPROCESSOR_H */
Header file for Particle Motion and migration related functions.
Header file for Particle Swarm management functions.
Public interface for grid, solver, and metric setup routines.
Public interface for data input/output routines.
Logging utilities and macros for PETSc-based applications.
Global statistics kernels for the Statistics Pipeline.
PetscErrorCode EulerianDataProcessingPipeline(UserCtx *user, PostProcessParams *pps)
Parses the processing pipeline string and executes the requested kernels.
PetscErrorCode WriteEulerianFile(UserCtx *user, PostProcessParams *pps, PetscInt ti)
Orchestrates the writing of a combined, multi-field VTK file for a single time step.
PetscErrorCode GlobalStatisticsPipeline(UserCtx *user, PostProcessParams *pps, PetscInt ti)
Executes the global statistics pipeline, computing aggregate reductions over all particles.
PetscErrorCode ResolvePostProcessingSteps(PostProcessParams *pps, PetscInt **steps, PetscInt *count)
Resolve the ordered steps one post-processing run processes.
PetscErrorCode ParticleDataProcessingPipeline(UserCtx *user, PostProcessParams *pps)
Parses and executes the particle pipeline using a robust two-pass approach.
PetscErrorCode WriteParticleFile(UserCtx *user, PostProcessParams *pps, PetscInt ti)
Writes particle data to a VTP file using the Prepare-Write-Cleanup pattern.
PetscErrorCode FieldStatisticsPipeline(UserCtx *user, PostProcessParams *pps, PetscInt ti)
Derives and writes field statistics for the windows a recipe requests.
PetscErrorCode SetupPostProcessSwarm(UserCtx *user, PostProcessParams *pps)
Creates a new, dedicated DMSwarm for post-processing tasks.
Main header file for a complex fluid dynamics solver.
Holds all configuration parameters for a post-processing run.
Definition variables.h:793
User-defined context containing data specific to a single computational grid level.
Definition variables.h:1157