20 char tmpdir[PETSC_MAX_PATH_LEN];
21 char csv_prefix[PETSC_MAX_PATH_LEN];
22 char csv_path[PETSC_MAX_PATH_LEN];
26 PetscReal (*pos_arr)[3] = NULL;
28 PetscFunctionBeginUser;
39 PetscCall(PetscSNPrintf(csv_prefix,
sizeof(csv_prefix),
"%s/stats", tmpdir));
40 PetscCall(PetscSNPrintf(csv_path,
sizeof(csv_path),
"%s_msd.csv", csv_prefix));
42 PetscCall(DMSwarmGetField(user->
swarm,
"position", NULL, NULL, (
void *)&pos_arr));
49 PetscCall(DMSwarmRestoreField(user->
swarm,
"position", NULL, NULL, (
void *)&pos_arr));
54 file = fopen(csv_path,
"r");
55 PetscCheck(file != NULL, PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN,
"Failed to open generated stats CSV '%s'.", csv_path);
56 PetscCheck(fgets(header,
sizeof(header), file) != NULL, PETSC_COMM_SELF, PETSC_ERR_FILE_READ,
"CSV header is missing.");
57 PetscCheck(fgets(row,
sizeof(row), file) != NULL, PETSC_COMM_SELF, PETSC_ERR_FILE_READ,
"CSV data row is missing.");
61 "MSD CSV header should contain MSD_total"));
63 "MSD CSV row should include the particle count"));
66 PetscFunctionReturn(0);
76 char tmpdir[PETSC_MAX_PATH_LEN];
77 char csv_prefix[PETSC_MAX_PATH_LEN];
78 char csv_path[PETSC_MAX_PATH_LEN];
79 PetscBool exists = PETSC_FALSE;
81 PetscFunctionBeginUser;
86 PetscCall(PetscSNPrintf(csv_prefix,
sizeof(csv_prefix),
"%s/stats", tmpdir));
87 PetscCall(PetscSNPrintf(csv_path,
sizeof(csv_path),
"%s_msd.csv", csv_prefix));
90 PetscCall(
VerifyPathExistence(csv_path, PETSC_FALSE, PETSC_TRUE,
"MSD CSV for empty swarm", &exists));
92 "ComputeParticleMSD should not write output when no particles are present"));
95 PetscFunctionReturn(0);
109 ierr = PetscInitialize(&argc, &argv, NULL,
"PICurv statistics tests");
114 ierr =
PicurvRunTests(
"unit-post-statistics", cases,
sizeof(cases) /
sizeof(cases[0]));
120 ierr = PetscFinalize();
PetscErrorCode VerifyPathExistence(const char *path, PetscBool is_dir, PetscBool is_optional, const char *description, PetscBool *exists)
A parallel-safe helper to verify the existence of a generic file or directory path.
Global statistics kernels for the Statistics Pipeline.
PetscErrorCode ComputeParticleMSD(UserCtx *user, const char *stats_prefix, PetscInt ti)
Computes the mean-squared displacement (MSD) of a particle cloud.
int main(int argc, char **argv)
Entry point for this unit-test binary.
static PetscErrorCode TestComputeParticleMSDEmptySwarmNoOutput(void)
Test-local routine.
static PetscErrorCode TestComputeParticleMSDWritesCSV(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 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 PicurvAssertBool(PetscBool value, const char *context)
Shared test-support routine.
C test module for PICurv.
Named test case descriptor consumed by PicurvRunTests.
PetscReal psrc_z
Point source location for PARTICLE_INIT_POINT_SOURCE.
The master context for the entire simulation.
User-defined context containing data specific to a single computational grid level.