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);
356 else SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_UNKNOWN_TYPE,
"Unknown BC Handler string: %s", str);
388 *found = PETSC_FALSE;
394 if (strcasecmp(current->
key, key) == 0) {
395 *value_out = atof(current->
value);
399 current = current->
next;
409 *found = PETSC_FALSE;
410 *value_out = PETSC_FALSE;
415 if (strcasecmp(current->
key, key) == 0) {
420 if (current->
value &&
421 (strcasecmp(current->
value,
"true") == 0 ||
422 strcmp(current->
value,
"1") == 0 ||
423 strcasecmp(current->
value,
"yes") == 0))
425 *value_out = PETSC_TRUE;
427 *value_out = PETSC_FALSE;
431 current = current->
next;
442#define __FUNCT__ "ParseAllBoundaryConditions"
455 PetscFunctionBeginUser;
457 ierr = MPI_Comm_rank(PETSC_COMM_WORLD, &rank); CHKERRQ(ierr);
461 char line_buffer[1024];
464 for (
int i = 0; i < 6; i++) {
468 configs_rank0[i].
params = NULL;
469 configs_rank0[i].
handler = NULL;
473 file = fopen(bcs_input_filename,
"r");
474 if (!file) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN,
"Could not open BCs file '%s'.", bcs_input_filename);
476 while (fgets(line_buffer,
sizeof(line_buffer), file)) {
477 char *current_pos = line_buffer;
478 while (isspace((
unsigned char)*current_pos)) current_pos++;
479 if (*current_pos ==
'#' || *current_pos ==
'\0' || *current_pos ==
'\n' || *current_pos ==
'\r')
continue;
481 char *face_str = strtok(current_pos,
" \t\n\r");
482 char *type_str = strtok(NULL,
" \t\n\r");
483 char *handler_str = strtok(NULL,
" \t\n\r");
485 if (!face_str || !type_str || !handler_str) {
493 const char* handler_name_for_log;
500 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);
506 LOG_ALLOW(
GLOBAL,
LOG_DEBUG,
" Parsed Face '%s': Type=%s, Handler=%s \n", face_str, type_str, handler_name_for_log);
510 configs_rank0[face_enum].
params = NULL;
514 while ((token = strtok(NULL,
" \t\n\r")) != NULL) {
515 char* equals_ptr = strchr(token,
'=');
522 char* key_str = token;
523 char* value_str = equals_ptr + 1;
526 ierr = PetscMalloc1(1, &new_param); CHKERRQ(ierr);
527 ierr = PetscStrallocpy(key_str, &new_param->
key); CHKERRQ(ierr);
528 ierr = PetscStrallocpy(value_str, &new_param->
value); CHKERRQ(ierr);
529 new_param->
next = NULL;
531 *param_next_ptr = new_param;
532 param_next_ptr = &new_param->
next;
546 for (
int i = 0; i < 6; i++) {
555 PetscInt n_params = 0;
559 ierr = MPI_Bcast(&n_params, 1, MPI_INT, 0, PETSC_COMM_WORLD);CHKERRQ(ierr);
568 for (
int j = 0; j < n_params; j++) {
569 char key_buf[256] = {0}, val_buf[256] = {0};
573 for (
int k = 0; k < j; k++) p = p->
next;
574 strncpy(key_buf, p->
key, 255);
575 strncpy(val_buf, p->
value, 255);
578 ierr = MPI_Bcast(key_buf, 256, MPI_CHAR, 0, PETSC_COMM_WORLD); CHKERRQ(ierr);
579 ierr = MPI_Bcast(val_buf, 256, MPI_CHAR, 0, PETSC_COMM_WORLD); CHKERRQ(ierr);
584 ierr = PetscMalloc1(1, &new_param); CHKERRQ(ierr);
585 ierr = PetscStrallocpy(key_buf, &new_param->
key); CHKERRQ(ierr);
586 ierr = PetscStrallocpy(val_buf, &new_param->
value); CHKERRQ(ierr);
587 new_param->
next = NULL;
588 *param_next_ptr = new_param;
589 param_next_ptr = &new_param->
next;
592 param_next_ptr = &((*param_next_ptr)->next);
600 for (
int i=0; i<6; i++) {
618 PetscFunctionReturn(0);
629#define __FUNCT__ "DeterminePeriodicity"
638 PetscInt periodic_flags[3] = {0, 0, 0};
640 PetscFunctionBeginUser;
641 ierr = MPI_Comm_rank(PETSC_COMM_WORLD, &rank); CHKERRQ(ierr);
644 for (PetscInt bi = 0; bi < simCtx->
block_number; bi++) {
645 const char *bcs_filename = simCtx->
bcs_files[bi];
646 if (!bcs_filename) SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_NULL,
"BCS filename for block %d is not set in SimCtx.", bi);
648 PetscBool file_exists;
649 snprintf(desc_buf,
sizeof(desc_buf),
"BCS file for block %d", bi);
650 ierr =
VerifyPathExistence(bcs_filename, PETSC_FALSE, PETSC_FALSE, desc_buf, &file_exists); CHKERRQ(ierr);
655 PetscBool global_is_periodic[3] = {PETSC_FALSE, PETSC_FALSE, PETSC_FALSE};
656 PetscBool is_set = PETSC_FALSE;
658 for (PetscInt bi = 0; bi < simCtx->
block_number; bi++) {
659 const char *bcs_filename = simCtx->
bcs_files[bi];
660 FILE *file = fopen(bcs_filename,
"r");
662 PetscBool face_is_periodic[6] = {PETSC_FALSE};
663 char line_buffer[1024];
665 while (fgets(line_buffer,
sizeof(line_buffer), file)) {
666 char *current_pos = line_buffer;
667 while (isspace((
unsigned char)*current_pos)) current_pos++;
668 if (*current_pos ==
'#' || *current_pos ==
'\0' || *current_pos ==
'\n')
continue;
671 char *face_str = strtok(current_pos,
" \t\n\r");
672 char *type_str = strtok(NULL,
" \t\n\r");
675 if (!face_str || !type_str)
continue;
678 if (strcasecmp(type_str,
"PERIODIC") == 0) {
682 face_is_periodic[face_enum] = PETSC_TRUE;
690 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);
692 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);
694 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);
700 global_is_periodic[0] = local_is_periodic[0];
701 global_is_periodic[1] = local_is_periodic[1];
702 global_is_periodic[2] = local_is_periodic[2];
705 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]) {
706 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_INCOMP,
707 "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).",
708 (
int)global_is_periodic[0], (
int)global_is_periodic[1], (
int)global_is_periodic[2],
710 (
int)local_is_periodic[0], (
int)local_is_periodic[1], (
int)local_is_periodic[2]);
715 periodic_flags[0] = (global_is_periodic[0]) ? 1 : 0;
716 periodic_flags[1] = (global_is_periodic[1]) ? 1 : 0;
717 periodic_flags[2] = (global_is_periodic[2]) ? 1 : 0;
720 periodic_flags[0], periodic_flags[1], periodic_flags[2]);
724 ierr = MPI_Bcast(periodic_flags, 3, MPIU_INT, 0, PETSC_COMM_WORLD); CHKERRQ(ierr);
731 PetscFunctionReturn(0);
738PetscErrorCode
VerifyPathExistence(
const char *path, PetscBool is_dir, PetscBool is_optional,
const char *description, PetscBool *exists)
742 MPI_Comm comm = PETSC_COMM_WORLD;
744 PetscFunctionBeginUser;
745 ierr = MPI_Comm_rank(comm, &rank); CHKERRQ(ierr);
749 ierr = PetscTestDirectory(path,
'r', exists); CHKERRQ(ierr);
751 ierr = PetscTestFile(path,
'r', exists); CHKERRQ(ierr);
766 PetscMPIInt exists_int = (rank == 0) ? (PetscMPIInt)(*exists) : 0;
767 ierr = MPI_Bcast(&exists_int, 1, MPI_INT, 0, comm); CHKERRMPI(ierr);
768 *exists = (PetscBool)exists_int;
771 if (!(*exists) && !is_optional) {
772 SETERRQ(comm, PETSC_ERR_FILE_OPEN,
"Mandatory %s not found. Rank 0 expected it at '%s'. Check path and permissions.", description, path);
775 PetscFunctionReturn(0);
782static PetscErrorCode
CheckDataFile(
UserCtx *user, PetscInt ti,
const char *fieldName,
const char *ext, PetscBool *fileExists)
786 MPI_Comm comm = PETSC_COMM_WORLD;
787 PetscInt placeholder_int = 0;
790 PetscFunctionBeginUser;
793 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_NULL,
"I/O context directory is NULL. Ensure it is set before calling CheckDataFile().");
796 ierr = MPI_Comm_rank(comm, &rank); CHKERRQ(ierr);
799 char filename[PETSC_MAX_PATH_LEN];
802 ierr = PetscSNPrintf(filename,
sizeof(filename),
"%s/%s%05"PetscInt_FMT
"_%d.%s",simCtx->
current_io_directory,fieldName, ti, placeholder_int, ext);
803 ierr = PetscTestFile(filename,
'r', fileExists); CHKERRQ(ierr);
804 if (!(*fileExists)) {
811 PetscMPIInt fileExists_int = (rank == 0) ? (PetscMPIInt)(*fileExists) : 0;
812 ierr = MPI_Bcast(&fileExists_int, 1, MPI_INT, 0, comm); CHKERRMPI(ierr);
813 *fileExists = (PetscBool)fileExists_int;
815 PetscFunctionReturn(0);
822static PetscErrorCode
ReadOptionalField(
UserCtx *user,
const char *field_name,
const char *field_label, Vec field_vec, PetscInt ti,
const char *ext)
825 PetscBool fileExists;
827 PetscFunctionBeginUser;
830 ierr =
CheckDataFile(user,ti, field_name, ext, &fileExists); CHKERRQ(ierr);
840 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);
849 PetscFunctionReturn(0);
859 PetscBool fileExists;
861 PetscFunctionBeginUser;
864 ierr =
CheckDataFile(user,ti, field_name, ext, &fileExists); CHKERRQ(ierr);
869 if(strcasecmp(field_name,
"DMSwarm_CellID") == 0 || strcasecmp(field_name,
"DMSwarm_pid")== 0 || strcasecmp(field_name,
"DMSwarm_location_status")== 0 ) {
880 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);
889 PetscFunctionReturn(0);
893#define __FUNCT__ "ReadFieldData"
899 const char *field_name,
905 char filename[PETSC_MAX_PATH_LEN];
907 PetscMPIInt rank,size;
911 PetscFunctionBeginUser;
915 SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,
"I/O context directory was not set before calling ReadFieldData().");
919 ierr = PetscObjectGetComm((PetscObject)field_vec,&comm);CHKERRQ(ierr);
920 ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr);
921 ierr = MPI_Comm_size(comm,&size);CHKERRQ(ierr);
923 const char *source_path = NULL;
927 SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,
"source_path was not set for the current execution mode.");
933 ierr = PetscSNPrintf(filename,
sizeof(filename),
934 "%s/%s%05" PetscInt_FMT
"_0.%s",
935 source_path,field_name,ti,ext);CHKERRQ(ierr);
938 "Attempting to read <%s> on rank %d/%d\n",
939 filename,(
int)rank,(
int)size);
949 PetscInt expectedSize,loadedSize;
951 ierr = PetscTestFile(filename,
'r',&found);CHKERRQ(ierr);
952 if(!found) SETERRQ(comm,PETSC_ERR_FILE_OPEN,
953 "Restart/Source file not found: %s",filename);
955 ierr = PetscViewerBinaryOpen(PETSC_COMM_SELF,filename,FILE_MODE_READ,&viewer);CHKERRQ(ierr);
959 ierr = VecCreate(PETSC_COMM_SELF, &temp_vec); CHKERRQ(ierr);
960 ierr = VecLoad(temp_vec,viewer);CHKERRQ(ierr);
961 ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
964 ierr = VecGetSize(field_vec, &expectedSize);CHKERRQ(ierr);
965 ierr = VecGetSize(temp_vec, &loadedSize);CHKERRQ(ierr);
966 if (loadedSize != expectedSize) {
967 SETERRQ(comm,PETSC_ERR_FILE_UNEXPECTED,
968 "File %s holds %d entries – expected %d for field '%s'",
969 filename, loadedSize, expectedSize, field_name);
973 ierr = VecCopy(temp_vec, field_vec);CHKERRQ(ierr);
976 ierr = VecDestroy(&temp_vec);CHKERRQ(ierr);
992 "Loaded <%s> (serial path)\n",filename);
995 PetscFunctionReturn(0);
1001 PetscInt globalSize;
1002 ierr = VecGetSize(field_vec,&globalSize);CHKERRQ(ierr);
1005 const char *dmtype = NULL;
1010 const PetscScalar *seqArray = NULL;
1017 ierr = PetscTestFile(filename,
'r',&found);CHKERRQ(ierr);
1018 if(!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,
1019 "Restart file not found: %s",filename);
1022 ierr = VecCreate(PETSC_COMM_SELF,&seq_vec);CHKERRQ(ierr);
1023 ierr = VecSetType(seq_vec,VECSEQ);CHKERRQ(ierr);
1025 ierr = PetscViewerBinaryOpen(PETSC_COMM_SELF,filename,
1026 FILE_MODE_READ,&viewer);CHKERRQ(ierr);
1027 ierr = VecLoad(seq_vec,viewer);CHKERRQ(ierr);
1028 ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
1032 ierr = VecGetSize(seq_vec,&loaded);CHKERRQ(ierr);
1033 if(loaded != globalSize)
1034 SETERRQ(comm,PETSC_ERR_FILE_UNEXPECTED,
1035 "File %s holds %d entries – expected %d",
1036 filename,loaded,globalSize);
1039 ierr = VecGetArrayRead(seq_vec,&seqArray);CHKERRQ(ierr);
1042 "Rank 0 successfully loaded <%s>\n",filename);
1046 ierr = VecGetDM(field_vec, &dm); CHKERRQ(ierr);
1047 if (dm) { ierr = DMGetType(dm, &dmtype); CHKERRQ(ierr); }
1049 if (dmtype && !strcmp(dmtype, DMDA)) {
1055 ierr = DMDACreateNaturalVector(dm, &nat); CHKERRQ(ierr);
1061 ierr = VecScatterCreateToZero(nat, &scatter, &nat_seq); CHKERRQ(ierr);
1064 ierr = VecScatterBegin(scatter, (rank == 0 ? seq_vec : nat_seq), nat,
1065 INSERT_VALUES, SCATTER_REVERSE); CHKERRQ(ierr);
1066 ierr = VecScatterEnd(scatter, (rank == 0 ? seq_vec : nat_seq), nat,
1067 INSERT_VALUES, SCATTER_REVERSE); CHKERRQ(ierr);
1070 ierr = DMDANaturalToGlobalBegin(dm, nat, INSERT_VALUES, field_vec); CHKERRQ(ierr);
1071 ierr = DMDANaturalToGlobalEnd(dm, nat, INSERT_VALUES, field_vec); CHKERRQ(ierr);
1074 ierr = VecScatterDestroy(&scatter); CHKERRQ(ierr);
1075 ierr = VecDestroy(&nat_seq); CHKERRQ(ierr);
1076 ierr = VecDestroy(&nat); CHKERRQ(ierr);
1083 PetscScalar *buffer = NULL;
1085 buffer = (PetscScalar *)seqArray;
1087 ierr = PetscMalloc1(globalSize, &buffer); CHKERRQ(ierr);
1090 ierr = MPI_Bcast(buffer, (
int)globalSize, MPIU_SCALAR, 0, comm); CHKERRQ(ierr);
1093 PetscInt rstart, rend, loc;
1094 PetscScalar *locArray;
1096 ierr = VecGetOwnershipRange(field_vec, &rstart, &rend); CHKERRQ(ierr);
1097 loc = rend - rstart;
1099 ierr = VecGetArray(field_vec, &locArray); CHKERRQ(ierr);
1100 ierr = PetscMemcpy(locArray, buffer + rstart, loc *
sizeof(PetscScalar)); CHKERRQ(ierr);
1101 ierr = VecRestoreArray(field_vec, &locArray); CHKERRQ(ierr);
1104 ierr = PetscFree(buffer); CHKERRQ(ierr);
1110 ierr = VecRestoreArrayRead(seq_vec, &seqArray); CHKERRQ(ierr);
1111 ierr = VecDestroy(&seq_vec); CHKERRQ(ierr);
1115 "Loaded <%s> (parallel path)\n",filename);
1118 PetscFunctionReturn(0);
1128 PetscErrorCode ierr;
1131 const char *source_path = NULL;
1132 const char *eulerian_ext =
"dat";
1142 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE,
"Invalid execution mode for reading simulation fields.");
1152 ierr =
ReadFieldData(user,
"ufield", user->
Ucat, ti, eulerian_ext); CHKERRQ(ierr);
1158 ierr =
ReadFieldData(user,
"pfield", user->
P, ti, eulerian_ext); CHKERRQ(ierr);
1168 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"ParticleCount Vec is NULL but np>0");
1172 ierr =
ReadOptionalField(user,
"psifield",
"Scalar Psi Field", user->
Psi, ti, eulerian_ext); CHKERRQ(ierr);
1207 PetscErrorCode ierr;
1208 const char *eulerian_ext =
"dat";
1231 PetscErrorCode ierr;
1232 const char *eulerian_ext =
"dat";
1239 ierr =
ReadOptionalField(user,
"Nu_t",
"Turbulent Viscosity", user->
Nu_t, ti, eulerian_ext); CHKERRQ(ierr);
1240 ierr =
ReadOptionalField(user,
"cs",
"Smagorinsky Constant (Cs)", user->
CS, ti, eulerian_ext); CHKERRQ(ierr);
1242 DMGlobalToLocalBegin(user->
da, user->
CS, INSERT_VALUES, user->
lCs);
1243 DMGlobalToLocalEnd(user->
da, user->
CS, INSERT_VALUES, user->
lCs);
1245 DMGlobalToLocalBegin(user->
da, user->
Nu_t, INSERT_VALUES, user->
lNu_t);
1246 DMGlobalToLocalEnd(user->
da, user->
Nu_t, INSERT_VALUES, user->
lNu_t);
1259 PetscErrorCode ierr;
1260 const char *eulerian_ext =
"dat";
1268 ierr =
ReadOptionalField(user,
"Nu_t",
"Turbulent Viscosity", user->
Nu_t, ti, eulerian_ext); CHKERRQ(ierr);
1275 DMGlobalToLocalBegin(user->
da, user->
Nu_t, INSERT_VALUES, user->
lNu_t);
1276 DMGlobalToLocalEnd(user->
da, user->
Nu_t, INSERT_VALUES, user->
lNu_t);
1293 PetscErrorCode ierr;
1299 swarm = user->
swarm;
1304 ierr = DMSwarmCreateGlobalVectorFromField(swarm, field_name, &fieldVec);CHKERRQ(ierr);
1309 ierr =
ReadFieldData(user, field_name, fieldVec, ti, ext);CHKERRQ(ierr);
1312 ierr = DMSwarmDestroyGlobalVectorFromField(swarm, field_name, &fieldVec);CHKERRQ(ierr);
1314 PetscFunctionReturn(0);
1323 PetscErrorCode ierr;
1324 DM swarm = user->
swarm;
1326 PetscInt nlocal, nglobal, bs, i;
1327 const PetscScalar *scalar_array;
1328 void *field_array_void;
1331 PetscFunctionBeginUser;
1336 ierr = DMSwarmGetLocalSize(swarm, &nlocal); CHKERRQ(ierr);
1337 ierr = DMSwarmGetSize(swarm, &nglobal); CHKERRQ(ierr);
1339 ierr = DMSwarmGetField(swarm, field_name, &bs, NULL, NULL); CHKERRQ(ierr);
1340 ierr = DMSwarmRestoreField(swarm, field_name, &bs, NULL, NULL); CHKERRQ(ierr);
1343 ierr = VecCreate(PETSC_COMM_WORLD, &temp_vec); CHKERRQ(ierr);
1344 ierr = VecSetType(temp_vec, VECMPI); CHKERRQ(ierr);
1345 ierr = VecSetSizes(temp_vec, nlocal * bs, nglobal * bs); CHKERRQ(ierr);
1346 ierr = VecSetBlockSize(temp_vec, bs); CHKERRQ(ierr);
1347 ierr = VecSetUp(temp_vec); CHKERRQ(ierr);
1350 ierr =
ReadFieldData(user, field_name, temp_vec, ti, ext); CHKERRQ(ierr);
1353 ierr = VecGetArrayRead(temp_vec, &scalar_array); CHKERRQ(ierr);
1354 ierr = DMSwarmGetField(swarm, field_name, NULL, NULL, &field_array_void); CHKERRQ(ierr);
1357 if (strcmp(field_name,
"DMSwarm_pid") == 0) {
1358 PetscInt64 *int64_array = (PetscInt64 *)field_array_void;
1359 for (i = 0; i < nlocal * bs; i++) {
1360 int64_array[i] = (PetscInt64)scalar_array[i];
1363 PetscInt *int_array = (PetscInt *)field_array_void;
1364 for (i = 0; i < nlocal * bs; i++) {
1365 int_array[i] = (PetscInt)scalar_array[i];
1370 ierr = DMSwarmRestoreField(swarm, field_name, NULL, NULL, &field_array_void); CHKERRQ(ierr);
1371 ierr = VecRestoreArrayRead(temp_vec, &scalar_array); CHKERRQ(ierr);
1374 ierr = VecDestroy(&temp_vec); CHKERRQ(ierr);
1376 PetscFunctionReturn(0);
1385 PetscErrorCode ierr;
1388 const char *source_path = NULL;
1389 const char *particle_ext =
"dat";
1391 PetscFunctionBeginUser;
1392 ierr = DMSwarmGetSize(user->
swarm, &nGlobal); CHKERRQ(ierr);
1397 PetscFunctionReturn(0);
1409 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONGSTATE,
"Invalid execution mode for reading simulation fields.");
1422 SETERRQ(PETSC_COMM_WORLD, ierr,
"Failed to read MANDATORY 'position' field for step %d. Cannot continue.", ti);
1433 ierr =
ReadOptionalSwarmField(user,
"DMSwarm_location_status",
"Migration Status", ti, particle_ext); CHKERRQ(ierr);
1438 PetscFunctionReturn(0);
1443#define __FUNCT__ "WriteFieldData"
1449 const char *field_name,
1454 PetscErrorCode ierr;
1456 PetscMPIInt rank, size;
1458 const PetscInt placeholder_int = 0;
1459 char filename[PETSC_MAX_PATH_LEN];
1462 PetscFunctionBeginUser;
1466 SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,
"I/O context directory was not set before calling WriteFieldData().");
1472 ierr = PetscObjectGetComm((PetscObject)field_vec,&comm);CHKERRQ(ierr);
1473 ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr);
1474 ierr = MPI_Comm_size(comm,&size);CHKERRQ(ierr);
1476 ierr = PetscSNPrintf(filename,
sizeof(filename),
1477 "%s/%s%05" PetscInt_FMT
"_%d.%s",
1481 " Preparing to write <%s> on rank %d/%d\n",
1482 filename,rank,size);
1490 ierr = PetscViewerBinaryOpen(comm,filename,
1491 FILE_MODE_WRITE,&viewer);CHKERRQ(ierr);
1492 ierr = VecView(field_vec,viewer);CHKERRQ(ierr);
1493 ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
1496 " Wrote <%s> (serial path)\n",filename);
1497 PetscFunctionReturn(0);
1506 const char *dmtype = NULL;
1510 ierr = VecGetDM(field_vec, &dm); CHKERRQ(ierr);
1511 if (dm) { ierr = DMGetType(dm, &dmtype); CHKERRQ(ierr); }
1513 if (dmtype && !strcmp(dmtype, DMDA)) {
1515 ierr = DMDACreateNaturalVector(dm, &nat); CHKERRQ(ierr);
1516 ierr = DMDAGlobalToNaturalBegin(dm, field_vec, INSERT_VALUES, nat); CHKERRQ(ierr);
1517 ierr = DMDAGlobalToNaturalEnd(dm, field_vec, INSERT_VALUES, nat); CHKERRQ(ierr);
1520 ierr = VecScatterCreateToZero(nat, &scatter, &seq_vec); CHKERRQ(ierr);
1523 ierr = VecScatterCreateToZero(field_vec, &scatter, &seq_vec); CHKERRQ(ierr);
1527 ierr = VecScatterBegin(scatter, (nat ? nat : field_vec), seq_vec,
1528 INSERT_VALUES, SCATTER_FORWARD); CHKERRQ(ierr);
1529 ierr = VecScatterEnd(scatter, (nat ? nat : field_vec), seq_vec,
1530 INSERT_VALUES, SCATTER_FORWARD); CHKERRQ(ierr);
1537 PetscReal vmin,vmax;
1538 ierr = VecMin(seq_vec,NULL,&vmin);CHKERRQ(ierr);
1539 ierr = VecMax(seq_vec,NULL,&vmax);CHKERRQ(ierr);
1541 " <%s> range = [%.4e … %.4e]\n",
1542 field_name,(
double)vmin,(
double)vmax);
1544 ierr = PetscViewerBinaryOpen(PETSC_COMM_SELF,filename,
1545 FILE_MODE_WRITE,&viewer);CHKERRQ(ierr);
1546 ierr = VecView(seq_vec,viewer);CHKERRQ(ierr);
1547 ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
1550 " Wrote <%s> (parallel path)\n",filename);
1554 ierr = VecScatterDestroy(&scatter);CHKERRQ(ierr);
1555 ierr = VecDestroy(&seq_vec);CHKERRQ(ierr);
1556 if (nat) { ierr = VecDestroy(&nat); CHKERRQ(ierr); }
1559 PetscFunctionReturn(0);
1570 PetscErrorCode ierr;
1629 PetscErrorCode ierr;
1651 PetscErrorCode ierr;
1658 DMLocalToGlobalBegin(user->
da, user->
lCs, INSERT_VALUES, user->
CS);
1659 DMLocalToGlobalEnd(user->
da, user->
lCs, INSERT_VALUES, user->
CS);
1661 DMLocalToGlobalBegin(user->
da, user->
lNu_t, INSERT_VALUES, user->
Nu_t);
1662 DMLocalToGlobalEnd(user->
da, user->
lNu_t, INSERT_VALUES, user->
Nu_t);
1681 PetscErrorCode ierr;
1702 PetscErrorCode ierr;
1706 PetscFunctionBeginUser;
1712 swarm = user->
swarm;
1720 "Attempting to create global vector from field: %s\n",
1722 ierr = DMSwarmCreateGlobalVectorFromField(swarm, field_name, &fieldVec);CHKERRQ(ierr);
1729 "Calling WriteFieldData for field: %s\n",
1731 ierr =
WriteFieldData(user, field_name, fieldVec, ti, ext);CHKERRQ(ierr);
1739 "Destroying the global vector for field: %s\n",
1741 ierr = DMSwarmDestroyGlobalVectorFromField(swarm, field_name, &fieldVec);CHKERRQ(ierr);
1745 "Successfully wrote swarm data for field: %s\n",
1748 PetscFunctionReturn(0);
1757 PetscErrorCode ierr;
1758 DM swarm = user->
swarm;
1760 PetscInt nlocal, nglobal,bs,i;
1761 void *field_array_void;
1762 PetscScalar *scalar_array;
1764 PetscFunctionBeginUser;
1769 ierr = DMSwarmGetLocalSize(swarm, &nlocal); CHKERRQ(ierr);
1770 ierr = DMSwarmGetSize(swarm, &nglobal); CHKERRQ(ierr);
1771 ierr = DMSwarmGetField(swarm, field_name, &bs, NULL, &field_array_void); CHKERRQ(ierr);
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 = VecSetUp(temp_vec); CHKERRQ(ierr);
1780 DMSwarmVectorDefineField(swarm,
"position");
1782 ierr = VecGetArray(temp_vec, &scalar_array); CHKERRQ(ierr);
1784 if(strcasecmp(field_name,
"DMSwarm_pid") == 0){
1785 PetscInt64 *int64_array = (PetscInt64 *)field_array_void;
1787 for (i = 0; i < nlocal*bs; i++) {
1788 scalar_array[i] = (PetscScalar)int64_array[i];
1791 PetscInt *int_array = (PetscInt *)field_array_void;
1793 for (i = 0; i < nlocal*bs; i++) {
1794 scalar_array[i] = (PetscScalar)int_array[i];
1799 ierr = VecRestoreArray(temp_vec, &scalar_array); CHKERRQ(ierr);
1800 ierr = DMSwarmRestoreField(swarm, field_name, &bs, NULL, &field_array_void); CHKERRQ(ierr);
1803 ierr =
WriteFieldData(user, field_name, temp_vec, ti, ext); CHKERRQ(ierr);
1806 ierr = VecDestroy(&temp_vec); CHKERRQ(ierr);
1808 PetscFunctionReturn(0);
1817 PetscErrorCode ierr;
1820 PetscFunctionBeginUser;
1823 if (!user->
swarm || simCtx->
np <= 0) {
1824 PetscFunctionReturn(0);
1861 PetscFunctionReturn(0);
1870 PetscErrorCode ierr;
1873 PetscInt globalSize;
1875 const char *dmtype = NULL;
1878 Vec nat = NULL, seqNat = NULL;
1879 VecScatter scatNat = NULL;
1880 const PetscScalar *nar = NULL;
1881 PetscScalar *buf = NULL;
1885 VecScatter scat = NULL;
1886 const PetscScalar *sar = NULL;
1888 PetscFunctionBeginUser;
1890 ierr = PetscObjectGetComm((PetscObject)inVec, &comm); CHKERRQ(ierr);
1891 ierr = MPI_Comm_rank(comm, &rank); CHKERRQ(ierr);
1892 ierr = VecGetSize(inVec, &globalSize); CHKERRQ(ierr);
1896 ierr = VecGetDM(inVec, &dm); CHKERRQ(ierr);
1897 if (dm) { ierr = DMGetType(dm, &dmtype); CHKERRQ(ierr); }
1899 if (dmtype && !strcmp(dmtype, DMDA)) {
1901 ierr = DMDACreateNaturalVector(dm, &nat); CHKERRQ(ierr);
1902 ierr = DMDAGlobalToNaturalBegin(dm, inVec, INSERT_VALUES, nat); CHKERRQ(ierr);
1903 ierr = DMDAGlobalToNaturalEnd (dm, inVec, INSERT_VALUES, nat); CHKERRQ(ierr);
1905 ierr = VecScatterCreateToZero(nat, &scatNat, &seqNat); CHKERRQ(ierr);
1906 ierr = VecScatterBegin(scatNat, nat, seqNat, INSERT_VALUES, SCATTER_FORWARD); CHKERRQ(ierr);
1907 ierr = VecScatterEnd (scatNat, nat, seqNat, INSERT_VALUES, SCATTER_FORWARD); CHKERRQ(ierr);
1911 ierr = VecGetLocalSize(seqNat, &nseq); CHKERRQ(ierr);
1912 ierr = VecGetArrayRead(seqNat, &nar); CHKERRQ(ierr);
1914 ierr = PetscMalloc1(nseq, &buf); CHKERRQ(ierr);
1915 ierr = PetscMemcpy(buf, nar, (
size_t)nseq *
sizeof(PetscScalar)); CHKERRQ(ierr);
1917 ierr = VecRestoreArrayRead(seqNat, &nar); CHKERRQ(ierr);
1918 *arrayOut = (
double*)buf;
1921 ierr = VecScatterDestroy(&scatNat); CHKERRQ(ierr);
1922 ierr = VecDestroy(&seqNat); CHKERRQ(ierr);
1923 ierr = VecDestroy(&nat); CHKERRQ(ierr);
1926 ierr = VecScatterCreateToZero(inVec, &scat, &seq); CHKERRQ(ierr);
1927 ierr = VecScatterBegin(scat, inVec, seq, INSERT_VALUES, SCATTER_FORWARD); CHKERRQ(ierr);
1928 ierr = VecScatterEnd (scat, inVec, seq, INSERT_VALUES, SCATTER_FORWARD); CHKERRQ(ierr);
1932 ierr = VecGetLocalSize(seq, &nseq); CHKERRQ(ierr);
1933 ierr = VecGetArrayRead(seq, &sar); CHKERRQ(ierr);
1935 ierr = PetscMalloc1(nseq, &buf); CHKERRQ(ierr);
1936 ierr = PetscMemcpy(buf, sar, (
size_t)nseq *
sizeof(PetscScalar)); CHKERRQ(ierr);
1938 ierr = VecRestoreArrayRead(seq, &sar); CHKERRQ(ierr);
1939 *arrayOut = (
double*)buf;
1942 ierr = VecScatterDestroy(&scat); CHKERRQ(ierr);
1943 ierr = VecDestroy(&seq); CHKERRQ(ierr);
1946 PetscFunctionReturn(0);
1953PetscErrorCode
SwarmFieldToArrayOnRank0(DM swarm,
const char *field_name, PetscInt *n_total_particles, PetscInt *n_components,
void **gathered_array)
1955 PetscErrorCode ierr;
1956 PetscMPIInt rank, size;
1957 PetscInt nlocal, nglobal, bs;
1958 void *local_array_void;
1959 size_t element_size = 0;
1961 PetscFunctionBeginUser;
1963 ierr = MPI_Comm_rank(PETSC_COMM_WORLD, &rank); CHKERRQ(ierr);
1964 ierr = MPI_Comm_size(PETSC_COMM_WORLD, &size); CHKERRQ(ierr);
1967 ierr = DMSwarmGetLocalSize(swarm, &nlocal); CHKERRQ(ierr);
1968 ierr = DMSwarmGetSize(swarm, &nglobal); CHKERRQ(ierr);
1969 ierr = DMSwarmGetField(swarm, field_name, &bs, NULL, &local_array_void); CHKERRQ(ierr);
1972 if (strcasecmp(field_name,
"DMSwarm_pid") == 0) {
1973 element_size =
sizeof(PetscInt64);
1974 }
else if (strcasecmp(field_name,
"DMSwarm_CellID") == 0 || strcasecmp(field_name,
"DMSwarm_location_status") == 0) {
1975 element_size =
sizeof(PetscInt);
1977 element_size =
sizeof(PetscScalar);
1981 *n_total_particles = nglobal;
1983 *gathered_array = NULL;
1988 ierr = PetscMalloc(nglobal * bs * element_size, gathered_array); CHKERRQ(ierr);
1989 ierr = PetscMemcpy(*gathered_array, local_array_void, nglobal * bs * element_size); CHKERRQ(ierr);
1992 PetscInt *recvcounts = NULL, *displs = NULL;
1994 ierr = PetscMalloc1(size, &recvcounts); CHKERRQ(ierr);
1995 ierr = PetscMalloc1(size, &displs); CHKERRQ(ierr);
1997 PetscInt sendcount = nlocal * bs;
2000 ierr = MPI_Gather(&sendcount, 1, MPIU_INT, recvcounts, 1, MPIU_INT, 0, PETSC_COMM_WORLD); CHKERRQ(ierr);
2005 for (PetscMPIInt i = 0; i < size; i++) recvcounts[i] *= element_size;
2006 for (PetscMPIInt i = 1; i < size; i++) displs[i] = displs[i-1] + recvcounts[i-1];
2008 ierr = PetscMalloc(nglobal * bs * element_size, gathered_array); CHKERRQ(ierr);
2012 ierr = MPI_Gatherv(local_array_void, nlocal * bs * element_size, MPI_BYTE,
2013 *gathered_array, recvcounts, displs, MPI_BYTE,
2014 0, PETSC_COMM_WORLD); CHKERRQ(ierr);
2017 ierr = PetscFree(recvcounts); CHKERRQ(ierr);
2018 ierr = PetscFree(displs); CHKERRQ(ierr);
2022 ierr = DMSwarmRestoreField(swarm, field_name, &bs, NULL, &local_array_void); CHKERRQ(ierr);
2024 PetscFunctionReturn(0);
2033 PetscErrorCode ierr;
2035 Cmpnts global_min_coords, global_max_coords;
2036 PetscReal StartTime;
2037 PetscInt StartStep,StepsToRun,total_num_particles;
2038 PetscMPIInt num_mpi_procs;
2042 num_mpi_procs = simCtx->
size;
2046 total_num_particles = simCtx->
np;
2050 PetscFunctionBeginUser;
2052 if (!user) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"DisplayBanner - UserCtx pointer is NULL.");
2055 ierr = MPI_Comm_rank(PETSC_COMM_WORLD, &rank); CHKERRQ(ierr);
2060 if (bboxlist_on_rank0 && num_mpi_procs > 0) {
2061 global_min_coords = bboxlist_on_rank0[0].
min_coords;
2062 global_max_coords = bboxlist_on_rank0[0].
max_coords;
2063 for (PetscMPIInt p = 1; p < num_mpi_procs; ++p) {
2064 global_min_coords.
x = PetscMin(global_min_coords.
x, bboxlist_on_rank0[p].
min_coords.
x);
2065 global_min_coords.
y = PetscMin(global_min_coords.
y, bboxlist_on_rank0[p].
min_coords.
y);
2066 global_min_coords.
z = PetscMin(global_min_coords.
z, bboxlist_on_rank0[p].
min_coords.
z);
2067 global_max_coords.
x = PetscMax(global_max_coords.
x, bboxlist_on_rank0[p].
max_coords.
x);
2068 global_max_coords.
y = PetscMax(global_max_coords.
y, bboxlist_on_rank0[p].
max_coords.
y);
2069 global_max_coords.
z = PetscMax(global_max_coords.
z, bboxlist_on_rank0[p].
max_coords.
z);
2076 LOG_ALLOW(
LOCAL,
LOG_WARNING,
"(Rank 0) - bboxlist not provided or num_mpi_procs <=0; using user->bbox for domain bounds.\n");
2081 ierr = PetscPrintf(PETSC_COMM_SELF,
"\n"); CHKERRQ(ierr);
2082 ierr = PetscPrintf(PETSC_COMM_SELF,
"=============================================================\n"); CHKERRQ(ierr);
2083 ierr = PetscPrintf(PETSC_COMM_SELF,
" CASE SUMMARY \n"); CHKERRQ(ierr);
2084 ierr = PetscPrintf(PETSC_COMM_SELF,
"=============================================================\n"); CHKERRQ(ierr);
2085 ierr = PetscPrintf(PETSC_COMM_SELF,
" Grid Points : %d X %d X %d\n", user->
IM, user->
JM, user->
KM); CHKERRQ(ierr);
2086 ierr = PetscPrintf(PETSC_COMM_SELF,
" Cells : %d X %d X %d\n", user->
IM - 1, user->
JM - 1, user->
KM - 1); CHKERRQ(ierr);
2087 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);
2088 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);
2089 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);
2091 ierr = PetscPrintf(PETSC_COMM_SELF,
"-------------------- Boundary Conditions --------------------\n"); CHKERRQ(ierr);
2092 const int face_name_width = 17;
2093 for (PetscInt i_face = 0; i_face < 6; ++i_face) {
2101 Cmpnts inlet_velocity = {0.0,0.0,0.0};
2106 ierr = PetscPrintf(PETSC_COMM_SELF,
" Face %-*s : %s - %s - [%.4f,%.4f,%.4f]\n",
2107 face_name_width, face_str, bc_type_str, bc_handler_type_str,inlet_velocity.
x,inlet_velocity.
y,inlet_velocity.
z); CHKERRQ(ierr);
2109 PetscReal v_max = 0.0;
2112 ierr = PetscPrintf(PETSC_COMM_SELF,
" Face %-*s : %s - %s - v_max=%.4f\n",
2113 face_name_width, face_str, bc_type_str, bc_handler_type_str, v_max); CHKERRQ(ierr);
2117 PetscBool trimflag,foundflux,foundtrimflag;
2120 ierr = PetscPrintf(PETSC_COMM_SELF,
" Face %-*s : %s - %s - [%.4f] - %s\n",
2121 face_name_width, face_str, bc_type_str, bc_handler_type_str,flux,trimflag?
"Trim Ucont":
"No Trim"); CHKERRQ(ierr);
2123 ierr = PetscPrintf(PETSC_COMM_SELF,
" Face %-*s : %s - %s\n",
2124 face_name_width, face_str, bc_type_str,bc_handler_type_str); CHKERRQ(ierr);
2128 ierr = PetscPrintf(PETSC_COMM_SELF,
"-------------------------------------------------------------\n"); CHKERRQ(ierr);
2129 ierr = PetscPrintf(PETSC_COMM_SELF,
" Run Mode : %s\n", simCtx->
OnlySetup ?
"SETUP ONLY" :
"Full Simulation"); CHKERRQ(ierr);
2130 ierr = PetscPrintf(PETSC_COMM_SELF,
" Start Time : %.4f\n", (
double)StartTime); CHKERRQ(ierr);
2131 ierr = PetscPrintf(PETSC_COMM_SELF,
" Timestep Size : %.4f\n", (
double)simCtx->
dt); CHKERRQ(ierr);
2132 ierr = PetscPrintf(PETSC_COMM_SELF,
" Starting Step : %d\n", StartStep); CHKERRQ(ierr);
2133 ierr = PetscPrintf(PETSC_COMM_SELF,
" Total Steps to Run : %d\n", StepsToRun); CHKERRQ(ierr);
2134 ierr = PetscPrintf(PETSC_COMM_SELF,
" Ending Step : %d\n", StartStep + StepsToRun); CHKERRQ(ierr);
2135 if (simCtx->
tiout > 0) {
2136 ierr = PetscPrintf(PETSC_COMM_SELF,
" Field/Restart Cadence : every %d step(s)\n", simCtx->
tiout); CHKERRQ(ierr);
2138 ierr = PetscPrintf(PETSC_COMM_SELF,
" Field/Restart Cadence : DISABLED\n"); CHKERRQ(ierr);
2140 ierr = PetscPrintf(PETSC_COMM_SELF,
" Immersed Boundary : %s\n", simCtx->
immersed ?
"ENABLED" :
"DISABLED"); CHKERRQ(ierr);
2144 " Runtime Walltime Guard : %s (warmup=%d, multiplier=%.2f, min=%.1f s, alpha=%.2f)\n",
2152 ierr = PetscPrintf(PETSC_COMM_SELF,
" Runtime Walltime Guard : DISABLED\n"); CHKERRQ(ierr);
2154 ierr = PetscPrintf(PETSC_COMM_SELF,
" Number of MPI Processes : %d\n", num_mpi_procs); CHKERRQ(ierr);
2155 ierr = PetscPrintf(PETSC_COMM_WORLD,
" Number of Particles : %d\n", total_num_particles); CHKERRQ(ierr);
2156 if (simCtx->
np > 0) {
2160 ierr = PetscPrintf(PETSC_COMM_SELF,
" Particle Console Cadence : every %d step(s)\n", simCtx->
particleConsoleOutputFreq); CHKERRQ(ierr);
2162 ierr = PetscPrintf(PETSC_COMM_SELF,
" Particle Console Cadence : DISABLED\n"); CHKERRQ(ierr);
2164 ierr = PetscPrintf(PETSC_COMM_SELF,
" Particle Log Row Sampling : every %d particle(s)\n", simCtx->
LoggingFrequency); CHKERRQ(ierr);
2166 ierr = PetscPrintf(PETSC_COMM_SELF,
" Particle Restart Mode : %s\n", simCtx->
particleRestartMode); CHKERRQ(ierr);
2168 ierr = PetscPrintf(PETSC_COMM_SELF,
" Particle Initialization Mode: %s\n", particle_init_str); CHKERRQ(ierr);
2169 ierr = PetscPrintf(PETSC_COMM_SELF,
" Interpolation Method : %s\n",
2176 ierr = PetscPrintf(PETSC_COMM_SELF,
" Particles Initialized At : --- (No INLET face identified)\n"); CHKERRQ(ierr);
2182 ierr = PetscPrintf(PETSC_COMM_WORLD,
" Reynolds Number : %le\n", simCtx->
ren); CHKERRQ(ierr);
2187 ierr = PetscPrintf(PETSC_COMM_WORLD,
" Initial Pseudo-CFL : %le\n", simCtx->
pseudo_cfl); CHKERRQ(ierr);
2188 ierr = PetscPrintf(PETSC_COMM_WORLD,
" Large Eddy Simulation Model : %s\n",
LESModelToString(simCtx->
les)); CHKERRQ(ierr);
2190 ierr = PetscPrintf(PETSC_COMM_SELF,
" Field Initialization Mode : %s\n", field_init_str); CHKERRQ(ierr);
2195 ierr = PetscPrintf(PETSC_COMM_WORLD,
" Analytical Solution Type : %s\n", simCtx->
AnalyticalSolutionType); CHKERRQ(ierr);
2197 ierr = PetscPrintf(PETSC_COMM_SELF,
"=============================================================\n"); CHKERRQ(ierr);
2198 ierr = PetscPrintf(PETSC_COMM_SELF,
"\n"); CHKERRQ(ierr);
2200 PetscFunctionReturn(0);
2204#define __FUNCT__ "ParsePostProcessingSettings"
2213 PetscBool startTimeSet, endTimeSet, timeStepSet;
2215 PetscFunctionBeginUser;
2218 if (!simCtx || !simCtx->
pps) {
2219 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_NULL,
"SimCtx or its pps member is NULL in ParsePostProcessingSettings.");
2248 file = fopen(configFile,
"r");
2251 while (fgets(line,
sizeof(line), file)) {
2252 char *key, *value, *comment;
2253 comment = strchr(line,
'#');
if (comment) *comment =
'\0';
2255 key = strtok(line,
"="); value = strtok(NULL,
"=");
2258 if (strcmp(key,
"startTime") == 0) pps->
startTime = atoi(value);
2259 else if (strcmp(key,
"endTime") == 0) pps->
endTime = atoi(value);
2260 else if (strcmp(key,
"timeStep") == 0) pps->
timeStep = atoi(value);
2261 else if (strcmp(key,
"output_particles") == 0) {
2262 if (strcasecmp(value,
"true") == 0) pps->
outputParticles = PETSC_TRUE;
2264 else if (strcasecmp(key,
"process_pipeline") == 0) {
2267 }
else if (strcasecmp(key,
"output_fields_instantaneous") == 0) {
2270 }
else if (strcasecmp(key,
"output_fields_averaged") == 0) {
2273 }
else if (strcasecmp(key,
"output_prefix") == 0) {
2276 }
else if (strcasecmp(key,
"particle_output_prefix") == 0) {
2279 }
else if (strcasecmp(key,
"particle_fields_instantaneous") == 0) {
2282 }
else if (strcasecmp(key,
"particle_pipeline") == 0) {
2285 }
else if (strcasecmp(key,
"particle_output_freq") == 0) {
2287 }
else if (strcasecmp(key,
"statistics_pipeline") == 0) {
2290 }
else if (strcasecmp(key,
"statistics_output_prefix") == 0) {
2293 }
else if (strcasecmp(key,
"particleExt") == 0) {
2296 }
else if (strcasecmp(key,
"eulerianExt") == 0) {
2299 }
else if (strcmp(key,
"reference_ip") == 0) {pps->
reference[0] = atoi(value);
2300 }
else if (strcmp(key,
"reference_jp") == 0) {pps->
reference[1] = atoi(value);
2301 }
else if (strcmp(key,
"reference_kp") == 0) {pps->
reference[2] = atoi(value);
2302 }
else if (strcasecmp(key,
"source_directory") == 0) {
2313 LOG_ALLOW(
GLOBAL,
LOG_WARNING,
"Could not open post-processing config file '%s'. Using defaults and command-line overrides.\n", configFile);
2317 PetscOptionsGetInt(NULL, NULL,
"-startTime", &pps->
startTime, &startTimeSet);
2318 PetscOptionsGetInt(NULL, NULL,
"-endTime", &pps->
endTime, &endTimeSet);
2319 PetscOptionsGetInt(NULL, NULL,
"-timeStep", &pps->
timeStep, &timeStepSet);
2320 PetscOptionsGetBool(NULL, NULL,
"-output_particles", &pps->
outputParticles, NULL);
2327 if (startTimeSet && !endTimeSet) {
2331 LOG_ALLOW(
GLOBAL,
LOG_INFO,
"Post-processing configured to run from t=%d to t=%d with step %d. Particle output: %s.\n",
2345 PetscFunctionReturn(0);
2350#define __FUNCT__ "ParseScalingInformation"
2359 PetscErrorCode ierr;
2362 PetscFunctionBeginUser;
2365 if (!simCtx) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"SimCtx is NULL in ParseScalingInformation");
2374 ierr = PetscOptionsGetReal(NULL, NULL,
"-scaling_L_ref", &simCtx->
scaling.
L_ref, &flg); CHKERRQ(ierr);
2375 ierr = PetscOptionsGetReal(NULL, NULL,
"-scaling_U_ref", &simCtx->
scaling.
U_ref, &flg); CHKERRQ(ierr);
2376 ierr = PetscOptionsGetReal(NULL, NULL,
"-scaling_rho_ref", &simCtx->
scaling.
rho_ref, &flg); CHKERRQ(ierr);
2381 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE,
"Reference velocity U_ref must be positive. Got %g", (
double)simCtx->
scaling.
U_ref);
2386 LOG(
GLOBAL,
LOG_INFO,
"---------------- Physical Scales Initialized -----------------\n");
2387 LOG(
GLOBAL,
LOG_INFO,
" L_ref: %.4f, U_ref: %.4f, rho_ref: %.4f, P_ref: %.4f\n",
2389 LOG(
GLOBAL,
LOG_INFO,
"--------------------------------------------------------------\n");
2392 PetscFunctionReturn(0);
2407 PetscMPIInt rank, size;
2408 PetscErrorCode ierr;
2411 double *array = NULL;
2412 PetscInt fileExistsFlag = 0;
2415 "Start reading from file: %s\n",
2419 if (!filename || !data_out || !Nout) {
2421 "Null pointer argument provided.\n");
2426 MPI_Comm_rank(comm, &rank);
2427 MPI_Comm_size(comm, &size);
2431 fp = fopen(filename,
"r");
2440 ierr = MPI_Bcast(&fileExistsFlag, 1, MPI_INT, 0, comm); CHKERRQ(ierr);
2442 if (!fileExistsFlag) {
2446 "File '%s' not found.\n",
2454 fp = fopen(filename,
"r");
2457 "File '%s' could not be opened for reading.\n",
2465 while (fgets(line,
sizeof(line), fp)) {
2471 "File '%s' has %d lines.\n",
2475 array = (
double*)malloc(N *
sizeof(
double));
2479 "malloc failed for array.\n");
2488 while (fgets(line,
sizeof(line), fp)) {
2490 if (sscanf(line,
"%lf", &val) == 1) {
2498 "Successfully read %d values from '%s'.\n",
2503 ierr = MPI_Bcast(&N, 1, MPI_INT, 0, comm); CHKERRQ(ierr);
2507 array = (
double*)malloc(N *
sizeof(
double));
2510 "malloc failed on rank %d.\n",
2517 ierr = MPI_Bcast(array, N, MPI_DOUBLE, 0, comm); CHKERRQ(ierr);
2524 "Done. Provided array of length=%d to all ranks.\n",
2535 double **coordsArray,
2538 PetscFunctionBeginUser;
2540 PetscErrorCode ierr;
2544 ierr = VecCreate(PETSC_COMM_WORLD, &coordsVec);CHKERRQ(ierr);
2545 ierr = VecSetFromOptions(coordsVec);CHKERRQ(ierr);
2548 ierr =
ReadFieldData(user,
"position", coordsVec, timeIndex,
"dat");
2551 "Error reading position data (ti=%d).\n",
2553 PetscFunctionReturn(ierr);
2559 ierr = VecDestroy(&coordsVec);CHKERRQ(ierr);
2562 "Successfully gathered coordinates. Ncoords=%d.\n", *Ncoords);
2563 PetscFunctionReturn(0);
2572 const char *fieldName,
2574 double **scalarArray,
2577 PetscFunctionBeginUser;
2579 PetscErrorCode ierr;
2583 ierr = VecCreate(PETSC_COMM_WORLD, &fieldVec);CHKERRQ(ierr);
2584 ierr = VecSetFromOptions(fieldVec);CHKERRQ(ierr);
2586 ierr =
ReadFieldData(user, fieldName, fieldVec, timeIndex,
"dat");
2589 "Error reading field '%s' (ti=%d).\n",
2590 fieldName, timeIndex);
2591 PetscFunctionReturn(ierr);
2597 ierr = VecDestroy(&fieldVec);CHKERRQ(ierr);
2600 "Successfully gathered field '%s'. Nscalars=%d.\n",
2601 fieldName, *Nscalars);
2602 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_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.