41 while (isspace((
unsigned char)*start)) {
46 char *end = str + strlen(str) - 1;
48 while (end > start && isspace((
unsigned char)*end)) {
57 memmove(str, start, (end - start) + 2);
63#define __FUNCT__ "ReadGridGenerationInputs"
82 PetscInt block_index = user->
_this;
86 PetscInt *IMs = NULL, *JMs = NULL, *KMs = NULL, *cgrids = NULL;
87 PetscReal *xMins = NULL, *xMaxs = NULL, *rxs = NULL;
88 PetscReal *yMins = NULL, *yMaxs = NULL, *rys = NULL;
89 PetscReal *zMins = NULL, *zMaxs = NULL, *rzs = NULL;
91 PetscFunctionBeginUser;
96 if (block_index >= nblk) {
97 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE,
"Block index %d is out of range for nblk=%d", block_index, nblk);
101 ierr = PetscMalloc4(nblk, &IMs, nblk, &JMs, nblk, &KMs, nblk, &cgrids); CHKERRQ(ierr);
102 ierr = PetscMalloc6(nblk, &xMins, nblk, &xMaxs, nblk, &rxs, nblk, &yMins, nblk, &yMaxs, nblk, &rys); CHKERRQ(ierr);
103 ierr = PetscMalloc3(nblk, &zMins, nblk, &zMaxs, nblk, &rzs); CHKERRQ(ierr);
106 for (PetscInt i = 0; i < nblk; ++i) {
107 IMs[i] = 10; JMs[i] = 10; KMs[i] = 10; cgrids[i] = 0;
108 xMins[i] = 0.0; xMaxs[i] = 1.0; rxs[i] = 1.0;
109 yMins[i] = 0.0; yMaxs[i] = 1.0; rys[i] = 1.0;
110 zMins[i] = 0.0; zMaxs[i] = 1.0; rzs[i] = 1.0;
115 count = nblk; ierr = PetscOptionsGetIntArray(NULL, NULL,
"-im", IMs, &count, &found); CHKERRQ(ierr);
116 count = nblk; ierr = PetscOptionsGetIntArray(NULL, NULL,
"-jm", JMs, &count, &found); CHKERRQ(ierr);
117 count = nblk; ierr = PetscOptionsGetIntArray(NULL, NULL,
"-km", KMs, &count, &found); CHKERRQ(ierr);
118 count = nblk; ierr = PetscOptionsGetRealArray(NULL, NULL,
"-xMins", xMins, &count, &found); CHKERRQ(ierr);
119 count = nblk; ierr = PetscOptionsGetRealArray(NULL, NULL,
"-xMaxs", xMaxs, &count, &found); CHKERRQ(ierr);
120 count = nblk; ierr = PetscOptionsGetRealArray(NULL, NULL,
"-rxs", rxs, &count, &found); CHKERRQ(ierr);
121 count = nblk; ierr = PetscOptionsGetRealArray(NULL, NULL,
"-yMins", yMins, &count, &found); CHKERRQ(ierr);
122 count = nblk; ierr = PetscOptionsGetRealArray(NULL, NULL,
"-yMaxs", yMaxs, &count, &found); CHKERRQ(ierr);
123 count = nblk; ierr = PetscOptionsGetRealArray(NULL, NULL,
"-rys", rys, &count, &found); CHKERRQ(ierr);
124 count = nblk; ierr = PetscOptionsGetRealArray(NULL, NULL,
"-zMins", zMins, &count, &found); CHKERRQ(ierr);
125 count = nblk; ierr = PetscOptionsGetRealArray(NULL, NULL,
"-zMaxs", zMaxs, &count, &found); CHKERRQ(ierr);
126 count = nblk; ierr = PetscOptionsGetRealArray(NULL, NULL,
"-rzs", rzs, &count, &found); CHKERRQ(ierr);
127 count = nblk; ierr = PetscOptionsGetIntArray(NULL, NULL,
"-cgrids", cgrids, &count, &found); CHKERRQ(ierr);
130 user->
IM = IMs[block_index];
131 user->
JM = JMs[block_index];
132 user->
KM = KMs[block_index];
133 user->
Min_X = xMins[block_index];
134 user->
Max_X = xMaxs[block_index];
135 user->
rx = rxs[block_index];
136 user->
Min_Y = yMins[block_index];
137 user->
Max_Y = yMaxs[block_index];
138 user->
ry = rys[block_index];
139 user->
Min_Z = zMins[block_index];
140 user->
Max_Z = zMaxs[block_index];
141 user->
rz = rzs[block_index];
142 user->
cgrid = cgrids[block_index];
145 simCtx->
rank, block_index, user->
IM, user->
JM, user->
KM);
150 ierr = PetscFree4(IMs, JMs, KMs, cgrids); CHKERRQ(ierr);
151 ierr = PetscFree6(xMins, xMaxs, rxs, yMins, yMaxs, rys); CHKERRQ(ierr);
152 ierr = PetscFree3(zMins, zMaxs, rzs); CHKERRQ(ierr);
155 PetscFunctionReturn(0);
165 PetscInt *IMs = NULL, *JMs = NULL, *KMs = NULL;
168 PetscFunctionBeginUser;
171 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"finest_users cannot be NULL.");
174 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE,
"nblk must be positive. Got %d.", nblk);
176 simCtx = finest_users[0].
simCtx;
178 ierr = PetscMalloc3(nblk, &IMs, nblk, &JMs, nblk, &KMs); CHKERRQ(ierr);
179 for (PetscInt i = 0; i < nblk; ++i) {
180 IMs[i] = 10; JMs[i] = 10; KMs[i] = 10;
184 count = nblk; ierr = PetscOptionsGetIntArray(NULL, NULL,
"-im", IMs, &count, &found); CHKERRQ(ierr);
185 count = nblk; ierr = PetscOptionsGetIntArray(NULL, NULL,
"-jm", JMs, &count, &found); CHKERRQ(ierr);
186 count = nblk; ierr = PetscOptionsGetIntArray(NULL, NULL,
"-km", KMs, &count, &found); CHKERRQ(ierr);
188 for (PetscInt bi = 0; bi < nblk; ++bi) {
189 finest_users[bi].
IM = IMs[bi];
190 finest_users[bi].
JM = JMs[bi];
191 finest_users[bi].
KM = KMs[bi];
194 "Rank %d: Preloaded analytical grid resolution for block %d: IM=%d, JM=%d, KM=%d\n",
195 simCtx->
rank, bi, finest_users[bi].
IM, finest_users[bi].
JM, finest_users[bi].
KM);
199 ierr = PetscFree3(IMs, JMs, KMs); CHKERRQ(ierr);
200 PetscFunctionReturn(0);
205#define __FUNCT__ "ReadGridFile"
226 PetscInt block_index = user->
_this;
228 PetscFunctionBeginUser;
234 PetscMPIInt rank = simCtx->
rank;
238 FILE *fd = fopen(simCtx->
grid_file,
"r");
239 if (!fd) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN,
"Cannot open file: %s", simCtx->
grid_file);
243 char firstTok[32] = {0};
244 if (fscanf(fd,
"%31s", firstTok) != 1)
245 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_FILE_READ,
"Empty grid file: %s", simCtx->
grid_file);
247 if (strcmp(firstTok,
"PICGRID") == 0) {
250 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_FILE_READ,
"Expected number of blocks after \"PICGRID\" in %s", simCtx->
grid_file);
256 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_FILE_UNEXPECTED,
"Mismatch: -nblk is %d but grid file specifies %d blocks.", nblk,
g_nblk_from_file);
260 for (PetscInt i = 0; i < nblk; ++i) {
262 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_FILE_READ,
"Expected 3 integers for block %d in %s", i, simCtx->
grid_file);
269 ierr = MPI_Bcast(&
g_nblk_from_file, 1, MPI_INT, 0, PETSC_COMM_WORLD); CHKERRQ(ierr);
277 ierr = MPI_Bcast(
g_IMs_from_file, nblk, MPI_INT, 0, PETSC_COMM_WORLD); CHKERRQ(ierr);
278 ierr = MPI_Bcast(
g_JMs_from_file, nblk, MPI_INT, 0, PETSC_COMM_WORLD); CHKERRQ(ierr);
279 ierr = MPI_Bcast(
g_KMs_from_file, nblk, MPI_INT, 0, PETSC_COMM_WORLD); CHKERRQ(ierr);
291 simCtx->
rank, block_index, user->
IM, user->
JM, user->
KM);
294 PetscFunctionReturn(0);
310 while (current != NULL) {
312 PetscFree(current->
key);
313 PetscFree(current->
value);
327 else if (strcasecmp(str,
"+Xi") == 0) *face_out =
BC_FACE_POS_X;
328 else if (strcasecmp(str,
"-Eta") == 0) *face_out =
BC_FACE_NEG_Y;
329 else if (strcasecmp(str,
"+Eta") == 0) *face_out =
BC_FACE_POS_Y;
330 else if (strcasecmp(str,
"-Zeta") == 0) *face_out =
BC_FACE_NEG_Z;
331 else if (strcasecmp(str,
"+Zeta") == 0) *face_out =
BC_FACE_POS_Z;
332 else SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_UNKNOWN_TYPE,
"Unknown face specifier: %s", str);
343 if (strcasecmp(str,
"WALL") == 0) *type_out =
WALL;
344 else if (strcasecmp(str,
"SYMMETRY") == 0) *type_out =
SYMMETRY;
345 else if (strcasecmp(str,
"INLET") == 0) *type_out =
INLET;
346 else if (strcasecmp(str,
"OUTLET") == 0) *type_out =
OUTLET;
347 else if (strcasecmp(str,
"PERIODIC") == 0) *type_out =
PERIODIC;
349 else SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_UNKNOWN_TYPE,
"Unknown BC Type string: %s", str);
368 else SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_UNKNOWN_TYPE,
"Unknown BC Handler string: %s", str);
406 *found = PETSC_FALSE;
412 if (strcasecmp(current->
key, key) == 0) {
413 *value_out = atof(current->
value);
417 current = current->
next;
431 *found = PETSC_FALSE;
432 *value_out = PETSC_FALSE;
437 if (strcasecmp(current->
key, key) == 0) {
442 if (current->
value &&
443 (strcasecmp(current->
value,
"true") == 0 ||
444 strcmp(current->
value,
"1") == 0 ||
445 strcasecmp(current->
value,
"yes") == 0))
447 *value_out = PETSC_TRUE;
449 *value_out = PETSC_FALSE;
453 current = current->
next;
464#define __FUNCT__ "ParseAllBoundaryConditions"
492 PetscFunctionBeginUser;
494 ierr = MPI_Comm_rank(PETSC_COMM_WORLD, &rank); CHKERRQ(ierr);
498 char line_buffer[1024];
501 for (
int i = 0; i < 6; i++) {
505 configs_rank0[i].
params = NULL;
506 configs_rank0[i].
handler = NULL;
510 file = fopen(bcs_input_filename,
"r");
511 if (!file) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN,
"Could not open BCs file '%s'.", bcs_input_filename);
513 while (fgets(line_buffer,
sizeof(line_buffer), file)) {
514 char *current_pos = line_buffer;
515 while (isspace((
unsigned char)*current_pos)) current_pos++;
516 if (*current_pos ==
'#' || *current_pos ==
'\0' || *current_pos ==
'\n' || *current_pos ==
'\r')
continue;
518 char *face_str = strtok(current_pos,
" \t\n\r");
519 char *type_str = strtok(NULL,
" \t\n\r");
520 char *handler_str = strtok(NULL,
" \t\n\r");
522 if (!face_str || !type_str || !handler_str) {
530 const char* handler_name_for_log;
537 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);
543 LOG_ALLOW(
GLOBAL,
LOG_DEBUG,
" Parsed Face '%s': Type=%s, Handler=%s \n", face_str, type_str, handler_name_for_log);
547 configs_rank0[face_enum].
params = NULL;
551 while ((token = strtok(NULL,
" \t\n\r")) != NULL) {
552 char* equals_ptr = strchr(token,
'=');
559 char* key_str = token;
560 char* value_str = equals_ptr + 1;
563 ierr = PetscMalloc1(1, &new_param); CHKERRQ(ierr);
564 ierr = PetscStrallocpy(key_str, &new_param->
key); CHKERRQ(ierr);
565 ierr = PetscStrallocpy(value_str, &new_param->
value); CHKERRQ(ierr);
566 new_param->
next = NULL;
568 *param_next_ptr = new_param;
569 param_next_ptr = &new_param->
next;
583 for (
int i = 0; i < 6; i++) {
592 PetscInt n_params = 0;
596 ierr = MPI_Bcast(&n_params, 1, MPI_INT, 0, PETSC_COMM_WORLD);CHKERRQ(ierr);
605 for (
int j = 0; j < n_params; j++) {
606 char key_buf[256] = {0}, val_buf[256] = {0};
610 for (
int k = 0; k < j; k++) p = p->
next;
611 strncpy(key_buf, p->
key, 255);
612 strncpy(val_buf, p->
value, 255);
615 ierr = MPI_Bcast(key_buf, 256, MPI_CHAR, 0, PETSC_COMM_WORLD); CHKERRQ(ierr);
616 ierr = MPI_Bcast(val_buf, 256, MPI_CHAR, 0, PETSC_COMM_WORLD); CHKERRQ(ierr);
621 ierr = PetscMalloc1(1, &new_param); CHKERRQ(ierr);
622 ierr = PetscStrallocpy(key_buf, &new_param->
key); CHKERRQ(ierr);
623 ierr = PetscStrallocpy(val_buf, &new_param->
value); CHKERRQ(ierr);
624 new_param->
next = NULL;
625 *param_next_ptr = new_param;
626 param_next_ptr = &new_param->
next;
629 param_next_ptr = &((*param_next_ptr)->next);
637 for (
int i=0; i<6; i++) {
655 PetscFunctionReturn(0);
666#define __FUNCT__ "DeterminePeriodicity"
694 PetscInt periodic_flags[3] = {0, 0, 0};
696 PetscFunctionBeginUser;
697 ierr = MPI_Comm_rank(PETSC_COMM_WORLD, &rank); CHKERRQ(ierr);
700 for (PetscInt bi = 0; bi < simCtx->
block_number; bi++) {
701 const char *bcs_filename = simCtx->
bcs_files[bi];
702 if (!bcs_filename) SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_NULL,
"BCS filename for block %d is not set in SimCtx.", bi);
704 PetscBool file_exists;
705 snprintf(desc_buf,
sizeof(desc_buf),
"BCS file for block %d", bi);
706 ierr =
VerifyPathExistence(bcs_filename, PETSC_FALSE, PETSC_FALSE, desc_buf, &file_exists); CHKERRQ(ierr);
711 PetscBool global_is_periodic[3] = {PETSC_FALSE, PETSC_FALSE, PETSC_FALSE};
712 PetscBool is_set = PETSC_FALSE;
714 for (PetscInt bi = 0; bi < simCtx->
block_number; bi++) {
715 const char *bcs_filename = simCtx->
bcs_files[bi];
716 FILE *file = fopen(bcs_filename,
"r");
718 PetscBool face_is_periodic[6] = {PETSC_FALSE};
719 char line_buffer[1024];
721 while (fgets(line_buffer,
sizeof(line_buffer), file)) {
722 char *current_pos = line_buffer;
723 while (isspace((
unsigned char)*current_pos)) current_pos++;
724 if (*current_pos ==
'#' || *current_pos ==
'\0' || *current_pos ==
'\n')
continue;
727 char *face_str = strtok(current_pos,
" \t\n\r");
728 char *type_str = strtok(NULL,
" \t\n\r");
731 if (!face_str || !type_str)
continue;
734 if (strcasecmp(type_str,
"PERIODIC") == 0) {
738 face_is_periodic[face_enum] = PETSC_TRUE;
746 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);
748 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);
750 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);
756 global_is_periodic[0] = local_is_periodic[0];
757 global_is_periodic[1] = local_is_periodic[1];
758 global_is_periodic[2] = local_is_periodic[2];
761 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]) {
762 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_INCOMP,
763 "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).",
764 (
int)global_is_periodic[0], (
int)global_is_periodic[1], (
int)global_is_periodic[2],
766 (
int)local_is_periodic[0], (
int)local_is_periodic[1], (
int)local_is_periodic[2]);
771 periodic_flags[0] = (global_is_periodic[0]) ? 1 : 0;
772 periodic_flags[1] = (global_is_periodic[1]) ? 1 : 0;
773 periodic_flags[2] = (global_is_periodic[2]) ? 1 : 0;
776 periodic_flags[0], periodic_flags[1], periodic_flags[2]);
780 ierr = MPI_Bcast(periodic_flags, 3, MPIU_INT, 0, PETSC_COMM_WORLD); CHKERRQ(ierr);
787 PetscFunctionReturn(0);
807PetscErrorCode
VerifyPathExistence(
const char *path, PetscBool is_dir, PetscBool is_optional,
const char *description, PetscBool *exists)
811 MPI_Comm comm = PETSC_COMM_WORLD;
813 PetscFunctionBeginUser;
814 ierr = MPI_Comm_rank(comm, &rank); CHKERRQ(ierr);
818 ierr = PetscTestDirectory(path,
'r', exists); CHKERRQ(ierr);
820 ierr = PetscTestFile(path,
'r', exists); CHKERRQ(ierr);
835 PetscMPIInt exists_int = (rank == 0) ? (PetscMPIInt)(*exists) : 0;
836 ierr = MPI_Bcast(&exists_int, 1, MPI_INT, 0, comm); CHKERRMPI(ierr);
837 *exists = (PetscBool)exists_int;
840 if (!(*exists) && !is_optional) {
841 SETERRQ(comm, PETSC_ERR_FILE_OPEN,
"Mandatory %s not found. Rank 0 expected it at '%s'. Check path and permissions.", description, path);
844 PetscFunctionReturn(0);
862static PetscErrorCode
CheckDataFile(
UserCtx *user, PetscInt ti,
const char *fieldName,
const char *ext, PetscBool *fileExists)
866 MPI_Comm comm = PETSC_COMM_WORLD;
867 PetscInt placeholder_int = 0;
870 PetscFunctionBeginUser;
873 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_NULL,
"I/O context directory is NULL. Ensure it is set before calling CheckDataFile().");
876 ierr = MPI_Comm_rank(comm, &rank); CHKERRQ(ierr);
879 char filename[PETSC_MAX_PATH_LEN];
882 ierr = PetscSNPrintf(filename,
sizeof(filename),
"%s/%s%05"PetscInt_FMT
"_%d.%s",simCtx->
current_io_directory,fieldName, ti, placeholder_int, ext);
883 ierr = PetscTestFile(filename,
'r', fileExists); CHKERRQ(ierr);
884 if (!(*fileExists)) {
891 PetscMPIInt fileExists_int = (rank == 0) ? (PetscMPIInt)(*fileExists) : 0;
892 ierr = MPI_Bcast(&fileExists_int, 1, MPI_INT, 0, comm); CHKERRMPI(ierr);
893 *fileExists = (PetscBool)fileExists_int;
895 PetscFunctionReturn(0);
920static PetscErrorCode
ReadOptionalField(
UserCtx *user,
const char *field_name,
const char *field_label, Vec field_vec, PetscInt ti,
const char *ext)
923 PetscBool fileExists;
925 PetscFunctionBeginUser;
928 ierr =
CheckDataFile(user,ti, field_name, ext, &fileExists); CHKERRQ(ierr);
938 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);
947 PetscFunctionReturn(0);
973 PetscBool fileExists;
975 PetscFunctionBeginUser;
978 ierr =
CheckDataFile(user,ti, field_name, ext, &fileExists); CHKERRQ(ierr);
983 if(strcasecmp(field_name,
"DMSwarm_CellID") == 0 || strcasecmp(field_name,
"DMSwarm_pid")== 0 || strcasecmp(field_name,
"DMSwarm_location_status")== 0 ) {
994 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);
1003 PetscFunctionReturn(0);
1007#define __FUNCT__ "ReadFieldData"
1041 const char *field_name,
1046 PetscErrorCode ierr;
1047 char filename[PETSC_MAX_PATH_LEN];
1049 PetscMPIInt rank,size;
1053 PetscFunctionBeginUser;
1057 SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,
"I/O context directory was not set before calling ReadFieldData().");
1061 ierr = PetscObjectGetComm((PetscObject)field_vec,&comm);CHKERRQ(ierr);
1062 ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr);
1063 ierr = MPI_Comm_size(comm,&size);CHKERRQ(ierr);
1065 const char *source_path = NULL;
1069 SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,
"source_path was not set for the current execution mode.");
1075 ierr = PetscSNPrintf(filename,
sizeof(filename),
1076 "%s/%s%05" PetscInt_FMT
"_0.%s",
1077 source_path,field_name,ti,ext);CHKERRQ(ierr);
1080 "Attempting to read <%s> on rank %d/%d\n",
1081 filename,(
int)rank,(
int)size);
1091 PetscInt expectedSize,loadedSize;
1093 ierr = PetscTestFile(filename,
'r',&found);CHKERRQ(ierr);
1094 if(!found) SETERRQ(comm,PETSC_ERR_FILE_OPEN,
1095 "Restart/Source file not found: %s",filename);
1097 ierr = PetscViewerBinaryOpen(PETSC_COMM_SELF,filename,FILE_MODE_READ,&viewer);CHKERRQ(ierr);
1101 ierr = VecCreate(PETSC_COMM_SELF, &temp_vec); CHKERRQ(ierr);
1102 ierr = VecLoad(temp_vec,viewer);CHKERRQ(ierr);
1103 ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
1106 ierr = VecGetSize(field_vec, &expectedSize);CHKERRQ(ierr);
1107 ierr = VecGetSize(temp_vec, &loadedSize);CHKERRQ(ierr);
1108 if (loadedSize != expectedSize) {
1109 SETERRQ(comm,PETSC_ERR_FILE_UNEXPECTED,
1110 "File %s holds %d entries – expected %d for field '%s'",
1111 filename, loadedSize, expectedSize, field_name);
1115 ierr = VecCopy(temp_vec, field_vec);CHKERRQ(ierr);
1118 ierr = VecDestroy(&temp_vec);CHKERRQ(ierr);
1134 "Loaded <%s> (serial path)\n",filename);
1137 PetscFunctionReturn(0);
1143 PetscInt globalSize;
1144 ierr = VecGetSize(field_vec,&globalSize);CHKERRQ(ierr);
1147 const char *dmtype = NULL;
1152 const PetscScalar *seqArray = NULL;
1159 ierr = PetscTestFile(filename,
'r',&found);CHKERRQ(ierr);
1160 if(!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,
1161 "Restart file not found: %s",filename);
1164 ierr = VecCreate(PETSC_COMM_SELF,&seq_vec);CHKERRQ(ierr);
1165 ierr = VecSetType(seq_vec,VECSEQ);CHKERRQ(ierr);
1167 ierr = PetscViewerBinaryOpen(PETSC_COMM_SELF,filename,
1168 FILE_MODE_READ,&viewer);CHKERRQ(ierr);
1169 ierr = VecLoad(seq_vec,viewer);CHKERRQ(ierr);
1170 ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
1174 ierr = VecGetSize(seq_vec,&loaded);CHKERRQ(ierr);
1175 if(loaded != globalSize)
1176 SETERRQ(comm,PETSC_ERR_FILE_UNEXPECTED,
1177 "File %s holds %d entries – expected %d",
1178 filename,loaded,globalSize);
1181 ierr = VecGetArrayRead(seq_vec,&seqArray);CHKERRQ(ierr);
1184 "Rank 0 successfully loaded <%s>\n",filename);
1188 ierr = VecGetDM(field_vec, &dm); CHKERRQ(ierr);
1189 if (dm) { ierr = DMGetType(dm, &dmtype); CHKERRQ(ierr); }
1191 if (dmtype && !strcmp(dmtype, DMDA)) {
1197 ierr = DMDACreateNaturalVector(dm, &nat); CHKERRQ(ierr);
1203 ierr = VecScatterCreateToZero(nat, &scatter, &nat_seq); CHKERRQ(ierr);
1206 ierr = VecScatterBegin(scatter, (rank == 0 ? seq_vec : nat_seq), nat,
1207 INSERT_VALUES, SCATTER_REVERSE); CHKERRQ(ierr);
1208 ierr = VecScatterEnd(scatter, (rank == 0 ? seq_vec : nat_seq), nat,
1209 INSERT_VALUES, SCATTER_REVERSE); CHKERRQ(ierr);
1212 ierr = DMDANaturalToGlobalBegin(dm, nat, INSERT_VALUES, field_vec); CHKERRQ(ierr);
1213 ierr = DMDANaturalToGlobalEnd(dm, nat, INSERT_VALUES, field_vec); CHKERRQ(ierr);
1216 ierr = VecScatterDestroy(&scatter); CHKERRQ(ierr);
1217 ierr = VecDestroy(&nat_seq); CHKERRQ(ierr);
1218 ierr = VecDestroy(&nat); CHKERRQ(ierr);
1225 PetscScalar *buffer = NULL;
1227 buffer = (PetscScalar *)seqArray;
1229 ierr = PetscMalloc1(globalSize, &buffer); CHKERRQ(ierr);
1232 ierr = MPI_Bcast(buffer, (
int)globalSize, MPIU_SCALAR, 0, comm); CHKERRQ(ierr);
1235 PetscInt rstart, rend, loc;
1236 PetscScalar *locArray;
1238 ierr = VecGetOwnershipRange(field_vec, &rstart, &rend); CHKERRQ(ierr);
1239 loc = rend - rstart;
1241 ierr = VecGetArray(field_vec, &locArray); CHKERRQ(ierr);
1242 ierr = PetscMemcpy(locArray, buffer + rstart, loc *
sizeof(PetscScalar)); CHKERRQ(ierr);
1243 ierr = VecRestoreArray(field_vec, &locArray); CHKERRQ(ierr);
1246 ierr = PetscFree(buffer); CHKERRQ(ierr);
1252 ierr = VecRestoreArrayRead(seq_vec, &seqArray); CHKERRQ(ierr);
1253 ierr = VecDestroy(&seq_vec); CHKERRQ(ierr);
1257 "Loaded <%s> (parallel path)\n",filename);
1260 PetscFunctionReturn(0);
1278 PetscErrorCode ierr;
1281 const char *source_path = NULL;
1282 const char *eulerian_ext =
"dat";
1292 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE,
"Invalid execution mode for reading simulation fields.");
1302 ierr =
ReadFieldData(user,
"ufield", user->
Ucat, ti, eulerian_ext); CHKERRQ(ierr);
1308 ierr =
ReadFieldData(user,
"pfield", user->
P, ti, eulerian_ext); CHKERRQ(ierr);
1318 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"ParticleCount Vec is NULL but np>0");
1322 ierr =
ReadOptionalField(user,
"psifield",
"Scalar Psi Field", user->
Psi, ti, eulerian_ext); CHKERRQ(ierr);
1362 PetscErrorCode ierr;
1363 const char *eulerian_ext =
"dat";
1393 PetscErrorCode ierr;
1394 const char *eulerian_ext =
"dat";
1401 ierr =
ReadOptionalField(user,
"Nu_t",
"Turbulent Viscosity", user->
Nu_t, ti, eulerian_ext); CHKERRQ(ierr);
1402 ierr =
ReadOptionalField(user,
"cs",
"Smagorinsky Constant (Cs)", user->
CS, ti, eulerian_ext); CHKERRQ(ierr);
1404 DMGlobalToLocalBegin(user->
da, user->
CS, INSERT_VALUES, user->
lCs);
1405 DMGlobalToLocalEnd(user->
da, user->
CS, INSERT_VALUES, user->
lCs);
1407 DMGlobalToLocalBegin(user->
da, user->
Nu_t, INSERT_VALUES, user->
lNu_t);
1408 DMGlobalToLocalEnd(user->
da, user->
Nu_t, INSERT_VALUES, user->
lNu_t);
1428 PetscErrorCode ierr;
1429 const char *eulerian_ext =
"dat";
1437 ierr =
ReadOptionalField(user,
"Nu_t",
"Turbulent Viscosity", user->
Nu_t, ti, eulerian_ext); CHKERRQ(ierr);
1444 DMGlobalToLocalBegin(user->
da, user->
Nu_t, INSERT_VALUES, user->
lNu_t);
1445 DMGlobalToLocalEnd(user->
da, user->
Nu_t, INSERT_VALUES, user->
lNu_t);
1474 PetscErrorCode ierr;
1480 swarm = user->
swarm;
1485 ierr = DMSwarmCreateGlobalVectorFromField(swarm, field_name, &fieldVec);CHKERRQ(ierr);
1490 ierr =
ReadFieldData(user, field_name, fieldVec, ti, ext);CHKERRQ(ierr);
1493 ierr = DMSwarmDestroyGlobalVectorFromField(swarm, field_name, &fieldVec);CHKERRQ(ierr);
1495 PetscFunctionReturn(0);
1519 PetscErrorCode ierr;
1520 DM swarm = user->
swarm;
1522 PetscInt nlocal, nglobal, bs, i;
1523 const PetscScalar *scalar_array;
1524 void *field_array_void;
1527 PetscFunctionBeginUser;
1532 ierr = DMSwarmGetLocalSize(swarm, &nlocal); CHKERRQ(ierr);
1533 ierr = DMSwarmGetSize(swarm, &nglobal); CHKERRQ(ierr);
1535 ierr = DMSwarmGetField(swarm, field_name, &bs, NULL, NULL); CHKERRQ(ierr);
1536 ierr = DMSwarmRestoreField(swarm, field_name, &bs, NULL, NULL); CHKERRQ(ierr);
1539 ierr = VecCreate(PETSC_COMM_WORLD, &temp_vec); CHKERRQ(ierr);
1540 ierr = VecSetType(temp_vec, VECMPI); CHKERRQ(ierr);
1541 ierr = VecSetSizes(temp_vec, nlocal * bs, nglobal * bs); CHKERRQ(ierr);
1542 ierr = VecSetBlockSize(temp_vec, bs); CHKERRQ(ierr);
1543 ierr = VecSetUp(temp_vec); CHKERRQ(ierr);
1546 ierr =
ReadFieldData(user, field_name, temp_vec, ti, ext); CHKERRQ(ierr);
1549 ierr = VecGetArrayRead(temp_vec, &scalar_array); CHKERRQ(ierr);
1550 ierr = DMSwarmGetField(swarm, field_name, NULL, NULL, &field_array_void); CHKERRQ(ierr);
1553 if (strcmp(field_name,
"DMSwarm_pid") == 0) {
1554 PetscInt64 *int64_array = (PetscInt64 *)field_array_void;
1555 for (i = 0; i < nlocal * bs; i++) {
1556 int64_array[i] = (PetscInt64)scalar_array[i];
1559 PetscInt *int_array = (PetscInt *)field_array_void;
1560 for (i = 0; i < nlocal * bs; i++) {
1561 int_array[i] = (PetscInt)scalar_array[i];
1566 ierr = DMSwarmRestoreField(swarm, field_name, NULL, NULL, &field_array_void); CHKERRQ(ierr);
1567 ierr = VecRestoreArrayRead(temp_vec, &scalar_array); CHKERRQ(ierr);
1570 ierr = VecDestroy(&temp_vec); CHKERRQ(ierr);
1572 PetscFunctionReturn(0);
1597 PetscErrorCode ierr;
1600 const char *source_path = NULL;
1601 const char *particle_ext =
"dat";
1603 PetscFunctionBeginUser;
1604 ierr = DMSwarmGetSize(user->
swarm, &nGlobal); CHKERRQ(ierr);
1609 PetscFunctionReturn(0);
1621 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONGSTATE,
"Invalid execution mode for reading simulation fields.");
1634 SETERRQ(PETSC_COMM_WORLD, ierr,
"Failed to read MANDATORY 'position' field for step %d. Cannot continue.", ti);
1645 ierr =
ReadOptionalSwarmField(user,
"DMSwarm_location_status",
"Migration Status", ti, particle_ext); CHKERRQ(ierr);
1650 PetscFunctionReturn(0);
1655#define __FUNCT__ "WriteFieldData"
1702 const char *field_name,
1707 PetscErrorCode ierr;
1709 PetscMPIInt rank, size;
1711 const PetscInt placeholder_int = 0;
1712 char filename[PETSC_MAX_PATH_LEN];
1715 PetscFunctionBeginUser;
1719 SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,
"Output directory was not set before calling WriteFieldData().");
1725 ierr = PetscObjectGetComm((PetscObject)field_vec,&comm);CHKERRQ(ierr);
1726 ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr);
1727 ierr = MPI_Comm_size(comm,&size);CHKERRQ(ierr);
1729 ierr = PetscSNPrintf(filename,
sizeof(filename),
1730 "%s/%s%05" PetscInt_FMT
"_%d.%s",
1734 " Preparing to write <%s> on rank %d/%d\n",
1735 filename,rank,size);
1743 ierr = PetscViewerBinaryOpen(comm,filename,
1744 FILE_MODE_WRITE,&viewer);CHKERRQ(ierr);
1745 ierr = VecView(field_vec,viewer);CHKERRQ(ierr);
1746 ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
1749 " Wrote <%s> (serial path)\n",filename);
1750 PetscFunctionReturn(0);
1759 const char *dmtype = NULL;
1763 ierr = VecGetDM(field_vec, &dm); CHKERRQ(ierr);
1764 if (dm) { ierr = DMGetType(dm, &dmtype); CHKERRQ(ierr); }
1766 if (dmtype && !strcmp(dmtype, DMDA)) {
1768 ierr = DMDACreateNaturalVector(dm, &nat); CHKERRQ(ierr);
1769 ierr = DMDAGlobalToNaturalBegin(dm, field_vec, INSERT_VALUES, nat); CHKERRQ(ierr);
1770 ierr = DMDAGlobalToNaturalEnd(dm, field_vec, INSERT_VALUES, nat); CHKERRQ(ierr);
1773 ierr = VecScatterCreateToZero(nat, &scatter, &seq_vec); CHKERRQ(ierr);
1776 ierr = VecScatterCreateToZero(field_vec, &scatter, &seq_vec); CHKERRQ(ierr);
1780 ierr = VecScatterBegin(scatter, (nat ? nat : field_vec), seq_vec,
1781 INSERT_VALUES, SCATTER_FORWARD); CHKERRQ(ierr);
1782 ierr = VecScatterEnd(scatter, (nat ? nat : field_vec), seq_vec,
1783 INSERT_VALUES, SCATTER_FORWARD); CHKERRQ(ierr);
1790 PetscReal vmin,vmax;
1791 ierr = VecMin(seq_vec,NULL,&vmin);CHKERRQ(ierr);
1792 ierr = VecMax(seq_vec,NULL,&vmax);CHKERRQ(ierr);
1794 " <%s> range = [%.4e … %.4e]\n",
1795 field_name,(
double)vmin,(
double)vmax);
1797 ierr = PetscViewerBinaryOpen(PETSC_COMM_SELF,filename,
1798 FILE_MODE_WRITE,&viewer);CHKERRQ(ierr);
1799 ierr = VecView(seq_vec,viewer);CHKERRQ(ierr);
1800 ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
1803 " Wrote <%s> (parallel path)\n",filename);
1807 ierr = VecScatterDestroy(&scatter);CHKERRQ(ierr);
1808 ierr = VecDestroy(&seq_vec);CHKERRQ(ierr);
1809 if (nat) { ierr = VecDestroy(&nat); CHKERRQ(ierr); }
1812 PetscFunctionReturn(0);
1828 PetscErrorCode ierr;
1891 PetscErrorCode ierr;
1919 PetscErrorCode ierr;
1926 DMLocalToGlobalBegin(user->
da, user->
lCs, INSERT_VALUES, user->
CS);
1927 DMLocalToGlobalEnd(user->
da, user->
lCs, INSERT_VALUES, user->
CS);
1929 DMLocalToGlobalBegin(user->
da, user->
lNu_t, INSERT_VALUES, user->
Nu_t);
1930 DMLocalToGlobalEnd(user->
da, user->
lNu_t, INSERT_VALUES, user->
Nu_t);
1953 PetscErrorCode ierr;
1987 PetscErrorCode ierr;
1991 PetscFunctionBeginUser;
1997 swarm = user->
swarm;
2005 "Attempting to create global vector from field: %s\n",
2007 ierr = DMSwarmCreateGlobalVectorFromField(swarm, field_name, &fieldVec);CHKERRQ(ierr);
2014 "Calling WriteFieldData for field: %s\n",
2016 ierr =
WriteFieldData(user, field_name, fieldVec, ti, ext);CHKERRQ(ierr);
2024 "Destroying the global vector for field: %s\n",
2026 ierr = DMSwarmDestroyGlobalVectorFromField(swarm, field_name, &fieldVec);CHKERRQ(ierr);
2030 "Successfully wrote swarm data for field: %s\n",
2033 PetscFunctionReturn(0);
2056 PetscErrorCode ierr;
2057 DM swarm = user->
swarm;
2059 PetscInt nlocal, nglobal,bs,i;
2060 void *field_array_void;
2061 PetscScalar *scalar_array;
2063 PetscFunctionBeginUser;
2068 ierr = DMSwarmGetLocalSize(swarm, &nlocal); CHKERRQ(ierr);
2069 ierr = DMSwarmGetSize(swarm, &nglobal); CHKERRQ(ierr);
2070 ierr = DMSwarmGetField(swarm, field_name, &bs, NULL, &field_array_void); CHKERRQ(ierr);
2073 ierr = VecCreate(PETSC_COMM_WORLD, &temp_vec); CHKERRQ(ierr);
2074 ierr = VecSetType(temp_vec, VECMPI); CHKERRQ(ierr);
2075 ierr = VecSetSizes(temp_vec, nlocal*bs, nglobal*bs); CHKERRQ(ierr);
2076 ierr = VecSetUp(temp_vec); CHKERRQ(ierr);
2079 DMSwarmVectorDefineField(swarm,
"position");
2081 ierr = VecGetArray(temp_vec, &scalar_array); CHKERRQ(ierr);
2083 if(strcasecmp(field_name,
"DMSwarm_pid") == 0){
2084 PetscInt64 *int64_array = (PetscInt64 *)field_array_void;
2086 for (i = 0; i < nlocal*bs; i++) {
2087 scalar_array[i] = (PetscScalar)int64_array[i];
2090 PetscInt *int_array = (PetscInt *)field_array_void;
2092 for (i = 0; i < nlocal*bs; i++) {
2093 scalar_array[i] = (PetscScalar)int_array[i];
2098 ierr = VecRestoreArray(temp_vec, &scalar_array); CHKERRQ(ierr);
2099 ierr = DMSwarmRestoreField(swarm, field_name, &bs, NULL, &field_array_void); CHKERRQ(ierr);
2102 ierr =
WriteFieldData(user, field_name, temp_vec, ti, ext); CHKERRQ(ierr);
2105 ierr = VecDestroy(&temp_vec); CHKERRQ(ierr);
2107 PetscFunctionReturn(0);
2128 PetscErrorCode ierr;
2131 PetscFunctionBeginUser;
2134 if (!user->
swarm || simCtx->
np <= 0) {
2135 PetscFunctionReturn(0);
2172 PetscFunctionReturn(0);
2186 PetscErrorCode ierr;
2189 PetscInt globalSize;
2191 const char *dmtype = NULL;
2194 Vec nat = NULL, seqNat = NULL;
2195 VecScatter scatNat = NULL;
2196 const PetscScalar *nar = NULL;
2197 PetscScalar *buf = NULL;
2201 VecScatter scat = NULL;
2202 const PetscScalar *sar = NULL;
2204 PetscFunctionBeginUser;
2206 ierr = PetscObjectGetComm((PetscObject)inVec, &comm); CHKERRQ(ierr);
2207 ierr = MPI_Comm_rank(comm, &rank); CHKERRQ(ierr);
2208 ierr = VecGetSize(inVec, &globalSize); CHKERRQ(ierr);
2212 ierr = VecGetDM(inVec, &dm); CHKERRQ(ierr);
2213 if (dm) { ierr = DMGetType(dm, &dmtype); CHKERRQ(ierr); }
2215 if (dmtype && !strcmp(dmtype, DMDA)) {
2217 ierr = DMDACreateNaturalVector(dm, &nat); CHKERRQ(ierr);
2218 ierr = DMDAGlobalToNaturalBegin(dm, inVec, INSERT_VALUES, nat); CHKERRQ(ierr);
2219 ierr = DMDAGlobalToNaturalEnd (dm, inVec, INSERT_VALUES, nat); CHKERRQ(ierr);
2221 ierr = VecScatterCreateToZero(nat, &scatNat, &seqNat); CHKERRQ(ierr);
2222 ierr = VecScatterBegin(scatNat, nat, seqNat, INSERT_VALUES, SCATTER_FORWARD); CHKERRQ(ierr);
2223 ierr = VecScatterEnd (scatNat, nat, seqNat, INSERT_VALUES, SCATTER_FORWARD); CHKERRQ(ierr);
2227 ierr = VecGetLocalSize(seqNat, &nseq); CHKERRQ(ierr);
2228 ierr = VecGetArrayRead(seqNat, &nar); CHKERRQ(ierr);
2230 ierr = PetscMalloc1(nseq, &buf); CHKERRQ(ierr);
2231 ierr = PetscMemcpy(buf, nar, (
size_t)nseq *
sizeof(PetscScalar)); CHKERRQ(ierr);
2233 ierr = VecRestoreArrayRead(seqNat, &nar); CHKERRQ(ierr);
2234 *arrayOut = (
double*)buf;
2237 ierr = VecScatterDestroy(&scatNat); CHKERRQ(ierr);
2238 ierr = VecDestroy(&seqNat); CHKERRQ(ierr);
2239 ierr = VecDestroy(&nat); CHKERRQ(ierr);
2242 ierr = VecScatterCreateToZero(inVec, &scat, &seq); CHKERRQ(ierr);
2243 ierr = VecScatterBegin(scat, inVec, seq, INSERT_VALUES, SCATTER_FORWARD); CHKERRQ(ierr);
2244 ierr = VecScatterEnd (scat, inVec, seq, INSERT_VALUES, SCATTER_FORWARD); CHKERRQ(ierr);
2248 ierr = VecGetLocalSize(seq, &nseq); CHKERRQ(ierr);
2249 ierr = VecGetArrayRead(seq, &sar); CHKERRQ(ierr);
2251 ierr = PetscMalloc1(nseq, &buf); CHKERRQ(ierr);
2252 ierr = PetscMemcpy(buf, sar, (
size_t)nseq *
sizeof(PetscScalar)); CHKERRQ(ierr);
2254 ierr = VecRestoreArrayRead(seq, &sar); CHKERRQ(ierr);
2255 *arrayOut = (
double*)buf;
2258 ierr = VecScatterDestroy(&scat); CHKERRQ(ierr);
2259 ierr = VecDestroy(&seq); CHKERRQ(ierr);
2262 PetscFunctionReturn(0);
2279PetscErrorCode
SwarmFieldToArrayOnRank0(DM swarm,
const char *field_name, PetscInt *n_total_particles, PetscInt *n_components,
void **gathered_array)
2281 PetscErrorCode ierr;
2282 PetscMPIInt rank, size;
2283 PetscInt nlocal, nglobal, bs;
2284 void *local_array_void;
2285 size_t element_size = 0;
2286 MPI_Datatype mpi_type = MPI_BYTE;
2288 PetscFunctionBeginUser;
2290 ierr = MPI_Comm_rank(PETSC_COMM_WORLD, &rank); CHKERRQ(ierr);
2291 ierr = MPI_Comm_size(PETSC_COMM_WORLD, &size); CHKERRQ(ierr);
2294 ierr = DMSwarmGetLocalSize(swarm, &nlocal); CHKERRQ(ierr);
2295 ierr = DMSwarmGetSize(swarm, &nglobal); CHKERRQ(ierr);
2296 ierr = DMSwarmGetField(swarm, field_name, &bs, NULL, &local_array_void); CHKERRQ(ierr);
2299 if (strcasecmp(field_name,
"DMSwarm_pid") == 0) {
2300 element_size =
sizeof(PetscInt64);
2301 }
else if (strcasecmp(field_name,
"DMSwarm_CellID") == 0 || strcasecmp(field_name,
"DMSwarm_location_status") == 0) {
2302 element_size =
sizeof(PetscInt);
2304 element_size =
sizeof(PetscScalar);
2308 *n_total_particles = nglobal;
2310 *gathered_array = NULL;
2315 ierr = PetscMalloc(nglobal * bs * element_size, gathered_array); CHKERRQ(ierr);
2316 ierr = PetscMemcpy(*gathered_array, local_array_void, nglobal * bs * element_size); CHKERRQ(ierr);
2319 PetscInt *recvcounts = NULL, *displs = NULL;
2321 ierr = PetscMalloc1(size, &recvcounts); CHKERRQ(ierr);
2322 ierr = PetscMalloc1(size, &displs); CHKERRQ(ierr);
2324 PetscInt sendcount = nlocal * bs;
2327 ierr = MPI_Gather(&sendcount, 1, MPIU_INT, recvcounts, 1, MPIU_INT, 0, PETSC_COMM_WORLD); CHKERRQ(ierr);
2332 for (PetscMPIInt i = 0; i < size; i++) recvcounts[i] *= element_size;
2333 for (PetscMPIInt i = 1; i < size; i++) displs[i] = displs[i-1] + recvcounts[i-1];
2335 ierr = PetscMalloc(nglobal * bs * element_size, gathered_array); CHKERRQ(ierr);
2339 ierr = MPI_Gatherv(local_array_void, nlocal * bs * element_size, MPI_BYTE,
2340 *gathered_array, recvcounts, displs, MPI_BYTE,
2341 0, PETSC_COMM_WORLD); CHKERRQ(ierr);
2344 ierr = PetscFree(recvcounts); CHKERRQ(ierr);
2345 ierr = PetscFree(displs); CHKERRQ(ierr);
2349 ierr = DMSwarmRestoreField(swarm, field_name, &bs, NULL, &local_array_void); CHKERRQ(ierr);
2351 PetscFunctionReturn(0);
2374 PetscErrorCode ierr;
2376 Cmpnts global_min_coords, global_max_coords;
2377 PetscReal StartTime;
2378 PetscInt StartStep,StepsToRun,total_num_particles;
2379 PetscMPIInt num_mpi_procs;
2383 num_mpi_procs = simCtx->
size;
2387 total_num_particles = simCtx->
np;
2391 PetscFunctionBeginUser;
2393 if (!user) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"DisplayBanner - UserCtx pointer is NULL.");
2394 ierr = MPI_Comm_rank(PETSC_COMM_WORLD, &rank); CHKERRQ(ierr);
2399 if (bboxlist_on_rank0 && num_mpi_procs > 0) {
2400 global_min_coords = bboxlist_on_rank0[0].
min_coords;
2401 global_max_coords = bboxlist_on_rank0[0].
max_coords;
2402 for (PetscMPIInt p = 1; p < num_mpi_procs; ++p) {
2403 global_min_coords.
x = PetscMin(global_min_coords.
x, bboxlist_on_rank0[p].
min_coords.
x);
2404 global_min_coords.
y = PetscMin(global_min_coords.
y, bboxlist_on_rank0[p].
min_coords.
y);
2405 global_min_coords.
z = PetscMin(global_min_coords.
z, bboxlist_on_rank0[p].
min_coords.
z);
2406 global_max_coords.
x = PetscMax(global_max_coords.
x, bboxlist_on_rank0[p].
max_coords.
x);
2407 global_max_coords.
y = PetscMax(global_max_coords.
y, bboxlist_on_rank0[p].
max_coords.
y);
2408 global_max_coords.
z = PetscMax(global_max_coords.
z, bboxlist_on_rank0[p].
max_coords.
z);
2415 LOG_ALLOW(
LOCAL,
LOG_WARNING,
"(Rank 0) - bboxlist not provided or num_mpi_procs <=0; using user->bbox for domain bounds.\n");
2420 ierr = PetscPrintf(PETSC_COMM_SELF,
"\n"); CHKERRQ(ierr);
2421 ierr = PetscPrintf(PETSC_COMM_SELF,
"=============================================================\n"); CHKERRQ(ierr);
2422 ierr = PetscPrintf(PETSC_COMM_SELF,
" CASE SUMMARY \n"); CHKERRQ(ierr);
2423 ierr = PetscPrintf(PETSC_COMM_SELF,
"=============================================================\n"); CHKERRQ(ierr);
2424 ierr = PetscPrintf(PETSC_COMM_SELF,
" Grid Points : %d X %d X %d\n", user->
IM, user->
JM, user->
KM); CHKERRQ(ierr);
2425 ierr = PetscPrintf(PETSC_COMM_SELF,
" Cells : %d X %d X %d\n", user->
IM - 1, user->
JM - 1, user->
KM - 1); CHKERRQ(ierr);
2426 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);
2427 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);
2428 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);
2430 ierr = PetscPrintf(PETSC_COMM_SELF,
"-------------------- Boundary Conditions --------------------\n"); CHKERRQ(ierr);
2431 const int face_name_width = 17;
2432 for (PetscInt i_face = 0; i_face < 6; ++i_face) {
2440 Cmpnts inlet_velocity = {0.0,0.0,0.0};
2445 ierr = PetscPrintf(PETSC_COMM_SELF,
" Face %-*s : %s - %s - [%.4f,%.4f,%.4f]\n",
2446 face_name_width, face_str, bc_type_str, bc_handler_type_str,inlet_velocity.
x,inlet_velocity.
y,inlet_velocity.
z); CHKERRQ(ierr);
2448 PetscReal v_max = 0.0;
2451 ierr = PetscPrintf(PETSC_COMM_SELF,
" Face %-*s : %s - %s - v_max=%.4f\n",
2452 face_name_width, face_str, bc_type_str, bc_handler_type_str, v_max); CHKERRQ(ierr);
2456 PetscBool trimflag,foundflux,foundtrimflag;
2459 ierr = PetscPrintf(PETSC_COMM_SELF,
" Face %-*s : %s - %s - [%.4f] - %s\n",
2460 face_name_width, face_str, bc_type_str, bc_handler_type_str,flux,trimflag?
"Trim Ucont":
"No Trim"); CHKERRQ(ierr);
2462 ierr = PetscPrintf(PETSC_COMM_SELF,
" Face %-*s : %s - %s\n",
2463 face_name_width, face_str, bc_type_str,bc_handler_type_str); CHKERRQ(ierr);
2467 ierr = PetscPrintf(PETSC_COMM_SELF,
"-------------------------------------------------------------\n"); CHKERRQ(ierr);
2468 ierr = PetscPrintf(PETSC_COMM_SELF,
" Start Time : %.4f\n", (
double)StartTime); CHKERRQ(ierr);
2469 ierr = PetscPrintf(PETSC_COMM_SELF,
" Timestep Size : %.4f\n", (
double)simCtx->
dt); CHKERRQ(ierr);
2470 ierr = PetscPrintf(PETSC_COMM_SELF,
" Starting Step : %d\n", StartStep); CHKERRQ(ierr);
2471 ierr = PetscPrintf(PETSC_COMM_SELF,
" Total Steps to Run : %d\n", StepsToRun); CHKERRQ(ierr);
2472 ierr = PetscPrintf(PETSC_COMM_SELF,
" Number of MPI Processes : %d\n", num_mpi_procs); CHKERRQ(ierr);
2473 ierr = PetscPrintf(PETSC_COMM_WORLD,
" Number of Particles : %d\n", total_num_particles); CHKERRQ(ierr);
2477 ierr = PetscPrintf(PETSC_COMM_WORLD,
" Reynolds Number : %le\n", simCtx->
ren); CHKERRQ(ierr);
2479 ierr = PetscPrintf(PETSC_COMM_SELF,
" Particle Initialization Mode: %s\n", particle_init_str); CHKERRQ(ierr);
2483 ierr = PetscPrintf(PETSC_COMM_WORLD,
" Initial Pseudo-CFL : %le\n", simCtx->
pseudo_cfl); CHKERRQ(ierr);
2484 ierr = PetscPrintf(PETSC_COMM_WORLD,
" Large Eddy Simulation Model : %s\n",
LESModelToString(simCtx->
les)); CHKERRQ(ierr);
2491 ierr = PetscPrintf(PETSC_COMM_SELF,
" Particles Initialized At : --- (No INLET face identified)\n"); CHKERRQ(ierr);
2495 ierr = PetscPrintf(PETSC_COMM_SELF,
" Field Initialization Mode : %s\n", field_init_str); CHKERRQ(ierr);
2500 ierr = PetscPrintf(PETSC_COMM_WORLD,
" Analytical Solution Type : %s\n", simCtx->
AnalyticalSolutionType); CHKERRQ(ierr);
2502 ierr = PetscPrintf(PETSC_COMM_SELF,
"=============================================================\n"); CHKERRQ(ierr);
2503 ierr = PetscPrintf(PETSC_COMM_SELF,
"\n"); CHKERRQ(ierr);
2505 PetscFunctionReturn(0);
2509#define __FUNCT__ "ParsePostProcessingSettings"
2527 PetscBool startTimeSet, endTimeSet, timeStepSet;
2529 PetscFunctionBeginUser;
2532 if (!simCtx || !simCtx->
pps) {
2533 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_NULL,
"SimCtx or its pps member is NULL in ParsePostProcessingSettings.");
2562 file = fopen(configFile,
"r");
2565 while (fgets(line,
sizeof(line), file)) {
2566 char *key, *value, *comment;
2567 comment = strchr(line,
'#');
if (comment) *comment =
'\0';
2569 key = strtok(line,
"="); value = strtok(NULL,
"=");
2572 if (strcmp(key,
"startTime") == 0) pps->
startTime = atoi(value);
2573 else if (strcmp(key,
"endTime") == 0) pps->
endTime = atoi(value);
2574 else if (strcmp(key,
"timeStep") == 0) pps->
timeStep = atoi(value);
2575 else if (strcmp(key,
"output_particles") == 0) {
2576 if (strcasecmp(value,
"true") == 0) pps->
outputParticles = PETSC_TRUE;
2578 else if (strcasecmp(key,
"process_pipeline") == 0) {
2581 }
else if (strcasecmp(key,
"output_fields_instantaneous") == 0) {
2584 }
else if (strcasecmp(key,
"output_fields_averaged") == 0) {
2587 }
else if (strcasecmp(key,
"output_prefix") == 0) {
2590 }
else if (strcasecmp(key,
"particle_output_prefix") == 0) {
2593 }
else if (strcasecmp(key,
"particle_fields_instantaneous") == 0) {
2596 }
else if (strcasecmp(key,
"particle_pipeline") == 0) {
2599 }
else if (strcasecmp(key,
"particle_output_freq") == 0) {
2601 }
else if (strcasecmp(key,
"statistics_pipeline") == 0) {
2604 }
else if (strcasecmp(key,
"statistics_output_prefix") == 0) {
2607 }
else if (strcasecmp(key,
"particleExt") == 0) {
2610 }
else if (strcasecmp(key,
"eulerianExt") == 0) {
2613 }
else if (strcmp(key,
"reference_ip") == 0) {pps->
reference[0] = atoi(value);
2614 }
else if (strcmp(key,
"reference_jp") == 0) {pps->
reference[1] = atoi(value);
2615 }
else if (strcmp(key,
"reference_kp") == 0) {pps->
reference[2] = atoi(value);
2616 }
else if (strcasecmp(key,
"source_directory") == 0) {
2627 LOG_ALLOW(
GLOBAL,
LOG_WARNING,
"Could not open post-processing config file '%s'. Using defaults and command-line overrides.\n", configFile);
2631 PetscOptionsGetInt(NULL, NULL,
"-startTime", &pps->
startTime, &startTimeSet);
2632 PetscOptionsGetInt(NULL, NULL,
"-endTime", &pps->
endTime, &endTimeSet);
2633 PetscOptionsGetInt(NULL, NULL,
"-timeStep", &pps->
timeStep, &timeStepSet);
2634 PetscOptionsGetBool(NULL, NULL,
"-output_particles", &pps->
outputParticles, NULL);
2641 if (startTimeSet && !endTimeSet) {
2645 LOG_ALLOW(
GLOBAL,
LOG_INFO,
"Post-processing configured to run from t=%d to t=%d with step %d. Particle output: %s.\n",
2659 PetscFunctionReturn(0);
2664#define __FUNCT__ "ParseScalingInformation"
2679 PetscErrorCode ierr;
2682 PetscFunctionBeginUser;
2685 if (!simCtx) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"SimCtx is NULL in ParseScalingInformation");
2694 ierr = PetscOptionsGetReal(NULL, NULL,
"-scaling_L_ref", &simCtx->
scaling.
L_ref, &flg); CHKERRQ(ierr);
2695 ierr = PetscOptionsGetReal(NULL, NULL,
"-scaling_U_ref", &simCtx->
scaling.
U_ref, &flg); CHKERRQ(ierr);
2696 ierr = PetscOptionsGetReal(NULL, NULL,
"-scaling_rho_ref", &simCtx->
scaling.
rho_ref, &flg); CHKERRQ(ierr);
2701 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE,
"Reference velocity U_ref must be positive. Got %g", (
double)simCtx->
scaling.
U_ref);
2706 LOG(
GLOBAL,
LOG_INFO,
"---------------- Physical Scales Initialized -----------------\n");
2707 LOG(
GLOBAL,
LOG_INFO,
" L_ref: %.4f, U_ref: %.4f, rho_ref: %.4f, P_ref: %.4f\n",
2709 LOG(
GLOBAL,
LOG_INFO,
"--------------------------------------------------------------\n");
2712 PetscFunctionReturn(0);
2733 PetscMPIInt rank, size;
2734 PetscErrorCode ierr;
2737 double *array = NULL;
2738 PetscInt fileExistsFlag = 0;
2741 "Start reading from file: %s\n",
2745 if (!filename || !data_out || !Nout) {
2747 "Null pointer argument provided.\n");
2752 MPI_Comm_rank(comm, &rank);
2753 MPI_Comm_size(comm, &size);
2757 fp = fopen(filename,
"r");
2766 ierr = MPI_Bcast(&fileExistsFlag, 1, MPI_INT, 0, comm); CHKERRQ(ierr);
2768 if (!fileExistsFlag) {
2772 "File '%s' not found.\n",
2780 fp = fopen(filename,
"r");
2783 "File '%s' could not be opened for reading.\n",
2791 while (fgets(line,
sizeof(line), fp)) {
2797 "File '%s' has %d lines.\n",
2801 array = (
double*)malloc(N *
sizeof(
double));
2805 "malloc failed for array.\n");
2814 while (fgets(line,
sizeof(line), fp)) {
2816 if (sscanf(line,
"%lf", &val) == 1) {
2824 "Successfully read %d values from '%s'.\n",
2829 ierr = MPI_Bcast(&N, 1, MPI_INT, 0, comm); CHKERRQ(ierr);
2833 array = (
double*)malloc(N *
sizeof(
double));
2836 "malloc failed on rank %d.\n",
2843 ierr = MPI_Bcast(array, N, MPI_DOUBLE, 0, comm); CHKERRQ(ierr);
2850 "Done. Provided array of length=%d to all ranks.\n",
2871 double **coordsArray,
2874 PetscFunctionBeginUser;
2876 PetscErrorCode ierr;
2880 ierr = VecCreate(PETSC_COMM_WORLD, &coordsVec);CHKERRQ(ierr);
2881 ierr = VecSetFromOptions(coordsVec);CHKERRQ(ierr);
2884 ierr =
ReadFieldData(user,
"position", coordsVec, timeIndex,
"dat");
2887 "Error reading position data (ti=%d).\n",
2889 PetscFunctionReturn(ierr);
2895 ierr = VecDestroy(&coordsVec);CHKERRQ(ierr);
2898 "Successfully gathered coordinates. Ncoords=%d.\n", *Ncoords);
2899 PetscFunctionReturn(0);
2918 const char *fieldName,
2920 double **scalarArray,
2923 PetscFunctionBeginUser;
2925 PetscErrorCode ierr;
2929 ierr = VecCreate(PETSC_COMM_WORLD, &fieldVec);CHKERRQ(ierr);
2930 ierr = VecSetFromOptions(fieldVec);CHKERRQ(ierr);
2932 ierr =
ReadFieldData(user, fieldName, fieldVec, timeIndex,
"dat");
2935 "Error reading field '%s' (ti=%d).\n",
2936 fieldName, timeIndex);
2937 PetscFunctionReturn(ierr);
2943 ierr = VecDestroy(&fieldVec);CHKERRQ(ierr);
2946 "Successfully gathered field '%s'. Nscalars=%d.\n",
2947 fieldName, *Nscalars);
2948 PetscFunctionReturn(0);
PetscErrorCode ReadStatisticalFields(UserCtx *user, PetscInt ti)
Reads statistical fields for averaging purposes.
PetscErrorCode ParsePostProcessingSettings(SimCtx *simCtx)
Initializes post-processing settings from a config file and command-line overrides.
PetscErrorCode WriteAllSwarmFields(UserCtx *user)
Writes a predefined set of PETSc Swarm fields to files.
PetscErrorCode SwarmFieldToArrayOnRank0(DM swarm, const char *field_name, PetscInt *n_total_particles, PetscInt *n_components, void **gathered_array)
Gathers any DMSwarm field from all ranks to a single, contiguous array on rank 0.
PetscErrorCode ParseScalingInformation(SimCtx *simCtx)
Parses physical scaling parameters from command-line options.
PetscInt ReadDataFileToArray(const char *filename, double **data_out, PetscInt *Nout, MPI_Comm comm)
PetscErrorCode ReadGridFile(UserCtx *user)
Sets grid dimensions from a file for a SINGLE block using a one-time read cache.
PetscErrorCode StringToBCHandlerType(const char *str, BCHandlerType *handler_out)
Converts a string representation of a handler to a BCHandlerType enum.
PetscErrorCode ReadRANSFields(UserCtx *user, PetscInt ti)
Reads RANS-related fields.
PetscErrorCode GetBCParamReal(BC_Param *params, const char *key, PetscReal *value_out, PetscBool *found)
Searches a BC_Param linked list for a key and returns its value as a double.
PetscErrorCode ReadSwarmIntField(UserCtx *user, const char *field_name, PetscInt ti, const char *ext)
Reads integer swarm data by using ReadFieldData and casting the result.
PetscErrorCode WriteSwarmField(UserCtx *user, const char *field_name, PetscInt ti, const char *ext)
Writes data from a specific field in a PETSc Swarm to a file.
static PetscInt * g_IMs_from_file
Caches the IM dimensions for all blocks read from the grid file.
PetscErrorCode WriteStatisticalFields(UserCtx *user)
Writes statistical fields for averaging purposes.
PetscErrorCode ReadSimulationFields(UserCtx *user, PetscInt ti)
Reads simulation fields from files into their respective PETSc vectors.
static PetscInt g_nblk_from_file
Stores the number of blocks read from the grid file.
PetscErrorCode WriteFieldData(UserCtx *user, const char *field_name, Vec field_vec, PetscInt ti, const char *ext)
Writes data from a specific PETSc vector to a single, sequential file.
PetscErrorCode ReadLESFields(UserCtx *user, PetscInt ti)
Reads LES-related fields.
PetscErrorCode ReadFieldData(UserCtx *user, const char *field_name, Vec field_vec, PetscInt ti, const char *ext)
Reads data for a specific field from a file into the provided vector.
PetscErrorCode ParseAllBoundaryConditions(UserCtx *user, const char *bcs_input_filename)
Parses the boundary conditions file to configure the type, handler, and any associated parameters for...
PetscErrorCode ValidateBCHandlerForBCType(BCType type, BCHandlerType handler)
Validates that a specific handler is compatible with a general BC type.
void TrimWhitespace(char *str)
Trims leading and trailing whitespace from a string in-place.
PetscErrorCode WriteSimulationFields(UserCtx *user)
Writes simulation fields to files.
PetscErrorCode ReadAllSwarmFields(UserCtx *user, PetscInt ti)
Reads multiple fields into a DMSwarm, gracefully handling missing optional files.
static PetscBool g_file_has_been_read
A flag to ensure the grid file is read only once.
PetscErrorCode ReadGridGenerationInputs(UserCtx *user)
Parses command-line options for a programmatically generated grid for a SINGLE block.
PetscErrorCode ReadSwarmField(UserCtx *user, const char *field_name, PetscInt ti, const char *ext)
Reads data from a file into a specified field of a PETSc DMSwarm.
PetscErrorCode WriteRANSFields(UserCtx *user)
Writes RANS-related fields.
PetscErrorCode PopulateFinestUserGridResolutionFromOptions(UserCtx *finest_users, PetscInt nblk)
Parses grid resolution arrays (-im, -jm, -km) once and applies them to all finest-grid blocks.
PetscErrorCode DeterminePeriodicity(SimCtx *simCtx)
Scans all block-specific boundary condition files to determine a globally consistent periodicity for ...
PetscErrorCode ReadFieldDataToRank0(PetscInt timeIndex, const char *fieldName, UserCtx *user, double **scalarArray, PetscInt *Nscalars)
Reads a named field from file into a PETSc Vec, then gathers it to rank 0.
PetscErrorCode VecToArrayOnRank0(Vec inVec, PetscInt *N, double **arrayOut)
Gather a (possibly distributed) PETSc Vec onto rank 0 as a contiguous C array.
PetscErrorCode WriteSwarmIntField(UserCtx *user, const char *field_name, PetscInt ti, const char *ext)
Writes integer swarm data by casting it to a temporary Vec and using WriteFieldData.
PetscErrorCode WriteLESFields(UserCtx *user)
Writes LES-related fields.
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)
Converts a string representation of a face to a BCFace enum.
PetscErrorCode ReadPositionsFromFile(PetscInt timeIndex, UserCtx *user, double **coordsArray, PetscInt *Ncoords)
Reads coordinate data (for particles) from file into a PETSc Vec, then gathers it to rank 0.
static PetscErrorCode ReadOptionalField(UserCtx *user, const char *field_name, const char *field_label, Vec field_vec, PetscInt ti, const char *ext)
Checks for and reads an optional Eulerian field from a file into a Vec.
PetscErrorCode VerifyPathExistence(const char *path, PetscBool is_dir, PetscBool is_optional, const char *description, PetscBool *exists)
A parallel-safe helper to verify the existence of a generic file or directory path.
PetscErrorCode GetBCParamBool(BC_Param *params, const char *key, PetscBool *value_out, PetscBool *found)
Searches a BC_Param linked list for a key and returns its value as a bool.
void FreeBC_ParamList(BC_Param *head)
Frees the memory allocated for a linked list of BC_Param structs.
PetscErrorCode StringToBCType(const char *str, BCType *type_out)
Converts a string representation of a BC type to a BCType enum.
PetscErrorCode DisplayBanner(SimCtx *simCtx)
Displays a structured banner summarizing the simulation configuration.
static PetscErrorCode CheckDataFile(UserCtx *user, PetscInt ti, const char *fieldName, const char *ext, PetscBool *fileExists)
Checks for a data file's existence in a parallel-safe manner.
static PetscErrorCode ReadOptionalSwarmField(UserCtx *user, const char *field_name, const char *field_label, PetscInt ti, const char *ext)
Checks for and reads an optional DMSwarm field from a file.
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,...)
----— DEBUG ---------------------------------------— #define LOG_ALLOW(scope, level,...
#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
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
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.
char output_fields_instantaneous[1024]
char particle_subdir[PETSC_MAX_PATH_LEN]
char source_dir[PETSC_MAX_PATH_LEN]
char particle_pipeline[1024]
char eulerianSource[PETSC_MAX_PATH_LEN]
ParticleInitializationType ParticleInitialization
char process_pipeline[1024]
PetscInt particle_output_freq
char particle_fields[1024]
PetscBool outputParticles
char AnalyticalSolutionType[PETSC_MAX_PATH_LEN]
Cmpnts InitialConstantContra
@ EXEC_MODE_POSTPROCESSOR
char _io_context_buffer[PETSC_MAX_PATH_LEN]
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.