27 PetscFunctionBeginUser;
28 PetscCall(PetscMemzero(&simCtx,
sizeof(simCtx)));
34 PetscFunctionReturn(0);
42 char tmpdir[PETSC_MAX_PATH_LEN];
43 char filepath[PETSC_MAX_PATH_LEN];
45 PetscBool exists = PETSC_FALSE;
47 PetscFunctionBeginUser;
49 PetscCall(PetscSNPrintf(filepath,
sizeof(filepath),
"%s/sample.txt", tmpdir));
51 file = fopen(filepath,
"w");
52 PetscCheck(file != NULL, PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN,
"Failed to create temp file '%s'.", filepath);
53 fputs(
"picurv\n", file);
57 PetscCall(
PicurvAssertBool(exists,
"VerifyPathExistence should find the temp directory"));
60 PetscCall(
PicurvAssertBool(exists,
"VerifyPathExistence should find the temp file"));
62 PetscFunctionReturn(0);
73 char tmpdir[PETSC_MAX_PATH_LEN];
74 char path[PETSC_MAX_PATH_LEN];
75 PetscBool exists = PETSC_FALSE;
76 const char *skipped[] = {
"initial",
"branch_start",
"final"};
78 PetscFunctionBeginUser;
82 PetscCallMPI(MPI_Bcast(tmpdir,
sizeof(tmpdir), MPI_CHAR, 0, PETSC_COMM_WORLD));
89 for (
size_t r = 0; r <
sizeof(skipped) /
sizeof(skipped[0]); ++r) {
92 PetscCall(PetscSNPrintf(path,
sizeof(path),
"%s/checkpoints/step_000000000001/COMMITTED", tmpdir));
93 PetscCall(PetscTestFile(path,
'r', &exists));
94 PetscCall(
PicurvAssertBool((PetscBool)!exists,
"turned-off boundary checkpoints write no bundle"));
97 PetscCall(PetscTestFile(path,
'r', &exists));
98 PetscCall(
PicurvAssertBool(exists,
"a cadence checkpoint is written regardless"));
102 PetscFunctionReturn(0);
113 char tmpdir[PETSC_MAX_PATH_LEN];
114 char path[PETSC_MAX_PATH_LEN];
115 PetscBool exists = PETSC_FALSE;
117 PetscFunctionBeginUser;
121 PetscCallMPI(MPI_Bcast(tmpdir,
sizeof(tmpdir), MPI_CHAR, 0, PETSC_COMM_WORLD));
125 PetscCall(VecSet(user->
P, 4.5));
126 PetscCall(VecSet(user->
Nvert, 0.0));
127 PetscCall(VecSet(user->
Ucat, 2.0));
128 PetscCall(VecSet(user->
Ucont, 3.0));
129 PetscCall(VecSet(user->
Ucont_rm1, 1.25));
133 PetscCall(PetscOptionsSetValue(NULL,
"-viewer_binary_mpiio", write_mpiio ?
"true" :
"false"));
135 PetscCall(PetscOptionsSetValue(NULL,
"-viewer_binary_mpiio", read_mpiio ?
"true" :
"false"));
136 PetscCall(PetscSNPrintf(path,
sizeof(path),
137 "%s/checkpoints/step_000000000001/checkpoint.meta", tmpdir));
138 PetscCall(PetscTestFile(path,
'r', &exists));
139 PetscCall(
PicurvAssertBool(exists,
"checkpoint coordinator should write checkpoint.meta"));
140 PetscCall(PetscSNPrintf(path,
sizeof(path),
141 "%s/checkpoints/step_000000000001/COMMITTED", tmpdir));
142 PetscCall(PetscTestFile(path,
'r', &exists));
143 PetscCall(
PicurvAssertBool(exists,
"checkpoint coordinator should write COMMITTED last"));
144 PetscCall(PetscSNPrintf(path,
sizeof(path),
145 "%s/checkpoints/step_000000000001/eulerian/block_0000/Ucat.dat", tmpdir));
146 PetscCall(PetscTestFile(path,
'r', &exists));
147 PetscCall(
PicurvAssertBool(exists,
"checkpoint should use catalogued canonical field names"));
148 PetscCall(VecZeroEntries(user->
P));
149 PetscCall(VecZeroEntries(user->
Ucat));
150 PetscCall(VecZeroEntries(user->
Ucont));
151 PetscCall(VecZeroEntries(user->
Ucont_rm1));
159 "ReadSimulationFields should restore BDF2 history"));
161 "checkpoint physical time should be authoritative"));
165 PetscErrorCode load_ierr;
167 PetscCall(PetscSNPrintf(path,
sizeof(path),
"%s/checkpoints/step_000000000001/eulerian/block_0000", tmpdir));
169 PetscCall(PetscPushErrorHandler(PetscReturnErrorHandler, NULL));
171 PetscCall(PetscPopErrorHandler());
174 "a payload of the wrong length must be refused"));
177 PetscCall(PetscOptionsClearValue(NULL,
"-viewer_binary_mpiio"));
178 PetscCallMPI(MPI_Barrier(PETSC_COMM_WORLD));
180 PetscCallMPI(MPI_Barrier(PETSC_COMM_WORLD));
182 PetscFunctionReturn(0);
190 PetscFunctionBeginUser;
192 PetscFunctionReturn(0);
201 PetscFunctionBeginUser;
204 PetscFunctionReturn(0);
218 char tmpdir[PETSC_MAX_PATH_LEN];
220 PetscFunctionBeginUser;
224 PetscCallMPI(MPI_Bcast(tmpdir,
sizeof(tmpdir), MPI_CHAR, 0, PETSC_COMM_WORLD));
228 PetscCall(VecSet(user->
P, 2.0));
229 PetscCall(VecSet(user->
Nvert, 0.0));
230 PetscCall(VecSet(user->
Ucat, 1.0));
231 PetscCall(VecSet(user->
Ucont, 1.0));
236 PetscCall(PetscCalloc1(1, &simCtx->
pps));
245 for (PetscInt pass = 0; pass < 2; ++pass) {
253 PetscCallMPI(MPI_Barrier(PETSC_COMM_WORLD));
255 PetscCallMPI(MPI_Barrier(PETSC_COMM_WORLD));
257 PetscFunctionReturn(0);
265 memset(&d, 0,
sizeof(d));
281 PetscFunctionBeginUser;
288 PetscFunctionReturn(0);
295 PetscFunctionBeginUser;
301 PetscFunctionReturn(0);
317 PetscBool accepted = PETSC_FALSE;
318 PetscReal weight = 0.0;
319 char step_directory[PETSC_MAX_PATH_LEN];
321 PetscFunctionBeginUser;
329 "the fixture window reaches its bounded end"));
333 PetscCall(PetscSNPrintf(step_directory,
sizeof(step_directory),
334 "%s/checkpoints/step_000000000001", simCtx->
output_dir));
335 if (simCtx->
rank == 0) PetscCall(PetscRMTree(step_directory));
336 PetscCallMPI(MPI_Barrier(PETSC_COMM_WORLD));
338 PetscFunctionReturn(0);
356 char tmpdir[PETSC_MAX_PATH_LEN];
357 char path[PETSC_MAX_PATH_LEN];
358 PetscBool exists = PETSC_FALSE;
359 PetscInt payload_count = 0;
360 Vec *reference = NULL;
362 PetscFunctionBeginUser;
366 PetscCallMPI(MPI_Bcast(tmpdir,
sizeof(tmpdir), MPI_CHAR, 0, PETSC_COMM_WORLD));
370 PetscCall(VecSet(user->
Nvert, 0.0));
376 const PetscReal scalars[3] = {1.0, 2.0, 6.0};
378 for (PetscInt s = 0; s < 3; ++s) {
379 PetscBool accepted = PETSC_FALSE;
380 PetscReal weight = 0.0;
382 PetscCall(VecSet(user->
P, scalars[s]));
383 PetscCall(VecSet(user->
Ucat, scalars[s]));
391 PetscCall(PetscSNPrintf(path,
sizeof(path),
392 "%s/checkpoints/step_000000000001/statistics/window_0000/block_0000/P_mean.dat",
394 PetscCall(PetscTestFile(path,
'r', &exists));
395 PetscCall(
PicurvAssertBool(exists,
"statistics payloads use their enumerated names"));
396 PetscCall(PetscSNPrintf(path,
sizeof(path),
397 "%s/checkpoints/step_000000000001/statistics/window_0000/block_0000/Ucat_m2.dat",
399 PetscCall(PetscTestFile(path,
'r', &exists));
400 PetscCall(
PicurvAssertBool(exists,
"the symmetric product is one payload, not six"));
405 PetscCall(PetscCalloc1((
size_t)payload_count, &reference));
406 for (PetscInt index = 0; index < payload_count; ++index) {
410 PetscCall(VecDuplicate(payload.
vec, &reference[index]));
411 PetscCall(VecCopy(payload.
vec, reference[index]));
412 PetscCall(VecZeroEntries(payload.
vec));
423 "the represented time is restored"));
425 "the quadrature origin is restored"));
428 "the duplicate-event guard survives the restart"));
431 "an open window resumes active"));
436 for (PetscInt index = 0; index < payload_count; ++index) {
438 PetscReal difference = 0.0;
442 PetscCall(VecAXPY(reference[index], -1.0, payload.
vec));
443 PetscCall(VecNorm(reference[index], NORM_INFINITY, &difference));
444 PetscCall(PetscSNPrintf(context,
sizeof(context),
445 "payload '%s' is restored bit for bit", payload.
name));
447 PetscCall(VecDestroy(&reference[index]));
449 PetscCall(PetscFree(reference));
454 PetscReal ***mean = NULL;
456 PetscCall(DMDAVecGetArrayRead(user->
da, storage.
mean[1], &mean));
457 if (user->
info.xs <= 2 && 2 < user->
info.xs + user->
info.xm &&
458 user->
info.ys <= 2 && 2 < user->
info.ys + user->
info.ym &&
459 user->
info.zs <= 2 && 2 < user->
info.zs + user->
info.zm) {
461 "the restored scalar mean holds the accumulated value"));
463 PetscCall(DMDAVecRestoreArrayRead(user->
da, storage.
mean[1], &mean));
466 PetscCallMPI(MPI_Barrier(PETSC_COMM_WORLD));
468 PetscCallMPI(MPI_Barrier(PETSC_COMM_WORLD));
471 PetscFunctionReturn(0);
489 char tmpdir[PETSC_MAX_PATH_LEN];
490 PetscErrorCode bad = 0;
492 PetscFunctionBeginUser;
496 PetscCallMPI(MPI_Bcast(tmpdir,
sizeof(tmpdir), MPI_CHAR, 0, PETSC_COMM_WORLD));
500 PetscCall(VecSet(user->
Nvert, 0.0));
503 PetscBool accepted = PETSC_FALSE;
504 PetscReal weight = 0.0;
513 changed = definition;
517 PetscCall(PetscPushErrorHandler(PetscIgnoreErrorHandler, NULL));
519 PetscCall(PetscPopErrorHandler());
521 "a changed definition is refused rather than merged"));
524 changed = definition;
527 PetscCall(PetscPushErrorHandler(PetscIgnoreErrorHandler, NULL));
529 PetscCall(PetscPopErrorHandler());
533 changed = definition;
537 PetscCall(PetscPushErrorHandler(PetscIgnoreErrorHandler, NULL));
539 PetscCall(PetscPopErrorHandler());
545 changed = definition;
552 "an extended window resumes active"));
558 changed = definition;
562 PetscCall(PetscPushErrorHandler(PetscIgnoreErrorHandler, NULL));
564 PetscCall(PetscPopErrorHandler());
566 "reopening a closed window across an unsampled gap is refused"));
573 "statistics start fresh when continuation is not requested"));
575 PetscCallMPI(MPI_Barrier(PETSC_COMM_WORLD));
577 PetscCallMPI(MPI_Barrier(PETSC_COMM_WORLD));
580 PetscFunctionReturn(0);
597 char tmpdir[PETSC_MAX_PATH_LEN];
598 char payload_path[PETSC_MAX_PATH_LEN];
599 PetscErrorCode bad = 0;
601 PetscFunctionBeginUser;
605 PetscCallMPI(MPI_Bcast(tmpdir,
sizeof(tmpdir), MPI_CHAR, 0, PETSC_COMM_WORLD));
609 PetscCall(VecSet(user->
Nvert, 0.0));
612 PetscBool accepted = PETSC_FALSE;
613 PetscReal weight = 0.0;
623 PetscCall(PetscSNPrintf(payload_path,
sizeof(payload_path),
624 "%s/checkpoints/step_000000000001/statistics/window_0000/block_0000/P_mean.dat",
626 if (simCtx->
rank == 0) {
627 FILE *damaged = fopen(payload_path,
"w");
629 PetscCheck(damaged != NULL, PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN,
630 "Unable to truncate '%s'.", payload_path);
631 PetscCheck(fclose(damaged) == 0, PETSC_COMM_SELF, PETSC_ERR_FILE_WRITE,
632 "Unable to close '%s'.", payload_path);
634 PetscCallMPI(MPI_Barrier(PETSC_COMM_WORLD));
637 PetscCall(PetscPushErrorHandler(PetscIgnoreErrorHandler, NULL));
639 PetscCall(PetscPopErrorHandler());
641 "a truncated statistics payload fails bundle validation"));
643 PetscCallMPI(MPI_Barrier(PETSC_COMM_WORLD));
645 PetscCallMPI(MPI_Barrier(PETSC_COMM_WORLD));
648 PetscFunctionReturn(0);
659 char tmpdir[PETSC_MAX_PATH_LEN];
660 char path[PETSC_MAX_PATH_LEN];
661 PetscBool exists = PETSC_TRUE;
662 PetscErrorCode bad = 0;
664 PetscFunctionBeginUser;
668 PetscCallMPI(MPI_Bcast(tmpdir,
sizeof(tmpdir), MPI_CHAR, 0, PETSC_COMM_WORLD));
674 PetscCall(PetscSNPrintf(path,
sizeof(path),
"%s/checkpoints/step_000000000001/statistics", tmpdir));
675 PetscCall(PetscTestDirectory(path,
'r', &exists));
677 "a run without statistics writes no statistics subtree"));
682 PetscCall(PetscPushErrorHandler(PetscIgnoreErrorHandler, NULL));
684 PetscCall(PetscPopErrorHandler());
686 "missing statistics state is fatal, never silently zeroed"));
688 PetscCallMPI(MPI_Barrier(PETSC_COMM_WORLD));
690 PetscCallMPI(MPI_Barrier(PETSC_COMM_WORLD));
693 PetscFunctionReturn(0);
709 char tmpdir[PETSC_MAX_PATH_LEN];
710 char payload_path[PETSC_MAX_PATH_LEN];
711 struct stat first_stat;
712 struct stat second_stat;
713 PetscErrorCode mismatch_ierr = 0;
715 PetscFunctionBeginUser;
719 PetscCallMPI(MPI_Bcast(tmpdir,
sizeof(tmpdir), MPI_CHAR, 0, PETSC_COMM_WORLD));
723 PetscCall(VecSet(user->
P, 4.5));
724 PetscCall(VecSet(user->
Nvert, 0.0));
725 PetscCall(VecSet(user->
Ucat, 2.0));
726 PetscCall(VecSet(user->
Ucont, 3.0));
727 PetscCall(VecSet(user->
Ucont_rm1, 1.25));
732 PetscCall(PetscSNPrintf(payload_path,
sizeof(payload_path),
733 "%s/checkpoints/step_000000000001/eulerian/block_0000/Ucat.dat", tmpdir));
734 PetscCall(
PicurvAssertBool((PetscBool)(stat(payload_path, &first_stat) == 0),
735 "first checkpoint write should produce a Ucat payload"));
738 PetscCall(VecSet(user->
Ucat, 99.0));
741 PetscCall(
PicurvAssertBool((PetscBool)(stat(payload_path, &second_stat) == 0),
742 "repeated checkpoint write should leave the Ucat payload in place"));
744 PetscCall(
PicurvAssertBool((PetscBool)(first_stat.st_mtim.tv_sec == second_stat.st_mtim.tv_sec &&
745 first_stat.st_mtim.tv_nsec == second_stat.st_mtim.tv_nsec),
746 "repeated checkpoint write at a committed step should not touch payload mtime"));
747 PetscCall(
PicurvAssertBool((PetscBool)(first_stat.st_size == second_stat.st_size),
748 "repeated checkpoint write at a committed step should not resize payloads"));
750 PetscCall(VecZeroEntries(user->
Ucat));
753 "repeated checkpoint write must not overwrite committed payload contents"));
757 PetscCall(PetscPushErrorHandler(PetscIgnoreErrorHandler, NULL));
759 PetscCall(PetscPopErrorHandler());
761 "same-step checkpoint write with a different physical time should fail"));
763 PetscCallMPI(MPI_Barrier(PETSC_COMM_WORLD));
765 PetscCallMPI(MPI_Barrier(PETSC_COMM_WORLD));
767 PetscFunctionReturn(0);
776 PetscFunctionBeginUser;
781 (PetscBool)!strcmp(digest,
"ba7816bf8f01cfea414140de5dae2223"
782 "b00361a396177a9cb410ff61f20015ad"),
783 "SHA-256 implementation should match the standard abc test vector"));
784 PetscFunctionReturn(0);
794 char tmpdir[PETSC_MAX_PATH_LEN];
795 char cfg_path[PETSC_MAX_PATH_LEN];
798 PetscFunctionBeginUser;
800 PetscCall(PetscCalloc1(1, &simCtx->
pps));
802 PetscCall(PetscSNPrintf(cfg_path,
sizeof(cfg_path),
"%s/post.run", tmpdir));
805 file = fopen(cfg_path,
"w");
806 PetscCheck(file != NULL, PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN,
"Failed to create temp config file '%s'.", cfg_path);
807 fputs(
"startTime = 2\n", file);
808 fputs(
"endTime = 6\n", file);
809 fputs(
"timeStep = 2\n", file);
810 fputs(
"output_particles = true\n", file);
811 fputs(
"output_prefix = SmokeField\n", file);
820 "ParsePostProcessingSettings should parse output_prefix"));
823 const PetscInt intervals[] = {1, 0, -1, 1, 1, 0};
824 const char *overrides[] = {NULL, NULL, NULL,
"0",
"-1",
"1"};
825 for (
size_t n = 0; n <
sizeof(intervals) /
sizeof(intervals[0]); ++n) {
826 PetscErrorCode parse_ierr;
827 file = fopen(cfg_path,
"w");
828 PetscCheck(file != NULL, PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN,
"Failed to reopen post config.");
829 fprintf(file,
"startTime = 100\nendTime = 100\ntimeStep = %d\n", (
int)intervals[n]);
831 if (overrides[n]) PetscCall(PetscOptionsSetValue(NULL,
"-timeStep", overrides[n]));
832 PetscCall(PetscPushErrorHandler(PetscIgnoreErrorHandler, NULL));
834 PetscCall(PetscPopErrorHandler());
835 PetscCall(PetscOptionsClearValue(NULL,
"-timeStep"));
837 parse_ierr,
"post interval must be positive after command-line overrides"));
842 PetscFunctionReturn(0);
851 char value_a[] =
" inlet_value ";
852 char value_b[] =
" ";
854 PetscFunctionBeginUser;
856 PetscCall(
PicurvAssertBool((PetscBool)(strcmp(value_a,
"inlet_value") == 0),
857 "TrimWhitespace should remove leading and trailing whitespace"));
861 "TrimWhitespace should reduce all-whitespace strings to empty"));
862 PetscFunctionReturn(0);
874 PetscFunctionBeginUser;
883 "StringToBCHandlerType should parse constant_flux"));
886 "StringToBCHandlerType should parse prescribed_velocity"));
887 PetscFunctionReturn(0);
895 PetscFunctionBeginUser;
897 "WALL + noslip should be a valid combination"));
899 "PERIODIC + geometric should be a valid combination"));
901 "INLET + prescribed_velocity should be a valid combination"));
903 "INLET + noslip should be rejected"));
904 PetscFunctionReturn(0);
914 PetscFunctionBeginUser;
915 PetscCall(PetscMemzero(&simCtx,
sizeof(simCtx)));
917 PetscCall(PetscOptionsClearValue(NULL,
"-scaling_L_ref"));
918 PetscCall(PetscOptionsClearValue(NULL,
"-scaling_U_ref"));
919 PetscCall(PetscOptionsClearValue(NULL,
"-scaling_rho_ref"));
927 PetscCall(PetscOptionsSetValue(NULL,
"-scaling_L_ref",
"2.5"));
928 PetscCall(PetscOptionsSetValue(NULL,
"-scaling_U_ref",
"4.0"));
929 PetscCall(PetscOptionsSetValue(NULL,
"-scaling_rho_ref",
"1.2"));
937 PetscCall(PetscOptionsClearValue(NULL,
"-scaling_L_ref"));
938 PetscCall(PetscOptionsClearValue(NULL,
"-scaling_U_ref"));
939 PetscCall(PetscOptionsClearValue(NULL,
"-scaling_rho_ref"));
940 PetscFunctionReturn(0);
947 char tmpdir[PETSC_MAX_PATH_LEN];
948 char capture_path[PETSC_MAX_PATH_LEN];
949 FILE *capture_file = NULL;
950 int saved_stdout = -1;
952 size_t bytes_read = 0;
955 PetscFunctionBeginUser;
956 PetscCheck(simCtx != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"SimCtx cannot be NULL.");
957 PetscCheck(captured != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"Capture buffer cannot be NULL.");
958 PetscCheck(captured_len > 0, PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ,
"Capture buffer must be non-empty.");
961 PetscCall(PetscSNPrintf(capture_path,
sizeof(capture_path),
"%s/banner.log", tmpdir));
964 saved_stdout = dup(STDOUT_FILENO);
965 PetscCheck(saved_stdout >= 0, PETSC_COMM_SELF, PETSC_ERR_SYS,
"dup(STDOUT_FILENO) failed.");
966 capture_fd = open(capture_path, O_CREAT | O_TRUNC | O_WRONLY, 0600);
967 PetscCheck(capture_fd >= 0, PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN,
"Failed to open capture file '%s'.", capture_path);
968 PetscCheck(dup2(capture_fd, STDOUT_FILENO) >= 0, PETSC_COMM_SELF, PETSC_ERR_SYS,
"dup2() failed while redirecting stdout.");
974 PetscCheck(dup2(saved_stdout, STDOUT_FILENO) >= 0, PETSC_COMM_SELF, PETSC_ERR_SYS,
"dup2() failed while restoring stdout.");
979 capture_file = fopen(capture_path,
"r");
980 PetscCheck(capture_file != NULL, PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN,
"Failed to read capture file '%s'.", capture_path);
981 bytes_read = fread(captured, 1, captured_len - 1, capture_file);
982 captured[bytes_read] =
'\0';
983 fclose(capture_file);
985 PetscCallMPI(MPI_Bcast(captured, (PetscMPIInt)captured_len, MPI_CHAR, 0, PETSC_COMM_WORLD));
986 PetscFunctionReturn(0);
993 PetscFunctionBeginUser;
994 PetscCall(
PicurvAssertBool((PetscBool)(strstr(captured, needle) != NULL), message));
995 PetscFunctionReturn(0);
1002 PetscFunctionBeginUser;
1003 PetscCall(
PicurvAssertBool((PetscBool)(strstr(captured, needle) == NULL), message));
1004 PetscFunctionReturn(0);
1022 char captured[16384];
1024 PetscFunctionBeginUser;
1038 "DisplayBanner should report the live statistics console cadence"));
1043 PetscCall(
AssertCapturedContains(captured,
"Statistics Console Cadence : DISABLED (1 window(s) accumulating)",
1044 "DisplayBanner should distinguish a silenced console from an inactive subsystem"));
1051 PetscCall(
AssertCapturedContains(captured,
"Statistics Console Cadence : DISABLED (no window configured)",
1052 "DisplayBanner should record that no statistics window was configured"));
1055 PetscFunctionReturn(0);
1065 char captured[16384];
1067 PetscFunctionBeginUser;
1080 "DisplayBanner should include the run mode"));
1082 "DisplayBanner should include field/restart cadence"));
1084 "DisplayBanner should include immersed-boundary state"));
1086 "DisplayBanner should include BC-derived periodic axes"));
1088 "DisplayBanner should include the total particle count"));
1090 "DisplayBanner should identify a fresh solve IC as the Eulerian source"));
1092 "DisplayBanner should omit particle console cadence when no particles are configured"));
1094 "DisplayBanner should omit particle row sampling when no particles are configured"));
1096 "DisplayBanner should omit particle restart mode when no particles are configured"));
1098 "DisplayBanner should omit particle initialization mode when no particles are configured"));
1100 "DisplayBanner should omit interpolation method when no particles are configured"));
1102 "DisplayBanner should report pseudo-CFL for the dual-time momentum solver"));
1104 "DisplayBanner should report the active dual-time controller"));
1106 "DisplayBanner should report the effective console log level"));
1108 "DisplayBanner should report profiling mode"));
1110 "DisplayBanner should report runtime-memory logging state"));
1115 "DisplayBanner should identify the selected Newton-Krylov solver"));
1117 "DisplayBanner must not report pseudo-CFL for Newton-Krylov"));
1119 "DisplayBanner should report the active Newton-Krylov control family"));
1126 "DisplayBanner should identify the active periodic convergence mode"));
1128 "DisplayBanner should report the active periodic convergence period"));
1132 "DisplayBanner should omit periodic-only convergence fields when inactive"));
1144 "DisplayBanner should identify restart authority"));
1146 "DisplayBanner should not present an IC as active during restart"));
1148 "DisplayBanner should include the active particle count"));
1150 "DisplayBanner should include validated periodic translation"));
1152 "DisplayBanner should not report particle wrapping as unsupported"));
1154 "DisplayBanner should show disabled particle console cadence when particles are configured"));
1156 "DisplayBanner should include particle row sampling when particles are configured"));
1158 "DisplayBanner should include particle restart mode for restarted particle runs"));
1160 "DisplayBanner should include particle initialization mode when particles are configured"));
1162 "DisplayBanner should include default interpolation method when particles are configured"));
1164 "DisplayBanner should omit inlet-face placement details for point-source particle initialization"));
1170 "DisplayBanner should identify load authority"));
1172 "DisplayBanner should not present an IC as active in load mode"));
1182 "DisplayBanner should include the analytical solution type for analytical runs"));
1184 "DisplayBanner should include active particle console cadence when particles are configured"));
1186 "DisplayBanner should include particle initialization mode for analytical particle runs"));
1188 "DisplayBanner should include inlet-face placement details for surface particle initialization"));
1191 PetscFunctionReturn(0);
1199 PetscErrorCode ierr;
1222 ierr = PetscInitialize(&argc, &argv, NULL,
"PICurv I/O tests");
1227 ierr =
PicurvRunTests(
"unit-io", cases,
sizeof(cases) /
sizeof(cases[0]));
1233 ierr = PetscFinalize();
Small dependency-free SHA-256 utility for persistent metadata identity.
void PicurvSHA256Init(PicurvSHA256Context *context)
Initialize an incremental SHA-256 calculation.
void PicurvSHA256Update(PicurvSHA256Context *context, const void *data, size_t length)
Add bytes to an incremental SHA-256 calculation.
void PicurvSHA256FinalHex(PicurvSHA256Context *context, char digest_hex[65])
Finish a SHA-256 calculation and return a lowercase hexadecimal digest.
Incremental SHA-256 state.
Authoritative identities and storage metadata for persistent Eulerian fields.
Public interface for data input/output routines.
PetscErrorCode ParsePostProcessingSettings(SimCtx *simCtx)
Initializes post-processing settings from a config file and command-line overrides.
PetscErrorCode ParseScalingInformation(SimCtx *simCtx)
Parses physical scaling parameters from command-line options.
PetscErrorCode StringToBCHandlerType(const char *str, BCHandlerType *handler_out)
Converts a BC handler token (implementation strategy) to BCHandlerType.
PetscErrorCode ReadSimulationFields(UserCtx *user, PetscInt ti)
Reads binary field data for velocity, pressure, and other required vectors.
PetscBool ShouldWriteDataOutput(const SimCtx *simCtx, PetscInt completed_step)
Returns whether full field/restart output should be written for the.
PetscErrorCode ValidateBCHandlerForBCType(BCType type, BCHandlerType handler)
Validates that a selected handler is compatible with a mathematical BC type.
void TrimWhitespace(char *str)
Removes leading and trailing ASCII whitespace from a mutable string.
PetscErrorCode ReadFieldData(UserCtx *user, const char *field_name, Vec field_vec, const char *ext)
Reads data for a specific field from a file into the provided vector.
PetscErrorCode RestoreFieldStatisticsState(SimCtx *simCtx, PetscInt ti)
Restores field-statistics window state and accumulators from a checkpoint.
PetscErrorCode StringToBCFace(const char *str, BCFace *face_out)
Converts a face-token string (e.g., "-Xi", "+Eta") to the internal BCFace enum.
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.
PetscErrorCode StringToBCType(const char *str, BCType *type_out)
Converts a mathematical BC type string (e.g., "PERIODIC", "WALL") to BCType.
PetscErrorCode DisplayBanner(SimCtx *simCtx)
Displays a structured banner summarizing the simulation configuration.
PetscErrorCode WriteCheckpointBundle(SimCtx *simCtx, const char *reason)
Write and atomically publish one complete checkpoint bundle.
Per-window PETSc accumulator storage and pointwise application.
Vec * mean
One per field, matching that field's layout.
Vec vec
Borrowed accumulator vector; never owned by the caller.
PetscErrorCode PicurvWindowStorageCreate(UserCtx *user, const PicurvWindowDefinition *definition, PicurvWindowStorage *storage)
Allocates the accumulator state one window owns on one block.
PetscErrorCode PicurvWindowStoragePayload(UserCtx *user, const PicurvWindowDefinition *definition, const PicurvWindowStorage *storage, PetscInt index, PicurvStatisticsPayload *payload)
Resolves one enumerated payload of a window's storage.
char name[96]
File basename, no extension.
PetscErrorCode PicurvWindowAccumulate(UserCtx *user, const PicurvWindowDefinition *definition, PicurvWindowStorage *storage, PetscReal weight)
Applies one accepted completed state to a window's accumulators.
PetscErrorCode PicurvWindowStorageDestroy(PicurvWindowStorage *storage)
Releases accumulator state previously created for one window.
PetscErrorCode PicurvWindowStoragePayloadCount(const PicurvWindowStorage *storage, PetscInt *count)
Reports how many checkpointable vectors one window's storage holds.
One checkpointable accumulator vector, resolved by enumeration index.
Independent accumulator state for one window on one block.
Window lifecycle, scheduling, and weighting for the field-statistics pipeline.
PetscInt last_event_step
Guards against a step being offered twice.
PetscReal last_accepted_time
Right edge of the last represented interval.
PicurvWindowFieldRequest fields[16]
PetscInt restart_count
Restart segments this state descends from.
PetscReal end_time
Requested end; ignored when bounded is false.
PicurvCadenceKind cadence_kind
PetscInt step_cadence
Used when cadence_kind is step; must be positive.
#define PICURV_WINDOW_NAME_LENGTH
Maximum stored length of a window name, including the terminator.
@ PICURV_WINDOW_COMPLETE
Bounded end reached; accepts nothing further.
@ PICURV_WINDOW_ACTIVE
Accepting due states.
PetscErrorCode PicurvWindowInit(PicurvWindow *window, const PicurvWindowDefinition *definition)
Validates a definition and initializes a window to the pending state.
PetscErrorCode PicurvWindowOfferState(PicurvWindow *window, PetscInt step, PetscReal time, PetscBool *accepted, PetscReal *weight)
Offers one completed state to a window and reports the decision.
PetscBool want_second
Also keep the centered second moment.
PetscBool bounded
False for an open-ended window.
PetscInt activation_step
Step at which the window became active.
PetscInt field_id
Catalogued Eulerian field identity.
@ PICURV_WEIGHTING_PHYSICAL_TIME
Weight is the represented interval.
@ PICURV_WEIGHTING_SAMPLE
Equal weight per accepted state.
@ PICURV_CADENCE_STEP
Every n completed steps from activation.
PetscReal represented_time
Physical time the window covers.
PicurvWeighting weighting
Runtime state of one window.
The scientifically immutable definition of one window.
static PetscErrorCode TestCheckpointSameStepRewriteIsRejected(void)
Verifies a committed checkpoint step is rewritten neither silently nor inconsistently.
static PetscErrorCode TestParseScalingInformation(void)
Tests scaling-reference parsing and derived pressure scaling.
static PetscErrorCode TestBoundaryCheckpointsCanBeSkipped(void)
Tests that turned-off boundary checkpoints are skipped while cadence ones are written.
static PetscErrorCode DetachStatisticsFixture(SimCtx *simCtx, UserCtx *user, PicurvWindowStorage *storage)
Detaches the statistics fixture without disturbing the shared teardown.
int main(int argc, char **argv)
Runs the unit-io PETSc test binary.
static PetscErrorCode TestValidateBCHandlerForBCType(void)
Tests validation of boundary-type and handler compatibility.
static PetscErrorCode TestFieldPayloadsAreTransportIndependent(void)
Tests that payloads written through the rank-0 relay load through MPI-IO and back: -viewer_binary_mpi...
static PetscErrorCode TestCheckpointStatisticsContinuationGuards(void)
Verifies continuation refuses every state that would corrupt an average.
static PetscErrorCode WriteAndReadSimulationFields(PetscBool write_mpiio, PetscBool read_mpiio)
Writes a checkpoint and reloads its core Eulerian fields, each side optionally through PETSc's rank-0...
static PetscErrorCode AssertCapturedOmits(const char *captured, const char *needle, const char *message)
Asserts that captured banner output omits one forbidden substring.
static PetscErrorCode TestPostprocessorReadScalesEachLoadOnce(void)
Tests that a dimensionalizing post-processor scales each loaded field once per load.
static PetscErrorCode TestParsePostProcessingSettings(void)
Tests parsing of post-processing control settings from a file.
static PicurvWindowDefinition StatisticsFixtureDefinition(void)
Builds the statistics fixture: one Ucat/P window with a second moment.
static PetscErrorCode TestCheckpointStatisticsPayloadIsValidated(void)
A damaged statistics payload must fail bundle validation, not load silently.
static PetscErrorCode TestCheckpointStatisticsAbsentWhenDisabled(void)
A run without statistics writes no statistics subtree and refuses to fake one.
static PetscErrorCode TestCheckpointSHA256KnownVector(void)
Verifies the dependency-free SHA-256 implementation against a standard vector.
static PetscErrorCode TestDisplayBannerTracksConditionalStartupFields(void)
Tests conditional startup-banner fields across particle and analytical cases.
static PetscErrorCode TestDisplayBannerReportsStatisticsCadence(void)
Tests that the startup banner reports statistics monitoring in every state.
static PetscErrorCode TestVerifyPathExistence(void)
Tests filesystem existence checks for files and directories.
static PetscErrorCode AssertCapturedContains(const char *captured, const char *needle, const char *message)
Asserts that captured banner output contains one expected substring.
static PetscErrorCode TestTrimWhitespace(void)
Tests trimming of leading and trailing whitespace.
static PetscErrorCode TestShouldWriteDataOutput(void)
Tests cadence-based Eulerian output triggering.
static PetscErrorCode WriteCompletedStatisticsWindow(SimCtx *simCtx, UserCtx *user, PicurvWindow *window, PicurvWindowStorage *storage, const PicurvWindowDefinition *definition)
Rewrites the bundle holding a window that closed well before the checkpoint time.
static PetscErrorCode TestCheckpointStatisticsRoundTrip(void)
Verifies accumulated statistics survive a checkpoint round trip unchanged.
static PetscErrorCode TestBoundaryConditionStringParsers(void)
Tests boundary-condition string parsers for face, type, and handler names.
static PetscErrorCode CaptureBannerOutput(SimCtx *simCtx, char *captured, size_t captured_len)
Captures the startup banner into a temporary file-backed buffer.
static PetscErrorCode TestWriteAndReadSimulationFields(void)
Tests writing and reloading core Eulerian field vectors through MPI-IO.
static PetscErrorCode AttachStatisticsFixture(SimCtx *simCtx, UserCtx *user, PicurvWindow *window, PicurvWindowStorage *storage, const PicurvWindowDefinition *definition)
Attaches one accumulating window to a fixture context and primes it with samples.
PetscErrorCode PicurvMakeTempDir(char *path, size_t path_len)
Creates a unique temporary directory for one test case.
PetscErrorCode PicurvCreateMinimalContexts(SimCtx **simCtx_out, UserCtx **user_out, PetscInt mx, PetscInt my, PetscInt mz)
Builds minimal SimCtx and UserCtx fixtures for C unit tests.
PetscErrorCode PicurvAssertRealNear(PetscReal expected, PetscReal actual, PetscReal tol, const char *context)
Asserts that two real values agree within tolerance.
PetscErrorCode PicurvDestroyMinimalContexts(SimCtx **simCtx_ptr, UserCtx **user_ptr)
Destroys minimal SimCtx/UserCtx fixtures and all owned PETSc objects.
PetscErrorCode PicurvRunTests(const char *suite_name, const PicurvTestCase *cases, size_t case_count)
Runs a named C test suite and prints pass/fail progress markers.
PetscErrorCode PicurvAssertVecConstant(Vec vec, PetscScalar expected, PetscReal tol, const char *context)
Asserts that a PETSc vector is spatially constant within tolerance.
PetscErrorCode PicurvAssertIntEqual(PetscInt expected, PetscInt actual, const char *context)
Asserts that two integer values are equal.
PetscErrorCode PicurvPopulateIdentityMetrics(UserCtx *user)
Populates identity metric vectors on the minimal grid fixture.
PetscErrorCode PicurvAssertBool(PetscBool value, const char *context)
Asserts that one boolean condition is true.
PetscErrorCode PicurvRemoveTempDir(const char *path)
Recursively removes a temporary directory created by PicurvMakeTempDir.
Shared declarations for the PICurv C test fixture and assertion layer.
Named test case descriptor consumed by PicurvRunTests.
PetscInt fieldStatisticsWindowCount
BCType
Defines the general mathematical/physical Category of a boundary.
PetscBool inletFaceDefined
PetscInt statisticsConsoleOutputFreq
BCFace identifiedInletBCFace
@ PARTICLE_INIT_SURFACE_RANDOM
Random placement on the inlet face.
@ PARTICLE_INIT_POINT_SOURCE
All particles at a fixed (psrc_x,psrc_y,psrc_z) — for validation.
PetscBool dimensionalize
Whether derived output leaves non-dimensional form, from global_operations.dimensionalize.
BCHandlerType
Defines the specific computational "strategy" for a boundary handler.
@ BC_HANDLER_PERIODIC_GEOMETRIC
@ BC_HANDLER_PERIODIC_DRIVEN_CONSTANT_FLUX
@ BC_HANDLER_INLET_PRESCRIBED_VELOCITY
char output_dir[PETSC_MAX_PATH_LEN]
PetscBool fieldStatisticsEnabled
PetscBool skipFinalCheckpoint
io.write_final_checkpoint false: no end-of-run bundle.
@ MOMENTUM_SOLVER_DUALTIME_PICARD_JAMESON_RK
@ MOMENTUM_SOLVER_NEWTON_KRYLOV
PetscInt solutionConvergencePeriodSteps
char * current_io_directory
char particleRestartMode[16]
struct PicurvWindow * fieldStatisticsWindows
char source_dir[PETSC_MAX_PATH_LEN]
char eulerianSource[PETSC_MAX_PATH_LEN]
ParticleInitializationType ParticleInitialization
PetscBool outputParticles
struct PicurvWindowStorage * fieldStatisticsStorage
PetscInt particleConsoleOutputFreq
PetscBool skipInitialCheckpoint
io.write_initial_checkpoint false: no initial/branch_start bundle.
@ EXEC_MODE_POSTPROCESSOR
Cmpnts periodic_translation[3]
@ SOLUTION_CONVERGENCE_PERIODIC_DETERMINISTIC
@ SOLUTION_CONVERGENCE_STEADY_DETERMINISTIC
PetscBool periodic_translation_valid[3]
SolutionConvergenceMode solutionConvergenceMode
MomentumSolverType mom_solver_type
char PostprocessingControlFile[PETSC_MAX_PATH_LEN]
char restart_dir[PETSC_MAX_PATH_LEN]
PetscInt LoggingFrequency
PetscBool fieldStatisticsContinue
BCFace
Identifies the six logical faces of a structured computational block.
A 3D point or vector with PetscScalar components.
The master context for the entire simulation.
User-defined context containing data specific to a single computational grid level.