22#define PICURV_CHECKPOINT_FORMAT "picurv-checkpoint"
23#define PICURV_CHECKPOINT_VERSION 1
24#define PICURV_CHECKPOINTS_DIRECTORY "checkpoints"
25#define PICURV_EULERIAN_DIRECTORY "eulerian"
26#define PICURV_PARTICLE_DIRECTORY "particles"
27#define PICURV_STATISTICS_DIRECTORY "statistics"
28#define PICURV_CHECKPOINT_STEP_WIDTH 12
55 const PetscScalar ***local_array = NULL;
56 PetscScalar ***global_array = NULL;
58 PetscFunctionBeginUser;
61 PetscCall(DMDAGetLocalInfo(dm, &info));
62 PetscCall(DMDAVecGetArrayRead(dm, local_vec, &local_array));
63 PetscCall(DMDAVecGetArray(dm, global_vec, &global_array));
64 for (PetscInt k = info.zs; k < info.zs + info.zm; ++k)
65 for (PetscInt j = info.ys; j < info.ys + info.ym; ++j)
66 for (PetscInt i = info.xs; i < info.xs + info.xm; ++i)
67 global_array[k][j][i] = local_array[k][j][i];
68 PetscCall(DMDAVecRestoreArray(dm, global_vec, &global_array));
69 PetscCall(DMDAVecRestoreArrayRead(dm, local_vec, &local_array));
71 PetscFunctionReturn(0);
106 const char *payload_name,
char *path,
size_t path_size)
110 PetscFunctionBeginUser;
112 PetscCheck(path != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"Output path is required.");
117 PetscCall(PetscStrlen(path, &used));
118 PetscCall(PetscSNPrintf(path + used, path_size - used,
"/window_%04" PetscInt_FMT, window));
121 PetscCall(PetscStrlen(path, &used));
122 PetscCall(PetscSNPrintf(path + used, path_size - used,
"/block_%04" PetscInt_FMT, block));
125 PetscCall(PetscStrlen(path, &used));
126 PetscCall(PetscSNPrintf(path + used, path_size - used,
"/%s.dat", payload_name));
128 PetscFunctionReturn(0);
140 const char *dm_type = NULL;
142 PetscFunctionBeginUser;
144 PetscCall(VecGetDM(field_vec, &dm));
145 if (dm) PetscCall(DMGetType(dm, &dm_type));
146 if (dm_type && !strcmp(dm_type, DMDA)) *dmda = dm;
147 PetscFunctionReturn(0);
160 PetscFunctionBeginUser;
163 *ordered_vec = field_vec;
166 PetscCall(DMDACreateNaturalVector(dm, natural_vec));
167 PetscCall(DMDAGlobalToNaturalBegin(dm, field_vec, INSERT_VALUES, *natural_vec));
168 PetscCall(DMDAGlobalToNaturalEnd(dm, field_vec, INSERT_VALUES, *natural_vec));
169 *ordered_vec = *natural_vec;
172 PetscFunctionReturn(0);
182static PetscErrorCode
OpenFieldPayloadViewer(MPI_Comm comm,
const char *filename, PetscFileMode mode, PetscViewer *viewer)
184 PetscBool use_mpiio = PETSC_TRUE;
186 PetscFunctionBeginUser;
188 PetscCall(PetscOptionsGetBool(NULL, NULL,
"-viewer_binary_mpiio", &use_mpiio, NULL));
189 PetscCall(PetscViewerCreate(comm, viewer));
190 PetscCall(PetscViewerSetType(*viewer, PETSCVIEWERBINARY));
191 PetscCall(PetscViewerFileSetMode(*viewer, mode));
192 PetscCall(PetscViewerBinarySetUseMPIIO(*viewer, use_mpiio));
193 PetscCall(PetscViewerBinarySetSkipInfo(*viewer, PETSC_TRUE));
194 PetscCall(PetscViewerFileSetName(*viewer, filename));
196 PetscFunctionReturn(0);
205 PetscFunctionBeginUser;
207 PetscCheck(simCtx != NULL && user != NULL && digest_hex != NULL,
208 PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"Geometry hash inputs cannot be NULL.");
212 PetscFunctionReturn(0);
216 for (PetscInt block = 0; block < simCtx->
block_number; ++block) {
218 Vec natural_vec = NULL, ordered_vec = NULL;
219 const PetscScalar *values = NULL;
220 PetscInt value_count = 0, local_count = 0, max_count = 0;
228 PetscCall(VecGetSize(ordered_vec, &value_count));
229 PetscCall(VecGetLocalSize(ordered_vec, &local_count));
230 PetscCall(VecGetArrayRead(ordered_vec, &values));
232 PetscCallMPI(MPI_Allreduce(&local_count, &max_count, 1, MPIU_INT, MPI_MAX, PETSC_COMM_WORLD));
233 if (simCtx->
rank == 0) {
234 PetscScalar *chunk = NULL;
235 size_t metadata_length = 0;
237 PetscCall(PetscSNPrintf(metadata,
sizeof(metadata),
238 "block=%" PetscInt_FMT
";im=%" PetscInt_FMT
";jm=%" PetscInt_FMT
239 ";km=%" PetscInt_FMT
";periodic=%d,%d,%d;",
240 block, user[block].IM, user[block].JM, user[block].KM,
242 PetscCall(PetscStrlen(metadata, &metadata_length));
246 PetscCall(PetscMalloc1(max_count + 1, &chunk));
247 for (PetscMPIInt r = 1; r < size; ++r) {
249 PetscCallMPI(MPI_Recv(&count, 1, MPIU_INT, r, 0, PETSC_COMM_WORLD, MPI_STATUS_IGNORE));
250 PetscCallMPI(MPI_Recv(chunk, (
int)count, MPIU_SCALAR, r, 1, PETSC_COMM_WORLD, MPI_STATUS_IGNORE));
253 PetscCall(PetscFree(chunk));
255 PetscCallMPI(MPI_Send(&local_count, 1, MPIU_INT, 0, 0, PETSC_COMM_WORLD));
256 PetscCallMPI(MPI_Send((
void *)values, (
int)local_count, MPIU_SCALAR, 0, 1, PETSC_COMM_WORLD));
258 PetscCall(VecRestoreArrayRead(ordered_vec, &values));
259 PetscCall(VecDestroy(&natural_vec));
263 PetscCallMPI(MPI_Bcast(digest_hex, 65, MPI_CHAR, 0, PETSC_COMM_WORLD));
267 PetscFunctionReturn(0);
273 PetscFunctionBeginUser;
275 PetscCheck(root != NULL && path != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
276 "Checkpoint root and output path are required.");
277 PetscCall(PetscSNPrintf(path, path_size,
"%s/%s/step_%0*" PetscInt_FMT,
280 PetscFunctionReturn(0);
285 char *path,
size_t path_size)
287 char metadata_path[PETSC_MAX_PATH_LEN];
288 PetscBool exact_bundle = PETSC_FALSE;
290 PetscFunctionBeginUser;
292 PetscCheck(source_root != NULL && path != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
293 "Checkpoint source and output path are required.");
294 PetscCall(PetscSNPrintf(metadata_path,
sizeof(metadata_path),
"%s/checkpoint.meta", source_root));
295 PetscCall(PetscTestFile(metadata_path,
'r', &exact_bundle));
296 if (exact_bundle) PetscCall(PetscStrncpy(path, source_root, path_size));
299 PetscFunctionReturn(0);
305 PetscMPIInt create_failed = 0;
307 PetscFunctionBeginUser;
309 PetscCheck(simCtx != NULL && path != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
310 "Simulation context and directory path are required.");
311 if (simCtx->
rank == 0 && mkdir(path, 0777) != 0) {
312 struct stat directory_stat;
313 if (errno != EEXIST || stat(path, &directory_stat) != 0 || !S_ISDIR(directory_stat.st_mode)) {
317 PetscCallMPI(MPI_Bcast(&create_failed, 1, MPI_INT, 0, PETSC_COMM_WORLD));
318 PetscCheck(!create_failed, PETSC_COMM_WORLD, PETSC_ERR_FILE_OPEN,
319 "Unable to create checkpoint directory '%s'.", path);
321 PetscFunctionReturn(0);
326 const char *checkpoint_directory,
327 PetscInt expected_step,
328 PetscReal *physical_time,
329 PetscInt *particle_count,
330 PetscBool *particles_saved,
331 PetscBool *les_saved,
332 PetscBool *inflow_saved)
334 char metadata_path[PETSC_MAX_PATH_LEN];
335 char commit_path[PETSC_MAX_PATH_LEN];
336 char expected_digest[65] =
"";
337 char actual_digest[65] =
"";
338 char format[64] =
"";
339 char saved_geometry_digest[65] =
"";
340 char current_geometry_digest[65] =
"";
341 PetscOptions options = NULL;
342 PetscInt version = 0;
343 PetscInt saved_step = -1;
344 PetscInt payload_count = 0;
345 PetscInt saved_particle_count = 0;
346 PetscReal saved_time = 0.0;
347 PetscBool saved_particles = PETSC_FALSE;
348 PetscBool saved_les = PETSC_FALSE;
349 PetscBool saved_inflow = PETSC_FALSE;
350 PetscBool found = PETSC_FALSE;
351 FILE *commit_file = NULL;
353 PetscFunctionBeginUser;
355 PetscCheck(simCtx != NULL && checkpoint_directory != NULL,
356 PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"Checkpoint validation inputs cannot be NULL.");
357 PetscCall(PetscSNPrintf(metadata_path,
sizeof(metadata_path),
"%s/checkpoint.meta", checkpoint_directory));
358 PetscCall(PetscSNPrintf(commit_path,
sizeof(commit_path),
"%s/COMMITTED", checkpoint_directory));
360 PetscCall(PetscTestFile(metadata_path,
'r', &found));
361 PetscCheck(found, PETSC_COMM_WORLD, PETSC_ERR_FILE_OPEN,
362 "Checkpoint metadata is missing: %s", metadata_path);
363 PetscCall(PetscTestFile(commit_path,
'r', &found));
364 PetscCheck(found, PETSC_COMM_WORLD, PETSC_ERR_FILE_OPEN,
365 "Checkpoint is not committed: %s", checkpoint_directory);
367 commit_file = fopen(commit_path,
"r");
368 PetscCheck(commit_file != NULL, PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN,
369 "Unable to read checkpoint commit marker '%s'.", commit_path);
370 PetscCheck(fgets(expected_digest,
sizeof(expected_digest), commit_file) != NULL,
371 PETSC_COMM_SELF, PETSC_ERR_FILE_READ,
372 "Checkpoint commit marker '%s' is empty.", commit_path);
373 PetscCheck(fclose(commit_file) == 0, PETSC_COMM_SELF, PETSC_ERR_FILE_READ,
374 "Unable to close checkpoint commit marker '%s'.", commit_path);
376 PetscCheck(strlen(expected_digest) == 64, PETSC_COMM_WORLD, PETSC_ERR_FILE_UNEXPECTED,
377 "Checkpoint commit marker '%s' does not contain a SHA-256 digest.", commit_path);
379 PetscCheck(!strcmp(expected_digest, actual_digest), PETSC_COMM_WORLD, PETSC_ERR_FILE_UNEXPECTED,
380 "Checkpoint metadata hash mismatch in '%s'.", checkpoint_directory);
382 PetscCall(PetscOptionsCreate(&options));
383 PetscCall(PetscOptionsInsertFile(PETSC_COMM_WORLD, options, metadata_path, PETSC_TRUE));
384 PetscCall(PetscOptionsGetString(options, NULL,
"-checkpoint_format", format,
sizeof(format), &found));
386 "Unsupported checkpoint format '%s' in '%s'.", found ? format :
"<missing>", metadata_path);
387 PetscCall(PetscOptionsGetInt(options, NULL,
"-checkpoint_version", &version, &found));
389 "Unsupported checkpoint version %" PetscInt_FMT
" in '%s'; expected %d.",
394 PetscInt index_bytes = 4;
395 PetscCall(PetscOptionsGetInt(options, NULL,
"-checkpoint_petsc_index_bytes", &index_bytes, NULL));
396 PetscCheck(index_bytes == (PetscInt)
sizeof(PetscInt), PETSC_COMM_WORLD, PETSC_ERR_ARG_INCOMP,
397 "Checkpoint '%s' was written by a PETSc with %" PetscInt_FMT
"-byte indices; this build uses "
398 "%d-byte indices. Restart or post-process it with a PICurv built on a %" PetscInt_FMT
"-bit-index PETSc.",
399 checkpoint_directory, index_bytes, (
int)
sizeof(PetscInt), 8 * index_bytes);
401 PetscCall(PetscOptionsGetInt(options, NULL,
"-checkpoint_step", &saved_step, &found));
402 PetscCheck(found && saved_step == expected_step, PETSC_COMM_WORLD, PETSC_ERR_FILE_UNEXPECTED,
403 "Checkpoint step is %" PetscInt_FMT
", expected %" PetscInt_FMT
".",
404 saved_step, expected_step);
405 PetscCall(PetscOptionsGetReal(options, NULL,
"-checkpoint_time", &saved_time, &found));
406 PetscCheck(found, PETSC_COMM_WORLD, PETSC_ERR_FILE_UNEXPECTED,
407 "Checkpoint '%s' does not record physical time.", metadata_path);
408 PetscCall(PetscOptionsGetString(options, NULL,
"-checkpoint_geometry_sha256",
409 saved_geometry_digest,
sizeof(saved_geometry_digest), &found));
410 PetscCheck(found, PETSC_COMM_WORLD, PETSC_ERR_FILE_UNEXPECTED,
411 "Checkpoint '%s' does not record geometry identity.", metadata_path);
415 PetscCheck(!strcmp(saved_geometry_digest, current_geometry_digest), PETSC_COMM_WORLD, PETSC_ERR_ARG_INCOMP,
416 "Checkpoint geometry/layout does not match the active grid.");
419 PetscCall(PetscOptionsGetInt(options, NULL,
"-checkpoint_payload_count", &payload_count, &found));
420 PetscCheck(found && payload_count > 0, PETSC_COMM_WORLD, PETSC_ERR_FILE_UNEXPECTED,
421 "Checkpoint '%s' has no payload inventory.", metadata_path);
422 PetscCall(PetscOptionsGetInt(options, NULL,
"-checkpoint_particle_count",
423 &saved_particle_count, &found));
424 PetscCheck(found && saved_particle_count >= 0, PETSC_COMM_WORLD, PETSC_ERR_FILE_UNEXPECTED,
425 "Checkpoint '%s' has no valid particle count.", metadata_path);
426 PetscCall(PetscOptionsGetBool(options, NULL,
"-checkpoint_particles", &saved_particles, &found));
427 PetscCheck(found, PETSC_COMM_WORLD, PETSC_ERR_FILE_UNEXPECTED,
428 "Checkpoint '%s' does not record particle-state availability.", metadata_path);
429 PetscCall(PetscOptionsGetBool(options, NULL,
"-checkpoint_les", &saved_les, &found));
430 PetscCheck(found, PETSC_COMM_WORLD, PETSC_ERR_FILE_UNEXPECTED,
431 "Checkpoint '%s' does not record LES-state availability.", metadata_path);
433 PetscCall(PetscOptionsGetBool(options, NULL,
"-checkpoint_inflow_fluctuation", &saved_inflow, NULL));
434 for (PetscInt payload = 0; payload < payload_count; ++payload) {
435 char option_name[96];
436 char relative_path[PETSC_MAX_PATH_LEN];
437 char payload_path[PETSC_MAX_PATH_LEN];
438 long long expected_bytes = -1;
439 char expected_bytes_text[64];
440 struct stat payload_stat;
442 PetscCall(PetscSNPrintf(option_name,
sizeof(option_name),
443 "-checkpoint_payload_%" PetscInt_FMT
"_path", payload));
444 PetscCall(PetscOptionsGetString(options, NULL, option_name,
445 relative_path,
sizeof(relative_path), &found));
446 PetscCheck(found, PETSC_COMM_WORLD, PETSC_ERR_FILE_UNEXPECTED,
447 "Checkpoint payload %" PetscInt_FMT
" has no path.", payload);
448 PetscCall(PetscSNPrintf(option_name,
sizeof(option_name),
449 "-checkpoint_payload_%" PetscInt_FMT
"_bytes", payload));
450 PetscCall(PetscOptionsGetString(options, NULL, option_name,
451 expected_bytes_text,
sizeof(expected_bytes_text), &found));
452 if (found) expected_bytes = strtoll(expected_bytes_text, NULL, 10);
453 PetscCheck(found && expected_bytes >= 0, PETSC_COMM_WORLD, PETSC_ERR_FILE_UNEXPECTED,
454 "Checkpoint payload %" PetscInt_FMT
" has no valid byte size.", payload);
455 PetscCall(PetscSNPrintf(payload_path,
sizeof(payload_path),
"%s/%s",
456 checkpoint_directory, relative_path));
457 PetscCheck(stat(payload_path, &payload_stat) == 0 && S_ISREG(payload_stat.st_mode),
458 PETSC_COMM_WORLD, PETSC_ERR_FILE_OPEN,
459 "Checkpoint payload is missing: %s", payload_path);
460 PetscCheck((
long long)payload_stat.st_size == expected_bytes,
461 PETSC_COMM_WORLD, PETSC_ERR_FILE_UNEXPECTED,
462 "Checkpoint payload '%s' is %lld bytes; expected %lld.",
463 payload_path, (
long long)payload_stat.st_size, expected_bytes);
465 PetscCall(PetscOptionsDestroy(&options));
466 if (physical_time) *physical_time = saved_time;
467 if (particle_count) *particle_count = saved_particle_count;
468 if (particles_saved) *particles_saved = saved_particles;
469 if (les_saved) *les_saved = saved_les;
470 if (inflow_saved) *inflow_saved = saved_inflow;
472 PetscFunctionReturn(0);
493 while (isspace((
unsigned char)*start)) {
498 char *end = str + strlen(str) - 1;
500 while (end > start && isspace((
unsigned char)*end)) {
509 memmove(str, start, (end - start) + 2);
529 return (PetscBool)(simCtx->
tiout > 0 && completed_step > 0 && completed_step % simCtx->
tiout == 0);
542 PetscInt block_index = user->
_this;
546 PetscInt *IMs = NULL, *JMs = NULL, *KMs = NULL, *cgrids = NULL;
547 PetscReal *xMins = NULL, *xMaxs = NULL, *rxs = NULL;
548 PetscReal *yMins = NULL, *yMaxs = NULL, *rys = NULL;
549 PetscReal *zMins = NULL, *zMaxs = NULL, *rzs = NULL;
551 PetscFunctionBeginUser;
556 if (block_index >= nblk) {
557 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE,
"Block index %" PetscInt_FMT
" is out of range for nblk=%" PetscInt_FMT
"", block_index, nblk);
561 ierr = PetscMalloc4(nblk, &IMs, nblk, &JMs, nblk, &KMs, nblk, &cgrids); CHKERRQ(ierr);
562 ierr = PetscMalloc6(nblk, &xMins, nblk, &xMaxs, nblk, &rxs, nblk, &yMins, nblk, &yMaxs, nblk, &rys); CHKERRQ(ierr);
563 ierr = PetscMalloc3(nblk, &zMins, nblk, &zMaxs, nblk, &rzs); CHKERRQ(ierr);
566 for (PetscInt i = 0; i < nblk; ++i) {
567 IMs[i] = 10; JMs[i] = 10; KMs[i] = 10; cgrids[i] = 0;
568 xMins[i] = 0.0; xMaxs[i] = 1.0; rxs[i] = 1.0;
569 yMins[i] = 0.0; yMaxs[i] = 1.0; rys[i] = 1.0;
570 zMins[i] = 0.0; zMaxs[i] = 1.0; rzs[i] = 1.0;
575 count = nblk; ierr = PetscOptionsGetIntArray(NULL, NULL,
"-im", IMs, &count, &found); CHKERRQ(ierr);
576 count = nblk; ierr = PetscOptionsGetIntArray(NULL, NULL,
"-jm", JMs, &count, &found); CHKERRQ(ierr);
577 count = nblk; ierr = PetscOptionsGetIntArray(NULL, NULL,
"-km", KMs, &count, &found); CHKERRQ(ierr);
578 count = nblk; ierr = PetscOptionsGetRealArray(NULL, NULL,
"-xMins", xMins, &count, &found); CHKERRQ(ierr);
579 count = nblk; ierr = PetscOptionsGetRealArray(NULL, NULL,
"-xMaxs", xMaxs, &count, &found); CHKERRQ(ierr);
580 count = nblk; ierr = PetscOptionsGetRealArray(NULL, NULL,
"-rxs", rxs, &count, &found); CHKERRQ(ierr);
581 count = nblk; ierr = PetscOptionsGetRealArray(NULL, NULL,
"-yMins", yMins, &count, &found); CHKERRQ(ierr);
582 count = nblk; ierr = PetscOptionsGetRealArray(NULL, NULL,
"-yMaxs", yMaxs, &count, &found); CHKERRQ(ierr);
583 count = nblk; ierr = PetscOptionsGetRealArray(NULL, NULL,
"-rys", rys, &count, &found); CHKERRQ(ierr);
584 count = nblk; ierr = PetscOptionsGetRealArray(NULL, NULL,
"-zMins", zMins, &count, &found); CHKERRQ(ierr);
585 count = nblk; ierr = PetscOptionsGetRealArray(NULL, NULL,
"-zMaxs", zMaxs, &count, &found); CHKERRQ(ierr);
586 count = nblk; ierr = PetscOptionsGetRealArray(NULL, NULL,
"-rzs", rzs, &count, &found); CHKERRQ(ierr);
587 count = nblk; ierr = PetscOptionsGetIntArray(NULL, NULL,
"-cgrids", cgrids, &count, &found); CHKERRQ(ierr);
597 PetscCheck(length_ref > 0.0, PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE,
598 "Reference length L_ref must be positive to non-dimensionalize the "
599 "programmatic domain bounds. Got %g", (
double)length_ref);
602 user->
IM = IMs[block_index];
603 user->
JM = JMs[block_index];
604 user->
KM = KMs[block_index];
605 user->
Min_X = xMins[block_index] / length_ref;
606 user->
Max_X = xMaxs[block_index] / length_ref;
607 user->
rx = rxs[block_index];
608 user->
Min_Y = yMins[block_index] / length_ref;
609 user->
Max_Y = yMaxs[block_index] / length_ref;
610 user->
ry = rys[block_index];
611 user->
Min_Z = zMins[block_index] / length_ref;
612 user->
Max_Z = zMaxs[block_index] / length_ref;
613 user->
rz = rzs[block_index];
614 user->
cgrid = cgrids[block_index];
616 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
"Rank %d: Block %" PetscInt_FMT
" grid generation inputs set: IM=%" PetscInt_FMT
", JM=%" PetscInt_FMT
", KM=%" PetscInt_FMT
"\n",
617 simCtx->
rank, block_index, user->
IM, user->
JM, user->
KM);
619 "Y=[%.4g, %.4g], Z=[%.4g, %.4g]\n",
620 simCtx->
rank, block_index, (
double)length_ref,
624 ierr = PetscFree4(IMs, JMs, KMs, cgrids); CHKERRQ(ierr);
625 ierr = PetscFree6(xMins, xMaxs, rxs, yMins, yMaxs, rys); CHKERRQ(ierr);
626 ierr = PetscFree3(zMins, zMaxs, rzs); CHKERRQ(ierr);
629 PetscFunctionReturn(0);
640 PetscInt block_index = user->
_this;
642 PetscFunctionBeginUser;
648 PetscMPIInt rank = simCtx->
rank;
652 FILE *fd = fopen(simCtx->
grid_file,
"r");
653 if (!fd) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN,
"Cannot open file: %s", simCtx->
grid_file);
656 char firstTok[32] = {0};
657 if (fscanf(fd,
"%31s", firstTok) != 1)
658 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_FILE_READ,
"Empty grid file: %s", simCtx->
grid_file);
659 if (strcmp(firstTok,
"PICGRID") != 0)
660 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_FILE_READ,
661 "Grid file %s must begin with the canonical PICGRID header.", simCtx->
grid_file);
663 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_FILE_READ,
"Expected number of blocks after \"PICGRID\" in %s", simCtx->
grid_file);
665 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_FILE_UNEXPECTED,
"Mismatch: -nblk is %" PetscInt_FMT
" but grid file specifies %" PetscInt_FMT
" blocks.", nblk,
g_nblk_from_file);
669 for (PetscInt i = 0; i < nblk; ++i) {
671 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_FILE_READ,
"Expected 3 integers for block %" PetscInt_FMT
" in %s", i, simCtx->
grid_file);
678 ierr = MPI_Bcast(&
g_nblk_from_file, 1, MPIU_INT, 0, PETSC_COMM_WORLD); CHKERRQ(ierr);
686 ierr = MPI_Bcast(
g_IMs_from_file, nblk, MPIU_INT, 0, PETSC_COMM_WORLD); CHKERRQ(ierr);
687 ierr = MPI_Bcast(
g_JMs_from_file, nblk, MPIU_INT, 0, PETSC_COMM_WORLD); CHKERRQ(ierr);
688 ierr = MPI_Bcast(
g_KMs_from_file, nblk, MPIU_INT, 0, PETSC_COMM_WORLD); CHKERRQ(ierr);
699 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
"Rank %d: Set file inputs for Block %" PetscInt_FMT
": IM=%" PetscInt_FMT
", JM=%" PetscInt_FMT
", KM=%" PetscInt_FMT
"\n",
700 simCtx->
rank, block_index, user->
IM, user->
JM, user->
KM);
703 PetscFunctionReturn(0);
722 while (current != NULL) {
724 PetscFree(current->
key);
725 PetscFree(current->
value);
739 else if (strcasecmp(str,
"+Xi") == 0) *face_out =
BC_FACE_POS_X;
740 else if (strcasecmp(str,
"-Eta") == 0) *face_out =
BC_FACE_NEG_Y;
741 else if (strcasecmp(str,
"+Eta") == 0) *face_out =
BC_FACE_POS_Y;
742 else if (strcasecmp(str,
"-Zeta") == 0) *face_out =
BC_FACE_NEG_Z;
743 else if (strcasecmp(str,
"+Zeta") == 0) *face_out =
BC_FACE_POS_Z;
744 else SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_UNKNOWN_TYPE,
"Unknown face specifier: %s", str);
755 if (strcasecmp(str,
"WALL") == 0) *type_out =
WALL;
756 else if (strcasecmp(str,
"SYMMETRY") == 0)
757 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_UNKNOWN_TYPE,
758 "The SYMMETRY boundary type is retired: a symmetry plane is a free-slip wall, "
759 "so use type WALL with handler free_slip.");
760 else if (strcasecmp(str,
"INLET") == 0) *type_out =
INLET;
761 else if (strcasecmp(str,
"OUTLET") == 0) *type_out =
OUTLET;
762 else if (strcasecmp(str,
"PERIODIC") == 0) *type_out =
PERIODIC;
764 else SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_UNKNOWN_TYPE,
"Unknown BC Type string: %s", str);
784 else SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_UNKNOWN_TYPE,
"Unknown BC Handler string: %s", str);
821 const char *text = NULL;
823 PetscFunctionBeginUser;
827 if (*found) *value_out = atof(text);
829 PetscFunctionReturn(0);
838 const char *text = NULL;
840 PetscFunctionBeginUser;
842 *value_out = PETSC_FALSE;
845 if (*found && text &&
846 (strcasecmp(text,
"true") == 0 || strcmp(text,
"1") == 0 || strcasecmp(text,
"yes") == 0)) {
847 *value_out = PETSC_TRUE;
850 PetscFunctionReturn(0);
861 PetscFunctionBeginUser;
863 *found = PETSC_FALSE;
866 for (
BC_Param *param = params; param; param = param->
next) {
867 if (strcasecmp(param->key, key) == 0) {
868 *value_out = param->value;
874 PetscFunctionReturn(0);
891 PetscFunctionBeginUser;
894 ierr =
GetBCParamBool(params,
"enforce_seam_flux", value_out, found); CHKERRQ(ierr);
896 ierr =
GetBCParamBool(params,
"apply_trim", value_out, found); CHKERRQ(ierr);
899 PetscFunctionReturn(0);
919 PetscFunctionBeginUser;
921 rank = PetscGlobalRank;
925 char line_buffer[1024];
928 for (
int i = 0; i < 6; i++) {
932 configs_rank0[i].
params = NULL;
933 configs_rank0[i].
handler = NULL;
937 file = fopen(bcs_input_filename,
"r");
938 if (!file) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN,
"Could not open BCs file '%s'.", bcs_input_filename);
940 while (fgets(line_buffer,
sizeof(line_buffer), file)) {
941 char *current_pos = line_buffer;
942 while (isspace((
unsigned char)*current_pos)) current_pos++;
943 if (*current_pos ==
'#' || *current_pos ==
'\0' || *current_pos ==
'\n' || *current_pos ==
'\r')
continue;
945 char *face_str = strtok(current_pos,
" \t\n\r");
946 char *type_str = strtok(NULL,
" \t\n\r");
947 char *handler_str = strtok(NULL,
" \t\n\r");
949 if (!face_str || !type_str || !handler_str) {
957 const char* handler_name_for_log;
964 if (ierr) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG,
"Validation failed: Handler '%s' is not valid for Type '%s' on Face '%s'.\n", handler_str, type_str, face_str);
970 LOG_ALLOW(
GLOBAL,
LOG_DEBUG,
" Parsed Face '%s': Type=%s, Handler=%s \n", face_str, type_str, handler_name_for_log);
974 configs_rank0[face_enum].
params = NULL;
978 while ((token = strtok(NULL,
" \t\n\r")) != NULL) {
979 char* equals_ptr = strchr(token,
'=');
986 char* key_str = token;
987 char* value_str = equals_ptr + 1;
990 ierr = PetscMalloc1(1, &new_param); CHKERRQ(ierr);
991 ierr = PetscStrallocpy(key_str, &new_param->
key); CHKERRQ(ierr);
992 ierr = PetscStrallocpy(value_str, &new_param->
value); CHKERRQ(ierr);
993 new_param->
next = NULL;
995 *param_next_ptr = new_param;
996 param_next_ptr = &new_param->
next;
1010 for (
int i = 0; i < 6; i++) {
1019 PetscInt n_params = 0;
1023 ierr = MPI_Bcast(&n_params, 1, MPIU_INT, 0, PETSC_COMM_WORLD);CHKERRQ(ierr);
1032 for (
int j = 0; j < n_params; j++) {
1033 char key_buf[256] = {0}, val_buf[256] = {0};
1037 for (
int k = 0; k < j; k++) p = p->
next;
1038 strncpy(key_buf, p->
key, 255);
1039 strncpy(val_buf, p->
value, 255);
1042 ierr = MPI_Bcast(key_buf, 256, MPI_CHAR, 0, PETSC_COMM_WORLD); CHKERRQ(ierr);
1043 ierr = MPI_Bcast(val_buf, 256, MPI_CHAR, 0, PETSC_COMM_WORLD); CHKERRQ(ierr);
1048 ierr = PetscMalloc1(1, &new_param); CHKERRQ(ierr);
1049 ierr = PetscStrallocpy(key_buf, &new_param->
key); CHKERRQ(ierr);
1050 ierr = PetscStrallocpy(val_buf, &new_param->
value); CHKERRQ(ierr);
1051 new_param->
next = NULL;
1052 *param_next_ptr = new_param;
1053 param_next_ptr = &new_param->
next;
1056 param_next_ptr = &((*param_next_ptr)->next);
1064 for (
int i=0; i<6; i++) {
1082 PetscFunctionReturn(0);
1098 PetscErrorCode ierr;
1100 PetscInt periodic_flags[3] = {0, 0, 0};
1102 PetscFunctionBeginUser;
1104 rank = simCtx->
rank;
1107 for (PetscInt bi = 0; bi < simCtx->
block_number; bi++) {
1108 const char *bcs_filename = simCtx->
bcs_files[bi];
1109 if (!bcs_filename) SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_NULL,
"BCS filename for block %" PetscInt_FMT
" is not set in SimCtx.", bi);
1111 PetscBool file_exists;
1112 snprintf(desc_buf,
sizeof(desc_buf),
"BCS file for block %" PetscInt_FMT
"", bi);
1113 ierr =
VerifyPathExistence(bcs_filename, PETSC_FALSE, PETSC_FALSE, desc_buf, &file_exists); CHKERRQ(ierr);
1118 PetscBool global_is_periodic[3] = {PETSC_FALSE, PETSC_FALSE, PETSC_FALSE};
1119 PetscBool is_set = PETSC_FALSE;
1121 for (PetscInt bi = 0; bi < simCtx->
block_number; bi++) {
1122 const char *bcs_filename = simCtx->
bcs_files[bi];
1123 FILE *file = fopen(bcs_filename,
"r");
1125 PetscBool face_is_periodic[6] = {PETSC_FALSE};
1126 char line_buffer[1024];
1128 while (fgets(line_buffer,
sizeof(line_buffer), file)) {
1129 char *current_pos = line_buffer;
1130 while (isspace((
unsigned char)*current_pos)) current_pos++;
1131 if (*current_pos ==
'#' || *current_pos ==
'\0' || *current_pos ==
'\n')
continue;
1134 char *face_str = strtok(current_pos,
" \t\n\r");
1135 char *type_str = strtok(NULL,
" \t\n\r");
1138 if (!face_str || !type_str)
continue;
1141 if (strcasecmp(type_str,
"PERIODIC") == 0) {
1145 face_is_periodic[face_enum] = PETSC_TRUE;
1153 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_INCOMP,
"Inconsistent X-periodicity in file '%s' for block %" PetscInt_FMT
". Both -Xi and +Xi must be periodic or neither.", bcs_filename, bi);
1155 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_INCOMP,
"Inconsistent Y-periodicity in file '%s' for block %" PetscInt_FMT
". Both -Eta and +Eta must be periodic or neither.", bcs_filename, bi);
1157 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_INCOMP,
"Inconsistent Z-periodicity in file '%s' for block %" PetscInt_FMT
". Both -Zeta and +Zeta must be periodic or neither.", bcs_filename, bi);
1163 global_is_periodic[0] = local_is_periodic[0];
1164 global_is_periodic[1] = local_is_periodic[1];
1165 global_is_periodic[2] = local_is_periodic[2];
1166 is_set = PETSC_TRUE;
1168 if (global_is_periodic[0] != local_is_periodic[0] || global_is_periodic[1] != local_is_periodic[1] || global_is_periodic[2] != local_is_periodic[2]) {
1169 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_INCOMP,
1170 "Periodicity mismatch between blocks. Block 0 requires (I:%d, J:%d, K:%d), but block %" PetscInt_FMT
" (file '%s') has (I:%d, J:%d, K:%d).",
1171 (
int)global_is_periodic[0], (
int)global_is_periodic[1], (
int)global_is_periodic[2],
1173 (
int)local_is_periodic[0], (
int)local_is_periodic[1], (
int)local_is_periodic[2]);
1178 periodic_flags[0] = (global_is_periodic[0]) ? 1 : 0;
1179 periodic_flags[1] = (global_is_periodic[1]) ? 1 : 0;
1180 periodic_flags[2] = (global_is_periodic[2]) ? 1 : 0;
1182 LOG_ALLOW(
GLOBAL,
LOG_INFO,
"Global periodicity determined: I-periodic=%" PetscInt_FMT
", J-periodic=%" PetscInt_FMT
", K-periodic=%" PetscInt_FMT
"\n",
1183 periodic_flags[0], periodic_flags[1], periodic_flags[2]);
1187 ierr = MPI_Bcast(periodic_flags, 3, MPIU_INT, 0, PETSC_COMM_WORLD); CHKERRQ(ierr);
1195 PetscFunctionReturn(0);
1202PetscErrorCode
VerifyPathExistence(
const char *path, PetscBool is_dir, PetscBool is_optional,
const char *description, PetscBool *exists)
1204 PetscErrorCode ierr;
1206 MPI_Comm comm = PETSC_COMM_WORLD;
1208 PetscFunctionBeginUser;
1210 ierr = MPI_Comm_rank(comm, &rank); CHKERRQ(ierr);
1214 ierr = PetscTestDirectory(path,
'r', exists); CHKERRQ(ierr);
1216 ierr = PetscTestFile(path,
'r', exists); CHKERRQ(ierr);
1231 PetscMPIInt exists_int = (rank == 0) ? (PetscMPIInt)(*exists) : 0;
1232 ierr = MPI_Bcast(&exists_int, 1, MPI_INT, 0, comm); CHKERRMPI(ierr);
1233 *exists = (PetscBool)exists_int;
1236 if (!(*exists) && !is_optional) {
1237 SETERRQ(comm, PETSC_ERR_FILE_OPEN,
"Mandatory %s not found. Rank 0 expected it at '%s'. Check path and permissions.", description, path);
1241 PetscFunctionReturn(0);
1249 const char *field_name,
1253 PetscErrorCode ierr;
1254 char filename[PETSC_MAX_PATH_LEN];
1256 PetscMPIInt rank,size;
1260 PetscFunctionBeginUser;
1264 SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,
"I/O context directory was not set before calling ReadFieldData().");
1268 ierr = PetscObjectGetComm((PetscObject)field_vec,&comm);CHKERRQ(ierr);
1269 ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr);
1270 ierr = MPI_Comm_size(comm,&size);CHKERRQ(ierr);
1273 ierr = PetscSNPrintf(filename,
sizeof(filename),
"%s/%s.%s",
1274 source_path, field_name, ext); CHKERRQ(ierr);
1278 PetscBool found = PETSC_FALSE;
1279 if (rank == 0) { ierr = PetscTestFile(filename,
'r', &found); CHKERRQ(ierr); }
1280 ierr = MPI_Bcast(&found, 1, MPIU_BOOL, 0, comm); CHKERRMPI(ierr);
1281 if (!found) SETERRQ(comm, PETSC_ERR_FILE_OPEN,
"Restart/Source file not found: %s", filename);
1288 PetscViewer viewer = NULL;
1290 const PetscBool natural = (PetscBool)(dm != NULL);
1291 if (natural) { ierr = DMDACreateNaturalVector(dm, &staged); CHKERRQ(ierr); }
1292 else { ierr = VecDuplicate(field_vec, &staged); CHKERRQ(ierr); }
1294 ierr = VecLoad(staged, viewer);
1296 ierr = PetscViewerDestroy(&viewer); CHKERRQ(ierr);
1297 ierr = VecDestroy(&staged); CHKERRQ(ierr);
1298 SETERRQ(comm, PETSC_ERR_FILE_UNEXPECTED,
"Could not load '%s' into field '%s'.", filename, field_name);
1300 ierr = PetscViewerDestroy(&viewer); CHKERRQ(ierr);
1302 ierr = DMDANaturalToGlobalBegin(dm, staged, INSERT_VALUES, field_vec); CHKERRQ(ierr);
1303 ierr = DMDANaturalToGlobalEnd(dm, staged, INSERT_VALUES, field_vec); CHKERRQ(ierr);
1305 ierr = VecCopy(staged, field_vec); CHKERRQ(ierr);
1307 ierr = VecDestroy(&staged); CHKERRQ(ierr);
1312 PetscFunctionReturn(0);
1335 const char *checkpoint_directory)
1337 char metadata_path[PETSC_MAX_PATH_LEN];
1338 PetscOptions options = NULL;
1339 PetscBool uses_initial_flux = PETSC_FALSE;
1340 PetscBool saved_latched = PETSC_FALSE;
1341 PetscBool found = PETSC_FALSE;
1342 PetscReal saved_target = 0.0;
1344 PetscFunctionBeginUser;
1347 for (PetscInt face = 0; face < 6; ++face) {
1349 uses_initial_flux = PETSC_TRUE;
1355 PetscCall(PetscSNPrintf(metadata_path,
sizeof(metadata_path),
1356 "%s/checkpoint.meta", checkpoint_directory));
1357 PetscCall(PetscOptionsCreate(&options));
1358 PetscCall(PetscOptionsInsertFile(PETSC_COMM_WORLD, options, metadata_path, PETSC_TRUE));
1359 PetscCall(PetscOptionsGetBool(options, NULL,
"-checkpoint_driven_flux_latched", &saved_latched, &found));
1360 if (found && saved_latched) {
1361 PetscCall(PetscOptionsGetReal(options, NULL,
"-checkpoint_driven_flux_target", &saved_target, &found));
1363 found = PETSC_FALSE;
1365 PetscCall(PetscOptionsDestroy(&options));
1371 "Driven Flow: restored latched target volumetric flux %.6e from checkpoint '%s'.\n",
1372 (
double)saved_target, checkpoint_directory);
1375 "Driven Flow: checkpoint '%s' records no latched flux target; the initial_flux "
1376 "controller will re-measure it from the restarted field.\n", checkpoint_directory);
1380 PetscFunctionReturn(0);
1390 const char *source_path = NULL;
1391 char checkpoint_directory[PETSC_MAX_PATH_LEN];
1392 PetscReal checkpoint_time = 0.0;
1393 PetscBool particles_saved = PETSC_FALSE;
1394 PetscBool les_saved = PETSC_FALSE;
1395 PetscBool inflow_saved = PETSC_FALSE;
1397 PetscFunctionBeginUser;
1404 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE,
"Invalid execution mode for reading simulation fields.");
1408 checkpoint_directory,
sizeof(checkpoint_directory)));
1410 checkpoint_directory, ti, &checkpoint_time, NULL,
1411 &particles_saved, &les_saved, &inflow_saved));
1413 PETSC_COMM_WORLD, PETSC_ERR_FILE_UNEXPECTED,
1414 "Particle restart_mode=load was requested, but checkpoint step %" PetscInt_FMT
1415 " contains no particle state.", ti);
1417 simCtx->
ti = checkpoint_time;
1423 user->
_this, checkpoint_directory);
1425 "%s/%s/block_%04" PetscInt_FMT,
1438 (!particles_saved ||
1447 !(simCtx->
les && les_saved))
continue;
1457 PetscReal scale = 1.0;
1460 if (scale != 1.0) PetscCall(VecScale(view.
global_vec, scale));
1467 PetscFunctionReturn(0);
1473 const char *metadata_path, PetscReal checkpoint_time,
1477 char option_name[128];
1479 char saved_digest[65] =
"";
1481 char saved_state[32] =
"";
1482 char current_digest[65] =
"";
1483 PetscBool found = PETSC_FALSE;
1484 PetscBool name_matches = PETSC_FALSE;
1486 PetscFunctionBeginUser;
1489#define PICURV_STATISTICS_REQUIRE(suffix, getter, target) \
1491 PetscCall(PetscSNPrintf(option_name, sizeof(option_name), \
1492 "-checkpoint_statistics_window_%" PetscInt_FMT "_" suffix, window)); \
1493 PetscCall(getter(options, NULL, option_name, target, &found)); \
1494 PetscCheck(found, PETSC_COMM_WORLD, PETSC_ERR_FILE_UNEXPECTED, \
1495 "Statistics continuation requested, but '%s' records no %s for window " \
1496 "%" PetscInt_FMT ".", metadata_path, suffix, window); \
1499 PetscCall(PetscSNPrintf(option_name,
sizeof(option_name),
1500 "-checkpoint_statistics_window_%" PetscInt_FMT
"_name", window));
1501 PetscCall(PetscOptionsGetString(options, NULL, option_name, saved_name,
sizeof(saved_name), &found));
1502 PetscCheck(found, PETSC_COMM_WORLD, PETSC_ERR_FILE_UNEXPECTED,
1503 "Statistics continuation requested, but '%s' records no name for window %" PetscInt_FMT
".",
1504 metadata_path, window);
1505 PetscCall(PetscStrcmp(saved_name, state->
definition.
name, &name_matches));
1506 PetscCheck(name_matches, PETSC_COMM_WORLD, PETSC_ERR_ARG_INCOMP,
1507 "Statistics window %" PetscInt_FMT
" is '%s' in the checkpoint but '%s' in this run. "
1508 "Window order and names must match to continue.",
1511 PetscCall(PetscSNPrintf(option_name,
sizeof(option_name),
1512 "-checkpoint_statistics_window_%" PetscInt_FMT
"_hash", window));
1513 PetscCall(PetscOptionsGetString(options, NULL, option_name, saved_digest,
sizeof(saved_digest), &found));
1514 PetscCheck(found, PETSC_COMM_WORLD, PETSC_ERR_FILE_UNEXPECTED,
1515 "Statistics continuation requested, but '%s' records no hash for window '%s'.",
1518 if (strcmp(saved_digest, current_digest)) {
1519 const char *differing =
"an unrecorded property";
1524 PetscCall(PetscSNPrintf(option_name,
sizeof(option_name),
1525 "-checkpoint_statistics_window_%" PetscInt_FMT
"_hash_groups", window));
1526 PetscCall(PetscOptionsGetString(options, NULL, option_name, saved_groups,
1527 sizeof(saved_groups), &found));
1529 PetscInt group = -1;
1534 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_INCOMP,
1535 "Statistics window '%s' was defined differently in the checkpoint: %s changed. "
1536 "Continuing would merge incompatible samples; rename the window to start a new one.",
1550#undef PICURV_STATISTICS_REQUIRE
1552 PetscCall(PetscSNPrintf(option_name,
sizeof(option_name),
1553 "-checkpoint_statistics_window_%" PetscInt_FMT
"_state", window));
1554 PetscCall(PetscOptionsGetString(options, NULL, option_name, saved_state,
sizeof(saved_state), &found));
1555 PetscCheck(found, PETSC_COMM_WORLD, PETSC_ERR_FILE_UNEXPECTED,
1556 "Statistics continuation requested, but '%s' records no lifecycle state for window '%s'.",
1570 PetscCheck(checkpoint_time - state->
effective_end <= PetscMax(step_size, 0.0),
1571 PETSC_COMM_WORLD, PETSC_ERR_ARG_INCOMP,
1572 "Statistics window '%s' ended at t=%.17g and this checkpoint is at t=%.17g, "
1573 "so extending it to %.17g would weight %.17g of unobserved time. "
1574 "Start a new window instead.",
1579 "Statistics window '%s' was complete at t=%.6g and is extended to t=%.6g.\n",
1585 PETSC_COMM_WORLD, PETSC_ERR_ARG_INCOMP,
1586 "Statistics window '%s' already represents time up to %.17g, past the requested end "
1587 "%.17g. A window may be extended forward but never shortened; rename it to start a new one.",
1595 PetscFunctionReturn(0);
1607 PetscOptions options = NULL;
1608 char checkpoint_directory[PETSC_MAX_PATH_LEN];
1609 char metadata_path[PETSC_MAX_PATH_LEN];
1610 const char *source_path = NULL;
1611 PetscInt saved_window_count = 0;
1612 PetscReal checkpoint_time = 0.0;
1613 PetscBool found = PETSC_FALSE;
1615 PetscFunctionBeginUser;
1617 PetscCheck(simCtx != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"SimCtx cannot be NULL.");
1621 "Statistics continuation was not requested; %" PetscInt_FMT
" window(s) start from zero.\n",
1624 PetscFunctionReturn(0);
1631 PetscCheck(user != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE,
1632 "Finest-level fields must exist before statistics state is restored.");
1636 PetscCheck(source_path != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE,
1637 "No checkpoint source directory is set for the current execution mode.");
1639 checkpoint_directory,
sizeof(checkpoint_directory)));
1641 &checkpoint_time, NULL, NULL, NULL, NULL));
1642 PetscCall(PetscSNPrintf(metadata_path,
sizeof(metadata_path),
"%s/checkpoint.meta",
1643 checkpoint_directory));
1645 PetscCall(PetscOptionsCreate(&options));
1646 PetscCall(PetscOptionsInsertFile(PETSC_COMM_WORLD, options, metadata_path, PETSC_TRUE));
1647 PetscCall(PetscOptionsGetInt(options, NULL,
"-checkpoint_statistics_window_count",
1648 &saved_window_count, &found));
1653 PETSC_COMM_WORLD, PETSC_ERR_ARG_INCOMP,
1654 "Statistics continuation requested, but checkpoint '%s' holds %" PetscInt_FMT
1655 " window(s) and this run configures %" PetscInt_FMT
".",
1656 checkpoint_directory, found ? saved_window_count : 0,
1664 PetscCall(PetscOptionsDestroy(&options));
1666 LOG_ALLOW(
GLOBAL,
LOG_INFO,
"Statistics continuation check passed: %" PetscInt_FMT
" window(s) can continue from '%s'.\n",
1669 PetscFunctionReturn(0);
1672 for (PetscInt block = 0; block < simCtx->
block_number; ++block) {
1673 PetscCheck(user[block].fieldStatisticsStorage != NULL, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONGSTATE,
1674 "Statistics accumulators were not allocated for block %" PetscInt_FMT
".", block);
1678 PetscInt payload_count = 0;
1685 for (PetscInt index = 0; index < payload_count; ++index) {
1699 "Statistics window '%s' continued from '%s': state %s, %" PetscInt_FMT
" sample(s), "
1700 "total weight %.6g, represented time %.6g, restart segment %" PetscInt_FMT
".\n",
1707 PetscFunctionReturn(0);
1716 PetscErrorCode ierr;
1723 swarm = user->
swarm;
1728 ierr = DMSwarmCreateGlobalVectorFromField(swarm, field_name, &fieldVec);CHKERRQ(ierr);
1733 ierr =
ReadFieldData(user, field_name, fieldVec, ext);CHKERRQ(ierr);
1736 ierr = DMSwarmDestroyGlobalVectorFromField(swarm, field_name, &fieldVec);CHKERRQ(ierr);
1739 PetscFunctionReturn(0);
1748 PetscErrorCode ierr;
1749 DM swarm = user->
swarm;
1751 PetscInt nlocal, nglobal, bs, i;
1752 PetscDataType field_type;
1753 const PetscScalar *scalar_array;
1754 void *field_array_void;
1757 PetscFunctionBeginUser;
1763 ierr = DMSwarmGetLocalSize(swarm, &nlocal); CHKERRQ(ierr);
1764 ierr = DMSwarmGetSize(swarm, &nglobal); CHKERRQ(ierr);
1766 ierr = DMSwarmGetField(swarm, field_name, &bs, &field_type, NULL); CHKERRQ(ierr);
1767 ierr = DMSwarmRestoreField(swarm, field_name, &bs, NULL, NULL); CHKERRQ(ierr);
1768 PetscCheck(field_type == PETSC_INT || field_type == PETSC_INT64,
1769 PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG,
1770 "Swarm field '%s' must use PETSC_INT or PETSC_INT64 for integer restart input, not %s.",
1771 field_name, PetscDataTypes[field_type]);
1774 ierr = VecCreate(PETSC_COMM_WORLD, &temp_vec); CHKERRQ(ierr);
1775 ierr = VecSetType(temp_vec, VECMPI); CHKERRQ(ierr);
1776 ierr = VecSetSizes(temp_vec, nlocal * bs, nglobal * bs); CHKERRQ(ierr);
1777 ierr = VecSetBlockSize(temp_vec, bs); CHKERRQ(ierr);
1778 ierr = VecSetUp(temp_vec); CHKERRQ(ierr);
1781 ierr =
ReadFieldData(user, field_name, temp_vec, ext); CHKERRQ(ierr);
1784 ierr = VecGetArrayRead(temp_vec, &scalar_array); CHKERRQ(ierr);
1785 ierr = DMSwarmGetField(swarm, field_name, NULL, NULL, &field_array_void); CHKERRQ(ierr);
1788 if (field_type == PETSC_INT64) {
1789 PetscInt64 *int64_array = (PetscInt64 *)field_array_void;
1790 for (i = 0; i < nlocal * bs; i++) {
1791 int64_array[i] = (PetscInt64)scalar_array[i];
1794 PetscInt *int_array = (PetscInt *)field_array_void;
1795 for (i = 0; i < nlocal * bs; i++) {
1796 int_array[i] = (PetscInt)scalar_array[i];
1801 ierr = DMSwarmRestoreField(swarm, field_name, NULL, NULL, &field_array_void); CHKERRQ(ierr);
1802 ierr = VecRestoreArrayRead(temp_vec, &scalar_array); CHKERRQ(ierr);
1805 ierr = VecDestroy(&temp_vec); CHKERRQ(ierr);
1808 PetscFunctionReturn(0);
1819 const char *source_path = NULL;
1820 char checkpoint_directory[PETSC_MAX_PATH_LEN];
1822 PetscFunctionBeginUser;
1824 PetscCall(DMSwarmGetSize(user->
swarm, &nGlobal));
1825 LOG_ALLOW(
GLOBAL,
LOG_INFO,
"Reading DMSwarm fields for timestep %" PetscInt_FMT
" (swarm size is %" PetscInt_FMT
").\n", ti, nGlobal);
1830 PetscFunctionReturn(0);
1839 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONGSTATE,
"Invalid execution mode for reading simulation fields.");
1843 checkpoint_directory,
sizeof(checkpoint_directory)));
1864 PetscFunctionReturn(0);
1871 const char *source_path = NULL;
1872 char checkpoint_directory[PETSC_MAX_PATH_LEN];
1873 PetscBool particles_saved = PETSC_FALSE;
1875 PetscFunctionBeginUser;
1877 PetscCheck(user != NULL && particle_count != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
1878 "Simulation context and particle-count output are required.");
1882 else SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONGSTATE,
1883 "Invalid execution mode for reading checkpoint particle metadata.");
1886 checkpoint_directory,
sizeof(checkpoint_directory)));
1888 checkpoint_directory, ti, NULL, particle_count,
1889 &particles_saved, NULL, NULL));
1890 PetscCheck(particles_saved, PETSC_COMM_WORLD, PETSC_ERR_FILE_UNEXPECTED,
1891 "Checkpoint step %" PetscInt_FMT
" contains no particle state.", ti);
1893 PetscFunctionReturn(0);
1902 const char *field_name,
1907 Vec natural_vec = NULL, ordered_vec = NULL;
1909 char filename[PETSC_MAX_PATH_LEN];
1912 PetscFunctionBeginUser;
1916 SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,
"I/O context directory was not set before calling WriteFieldData().");
1922 PetscCall(PetscObjectGetComm((PetscObject)field_vec,&comm));
1924 PetscCall(PetscSNPrintf(filename,
sizeof(filename),
"%s/%s.%s",
1932 PetscReal vmin, vmax;
1934 PetscCall(VecMin(ordered_vec, NULL, &vmin));
1935 PetscCall(VecMax(ordered_vec, NULL, &vmax));
1939 PetscCall(VecView(ordered_vec, viewer));
1940 PetscCall(PetscViewerDestroy(&viewer));
1941 PetscCall(VecDestroy(&natural_vec));
1945 PetscFunctionReturn(0);
1958 PetscFunctionBeginUser;
1960 PetscCheck(checkpoint_directory != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
1961 "Checkpoint destination cannot be NULL.");
1963 "%s/%s/block_%04" PetscInt_FMT,
1985 PetscFunctionReturn(0);
1993 PetscFunctionBeginUser;
1995 PetscCheck(checkpoint_directory != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
1996 "Checkpoint destination cannot be NULL.");
2001 PetscInt payload_count = 0;
2008 for (PetscInt index = 0; index < payload_count; ++index) {
2012 storage, index, &payload));
2016 "Wrote %d statistics payload(s) for window '%s' block %d.\n",
2022 PetscFunctionReturn(0);
2033 PetscErrorCode ierr;
2037 PetscFunctionBeginUser;
2044 swarm = user->
swarm;
2052 "Attempting to create global vector from field: %s\n",
2054 ierr = DMSwarmCreateGlobalVectorFromField(swarm, field_name, &fieldVec);CHKERRQ(ierr);
2061 "Calling WriteFieldData for field: %s\n",
2063 ierr =
WriteFieldData(user, field_name, fieldVec, ext);CHKERRQ(ierr);
2071 "Destroying the global vector for field: %s\n",
2073 ierr = DMSwarmDestroyGlobalVectorFromField(swarm, field_name, &fieldVec);CHKERRQ(ierr);
2077 "Successfully wrote swarm data for field: %s\n",
2081 PetscFunctionReturn(0);
2090 PetscErrorCode ierr;
2091 DM swarm = user->
swarm;
2093 PetscInt nlocal, nglobal,bs,i;
2094 PetscDataType field_type;
2095 void *field_array_void;
2096 PetscScalar *scalar_array;
2098 PetscFunctionBeginUser;
2104 ierr = DMSwarmGetLocalSize(swarm, &nlocal); CHKERRQ(ierr);
2105 ierr = DMSwarmGetSize(swarm, &nglobal); CHKERRQ(ierr);
2106 ierr = DMSwarmGetField(swarm, field_name, &bs, &field_type, &field_array_void); CHKERRQ(ierr);
2107 PetscCheck(field_type == PETSC_INT || field_type == PETSC_INT64,
2108 PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG,
2109 "Swarm field '%s' must use PETSC_INT or PETSC_INT64 for integer output, not %s.",
2110 field_name, PetscDataTypes[field_type]);
2113 ierr = VecCreate(PETSC_COMM_WORLD, &temp_vec); CHKERRQ(ierr);
2114 ierr = VecSetType(temp_vec, VECMPI); CHKERRQ(ierr);
2115 ierr = VecSetSizes(temp_vec, nlocal*bs, nglobal*bs); CHKERRQ(ierr);
2116 ierr = VecSetUp(temp_vec); CHKERRQ(ierr);
2121 ierr = VecGetArray(temp_vec, &scalar_array); CHKERRQ(ierr);
2123 if (field_type == PETSC_INT64) {
2124 PetscInt64 *int64_array = (PetscInt64 *)field_array_void;
2126 for (i = 0; i < nlocal*bs; i++) {
2127 scalar_array[i] = (PetscScalar)int64_array[i];
2130 PetscInt *int_array = (PetscInt *)field_array_void;
2132 for (i = 0; i < nlocal*bs; i++) {
2133 scalar_array[i] = (PetscScalar)int_array[i];
2138 ierr = VecRestoreArray(temp_vec, &scalar_array); CHKERRQ(ierr);
2139 ierr = DMSwarmRestoreField(swarm, field_name, &bs, NULL, &field_array_void); CHKERRQ(ierr);
2142 ierr =
WriteFieldData(user, field_name, temp_vec, ext); CHKERRQ(ierr);
2145 ierr = VecDestroy(&temp_vec); CHKERRQ(ierr);
2148 PetscFunctionReturn(0);
2159 PetscFunctionBeginUser;
2165 PetscFunctionReturn(0);
2168 PetscCheck(checkpoint_directory != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
2169 "Checkpoint destination cannot be NULL.");
2189 PetscFunctionReturn(0);
2194 const char *checkpoint_directory,
2195 PetscInt payload_index,
2196 const char *relative_path,
2198 const char *field_name,
2201 PetscInt components,
2202 const char *logical_type,
2203 PetscInt global_size,
2204 const char *encoding)
2206 char payload_path[PETSC_MAX_PATH_LEN];
2207 struct stat payload_stat;
2209 PetscFunctionBeginUser;
2211 PetscCheck(manifest != NULL && checkpoint_directory != NULL && relative_path != NULL,
2212 PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"Checkpoint payload metadata inputs are required.");
2213 PetscCall(PetscSNPrintf(payload_path,
sizeof(payload_path),
"%s/%s",
2214 checkpoint_directory, relative_path));
2215 PetscCheck(stat(payload_path, &payload_stat) == 0 && S_ISREG(payload_stat.st_mode),
2216 PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN,
2217 "Expected checkpoint payload was not written: %s", payload_path);
2218 PetscCheck(fprintf(manifest,
2219 "-checkpoint_payload_%" PetscInt_FMT
"_path %s\n"
2220 "-checkpoint_payload_%" PetscInt_FMT
"_kind %s\n"
2221 "-checkpoint_payload_%" PetscInt_FMT
"_field %s\n"
2222 "-checkpoint_payload_%" PetscInt_FMT
"_block %" PetscInt_FMT
"\n"
2223 "-checkpoint_payload_%" PetscInt_FMT
"_layout %s\n"
2224 "-checkpoint_payload_%" PetscInt_FMT
"_components %" PetscInt_FMT
"\n"
2225 "-checkpoint_payload_%" PetscInt_FMT
"_logical_type %s\n"
2226 "-checkpoint_payload_%" PetscInt_FMT
"_global_size %" PetscInt_FMT
"\n"
2227 "-checkpoint_payload_%" PetscInt_FMT
"_encoding %s\n"
2228 "-checkpoint_payload_%" PetscInt_FMT
"_bytes %lld\n",
2229 payload_index, relative_path,
2230 payload_index, kind,
2231 payload_index, field_name,
2232 payload_index, block,
2233 payload_index, layout,
2234 payload_index, components,
2235 payload_index, logical_type,
2236 payload_index, global_size,
2237 payload_index, encoding,
2238 payload_index, (
long long)payload_stat.st_size) > 0,
2239 PETSC_COMM_SELF, PETSC_ERR_FILE_WRITE,
2240 "Unable to append payload metadata for '%s'.", relative_path);
2242 PetscFunctionReturn(0);
2247 const char *checkpoint_directory,
2249 const char *geometry_digest,
2250 PetscInt particle_count,
2251 char manifest_digest[65])
2253 char metadata_path[PETSC_MAX_PATH_LEN];
2254 PetscInt payload_count = 0;
2255 PetscInt payload_index = 0;
2256 FILE *manifest = NULL;
2258 PetscFunctionBeginUser;
2260 for (PetscInt block = 0; block < simCtx->
block_number; ++block) {
2275 for (PetscInt block = 0; block < simCtx->
block_number; ++block) {
2276 if (!user[block].fieldStatisticsStorage)
continue;
2278 PetscInt storage_payloads = 0;
2281 &storage_payloads));
2282 payload_count += storage_payloads;
2287 if (simCtx->
rank == 0) {
2288 PetscCall(PetscSNPrintf(metadata_path,
sizeof(metadata_path),
2289 "%s/checkpoint.meta", checkpoint_directory));
2290 manifest = fopen(metadata_path,
"w");
2291 PetscCheck(manifest != NULL, PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN,
2292 "Unable to create checkpoint metadata '%s'.", metadata_path);
2293 PetscCheck(fprintf(manifest,
2294 "-checkpoint_format %s\n"
2295 "-checkpoint_version %d\n"
2296 "-checkpoint_picurv_release %s\n"
2297 "-checkpoint_picurv_commit %s\n"
2298 "-checkpoint_picurv_dirty %s\n"
2299 "-checkpoint_petsc_index_bytes %d\n"
2300 "-checkpoint_step %" PetscInt_FMT
"\n"
2301 "-checkpoint_time %.17g\n"
2302 "-checkpoint_dt %.17g\n"
2303 "-checkpoint_reason %s\n"
2304 "-checkpoint_geometry_sha256 %s\n"
2305 "-checkpoint_block_count %" PetscInt_FMT
"\n"
2306 "-checkpoint_particles %s\n"
2307 "-checkpoint_particle_count %" PetscInt_FMT
"\n"
2308 "-checkpoint_les %s\n"
2309 "-checkpoint_inflow_fluctuation %s\n"
2310 "-checkpoint_payload_count %" PetscInt_FMT
"\n",
2313 (
int)
sizeof(PetscInt), simCtx->
step, (
double)simCtx->
ti, (
double)simCtx->
dt,
2317 simCtx->
les ?
"true" :
"false",
2320 PETSC_COMM_SELF, PETSC_ERR_FILE_WRITE,
2321 "Unable to write checkpoint metadata '%s'.", metadata_path);
2323 for (PetscInt block = 0; block < simCtx->
block_number; ++block) {
2324 PetscCheck(fprintf(manifest,
2325 "-checkpoint_block_%" PetscInt_FMT
"_im %" PetscInt_FMT
"\n"
2326 "-checkpoint_block_%" PetscInt_FMT
"_jm %" PetscInt_FMT
"\n"
2327 "-checkpoint_block_%" PetscInt_FMT
"_km %" PetscInt_FMT
"\n",
2328 block, user[block].IM, block, user[block].JM, block, user[block].KM) > 0,
2329 PETSC_COMM_SELF, PETSC_ERR_FILE_WRITE,
2330 "Unable to write block metadata for block %" PetscInt_FMT
".", block);
2332 PetscCheck(fprintf(manifest,
"-checkpoint_periodic %d,%d,%d\n",
2335 PETSC_COMM_SELF, PETSC_ERR_FILE_WRITE,
2336 "Unable to write checkpoint periodicity metadata.");
2341 PetscCheck(fprintf(manifest,
2342 "-checkpoint_driven_flux_latched %s\n"
2343 "-checkpoint_driven_flux_target %.17g\n",
2346 PETSC_COMM_SELF, PETSC_ERR_FILE_WRITE,
2347 "Unable to write driven-flow controller metadata.");
2351 PetscCheck(fprintf(manifest,
"-checkpoint_statistics_window_count %" PetscInt_FMT
"\n",
2353 PETSC_COMM_SELF, PETSC_ERR_FILE_WRITE,
2354 "Unable to write statistics window count.");
2358 char digest[65] =
"";
2367 PetscCall(PetscStrlen(group_list, &used));
2368 PetscCall(PetscSNPrintf(group_list + used,
sizeof(group_list) - used,
"%s%s",
2369 group ?
"," :
"", groups[group]));
2371 PetscCheck(fprintf(manifest,
2372 "-checkpoint_statistics_window_%" PetscInt_FMT
"_name %s\n"
2373 "-checkpoint_statistics_window_%" PetscInt_FMT
"_hash %s\n"
2374 "-checkpoint_statistics_window_%" PetscInt_FMT
"_hash_groups %s\n"
2375 "-checkpoint_statistics_window_%" PetscInt_FMT
"_state %s\n"
2376 "-checkpoint_statistics_window_%" PetscInt_FMT
"_sample_count %" PetscInt_FMT
"\n"
2377 "-checkpoint_statistics_window_%" PetscInt_FMT
"_total_weight %.17g\n"
2378 "-checkpoint_statistics_window_%" PetscInt_FMT
"_represented_time %.17g\n"
2379 "-checkpoint_statistics_window_%" PetscInt_FMT
"_last_accepted_time %.17g\n"
2380 "-checkpoint_statistics_window_%" PetscInt_FMT
"_effective_start %.17g\n"
2381 "-checkpoint_statistics_window_%" PetscInt_FMT
"_effective_end %.17g\n"
2382 "-checkpoint_statistics_window_%" PetscInt_FMT
"_activation_step %" PetscInt_FMT
"\n"
2383 "-checkpoint_statistics_window_%" PetscInt_FMT
"_last_event_step %" PetscInt_FMT
"\n"
2384 "-checkpoint_statistics_window_%" PetscInt_FMT
"_next_time_target %" PetscInt_FMT
"\n"
2385 "-checkpoint_statistics_window_%" PetscInt_FMT
"_restart_count %" PetscInt_FMT
"\n",
2400 PETSC_COMM_SELF, PETSC_ERR_FILE_WRITE,
2401 "Unable to write metadata for statistics window '%s'.",
2406 for (PetscInt block = 0; block < simCtx->
block_number; ++block) {
2410 PetscInt global_size = 0;
2411 char relative_path[PETSC_MAX_PATH_LEN];
2416 PetscCall(VecGetSize(view.
global_vec, &global_size));
2417 PetscCall(PetscSNPrintf(relative_path,
sizeof(relative_path),
2418 "%s/block_%04" PetscInt_FMT
"/%s.dat",
2421 payload_index++, relative_path,
2424 descriptor->
dof,
"PetscScalar", global_size,
2425 "petsc_vec_binary_natural"));
2431 char relative_path[PETSC_MAX_PATH_LEN];
2432 const char *encoding =
"petsc_vec_binary_global";
2437 encoding =
"petsc_vec_binary_scalar_cast";
2439 PetscCall(PetscSNPrintf(relative_path,
sizeof(relative_path),
2443 payload_index++, relative_path,
2452 for (PetscInt block = 0; block < simCtx->
block_number; ++block) {
2453 if (!user[block].fieldStatisticsStorage)
continue;
2458 PetscInt storage_payloads = 0;
2461 for (PetscInt index = 0; index < storage_payloads; ++index) {
2463 PetscInt global_size = 0;
2464 char relative_path[PETSC_MAX_PATH_LEN];
2465 char qualified_name[PETSC_MAX_PATH_LEN];
2469 PetscCall(VecGetSize(payload.
vec, &global_size));
2471 relative_path,
sizeof(relative_path)));
2475 PetscCall(PetscSNPrintf(qualified_name,
sizeof(qualified_name),
"%s/%s",
2478 payload_index++, relative_path,
2479 payload.
role, qualified_name,
2483 "petsc_vec_binary_natural"));
2488 PetscCheck(fflush(manifest) == 0 && fsync(fileno(manifest)) == 0,
2489 PETSC_COMM_SELF, PETSC_ERR_FILE_WRITE,
2490 "Unable to flush checkpoint metadata '%s'.", metadata_path);
2491 PetscCheck(fclose(manifest) == 0, PETSC_COMM_SELF, PETSC_ERR_FILE_WRITE,
2492 "Unable to close checkpoint metadata '%s'.", metadata_path);
2495 PetscCallMPI(MPI_Bcast(manifest_digest, 65, MPI_CHAR, 0, PETSC_COMM_WORLD));
2497 PetscFunctionReturn(0);
2504 char checkpoints_root[PETSC_MAX_PATH_LEN];
2505 char final_directory[PETSC_MAX_PATH_LEN];
2506 char temporary_directory[PETSC_MAX_PATH_LEN];
2507 char nested_directory[PETSC_MAX_PATH_LEN];
2508 char commit_path[PETSC_MAX_PATH_LEN];
2509 char geometry_digest[65] =
"";
2510 char manifest_digest[65] =
"";
2511 PetscBool final_exists = PETSC_FALSE;
2512 PetscInt particle_count = 0;
2513 PetscMPIInt writer_pid = 0;
2515 PetscFunctionBeginUser;
2517 PetscCheck(simCtx != NULL && reason != NULL && reason[0] !=
'\0',
2518 PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
2519 "Simulation context and checkpoint reason are required.");
2522 if ((simCtx->
skipInitialCheckpoint && (strcmp(reason,
"initial") == 0 || strcmp(reason,
"branch_start") == 0)) ||
2524 LOG_ALLOW(
GLOBAL,
LOG_INFO,
"Skipping the %s checkpoint at step %" PetscInt_FMT
" (io.write_%s_checkpoint is false).\n",
2525 reason, simCtx->
step, strcmp(reason,
"final") == 0 ?
"final" :
"initial");
2527 PetscFunctionReturn(0);
2530 PetscCheck(user != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE,
2531 "Finest-level fields must exist before checkpoint output.");
2533 PetscCall(PetscSNPrintf(checkpoints_root,
sizeof(checkpoints_root),
"%s/%s",
2536 final_directory,
sizeof(final_directory)));
2537 PetscCall(PetscTestDirectory(final_directory,
'r', &final_exists));
2539 PetscReal saved_time = 0.0;
2541 &saved_time, NULL, NULL, NULL, NULL));
2542 PetscCheck(PetscAbsReal(saved_time - simCtx->
ti) <=
2543 10.0 * PETSC_MACHINE_EPSILON * PetscMax(1.0, PetscAbsReal(simCtx->
ti)),
2544 PETSC_COMM_WORLD, PETSC_ERR_FILE_UNEXPECTED,
2545 "Committed checkpoint step %" PetscInt_FMT
" has time %.17g, current state has time %.17g.",
2546 simCtx->
step, (
double)saved_time, (
double)simCtx->
ti);
2547 LOG_ALLOW(
GLOBAL,
LOG_DEBUG,
"Checkpoint step %" PetscInt_FMT
" is already committed; skipping duplicate write.\n",
2550 PetscFunctionReturn(0);
2553 if (simCtx->
rank == 0) writer_pid = (PetscMPIInt)getpid();
2554 PetscCallMPI(MPI_Bcast(&writer_pid, 1, MPI_INT, 0, PETSC_COMM_WORLD));
2555 PetscCall(PetscSNPrintf(temporary_directory,
sizeof(temporary_directory),
2556 "%s/.step_%0*" PetscInt_FMT
".incomplete.%d",
2558 simCtx->
step, (
int)writer_pid));
2561 PetscCall(PetscSNPrintf(nested_directory,
sizeof(nested_directory),
"%s/%s",
2564 for (PetscInt block = 0; block < simCtx->
block_number; ++block) {
2565 PetscCall(PetscSNPrintf(nested_directory,
sizeof(nested_directory),
2566 "%s/%s/block_%04" PetscInt_FMT,
2571 PetscCall(PetscSNPrintf(nested_directory,
sizeof(nested_directory),
"%s/%s",
2574 PetscCall(DMSwarmGetSize(user->
swarm, &particle_count));
2578 nested_directory,
sizeof(nested_directory)));
2582 nested_directory,
sizeof(nested_directory)));
2584 for (PetscInt block = 0; block < simCtx->
block_number; ++block) {
2586 nested_directory,
sizeof(nested_directory)));
2593 for (PetscInt block = 0; block < simCtx->
block_number; ++block) {
2597 for (PetscInt block = 0; block < simCtx->
block_number; ++block) {
2600 PetscCallMPI(MPI_Barrier(PETSC_COMM_WORLD));
2603 geometry_digest, particle_count, manifest_digest));
2604 if (simCtx->
rank == 0) {
2605 FILE *commit_file = NULL;
2607 PetscCall(PetscSNPrintf(commit_path,
sizeof(commit_path),
"%s/COMMITTED", temporary_directory));
2608 commit_file = fopen(commit_path,
"w");
2609 PetscCheck(commit_file != NULL, PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN,
2610 "Unable to create checkpoint commit marker '%s'.", commit_path);
2611 PetscCheck(fprintf(commit_file,
"%s\n", manifest_digest) > 0 &&
2612 fflush(commit_file) == 0 && fsync(fileno(commit_file)) == 0,
2613 PETSC_COMM_SELF, PETSC_ERR_FILE_WRITE,
2614 "Unable to write checkpoint commit marker '%s'.", commit_path);
2615 PetscCheck(fclose(commit_file) == 0, PETSC_COMM_SELF, PETSC_ERR_FILE_WRITE,
2616 "Unable to close checkpoint commit marker '%s'.", commit_path);
2617 PetscCheck(rename(temporary_directory, final_directory) == 0,
2618 PETSC_COMM_SELF, PETSC_ERR_FILE_WRITE,
2619 "Unable to commit checkpoint '%s': %s", final_directory, strerror(errno));
2621 PetscCallMPI(MPI_Barrier(PETSC_COMM_WORLD));
2623 "Committed checkpoint step %" PetscInt_FMT
" at t=%.17g (%s): %s\n",
2624 simCtx->
step, (
double)simCtx->
ti, reason, final_directory);
2626 PetscFunctionReturn(0);
2637 PetscErrorCode ierr;
2639 Cmpnts global_min_coords, global_max_coords;
2640 PetscReal StartTime;
2641 PetscInt StartStep,StepsToRun,total_num_particles;
2642 PetscMPIInt num_mpi_procs;
2643 const char *log_level_name;
2644 const char *convergence_mode_name;
2648 num_mpi_procs = simCtx->
size;
2652 total_num_particles = simCtx->
np;
2656 PetscFunctionBeginUser;
2659 if (!user) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"DisplayBanner - UserCtx pointer is NULL.");
2661 case LOG_ERROR: log_level_name =
"ERROR";
break;
2662 case LOG_WARNING: log_level_name =
"WARNING";
break;
2663 case LOG_INFO: log_level_name =
"INFO";
break;
2664 case LOG_DEBUG: log_level_name =
"DEBUG";
break;
2665 case LOG_TRACE: log_level_name =
"TRACE";
break;
2666 case LOG_VERBOSE: log_level_name =
"VERBOSE";
break;
2667 default: log_level_name =
"UNKNOWN";
break;
2674 default: convergence_mode_name =
"UNKNOWN";
break;
2678 rank = simCtx->
rank;
2683 if (bboxlist_on_rank0 && num_mpi_procs > 0) {
2684 global_min_coords = bboxlist_on_rank0[0].
min_coords;
2685 global_max_coords = bboxlist_on_rank0[0].
max_coords;
2686 for (PetscMPIInt p = 1; p < num_mpi_procs; ++p) {
2687 global_min_coords.
x = PetscMin(global_min_coords.
x, bboxlist_on_rank0[p].
min_coords.
x);
2688 global_min_coords.
y = PetscMin(global_min_coords.
y, bboxlist_on_rank0[p].
min_coords.
y);
2689 global_min_coords.
z = PetscMin(global_min_coords.
z, bboxlist_on_rank0[p].
min_coords.
z);
2690 global_max_coords.
x = PetscMax(global_max_coords.
x, bboxlist_on_rank0[p].
max_coords.
x);
2691 global_max_coords.
y = PetscMax(global_max_coords.
y, bboxlist_on_rank0[p].
max_coords.
y);
2692 global_max_coords.
z = PetscMax(global_max_coords.
z, bboxlist_on_rank0[p].
max_coords.
z);
2699 LOG_ALLOW(
LOCAL,
LOG_WARNING,
"(Rank 0) - bboxlist not provided or num_mpi_procs <=0; using user->bbox for domain bounds.\n");
2704 ierr = PetscPrintf(PETSC_COMM_SELF,
"\n"); CHKERRQ(ierr);
2705 ierr = PetscPrintf(PETSC_COMM_SELF,
"=============================================================\n"); CHKERRQ(ierr);
2706 ierr = PetscPrintf(PETSC_COMM_SELF,
" CASE SUMMARY \n"); CHKERRQ(ierr);
2707 ierr = PetscPrintf(PETSC_COMM_SELF,
"=============================================================\n"); CHKERRQ(ierr);
2708 ierr = PetscPrintf(PETSC_COMM_SELF,
" Grid Points : %" PetscInt_FMT
" X %" PetscInt_FMT
" X %" PetscInt_FMT
"\n", user->
IM, user->
JM, user->
KM); CHKERRQ(ierr);
2709 ierr = PetscPrintf(PETSC_COMM_SELF,
" Cells : %" PetscInt_FMT
" X %" PetscInt_FMT
" X %" PetscInt_FMT
"\n", user->
IM - 1, user->
JM - 1, user->
KM - 1); CHKERRQ(ierr);
2710 ierr = PetscPrintf(PETSC_COMM_SELF,
" Global Domain Bounds (X) : %.6f to %.6f\n", (
double)global_min_coords.
x, (
double)global_max_coords.
x); CHKERRQ(ierr);
2711 ierr = PetscPrintf(PETSC_COMM_SELF,
" Global Domain Bounds (Y) : %.6f to %.6f\n", (
double)global_min_coords.
y, (
double)global_max_coords.
y); CHKERRQ(ierr);
2712 ierr = PetscPrintf(PETSC_COMM_SELF,
" Global Domain Bounds (Z) : %.6f to %.6f\n", (
double)global_min_coords.
z, (
double)global_max_coords.
z); CHKERRQ(ierr);
2713 ierr = PetscPrintf(PETSC_COMM_SELF,
" Periodic Axes (BC-derived) : I=%s, J=%s, K=%s\n",
2716 simCtx->
k_periodic ?
"YES" :
"NO"); CHKERRQ(ierr);
2717 for (PetscInt axis = 0; axis < 3; axis++) {
2719 ierr = PetscPrintf(PETSC_COMM_SELF,
2720 " Periodic %c Translation : (%.6e, %.6e, %.6e)\n",
2727 ierr = PetscPrintf(PETSC_COMM_SELF,
"-------------------- Boundary Conditions --------------------\n"); CHKERRQ(ierr);
2728 const int face_name_width = 17;
2729 for (PetscInt i_face = 0; i_face < 6; ++i_face) {
2737 PetscReal source_id = -1.0;
2738 const char *source_file = NULL;
2739 PetscBool found, found_file;
2742 if (found_file && source_file) {
2743 ierr = PetscPrintf(PETSC_COMM_SELF,
" Face %-*s : %s - %s - source_file=%s\n",
2744 face_name_width, face_str, bc_type_str, bc_handler_type_str, source_file); CHKERRQ(ierr);
2746 ierr = PetscPrintf(PETSC_COMM_SELF,
" Face %-*s : %s - %s - source -face_source_%d\n",
2747 face_name_width, face_str, bc_type_str, bc_handler_type_str, (
int)source_id); CHKERRQ(ierr);
2751 PetscBool trimflag,foundtrimflag;
2753 ierr = PetscPrintf(PETSC_COMM_SELF,
" Face %-*s : %s - %s - [from initial state] - %s\n",
2754 face_name_width, face_str, bc_type_str, bc_handler_type_str,trimflag?
"Enforce seam flux":
"Seam flux not enforced"); CHKERRQ(ierr);
2757 PetscBool trimflag,foundflux,foundtrimflag;
2760 ierr = PetscPrintf(PETSC_COMM_SELF,
" Face %-*s : %s - %s - [%.4f] - %s\n",
2761 face_name_width, face_str, bc_type_str, bc_handler_type_str,flux,trimflag?
"Enforce seam flux":
"Seam flux not enforced"); CHKERRQ(ierr);
2763 ierr = PetscPrintf(PETSC_COMM_SELF,
" Face %-*s : %s - %s\n",
2764 face_name_width, face_str, bc_type_str,bc_handler_type_str); CHKERRQ(ierr);
2768 ierr = PetscPrintf(PETSC_COMM_SELF,
"-------------------------------------------------------------\n"); CHKERRQ(ierr);
2769 ierr = PetscPrintf(PETSC_COMM_SELF,
" Run Mode : %s\n", simCtx->
OnlySetup ?
"SETUP ONLY" :
"Full Simulation"); CHKERRQ(ierr);
2770 ierr = PetscPrintf(PETSC_COMM_SELF,
" Start Time : %.4f\n", (
double)StartTime); CHKERRQ(ierr);
2771 ierr = PetscPrintf(PETSC_COMM_SELF,
" Timestep Size : %.4f\n", (
double)simCtx->
dt); CHKERRQ(ierr);
2772 ierr = PetscPrintf(PETSC_COMM_SELF,
" Starting Step : %" PetscInt_FMT
"\n", StartStep); CHKERRQ(ierr);
2773 ierr = PetscPrintf(PETSC_COMM_SELF,
" Total Steps to Run : %" PetscInt_FMT
"\n", StepsToRun); CHKERRQ(ierr);
2774 ierr = PetscPrintf(PETSC_COMM_SELF,
" Ending Step : %" PetscInt_FMT
"\n", StartStep + StepsToRun); CHKERRQ(ierr);
2775 if (simCtx->
tiout > 0) {
2776 ierr = PetscPrintf(PETSC_COMM_SELF,
" Field/Restart Cadence : every %" PetscInt_FMT
" step(s)\n", simCtx->
tiout); CHKERRQ(ierr);
2778 ierr = PetscPrintf(PETSC_COMM_SELF,
" Field/Restart Cadence : DISABLED\n"); CHKERRQ(ierr);
2783 ierr = PetscPrintf(PETSC_COMM_SELF,
" Statistics Console Cadence : every %" PetscInt_FMT
" step(s), %" PetscInt_FMT
" window(s)\n",
2786 ierr = PetscPrintf(PETSC_COMM_SELF,
" Statistics Console Cadence : DISABLED (%" PetscInt_FMT
" window(s) accumulating)\n",
2789 ierr = PetscPrintf(PETSC_COMM_SELF,
" Statistics Console Cadence : DISABLED (no window configured)\n"); CHKERRQ(ierr);
2791 ierr = PetscPrintf(PETSC_COMM_SELF,
" Immersed Boundary : %s\n", simCtx->
immersed ?
"ENABLED" :
"DISABLED"); CHKERRQ(ierr);
2795 " Runtime Walltime Guard : %s (warmup=%" PetscInt_FMT
", multiplier=%.2f, min=%.1f s, alpha=%.2f)\n",
2803 ierr = PetscPrintf(PETSC_COMM_SELF,
" Runtime Walltime Guard : DISABLED\n"); CHKERRQ(ierr);
2805 ierr = PetscPrintf(PETSC_COMM_SELF,
" Console Log Level : %s\n", log_level_name); CHKERRQ(ierr);
2806 ierr = PetscPrintf(PETSC_COMM_SELF,
" Profiling Timestep Output : %s\n", simCtx->
profilingTimestepMode); CHKERRQ(ierr);
2807 ierr = PetscPrintf(PETSC_COMM_SELF,
" Profiling Final Summary : %s\n", simCtx->
profilingFinalSummary ?
"ENABLED" :
"DISABLED"); CHKERRQ(ierr);
2809 ierr = PetscPrintf(PETSC_COMM_SELF,
" Runtime Memory Log : ENABLED (Runtime_Memory.csv)\n"); CHKERRQ(ierr);
2811 ierr = PetscPrintf(PETSC_COMM_SELF,
" Runtime Memory Log : DISABLED\n"); CHKERRQ(ierr);
2813 ierr = PetscPrintf(PETSC_COMM_SELF,
" Solution Convergence Log : %s\n",
2815 ierr = PetscPrintf(PETSC_COMM_SELF,
" Number of MPI Processes : %d\n", num_mpi_procs); CHKERRQ(ierr);
2816 ierr = PetscPrintf(PETSC_COMM_WORLD,
" Number of Particles : %" PetscInt_FMT
"\n", total_num_particles); CHKERRQ(ierr);
2821 ierr = PetscPrintf(PETSC_COMM_SELF,
" Particle Console Cadence : every %" PetscInt_FMT
" step(s)\n", simCtx->
particleConsoleOutputFreq); CHKERRQ(ierr);
2823 ierr = PetscPrintf(PETSC_COMM_SELF,
" Particle Console Cadence : DISABLED\n"); CHKERRQ(ierr);
2825 ierr = PetscPrintf(PETSC_COMM_SELF,
" Particle Log Row Sampling : every %" PetscInt_FMT
" particle(s)\n", simCtx->
LoggingFrequency); CHKERRQ(ierr);
2827 ierr = PetscPrintf(PETSC_COMM_SELF,
" Traced Particles :"); CHKERRQ(ierr);
2828 for (PetscInt t = 0; t < simCtx->
nTracePIDs; ++t) {
2829 ierr = PetscPrintf(PETSC_COMM_SELF,
" %lld", (
long long)simCtx->
tracePIDs[t]); CHKERRQ(ierr);
2831 ierr = PetscPrintf(PETSC_COMM_SELF,
"\n"); CHKERRQ(ierr);
2834 ierr = PetscPrintf(PETSC_COMM_SELF,
" Particle Restart Mode : %s\n", simCtx->
particleRestartMode); CHKERRQ(ierr);
2836 ierr = PetscPrintf(PETSC_COMM_SELF,
" Particle Initialization Mode: %s\n", particle_init_str); CHKERRQ(ierr);
2837 ierr = PetscPrintf(PETSC_COMM_SELF,
" Particle Boundary Policy :"); CHKERRQ(ierr);
2838 for (PetscInt i_face = 0; i_face < 6; ++i_face) {
2842 ierr = PetscPrintf(PETSC_COMM_SELF,
"\n"); CHKERRQ(ierr);
2843 ierr = PetscPrintf(PETSC_COMM_SELF,
" Interpolation Method : %s\n",
2849 ierr = PetscPrintf(PETSC_COMM_SELF,
" Particles Initialized At : --- (No INLET face identified)\n"); CHKERRQ(ierr);
2854 ierr = PetscPrintf(PETSC_COMM_WORLD,
" Reynolds Number : %le\n", simCtx->
ren); CHKERRQ(ierr);
2860 ierr = PetscPrintf(PETSC_COMM_WORLD,
" Initial Pseudo-CFL (Courant): %le\n", simCtx->
pseudo_cfl); CHKERRQ(ierr);
2861 ierr = PetscPrintf(PETSC_COMM_WORLD,
" Pseudo-CFL Range : [%le, %le]\n", simCtx->
min_pseudo_cfl, simCtx->
max_pseudo_cfl); CHKERRQ(ierr);
2862 ierr = PetscPrintf(PETSC_COMM_WORLD,
" Pseudo-CFL Adaptation : growth=%le, reduction=%le, backtrack=%s\n",
2865 ierr = PetscPrintf(PETSC_COMM_WORLD,
" Pseudo-Time Iteration Limit : %" PetscInt_FMT
"\n", simCtx->
mom_max_pseudo_steps); CHKERRQ(ierr);
2867 ierr = PetscPrintf(PETSC_COMM_WORLD,
" Newton-Krylov PETSc Controls: SNES/KSP options (mom_nk_*)\n"); CHKERRQ(ierr);
2868 ierr = PetscPrintf(PETSC_COMM_WORLD,
" Newton-Krylov History Log : %s\n", simCtx->
mom_nk_monitor_history ?
"ENABLED" :
"DISABLED"); CHKERRQ(ierr);
2870 ierr = PetscPrintf(PETSC_COMM_WORLD,
" Pseudo-Time Controller : NOT APPLICABLE\n"); CHKERRQ(ierr);
2872 ierr = PetscPrintf(PETSC_COMM_WORLD,
" Solution Convergence Mode : %s\n", convergence_mode_name); CHKERRQ(ierr);
2878 ierr = PetscPrintf(PETSC_COMM_WORLD,
" Large Eddy Simulation Model : %s\n",
LESModelToString(simCtx->
les)); CHKERRQ(ierr);
2885 ierr = PetscPrintf(PETSC_COMM_WORLD,
" LES Filter Width : per direction (cell edges; filter_width unused)\n"); CHKERRQ(ierr);
2887 ierr = PetscPrintf(PETSC_COMM_WORLD,
" LES Filter Width : %s\n",
2891 ierr = PetscPrintf(PETSC_COMM_WORLD,
" LES Vreman Coefficient : %.4f (no coefficient field)\n",
2893 }
else if (simCtx->
les ==
WALE) {
2894 ierr = PetscPrintf(PETSC_COMM_WORLD,
" LES WALE Coefficient : %.4f (no coefficient field)\n",
2897 ierr = PetscPrintf(PETSC_COMM_WORLD,
" LES Smagorinsky Constant : %.4f (no coefficient field)\n",
2900 char directions[8] =
"";
2906 directions[used] =
'\0';
2908 ierr = PetscPrintf(PETSC_COMM_WORLD,
" LES Test Filter : %s (width ratio %.3f)\n",
2911 ierr = PetscPrintf(PETSC_COMM_WORLD,
" LES Dynamic Update Cadence : every %d step(s)\n",
2916 ierr = PetscPrintf(PETSC_COMM_WORLD,
" LES Coefficient Averaging : %s%s%s\n",
2918 used > 0 ?
" over " :
"",
2919 used > 0 ? directions :
""); CHKERRQ(ierr);
2921 ierr = PetscPrintf(PETSC_COMM_WORLD,
" LES Coefficient Limiting : clamp (max Cs %.3f)\n",
2922 (
double)les->
max_cs); CHKERRQ(ierr);
2924 ierr = PetscPrintf(PETSC_COMM_WORLD,
" LES Coefficient Limiting : %s\n",
2927 ierr = PetscPrintf(PETSC_COMM_WORLD,
" LES Total Viscosity Floor : %.3f x molecular\n",
2930 ierr = PetscPrintf(PETSC_COMM_WORLD,
" LES Gradient (Clark) Term : %s\n",
2933 ierr = PetscPrintf(PETSC_COMM_WORLD,
" LES Coefficient Diagnostics : ENABLED (les_coefficient.csv, every %d step(s))\n",
2937 ierr = PetscPrintf(PETSC_COMM_WORLD,
" LES Yoshizawa Coefficient : %.4f (subgrid energy estimate)\n",
2940 ierr = PetscPrintf(PETSC_COMM_WORLD,
" LES Coefficient Diagnostics : DISABLED\n"); CHKERRQ(ierr);
2949 ierr = PetscPrintf(PETSC_COMM_WORLD,
" Wall Function Model : %s (roughness height %.3e)\n",
2953 ierr = PetscPrintf(PETSC_COMM_WORLD,
" Wall Function Model : %s (smooth wall; no roughness term)\n",
2957 ierr = PetscPrintf(PETSC_COMM_WORLD,
" Wall Function Model : DISABLED\n"); CHKERRQ(ierr);
2961 ierr = PetscPrintf(PETSC_COMM_SELF,
" Eulerian State Source : load (%s)\n",
2964 ierr = PetscPrintf(PETSC_COMM_SELF,
" Eulerian State Source : restart step %" PetscInt_FMT
" (%s)\n",
2967 ierr = PetscPrintf(PETSC_COMM_SELF,
" Eulerian State Source : initial condition (Source)\n"); CHKERRQ(ierr);
2969 ierr = PetscPrintf(PETSC_COMM_SELF,
2970 " Initial Velocity File : field=%s directory=%s\n",
2976 ierr = PetscPrintf(PETSC_COMM_WORLD,
" Eulerian State Source : analytical (Source)\n"); CHKERRQ(ierr);
2978 ierr = PetscPrintf(PETSC_COMM_SELF,
"=============================================================\n"); CHKERRQ(ierr);
2979 ierr = PetscPrintf(PETSC_COMM_SELF,
"\n"); CHKERRQ(ierr);
2982 PetscFunctionReturn(0);
2989 PetscReal scale = 1.0;
2991 PetscFunctionBeginUser;
2993 PetscCheck(simCtx && physical, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
2994 "Context and physical-time output are required.");
2996 *physical = solver_time * scale;
2998 PetscFunctionReturn(0);
3007 PetscReal *scale,
char *description,
3008 size_t description_length)
3013 PetscBool found = PETSC_FALSE;
3015 PetscFunctionBeginUser;
3017 PetscCheck(simCtx && field_name && scale, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
3018 "Context, field name, and output scale are required.");
3031 PetscCheck(found, PETSC_COMM_SELF, PETSC_ERR_ARG_UNKNOWN_TYPE,
3032 "Field '%s' is in neither the Eulerian nor the particle field catalog.", field_name);
3037 "Field '%s' has no fixed physical dimension, so it has no reference scale.", field_name);
3039 if (description && description_length) {
3043 PetscFunctionReturn(0);
3055 PetscBool startTimeSet, endTimeSet, timeStepSet;
3057 PetscFunctionBeginUser;
3060 if (!simCtx || !simCtx->
pps) {
3061 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_NULL,
"SimCtx or its pps member is NULL in ParsePostProcessingSettings.");
3102 file = fopen(configFile,
"r");
3105 while (fgets(line,
sizeof(line), file)) {
3106 char *key, *value, *comment;
3107 comment = strchr(line,
'#');
if (comment) *comment =
'\0';
3109 key = strtok(line,
"="); value = strtok(NULL,
"=");
3112 if (strcmp(key,
"startTime") == 0) pps->
startTime = atoi(value);
3113 else if (strcmp(key,
"endTime") == 0) pps->
endTime = atoi(value);
3114 else if (strcmp(key,
"timeStep") == 0) pps->
timeStep = atoi(value);
3115 else if (strcmp(key,
"step_list_file") == 0) {
3119 else if (strcmp(key,
"output_particles") == 0) {
3120 if (strcasecmp(value,
"true") == 0) pps->
outputParticles = PETSC_TRUE;
3122 else if (strcasecmp(key,
"process_pipeline") == 0) {
3125 }
else if (strcasecmp(key,
"field_statistics_windows") == 0) {
3128 }
else if (strcasecmp(key,
"field_statistics_formats") == 0) {
3131 }
else if (strcasecmp(key,
"field_statistics_outputs") == 0) {
3134 }
else if (strcasecmp(key,
"field_statistics_source_step") == 0) {
3136 }
else if (strcasecmp(key,
"field_statistics_homogeneous") == 0) {
3140 }
else if (strncasecmp(key,
"field_statistics_ensemble_", 26) == 0) {
3145 PetscCall(PetscSNPrintf(option,
sizeof(option),
"-%s", key));
3146 PetscCall(PetscOptionsSetValue(NULL, option, value));
3147 }
else if (strcasecmp(key,
"da_processors") == 0) {
3149 PetscCheck(sscanf(value,
"%" PetscInt_FMT
" %" PetscInt_FMT
" %" PetscInt_FMT,
3150 &parsed[0], &parsed[1], &parsed[2]) == 3
3151 && parsed[0] > 0 && parsed[1] > 0 && parsed[2] > 0,
3152 PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
3153 "Post recipe da_processors must be three positive integers, got '%s'.", value);
3154 for (PetscInt axis = 0; axis < 3; ++axis) pps->
da_procs[axis] = parsed[axis];
3155 }
else if (strcasecmp(key,
"dimensionalize") == 0) {
3157 || strcmp(value,
"1") == 0);
3158 }
else if (strcasecmp(key,
"field_statistics_output_prefix") == 0) {
3163 }
else if (strcasecmp(key,
"output_fields_instantaneous") == 0) {
3166 }
else if (strcasecmp(key,
"output_prefix") == 0) {
3169 }
else if (strcasecmp(key,
"particle_output_prefix") == 0) {
3172 }
else if (strcasecmp(key,
"particle_fields_instantaneous") == 0) {
3175 }
else if (strcasecmp(key,
"particle_pipeline") == 0) {
3178 }
else if (strcasecmp(key,
"particle_output_freq") == 0) {
3180 }
else if (strcasecmp(key,
"statistics_pipeline") == 0) {
3183 }
else if (strcasecmp(key,
"statistics_output_prefix") == 0) {
3186 }
else if (strcasecmp(key,
"particleExt") == 0) {
3189 }
else if (strcasecmp(key,
"eulerianExt") == 0) {
3192 }
else if (strcmp(key,
"reference_ip") == 0) {pps->
reference[0] = atoi(value);
3193 }
else if (strcmp(key,
"reference_jp") == 0) {pps->
reference[1] = atoi(value);
3194 }
else if (strcmp(key,
"reference_kp") == 0) {pps->
reference[2] = atoi(value);
3195 }
else if (strcasecmp(key,
"source_directory") == 0) {
3198 }
else if (strcasecmp(key,
"spectra_signature") == 0) {
3212 LOG_ALLOW(
GLOBAL,
LOG_INFO,
"Could not open post-processing config file '%s'. Using defaults and command-line overrides.\n", configFile);
3216 PetscOptionsGetInt(NULL, NULL,
"-startTime", &pps->
startTime, &startTimeSet);
3217 PetscOptionsGetInt(NULL, NULL,
"-endTime", &pps->
endTime, &endTimeSet);
3218 PetscCall(PetscOptionsGetInt(NULL, NULL,
"-timeStep", &pps->
timeStep, &timeStepSet));
3219 PetscCheck(pps->
timeStep > 0, PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE,
3220 "Post-processing timeStep must be positive (got %" PetscInt_FMT
"). "
3221 "For one checkpoint, set startTime=endTime and timeStep=1.", pps->
timeStep);
3222 PetscOptionsGetBool(NULL, NULL,
"-output_particles", &pps->
outputParticles, NULL);
3229 if (startTimeSet && !endTimeSet) {
3233 LOG_ALLOW(
GLOBAL,
LOG_INFO,
"Post-processing configured to run from t=%" PetscInt_FMT
" to t=%" PetscInt_FMT
" with step %" PetscInt_FMT
". Particle output: %s.\n",
3247 PetscFunctionReturn(0);
3258 PetscErrorCode ierr;
3261 PetscFunctionBeginUser;
3264 if (!simCtx) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"SimCtx is NULL in ParseScalingInformation");
3273 ierr = PetscOptionsGetReal(NULL, NULL,
"-scaling_L_ref", &simCtx->
scaling.
L_ref, &flg); CHKERRQ(ierr);
3274 ierr = PetscOptionsGetReal(NULL, NULL,
"-scaling_U_ref", &simCtx->
scaling.
U_ref, &flg); CHKERRQ(ierr);
3275 ierr = PetscOptionsGetReal(NULL, NULL,
"-scaling_rho_ref", &simCtx->
scaling.
rho_ref, &flg); CHKERRQ(ierr);
3280 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE,
"Reference velocity U_ref must be positive. Got %g", (
double)simCtx->
scaling.
U_ref);
3285 LOG(
GLOBAL,
LOG_INFO,
"---------------- Physical Scales Initialized -----------------\n");
3286 LOG(
GLOBAL,
LOG_INFO,
" L_ref: %.4f, U_ref: %.4f, rho_ref: %.4f, P_ref: %.4f\n",
3288 LOG(
GLOBAL,
LOG_INFO,
"--------------------------------------------------------------\n");
3291 PetscFunctionReturn(0);
3307 PetscMPIInt rank, size;
3308 PetscErrorCode ierr;
3311 double *array = NULL;
3312 PetscInt fileExistsFlag = 0;
3315 "Start reading from file: %s\n",
3319 if (!filename || !data_out || !Nout) {
3321 "Null pointer argument provided.\n");
3327 MPI_Comm_rank(comm, &rank);
3328 MPI_Comm_size(comm, &size);
3332 fp = fopen(filename,
"r");
3341 ierr = MPI_Bcast(&fileExistsFlag, 1, MPIU_INT, 0, comm); CHKERRQ(ierr);
3343 if (!fileExistsFlag) {
3347 "File '%s' not found.\n",
3356 fp = fopen(filename,
"r");
3359 "File '%s' could not be opened for reading.\n",
3368 while (fgets(line,
sizeof(line), fp)) {
3374 "File '%s' has %" PetscInt_FMT
" lines.\n",
3378 array = (
double*)malloc(N *
sizeof(
double));
3382 "malloc failed for array.\n");
3392 while (fgets(line,
sizeof(line), fp)) {
3394 if (sscanf(line,
"%lf", &val) == 1) {
3402 "Successfully read %" PetscInt_FMT
" values from '%s'.\n",
3407 ierr = MPI_Bcast(&N, 1, MPIU_INT, 0, comm); CHKERRQ(ierr);
3411 array = (
double*)malloc(N *
sizeof(
double));
3414 "malloc failed on rank %d.\n",
3422 ierr = MPI_Bcast(array, N, MPI_DOUBLE, 0, comm); CHKERRQ(ierr);
3429 "Done. Provided array of length=%" PetscInt_FMT
" to all ranks.\n",
Small dependency-free SHA-256 utility for persistent metadata identity.
PetscErrorCode PicurvSHA256File(const char *path, char digest_hex[65])
Compute the lowercase SHA-256 digest of a file.
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.
@ FIELD_DIMENSION_FIXED
The exponents are the field's dimension.
PetscErrorCode FieldDimensionReferenceScale(const ScalingCtx *scaling, FieldDimension dimension, PetscReal *scale)
Return the factor that turns a solver value of one dimension into physical units.
@ FIELD_CAPABILITY_CHECKPOINT
@ FIELD_AVAILABILITY_WALL_MODEL
@ FIELD_AVAILABILITY_PARTICLES
@ FIELD_AVAILABILITY_TURBULENCE
@ FIELD_AVAILABILITY_LES_DYNAMIC
@ FIELD_AVAILABILITY_ALWAYS
@ FIELD_AVAILABILITY_INFLOW_FLUCTUATION
unsigned int capabilities
unsigned int availability
PetscErrorCode FieldGetView(UserCtx *user, FieldId field_id, FieldView *view)
Resolve the existing DM and global/local vectors for one field.
PetscErrorCode FieldTryIdFromName(const char *field_name, FieldId *field_id, PetscBool *found)
Look a name up without treating an unknown name as an error.
const char * canonical_name
const char * FieldLayoutName(FieldLayout layout)
Return a stable printable label for a field layout.
PetscErrorCode FieldDimensionLabel(FieldDimension dimension, char *label, size_t length)
Write a printable form of a dimension, such as L^2 U or dimensionless.
PetscErrorCode FieldGetDescriptor(FieldId field_id, const FieldDescriptor **descriptor)
Return immutable metadata for a valid field identifier.
FieldId
Compile-time identity for a catalogued Eulerian field.
Immutable metadata for one field identity.
Physical dimension as exponents of the reference length, velocity, and density.
Non-owning runtime objects resolved for one field and UserCtx.
PetscErrorCode ParsePostProcessingSettings(SimCtx *simCtx)
Implementation of ParsePostProcessingSettings().
PetscErrorCode ParseScalingInformation(SimCtx *simCtx)
Implementation of ParseScalingInformation().
PetscInt ReadDataFileToArray(const char *filename, double **data_out, PetscInt *Nout, MPI_Comm comm)
Implementation of ReadDataFileToArray().
PetscErrorCode ReadGridFile(UserCtx *user)
Implementation of ReadGridFile().
static PetscErrorCode WriteCheckpointPayloadEntry(FILE *manifest, const char *checkpoint_directory, PetscInt payload_index, const char *relative_path, const char *kind, const char *field_name, PetscInt block, const char *layout, PetscInt components, const char *logical_type, PetscInt global_size, const char *encoding)
Append one payload inventory entry to a checkpoint manifest.
PetscErrorCode StringToBCHandlerType(const char *str, BCHandlerType *handler_out)
Implementation of StringToBCHandlerType().
PetscErrorCode ReadSwarmField(UserCtx *user, const char *field_name, const char *ext)
Implementation of ReadSwarmField().
static PetscErrorCode FieldVecDMDA(Vec field_vec, DM *dmda)
The DMDA a vector belongs to, or NULL for a vector of any other layout (a swarm field).
#define PICURV_CHECKPOINT_STEP_WIDTH
PetscErrorCode GetBCParamReal(BC_Param *params, const char *key, PetscReal *value_out, PetscBool *found)
Implementation of GetBCParamReal().
#define PICURV_CHECKPOINTS_DIRECTORY
PetscErrorCode WriteAllSwarmFields(UserCtx *user, const char *checkpoint_directory)
Implementation of WriteAllSwarmFields().
static PetscErrorCode FormatStatisticsPath(const char *root, PetscInt window, PetscInt block, const char *payload_name, char *path, size_t path_size)
Format any level of the statistics subtree, from the root down to one payload.
#define PICURV_PARTICLE_DIRECTORY
static PetscInt * g_IMs_from_file
Caches the IM dimensions for all blocks read from the grid file.
PetscErrorCode WriteSwarmIntField(UserCtx *user, const char *field_name, const char *ext)
Implementation of WriteSwarmIntField().
PetscErrorCode ReadCheckpointParticleCount(UserCtx *user, PetscInt ti, PetscInt *particle_count)
Implementation of ReadCheckpointParticleCount().
#define PICURV_STATISTICS_DIRECTORY
PetscErrorCode ReadSimulationFields(UserCtx *user, PetscInt ti)
Implementation of ReadSimulationFields().
static PetscInt g_nblk_from_file
Stores the number of blocks read from the grid file.
PetscBool ShouldWriteDataOutput(const SimCtx *simCtx, PetscInt completed_step)
Implementation of ShouldWriteDataOutput().
PetscErrorCode PicurvFieldReferenceScale(SimCtx *simCtx, const char *field_name, PetscReal *scale, char *description, size_t description_length)
Implementation of PicurvFieldReferenceScale().
static PetscErrorCode RestoreDrivenFluxTarget(SimCtx *simCtx, UserCtx *user, const char *checkpoint_directory)
Restore a latched driven-flow flux target from a checkpoint manifest.
#define PICURV_CHECKPOINT_FORMAT
static PetscErrorCode FormatCheckpointStepDirectory(const char *root, PetscInt step, char *path, size_t path_size)
Format the canonical directory name for one completed step.
PetscErrorCode GetDrivenSeamFluxFlag(BC_Param *params, PetscBool *value_out, PetscBool *found)
Implementation of GetDrivenSeamFluxFlag().
PetscErrorCode ParseAllBoundaryConditions(UserCtx *user, const char *bcs_input_filename)
Implementation of ParseAllBoundaryConditions().
PetscErrorCode ValidateBCHandlerForBCType(BCType type, BCHandlerType handler)
Implementation of ValidateBCHandlerForBCType().
void TrimWhitespace(char *str)
Implementation of TrimWhitespace().
PetscErrorCode ReadAllSwarmFields(UserCtx *user, PetscInt ti)
Implementation of ReadAllSwarmFields().
PetscErrorCode WriteSimulationFields(UserCtx *user, const char *checkpoint_directory)
Implementation of WriteSimulationFields().
PetscBool CheckpointFieldIsEnabled(const SimCtx *simCtx, const FieldDescriptor *descriptor)
Implementation of CheckpointFieldIsEnabled().
static PetscErrorCode NaturalOrderedVector(Vec field_vec, Vec *natural_vec, Vec *ordered_vec)
Express a vector in decomposition-independent natural ordering.
static PetscErrorCode CreateCheckpointDirectoryCollective(const SimCtx *simCtx, const char *path)
Create one directory on rank zero and report failures collectively.
static PetscBool g_file_has_been_read
A flag to ensure the grid file is read only once.
PetscErrorCode ReadGridGenerationInputs(UserCtx *user)
Implementation of ReadGridGenerationInputs().
static PetscErrorCode ComputeCheckpointGeometrySHA256(SimCtx *simCtx, UserCtx *user, char digest_hex[65])
Compute and cache a rank-count-independent hash of the active grid geometry.
PetscErrorCode ReadFieldData(UserCtx *user, const char *field_name, Vec field_vec, const char *ext)
Implementation of ReadFieldData().
PetscErrorCode DeterminePeriodicity(SimCtx *simCtx)
Implementation of DeterminePeriodicity().
static PetscErrorCode ValidateCheckpointBundle(SimCtx *simCtx, UserCtx *user, const char *checkpoint_directory, PetscInt expected_step, PetscReal *physical_time, PetscInt *particle_count, PetscBool *particles_saved, PetscBool *les_saved, PetscBool *inflow_saved)
Validate a committed bundle and return selected authoritative metadata; a NULL user skips the geometr...
static PetscErrorCode CopyOwnedLocalScalarToGlobal(DM dm, Vec local_vec, Vec global_vec)
Copies the owned entries of a ghosted scalar DMDA vector to its global vector.
PetscErrorCode RestoreFieldStatisticsState(SimCtx *simCtx, PetscInt ti)
Implementation of RestoreFieldStatisticsState().
static PetscInt * g_KMs_from_file
Caches the KM dimensions for all blocks read from the grid file.
static PetscInt * g_JMs_from_file
Caches the JM dimensions for all blocks read from the grid file.
static PetscErrorCode ReadStatisticsWindowState(PetscOptions options, PetscInt window, const char *metadata_path, PetscReal checkpoint_time, PetscReal step_size, ExecutionMode exec_mode, PicurvWindow *state)
Restore one window's scalar bookkeeping from a validated manifest.
PetscErrorCode StringToBCFace(const char *str, BCFace *face_out)
Implementation of StringToBCFace().
PetscErrorCode GetBCParamString(BC_Param *params, const char *key, const char **value_out, PetscBool *found)
Implementation of GetBCParamString().
static PetscErrorCode OpenFieldPayloadViewer(MPI_Comm comm, const char *filename, PetscFileMode mode, PetscViewer *viewer)
Open a PETSc binary viewer for one field payload, reading or writing through MPI-IO.
PetscErrorCode WriteSwarmField(UserCtx *user, const char *field_name, const char *ext)
Implementation of WriteSwarmField().
PetscErrorCode ReadSwarmIntField(UserCtx *user, const char *field_name, const char *ext)
Implementation of ReadSwarmIntField().
static PetscErrorCode ResolveCheckpointStepDirectory(const char *source_root, PetscInt step, char *path, size_t path_size)
Resolve either an exact bundle or a run/output root to one step bundle.
PetscErrorCode WriteFieldData(UserCtx *user, const char *field_name, Vec field_vec, const char *ext)
Implementation of WriteFieldData().
PetscErrorCode VerifyPathExistence(const char *path, PetscBool is_dir, PetscBool is_optional, const char *description, PetscBool *exists)
Implementation of VerifyPathExistence().
static PetscErrorCode WriteStatisticsFields(UserCtx *user, const char *checkpoint_directory)
Write every window's accumulator payloads for one block into a bundle.
PetscErrorCode GetBCParamBool(BC_Param *params, const char *key, PetscBool *value_out, PetscBool *found)
Implementation of GetBCParamBool().
void FreeBC_ParamList(BC_Param *head)
Implementation of FreeBC_ParamList().
PetscErrorCode StringToBCType(const char *str, BCType *type_out)
Implementation of StringToBCType().
PetscErrorCode DisplayBanner(SimCtx *simCtx)
Emit the rank-zero startup summary from the effective simulation context.
#define PICURV_CHECKPOINT_VERSION
PetscErrorCode WriteCheckpointBundle(SimCtx *simCtx, const char *reason)
Implementation of the transactional full-state checkpoint coordinator.
#define PICURV_EULERIAN_DIRECTORY
#define PICURV_STATISTICS_REQUIRE(suffix, getter, target)
PetscErrorCode PicurvPhysicalTime(const SimCtx *simCtx, PetscReal solver_time, PetscReal *physical)
Implementation of PicurvPhysicalTime().
static PetscErrorCode WriteCheckpointManifest(SimCtx *simCtx, UserCtx *user, const char *checkpoint_directory, const char *reason, const char *geometry_digest, PetscInt particle_count, char manifest_digest[65])
Write the complete manifest after every payload has closed successfully.
Public interface for data input/output routines.
const char * LESTestFilterKernelToString(LESTestFilterKernel kernel)
Returns the user-facing name of an LES test-filter kernel.
const char * BCHandlerTypeToString(BCHandlerType handler_type)
Converts a BCHandlerType enum to its string representation.
#define LOG_ALLOW_SYNC(scope, level, fmt,...)
Synchronized logging macro that checks both the log level and whether the calling function is in the ...
#define LOCAL
Logging scope definitions for controlling message output.
const char * ParticleBoundaryPolicyToString(ParticleBoundaryPolicy policy)
Returns the configuration token for a particle boundary policy.
#define GLOBAL
Scope for global logging across all processes.
const char * BCFaceToString(BCFace face)
Returns the canonical log token for a boundary-face enum value.
#define LOG_ALLOW(scope, level, fmt,...)
Logging macro that checks both the log level and whether the calling function is in the allowed-funct...
#define PROFILE_HELPER_BEGIN
Marks the beginning of a profiled helper: timed only when enabled by name.
#define PROFILE_HELPER_END
Alias of PROFILE_FUNCTION_END for a function that began with PROFILE_HELPER_BEGIN.
#define PROFILE_FUNCTION_END
Marks the end of a profiled code block.
#define LOG(scope, level, fmt,...)
Logging macro for PETSc-based applications with scope control.
const char * WallFunctionModelToString(WallFunctionModel model)
Returns the user-facing name of a wall-function model.
const char * LESFilterWidthModelToString(LESFilterWidthModel model)
Returns the user-facing name of an LES grid-filter-width model.
const char * BCTypeToString(BCType type)
Returns the canonical log token for a boundary mathematical type.
const char * LESAveragingModeToString(LESAveragingMode mode)
Returns the user-facing name of an LES coefficient-averaging mode.
const char * InterpolationMethodToString(InterpolationMethod method)
Returns the display name of a grid-to-particle interpolation method.
@ LOG_ERROR
Critical errors that may halt the program.
@ LOG_TRACE
Very fine-grained tracing information for in-depth debugging.
@ LOG_INFO
Informational messages about program execution.
@ LOG_WARNING
Non-critical issues that warrant attention.
@ LOG_DEBUG
Detailed debugging information.
@ LOG_VERBOSE
Extremely detailed logs, typically for development use only.
#define PROFILE_FUNCTION_BEGIN
Marks the beginning of a profiled function: an always-on aggregate timer.
const char * LESModelToString(LESModelType LESFlag)
Returns the canonical log token for an LES model selector.
const char * LESClipModeToString(LESClipMode mode)
Returns the user-facing name of an LES coefficient-limiting mode.
const char * MomentumSolverTypeToString(MomentumSolverType SolverFlag)
Returns the canonical log token for a momentum-solver selector.
const char * ParticleInitializationToString(ParticleInitializationType ParticleInitialization)
Returns the canonical log token for a particle-initialization mode.
static LogLevel get_log_level(void)
Retrieves the current logging level from the environment variable LOG_LEVEL.
Typed identities and metadata for persistent solver-particle fields.
const char * ParticleFieldName(ParticleFieldId field_id)
Return the canonical PETSc DMSwarm name for an ID.
ParticleFieldId
Compile-time identity for a persistent solver-particle field.
@ PARTICLE_FIELD_ID_POSITION
@ PARTICLE_FIELD_ID_COUNT
@ PARTICLE_FIELD_ID_INVALID
unsigned int capabilities
@ PARTICLE_FIELD_CAPABILITY_CHECKPOINT
PetscErrorCode ParticleFieldGetDescriptor(ParticleFieldId field_id, const ParticleFieldDescriptor **descriptor)
Return immutable metadata for a valid particle field ID.
const char * canonical_name
PetscErrorCode ParticleFieldTryIdFromName(const char *field_name, ParticleFieldId *field_id, PetscBool *found)
Look a name up without treating an unknown name as an error.
Immutable metadata for one persistent particle field.
PetscErrorCode UpdateLocalGhosts(UserCtx *user, FieldId field_id)
Updates the local vector (including ghost points) from its corresponding global vector.
Per-window PETSc accumulator storage and pointwise application.
PetscInt components
Degrees of freedom the vector carries.
Vec vec
Borrowed accumulator vector; never owned by the caller.
PetscErrorCode PicurvWindowStoragePayload(UserCtx *user, const PicurvWindowDefinition *definition, const PicurvWindowStorage *storage, PetscInt index, PicurvStatisticsPayload *payload)
Resolves one enumerated payload of a window's storage.
const char * role
Inventory role: occupancy, mean, second_moment, co_moment.
char name[96]
File basename, no extension.
const char * layout
Catalog layout name for the inventory entry.
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.
Control ingress for the field-statistics pipeline.
PetscErrorCode ParsePostStatisticsEnsembles(SimCtx *simCtx)
Resolves the statistics ensembles a post-processing recipe defines.
PetscInt last_event_step
Guards against a step being offered twice.
PetscErrorCode PicurvWindowComputeHash(const PicurvWindowDefinition *definition, char digest_hex[65], char group_digest_hex[][17])
Computes the resolved identity hash of one window definition.
#define PICURV_WINDOW_HASH_GROUP_COUNT
Number of independently hashed property groups in a window definition.
#define PICURV_WINDOW_HASH_GROUP_LENGTH
Stored length of one truncated group digest, including the terminator.
PetscReal effective_start
Origin of the first represented interval.
const char * PicurvWindowHashGroupName(PetscInt group)
Returns the stable name of one hashed property group.
PetscReal last_accepted_time
Right edge of the last represented interval.
PetscInt restart_count
Restart segments this state descends from.
PetscReal effective_end
End of the last represented interval.
PetscReal end_time
Requested end; ignored when bounded is false.
#define PICURV_WINDOW_NAME_LENGTH
Maximum stored length of a window name, including the terminator.
@ PICURV_WINDOW_PENDING
Requested start not yet reached.
@ PICURV_WINDOW_COMPLETE
Bounded end reached; accepts nothing further.
@ PICURV_WINDOW_ACTIVE
Accepting due states.
const char * PicurvWindowStateName(PicurvWindowState state)
Returns a stable human-readable name for a window state.
PetscBool bounded
False for an open-ended window.
PicurvWindowDefinition definition
PetscInt next_time_target
k in effective_start + k*time_cadence.
PetscBool FieldStatisticsIsActive(const struct SimCtx *simCtx)
Reports whether this run has live field-statistics state.
PetscInt activation_step
Step at which the window became active.
PetscReal represented_time
Physical time the window covers.
PetscErrorCode PicurvWindowFirstHashDifference(const PicurvWindowDefinition *definition, const char *saved_group_digests, PetscInt *group)
Reports which hashed property group first differs from saved group digests.
Runtime state of one window.
The scientifically immutable definition of one window.
PetscBool inflowFluctuations
Some inlet adds synthetic fluctuations; their filter state is checkpointed.
PetscBool mom_nk_monitor_history
PetscInt fieldStatisticsWindowCount
char statistics_output_prefix[256]
basename for CSV output, e.g.
BCType
Defines the general mathematical/physical Category of a boundary.
PetscReal yoshizawa_ci
Yoshizawa constant for the reported SGS kinetic energy.
PetscBool inletFaceDefined
PetscBool profilingFinalSummary
char particle_output_prefix[256]
PetscInt dynamic_frequency
Recompute the dynamic coefficient every N steps.
BoundaryFaceConfig boundary_faces[6]
LESFilterWidthModel filter_width_model
How the grid filter width Delta is derived per cell.
PetscInt statisticsConsoleOutputFreq
#define PICURV_BUILD_DIRTY
BCFace identifiedInletBCFace
PetscReal targetVolumetricFlux
PetscBool walltimeGuardActive
LESTestFilterKernel test_filter_kernel
Discrete test-filter stencil.
LESConfig les_config
Parameters of the LES closure selected by les.
PetscReal pseudo_cfl_reduction_factor
SimCtx * simCtx
Back-pointer to the master simulation context.
@ PARTICLE_INIT_SURFACE_RANDOM
Random placement on the inlet face.
PetscInt nTracePIDs
Number of entries in tracePIDs (at most PICURV_MAX_TRACED_PARTICLES).
PetscBool runtimeMemoryLogEnabled
Enable the rank-reduced runtime memory log (log_dir/Runtime_Memory.csv).
PetscBool dimensionalize
Whether derived output leaves non-dimensional form, from global_operations.dimensionalize.
char field_statistics_output_prefix[PETSC_MAX_PATH_LEN]
Analysis prefix for CSV summaries; VTK continues to use output_prefix.
#define MAX_FIELD_LIST_LENGTH
PetscBool inflowFluctuationsRestored
That state was read from the restart checkpoint.
PetscReal walltimeGuardMinSeconds
BCHandlerType
Defines the specific computational "strategy" for a boundary handler.
@ BC_HANDLER_PERIODIC_GEOMETRIC
@ BC_HANDLER_PERIODIC_DRIVEN_INITIAL_FLUX
@ BC_HANDLER_PERIODIC_DRIVEN_CONSTANT_FLUX
@ BC_HANDLER_INLET_PRESCRIBED_VELOCITY
@ BC_HANDLER_OUTLET_CONSERVATION
@ BC_HANDLER_WALL_FREE_SLIP
#define MAX_PIPELINE_LENGTH
BCHandlerType handler_type
Cmpnts max_coords
Maximum x, y, z coordinates of the bounding box.
PetscBool drivenFluxTargetLatched
char step_list_file[PETSC_MAX_PATH_LEN]
File listing the exact steps to process, one per line; empty uses the time controls.
char output_dir[PETSC_MAX_PATH_LEN]
PetscBool solutionConvergenceEnabled
char profilingTimestepMode[32]
static PetscBool ParticlesEnabled(const SimCtx *simCtx)
Whether the run carries particles: a seeded or restored population, or inlets that inject them.
WallFunctionModel
Selects the wall model applied on WALL faces.
PetscReal max_cs
Ceiling on Cs under LES_CLIP_CLAMP.
LESClipMode clip_mode
Admissible range for the coefficient.
PetscBool no_pseudo_cfl_backtrack
#define PICURV_GIT_COMMIT
PetscBool skipFinalCheckpoint
io.write_final_checkpoint false: no end-of-run bundle.
#define MAX_FILENAME_LENGTH
Cmpnts min_coords
Minimum x, y, z coordinates of the bounding box.
@ MOMENTUM_SOLVER_DUALTIME_PICARD_JAMESON_RK
@ MOMENTUM_SOLVER_EXPLICIT_RK
@ MOMENTUM_SOLVER_NEWTON_KRYLOV
PetscInt solutionConvergencePeriodSteps
PetscBool averaging_direction[3]
Averaged-over logical directions (xi, eta, zeta).
PetscReal wale_coefficient
Model constant C_w for WALE (Nicoud & Ducros 1999).
char * current_io_directory
char grid_file[PETSC_MAX_PATH_LEN]
char statistics_pipeline[1024]
e.g.
InterpolationMethod interpolationMethod
char field_statistics_formats[1024]
Comma-separated formats: vtk for derived fields, csv for the convergence history.
char output_fields_instantaneous[1024]
char particleRestartMode[16]
struct PicurvWindow * fieldStatisticsWindows
char source_dir[PETSC_MAX_PATH_LEN]
PetscInt les_gradient_model
Add the Clark gradient (tensor-diffusivity) term to the viscous flux.
ParticleBoundaryPolicy particle_policy
What a particle crossing this face becomes (BC param particle_policy).
char particle_pipeline[1024]
char eulerianSource[PETSC_MAX_PATH_LEN]
PetscBool walltimeGuardEnabled
PetscBool checkpointGeometryHashReady
PetscReal wall_roughness_height
PetscInt walltimeGuardWarmupSteps
ParticleInitializationType ParticleInitialization
PetscInt diagnostics_cadence
Steps between diagnostic rows.
PetscReal min_viscosity_ratio
Enforce nu + nu_t >= ratio * nu.
PetscInt wallfunction
Enable wall functions on WALL faces.
PetscInt da_procs[3]
Postprocessor MPI decomposition (i, j, k) from the recipe; PETSC_DECIDE where unset.
PetscBool diagnostics_enabled
Append per-step coefficient statistics to the run log directory.
PetscReal constant_cs
Fixed Cs for CONSTANT_SMAGORINSKY; unused by the dynamic model.
PetscInt solutionConvergenceWindowSteps
char process_pipeline[1024]
PetscInt particle_output_freq
PetscReal test_filter_width_ratio
Test-to-grid ratio per filtered direction; alpha is its square for the box, ratio^(4/3) for Simpson.
char particle_fields[1024]
PetscReal pseudo_cfl_growth_factor
PetscBool outputParticles
char initialConditionDirectory[PETSC_MAX_PATH_LEN]
LESAveragingMode averaging_mode
Averaging set for the Germano contractions.
PetscInt64 * tracePIDs
Sorted, distinct IDs of the particles whose every stage is reported (-picurv_trace_particles); NULL w...
struct PicurvWindowStorage * fieldStatisticsStorage
PetscInt particleConsoleOutputFreq
PetscBool initialConditionStaged
PetscBool skipInitialCheckpoint
io.write_initial_checkpoint false: no initial/branch_start bundle.
char checkpointGeometrySHA256[65]
PetscReal vreman_coefficient
Model constant c for VREMAN (Vreman 2004: 2.5 Cs^2).
PetscInt mom_max_pseudo_steps
ExecutionMode
Defines the execution mode of the application.
@ EXEC_MODE_POSTPROCESSOR
@ EXEC_MODE_RESTART_CHECK
char _io_context_buffer[PETSC_MAX_PATH_LEN]
PetscInt field_statistics_source_step
Committed step supplying the state; negative means the step being processed.
Cmpnts periodic_translation[3]
PetscReal walltimeGuardEstimatorAlpha
PetscInt les
Active LES closure; an LESModelType value.
char field_statistics_windows[1024]
Comma-separated window names to derive; empty disables the pipeline.
char field_statistics_outputs[1024]
Comma-separated outputs: mean, reynolds_stress, rms, tke, flux, point_variance.
@ SOLUTION_CONVERGENCE_TRANSIENT
@ SOLUTION_CONVERGENCE_PERIODIC_DETERMINISTIC
@ SOLUTION_CONVERGENCE_STATISTICAL_STEADY
@ SOLUTION_CONVERGENCE_STEADY_DETERMINISTIC
PetscBool periodic_translation_valid[3]
SolutionConvergenceMode solutionConvergenceMode
InitialConditionField initialConditionField
PetscBool restartHistoryAvailable
PetscBool field_statistics_homogeneous[3]
Directions profiles merge over, in (i, j, k) order; none selected writes no profile.
PetscReal walltimeGuardMultiplier
MomentumSolverType mom_solver_type
char PostprocessingControlFile[PETSC_MAX_PATH_LEN]
char restart_dir[PETSC_MAX_PATH_LEN]
PetscInt LoggingFrequency
#define PICURV_RELEASE_VERSION
PetscBool fieldStatisticsContinue
BCFace
Identifies the six logical faces of a structured computational block.
BoundaryCondition * handler
A node in a linked list for storing key-value parameters from the bcs.dat file.
Holds the complete configuration for one of the six boundary faces.
Defines a 3D axis-aligned bounding box.
A 3D point or vector with PetscScalar components.
Every user-selectable parameter of the LES closure.
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.