22 void *field_ptr = NULL;
24 PetscFunctionBeginUser;
25 PetscCall(PetscMemzero(&pps,
sizeof(pps)));
31 "SetupPostProcessSwarm should allocate a dedicated post swarm"));
33 PetscCall(DMSwarmSetLocalSizes(user->
post_swarm, 0, 0));
34 PetscCall(DMSwarmGetField(user->
post_swarm,
"ske", &bs, NULL, &field_ptr));
35 PetscCall(
PicurvAssertIntEqual(1, bs,
"SetupPostProcessSwarm should register scalar output field 'ske'"));
36 PetscCall(DMSwarmRestoreField(user->
post_swarm,
"ske", &bs, NULL, &field_ptr));
39 PetscFunctionReturn(0);
50 const PetscScalar ***p_nodal_arr = NULL;
52 PetscFunctionBeginUser;
53 PetscCall(PetscMemzero(&pps,
sizeof(pps)));
57 PetscCall(VecSet(user->
P, 9.0));
58 PetscCall(VecSet(user->
P_nodal, -1.0));
61 PetscCall(DMDAVecGetArrayRead(user->
da, user->
P_nodal, (
void *)&p_nodal_arr));
63 "Eulerian pipeline should execute CellToNodeAverage for P->P_nodal"));
65 "Eulerian pipeline should leave non-computed boundary nodes unchanged"));
66 PetscCall(DMDAVecRestoreArrayRead(user->
da, user->
P_nodal, (
void *)&p_nodal_arr));
69 PetscFunctionReturn(0);
80 PetscReal (*vel_arr)[3] = NULL;
81 PetscScalar *ske_arr = NULL;
83 PetscFunctionBeginUser;
84 PetscCall(PetscMemzero(&pps,
sizeof(pps)));
89 PetscCall(DMSwarmGetField(user->
swarm,
"velocity", NULL, NULL, (
void *)&vel_arr));
96 PetscCall(DMSwarmRestoreField(user->
swarm,
"velocity", NULL, NULL, (
void *)&vel_arr));
99 PetscCall(DMSwarmGetField(user->
post_swarm,
"ske", NULL, NULL, (
void *)&ske_arr));
101 "Particle pipeline should write first specific kinetic energy value"));
103 "Particle pipeline should write second specific kinetic energy value"));
104 PetscCall(DMSwarmRestoreField(user->
post_swarm,
"ske", NULL, NULL, (
void *)&ske_arr));
107 PetscFunctionReturn(0);
118 char tmpdir[PETSC_MAX_PATH_LEN];
119 char csv_prefix[PETSC_MAX_PATH_LEN];
120 char csv_path[PETSC_MAX_PATH_LEN];
121 PetscReal (*pos_arr)[3] = NULL;
123 PetscFunctionBeginUser;
124 PetscCall(PetscMemzero(&pps,
sizeof(pps)));
136 PetscCall(PetscSNPrintf(csv_prefix,
sizeof(csv_prefix),
"%s/stats", tmpdir));
137 PetscCall(PetscSNPrintf(csv_path,
sizeof(csv_path),
"%s_msd.csv", csv_prefix));
142 PetscCall(DMSwarmGetField(user->
swarm,
"position", NULL, NULL, (
void *)&pos_arr));
146 pos_arr[1][0] = -1.0;
149 PetscCall(DMSwarmRestoreField(user->
swarm,
"position", NULL, NULL, (
void *)&pos_arr));
152 PetscCall(
PicurvAssertFileExists(csv_path,
"GlobalStatisticsPipeline should dispatch ComputeMSD and emit CSV output"));
155 PetscFunctionReturn(0);
166 char tmpdir[PETSC_MAX_PATH_LEN];
167 char vtk_path[PETSC_MAX_PATH_LEN];
169 PetscFunctionBeginUser;
170 PetscCall(PetscMemzero(&pps,
sizeof(pps)));
173 PetscCall(PetscSNPrintf(vtk_path,
sizeof(vtk_path),
"%s/field_00003.vts", tmpdir));
177 PetscCall(VecSet(user->
P_nodal, 7.0));
180 PetscCall(
PicurvAssertFileExists(vtk_path,
"WriteEulerianFile should emit a .vts file for requested output fields"));
183 PetscFunctionReturn(0);
194 char tmpdir[PETSC_MAX_PATH_LEN];
195 char vtk_path[PETSC_MAX_PATH_LEN];
196 PetscReal (*pos_arr)[3] = NULL;
197 PetscReal (*vel_arr)[3] = NULL;
199 PetscFunctionBeginUser;
200 PetscCall(PetscMemzero(&pps,
sizeof(pps)));
204 PetscCall(PetscSNPrintf(vtk_path,
sizeof(vtk_path),
"%s/particles_00004.vtp", tmpdir));
211 PetscCall(DMSwarmGetField(user->
swarm,
"position", NULL, NULL, (
void *)&pos_arr));
212 PetscCall(DMSwarmGetField(user->
swarm,
"velocity", NULL, NULL, (
void *)&vel_arr));
213 for (PetscInt p = 0; p < 3; ++p) {
214 pos_arr[p][0] = (PetscReal)p;
215 pos_arr[p][1] = (PetscReal)(p + 1);
216 pos_arr[p][2] = (PetscReal)(p + 2);
217 vel_arr[p][0] = 2.0 * (PetscReal)p;
218 vel_arr[p][1] = 3.0 * (PetscReal)p;
219 vel_arr[p][2] = 4.0 * (PetscReal)p;
221 PetscCall(DMSwarmRestoreField(user->
swarm,
"position", NULL, NULL, (
void *)&pos_arr));
222 PetscCall(DMSwarmRestoreField(user->
swarm,
"velocity", NULL, NULL, (
void *)&vel_arr));
225 PetscCall(
PicurvAssertFileExists(vtk_path,
"WriteParticleFile should emit a .vtp file for requested particle fields"));
228 PetscFunctionReturn(0);
246 ierr = PetscInitialize(&argc, &argv, NULL,
"PICurv postprocessor tests");
251 ierr =
PicurvRunTests(
"unit-postprocessor", cases,
sizeof(cases) /
sizeof(cases[0]));
257 ierr = PetscFinalize();
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 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 SetupPostProcessSwarm(UserCtx *user, PostProcessParams *pps)
Creates a new, dedicated DMSwarm for post-processing tasks.
static PetscErrorCode TestWriteParticleFileWritesVTP(void)
Test-local routine.
int main(int argc, char **argv)
Entry point for this unit-test binary.
static PetscErrorCode TestParticleDataProcessingPipelineComputesSpecificKE(void)
Test-local routine.
static PetscErrorCode TestGlobalStatisticsPipelineWritesMSDCSV(void)
Test-local routine.
static PetscErrorCode TestWriteEulerianFileWritesVTS(void)
Test-local routine.
static PetscErrorCode TestEulerianDataProcessingPipelineRunsConfiguredKernels(void)
Test-local routine.
static PetscErrorCode TestSetupPostProcessSwarmRegistersPipelineFields(void)
Test-local routine.
PetscErrorCode PicurvMakeTempDir(char *path, size_t path_len)
Shared test-support routine.
PetscErrorCode PicurvCreateMinimalContexts(SimCtx **simCtx_out, UserCtx **user_out, PetscInt mx, PetscInt my, PetscInt mz)
Shared test-support routine.
PetscErrorCode PicurvAssertRealNear(PetscReal expected, PetscReal actual, PetscReal tol, const char *context)
Shared test-support routine.
PetscErrorCode PicurvDestroyMinimalContexts(SimCtx **simCtx_ptr, UserCtx **user_ptr)
Shared test-support routine.
PetscErrorCode PicurvCreateSwarmPair(UserCtx *user, PetscInt nlocal, const char *post_field_name)
Shared test-support routine.
PetscErrorCode PicurvRunTests(const char *suite_name, const PicurvTestCase *cases, size_t case_count)
Shared test-support routine.
PetscErrorCode PicurvAssertFileExists(const char *path, const char *context)
Shared test-support routine.
PetscErrorCode PicurvAssertIntEqual(PetscInt expected, PetscInt actual, const char *context)
Shared test-support routine.
PetscErrorCode PicurvAssertBool(PetscBool value, const char *context)
Shared test-support routine.
C test module for PICurv.
Named test case descriptor consumed by PicurvRunTests.
char statistics_output_prefix[256]
basename for CSV output, e.g.
char particle_output_prefix[256]
char statistics_pipeline[1024]
e.g.
PetscReal psrc_z
Point source location for PARTICLE_INIT_POINT_SOURCE.
char output_fields_instantaneous[1024]
char particle_pipeline[1024]
char process_pipeline[1024]
PetscInt particle_output_freq
char particle_fields[1024]
PetscBool outputParticles
Holds all configuration parameters for a post-processing run.
The master context for the entire simulation.
User-defined context containing data specific to a single computational grid level.