43 while (isspace((
unsigned char)*start)) {
48 char *end = str + strlen(str) - 1;
50 while (end > start && isspace((
unsigned char)*end)) {
59 memmove(str, start, (end - start) + 2);
75 return (PetscBool)(simCtx->
tiout > 0 && completed_step > 0 && completed_step % simCtx->
tiout == 0);
80#define __FUNCT__ "ReadGridGenerationInputs"
90 PetscInt block_index = user->
_this;
94 PetscInt *IMs = NULL, *JMs = NULL, *KMs = NULL, *cgrids = NULL;
95 PetscReal *xMins = NULL, *xMaxs = NULL, *rxs = NULL;
96 PetscReal *yMins = NULL, *yMaxs = NULL, *rys = NULL;
97 PetscReal *zMins = NULL, *zMaxs = NULL, *rzs = NULL;
99 PetscFunctionBeginUser;
104 if (block_index >= nblk) {
105 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE,
"Block index %d is out of range for nblk=%d", block_index, nblk);
109 ierr = PetscMalloc4(nblk, &IMs, nblk, &JMs, nblk, &KMs, nblk, &cgrids); CHKERRQ(ierr);
110 ierr = PetscMalloc6(nblk, &xMins, nblk, &xMaxs, nblk, &rxs, nblk, &yMins, nblk, &yMaxs, nblk, &rys); CHKERRQ(ierr);
111 ierr = PetscMalloc3(nblk, &zMins, nblk, &zMaxs, nblk, &rzs); CHKERRQ(ierr);
114 for (PetscInt i = 0; i < nblk; ++i) {
115 IMs[i] = 10; JMs[i] = 10; KMs[i] = 10; cgrids[i] = 0;
116 xMins[i] = 0.0; xMaxs[i] = 1.0; rxs[i] = 1.0;
117 yMins[i] = 0.0; yMaxs[i] = 1.0; rys[i] = 1.0;
118 zMins[i] = 0.0; zMaxs[i] = 1.0; rzs[i] = 1.0;
123 count = nblk; ierr = PetscOptionsGetIntArray(NULL, NULL,
"-im", IMs, &count, &found); CHKERRQ(ierr);
124 count = nblk; ierr = PetscOptionsGetIntArray(NULL, NULL,
"-jm", JMs, &count, &found); CHKERRQ(ierr);
125 count = nblk; ierr = PetscOptionsGetIntArray(NULL, NULL,
"-km", KMs, &count, &found); CHKERRQ(ierr);
126 count = nblk; ierr = PetscOptionsGetRealArray(NULL, NULL,
"-xMins", xMins, &count, &found); CHKERRQ(ierr);
127 count = nblk; ierr = PetscOptionsGetRealArray(NULL, NULL,
"-xMaxs", xMaxs, &count, &found); CHKERRQ(ierr);
128 count = nblk; ierr = PetscOptionsGetRealArray(NULL, NULL,
"-rxs", rxs, &count, &found); CHKERRQ(ierr);
129 count = nblk; ierr = PetscOptionsGetRealArray(NULL, NULL,
"-yMins", yMins, &count, &found); CHKERRQ(ierr);
130 count = nblk; ierr = PetscOptionsGetRealArray(NULL, NULL,
"-yMaxs", yMaxs, &count, &found); CHKERRQ(ierr);
131 count = nblk; ierr = PetscOptionsGetRealArray(NULL, NULL,
"-rys", rys, &count, &found); CHKERRQ(ierr);
132 count = nblk; ierr = PetscOptionsGetRealArray(NULL, NULL,
"-zMins", zMins, &count, &found); CHKERRQ(ierr);
133 count = nblk; ierr = PetscOptionsGetRealArray(NULL, NULL,
"-zMaxs", zMaxs, &count, &found); CHKERRQ(ierr);
134 count = nblk; ierr = PetscOptionsGetRealArray(NULL, NULL,
"-rzs", rzs, &count, &found); CHKERRQ(ierr);
135 count = nblk; ierr = PetscOptionsGetIntArray(NULL, NULL,
"-cgrids", cgrids, &count, &found); CHKERRQ(ierr);
138 user->
IM = IMs[block_index];
139 user->
JM = JMs[block_index];
140 user->
KM = KMs[block_index];
141 user->
Min_X = xMins[block_index];
142 user->
Max_X = xMaxs[block_index];
143 user->
rx = rxs[block_index];
144 user->
Min_Y = yMins[block_index];
145 user->
Max_Y = yMaxs[block_index];
146 user->
ry = rys[block_index];
147 user->
Min_Z = zMins[block_index];
148 user->
Max_Z = zMaxs[block_index];
149 user->
rz = rzs[block_index];
150 user->
cgrid = cgrids[block_index];
153 simCtx->
rank, block_index, user->
IM, user->
JM, user->
KM);
158 ierr = PetscFree4(IMs, JMs, KMs, cgrids); CHKERRQ(ierr);
159 ierr = PetscFree6(xMins, xMaxs, rxs, yMins, yMaxs, rys); CHKERRQ(ierr);
160 ierr = PetscFree3(zMins, zMaxs, rzs); CHKERRQ(ierr);
163 PetscFunctionReturn(0);
174 PetscInt *IMs = NULL, *JMs = NULL, *KMs = NULL;
177 PetscFunctionBeginUser;
180 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"finest_users cannot be NULL.");
183 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE,
"nblk must be positive. Got %d.", nblk);
185 simCtx = finest_users[0].
simCtx;
187 ierr = PetscMalloc3(nblk, &IMs, nblk, &JMs, nblk, &KMs); CHKERRQ(ierr);
188 for (PetscInt i = 0; i < nblk; ++i) {
189 IMs[i] = 10; JMs[i] = 10; KMs[i] = 10;
193 count = nblk; ierr = PetscOptionsGetIntArray(NULL, NULL,
"-im", IMs, &count, &found); CHKERRQ(ierr);
194 count = nblk; ierr = PetscOptionsGetIntArray(NULL, NULL,
"-jm", JMs, &count, &found); CHKERRQ(ierr);
195 count = nblk; ierr = PetscOptionsGetIntArray(NULL, NULL,
"-km", KMs, &count, &found); CHKERRQ(ierr);
197 for (PetscInt bi = 0; bi < nblk; ++bi) {
198 finest_users[bi].
IM = IMs[bi];
199 finest_users[bi].
JM = JMs[bi];
200 finest_users[bi].
KM = KMs[bi];
203 "Rank %d: Preloaded analytical grid resolution for block %d: IM=%d, JM=%d, KM=%d\n",
204 simCtx->
rank, bi, finest_users[bi].
IM, finest_users[bi].
JM, finest_users[bi].
KM);
208 ierr = PetscFree3(IMs, JMs, KMs); CHKERRQ(ierr);
209 PetscFunctionReturn(0);
214#define __FUNCT__ "ReadGridFile"
223 PetscInt block_index = user->
_this;
225 PetscFunctionBeginUser;
231 PetscMPIInt rank = simCtx->
rank;
235 FILE *fd = fopen(simCtx->
grid_file,
"r");
236 if (!fd) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN,
"Cannot open file: %s", simCtx->
grid_file);
239 char firstTok[32] = {0};
240 if (fscanf(fd,
"%31s", firstTok) != 1)
241 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_FILE_READ,
"Empty grid file: %s", simCtx->
grid_file);
242 if (strcmp(firstTok,
"PICGRID") != 0)
243 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_FILE_READ,
244 "Grid file %s must begin with the canonical PICGRID header.", simCtx->
grid_file);
246 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_FILE_READ,
"Expected number of blocks after \"PICGRID\" in %s", simCtx->
grid_file);
248 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_FILE_UNEXPECTED,
"Mismatch: -nblk is %d but grid file specifies %d blocks.", nblk,
g_nblk_from_file);
252 for (PetscInt i = 0; i < nblk; ++i) {
254 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_FILE_READ,
"Expected 3 integers for block %d in %s", i, simCtx->
grid_file);
261 ierr = MPI_Bcast(&
g_nblk_from_file, 1, MPI_INT, 0, PETSC_COMM_WORLD); CHKERRQ(ierr);
269 ierr = MPI_Bcast(
g_IMs_from_file, nblk, MPI_INT, 0, PETSC_COMM_WORLD); CHKERRQ(ierr);
270 ierr = MPI_Bcast(
g_JMs_from_file, nblk, MPI_INT, 0, PETSC_COMM_WORLD); CHKERRQ(ierr);
271 ierr = MPI_Bcast(
g_KMs_from_file, nblk, MPI_INT, 0, PETSC_COMM_WORLD); CHKERRQ(ierr);
283 simCtx->
rank, block_index, user->
IM, user->
JM, user->
KM);
286 PetscFunctionReturn(0);
304 while (current != NULL) {
306 PetscFree(current->
key);
307 PetscFree(current->
value);
319 else if (strcasecmp(str,
"+Xi") == 0) *face_out =
BC_FACE_POS_X;
320 else if (strcasecmp(str,
"-Eta") == 0) *face_out =
BC_FACE_NEG_Y;
321 else if (strcasecmp(str,
"+Eta") == 0) *face_out =
BC_FACE_POS_Y;
322 else if (strcasecmp(str,
"-Zeta") == 0) *face_out =
BC_FACE_NEG_Z;
323 else if (strcasecmp(str,
"+Zeta") == 0) *face_out =
BC_FACE_POS_Z;
324 else SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_UNKNOWN_TYPE,
"Unknown face specifier: %s", str);
333 if (strcasecmp(str,
"WALL") == 0) *type_out =
WALL;
334 else if (strcasecmp(str,
"SYMMETRY") == 0) *type_out =
SYMMETRY;
335 else if (strcasecmp(str,
"INLET") == 0) *type_out =
INLET;
336 else if (strcasecmp(str,
"OUTLET") == 0) *type_out =
OUTLET;
337 else if (strcasecmp(str,
"PERIODIC") == 0) *type_out =
PERIODIC;
339 else SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_UNKNOWN_TYPE,
"Unknown BC Type string: %s", str);
357 else SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_UNKNOWN_TYPE,
"Unknown BC Handler string: %s", str);
391 *found = PETSC_FALSE;
397 if (strcasecmp(current->
key, key) == 0) {
398 *value_out = atof(current->
value);
402 current = current->
next;
412 *found = PETSC_FALSE;
413 *value_out = PETSC_FALSE;
418 if (strcasecmp(current->
key, key) == 0) {
423 if (current->
value &&
424 (strcasecmp(current->
value,
"true") == 0 ||
425 strcmp(current->
value,
"1") == 0 ||
426 strcasecmp(current->
value,
"yes") == 0))
428 *value_out = PETSC_TRUE;
430 *value_out = PETSC_FALSE;
434 current = current->
next;
445#define __FUNCT__ "ParseAllBoundaryConditions"
458 PetscFunctionBeginUser;
460 ierr = MPI_Comm_rank(PETSC_COMM_WORLD, &rank); CHKERRQ(ierr);
464 char line_buffer[1024];
467 for (
int i = 0; i < 6; i++) {
471 configs_rank0[i].
params = NULL;
472 configs_rank0[i].
handler = NULL;
476 file = fopen(bcs_input_filename,
"r");
477 if (!file) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN,
"Could not open BCs file '%s'.", bcs_input_filename);
479 while (fgets(line_buffer,
sizeof(line_buffer), file)) {
480 char *current_pos = line_buffer;
481 while (isspace((
unsigned char)*current_pos)) current_pos++;
482 if (*current_pos ==
'#' || *current_pos ==
'\0' || *current_pos ==
'\n' || *current_pos ==
'\r')
continue;
484 char *face_str = strtok(current_pos,
" \t\n\r");
485 char *type_str = strtok(NULL,
" \t\n\r");
486 char *handler_str = strtok(NULL,
" \t\n\r");
488 if (!face_str || !type_str || !handler_str) {
496 const char* handler_name_for_log;
503 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);
509 LOG_ALLOW(
GLOBAL,
LOG_DEBUG,
" Parsed Face '%s': Type=%s, Handler=%s \n", face_str, type_str, handler_name_for_log);
513 configs_rank0[face_enum].
params = NULL;
517 while ((token = strtok(NULL,
" \t\n\r")) != NULL) {
518 char* equals_ptr = strchr(token,
'=');
525 char* key_str = token;
526 char* value_str = equals_ptr + 1;
529 ierr = PetscMalloc1(1, &new_param); CHKERRQ(ierr);
530 ierr = PetscStrallocpy(key_str, &new_param->
key); CHKERRQ(ierr);
531 ierr = PetscStrallocpy(value_str, &new_param->
value); CHKERRQ(ierr);
532 new_param->
next = NULL;
534 *param_next_ptr = new_param;
535 param_next_ptr = &new_param->
next;
549 for (
int i = 0; i < 6; i++) {
558 PetscInt n_params = 0;
562 ierr = MPI_Bcast(&n_params, 1, MPI_INT, 0, PETSC_COMM_WORLD);CHKERRQ(ierr);
571 for (
int j = 0; j < n_params; j++) {
572 char key_buf[256] = {0}, val_buf[256] = {0};
576 for (
int k = 0; k < j; k++) p = p->
next;
577 strncpy(key_buf, p->
key, 255);
578 strncpy(val_buf, p->
value, 255);
581 ierr = MPI_Bcast(key_buf, 256, MPI_CHAR, 0, PETSC_COMM_WORLD); CHKERRQ(ierr);
582 ierr = MPI_Bcast(val_buf, 256, MPI_CHAR, 0, PETSC_COMM_WORLD); CHKERRQ(ierr);
587 ierr = PetscMalloc1(1, &new_param); CHKERRQ(ierr);
588 ierr = PetscStrallocpy(key_buf, &new_param->
key); CHKERRQ(ierr);
589 ierr = PetscStrallocpy(val_buf, &new_param->
value); CHKERRQ(ierr);
590 new_param->
next = NULL;
591 *param_next_ptr = new_param;
592 param_next_ptr = &new_param->
next;
595 param_next_ptr = &((*param_next_ptr)->next);
603 for (
int i=0; i<6; i++) {
621 PetscFunctionReturn(0);
632#define __FUNCT__ "DeterminePeriodicity"
641 PetscInt periodic_flags[3] = {0, 0, 0};
643 PetscFunctionBeginUser;
644 ierr = MPI_Comm_rank(PETSC_COMM_WORLD, &rank); CHKERRQ(ierr);
647 for (PetscInt bi = 0; bi < simCtx->
block_number; bi++) {
648 const char *bcs_filename = simCtx->
bcs_files[bi];
649 if (!bcs_filename) SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_NULL,
"BCS filename for block %d is not set in SimCtx.", bi);
651 PetscBool file_exists;
652 snprintf(desc_buf,
sizeof(desc_buf),
"BCS file for block %d", bi);
653 ierr =
VerifyPathExistence(bcs_filename, PETSC_FALSE, PETSC_FALSE, desc_buf, &file_exists); CHKERRQ(ierr);
658 PetscBool global_is_periodic[3] = {PETSC_FALSE, PETSC_FALSE, PETSC_FALSE};
659 PetscBool is_set = PETSC_FALSE;
661 for (PetscInt bi = 0; bi < simCtx->
block_number; bi++) {
662 const char *bcs_filename = simCtx->
bcs_files[bi];
663 FILE *file = fopen(bcs_filename,
"r");
665 PetscBool face_is_periodic[6] = {PETSC_FALSE};
666 char line_buffer[1024];
668 while (fgets(line_buffer,
sizeof(line_buffer), file)) {
669 char *current_pos = line_buffer;
670 while (isspace((
unsigned char)*current_pos)) current_pos++;
671 if (*current_pos ==
'#' || *current_pos ==
'\0' || *current_pos ==
'\n')
continue;
674 char *face_str = strtok(current_pos,
" \t\n\r");
675 char *type_str = strtok(NULL,
" \t\n\r");
678 if (!face_str || !type_str)
continue;
681 if (strcasecmp(type_str,
"PERIODIC") == 0) {
685 face_is_periodic[face_enum] = PETSC_TRUE;
693 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_INCOMP,
"Inconsistent X-periodicity in file '%s' for block %d. Both -Xi and +Xi must be periodic or neither.", bcs_filename, bi);
695 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_INCOMP,
"Inconsistent Y-periodicity in file '%s' for block %d. Both -Eta and +Eta must be periodic or neither.", bcs_filename, bi);
697 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_INCOMP,
"Inconsistent Z-periodicity in file '%s' for block %d. Both -Zeta and +Zeta must be periodic or neither.", bcs_filename, bi);
703 global_is_periodic[0] = local_is_periodic[0];
704 global_is_periodic[1] = local_is_periodic[1];
705 global_is_periodic[2] = local_is_periodic[2];
708 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]) {
709 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_INCOMP,
710 "Periodicity mismatch between blocks. Block 0 requires (I:%d, J:%d, K:%d), but block %d (file '%s') has (I:%d, J:%d, K:%d).",
711 (
int)global_is_periodic[0], (
int)global_is_periodic[1], (
int)global_is_periodic[2],
713 (
int)local_is_periodic[0], (
int)local_is_periodic[1], (
int)local_is_periodic[2]);
718 periodic_flags[0] = (global_is_periodic[0]) ? 1 : 0;
719 periodic_flags[1] = (global_is_periodic[1]) ? 1 : 0;
720 periodic_flags[2] = (global_is_periodic[2]) ? 1 : 0;
723 periodic_flags[0], periodic_flags[1], periodic_flags[2]);
727 ierr = MPI_Bcast(periodic_flags, 3, MPIU_INT, 0, PETSC_COMM_WORLD); CHKERRQ(ierr);
734 PetscFunctionReturn(0);
741PetscErrorCode
VerifyPathExistence(
const char *path, PetscBool is_dir, PetscBool is_optional,
const char *description, PetscBool *exists)
745 MPI_Comm comm = PETSC_COMM_WORLD;
747 PetscFunctionBeginUser;
748 ierr = MPI_Comm_rank(comm, &rank); CHKERRQ(ierr);
752 ierr = PetscTestDirectory(path,
'r', exists); CHKERRQ(ierr);
754 ierr = PetscTestFile(path,
'r', exists); CHKERRQ(ierr);
769 PetscMPIInt exists_int = (rank == 0) ? (PetscMPIInt)(*exists) : 0;
770 ierr = MPI_Bcast(&exists_int, 1, MPI_INT, 0, comm); CHKERRMPI(ierr);
771 *exists = (PetscBool)exists_int;
774 if (!(*exists) && !is_optional) {
775 SETERRQ(comm, PETSC_ERR_FILE_OPEN,
"Mandatory %s not found. Rank 0 expected it at '%s'. Check path and permissions.", description, path);
778 PetscFunctionReturn(0);
785static PetscErrorCode
CheckDataFile(
UserCtx *user, PetscInt ti,
const char *fieldName,
const char *ext, PetscBool *fileExists)
789 MPI_Comm comm = PETSC_COMM_WORLD;
790 PetscInt placeholder_int = 0;
793 PetscFunctionBeginUser;
796 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_NULL,
"I/O context directory is NULL. Ensure it is set before calling CheckDataFile().");
799 ierr = MPI_Comm_rank(comm, &rank); CHKERRQ(ierr);
802 char filename[PETSC_MAX_PATH_LEN];
805 ierr = PetscSNPrintf(filename,
sizeof(filename),
"%s/%s%05"PetscInt_FMT
"_%d.%s",simCtx->
current_io_directory,fieldName, ti, placeholder_int, ext);
806 ierr = PetscTestFile(filename,
'r', fileExists); CHKERRQ(ierr);
807 if (!(*fileExists)) {
814 PetscMPIInt fileExists_int = (rank == 0) ? (PetscMPIInt)(*fileExists) : 0;
815 ierr = MPI_Bcast(&fileExists_int, 1, MPI_INT, 0, comm); CHKERRMPI(ierr);
816 *fileExists = (PetscBool)fileExists_int;
818 PetscFunctionReturn(0);
825static PetscErrorCode
ReadOptionalField(
UserCtx *user,
const char *field_name,
const char *field_label, Vec field_vec, PetscInt ti,
const char *ext)
828 PetscBool fileExists;
830 PetscFunctionBeginUser;
833 ierr =
CheckDataFile(user,ti, field_name, ext, &fileExists); CHKERRQ(ierr);
843 SETERRQ(PETSC_COMM_WORLD, ierr,
"Failed to read data for %s from existing file for step %d. The file may be corrupt or have an incorrect size.", field_label, ti);
852 PetscFunctionReturn(0);
862 PetscBool fileExists;
864 PetscFunctionBeginUser;
867 ierr =
CheckDataFile(user,ti, field_name, ext, &fileExists); CHKERRQ(ierr);
872 if(strcasecmp(field_name,
"DMSwarm_CellID") == 0 || strcasecmp(field_name,
"DMSwarm_pid")== 0 || strcasecmp(field_name,
"DMSwarm_location_status")== 0 ) {
883 SETERRQ(PETSC_COMM_WORLD, ierr,
"Failed to read data for %s from existing file for step %d. The file may be corrupt or have an incorrect size.", field_label, ti);
892 PetscFunctionReturn(0);
896#define __FUNCT__ "ReadFieldData"
902 const char *field_name,
908 char filename[PETSC_MAX_PATH_LEN];
910 PetscMPIInt rank,size;
914 PetscFunctionBeginUser;
918 SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,
"I/O context directory was not set before calling ReadFieldData().");
922 ierr = PetscObjectGetComm((PetscObject)field_vec,&comm);CHKERRQ(ierr);
923 ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr);
924 ierr = MPI_Comm_size(comm,&size);CHKERRQ(ierr);
926 const char *source_path = NULL;
930 SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,
"source_path was not set for the current execution mode.");
936 ierr = PetscSNPrintf(filename,
sizeof(filename),
937 "%s/%s%05" PetscInt_FMT
"_0.%s",
938 source_path,field_name,ti,ext);CHKERRQ(ierr);
941 "Attempting to read <%s> on rank %d/%d\n",
942 filename,(
int)rank,(
int)size);
952 PetscInt expectedSize,loadedSize;
954 ierr = PetscTestFile(filename,
'r',&found);CHKERRQ(ierr);
955 if(!found) SETERRQ(comm,PETSC_ERR_FILE_OPEN,
956 "Restart/Source file not found: %s",filename);
958 ierr = PetscViewerBinaryOpen(PETSC_COMM_SELF,filename,FILE_MODE_READ,&viewer);CHKERRQ(ierr);
962 ierr = VecCreate(PETSC_COMM_SELF, &temp_vec); CHKERRQ(ierr);
963 ierr = VecLoad(temp_vec,viewer);CHKERRQ(ierr);
964 ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
967 ierr = VecGetSize(field_vec, &expectedSize);CHKERRQ(ierr);
968 ierr = VecGetSize(temp_vec, &loadedSize);CHKERRQ(ierr);
969 if (loadedSize != expectedSize) {
970 SETERRQ(comm,PETSC_ERR_FILE_UNEXPECTED,
971 "File %s holds %d entries – expected %d for field '%s'",
972 filename, loadedSize, expectedSize, field_name);
976 ierr = VecCopy(temp_vec, field_vec);CHKERRQ(ierr);
979 ierr = VecDestroy(&temp_vec);CHKERRQ(ierr);
995 "Loaded <%s> (serial path)\n",filename);
998 PetscFunctionReturn(0);
1004 PetscInt globalSize;
1005 ierr = VecGetSize(field_vec,&globalSize);CHKERRQ(ierr);
1008 const char *dmtype = NULL;
1013 const PetscScalar *seqArray = NULL;
1020 ierr = PetscTestFile(filename,
'r',&found);CHKERRQ(ierr);
1021 if(!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,
1022 "Restart file not found: %s",filename);
1025 ierr = VecCreate(PETSC_COMM_SELF,&seq_vec);CHKERRQ(ierr);
1026 ierr = VecSetType(seq_vec,VECSEQ);CHKERRQ(ierr);
1028 ierr = PetscViewerBinaryOpen(PETSC_COMM_SELF,filename,
1029 FILE_MODE_READ,&viewer);CHKERRQ(ierr);
1030 ierr = VecLoad(seq_vec,viewer);CHKERRQ(ierr);
1031 ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
1035 ierr = VecGetSize(seq_vec,&loaded);CHKERRQ(ierr);
1036 if(loaded != globalSize)
1037 SETERRQ(comm,PETSC_ERR_FILE_UNEXPECTED,
1038 "File %s holds %d entries – expected %d",
1039 filename,loaded,globalSize);
1042 ierr = VecGetArrayRead(seq_vec,&seqArray);CHKERRQ(ierr);
1045 "Rank 0 successfully loaded <%s>\n",filename);
1049 ierr = VecGetDM(field_vec, &dm); CHKERRQ(ierr);
1050 if (dm) { ierr = DMGetType(dm, &dmtype); CHKERRQ(ierr); }
1052 if (dmtype && !strcmp(dmtype, DMDA)) {
1058 ierr = DMDACreateNaturalVector(dm, &nat); CHKERRQ(ierr);
1064 ierr = VecScatterCreateToZero(nat, &scatter, &nat_seq); CHKERRQ(ierr);
1067 ierr = VecScatterBegin(scatter, (rank == 0 ? seq_vec : nat_seq), nat,
1068 INSERT_VALUES, SCATTER_REVERSE); CHKERRQ(ierr);
1069 ierr = VecScatterEnd(scatter, (rank == 0 ? seq_vec : nat_seq), nat,
1070 INSERT_VALUES, SCATTER_REVERSE); CHKERRQ(ierr);
1073 ierr = DMDANaturalToGlobalBegin(dm, nat, INSERT_VALUES, field_vec); CHKERRQ(ierr);
1074 ierr = DMDANaturalToGlobalEnd(dm, nat, INSERT_VALUES, field_vec); CHKERRQ(ierr);
1077 ierr = VecScatterDestroy(&scatter); CHKERRQ(ierr);
1078 ierr = VecDestroy(&nat_seq); CHKERRQ(ierr);
1079 ierr = VecDestroy(&nat); CHKERRQ(ierr);
1086 PetscScalar *buffer = NULL;
1088 buffer = (PetscScalar *)seqArray;
1090 ierr = PetscMalloc1(globalSize, &buffer); CHKERRQ(ierr);
1093 ierr = MPI_Bcast(buffer, (
int)globalSize, MPIU_SCALAR, 0, comm); CHKERRQ(ierr);
1096 PetscInt rstart, rend, loc;
1097 PetscScalar *locArray;
1099 ierr = VecGetOwnershipRange(field_vec, &rstart, &rend); CHKERRQ(ierr);
1100 loc = rend - rstart;
1102 ierr = VecGetArray(field_vec, &locArray); CHKERRQ(ierr);
1103 ierr = PetscMemcpy(locArray, buffer + rstart, loc *
sizeof(PetscScalar)); CHKERRQ(ierr);
1104 ierr = VecRestoreArray(field_vec, &locArray); CHKERRQ(ierr);
1107 ierr = PetscFree(buffer); CHKERRQ(ierr);
1113 ierr = VecRestoreArrayRead(seq_vec, &seqArray); CHKERRQ(ierr);
1114 ierr = VecDestroy(&seq_vec); CHKERRQ(ierr);
1118 "Loaded <%s> (parallel path)\n",filename);
1121 PetscFunctionReturn(0);
1131 PetscErrorCode ierr;
1134 const char *source_path = NULL;
1135 const char *eulerian_ext =
"dat";
1145 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE,
"Invalid execution mode for reading simulation fields.");
1155 ierr =
ReadFieldData(user,
"ufield", user->
Ucat, ti, eulerian_ext); CHKERRQ(ierr);
1161 ierr =
ReadFieldData(user,
"pfield", user->
P, ti, eulerian_ext); CHKERRQ(ierr);
1171 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"ParticleCount Vec is NULL but np>0");
1175 ierr =
ReadOptionalField(user,
"psifield",
"Scalar Psi Field", user->
Psi, ti, eulerian_ext); CHKERRQ(ierr);
1210 PetscErrorCode ierr;
1211 const char *eulerian_ext =
"dat";
1234 PetscErrorCode ierr;
1235 const char *eulerian_ext =
"dat";
1242 ierr =
ReadOptionalField(user,
"Nu_t",
"Turbulent Viscosity", user->
Nu_t, ti, eulerian_ext); CHKERRQ(ierr);
1243 ierr =
ReadOptionalField(user,
"cs",
"Smagorinsky Constant (Cs)", user->
CS, ti, eulerian_ext); CHKERRQ(ierr);
1245 DMGlobalToLocalBegin(user->
da, user->
CS, INSERT_VALUES, user->
lCs);
1246 DMGlobalToLocalEnd(user->
da, user->
CS, INSERT_VALUES, user->
lCs);
1248 DMGlobalToLocalBegin(user->
da, user->
Nu_t, INSERT_VALUES, user->
lNu_t);
1249 DMGlobalToLocalEnd(user->
da, user->
Nu_t, INSERT_VALUES, user->
lNu_t);
1262 PetscErrorCode ierr;
1263 const char *eulerian_ext =
"dat";
1271 ierr =
ReadOptionalField(user,
"Nu_t",
"Turbulent Viscosity", user->
Nu_t, ti, eulerian_ext); CHKERRQ(ierr);
1278 DMGlobalToLocalBegin(user->
da, user->
Nu_t, INSERT_VALUES, user->
lNu_t);
1279 DMGlobalToLocalEnd(user->
da, user->
Nu_t, INSERT_VALUES, user->
lNu_t);
1296 PetscErrorCode ierr;
1302 swarm = user->
swarm;
1307 ierr = DMSwarmCreateGlobalVectorFromField(swarm, field_name, &fieldVec);CHKERRQ(ierr);
1312 ierr =
ReadFieldData(user, field_name, fieldVec, ti, ext);CHKERRQ(ierr);
1315 ierr = DMSwarmDestroyGlobalVectorFromField(swarm, field_name, &fieldVec);CHKERRQ(ierr);
1317 PetscFunctionReturn(0);
1326 PetscErrorCode ierr;
1327 DM swarm = user->
swarm;
1329 PetscInt nlocal, nglobal, bs, i;
1330 const PetscScalar *scalar_array;
1331 void *field_array_void;
1334 PetscFunctionBeginUser;
1339 ierr = DMSwarmGetLocalSize(swarm, &nlocal); CHKERRQ(ierr);
1340 ierr = DMSwarmGetSize(swarm, &nglobal); CHKERRQ(ierr);
1342 ierr = DMSwarmGetField(swarm, field_name, &bs, NULL, NULL); CHKERRQ(ierr);
1343 ierr = DMSwarmRestoreField(swarm, field_name, &bs, NULL, NULL); CHKERRQ(ierr);
1346 ierr = VecCreate(PETSC_COMM_WORLD, &temp_vec); CHKERRQ(ierr);
1347 ierr = VecSetType(temp_vec, VECMPI); CHKERRQ(ierr);
1348 ierr = VecSetSizes(temp_vec, nlocal * bs, nglobal * bs); CHKERRQ(ierr);
1349 ierr = VecSetBlockSize(temp_vec, bs); CHKERRQ(ierr);
1350 ierr = VecSetUp(temp_vec); CHKERRQ(ierr);
1353 ierr =
ReadFieldData(user, field_name, temp_vec, ti, ext); CHKERRQ(ierr);
1356 ierr = VecGetArrayRead(temp_vec, &scalar_array); CHKERRQ(ierr);
1357 ierr = DMSwarmGetField(swarm, field_name, NULL, NULL, &field_array_void); CHKERRQ(ierr);
1360 if (strcmp(field_name,
"DMSwarm_pid") == 0) {
1361 PetscInt64 *int64_array = (PetscInt64 *)field_array_void;
1362 for (i = 0; i < nlocal * bs; i++) {
1363 int64_array[i] = (PetscInt64)scalar_array[i];
1366 PetscInt *int_array = (PetscInt *)field_array_void;
1367 for (i = 0; i < nlocal * bs; i++) {
1368 int_array[i] = (PetscInt)scalar_array[i];
1373 ierr = DMSwarmRestoreField(swarm, field_name, NULL, NULL, &field_array_void); CHKERRQ(ierr);
1374 ierr = VecRestoreArrayRead(temp_vec, &scalar_array); CHKERRQ(ierr);
1377 ierr = VecDestroy(&temp_vec); CHKERRQ(ierr);
1379 PetscFunctionReturn(0);
1388 PetscErrorCode ierr;
1391 const char *source_path = NULL;
1392 const char *particle_ext =
"dat";
1394 PetscFunctionBeginUser;
1395 ierr = DMSwarmGetSize(user->
swarm, &nGlobal); CHKERRQ(ierr);
1400 PetscFunctionReturn(0);
1412 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONGSTATE,
"Invalid execution mode for reading simulation fields.");
1425 SETERRQ(PETSC_COMM_WORLD, ierr,
"Failed to read MANDATORY 'position' field for step %d. Cannot continue.", ti);
1436 ierr =
ReadOptionalSwarmField(user,
"DMSwarm_location_status",
"Migration Status", ti, particle_ext); CHKERRQ(ierr);
1441 PetscFunctionReturn(0);
1446#define __FUNCT__ "WriteFieldData"
1452 const char *field_name,
1457 PetscErrorCode ierr;
1459 PetscMPIInt rank, size;
1461 const PetscInt placeholder_int = 0;
1462 char filename[PETSC_MAX_PATH_LEN];
1465 PetscFunctionBeginUser;
1469 SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,
"I/O context directory was not set before calling WriteFieldData().");
1475 ierr = PetscObjectGetComm((PetscObject)field_vec,&comm);CHKERRQ(ierr);
1476 ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr);
1477 ierr = MPI_Comm_size(comm,&size);CHKERRQ(ierr);
1479 ierr = PetscSNPrintf(filename,
sizeof(filename),
1480 "%s/%s%05" PetscInt_FMT
"_%d.%s",
1484 " Preparing to write <%s> on rank %d/%d\n",
1485 filename,rank,size);
1493 ierr = PetscViewerBinaryOpen(comm,filename,
1494 FILE_MODE_WRITE,&viewer);CHKERRQ(ierr);
1495 ierr = VecView(field_vec,viewer);CHKERRQ(ierr);
1496 ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
1499 " Wrote <%s> (serial path)\n",filename);
1500 PetscFunctionReturn(0);
1509 const char *dmtype = NULL;
1513 ierr = VecGetDM(field_vec, &dm); CHKERRQ(ierr);
1514 if (dm) { ierr = DMGetType(dm, &dmtype); CHKERRQ(ierr); }
1516 if (dmtype && !strcmp(dmtype, DMDA)) {
1518 ierr = DMDACreateNaturalVector(dm, &nat); CHKERRQ(ierr);
1519 ierr = DMDAGlobalToNaturalBegin(dm, field_vec, INSERT_VALUES, nat); CHKERRQ(ierr);
1520 ierr = DMDAGlobalToNaturalEnd(dm, field_vec, INSERT_VALUES, nat); CHKERRQ(ierr);
1523 ierr = VecScatterCreateToZero(nat, &scatter, &seq_vec); CHKERRQ(ierr);
1526 ierr = VecScatterCreateToZero(field_vec, &scatter, &seq_vec); CHKERRQ(ierr);
1530 ierr = VecScatterBegin(scatter, (nat ? nat : field_vec), seq_vec,
1531 INSERT_VALUES, SCATTER_FORWARD); CHKERRQ(ierr);
1532 ierr = VecScatterEnd(scatter, (nat ? nat : field_vec), seq_vec,
1533 INSERT_VALUES, SCATTER_FORWARD); CHKERRQ(ierr);
1540 PetscReal vmin,vmax;
1541 ierr = VecMin(seq_vec,NULL,&vmin);CHKERRQ(ierr);
1542 ierr = VecMax(seq_vec,NULL,&vmax);CHKERRQ(ierr);
1544 " <%s> range = [%.4e … %.4e]\n",
1545 field_name,(
double)vmin,(
double)vmax);
1547 ierr = PetscViewerBinaryOpen(PETSC_COMM_SELF,filename,
1548 FILE_MODE_WRITE,&viewer);CHKERRQ(ierr);
1549 ierr = VecView(seq_vec,viewer);CHKERRQ(ierr);
1550 ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
1553 " Wrote <%s> (parallel path)\n",filename);
1557 ierr = VecScatterDestroy(&scatter);CHKERRQ(ierr);
1558 ierr = VecDestroy(&seq_vec);CHKERRQ(ierr);
1559 if (nat) { ierr = VecDestroy(&nat); CHKERRQ(ierr); }
1562 PetscFunctionReturn(0);
1573 PetscErrorCode ierr;
1632 PetscErrorCode ierr;
1654 PetscErrorCode ierr;
1661 DMLocalToGlobalBegin(user->
da, user->
lCs, INSERT_VALUES, user->
CS);
1662 DMLocalToGlobalEnd(user->
da, user->
lCs, INSERT_VALUES, user->
CS);
1664 DMLocalToGlobalBegin(user->
da, user->
lNu_t, INSERT_VALUES, user->
Nu_t);
1665 DMLocalToGlobalEnd(user->
da, user->
lNu_t, INSERT_VALUES, user->
Nu_t);
1684 PetscErrorCode ierr;
1705 PetscErrorCode ierr;
1709 PetscFunctionBeginUser;
1715 swarm = user->
swarm;
1723 "Attempting to create global vector from field: %s\n",
1725 ierr = DMSwarmCreateGlobalVectorFromField(swarm, field_name, &fieldVec);CHKERRQ(ierr);
1732 "Calling WriteFieldData for field: %s\n",
1734 ierr =
WriteFieldData(user, field_name, fieldVec, ti, ext);CHKERRQ(ierr);
1742 "Destroying the global vector for field: %s\n",
1744 ierr = DMSwarmDestroyGlobalVectorFromField(swarm, field_name, &fieldVec);CHKERRQ(ierr);
1748 "Successfully wrote swarm data for field: %s\n",
1751 PetscFunctionReturn(0);
1760 PetscErrorCode ierr;
1761 DM swarm = user->
swarm;
1763 PetscInt nlocal, nglobal,bs,i;
1764 void *field_array_void;
1765 PetscScalar *scalar_array;
1767 PetscFunctionBeginUser;
1772 ierr = DMSwarmGetLocalSize(swarm, &nlocal); CHKERRQ(ierr);
1773 ierr = DMSwarmGetSize(swarm, &nglobal); CHKERRQ(ierr);
1774 ierr = DMSwarmGetField(swarm, field_name, &bs, NULL, &field_array_void); CHKERRQ(ierr);
1777 ierr = VecCreate(PETSC_COMM_WORLD, &temp_vec); CHKERRQ(ierr);
1778 ierr = VecSetType(temp_vec, VECMPI); CHKERRQ(ierr);
1779 ierr = VecSetSizes(temp_vec, nlocal*bs, nglobal*bs); CHKERRQ(ierr);
1780 ierr = VecSetUp(temp_vec); CHKERRQ(ierr);
1783 DMSwarmVectorDefineField(swarm,
"position");
1785 ierr = VecGetArray(temp_vec, &scalar_array); CHKERRQ(ierr);
1787 if(strcasecmp(field_name,
"DMSwarm_pid") == 0){
1788 PetscInt64 *int64_array = (PetscInt64 *)field_array_void;
1790 for (i = 0; i < nlocal*bs; i++) {
1791 scalar_array[i] = (PetscScalar)int64_array[i];
1794 PetscInt *int_array = (PetscInt *)field_array_void;
1796 for (i = 0; i < nlocal*bs; i++) {
1797 scalar_array[i] = (PetscScalar)int_array[i];
1802 ierr = VecRestoreArray(temp_vec, &scalar_array); CHKERRQ(ierr);
1803 ierr = DMSwarmRestoreField(swarm, field_name, &bs, NULL, &field_array_void); CHKERRQ(ierr);
1806 ierr =
WriteFieldData(user, field_name, temp_vec, ti, ext); CHKERRQ(ierr);
1809 ierr = VecDestroy(&temp_vec); CHKERRQ(ierr);
1811 PetscFunctionReturn(0);
1820 PetscErrorCode ierr;
1823 PetscFunctionBeginUser;
1826 if (!user->
swarm || simCtx->
np <= 0) {
1827 PetscFunctionReturn(0);
1864 PetscFunctionReturn(0);
1873 PetscErrorCode ierr;
1876 PetscInt globalSize;
1878 const char *dmtype = NULL;
1881 Vec nat = NULL, seqNat = NULL;
1882 VecScatter scatNat = NULL;
1883 const PetscScalar *nar = NULL;
1884 PetscScalar *buf = NULL;
1888 VecScatter scat = NULL;
1889 const PetscScalar *sar = NULL;
1891 PetscFunctionBeginUser;
1893 ierr = PetscObjectGetComm((PetscObject)inVec, &comm); CHKERRQ(ierr);
1894 ierr = MPI_Comm_rank(comm, &rank); CHKERRQ(ierr);
1895 ierr = VecGetSize(inVec, &globalSize); CHKERRQ(ierr);
1899 ierr = VecGetDM(inVec, &dm); CHKERRQ(ierr);
1900 if (dm) { ierr = DMGetType(dm, &dmtype); CHKERRQ(ierr); }
1902 if (dmtype && !strcmp(dmtype, DMDA)) {
1904 ierr = DMDACreateNaturalVector(dm, &nat); CHKERRQ(ierr);
1905 ierr = DMDAGlobalToNaturalBegin(dm, inVec, INSERT_VALUES, nat); CHKERRQ(ierr);
1906 ierr = DMDAGlobalToNaturalEnd (dm, inVec, INSERT_VALUES, nat); CHKERRQ(ierr);
1908 ierr = VecScatterCreateToZero(nat, &scatNat, &seqNat); CHKERRQ(ierr);
1909 ierr = VecScatterBegin(scatNat, nat, seqNat, INSERT_VALUES, SCATTER_FORWARD); CHKERRQ(ierr);
1910 ierr = VecScatterEnd (scatNat, nat, seqNat, INSERT_VALUES, SCATTER_FORWARD); CHKERRQ(ierr);
1914 ierr = VecGetLocalSize(seqNat, &nseq); CHKERRQ(ierr);
1915 ierr = VecGetArrayRead(seqNat, &nar); CHKERRQ(ierr);
1917 ierr = PetscMalloc1(nseq, &buf); CHKERRQ(ierr);
1918 ierr = PetscMemcpy(buf, nar, (
size_t)nseq *
sizeof(PetscScalar)); CHKERRQ(ierr);
1920 ierr = VecRestoreArrayRead(seqNat, &nar); CHKERRQ(ierr);
1921 *arrayOut = (
double*)buf;
1924 ierr = VecScatterDestroy(&scatNat); CHKERRQ(ierr);
1925 ierr = VecDestroy(&seqNat); CHKERRQ(ierr);
1926 ierr = VecDestroy(&nat); CHKERRQ(ierr);
1929 ierr = VecScatterCreateToZero(inVec, &scat, &seq); CHKERRQ(ierr);
1930 ierr = VecScatterBegin(scat, inVec, seq, INSERT_VALUES, SCATTER_FORWARD); CHKERRQ(ierr);
1931 ierr = VecScatterEnd (scat, inVec, seq, INSERT_VALUES, SCATTER_FORWARD); CHKERRQ(ierr);
1935 ierr = VecGetLocalSize(seq, &nseq); CHKERRQ(ierr);
1936 ierr = VecGetArrayRead(seq, &sar); CHKERRQ(ierr);
1938 ierr = PetscMalloc1(nseq, &buf); CHKERRQ(ierr);
1939 ierr = PetscMemcpy(buf, sar, (
size_t)nseq *
sizeof(PetscScalar)); CHKERRQ(ierr);
1941 ierr = VecRestoreArrayRead(seq, &sar); CHKERRQ(ierr);
1942 *arrayOut = (
double*)buf;
1945 ierr = VecScatterDestroy(&scat); CHKERRQ(ierr);
1946 ierr = VecDestroy(&seq); CHKERRQ(ierr);
1949 PetscFunctionReturn(0);
1956PetscErrorCode
SwarmFieldToArrayOnRank0(DM swarm,
const char *field_name, PetscInt *n_total_particles, PetscInt *n_components,
void **gathered_array)
1958 PetscErrorCode ierr;
1959 PetscMPIInt rank, size;
1960 PetscInt nlocal, nglobal, bs;
1961 void *local_array_void;
1962 size_t element_size = 0;
1964 PetscFunctionBeginUser;
1966 ierr = MPI_Comm_rank(PETSC_COMM_WORLD, &rank); CHKERRQ(ierr);
1967 ierr = MPI_Comm_size(PETSC_COMM_WORLD, &size); CHKERRQ(ierr);
1970 ierr = DMSwarmGetLocalSize(swarm, &nlocal); CHKERRQ(ierr);
1971 ierr = DMSwarmGetSize(swarm, &nglobal); CHKERRQ(ierr);
1972 ierr = DMSwarmGetField(swarm, field_name, &bs, NULL, &local_array_void); CHKERRQ(ierr);
1975 if (strcasecmp(field_name,
"DMSwarm_pid") == 0) {
1976 element_size =
sizeof(PetscInt64);
1977 }
else if (strcasecmp(field_name,
"DMSwarm_CellID") == 0 || strcasecmp(field_name,
"DMSwarm_location_status") == 0) {
1978 element_size =
sizeof(PetscInt);
1980 element_size =
sizeof(PetscScalar);
1984 *n_total_particles = nglobal;
1986 *gathered_array = NULL;
1991 ierr = PetscMalloc(nglobal * bs * element_size, gathered_array); CHKERRQ(ierr);
1992 ierr = PetscMemcpy(*gathered_array, local_array_void, nglobal * bs * element_size); CHKERRQ(ierr);
1995 PetscInt *recvcounts = NULL, *displs = NULL;
1997 ierr = PetscMalloc1(size, &recvcounts); CHKERRQ(ierr);
1998 ierr = PetscMalloc1(size, &displs); CHKERRQ(ierr);
2000 PetscInt sendcount = nlocal * bs;
2003 ierr = MPI_Gather(&sendcount, 1, MPIU_INT, recvcounts, 1, MPIU_INT, 0, PETSC_COMM_WORLD); CHKERRQ(ierr);
2008 for (PetscMPIInt i = 0; i < size; i++) recvcounts[i] *= element_size;
2009 for (PetscMPIInt i = 1; i < size; i++) displs[i] = displs[i-1] + recvcounts[i-1];
2011 ierr = PetscMalloc(nglobal * bs * element_size, gathered_array); CHKERRQ(ierr);
2015 ierr = MPI_Gatherv(local_array_void, nlocal * bs * element_size, MPI_BYTE,
2016 *gathered_array, recvcounts, displs, MPI_BYTE,
2017 0, PETSC_COMM_WORLD); CHKERRQ(ierr);
2020 ierr = PetscFree(recvcounts); CHKERRQ(ierr);
2021 ierr = PetscFree(displs); CHKERRQ(ierr);
2025 ierr = DMSwarmRestoreField(swarm, field_name, &bs, NULL, &local_array_void); CHKERRQ(ierr);
2027 PetscFunctionReturn(0);
2036 PetscErrorCode ierr;
2038 Cmpnts global_min_coords, global_max_coords;
2039 PetscReal StartTime;
2040 PetscInt StartStep,StepsToRun,total_num_particles;
2041 PetscMPIInt num_mpi_procs;
2045 num_mpi_procs = simCtx->
size;
2049 total_num_particles = simCtx->
np;
2053 PetscFunctionBeginUser;
2055 if (!user) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"DisplayBanner - UserCtx pointer is NULL.");
2058 ierr = MPI_Comm_rank(PETSC_COMM_WORLD, &rank); CHKERRQ(ierr);
2063 if (bboxlist_on_rank0 && num_mpi_procs > 0) {
2064 global_min_coords = bboxlist_on_rank0[0].
min_coords;
2065 global_max_coords = bboxlist_on_rank0[0].
max_coords;
2066 for (PetscMPIInt p = 1; p < num_mpi_procs; ++p) {
2067 global_min_coords.
x = PetscMin(global_min_coords.
x, bboxlist_on_rank0[p].
min_coords.
x);
2068 global_min_coords.
y = PetscMin(global_min_coords.
y, bboxlist_on_rank0[p].
min_coords.
y);
2069 global_min_coords.
z = PetscMin(global_min_coords.
z, bboxlist_on_rank0[p].
min_coords.
z);
2070 global_max_coords.
x = PetscMax(global_max_coords.
x, bboxlist_on_rank0[p].
max_coords.
x);
2071 global_max_coords.
y = PetscMax(global_max_coords.
y, bboxlist_on_rank0[p].
max_coords.
y);
2072 global_max_coords.
z = PetscMax(global_max_coords.
z, bboxlist_on_rank0[p].
max_coords.
z);
2079 LOG_ALLOW(
LOCAL,
LOG_WARNING,
"(Rank 0) - bboxlist not provided or num_mpi_procs <=0; using user->bbox for domain bounds.\n");
2084 ierr = PetscPrintf(PETSC_COMM_SELF,
"\n"); CHKERRQ(ierr);
2085 ierr = PetscPrintf(PETSC_COMM_SELF,
"=============================================================\n"); CHKERRQ(ierr);
2086 ierr = PetscPrintf(PETSC_COMM_SELF,
" CASE SUMMARY \n"); CHKERRQ(ierr);
2087 ierr = PetscPrintf(PETSC_COMM_SELF,
"=============================================================\n"); CHKERRQ(ierr);
2088 ierr = PetscPrintf(PETSC_COMM_SELF,
" Grid Points : %d X %d X %d\n", user->
IM, user->
JM, user->
KM); CHKERRQ(ierr);
2089 ierr = PetscPrintf(PETSC_COMM_SELF,
" Cells : %d X %d X %d\n", user->
IM - 1, user->
JM - 1, user->
KM - 1); CHKERRQ(ierr);
2090 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);
2091 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);
2092 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);
2094 ierr = PetscPrintf(PETSC_COMM_SELF,
"-------------------- Boundary Conditions --------------------\n"); CHKERRQ(ierr);
2095 const int face_name_width = 17;
2096 for (PetscInt i_face = 0; i_face < 6; ++i_face) {
2104 Cmpnts inlet_velocity = {0.0,0.0,0.0};
2109 ierr = PetscPrintf(PETSC_COMM_SELF,
" Face %-*s : %s - %s - [%.4f,%.4f,%.4f]\n",
2110 face_name_width, face_str, bc_type_str, bc_handler_type_str,inlet_velocity.
x,inlet_velocity.
y,inlet_velocity.
z); CHKERRQ(ierr);
2112 PetscReal v_max = 0.0;
2115 ierr = PetscPrintf(PETSC_COMM_SELF,
" Face %-*s : %s - %s - v_max=%.4f\n",
2116 face_name_width, face_str, bc_type_str, bc_handler_type_str, v_max); CHKERRQ(ierr);
2118 const char *source_file =
"(missing)";
2120 if (strcasecmp(param->key,
"source_file") == 0 && param->value) {
2121 source_file = param->value;
2125 ierr = PetscPrintf(PETSC_COMM_SELF,
" Face %-*s : %s - %s - source_file=%s\n",
2126 face_name_width, face_str, bc_type_str, bc_handler_type_str, source_file); CHKERRQ(ierr);
2130 PetscBool trimflag,foundflux,foundtrimflag;
2133 ierr = PetscPrintf(PETSC_COMM_SELF,
" Face %-*s : %s - %s - [%.4f] - %s\n",
2134 face_name_width, face_str, bc_type_str, bc_handler_type_str,flux,trimflag?
"Trim Ucont":
"No Trim"); CHKERRQ(ierr);
2136 ierr = PetscPrintf(PETSC_COMM_SELF,
" Face %-*s : %s - %s\n",
2137 face_name_width, face_str, bc_type_str,bc_handler_type_str); CHKERRQ(ierr);
2141 ierr = PetscPrintf(PETSC_COMM_SELF,
"-------------------------------------------------------------\n"); CHKERRQ(ierr);
2142 ierr = PetscPrintf(PETSC_COMM_SELF,
" Run Mode : %s\n", simCtx->
OnlySetup ?
"SETUP ONLY" :
"Full Simulation"); CHKERRQ(ierr);
2143 ierr = PetscPrintf(PETSC_COMM_SELF,
" Start Time : %.4f\n", (
double)StartTime); CHKERRQ(ierr);
2144 ierr = PetscPrintf(PETSC_COMM_SELF,
" Timestep Size : %.4f\n", (
double)simCtx->
dt); CHKERRQ(ierr);
2145 ierr = PetscPrintf(PETSC_COMM_SELF,
" Starting Step : %d\n", StartStep); CHKERRQ(ierr);
2146 ierr = PetscPrintf(PETSC_COMM_SELF,
" Total Steps to Run : %d\n", StepsToRun); CHKERRQ(ierr);
2147 ierr = PetscPrintf(PETSC_COMM_SELF,
" Ending Step : %d\n", StartStep + StepsToRun); CHKERRQ(ierr);
2148 if (simCtx->
tiout > 0) {
2149 ierr = PetscPrintf(PETSC_COMM_SELF,
" Field/Restart Cadence : every %d step(s)\n", simCtx->
tiout); CHKERRQ(ierr);
2151 ierr = PetscPrintf(PETSC_COMM_SELF,
" Field/Restart Cadence : DISABLED\n"); CHKERRQ(ierr);
2153 ierr = PetscPrintf(PETSC_COMM_SELF,
" Immersed Boundary : %s\n", simCtx->
immersed ?
"ENABLED" :
"DISABLED"); CHKERRQ(ierr);
2157 " Runtime Walltime Guard : %s (warmup=%d, multiplier=%.2f, min=%.1f s, alpha=%.2f)\n",
2165 ierr = PetscPrintf(PETSC_COMM_SELF,
" Runtime Walltime Guard : DISABLED\n"); CHKERRQ(ierr);
2167 ierr = PetscPrintf(PETSC_COMM_SELF,
" Number of MPI Processes : %d\n", num_mpi_procs); CHKERRQ(ierr);
2168 ierr = PetscPrintf(PETSC_COMM_WORLD,
" Number of Particles : %d\n", total_num_particles); CHKERRQ(ierr);
2169 if (simCtx->
np > 0) {
2173 ierr = PetscPrintf(PETSC_COMM_SELF,
" Particle Console Cadence : every %d step(s)\n", simCtx->
particleConsoleOutputFreq); CHKERRQ(ierr);
2175 ierr = PetscPrintf(PETSC_COMM_SELF,
" Particle Console Cadence : DISABLED\n"); CHKERRQ(ierr);
2177 ierr = PetscPrintf(PETSC_COMM_SELF,
" Particle Log Row Sampling : every %d particle(s)\n", simCtx->
LoggingFrequency); CHKERRQ(ierr);
2179 ierr = PetscPrintf(PETSC_COMM_SELF,
" Particle Restart Mode : %s\n", simCtx->
particleRestartMode); CHKERRQ(ierr);
2181 ierr = PetscPrintf(PETSC_COMM_SELF,
" Particle Initialization Mode: %s\n", particle_init_str); CHKERRQ(ierr);
2182 ierr = PetscPrintf(PETSC_COMM_SELF,
" Interpolation Method : %s\n",
2189 ierr = PetscPrintf(PETSC_COMM_SELF,
" Particles Initialized At : --- (No INLET face identified)\n"); CHKERRQ(ierr);
2195 ierr = PetscPrintf(PETSC_COMM_WORLD,
" Reynolds Number : %le\n", simCtx->
ren); CHKERRQ(ierr);
2200 ierr = PetscPrintf(PETSC_COMM_WORLD,
" Initial Pseudo-CFL : %le\n", simCtx->
pseudo_cfl); CHKERRQ(ierr);
2201 ierr = PetscPrintf(PETSC_COMM_WORLD,
" Large Eddy Simulation Model : %s\n",
LESModelToString(simCtx->
les)); CHKERRQ(ierr);
2203 ierr = PetscPrintf(PETSC_COMM_SELF,
" Field Initialization Mode : %s\n", field_init_str); CHKERRQ(ierr);
2208 ierr = PetscPrintf(PETSC_COMM_WORLD,
" Analytical Solution Type : %s\n", simCtx->
AnalyticalSolutionType); CHKERRQ(ierr);
2210 ierr = PetscPrintf(PETSC_COMM_SELF,
"=============================================================\n"); CHKERRQ(ierr);
2211 ierr = PetscPrintf(PETSC_COMM_SELF,
"\n"); CHKERRQ(ierr);
2213 PetscFunctionReturn(0);
2217#define __FUNCT__ "ParsePostProcessingSettings"
2226 PetscBool startTimeSet, endTimeSet, timeStepSet;
2228 PetscFunctionBeginUser;
2231 if (!simCtx || !simCtx->
pps) {
2232 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_NULL,
"SimCtx or its pps member is NULL in ParsePostProcessingSettings.");
2261 file = fopen(configFile,
"r");
2264 while (fgets(line,
sizeof(line), file)) {
2265 char *key, *value, *comment;
2266 comment = strchr(line,
'#');
if (comment) *comment =
'\0';
2268 key = strtok(line,
"="); value = strtok(NULL,
"=");
2271 if (strcmp(key,
"startTime") == 0) pps->
startTime = atoi(value);
2272 else if (strcmp(key,
"endTime") == 0) pps->
endTime = atoi(value);
2273 else if (strcmp(key,
"timeStep") == 0) pps->
timeStep = atoi(value);
2274 else if (strcmp(key,
"output_particles") == 0) {
2275 if (strcasecmp(value,
"true") == 0) pps->
outputParticles = PETSC_TRUE;
2277 else if (strcasecmp(key,
"process_pipeline") == 0) {
2280 }
else if (strcasecmp(key,
"output_fields_instantaneous") == 0) {
2283 }
else if (strcasecmp(key,
"output_fields_averaged") == 0) {
2286 }
else if (strcasecmp(key,
"output_prefix") == 0) {
2289 }
else if (strcasecmp(key,
"particle_output_prefix") == 0) {
2292 }
else if (strcasecmp(key,
"particle_fields_instantaneous") == 0) {
2295 }
else if (strcasecmp(key,
"particle_pipeline") == 0) {
2298 }
else if (strcasecmp(key,
"particle_output_freq") == 0) {
2300 }
else if (strcasecmp(key,
"statistics_pipeline") == 0) {
2303 }
else if (strcasecmp(key,
"statistics_output_prefix") == 0) {
2306 }
else if (strcasecmp(key,
"particleExt") == 0) {
2309 }
else if (strcasecmp(key,
"eulerianExt") == 0) {
2312 }
else if (strcmp(key,
"reference_ip") == 0) {pps->
reference[0] = atoi(value);
2313 }
else if (strcmp(key,
"reference_jp") == 0) {pps->
reference[1] = atoi(value);
2314 }
else if (strcmp(key,
"reference_kp") == 0) {pps->
reference[2] = atoi(value);
2315 }
else if (strcasecmp(key,
"source_directory") == 0) {
2326 LOG_ALLOW(
GLOBAL,
LOG_WARNING,
"Could not open post-processing config file '%s'. Using defaults and command-line overrides.\n", configFile);
2330 PetscOptionsGetInt(NULL, NULL,
"-startTime", &pps->
startTime, &startTimeSet);
2331 PetscOptionsGetInt(NULL, NULL,
"-endTime", &pps->
endTime, &endTimeSet);
2332 PetscOptionsGetInt(NULL, NULL,
"-timeStep", &pps->
timeStep, &timeStepSet);
2333 PetscOptionsGetBool(NULL, NULL,
"-output_particles", &pps->
outputParticles, NULL);
2340 if (startTimeSet && !endTimeSet) {
2344 LOG_ALLOW(
GLOBAL,
LOG_INFO,
"Post-processing configured to run from t=%d to t=%d with step %d. Particle output: %s.\n",
2358 PetscFunctionReturn(0);
2363#define __FUNCT__ "ParseScalingInformation"
2372 PetscErrorCode ierr;
2375 PetscFunctionBeginUser;
2378 if (!simCtx) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"SimCtx is NULL in ParseScalingInformation");
2387 ierr = PetscOptionsGetReal(NULL, NULL,
"-scaling_L_ref", &simCtx->
scaling.
L_ref, &flg); CHKERRQ(ierr);
2388 ierr = PetscOptionsGetReal(NULL, NULL,
"-scaling_U_ref", &simCtx->
scaling.
U_ref, &flg); CHKERRQ(ierr);
2389 ierr = PetscOptionsGetReal(NULL, NULL,
"-scaling_rho_ref", &simCtx->
scaling.
rho_ref, &flg); CHKERRQ(ierr);
2394 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE,
"Reference velocity U_ref must be positive. Got %g", (
double)simCtx->
scaling.
U_ref);
2399 LOG(
GLOBAL,
LOG_INFO,
"---------------- Physical Scales Initialized -----------------\n");
2400 LOG(
GLOBAL,
LOG_INFO,
" L_ref: %.4f, U_ref: %.4f, rho_ref: %.4f, P_ref: %.4f\n",
2402 LOG(
GLOBAL,
LOG_INFO,
"--------------------------------------------------------------\n");
2405 PetscFunctionReturn(0);
2420 PetscMPIInt rank, size;
2421 PetscErrorCode ierr;
2424 double *array = NULL;
2425 PetscInt fileExistsFlag = 0;
2428 "Start reading from file: %s\n",
2432 if (!filename || !data_out || !Nout) {
2434 "Null pointer argument provided.\n");
2439 MPI_Comm_rank(comm, &rank);
2440 MPI_Comm_size(comm, &size);
2444 fp = fopen(filename,
"r");
2453 ierr = MPI_Bcast(&fileExistsFlag, 1, MPI_INT, 0, comm); CHKERRQ(ierr);
2455 if (!fileExistsFlag) {
2459 "File '%s' not found.\n",
2467 fp = fopen(filename,
"r");
2470 "File '%s' could not be opened for reading.\n",
2478 while (fgets(line,
sizeof(line), fp)) {
2484 "File '%s' has %d lines.\n",
2488 array = (
double*)malloc(N *
sizeof(
double));
2492 "malloc failed for array.\n");
2501 while (fgets(line,
sizeof(line), fp)) {
2503 if (sscanf(line,
"%lf", &val) == 1) {
2511 "Successfully read %d values from '%s'.\n",
2516 ierr = MPI_Bcast(&N, 1, MPI_INT, 0, comm); CHKERRQ(ierr);
2520 array = (
double*)malloc(N *
sizeof(
double));
2523 "malloc failed on rank %d.\n",
2530 ierr = MPI_Bcast(array, N, MPI_DOUBLE, 0, comm); CHKERRQ(ierr);
2537 "Done. Provided array of length=%d to all ranks.\n",
2548 double **coordsArray,
2551 PetscFunctionBeginUser;
2553 PetscErrorCode ierr;
2557 ierr = VecCreate(PETSC_COMM_WORLD, &coordsVec);CHKERRQ(ierr);
2558 ierr = VecSetFromOptions(coordsVec);CHKERRQ(ierr);
2561 ierr =
ReadFieldData(user,
"position", coordsVec, timeIndex,
"dat");
2564 "Error reading position data (ti=%d).\n",
2566 PetscFunctionReturn(ierr);
2572 ierr = VecDestroy(&coordsVec);CHKERRQ(ierr);
2575 "Successfully gathered coordinates. Ncoords=%d.\n", *Ncoords);
2576 PetscFunctionReturn(0);
2585 const char *fieldName,
2587 double **scalarArray,
2590 PetscFunctionBeginUser;
2592 PetscErrorCode ierr;
2596 ierr = VecCreate(PETSC_COMM_WORLD, &fieldVec);CHKERRQ(ierr);
2597 ierr = VecSetFromOptions(fieldVec);CHKERRQ(ierr);
2599 ierr =
ReadFieldData(user, fieldName, fieldVec, timeIndex,
"dat");
2602 "Error reading field '%s' (ti=%d).\n",
2603 fieldName, timeIndex);
2604 PetscFunctionReturn(ierr);
2610 ierr = VecDestroy(&fieldVec);CHKERRQ(ierr);
2613 "Successfully gathered field '%s'. Nscalars=%d.\n",
2614 fieldName, *Nscalars);
2615 PetscFunctionReturn(0);
PetscErrorCode ReadStatisticalFields(UserCtx *user, PetscInt ti)
Implementation of ReadStatisticalFields().
PetscErrorCode ParsePostProcessingSettings(SimCtx *simCtx)
Internal helper implementation: ParsePostProcessingSettings().
PetscErrorCode WriteAllSwarmFields(UserCtx *user)
Internal helper implementation: WriteAllSwarmFields().
PetscErrorCode SwarmFieldToArrayOnRank0(DM swarm, const char *field_name, PetscInt *n_total_particles, PetscInt *n_components, void **gathered_array)
Internal helper implementation: SwarmFieldToArrayOnRank0().
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)
Internal helper implementation: ReadGridFile().
PetscErrorCode StringToBCHandlerType(const char *str, BCHandlerType *handler_out)
Internal helper implementation: StringToBCHandlerType().
PetscErrorCode ReadRANSFields(UserCtx *user, PetscInt ti)
Internal helper implementation: ReadRANSFields().
PetscErrorCode GetBCParamReal(BC_Param *params, const char *key, PetscReal *value_out, PetscBool *found)
Internal helper implementation: GetBCParamReal().
PetscErrorCode ReadSwarmIntField(UserCtx *user, const char *field_name, PetscInt ti, const char *ext)
Internal helper implementation: ReadSwarmIntField().
PetscErrorCode WriteSwarmField(UserCtx *user, const char *field_name, PetscInt ti, const char *ext)
Implementation of WriteSwarmField().
static PetscInt * g_IMs_from_file
Caches the IM dimensions for all blocks read from the grid file.
PetscErrorCode WriteStatisticalFields(UserCtx *user)
Implementation of WriteStatisticalFields().
PetscErrorCode ReadSimulationFields(UserCtx *user, PetscInt ti)
Internal helper implementation: 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 WriteFieldData(UserCtx *user, const char *field_name, Vec field_vec, PetscInt ti, const char *ext)
Internal helper implementation: WriteFieldData().
PetscErrorCode ReadLESFields(UserCtx *user, PetscInt ti)
Internal helper implementation: ReadLESFields().
PetscErrorCode ReadFieldData(UserCtx *user, const char *field_name, Vec field_vec, PetscInt ti, const char *ext)
Internal helper implementation: ReadFieldData().
PetscErrorCode ParseAllBoundaryConditions(UserCtx *user, const char *bcs_input_filename)
Internal helper implementation: ParseAllBoundaryConditions().
PetscErrorCode ValidateBCHandlerForBCType(BCType type, BCHandlerType handler)
Internal helper implementation: ValidateBCHandlerForBCType().
void TrimWhitespace(char *str)
Implementation of TrimWhitespace().
PetscErrorCode WriteSimulationFields(UserCtx *user)
Implementation of WriteSimulationFields().
PetscErrorCode ReadAllSwarmFields(UserCtx *user, PetscInt ti)
Internal helper implementation: ReadAllSwarmFields().
static PetscBool g_file_has_been_read
A flag to ensure the grid file is read only once.
PetscErrorCode ReadGridGenerationInputs(UserCtx *user)
Internal helper implementation: ReadGridGenerationInputs().
PetscErrorCode ReadSwarmField(UserCtx *user, const char *field_name, PetscInt ti, const char *ext)
Internal helper implementation: ReadSwarmField().
PetscErrorCode WriteRANSFields(UserCtx *user)
Implementation of WriteRANSFields().
PetscErrorCode PopulateFinestUserGridResolutionFromOptions(UserCtx *finest_users, PetscInt nblk)
Internal helper implementation: PopulateFinestUserGridResolutionFromOptions().
PetscErrorCode DeterminePeriodicity(SimCtx *simCtx)
Internal helper implementation: DeterminePeriodicity().
PetscErrorCode ReadFieldDataToRank0(PetscInt timeIndex, const char *fieldName, UserCtx *user, double **scalarArray, PetscInt *Nscalars)
Internal helper implementation: ReadFieldDataToRank0().
PetscErrorCode VecToArrayOnRank0(Vec inVec, PetscInt *N, double **arrayOut)
Internal helper implementation: VecToArrayOnRank0().
PetscErrorCode WriteSwarmIntField(UserCtx *user, const char *field_name, PetscInt ti, const char *ext)
Internal helper implementation: WriteSwarmIntField().
PetscErrorCode WriteLESFields(UserCtx *user)
Internal helper implementation: WriteLESFields().
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.
PetscErrorCode StringToBCFace(const char *str, BCFace *face_out)
Internal helper implementation: StringToBCFace().
PetscErrorCode ReadPositionsFromFile(PetscInt timeIndex, UserCtx *user, double **coordsArray, PetscInt *Ncoords)
Internal helper implementation: ReadPositionsFromFile().
static PetscErrorCode ReadOptionalField(UserCtx *user, const char *field_name, const char *field_label, Vec field_vec, PetscInt ti, const char *ext)
Internal helper implementation: ReadOptionalField().
PetscErrorCode VerifyPathExistence(const char *path, PetscBool is_dir, PetscBool is_optional, const char *description, PetscBool *exists)
Internal helper implementation: VerifyPathExistence().
PetscErrorCode GetBCParamBool(BC_Param *params, const char *key, PetscBool *value_out, PetscBool *found)
Internal helper implementation: GetBCParamBool().
void FreeBC_ParamList(BC_Param *head)
Implementation of FreeBC_ParamList().
PetscErrorCode StringToBCType(const char *str, BCType *type_out)
Internal helper implementation: StringToBCType().
PetscErrorCode DisplayBanner(SimCtx *simCtx)
Internal helper implementation: DisplayBanner().
static PetscErrorCode CheckDataFile(UserCtx *user, PetscInt ti, const char *fieldName, const char *ext, PetscBool *fileExists)
Internal helper implementation: CheckDataFile().
static PetscErrorCode ReadOptionalSwarmField(UserCtx *user, const char *field_name, const char *field_label, PetscInt ti, const char *ext)
Internal helper implementation: ReadOptionalSwarmField().
Public interface for data input/output routines.
const char * BCHandlerTypeToString(BCHandlerType handler_type)
Converts a BCHandlerType enum to its string representation.
const char * FieldInitializationToString(PetscInt FieldInitialization)
Helper function to convert FieldInitialization to a 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.
#define GLOBAL
Scope for global logging across all processes.
const char * BCFaceToString(BCFace face)
Helper function to convert BCFace enum to a string representation.
#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_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 * BCTypeToString(BCType type)
Helper function to convert BCType enum to a string representation.
@ 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.
#define PROFILE_FUNCTION_BEGIN
Marks the beginning of a profiled code block (typically a function).
const char * LESModelToString(LESModelType LESFlag)
Helper function to convert LES Flag to a string representation.
const char * MomentumSolverTypeToString(MomentumSolverType SolverFlag)
Helper function to convert Momentum Solver flag to a string representation.
const char * ParticleInitializationToString(ParticleInitializationType ParticleInitialization)
Helper function to convert ParticleInitialization to a string representation.
char statistics_output_prefix[256]
basename for CSV output, e.g.
BCType
Defines the general mathematical/physical Category of a boundary.
PetscBool inletFaceDefined
char particle_output_prefix[256]
BoundaryFaceConfig boundary_faces[6]
BCFace identifiedInletBCFace
PetscBool walltimeGuardActive
char euler_subdir[PETSC_MAX_PATH_LEN]
SimCtx * simCtx
Back-pointer to the master simulation context.
@ PARTICLE_INIT_SURFACE_RANDOM
Random placement on the inlet face.
@ PARTICLE_INIT_SURFACE_EDGES
Deterministic placement at inlet face edges.
#define MAX_FIELD_LIST_LENGTH
PetscReal walltimeGuardMinSeconds
BCHandlerType
Defines the specific computational "strategy" for a boundary handler.
@ BC_HANDLER_PERIODIC_GEOMETRIC
@ BC_HANDLER_INLET_PARABOLIC
@ BC_HANDLER_INLET_CONSTANT_VELOCITY
@ BC_HANDLER_PERIODIC_DRIVEN_INITIAL_FLUX
@ BC_HANDLER_PERIODIC_DRIVEN_CONSTANT_FLUX
@ BC_HANDLER_INLET_PROFILE_FROM_FILE
@ BC_HANDLER_OUTLET_CONSERVATION
char output_fields_averaged[1024]
PetscInt FieldInitialization
#define MAX_PIPELINE_LENGTH
BCHandlerType handler_type
Cmpnts max_coords
Maximum x, y, z coordinates of the bounding box.
char output_dir[PETSC_MAX_PATH_LEN]
#define MAX_FILENAME_LENGTH
Cmpnts min_coords
Minimum x, y, z coordinates of the bounding box.
char * current_io_directory
char grid_file[PETSC_MAX_PATH_LEN]
char statistics_pipeline[1024]
e.g.
InterpolationMethod interpolationMethod
char output_fields_instantaneous[1024]
char particleRestartMode[16]
char particle_subdir[PETSC_MAX_PATH_LEN]
char source_dir[PETSC_MAX_PATH_LEN]
char particle_pipeline[1024]
char eulerianSource[PETSC_MAX_PATH_LEN]
PetscBool walltimeGuardEnabled
PetscInt walltimeGuardWarmupSteps
ParticleInitializationType ParticleInitialization
char process_pipeline[1024]
PetscInt particle_output_freq
char particle_fields[1024]
PetscBool outputParticles
char AnalyticalSolutionType[PETSC_MAX_PATH_LEN]
PetscInt particleConsoleOutputFreq
Cmpnts InitialConstantContra
@ EXEC_MODE_POSTPROCESSOR
char _io_context_buffer[PETSC_MAX_PATH_LEN]
PetscReal walltimeGuardEstimatorAlpha
PetscReal walltimeGuardMultiplier
MomentumSolverType mom_solver_type
char PostprocessingControlFile[PETSC_MAX_PATH_LEN]
char restart_dir[PETSC_MAX_PATH_LEN]
PetscInt LoggingFrequency
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.
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.