20#define PICURV_STRINGIZE_(x) #x
21#define PICURV_STRINGIZE(x) PICURV_STRINGIZE_(x)
22#if defined(PETSC_USE_DEBUG)
23#define PICURV_PETSC_MODE "debug"
25#define PICURV_PETSC_MODE "optimized"
27#if defined(PETSC_USE_64BIT_INDICES)
28#define PICURV_PETSC_INDICES "int64"
30#define PICURV_PETSC_INDICES "int32"
38#define PICURV_PETSC_STAMP_MARKER "PICURV_PETSC_BUILD:"
48#define PICURV_BUILD_STAMP_MARKER "PICURV_BUILD:"
69 const char *name = (argc > 0 && argv && argv[0] && argv[0][0]) ? argv[0] : fallback;
70 const char *slash = (name != fallback) ? strrchr(name,
'/') : NULL;
72 return slash ? slash + 1 : name;
84 if (PetscDataTypeGetSize(PETSC_INT, &linked) || linked !=
sizeof(PetscInt)) {
86 "[FATAL] %s was built against a PETSc with %d-byte indices, but the libpetsc it loaded has "
87 "%d-byte indices: another PETSc build's library is first on LD_LIBRARY_PATH, as when the "
88 "other build's PETSc module is loaded. Launch it through picurv, which puts its own "
89 "PETSc first, or unload that module.\n",
104 PetscFunctionBeginUser;
106 PetscCheck(entries <= (PetscInt64)PETSC_MAX_INT, comm, PETSC_ERR_ARG_OUTOFRANGE,
107 "%s needs %" PetscInt64_FMT
" entries, beyond the %" PetscInt64_FMT
" this PETSc's %d-byte PetscInt "
108 "can index; use a PICurv built on a PETSc configured with --with-64-bit-indices.",
109 object, entries, (PetscInt64)PETSC_MAX_INT, (
int)
sizeof(PetscInt));
111 PetscFunctionReturn(0);
124 for (
int index = 1; index < argc; ++index) {
125 if (!strcmp(argv[index],
"--version") || !strcmp(argv[index],
"-version")) {
150 if (seconds_out) *seconds_out = 0.0;
154 parsed_value = strtod(text, &endptr);
155 if (endptr == text || errno == ERANGE || !isfinite(parsed_value) || parsed_value <= 0.0) {
160 while (*endptr !=
'\0' && isspace((
unsigned char)*endptr)) {
165 if (seconds_out) *seconds_out = (PetscReal)parsed_value;
179 PetscInt history_capacity = 0;
181 PetscFunctionBeginUser;
183 if (!simCtx) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"SimCtx cannot be NULL.");
187 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE,
188 "Multigrid hierarchy must exist before initializing solution convergence storage.");
193 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE,
194 "Finest-level UserCtx must exist before initializing solution convergence storage.");
200 for (PetscInt bi = 0; bi < simCtx->
block_number; ++bi) {
206 PetscCall(VecDuplicate(user[bi].Ucat, &user[bi].solutionConvergencePeriodicUcatRef[phase]));
207 PetscCall(VecSet(user[bi].solutionConvergencePeriodicUcatRef[phase], 0.0));
208 PetscCall(VecDuplicate(user[bi].P, &user[bi].solutionConvergencePeriodicPRef[phase]));
209 PetscCall(VecSet(user[bi].solutionConvergencePeriodicPRef[phase], 0.0));
221 PetscFunctionReturn(0);
234 PetscFunctionBeginUser;
246 for (PetscInt bi = 0; bi < simCtx->
block_number; ++bi) {
247 if (user[bi].solutionConvergencePeriodicUcatRef) {
249 if (user[bi].solutionConvergencePeriodicUcatRef[phase]) {
250 PetscCall(VecDestroy(&user[bi].solutionConvergencePeriodicUcatRef[phase]));
253 PetscCall(PetscFree(user[bi].solutionConvergencePeriodicUcatRef));
256 if (user[bi].solutionConvergencePeriodicPRef) {
258 if (user[bi].solutionConvergencePeriodicPRef[phase]) {
259 PetscCall(VecDestroy(&user[bi].solutionConvergencePeriodicPRef[phase]));
262 PetscCall(PetscFree(user[bi].solutionConvergencePeriodicPRef));
279 PetscFunctionReturn(0);
290 PetscFunctionBeginUser;
292 PetscCheck(config != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
293 "LES configuration destination cannot be NULL.");
321 PetscFunctionReturn(0);
345 char directions[8] =
"";
346 PetscBool found = PETSC_FALSE;
348 PetscFunctionBeginUser;
351 PetscCall(PetscOptionsGetReal(NULL, NULL,
"-les_constant_cs", &config->
constant_cs, NULL));
352 PetscCall(PetscOptionsGetReal(NULL, NULL,
"-les_vreman_coefficient", &config->
vreman_coefficient, NULL));
353 PetscCall(PetscOptionsGetReal(NULL, NULL,
"-les_wale_coefficient", &config->
wale_coefficient, NULL));
354 PetscCall(PetscOptionsGetInt(NULL, NULL,
"-les_dynamic_frequency", &config->
dynamic_frequency, NULL));
357 PetscCall(PetscOptionsGetInt(NULL, NULL,
"-les_filter_width", &selector, NULL));
359 PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE,
360 "-les_filter_width must be 0 (cube_root_volume), 1 (geometric_mean), 2 (max_edge), or 3 (scotti); received %" PetscInt_FMT
".",
365 PetscCall(PetscOptionsGetInt(NULL, NULL,
"-les_test_filter_kernel", &selector, NULL));
367 PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE,
368 "-les_test_filter_kernel must be 0 (volume_weighted_box) or 1 (simpson_ik); received %" PetscInt_FMT
".",
372 PetscCall(PetscOptionsGetReal(NULL, NULL,
"-les_test_filter_width_ratio",
375 "-les_test_filter_width_ratio must exceed 1; a test filter no wider than the grid "
376 "filter leaves the dynamic procedure nothing to measure. Received %g.",
380 PetscCall(PetscOptionsGetInt(NULL, NULL,
"-les_averaging_mode", &selector, NULL));
382 PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE,
383 "-les_averaging_mode must be 0 (local), 1 (homogeneous), or 2 (global); received %" PetscInt_FMT
".",
389 PetscCall(PetscOptionsGetString(NULL, NULL,
"-les_averaging_directions",
390 directions,
sizeof(directions), &found));
392 for (
size_t index = 0; directions[index] !=
'\0'; index++) {
393 switch (directions[index]) {
398 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE,
399 "-les_averaging_directions accepts only the characters i, j, and k; "
400 "received '%s'.", directions);
406 PetscCall(PetscOptionsGetInt(NULL, NULL,
"-les_clip_mode", &selector, NULL));
408 PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE,
409 "-les_clip_mode must be 0 (clamp), 1 (clip_negative), or 2 (none); received %" PetscInt_FMT
".",
413 PetscCall(PetscOptionsGetReal(NULL, NULL,
"-les_clip_max_cs", &config->
max_cs, NULL));
414 PetscCall(PetscOptionsGetReal(NULL, NULL,
"-les_min_viscosity_ratio",
416 PetscCall(PetscOptionsGetReal(NULL, NULL,
"-les_yoshizawa_ci", &config->
yoshizawa_ci, NULL));
417 PetscCall(PetscOptionsGetBool(NULL, NULL,
"-les_diagnostics",
419 PetscCall(PetscOptionsGetInt(NULL, NULL,
"-les_diagnostics_cadence",
422 PetscCheck(config->
dynamic_frequency > 0, PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE,
423 "-les_dynamic_frequency must be positive; received %" PetscInt_FMT
".",
425 PetscCheck(config->
constant_cs >= 0.0, PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE,
426 "-les_constant_cs must be nonnegative; received %g.", (
double)config->
constant_cs);
427 PetscCheck(config->
vreman_coefficient >= 0.0, PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE,
428 "-les_vreman_coefficient must be nonnegative; received %g.",
430 PetscCheck(config->
wale_coefficient >= 0.0, PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE,
431 "-les_wale_coefficient must be nonnegative; received %g.",
433 PetscCheck(config->
max_cs >= 0.0, PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE,
434 "-les_clip_max_cs must be nonnegative; received %g.", (
double)config->
max_cs);
436 "-les_min_viscosity_ratio must be nonnegative; received %g.",
439 "-les_diagnostics_cadence must be positive; received %" PetscInt_FMT
".",
443 PetscFunctionReturn(0);
459 char control_filename[PETSC_MAX_PATH_LEN] =
"";
460 PetscBool control_flg;
461 PetscBool particle_console_output_freq_flg = PETSC_FALSE;
463 PetscFunctionBeginUser;
468 ierr = PetscNew(p_simCtx); CHKERRQ(ierr);
484 strcpy(simCtx->
log_dir,
"logs");
498 simCtx->
MHV=0; simCtx->
LV=0;
551 simCtx->
max_angle = -54. * 3.1415926 / 180.;
561 strcpy(simCtx->
grid_file,
"config/grid.run");
567 ierr = PetscMalloc1(1, &simCtx->
bcs_files); CHKERRQ(ierr);
568 ierr = PetscStrallocpy(
"config/bcs.run", &simCtx->
bcs_files[0]); CHKERRQ(ierr);
626 simCtx->
ibm = NULL; simCtx->
ibmv = NULL; simCtx->
fsi = NULL;
629 strcpy(simCtx->
allowedFile,
"config/whitelist.run");
630 simCtx->
useCfg = PETSC_FALSE;
669 ierr = PetscNew(&simCtx->
pps); CHKERRQ(ierr);
673 ierr = MPI_Comm_rank(PETSC_COMM_WORLD, &simCtx->
rank); CHKERRQ(ierr);
674 ierr = MPI_Comm_size(PETSC_COMM_WORLD, &simCtx->
size); CHKERRQ(ierr);
677 ierr = PetscOptionsGetString(NULL, NULL,
"-control_file", control_filename,
sizeof(control_filename), &control_flg); CHKERRQ(ierr);
680 if (!control_flg || strlen(control_filename) == 0) {
681 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
682 "\n\n*** MANDATORY ARGUMENT MISSING ***\n"
683 "The -control_file argument was not provided.\n"
684 "This program must be launched with a configuration file.\n"
685 "Example: mpiexec -n 4 ./simulator -control_file /path/to/your/config.control\n"
686 "This is typically handled automatically by the 'picurv' script.\n");
690 LOG(
GLOBAL,
LOG_INFO,
"Loading mandatory configuration from: %s\n", control_filename);
691 ierr = PetscOptionsInsertFile(PETSC_COMM_WORLD, NULL, control_filename, PETSC_FALSE);
692 if (ierr == PETSC_ERR_FILE_OPEN) {
693 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_FILE_OPEN,
"The specified control file was not found or could not be opened: %s", control_filename);
698 PetscBool legacy_averaging = PETSC_FALSE;
699 ierr = PetscOptionsHasName(NULL, NULL,
"-averaging", &legacy_averaging); CHKERRQ(ierr);
700 PetscCheck(!legacy_averaging, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
701 "Legacy -averaging was removed. Use instantaneous output and offline "
702 "postprocessing until the replacement field-statistics pipeline is available.");
708 ierr = PetscOptionsGetString(NULL, NULL,
"-whitelist_config_file", simCtx->
allowedFile, PETSC_MAX_PATH_LEN, &simCtx->
useCfg); CHKERRQ(ierr);
714 PetscPrintf(PETSC_COMM_SELF,
"[%s] WARNING: Failed to load allowed functions from '%s'. Falling back to default list.\n", __func__, simCtx->
allowedFile);
715 simCtx->
useCfg = PETSC_FALSE;
718 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
719 "Whitelist config file '%s' is empty. Omit -whitelist_config_file to use the default allow-list, or list at least one function.",
727 ierr = PetscStrallocpy(
"main", &simCtx->
allowedFuncs[0]); CHKERRQ(ierr);
728 ierr = PetscStrallocpy(
"CreateSimulationContext", &simCtx->
allowedFuncs[1]); CHKERRQ(ierr);
740 ierr = PetscOptionsGetBool(NULL, NULL,
"-profiling_final_summary", &simCtx->
profilingFinalSummary, NULL); CHKERRQ(ierr);
741 ierr = PetscOptionsGetBool(NULL, NULL,
"-picurv_verify_ghost_updates", &simCtx->
verifyGhostUpdates, NULL); CHKERRQ(ierr);
745 PetscPrintf(PETSC_COMM_SELF,
"[%s] WARNING: Unknown profiling timestep mode '%s'. Falling back to 'selected'.\n", __func__, simCtx->
profilingTimestepMode);
754 PetscPrintf(PETSC_COMM_SELF,
"[%s] WARNING: Failed to load selected profiling functions from '%s'. Falling back to default list.\n", __func__, simCtx->
profilingSelectedFuncsFile);
773 PetscBool found = PETSC_FALSE;
775 ierr = PetscOptionsGetStringArray(NULL, NULL,
"-profiling_helpers", simCtx->
profilingHelpers, &nmax, &found); CHKERRQ(ierr);
792 ierr = PetscOptionsGetInt(NULL, NULL,
"-start_step", &simCtx->
StartStep, NULL); CHKERRQ(ierr);
793 ierr = PetscOptionsGetInt(NULL,NULL,
"-totalsteps", &simCtx->
StepsToRun, NULL); CHKERRQ(ierr);
794 ierr = PetscOptionsGetBool(NULL, NULL,
"-only_setup", &simCtx->
OnlySetup, NULL); CHKERRQ(ierr);
795 ierr = PetscOptionsGetBool(NULL, NULL,
"-continue_mode", &simCtx->
continueMode, NULL); CHKERRQ(ierr);
800 ierr = PetscOptionsGetBool(NULL, NULL,
"-field_statistics_continue",
802 ierr = PetscOptionsGetReal(NULL, NULL,
"-dt", &simCtx->
dt, NULL); CHKERRQ(ierr);
803 ierr = PetscOptionsGetInt(NULL, NULL,
"-tio", &simCtx->
tiout, NULL); CHKERRQ(ierr);
806 PetscBool write_initial = PETSC_TRUE, write_final = PETSC_TRUE;
807 ierr = PetscOptionsGetBool(NULL, NULL,
"-write_initial_checkpoint", &write_initial, NULL); CHKERRQ(ierr);
808 ierr = PetscOptionsGetBool(NULL, NULL,
"-write_final_checkpoint", &write_final, NULL); CHKERRQ(ierr);
812 ierr = PetscOptionsGetInt(NULL, NULL,
"-particle_console_output_freq", &simCtx->
particleConsoleOutputFreq, &particle_console_output_freq_flg); CHKERRQ(ierr);
813 if (!particle_console_output_freq_flg) {
817 ierr = PetscOptionsGetString(NULL,NULL,
"-output_dir",simCtx->
output_dir,
sizeof(simCtx->
output_dir),NULL);CHKERRQ(ierr);
818 ierr = PetscOptionsGetString(NULL,NULL,
"-restart_dir",simCtx->
restart_dir,
sizeof(simCtx->
restart_dir),NULL);CHKERRQ(ierr);
819 ierr = PetscOptionsGetString(NULL,NULL,
"-log_dir",simCtx->
log_dir,
sizeof(simCtx->
log_dir),NULL);CHKERRQ(ierr);
820 ierr = PetscOptionsGetString(NULL,NULL,
"-analysis_dir",simCtx->
analysis_dir,
sizeof(simCtx->
analysis_dir),NULL);CHKERRQ(ierr);
821 ierr = PetscOptionsGetBool(NULL, NULL,
"-walltime_guard_enabled", &simCtx->
walltimeGuardEnabled, NULL); CHKERRQ(ierr);
822 ierr = PetscOptionsGetInt(NULL, NULL,
"-walltime_guard_warmup_steps", &simCtx->
walltimeGuardWarmupSteps, NULL); CHKERRQ(ierr);
823 ierr = PetscOptionsGetReal(NULL, NULL,
"-walltime_guard_multiplier", &simCtx->
walltimeGuardMultiplier, NULL); CHKERRQ(ierr);
824 ierr = PetscOptionsGetBool(NULL, NULL,
"-runtime_memory_log_enabled", &simCtx->
runtimeMemoryLogEnabled, NULL); CHKERRQ(ierr);
825 ierr = PetscOptionsGetReal(NULL, NULL,
"-walltime_guard_min_seconds", &simCtx->
walltimeGuardMinSeconds, NULL); CHKERRQ(ierr);
826 ierr = PetscOptionsGetReal(NULL, NULL,
"-walltime_guard_estimator_alpha", &simCtx->
walltimeGuardEstimatorAlpha, NULL); CHKERRQ(ierr);
829 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
"Invalid value for -walltime_guard_warmup_steps: %" PetscInt_FMT
". Must be > 0.", simCtx->
walltimeGuardWarmupSteps);
832 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
"Invalid value for -walltime_guard_multiplier: %.6f. Must be in (0, 5].", (
double)simCtx->
walltimeGuardMultiplier);
835 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
"Invalid value for -walltime_guard_min_seconds: %.6f. Must be > 0.", (
double)simCtx->
walltimeGuardMinSeconds);
838 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
"Invalid value for -walltime_guard_estimator_alpha: %.6f. Must be in (0, 1].", (
double)simCtx->
walltimeGuardEstimatorAlpha);
842 SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_ARG_WRONG,
"Invalid value for -euler_field_source. Must be 'load','analytical' or 'solve'. You provided '%s'.",simCtx->
eulerianSource);
847 ierr = PetscOptionsGetInt(NULL, NULL,
"-imm", &simCtx->
immersed, NULL); CHKERRQ(ierr);
848 ierr = PetscOptionsGetInt(NULL, NULL,
"-fsi", &simCtx->
movefsi, NULL); CHKERRQ(ierr);
849 ierr = PetscOptionsGetInt(NULL, NULL,
"-rfsi", &simCtx->
rotatefsi, NULL); CHKERRQ(ierr);
850 ierr = PetscOptionsGetInt(NULL, NULL,
"-inv", &simCtx->
invicid, NULL); CHKERRQ(ierr);
851 ierr = PetscOptionsGetInt(NULL, NULL,
"-TwoD", &simCtx->
TwoD, NULL); CHKERRQ(ierr);
852 ierr = PetscOptionsGetInt(NULL, NULL,
"-mframe", &simCtx->
moveframe, NULL); CHKERRQ(ierr);
853 ierr = PetscOptionsGetInt(NULL, NULL,
"-rframe", &simCtx->
rotateframe, NULL); CHKERRQ(ierr);
864 "Immersed boundaries and moving bodies (-imm, -fsi, -rfsi) are planned, not implemented.");
866 "Moving and rotating reference frames (-mframe, -rframe) are planned, not implemented: "
867 "their convection branch is absent, so the convective term would be dropped.");
871 ierr = PetscOptionsGetInt(NULL, NULL,
"-mhv", &simCtx->
MHV, NULL); CHKERRQ(ierr);
872 ierr = PetscOptionsGetInt(NULL, NULL,
"-lv", &simCtx->
LV, NULL); CHKERRQ(ierr);
875 PetscCheck(!simCtx->
MHV && !simCtx->
LV, PETSC_COMM_WORLD, PETSC_ERR_SUP,
876 "The -mhv/-lv immersed-body flux corrections need immersed boundaries, which are planned, not implemented.");
877 ierr = PetscOptionsGetReal(NULL,NULL,
"-driven_flow_initial_force",&simCtx->
drivingForceMagnitude,NULL);CHKERRQ(ierr);
878 ierr = PetscOptionsGetReal(NULL,NULL,
"-driven_flow_scaling_factor",&simCtx->
forceScalingFactor,NULL);CHKERRQ(ierr);
881 char mom_solver_type_char[PETSC_MAX_PATH_LEN];
882 char solution_convergence_mode_char[PETSC_MAX_PATH_LEN];
883 PetscBool mom_solver_type_flg = PETSC_FALSE;
884 PetscBool solution_convergence_mode_flg = PETSC_FALSE;
885 ierr = PetscOptionsGetString(NULL, NULL,
"-mom_solver_type", mom_solver_type_char,
sizeof(mom_solver_type_char), &mom_solver_type_flg); CHKERRQ(ierr);
886 ierr = PetscOptionsGetInt(NULL, NULL,
"-mom_max_pseudo_steps", &simCtx->
mom_max_pseudo_steps, NULL); CHKERRQ(ierr);
887 ierr = PetscOptionsGetInt(NULL, NULL,
"-mom_max_unconverged_steps", &simCtx->
mom_max_unconverged_steps, NULL); CHKERRQ(ierr);
889 "-mom_max_unconverged_steps must be 0 (never stop) or a positive step count; received %" PetscInt_FMT
".",
891 ierr = PetscOptionsGetReal(NULL, NULL,
"-mom_atol", &simCtx->
mom_atol, NULL); CHKERRQ(ierr);
892 ierr = PetscOptionsGetReal(NULL, NULL,
"-mom_rtol", &simCtx->
mom_rtol, NULL); CHKERRQ(ierr);
893 ierr = PetscOptionsGetReal(NULL, NULL,
"-mom_resid_atol", &simCtx->
mom_resid_atol, NULL); CHKERRQ(ierr);
894 ierr = PetscOptionsGetReal(NULL, NULL,
"-mom_resid_rtol", &simCtx->
mom_resid_rtol, NULL); CHKERRQ(ierr);
895 ierr = PetscOptionsGetReal(NULL, NULL,
"-imp_stol", &simCtx->
imp_stol, NULL); CHKERRQ(ierr);
896 ierr = PetscOptionsGetInt(NULL, NULL,
"-central", &simCtx->
central, NULL); CHKERRQ(ierr);
897 ierr = PetscOptionsGetString(NULL, NULL,
"-solution_convergence_mode",
898 solution_convergence_mode_char,
sizeof(solution_convergence_mode_char),
899 &solution_convergence_mode_flg); CHKERRQ(ierr);
900 ierr = PetscOptionsGetBool(NULL, NULL,
"-solution_convergence_enabled", &simCtx->
solutionConvergenceEnabled, NULL); CHKERRQ(ierr);
910 if (mom_solver_type_flg) {
911 if(strcmp(mom_solver_type_char,
"DUALTIME_PICARD_JAMESON_RK") == 0 ||
912 strcmp(mom_solver_type_char,
"DUALTIME_PICARD_RK4") == 0) {
914 }
else if (strcmp(mom_solver_type_char,
"EXPLICIT_RK") == 0) {
916 }
else if (strcmp(mom_solver_type_char,
"newton_krylov") == 0) {
919 LOG(
GLOBAL,
LOG_ERROR,
"Invalid value for -mom_solver_type: '%s'. Valid options are: 'DUALTIME_PICARD_JAMESON_RK', 'EXPLICIT_RK', 'newton_krylov'.\n", mom_solver_type_char);
920 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
"Invalid value for -mom_solver_type: '%s'.", mom_solver_type_char);
924 if (solution_convergence_mode_flg) {
925 if (strcmp(solution_convergence_mode_char,
"STEADY_DETERMINISTIC") == 0) {
927 }
else if (strcmp(solution_convergence_mode_char,
"PERIODIC_DETERMINISTIC") == 0) {
929 }
else if (strcmp(solution_convergence_mode_char,
"STATISTICAL_STEADY") == 0) {
931 }
else if (strcmp(solution_convergence_mode_char,
"TRANSIENT") == 0) {
934 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
935 "Invalid value for -solution_convergence_mode: '%s'.", solution_convergence_mode_char);
941 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
942 "solution convergence mode PERIODIC_DETERMINISTIC requires -solution_convergence_period_steps > 0.");
946 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
947 "solution convergence mode STATISTICAL_STEADY requires -solution_convergence_window_steps > 0.");
951 ierr = PetscOptionsGetInt(NULL, NULL,
"-mg_level", &simCtx->
mglevels, NULL); CHKERRQ(ierr);
960 ierr = PetscOptionsGetInt(NULL, NULL,
"-mg_pre_it", &simCtx->
mg_preItr, NULL); CHKERRQ(ierr);
961 ierr = PetscOptionsGetInt(NULL, NULL,
"-mg_post_it", &simCtx->
mg_poItr, NULL); CHKERRQ(ierr);
964 ierr = PetscOptionsGetInt(NULL, NULL,
"-poisson", &simCtx->
poisson, NULL); CHKERRQ(ierr);
965 ierr = PetscOptionsGetReal(NULL, NULL,
"-ren", &simCtx->
ren, NULL); CHKERRQ(ierr);
966 ierr = PetscOptionsGetReal(NULL, NULL,
"-pseudo_cfl", &simCtx->
pseudo_cfl, NULL); CHKERRQ(ierr);
967 ierr = PetscOptionsGetReal(NULL, NULL,
"-max_pseudo_cfl", &simCtx->
max_pseudo_cfl, NULL); CHKERRQ(ierr);
968 ierr = PetscOptionsGetReal(NULL, NULL,
"-min_pseudo_cfl", &simCtx->
min_pseudo_cfl, NULL); CHKERRQ(ierr);
970 ierr = PetscOptionsGetReal(NULL, NULL,
"-pseudo_cfl_growth_factor", &simCtx->
pseudo_cfl_growth_factor, NULL); CHKERRQ(ierr);
974 ierr = PetscOptionsGetBool(NULL, NULL,
"-no_pseudo_cfl_backtrack", &simCtx->
no_pseudo_cfl_backtrack, NULL); CHKERRQ(ierr);
975 ierr = PetscOptionsGetReal(NULL, NULL,
"-mom_ratio_ema_alpha", &simCtx->
mom_ratio_ema_alpha, NULL); CHKERRQ(ierr);
979 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE,
980 "Pseudo-CFL controls require 0 < minimum <= initial <= maximum.");
986 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE,
987 "Pseudo-CFL controls require growth_factor >= 1, 0 < reduction_factor < 1, and noise allowance >= 1.");
990 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE,
991 "-mom_ratio_ema_alpha must be in [0, 1].");
994 ierr = PetscOptionsGetBool(NULL, NULL,
"-mom_nk_pic_monitor", &simCtx->
mom_nk_monitor_history, NULL); CHKERRQ(ierr);
997 ierr = PetscOptionsGetInt(NULL, NULL,
"-ic_field", &ic_field, NULL); CHKERRQ(ierr);
1003 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE,
1004 "Invalid value for -ic_field. Expected 0 (Ucat) or 1 (Ucont), got %d.",
1012 ierr = PetscOptionsGetReal(NULL,NULL,
"-schmidt_number",&simCtx->
schmidt_number,NULL);CHKERRQ(ierr);
1014 ierr = PetscOptionsGetReal(NULL,NULL,
"-iem_constant",&simCtx->
iem_constant,NULL);CHKERRQ(ierr);
1017 PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE,
1018 "-iem_constant must be a non-negative finite number (got %g).", (
double)simCtx->
iem_constant);
1019 ierr = PetscOptionsGetReal(NULL,NULL,
"-wall_roughness",&simCtx->
wall_roughness_height,NULL);CHKERRQ(ierr);
1028 ierr = PetscOptionsGetInt(NULL, NULL,
"-nblk", &simCtx->
block_number, NULL); CHKERRQ(ierr);
1032 PetscCheck(simCtx->
block_number == 1, PETSC_COMM_WORLD, PETSC_ERR_SUP,
1033 "Multi-block domains are planned, not implemented: blocks are never coupled (got -nblk %" PetscInt_FMT
").",
1035 ierr = PetscOptionsGetInt(NULL, NULL,
"-inlet", &simCtx->
inletprofile, NULL); CHKERRQ(ierr);
1037 ierr = PetscOptionsGetBool(NULL, NULL,
"-grid", &simCtx->
generate_grid, NULL); CHKERRQ(ierr);
1038 ierr = PetscOptionsGetString(NULL, NULL,
"-grid_file", simCtx->
grid_file, PETSC_MAX_PATH_LEN, NULL); CHKERRQ(ierr);
1039 ierr = PetscOptionsGetInt(NULL, NULL,
"-da_processors_x", &simCtx->
da_procs_x, NULL); CHKERRQ(ierr);
1040 ierr = PetscOptionsGetInt(NULL, NULL,
"-da_processors_y", &simCtx->
da_procs_y, NULL); CHKERRQ(ierr);
1041 ierr = PetscOptionsGetInt(NULL, NULL,
"-da_processors_z", &simCtx->
da_procs_z, NULL); CHKERRQ(ierr);
1044 char file_list_str[PETSC_MAX_PATH_LEN * 10];
1046 ierr = PetscOptionsGetString(NULL, NULL,
"-bcs_files", file_list_str,
sizeof(file_list_str), &bcs_flg); CHKERRQ(ierr);
1052 ierr = PetscFree(simCtx->
bcs_files[0]); CHKERRQ(ierr);
1053 ierr = PetscFree(simCtx->
bcs_files); CHKERRQ(ierr);
1060 ierr = PetscStrallocpy(file_list_str, &str_copy); CHKERRQ(ierr);
1063 token = strtok(str_copy,
",");
1066 token = strtok(NULL,
",");
1068 ierr = PetscFree(str_copy); CHKERRQ(ierr);
1072 ierr = PetscStrallocpy(file_list_str, &str_copy); CHKERRQ(ierr);
1073 token = strtok(str_copy,
",");
1075 ierr = PetscStrallocpy(token, &simCtx->
bcs_files[i]); CHKERRQ(ierr);
1076 token = strtok(NULL,
",");
1078 ierr = PetscFree(str_copy); CHKERRQ(ierr);
1086 PetscInt temp_les_model = (PetscInt)simCtx->
les;
1087 ierr = PetscOptionsGetInt(NULL, NULL,
"-les", &temp_les_model, NULL); CHKERRQ(ierr);
1088 PetscCheck(temp_les_model >=
NO_LES_MODEL && temp_les_model <=
WALE, PETSC_COMM_WORLD,
1089 PETSC_ERR_ARG_OUTOFRANGE,
1090 "-les must be 0 (none), 1 (constant_smagorinsky), 2 (dynamic_smagorinsky), "
1091 "3 (vreman), or 4 (wale); received %" PetscInt_FMT
".", temp_les_model);
1098 PetscInt requested_rans = 0;
1099 ierr = PetscOptionsGetInt(NULL, NULL,
"-rans", &requested_rans, NULL); CHKERRQ(ierr);
1100 PetscCheck(requested_rans == 0, PETSC_COMM_WORLD, PETSC_ERR_SUP,
1101 "RANS closures (-rans) are planned, not implemented: no transport equation is "
1102 "solved for them. Use an LES closure, or run laminar.");
1104 ierr = PetscOptionsGetInt(NULL, NULL,
"-wallfunction", &simCtx->
wallfunction, NULL); CHKERRQ(ierr);
1105 ierr = PetscOptionsGetBool(NULL, NULL,
"-inflow_fluctuations", &simCtx->
inflowFluctuations, NULL); CHKERRQ(ierr);
1107 PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE,
1108 "-wallfunction must be 0 (none), 1 (log_law), 2 (werner), or 3 (cabot); received %" PetscInt_FMT
".",
1110 ierr = PetscOptionsGetInt(NULL, NULL,
"-les_gradient_model", &simCtx->
les_gradient_model, NULL); CHKERRQ(ierr);
1115 ierr = PetscOptionsGetInt(NULL, NULL,
"-numParticles", &simCtx->
np, NULL); CHKERRQ(ierr);
1119 PetscInt widest = 1;
1123 widest = PetscMax(widest, descriptor->
components);
1126 ierr = PetscSNPrintf(
object,
sizeof(
object),
"-numParticles %" PetscInt_FMT
" (a %" PetscInt_FMT
1127 "-component particle field; at most %" PetscInt_FMT
" particles here)",
1128 simCtx->
np, widest, (PetscInt)(PETSC_MAX_INT / widest)); CHKERRQ(ierr);
1132 ierr = PetscOptionsGetInt(NULL, NULL,
"-pinit", &temp_pinit, NULL); CHKERRQ(ierr);
1135 ierr = PetscOptionsGetInt(NULL, NULL,
"-interpolation_method", &temp_interp, NULL); CHKERRQ(ierr);
1138 ierr = PetscOptionsGetReal(NULL, NULL,
"-psrc_x", &simCtx->
psrc_x, NULL); CHKERRQ(ierr);
1139 ierr = PetscOptionsGetReal(NULL, NULL,
"-psrc_y", &simCtx->
psrc_y, NULL); CHKERRQ(ierr);
1140 ierr = PetscOptionsGetReal(NULL, NULL,
"-psrc_z", &simCtx->
psrc_z, NULL); CHKERRQ(ierr);
1147 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
"Invalid value for -particle_restart_mode. Must be 'load' or 'init'. You provided '%s'.", simCtx->
particleRestartMode);
1149 ierr = PetscOptionsGetInt(NULL, NULL,
"-particle_random_seed", &simCtx->
particleRandomSeed, NULL); CHKERRQ(ierr);
1150 PetscCheck(simCtx->
particleRandomSeed >= 0, PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE,
1151 "-particle_random_seed must be non-negative (got %" PetscInt_FMT
").", simCtx->
particleRandomSeed);
1152 ierr = PetscOptionsGetInt(NULL, NULL,
"-source_random_seed", &simCtx->
sourceRandomSeed, NULL); CHKERRQ(ierr);
1153 PetscCheck(simCtx->
sourceRandomSeed >= 0, PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE,
1154 "-source_random_seed must be non-negative (got %" PetscInt_FMT
").", simCtx->
sourceRandomSeed);
1158 "Particle field initial values are configured but the run has no particles.");
1160 PETSC_ERR_ARG_WRONG,
1161 "Particle field initial values cannot be combined with the verification scalar source, "
1162 "which prescribes Psi at every step.");
1168 ierr = PetscOptionsGetInt(NULL, NULL,
"-logfreq", &simCtx->
LoggingFrequency, NULL); CHKERRQ(ierr);
1172 PetscBool found = PETSC_FALSE;
1173 ierr = PetscOptionsGetIntArray(NULL, NULL,
"-picurv_trace_particles", ids, &n, &found); CHKERRQ(ierr);
1174 if (found && n > 0) {
1177 ierr = PetscMalloc1(n, &simCtx->
tracePIDs); CHKERRQ(ierr);
1178 for (PetscInt t = 0; t < n; ++t) {
1179 PetscCheck(ids[t] >= 0, PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE,
1180 "-picurv_trace_particles: particle IDs are non-negative (got %" PetscInt_FMT
").", ids[t]);
1181 simCtx->
tracePIDs[t] = (PetscInt64)ids[t];
1183 ierr = PetscSortInt64(n, simCtx->
tracePIDs); CHKERRQ(ierr);
1185 for (PetscInt t = 1; t < n; ++t) {
1192 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_INCOMP,
"Number of BC files (%" PetscInt_FMT
") does not match number of blocks (%" PetscInt_FMT
"). Use -bcs_files \"file1.dat,file2.dat,...\".", simCtx->
num_bcs_files, simCtx->
block_number);
1198 ierr = PetscOptionsGetString(NULL,NULL,
"-postprocessing_config_file",simCtx->
PostprocessingControlFile,PETSC_MAX_PATH_LEN,NULL); CHKERRQ(ierr);
1210 for (PetscInt i = 0; i < simCtx->
nAllowed; ++i) {
1218 if (simCtx->
tiout > 0) {
1238 ierr = PetscLogDefaultBegin(); CHKERRQ(ierr);
1239 ierr = PetscMemorySetGetMaximumUsage(); CHKERRQ(ierr);
1244 PetscFunctionReturn(0);
1252 PetscErrorCode ierr;
1253 char tmp_path[PETSC_MAX_PATH_LEN];
1258 PetscFunctionBeginUser;
1263 if (len >=
sizeof(tmp_path)) {
1264 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ,
"Path is too long to process: %s", path);
1266 strcpy(tmp_path, path);
1269 if (tmp_path[len - 1] ==
'/') {
1270 tmp_path[len - 1] = 0;
1274 for (p = tmp_path + 1; *p; p++) {
1279 ierr = PetscTestDirectory(tmp_path,
'r', &exists); CHKERRQ(ierr);
1281 ierr = PetscMkdir(tmp_path); CHKERRQ(ierr);
1289 ierr = PetscTestDirectory(tmp_path,
'r', &exists); CHKERRQ(ierr);
1291 ierr = PetscMkdir(tmp_path); CHKERRQ(ierr);
1295 PetscFunctionReturn(0);
1312 char a[PETSC_MAX_PATH_LEN], b[PETSC_MAX_PATH_LEN];
1313 const char *source[2];
1318 source[0] = first; source[1] = second;
1319 target[0] = a; target[1] = b;
1321 for (which = 0; which < 2; ++which) {
1322 const char *cursor = source[which];
1323 char *out = target[which];
1326 while (*cursor && used + 1 < PETSC_MAX_PATH_LEN) {
1328 while (*cursor ==
'/') ++cursor;
1329 segment = strcspn(cursor,
"/");
1330 if (segment == 0)
break;
1331 if (segment == 1 && cursor[0] ==
'.') { cursor += segment;
continue; }
1332 if (used) out[used++] =
'/';
1333 if (used + segment + 1 >= PETSC_MAX_PATH_LEN)
break;
1334 memcpy(out + used, cursor, segment);
1343 if (strncmp(a, b, strlen(b)) == 0 && a[strlen(b)] ==
'/') {
PROFILE_FUNCTION_END;
return PETSC_TRUE; }
1344 if (strncmp(b, a, strlen(a)) == 0 && b[strlen(a)] ==
'/') {
PROFILE_FUNCTION_END;
return PETSC_TRUE; }
1368 for (cursor = value; *cursor; ++cursor) {
1370 if (*cursor ==
'"' || *cursor ==
'\'' || *cursor ==
'#') {
PROFILE_FUNCTION_END;
return PETSC_FALSE; }
1385 const char *cursor = value;
1396 while (*cursor ==
'/') ++cursor;
1397 if (!*cursor)
break;
1398 segment = strcspn(cursor,
"/");
1399 if (!(segment == 1 && cursor[0] ==
'.')) {
1445 const char *cursor = value;
1447 PetscBool absolute = (PetscBool)(value[0] ==
'/');
1454 while (*cursor ==
'/') cursor++;
1455 if (!*cursor)
break;
1456 slash = strchr(cursor,
'/');
1457 len = slash ? (size_t)(slash - cursor) : strlen(cursor);
1459 if (len == 1 && cursor[0] ==
'.') {
1461 }
else if (len == 2 && cursor[0] ==
'.' && cursor[1] ==
'.') {
1462 char *last = strrchr(stack,
'/');
1463 if (last) { *last =
'\0'; used = strlen(stack); }
1464 else if (used) { stack[0] =
'\0'; used = 0; }
1467 stack[used++] =
'/';
1468 memcpy(stack + used, cursor, len);
1478 strcpy(out, used ? stack :
"/");
1480 const char *relative = used ? stack + 1 :
".";
1482 strcpy(out, relative);
1504 char *out,
size_t size,
char *scratch)
1511 char *absolute = scratch;
1512 char *normalized = scratch + PETSC_MAX_PATH_LEN;
1513 char *probe = scratch + 2 * PETSC_MAX_PATH_LEN;
1514 char *resolved = scratch + 3 * PETSC_MAX_PATH_LEN;
1515 char *lexical = scratch + 4 * PETSC_MAX_PATH_LEN;
1517 if (value[0] ==
'/') {
1518 if ((
size_t)snprintf(absolute, PETSC_MAX_PATH_LEN,
"%s", value) >= PETSC_MAX_PATH_LEN)
1521 if ((
size_t)snprintf(absolute, PETSC_MAX_PATH_LEN,
"%s/%s", cwd, value)
1522 >= PETSC_MAX_PATH_LEN)
1528 if ((
size_t)snprintf(probe, PETSC_MAX_PATH_LEN,
"%s", normalized) >= PETSC_MAX_PATH_LEN)
1534 if (realpath(probe, resolved)) {
1535 size_t consumed = strlen(probe);
1536 const char *tail = normalized + consumed;
1537 if ((
size_t)snprintf(out, size,
"%s%s", resolved, tail) >= size) {
PROFILE_FUNCTION_END;
return PETSC_FALSE; }
1542 last = strrchr(probe,
'/');
1544 if (last == probe) { probe[1] =
'\0'; }
1545 else { *last =
'\0'; }
1546 if (strcmp(probe,
"/") == 0 && !realpath(probe, resolved)) {
PROFILE_FUNCTION_END;
return PETSC_FALSE; }
1560 size_t len = strlen(ancestor);
1565 return (PetscBool)(strncmp(path, ancestor, len) == 0 && path[len] ==
'/');
1584 const char **reason)
1589 char *scratch = NULL;
1590 char *cwd, *resolved, *cwd_real;
1593 *reason =
"unknown";
1596 if (!log_dir || log_dir[0] ==
'\0') {
1597 *reason =
"is empty";
1602 *reason =
"contains whitespace, a quote, or a comment marker";
1607 *reason =
"collides with a reserved run directory";
1612 *reason =
"overlaps the solver output directory";
1623 if (log_dir[0] ==
'~') {
1624 *reason =
"starts with '~', which nothing expands - the options file is read by "
1625 "PETSc, not by a shell, so this would name a literal '~' directory "
1626 "inside the run. Give a real absolute path. This cannot be overridden";
1632 if (log_dir[0] !=
'/' &&
1633 (strcmp(log_dir,
"..") == 0 || strncmp(log_dir,
"../", 3) == 0 ||
1634 strstr(log_dir,
"/../") != NULL ||
1635 (strlen(log_dir) >= 3 && strcmp(log_dir + strlen(log_dir) - 3,
"/..") == 0))) {
1636 *reason =
"walks above the working directory by relative traversal, which cannot "
1642 if (PetscMalloc1(8 * PETSC_MAX_PATH_LEN, &scratch)) {
1643 *reason =
"cannot be checked because scratch space could not be allocated";
1648 resolved = scratch + PETSC_MAX_PATH_LEN;
1649 cwd_real = scratch + 2 * PETSC_MAX_PATH_LEN;
1652 if (!getcwd(cwd, PETSC_MAX_PATH_LEN)) {
1653 *reason =
"cannot be checked because the working directory could not be determined";
1654 }
else if (!realpath(cwd, cwd_real)) {
1655 *reason =
"cannot be checked because the working directory could not be resolved";
1657 scratch + 3 * PETSC_MAX_PATH_LEN)) {
1658 *reason =
"could not be resolved to a physical path";
1659 }
else if (strcmp(resolved, cwd_real) == 0) {
1661 *reason =
"resolves to the working directory itself; deleting it would destroy "
1662 "the run. This cannot be overridden";
1665 *reason =
"contains the working directory, so deleting it recursively would "
1666 "destroy the run and everything beside it. This cannot be overridden";
1670 }
else if (log_dir[0] ==
'/') {
1674 *reason =
"is an absolute path outside the working directory and no "
1675 "-allow_unsafe_log_dir authorization was given";
1678 *reason =
"is a relative name that resolves outside the working directory "
1679 "through a symlink, which cannot be authorized";
1713 PetscBool authorized,
const char **reason)
1730 PetscErrorCode ierr;
1734 PetscFunctionBeginUser;
1736 rank = simCtx->
rank;
1743 const char *job_start_env = getenv(
"PICURV_JOB_START_EPOCH");
1744 const char *limit_env = getenv(
"PICURV_WALLTIME_LIMIT_SECONDS");
1748 if (!job_start_ok || !limit_ok) {
1755 "Runtime walltime guard enabled but %s/%s are missing or invalid. Falling back to external shutdown signals only.\n",
1756 "PICURV_JOB_START_EPOCH",
1757 "PICURV_WALLTIME_LIMIT_SECONDS"
1775 ierr = PetscSNPrintf(desc,
sizeof(desc),
"BCS file #%" PetscInt_FMT
"", i + 1); CHKERRQ(ierr);
1807 "Initial-condition source directory", &exists); CHKERRQ(ierr);
1826 PetscBool unsafe_authorized = PETSC_FALSE;
1827 const char *refusal = NULL;
1828 ierr = PetscOptionsGetBool(NULL, NULL,
"-allow_unsafe_log_dir",
1829 &unsafe_authorized, NULL); CHKERRQ(ierr);
1831 unsafe_authorized, &refusal)) {
1832 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE,
1833 "Refusing to delete log directory '%s': it %s. Configure run "
1834 "directories through monitor.io.directories.",
1837 if (unsafe_authorized) {
1839 "Deleting log directory '%s' outside the working directory, "
1840 "authorized by -allow_unsafe_log_dir.\n", simCtx->
log_dir);
1844 ierr = PetscRMTree(simCtx->
log_dir);
1846 PetscError(PETSC_COMM_SELF, __LINE__, PETSC_FUNCTION_NAME, __FILE__, ierr, PETSC_ERROR_INITIAL,
"Could not remove existing log directory '%s'. Check permissions.", simCtx->
log_dir);
1848 ierr = PetscMkdir(simCtx->
log_dir); CHKERRQ(ierr);
1852 ierr = PetscMkdir(simCtx->
log_dir); CHKERRQ(ierr);
1859 ierr = PetscTestDirectory(simCtx->
output_dir,
'r', &exists); CHKERRQ(ierr);
1862 ierr = PetscMkdir(simCtx->
output_dir); CHKERRQ(ierr);
1872 char path_buffer[PETSC_MAX_PATH_LEN];
1874 const char *last_slash_euler = strrchr(pps->
output_prefix,
'/');
1875 if(last_slash_euler){
1878 if(dir_len >=
sizeof(path_buffer)) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_ARG_WRONG,
"Post-processing output prefix path is too long.");
1880 path_buffer[dir_len] =
'\0';
1882 ierr = PetscTestDirectory(path_buffer,
'r', &exists); CHKERRQ(ierr);
1893 if(last_slash_particle){
1896 if(dir_len >
sizeof(path_buffer)) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_ARG_WRONG,
"Post-processing particle output prefix path is too long.");
1898 path_buffer[dir_len] =
'\0';
1900 ierr = PetscTestDirectory(path_buffer,
'r', &exists); CHKERRQ(ierr);
1913 if(last_slash_stats){
1916 if(dir_len >=
sizeof(path_buffer)) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_ARG_WRONG,
"Post-processing statistics output prefix path is too long.");
1918 path_buffer[dir_len] =
'\0';
1920 ierr = PetscTestDirectory(path_buffer,
'r', &exists); CHKERRQ(ierr);
1932 ierr = MPI_Barrier(PETSC_COMM_WORLD); CHKERRMPI(ierr);
1940 char *info_name = NULL;
1941 FILE *info_file = NULL;
1942 ierr = PetscInfoGetFile(&info_name, &info_file); CHKERRQ(ierr);
1943 if (info_name && info_name[0] !=
'\0') {
1944 char reopen_name[PETSC_MAX_PATH_LEN];
1945 ierr = PetscStrncpy(reopen_name, info_name,
sizeof(reopen_name)); CHKERRQ(ierr);
1946 if (info_file && info_file != PETSC_STDOUT) {
1947 ierr = PetscFClose(PETSC_COMM_SELF, info_file); CHKERRQ(ierr);
1949 ierr = PetscInfoSetFile(reopen_name,
"w"); CHKERRQ(ierr);
1952 ierr = PetscFree(info_name); CHKERRQ(ierr);
1958 PetscFunctionReturn(0);
1966 PetscErrorCode ierr;
1971 PetscFunctionBeginUser;
1983 mgctx = usermg->
mgctx;
1988 PetscInt *isc, *jsc, *ksc;
1989 ierr = PetscMalloc3(nblk, &isc, nblk, &jsc, nblk, &ksc); CHKERRQ(ierr);
1991 for (PetscInt i = 0; i < nblk; ++i) {
1992 isc[i] = 0; jsc[i] = 0; ksc[i] = 0;
1997 PetscInt n_opts_found = nblk;
1998 ierr = PetscOptionsGetIntArray(NULL, NULL,
"-mg_i_semi", isc, &n_opts_found, &found); CHKERRQ(ierr);
2000 n_opts_found = nblk;
2001 ierr = PetscOptionsGetIntArray(NULL, NULL,
"-mg_j_semi", jsc, &n_opts_found, &found); CHKERRQ(ierr);
2003 n_opts_found = nblk;
2004 ierr = PetscOptionsGetIntArray(NULL, NULL,
"-mg_k_semi", ksc, &n_opts_found, &found); CHKERRQ(ierr);
2007 for (PetscInt level = 0; level < simCtx->
mglevels; level++) {
2011 ierr = PetscMalloc(nblk *
sizeof(
UserCtx), &mgctx[level].user); CHKERRQ(ierr);
2013 ierr = PetscMemzero(mgctx[level].user, nblk *
sizeof(
UserCtx)); CHKERRQ(ierr);
2016 for (PetscInt bi = 0; bi < nblk; bi++) {
2018 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
"Rank %d: Initializing UserCtx for Level %" PetscInt_FMT
", Block %" PetscInt_FMT
".\n", simCtx->
rank, level, bi);
2021 currentUser->
simCtx = simCtx;
2025 currentUser->
_this = bi;
2029 currentUser->
isc = isc[bi];
2030 currentUser->
jsc = jsc[bi];
2031 currentUser->
ksc = ksc[bi];
2037 currentUser->
user_c = &mgctx[level-1].
user[bi];
2038 mgctx[level-1].
user[bi].
user_f = currentUser;
2047 for (PetscInt bi = 0; bi < nblk; ++bi) {
2048 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
"Rank %d: Block %" PetscInt_FMT
": i-semi=%" PetscInt_FMT
", j-semi=%" PetscInt_FMT
", k-semi=%" PetscInt_FMT
"\n", simCtx->
rank, bi, isc[bi], jsc[bi], ksc[bi]);
2053 ierr = PetscFree3(isc, jsc, ksc); CHKERRQ(ierr);
2057 PetscFunctionReturn(0);
2068 PetscErrorCode ierr;
2069 PetscFunctionBeginUser;
2091 PetscFunctionReturn(0);
2101 PetscErrorCode ierr;
2106 PetscFunctionBeginUser;
2112 for (PetscInt level = usermg->
mglevels-1; level >=0; level--) {
2113 for (PetscInt bi = 0; bi < nblk; bi++) {
2116 if(!user->
da || !user->
fda) {
2117 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONGSTATE,
"DMs not properly initialized in UserCtx before vector creation.");
2124 ierr = DMCreateGlobalVector(user->
fda, &user->
Ucont); CHKERRQ(ierr); ierr = VecSet(user->
Ucont, 0.0); CHKERRQ(ierr);
2125 ierr = DMCreateGlobalVector(user->
fda, &user->
Ucat); CHKERRQ(ierr); ierr = VecSet(user->
Ucat, 0.0); CHKERRQ(ierr);
2126 ierr = DMCreateGlobalVector(user->
da, &user->
P); CHKERRQ(ierr); ierr = VecSet(user->
P, 0.0); CHKERRQ(ierr);
2127 ierr = DMCreateGlobalVector(user->
da, &user->
Nvert); CHKERRQ(ierr); ierr = VecSet(user->
Nvert, 0.0); CHKERRQ(ierr);
2129 ierr = DMCreateLocalVector(user->
fda, &user->
lUcont); CHKERRQ(ierr); ierr = VecSet(user->
lUcont, 0.0); CHKERRQ(ierr);
2130 ierr = DMCreateLocalVector(user->
fda, &user->
lUcat); CHKERRQ(ierr); ierr = VecSet(user->
lUcat, 0.0); CHKERRQ(ierr);
2131 ierr = DMCreateLocalVector(user->
da, &user->
lP); CHKERRQ(ierr); ierr = VecSet(user->
lP, 0.0); CHKERRQ(ierr);
2132 ierr = DMCreateLocalVector(user->
da, &user->
lNvert); CHKERRQ(ierr); ierr = VecSet(user->
lNvert, 0.0); CHKERRQ(ierr);
2135 ierr = VecDuplicate(user->
P,&user->
Diffusivity); CHKERRQ(ierr); ierr = VecSet(user->
Diffusivity, 0.0); CHKERRQ(ierr);
2141 ierr = VecDuplicate(user->
P, &user->
Phi); CHKERRQ(ierr); ierr = VecSet(user->
Phi, 0.0); CHKERRQ(ierr);
2142 ierr = VecDuplicate(user->
lP, &user->
lPhi); CHKERRQ(ierr); ierr = VecSet(user->
lPhi, 0.0); CHKERRQ(ierr);
2145 if (level == usermg->
mglevels - 1) {
2146 ierr = VecDuplicate(user->
Ucont, &user->
Ucont_o); CHKERRQ(ierr); ierr = VecSet(user->
Ucont_o, 0.0); CHKERRQ(ierr);
2147 ierr = VecDuplicate(user->
Ucont, &user->
Ucont_rm1); CHKERRQ(ierr); ierr = VecSet(user->
Ucont_rm1, 0.0); CHKERRQ(ierr);
2148 ierr = VecDuplicate(user->
Ucat, &user->
Ucat_o); CHKERRQ(ierr); ierr = VecSet(user->
Ucat_o, 0.0); CHKERRQ(ierr);
2149 ierr = VecDuplicate(user->
P, &user->
P_o); CHKERRQ(ierr); ierr = VecSet(user->
P_o, 0.0); CHKERRQ(ierr);
2150 ierr = VecDuplicate(user->
lUcont, &user->
lUcont_o); CHKERRQ(ierr); ierr = VecSet(user->
lUcont_o, 0.0); CHKERRQ(ierr);
2152 ierr = DMCreateLocalVector(user->
da, &user->
lNvert_o); CHKERRQ(ierr); ierr = VecSet(user->
lNvert_o, 0.0); CHKERRQ(ierr);
2153 ierr = VecDuplicate(user->
Nvert, &user->
Nvert_o); CHKERRQ(ierr); ierr = VecSet(user->
Nvert_o, 0.0); CHKERRQ(ierr);
2157 ierr = DMCreateGlobalVector(user->
fda, &user->
Csi); CHKERRQ(ierr); ierr = VecSet(user->
Csi, 0.0); CHKERRQ(ierr);
2158 ierr = VecDuplicate(user->
Csi, &user->
Eta); CHKERRQ(ierr); ierr = VecSet(user->
Eta, 0.0); CHKERRQ(ierr);
2159 ierr = VecDuplicate(user->
Csi, &user->
Zet); CHKERRQ(ierr); ierr = VecSet(user->
Zet, 0.0); CHKERRQ(ierr);
2160 ierr = DMCreateGlobalVector(user->
da, &user->
Aj); CHKERRQ(ierr); ierr = VecSet(user->
Aj, 0.0); CHKERRQ(ierr);
2162 ierr = DMCreateLocalVector(user->
fda, &user->
lCsi); CHKERRQ(ierr); ierr = VecSet(user->
lCsi, 0.0); CHKERRQ(ierr);
2163 ierr = VecDuplicate(user->
lCsi, &user->
lEta); CHKERRQ(ierr); ierr = VecSet(user->
lEta, 0.0); CHKERRQ(ierr);
2164 ierr = VecDuplicate(user->
lCsi, &user->
lZet); CHKERRQ(ierr); ierr = VecSet(user->
lZet, 0.0); CHKERRQ(ierr);
2165 ierr = DMCreateLocalVector(user->
da, &user->
lAj); CHKERRQ(ierr); ierr = VecSet(user->
lAj, 0.0); CHKERRQ(ierr);
2170 ierr = VecDuplicate(user->
Csi, &user->
ICsi); CHKERRQ(ierr); ierr = VecSet(user->
ICsi, 0.0); CHKERRQ(ierr);
2171 ierr = VecDuplicate(user->
Csi, &user->
IEta); CHKERRQ(ierr); ierr = VecSet(user->
IEta, 0.0); CHKERRQ(ierr);
2172 ierr = VecDuplicate(user->
Csi, &user->
IZet); CHKERRQ(ierr); ierr = VecSet(user->
IZet, 0.0); CHKERRQ(ierr);
2173 ierr = VecDuplicate(user->
Csi, &user->
JCsi); CHKERRQ(ierr); ierr = VecSet(user->
JCsi, 0.0); CHKERRQ(ierr);
2174 ierr = VecDuplicate(user->
Csi, &user->
JEta); CHKERRQ(ierr); ierr = VecSet(user->
JEta, 0.0); CHKERRQ(ierr);
2175 ierr = VecDuplicate(user->
Csi, &user->
JZet); CHKERRQ(ierr); ierr = VecSet(user->
JZet, 0.0); CHKERRQ(ierr);
2176 ierr = VecDuplicate(user->
Csi, &user->
KCsi); CHKERRQ(ierr); ierr = VecSet(user->
KCsi, 0.0); CHKERRQ(ierr);
2177 ierr = VecDuplicate(user->
Csi, &user->
KEta); CHKERRQ(ierr); ierr = VecSet(user->
KEta, 0.0); CHKERRQ(ierr);
2178 ierr = VecDuplicate(user->
Csi, &user->
KZet); CHKERRQ(ierr); ierr = VecSet(user->
KZet, 0.0); CHKERRQ(ierr);
2180 ierr = VecDuplicate(user->
Aj, &user->
IAj); CHKERRQ(ierr); ierr = VecSet(user->
IAj, 0.0); CHKERRQ(ierr);
2181 ierr = VecDuplicate(user->
Aj, &user->
JAj); CHKERRQ(ierr); ierr = VecSet(user->
JAj, 0.0); CHKERRQ(ierr);
2182 ierr = VecDuplicate(user->
Aj, &user->
KAj); CHKERRQ(ierr); ierr = VecSet(user->
KAj, 0.0); CHKERRQ(ierr);
2184 ierr = VecDuplicate(user->
lCsi, &user->
lICsi); CHKERRQ(ierr); ierr = VecSet(user->
lICsi, 0.0); CHKERRQ(ierr);
2185 ierr = VecDuplicate(user->
lCsi, &user->
lIEta); CHKERRQ(ierr); ierr = VecSet(user->
lIEta, 0.0); CHKERRQ(ierr);
2186 ierr = VecDuplicate(user->
lCsi, &user->
lIZet); CHKERRQ(ierr); ierr = VecSet(user->
lIZet, 0.0); CHKERRQ(ierr);
2187 ierr = VecDuplicate(user->
lCsi, &user->
lJCsi); CHKERRQ(ierr); ierr = VecSet(user->
lJCsi, 0.0); CHKERRQ(ierr);
2188 ierr = VecDuplicate(user->
lCsi, &user->
lJEta); CHKERRQ(ierr); ierr = VecSet(user->
lJEta, 0.0); CHKERRQ(ierr);
2189 ierr = VecDuplicate(user->
lCsi, &user->
lJZet); CHKERRQ(ierr); ierr = VecSet(user->
lJZet, 0.0); CHKERRQ(ierr);
2190 ierr = VecDuplicate(user->
lCsi, &user->
lKCsi); CHKERRQ(ierr); ierr = VecSet(user->
lKCsi, 0.0); CHKERRQ(ierr);
2191 ierr = VecDuplicate(user->
lCsi, &user->
lKEta); CHKERRQ(ierr); ierr = VecSet(user->
lKEta, 0.0); CHKERRQ(ierr);
2192 ierr = VecDuplicate(user->
lCsi, &user->
lKZet); CHKERRQ(ierr); ierr = VecSet(user->
lKZet, 0.0); CHKERRQ(ierr);
2194 ierr = VecDuplicate(user->
lAj, &user->
lIAj); CHKERRQ(ierr); ierr = VecSet(user->
lIAj, 0.0); CHKERRQ(ierr);
2195 ierr = VecDuplicate(user->
lAj, &user->
lJAj); CHKERRQ(ierr); ierr = VecSet(user->
lJAj, 0.0); CHKERRQ(ierr);
2196 ierr = VecDuplicate(user->
lAj, &user->
lKAj); CHKERRQ(ierr); ierr = VecSet(user->
lKAj, 0.0); CHKERRQ(ierr);
2199 ierr = DMCreateGlobalVector(user->
fda, &user->
Cent); CHKERRQ(ierr); ierr = VecSet(user->
Cent, 0.0); CHKERRQ(ierr);
2200 ierr = DMCreateLocalVector(user->
fda, &user->
lCent); CHKERRQ(ierr); ierr = VecSet(user->
lCent, 0.0); CHKERRQ(ierr);
2203 ierr = VecDuplicate(user->
Cent, &user->
Centx); CHKERRQ(ierr); ierr = VecSet(user->
Centx, 0.0); CHKERRQ(ierr);
2204 ierr = VecDuplicate(user->
Cent, &user->
Centy); CHKERRQ(ierr); ierr = VecSet(user->
Centy, 0.0); CHKERRQ(ierr);
2205 ierr = VecDuplicate(user->
Cent, &user->
Centz); CHKERRQ(ierr); ierr = VecSet(user->
Centz, 0.0); CHKERRQ(ierr);
2206 ierr = VecDuplicate(user->
lCent, &user->
lCentx); CHKERRQ(ierr); ierr = VecSet(user->
lCentx, 0.0); CHKERRQ(ierr);
2207 ierr = VecDuplicate(user->
lCent, &user->
lCenty); CHKERRQ(ierr); ierr = VecSet(user->
lCenty, 0.0); CHKERRQ(ierr);
2208 ierr = VecDuplicate(user->
lCent, &user->
lCentz); CHKERRQ(ierr); ierr = VecSet(user->
lCentz, 0.0); CHKERRQ(ierr);
2213 ierr = DMCreateGlobalVector(user->
da, &user->
Nu_t); CHKERRQ(ierr); ierr = VecSet(user->
Nu_t, 0.0); CHKERRQ(ierr);
2214 ierr = DMCreateLocalVector(user->
da, &user->
lNu_t); CHKERRQ(ierr); ierr = VecSet(user->
lNu_t, 0.0); CHKERRQ(ierr);
2221 ierr = DMCreateGlobalVector(user->
da,&user->
CS); CHKERRQ(ierr); ierr = VecSet(user->
CS,0.0); CHKERRQ(ierr);
2222 ierr = DMCreateLocalVector(user->
da,&user->
lCs); CHKERRQ(ierr); ierr = VecSet(user->
lCs,0.0); CHKERRQ(ierr);
2245 ierr = DMCreateGlobalVector(user->
fda, &user->
Wall_Stress); CHKERRQ(ierr);
2246 ierr = VecSet(user->
Wall_Stress, 0.0); CHKERRQ(ierr);
2247 ierr = DMCreateLocalVector(user->
fda, &user->
lWall_Stress); CHKERRQ(ierr);
2263 ierr = DMCreateGlobalVector(user->
da,&user->
Psi); CHKERRQ(ierr); ierr = VecSet(user->
Psi,0.0); CHKERRQ(ierr);
2264 ierr = DMCreateLocalVector(user->
da,&user->
lPsi); CHKERRQ(ierr); ierr = VecSet(user->
lPsi,0.0); CHKERRQ(ierr);
2269 ierr = DMCreateGlobalVector(user->
fda, &user->
Bcs.
Ubcs); CHKERRQ(ierr);
2270 ierr = VecSet(user->
Bcs.
Ubcs, 0.0); CHKERRQ(ierr);
2271 ierr = DMCreateGlobalVector(user->
fda, &user->
Bcs.
Uch); CHKERRQ(ierr);
2272 ierr = VecSet(user->
Bcs.
Uch, 0.0); CHKERRQ(ierr);
2287 "Allocated accumulators for %" PetscInt_FMT
" statistics window(s).\n",
2295 if (level == usermg->
mglevels - 1) {
2312 ierr = DMCreateGlobalVector(user->
da, &user->
PostScalar); CHKERRQ(ierr);
2313 ierr = VecSet(user->
PostScalar, 0.0); CHKERRQ(ierr);
2314 ierr = DMCreateLocalVector(user->
da, &user->
lPostScalar); CHKERRQ(ierr);
2315 ierr = VecSet(user->
lPostScalar, 0.0); CHKERRQ(ierr);
2318 ierr = DMCreateGlobalVector(user->
fda, &user->
PostVector); CHKERRQ(ierr);
2319 ierr = VecSet(user->
PostVector, 0.0); CHKERRQ(ierr);
2320 ierr = DMCreateLocalVector(user->
fda, &user->
lPostVector); CHKERRQ(ierr);
2321 ierr = VecSet(user->
lPostVector, 0.0); CHKERRQ(ierr);
2330 ierr = VecDuplicate(user->
P, &user->
P_nodal); CHKERRQ(ierr);
2331 ierr = VecSet(user->
P_nodal, 0.0); CHKERRQ(ierr);
2333 ierr = VecDuplicate(user->
Ucat, &user->
Ucat_nodal); CHKERRQ(ierr);
2334 ierr = VecSet(user->
Ucat_nodal, 0.0); CHKERRQ(ierr);
2336 ierr = VecDuplicate(user->
P, &user->
Qcrit); CHKERRQ(ierr);
2337 ierr = VecSet(user->
Qcrit, 0.0); CHKERRQ(ierr);
2338 ierr = DMCreateLocalVector(user->
da, &user->
lQcrit); CHKERRQ(ierr);
2339 ierr = VecSet(user->
lQcrit, 0.0); CHKERRQ(ierr);
2340 ierr = VecDuplicate(user->
P, &user->
Qcrit_nodal); CHKERRQ(ierr);
2341 ierr = VecSet(user->
Qcrit_nodal, 0.0); CHKERRQ(ierr);
2346 ierr = VecDuplicate(user->
Psi, &user->
Psi_nodal); CHKERRQ(ierr);
2347 ierr = VecSet(user->
Psi_nodal, 0.0); CHKERRQ(ierr);
2375 PetscFunctionReturn(0);
2387 PetscInt dof,
char face_direction,
2388 PetscBool component_staggered)
2391 PetscInt xs, xe, ys, ye, zs, ze;
2392 PetscInt gxs, gxe, gys, gye, gzs, gze;
2393 PetscInt mx, my, mz;
2395 PetscFunctionBeginUser;
2397 if (!face_direction && !component_staggered) {
PROFILE_HELPER_END; PetscFunctionReturn(0); }
2400 xs = info.xs; xe = info.xs + info.xm;
2401 ys = info.ys; ye = info.ys + info.ym;
2402 zs = info.zs; ze = info.zs + info.zm;
2403 gxs = info.gxs; gxe = info.gxs + info.gxm;
2404 gys = info.gys; gye = info.gys + info.gym;
2405 gzs = info.gzs; gze = info.gzs + info.gzm;
2406 mx = info.mx; my = info.my; mz = info.mz;
2408 if (component_staggered) {
2410 PetscCall(DMDAVecGetArray(dm, local_vec, &array));
2413 PetscCheck(gxs <= -3, PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ,
2414 "Periodic Ucont.x ghost repair requires DMDA stencil width at least 3.");
2415 for (PetscInt k = gzs; k < gze; k++)
for (PetscInt j = gys; j < gye; j++)
2416 array[k][j][-1].x = array[k][j][-3].x;
2419 PetscCheck(gxe > mx + 2, PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ,
2420 "Periodic Ucont.x ghost repair requires DMDA stencil width at least 3.");
2421 for (PetscInt k = gzs; k < gze; k++)
for (PetscInt j = gys; j < gye; j++)
2422 array[k][j][mx].x = array[k][j][mx + 2].x;
2425 PetscCheck(gys <= -3, PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ,
2426 "Periodic Ucont.y ghost repair requires DMDA stencil width at least 3.");
2427 for (PetscInt k = gzs; k < gze; k++)
for (PetscInt i = gxs; i < gxe; i++)
2428 array[k][-1][i].y = array[k][-3][i].y;
2431 PetscCheck(gye > my + 2, PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ,
2432 "Periodic Ucont.y ghost repair requires DMDA stencil width at least 3.");
2433 for (PetscInt k = gzs; k < gze; k++)
for (PetscInt i = gxs; i < gxe; i++)
2434 array[k][my][i].y = array[k][my + 2][i].y;
2437 PetscCheck(gzs <= -3, PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ,
2438 "Periodic Ucont.z ghost repair requires DMDA stencil width at least 3.");
2439 for (PetscInt j = gys; j < gye; j++)
for (PetscInt i = gxs; i < gxe; i++)
2440 array[-1][j][i].z = array[-3][j][i].z;
2443 PetscCheck(gze > mz + 2, PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ,
2444 "Periodic Ucont.z ghost repair requires DMDA stencil width at least 3.");
2445 for (PetscInt j = gys; j < gye; j++)
for (PetscInt i = gxs; i < gxe; i++)
2446 array[mz][j][i].z = array[mz + 2][j][i].z;
2449 PetscCall(DMDAVecRestoreArray(dm, local_vec, &array));
2451 PetscFunctionReturn(0);
2456 PetscCall(DMDAVecGetArray(dm, local_vec, &array));
2458 if (face_direction ==
'i') {
2460 PetscCheck(gxs <= -3, PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ,
2461 "Periodic I-face ghost repair requires DMDA stencil width at least 3.");
2462 for (PetscInt k = gzs; k < gze; k++)
for (PetscInt j = gys; j < gye; j++)
2463 array[k][j][-1] = array[k][j][-3];
2466 PetscCheck(gxe > mx + 2, PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ,
2467 "Periodic I-face ghost repair requires DMDA stencil width at least 3.");
2468 for (PetscInt k = gzs; k < gze; k++)
for (PetscInt j = gys; j < gye; j++)
2469 array[k][j][mx] = array[k][j][mx + 2];
2471 }
else if (face_direction ==
'j') {
2473 PetscCheck(gys <= -3, PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ,
2474 "Periodic J-face ghost repair requires DMDA stencil width at least 3.");
2475 for (PetscInt k = gzs; k < gze; k++)
for (PetscInt i = gxs; i < gxe; i++)
2476 array[k][-1][i] = array[k][-3][i];
2479 PetscCheck(gye > my + 2, PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ,
2480 "Periodic J-face ghost repair requires DMDA stencil width at least 3.");
2481 for (PetscInt k = gzs; k < gze; k++)
for (PetscInt i = gxs; i < gxe; i++)
2482 array[k][my][i] = array[k][my + 2][i];
2484 }
else if (face_direction ==
'k') {
2486 PetscCheck(gzs <= -3, PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ,
2487 "Periodic K-face ghost repair requires DMDA stencil width at least 3.");
2488 for (PetscInt j = gys; j < gye; j++)
for (PetscInt i = gxs; i < gxe; i++)
2489 array[-1][j][i] = array[-3][j][i];
2492 PetscCheck(gze > mz + 2, PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ,
2493 "Periodic K-face ghost repair requires DMDA stencil width at least 3.");
2494 for (PetscInt j = gys; j < gye; j++)
for (PetscInt i = gxs; i < gxe; i++)
2495 array[mz][j][i] = array[mz + 2][j][i];
2499 PetscCall(DMDAVecRestoreArray(dm, local_vec, &array));
2502 PetscCall(DMDAVecGetArray(dm, local_vec, &array));
2504 if (face_direction ==
'i') {
2506 PetscCheck(gxs <= -3, PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ,
2507 "Periodic I-face ghost repair requires DMDA stencil width at least 3.");
2508 for (PetscInt k = gzs; k < gze; k++)
for (PetscInt j = gys; j < gye; j++)
2509 array[k][j][-1] = array[k][j][-3];
2512 PetscCheck(gxe > mx + 2, PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ,
2513 "Periodic I-face ghost repair requires DMDA stencil width at least 3.");
2514 for (PetscInt k = gzs; k < gze; k++)
for (PetscInt j = gys; j < gye; j++)
2515 array[k][j][mx] = array[k][j][mx + 2];
2517 }
else if (face_direction ==
'j') {
2519 PetscCheck(gys <= -3, PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ,
2520 "Periodic J-face ghost repair requires DMDA stencil width at least 3.");
2521 for (PetscInt k = gzs; k < gze; k++)
for (PetscInt i = gxs; i < gxe; i++)
2522 array[k][-1][i] = array[k][-3][i];
2525 PetscCheck(gye > my + 2, PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ,
2526 "Periodic J-face ghost repair requires DMDA stencil width at least 3.");
2527 for (PetscInt k = gzs; k < gze; k++)
for (PetscInt i = gxs; i < gxe; i++)
2528 array[k][my][i] = array[k][my + 2][i];
2530 }
else if (face_direction ==
'k') {
2532 PetscCheck(gzs <= -3, PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ,
2533 "Periodic K-face ghost repair requires DMDA stencil width at least 3.");
2534 for (PetscInt j = gys; j < gye; j++)
for (PetscInt i = gxs; i < gxe; i++)
2535 array[-1][j][i] = array[-3][j][i];
2538 PetscCheck(gze > mz + 2, PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ,
2539 "Periodic K-face ghost repair requires DMDA stencil width at least 3.");
2540 for (PetscInt j = gys; j < gye; j++)
for (PetscInt i = gxs; i < gxe; i++)
2541 array[mz][j][i] = array[mz + 2][j][i];
2545 PetscCall(DMDAVecRestoreArray(dm, local_vec, &array));
2549 PetscFunctionReturn(0);
2558 char face_direction =
'\0';
2559 PetscBool component_staggered = PETSC_FALSE;
2561 PetscFunctionBeginUser;
2565 face_direction =
'i';
2568 face_direction =
'j';
2571 face_direction =
'k';
2574 component_staggered = PETSC_TRUE;
2579 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_PLIB,
2583 component_staggered));
2585 PetscFunctionReturn(0);
2595 PetscErrorCode ierr;
2598 const char *field_name;
2603 PetscFunctionBeginUser;
2606 ierr =
FieldGetView(user, field_id, &field_view); CHKERRQ(ierr);
2608 PETSC_COMM_SELF, PETSC_ERR_SUP,
2609 "Field '%s' does not support ghost updates.",
2619 rank, field_name, (
void*)dm, (
void*)globalVec, (
void*)localVec);
2625 PetscReal norm_global_before;
2626 ierr = VecNorm(globalVec, NORM_INFINITY, &norm_global_before); CHKERRQ(ierr);
2627 LOG_ALLOW(
GLOBAL,
LOG_INFO,
"Max norm '%s' (Global) BEFORE Ghost Update: %g\n", field_name, norm_global_before);
2636 ierr = DMGlobalToLocalBegin(dm, globalVec, INSERT_VALUES, localVec); CHKERRQ(ierr);
2637 ierr = DMGlobalToLocalEnd(dm, globalVec, INSERT_VALUES, localVec); CHKERRQ(ierr);
2645 PetscReal norm_local_after;
2646 ierr = VecNorm(localVec, NORM_INFINITY, &norm_local_after); CHKERRQ(ierr);
2652 PetscMPIInt rank_test;
2656 DMDALocalInfo info_check;
2657 info_check = user->
info;
2660 Cmpnts ***lUcat_arr_test = NULL;
2661 PetscErrorCode ierr_test = 0;
2663 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
"Rank %d: Testing '%s' access immediately after ghost update...\n", rank_test, field_name);
2664 ierr_test = DMDAVecGetArrayDOFRead(dm, localVec, &lUcat_arr_test);
2667 LOG_ALLOW(
LOCAL,
LOG_ERROR,
"Rank %d: ERROR %d getting '%s' array after ghost update!\n", rank_test, ierr_test, field_name);
2668 }
else if (!lUcat_arr_test) {
2669 LOG_ALLOW(
LOCAL,
LOG_ERROR,
"Rank %d: ERROR NULL pointer getting '%s' array after ghost update!\n", rank_test, field_name);
2673 PetscInt k_int = info_check.zs + (info_check.zm > 1 ? 1 : 0);
2674 PetscInt j_int = info_check.ys + (info_check.ym > 1 ? 1 : 0);
2675 PetscInt i_int = info_check.xs + (info_check.xm > 1 ? 1 : 0);
2681 if (k_int >= info_check.mz - 1) {
2682 k_int = info_check.mz - 2;
2689 if (j_int >= info_check.my - 1) {
2690 j_int = info_check.my - 2;
2697 if (i_int >= info_check.mx - 1) {
2698 i_int = info_check.mx - 2;
2705 if (k_int >= info_check.zs && k_int < info_check.zs + info_check.zm &&
2706 j_int >= info_check.ys && j_int < info_check.ys + info_check.ym &&
2707 i_int >= info_check.xs && i_int < info_check.xs + info_check.xm)
2709 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
"Rank %d: Attempting test read OWNED INTERIOR [%" PetscInt_FMT
"][%" PetscInt_FMT
"][%" PetscInt_FMT
"] (Global)\n", rank_test, k_int, j_int, i_int);
2710 Cmpnts test_val_owned_interior = lUcat_arr_test[k_int][j_int][i_int];
2711 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
"Rank %d: SUCCESS reading owned interior: x=%g\n", rank_test, test_val_owned_interior.
x);
2713 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
"Rank %d: Skipping interior test read for non-owned index [%" PetscInt_FMT
"][%" PetscInt_FMT
"][%" PetscInt_FMT
"].\n", rank_test, k_int, j_int, i_int);
2718 PetscInt k_bnd = info_check.zs;
2719 PetscInt j_bnd = info_check.ys;
2720 PetscInt i_bnd = info_check.xs;
2721 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
"Rank %d: Attempting test read OWNED BOUNDARY [%" PetscInt_FMT
"][%" PetscInt_FMT
"][%" PetscInt_FMT
"] (Global)\n", rank_test, k_bnd, j_bnd, i_bnd);
2722 Cmpnts test_val_owned_boundary = lUcat_arr_test[k_bnd][j_bnd][i_bnd];
2723 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
"Rank %d: SUCCESS reading owned boundary: x=%g\n", rank_test, test_val_owned_boundary.
x);
2727 if (info_check.zs > 0) {
2728 PetscInt k_ghost = info_check.zs - 1;
2729 PetscInt j_ghost = info_check.ys;
2730 PetscInt i_ghost = info_check.xs;
2731 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
"Rank %d: Attempting test read GHOST [%" PetscInt_FMT
"][%" PetscInt_FMT
"][%" PetscInt_FMT
"] (Global)\n", rank_test, k_ghost, j_ghost, i_ghost);
2732 Cmpnts test_val_ghost = lUcat_arr_test[k_ghost][j_ghost][i_ghost];
2739 ierr_test = DMDAVecRestoreArrayDOFRead(dm, localVec, &lUcat_arr_test);
2740 if(ierr_test){
LOG_ALLOW(
LOCAL,
LOG_ERROR,
"Rank %d: ERROR %d restoring '%s' array after test read!\n", rank_test, ierr_test, field_name); }
2748 PetscFunctionReturn(0);
2757 PetscErrorCode ierr;
2758 PetscFunctionBeginUser;
2764 LOG_ALLOW(
GLOBAL,
LOG_INFO,
"Parsing BC configuration files and initializing boundary condition data structures.\n");
2766 for (PetscInt bi = 0; bi < simCtx->
block_number; bi++) {
2770 const char *current_bc_filename = simCtx->
bcs_files[bi];
2771 LOG_ALLOW(
GLOBAL,
LOG_DEBUG,
" -> Processing Block %" PetscInt_FMT
" using config file '%s'\n", bi, current_bc_filename);
2783 for (PetscInt level = simCtx->
usermg.
mglevels - 1; level >= 0; level--) {
2785 for (PetscInt bi = 0; bi < simCtx->
block_number; bi++) {
2800 for (PetscInt bi = 0; bi < simCtx->
block_number; bi++) {
2812 PetscFunctionReturn(0);
2821 PetscErrorCode ierr;
2823 PetscReal *dataContiguous;
2829 ierr = PetscCalloc1(nz, &data); CHKERRQ(ierr);
2832 ierr = PetscCalloc1(nz * ny, &data[0]); CHKERRQ(ierr);
2833 for (k = 1; k < nz; k++) {
2834 data[k] = data[0] + k * ny;
2838 ierr = PetscCalloc1(nz * ny * nx, &dataContiguous); CHKERRQ(ierr);
2841 for (k = 0; k < nz; k++) {
2842 for (j = 0; j < ny; j++) {
2843 data[k][j] = dataContiguous + (k * ny + j) * nx;
2849 PetscFunctionReturn(0);
2858 PetscErrorCode ierr;
2864 if (!array || !array[0] || !array[0][0] ) {
2870 ierr = PetscFree(array[0]); CHKERRQ(ierr);
2872 ierr = PetscFree(array); CHKERRQ(ierr);
2875 PetscFunctionReturn(0);
2882 ierr = PetscFree(array[0][0]); CHKERRQ(ierr);
2886 ierr = PetscFree(array[0]); CHKERRQ(ierr);
2890 ierr = PetscFree(array); CHKERRQ(ierr);
2893 PetscFunctionReturn(0);
2904 PetscErrorCode ierr;
2913 rank = PetscGlobalRank;
2916 ierr = PetscCalloc1(nz, &data); CHKERRQ(ierr);
2918 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
" [Rank %d] memory allocated for outermost layer (%" PetscInt_FMT
" k-layer pointers).\n",rank,nz);
2921 ierr = PetscCalloc1(nz * ny, &data[0]); CHKERRQ(ierr);
2922 for (k = 1; k < nz; k++) {
2923 data[k] = data[0] + k * ny;
2926 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
"[Rank %d] memory allocated for %" PetscInt_FMT
"x%" PetscInt_FMT
" row pointers.\n",rank,nz,ny);
2929 ierr = PetscCalloc1(nz * ny * nx, &dataContiguous); CHKERRQ(ierr);
2931 LOG_ALLOW(
GLOBAL,
LOG_DEBUG,
"[Rank %d] memory allocated for contigous block of %" PetscInt_FMT
"x%" PetscInt_FMT
"x%" PetscInt_FMT
" Cmpnts structures).\n",rank,nz,ny,nx);
2934 for (k = 0; k < nz; k++) {
2935 for (j = 0; j < ny; j++) {
2936 data[k][j] = dataContiguous + (k * ny + j) * nx;
2945 PetscFunctionReturn(0);
2956 PetscErrorCode ierr;
2963 if (!array || !array[0] || !array[0][0] ) {
2984 Cmpnts *dataContiguous = array[0][0];
2985 ierr = PetscFree(dataContiguous); CHKERRQ(ierr);
2988 ierr = PetscFree(array[0]); CHKERRQ(ierr);
2992 ierr = PetscFree(array); CHKERRQ(ierr);
2995 PetscFunctionReturn(0);
3003 ierr = PetscFree(array[0][0]); CHKERRQ(ierr);
3007 ierr = PetscFree(array[0]); CHKERRQ(ierr);
3011 ierr = PetscFree(array); CHKERRQ(ierr);
3014 PetscFunctionReturn(0);
3023 PetscInt *xs_cell_global_out,
3024 PetscInt *xm_cell_local_out)
3026 PetscErrorCode ierr = 0;
3027 PetscInt xs_node_global_rank;
3028 PetscInt num_nodes_owned_rank;
3029 PetscInt GlobalNodesInDim_from_info;
3031 PetscFunctionBeginUser;
3034 if (!info_nodes || !xs_cell_global_out || !xm_cell_local_out) {
3035 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"Null pointer passed to GetOwnedCellRange.");
3040 xs_node_global_rank = info_nodes->xs;
3041 num_nodes_owned_rank = info_nodes->xm;
3042 GlobalNodesInDim_from_info = info_nodes->mx;
3043 }
else if (dim == 1) {
3044 xs_node_global_rank = info_nodes->ys;
3045 num_nodes_owned_rank = info_nodes->ym;
3046 GlobalNodesInDim_from_info = info_nodes->my;
3047 }
else if (dim == 2) {
3048 xs_node_global_rank = info_nodes->zs;
3049 num_nodes_owned_rank = info_nodes->zm;
3050 GlobalNodesInDim_from_info = info_nodes->mz;
3052 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE,
"Invalid dimension %" PetscInt_FMT
" in GetOwnedCellRange. Must be 0, 1, or 2.", dim);
3058 const PetscInt physical_nodes_in_dim = GlobalNodesInDim_from_info - 1;
3062 if (physical_nodes_in_dim <= 1) {
3063 *xs_cell_global_out = xs_node_global_rank;
3064 *xm_cell_local_out = 0;
3065 PetscFunctionReturn(0);
3070 *xs_cell_global_out = xs_node_global_rank;
3073 if (num_nodes_owned_rank == 0) {
3074 *xm_cell_local_out = 0;
3082 PetscInt first_owned_origin = xs_node_global_rank;
3086 PetscInt last_node_owned_by_rank = xs_node_global_rank + num_nodes_owned_rank - 1;
3090 PetscInt last_possible_origin_global_idx = physical_nodes_in_dim - 2;
3095 PetscInt actual_last_origin_this_rank_can_form = PetscMin(last_node_owned_by_rank, last_possible_origin_global_idx);
3100 if (first_owned_origin > actual_last_origin_this_rank_can_form) {
3101 *xm_cell_local_out = 0;
3105 *xm_cell_local_out = actual_last_origin_this_rank_can_form - first_owned_origin + 1;
3109 PetscFunctionReturn(ierr);
3118 PetscErrorCode ierr;
3121 const PetscMPIInt *neighbor_ranks_ptr;
3123 PetscFunctionBeginUser;
3125 rank = PetscGlobalRank;
3126 size = PetscGlobalSize;
3130 if (!user || !user->
da) {
3131 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"UserCtx or user->da is NULL in ComputeAndStoreNeighborRanks.");
3136 ierr = DMDAGetNeighbors(user->
da, &neighbor_ranks_ptr); CHKERRQ(ierr);
3138 if (neighbor_ranks_ptr[13] != rank) {
3139 LOG_ALLOW(
GLOBAL,
LOG_WARNING,
"Rank %d: DMDAGetNeighbors center index (13) is %d, expected current rank %d. Neighbor indexing might be non-standard or DMDA small.\n",
3140 rank, neighbor_ranks_ptr[13], rank);
3146 for (PetscInt n = 0; n < 27; ++n) {
3147 const PetscMPIInt neighbor = neighbor_ranks_ptr[n];
3148 user->
neighbors.
rank[n] = (neighbor < 0 || neighbor >= size) ? MPI_PROC_NULL : neighbor;
3155 PetscSynchronizedFlush(PETSC_COMM_WORLD, PETSC_STDOUT);
3159 PetscFunctionReturn(0);
3168 PetscErrorCode ierr;
3169 PetscMPIInt size, rank;
3170 PetscInt px = PETSC_DECIDE, py = PETSC_DECIDE, pz = PETSC_DECIDE;
3171 PetscBool px_set = PETSC_FALSE, py_set = PETSC_FALSE, pz_set = PETSC_FALSE;
3176 px_set = PETSC_TRUE;
3181 py_set = PETSC_TRUE;
3186 pz_set = PETSC_TRUE;
3190 PetscFunctionBeginUser;
3192 ierr = MPI_Comm_size(PetscObjectComm((PetscObject)dm), &size); CHKERRQ(ierr);
3193 ierr = MPI_Comm_rank(PetscObjectComm((PetscObject)dm), &rank); CHKERRQ(ierr);
3194 LOG_ALLOW(
GLOBAL,
LOG_INFO,
"Rank %d: Configuring DMDA processor layout for %d total processes.\n", rank, size);
3198 if (px_set && py_set && pz_set) {
3199 if (px * py * pz != size) {
3200 SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_INCOMP,
3201 "Specified processor layout %" PetscInt_FMT
" x %" PetscInt_FMT
" x %" PetscInt_FMT
" = %" PetscInt_FMT
" does not match MPI size %d",
3202 px, py, pz, px * py * pz, size);
3204 LOG_ALLOW(
GLOBAL,
LOG_INFO,
"Using specified processor layout: %" PetscInt_FMT
" x %" PetscInt_FMT
" x %" PetscInt_FMT
"\n", px, py, pz);
3205 }
else if (px_set || py_set || pz_set) {
3207 LOG_ALLOW(
GLOBAL,
LOG_INFO,
"Using partially specified processor layout: %" PetscInt_FMT
" x %" PetscInt_FMT
" x %" PetscInt_FMT
" (PETSC_DECIDE for unspecified)\n", px, py, pz);
3209 LOG_ALLOW(
GLOBAL,
LOG_INFO,
"Using fully automatic processor layout (PETSC_DECIDE x PETSC_DECIDE x PETSC_DECIDE)\n");
3212 if ((px_set && px <= 0) || (py_set && py <= 0) || (pz_set && pz <= 0)) {
3213 SETERRQ(PetscObjectComm((PetscObject)dm), PETSC_ERR_ARG_OUTOFRANGE,
"Specified processor counts must be positive.");
3218 ierr = DMDASetNumProcs(dm, px, py, pz); CHKERRQ(ierr);
3219 LOG_ALLOW(
GLOBAL,
LOG_DEBUG,
"Rank %d: DMDASetNumProcs called with px=%" PetscInt_FMT
", py=%" PetscInt_FMT
", pz=%" PetscInt_FMT
".\n", rank, px, py, pz);
3233 PetscFunctionReturn(0);
3244 PetscErrorCode ierr;
3246 PetscInt size = simCtx->
size;
3249 PetscFunctionBeginUser;
3252 LOG_ALLOW(
GLOBAL,
LOG_INFO,
"Starting full rank communication setup for %" PetscInt_FMT
" block(s).\n", nblk);
3257 for (
int bi = 0; bi < nblk; bi++) {
3264 ierr = PetscMalloc1(size * nblk, &final_bboxlist); CHKERRQ(ierr);
3267 for (
int bi = 0; bi < nblk; bi++) {
3285 for (
int r = 0; r < size; r++) {
3287 final_bboxlist[bi * size + r] = block_bboxlist[r];
3293 free(block_bboxlist);
3306 PetscFunctionReturn(0);
3315 PetscErrorCode ierr;
3317 Cmpnts ***lcsi_arr, ***leta_arr, ***lzet_arr;
3320 PetscReal ***lnvert_arr;
3321 PetscReal ***laj_arr;
3323 PetscFunctionBeginUser;
3332 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE,
"Contra2Cart requires lUcont, lCsi/Eta/Zet, lNvert, and Ucat to be non-NULL.");
3337 ierr = DMDAVecGetArrayRead(user->
fda, user->
lUcont, &lucont_arr); CHKERRQ(ierr);
3338 ierr = DMDAVecGetArrayRead(user->
fda, user->
lCsi, &lcsi_arr); CHKERRQ(ierr);
3339 ierr = DMDAVecGetArrayRead(user->
fda, user->
lEta, &leta_arr); CHKERRQ(ierr);
3340 ierr = DMDAVecGetArrayRead(user->
fda, user->
lZet, &lzet_arr); CHKERRQ(ierr);
3341 ierr = DMDAVecGetArrayRead(user->
da, user->
lNvert, &lnvert_arr); CHKERRQ(ierr);
3342 ierr = DMDAVecGetArrayRead(user->
da, user->
lAj, &laj_arr); CHKERRQ(ierr);
3347 ierr = DMDAVecGetArray(user->
fda, user->
Ucat, &gucat_arr); CHKERRQ(ierr);
3354 PetscInt i_start = (info.xs == 0) ? info.xs + 1 : info.xs;
3355 PetscInt i_end = (info.xs + info.xm == info.mx) ? info.xs + info.xm - 1 : info.xs + info.xm;
3357 PetscInt j_start = (info.ys == 0) ? info.ys + 1 : info.ys;
3358 PetscInt j_end = (info.ys + info.ym == info.my) ? info.ys + info.ym - 1 : info.ys + info.ym;
3360 PetscInt k_start = (info.zs == 0) ? info.zs + 1 : info.zs;
3361 PetscInt k_end = (info.zs + info.zm == info.mz) ? info.zs + info.zm - 1 : info.zs + info.zm;
3365 for (PetscInt k_cell = k_start; k_cell < k_end; ++k_cell) {
3366 for (PetscInt j_cell = j_start; j_cell < j_end; ++j_cell) {
3367 for (PetscInt i_cell = i_start; i_cell < i_end; ++i_cell) {
3372 const Cmpnts centre = {0.5, 0.5, 0.5};
3374 centre, &gucat_arr[k_cell][j_cell][i_cell]); CHKERRQ(ierr);
3380 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lUcont, &lucont_arr); CHKERRQ(ierr);
3381 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lCsi, &lcsi_arr); CHKERRQ(ierr);
3382 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lEta, &leta_arr); CHKERRQ(ierr);
3383 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lZet, &lzet_arr); CHKERRQ(ierr);
3384 ierr = DMDAVecRestoreArrayRead(user->
da, user->
lNvert, &lnvert_arr); CHKERRQ(ierr);
3385 ierr = DMDAVecRestoreArrayRead(user->
da, user->
lAj, &laj_arr); CHKERRQ(ierr);
3386 ierr = DMDAVecRestoreArray(user->
fda, user->
Ucat, &gucat_arr); CHKERRQ(ierr);
3390 PetscFunctionReturn(0);
3398 PetscErrorCode ierr;
3400 const Cmpnts ***ucat_arr, ***csi_arr, ***eta_arr, ***zet_arr;
3403 PetscFunctionBeginUser;
3407 ierr = DMDAVecGetArrayRead(user->
fda, user->
lUcat, &ucat_arr); CHKERRQ(ierr);
3408 ierr = DMDAVecGetArrayRead(user->
fda, user->
lCsi, &csi_arr); CHKERRQ(ierr);
3409 ierr = DMDAVecGetArrayRead(user->
fda, user->
lEta, &eta_arr); CHKERRQ(ierr);
3410 ierr = DMDAVecGetArrayRead(user->
fda, user->
lZet, &zet_arr); CHKERRQ(ierr);
3411 ierr = DMDAVecGetArray(user->
fda, user->
Ucont, &ucont_arr); CHKERRQ(ierr);
3413 const PetscInt i_start = PetscMax(info.xs, 1);
3414 const PetscInt j_start = PetscMax(info.ys, 1);
3415 const PetscInt k_start = PetscMax(info.zs, 1);
3416 const PetscInt i_end = PetscMin(info.xs + info.xm, info.mx - 1);
3417 const PetscInt j_end = PetscMin(info.ys + info.ym, info.my - 1);
3418 const PetscInt k_end = PetscMin(info.zs + info.zm, info.mz - 1);
3420 for (PetscInt k = k_start; k < k_end; k++) {
3421 for (PetscInt j = j_start; j < j_end; j++) {
3422 for (PetscInt i = i_start; i < i_end; i++) {
3424 0.5 * (ucat_arr[k][j][i].
x + ucat_arr[k][j][i + 1].
x),
3425 0.5 * (ucat_arr[k][j][i].y + ucat_arr[k][j][i + 1].y),
3426 0.5 * (ucat_arr[k][j][i].
z + ucat_arr[k][j][i + 1].
z)
3429 0.5 * (ucat_arr[k][j][i].
x + ucat_arr[k][j + 1][i].
x),
3430 0.5 * (ucat_arr[k][j][i].y + ucat_arr[k][j + 1][i].y),
3431 0.5 * (ucat_arr[k][j][i].
z + ucat_arr[k][j + 1][i].
z)
3434 0.5 * (ucat_arr[k][j][i].
x + ucat_arr[k + 1][j][i].
x),
3435 0.5 * (ucat_arr[k][j][i].y + ucat_arr[k + 1][j][i].y),
3436 0.5 * (ucat_arr[k][j][i].
z + ucat_arr[k + 1][j][i].
z)
3438 ucont_arr[k][j][i].
x = csi_arr[k][j][i].
x * u_xi.
x + csi_arr[k][j][i].
y * u_xi.
y + csi_arr[k][j][i].
z * u_xi.
z;
3439 ucont_arr[k][j][i].
y = eta_arr[k][j][i].
x * u_eta.
x + eta_arr[k][j][i].
y * u_eta.
y + eta_arr[k][j][i].
z * u_eta.
z;
3440 ucont_arr[k][j][i].
z = zet_arr[k][j][i].
x * u_zeta.
x + zet_arr[k][j][i].
y * u_zeta.
y + zet_arr[k][j][i].
z * u_zeta.
z;
3445 ierr = DMDAVecRestoreArray(user->
fda, user->
Ucont, &ucont_arr); CHKERRQ(ierr);
3446 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lZet, &zet_arr); CHKERRQ(ierr);
3447 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lEta, &eta_arr); CHKERRQ(ierr);
3448 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lCsi, &csi_arr); CHKERRQ(ierr);
3449 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lUcat, &ucat_arr); CHKERRQ(ierr);
3452 PetscFunctionReturn(0);
3469 PetscErrorCode ierr;
3470 DMDALocalInfo local_node_info;
3472 PetscMPIInt rank, size;
3474 PetscFunctionBeginUser;
3479 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"UserCtx pointer is NULL in SetupDomainCellDecompositionMap.");
3482 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE,
"user->da is not initialized in SetupDomainCellDecompositionMap.");
3485 rank = PetscGlobalRank;
3486 size = PetscGlobalSize;
3492 local_node_info = user->
info;
3502 LOG_ALLOW(
LOCAL,
LOG_DEBUG,
"[Rank %d] Owns cells: i[%" PetscInt_FMT
", %" PetscInt_FMT
"), j[%" PetscInt_FMT
", %" PetscInt_FMT
"), k[%" PetscInt_FMT
", %" PetscInt_FMT
")\n",
3514 ierr = MPI_Allgather(&my_cell_info,
sizeof(
RankCellInfo), MPI_BYTE,
3516 PETSC_COMM_WORLD); CHKERRQ(ierr);
3518 &user->
RankCellInfoProcs[2], NULL, NULL, NULL, NULL, NULL, NULL); CHKERRQ(ierr);
3523 PetscFunctionReturn(0);
3532PetscErrorCode
BinarySearchInt64(PetscInt n,
const PetscInt64 arr[], PetscInt64 key, PetscBool *found)
3534 PetscInt low = 0, high = n - 1;
3536 PetscFunctionBeginUser;
3541 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"Output pointer 'found' is NULL in PetscBinarySearchInt64.");
3543 if (n > 0 && !arr) {
3544 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"Input array 'arr' is NULL for n > 0.");
3548 *found = PETSC_FALSE;
3551 while (low <= high) {
3553 PetscInt mid = low + (high - low) / 2;
3555 if (arr[mid] == key) {
3556 *found = PETSC_TRUE;
3560 if (arr[mid] < key) {
3568 PetscFunctionReturn(0);
3575static PetscInt
Gidx(PetscInt i, PetscInt j, PetscInt k,
UserCtx *user)
3578 DMDALocalInfo info = user->
info;
3580 PetscInt mx = info.mx, my = info.my;
3583 DMDAGetAO(user->
da, &ao);
3584 nidx=i+j*mx+k*mx*my;
3586 AOApplicationToPetsc(ao,1,&nidx);
3601 PetscErrorCode ierr;
3602 DM da = user->
da, fda = user->
fda;
3603 DMDALocalInfo info = user->
info;
3607 PetscInt xs = info.xs, xe = info.xs + info.xm;
3608 PetscInt ys = info.ys, ye = info.ys + info.ym;
3609 PetscInt zs = info.zs, ze = info.zs + info.zm;
3610 PetscInt mx = info.mx, my = info.my, mz = info.mz;
3612 PetscInt lxs, lys, lzs, lxe, lye, lze;
3616 PetscReal ***div, ***aj, ***nvert;
3624 if (xs==0) lxs = xs+1;
3625 if (ys==0) lys = ys+1;
3626 if (zs==0) lzs = zs+1;
3628 if (xe==mx) lxe = xe-1;
3629 if (ye==my) lye = ye-1;
3630 if (ze==mz) lze = ze-1;
3632 PetscFunctionBeginUser;
3635 DMDAVecGetArray(fda,user->
lUcont, &ucont);
3636 DMDAVecGetArray(da, user->
lAj, &aj);
3637 VecDuplicate(user->
P, &Div);
3638 DMDAVecGetArray(da, Div, &div);
3639 DMDAVecGetArray(da, user->
lNvert, &nvert);
3641 for (k=lzs; k<lze; k++) {
3642 for (j=lys; j<lye; j++) {
3643 for (i=lxs; i<lxe; i++) {
3644 maxdiv = fabs((ucont[k][j][i].x - ucont[k][j][i-1].x +
3645 ucont[k][j][i].y - ucont[k][j-1][i].y +
3646 ucont[k][j][i].z - ucont[k-1][j][i].z)*aj[k][j][i]);
3647 if (nvert[k][j][i] + nvert[k+1][j][i] + nvert[k-1][j][i] +
3648 nvert[k][j+1][i] + nvert[k][j-1][i] +
3649 nvert[k][j][i+1] + nvert[k][j][i-1] > 0.1) maxdiv = 0.;
3650 div[k][j][i] = maxdiv;
3658 for (j=ys; j<ye; j++) {
3659 for (i=xs; i<xe; i++) {
3667 for (j=ys; j<ye; j++) {
3668 for (i=xs; i<xe; i++) {
3676 for (k=zs; k<ze; k++) {
3677 for (j=ys; j<ye; j++) {
3685 for (k=zs; k<ze; k++) {
3686 for (j=ys; j<ye; j++) {
3694 for (k=zs; k<ze; k++) {
3695 for (i=xs; i<xe; i++) {
3703 for (k=zs; k<ze; k++) {
3704 for (i=xs; i<xe; i++) {
3709 DMDAVecRestoreArray(da, Div, &div);
3710 PetscInt MaxFlatIndex;
3712 VecMax(Div, &MaxFlatIndex, &maxdiv);
3714 LOG_ALLOW(
GLOBAL,
LOG_INFO,
"[Step %" PetscInt_FMT
"]] The Maximum Divergence is %e at flat index %" PetscInt_FMT
".\n",ti,maxdiv,MaxFlatIndex);
3720 PetscInt max_location[3] = {-1, -1, -1};
3721 for (k=zs; k<ze; k++) {
3722 for (j=ys; j<ye; j++) {
3723 for (i=xs; i<xe; i++) {
3724 if (
Gidx(i,j,k,user) == MaxFlatIndex) {
3725 max_location[0] = k; max_location[1] = j; max_location[2] = i;
3730 ierr = MPI_Allreduce(MPI_IN_PLACE, max_location, 3, MPIU_INT, MPI_MAX, PETSC_COMM_WORLD); CHKERRMPI(ierr);
3734 LOG_ALLOW(
GLOBAL,
LOG_INFO,
"[Step %" PetscInt_FMT
"] The Maximum Divergence(%e) is at location [%" PetscInt_FMT
"][%" PetscInt_FMT
"][%" PetscInt_FMT
"]. \n", ti, maxdiv, max_location[0], max_location[1], max_location[2]);
3737 DMDAVecRestoreArray(da, user->
lNvert, &nvert);
3738 DMDAVecRestoreArray(fda, user->
lUcont, &ucont);
3739 DMDAVecRestoreArray(da, user->
lAj, &aj);
3743 PetscFunctionReturn(0);
3757 PetscReal dPhi_dcsi,
3758 PetscReal dPhi_deta,
3759 PetscReal dPhi_dzet,
3764 gradPhi->
x = jacobian * (dPhi_dcsi * csi_metrics.
x + dPhi_deta * eta_metrics.
x + dPhi_dzet * zet_metrics.
x);
3767 gradPhi->
y = jacobian * (dPhi_dcsi * csi_metrics.
y + dPhi_deta * eta_metrics.
y + dPhi_dzet * zet_metrics.
y);
3770 gradPhi->
z = jacobian * (dPhi_dcsi * csi_metrics.
z + dPhi_deta * eta_metrics.
z + dPhi_dzet * zet_metrics.
z);
3782 dudx->
x = jacobian * (deriv_csi.
x * csi_metrics.
x + deriv_eta.
x * eta_metrics.
x + deriv_zet.
x * zet_metrics.
x);
3783 dudx->
y = jacobian * (deriv_csi.
x * csi_metrics.
y + deriv_eta.
x * eta_metrics.
y + deriv_zet.
x * zet_metrics.
y);
3784 dudx->
z = jacobian * (deriv_csi.
x * csi_metrics.
z + deriv_eta.
x * eta_metrics.
z + deriv_zet.
x * zet_metrics.
z);
3786 dvdx->
x = jacobian * (deriv_csi.
y * csi_metrics.
x + deriv_eta.
y * eta_metrics.
x + deriv_zet.
y * zet_metrics.
x);
3787 dvdx->
y = jacobian * (deriv_csi.
y * csi_metrics.
y + deriv_eta.
y * eta_metrics.
y + deriv_zet.
y * zet_metrics.
y);
3788 dvdx->
z = jacobian * (deriv_csi.
y * csi_metrics.
z + deriv_eta.
y * eta_metrics.
z + deriv_zet.
y * zet_metrics.
z);
3790 dwdx->
x = jacobian * (deriv_csi.
z * csi_metrics.
x + deriv_eta.
z * eta_metrics.
x + deriv_zet.
z * zet_metrics.
x);
3791 dwdx->
y = jacobian * (deriv_csi.
z * csi_metrics.
y + deriv_eta.
z * eta_metrics.
y + deriv_zet.
z * zet_metrics.
y);
3792 dwdx->
z = jacobian * (deriv_csi.
z * csi_metrics.
z + deriv_eta.
z * eta_metrics.
z + deriv_zet.
z * zet_metrics.
z);
3800 PetscReal ***field_data,
Cmpnts *grad)
3802 PetscErrorCode ierr;
3803 Cmpnts ***csi, ***eta, ***zet;
3805 PetscReal d_csi, d_eta, d_zet;
3807 PetscFunctionBeginUser;
3811 ierr = DMDAVecGetArrayRead(user->
fda, user->
lCsi, &csi); CHKERRQ(ierr);
3812 ierr = DMDAVecGetArrayRead(user->
fda, user->
lEta, &eta); CHKERRQ(ierr);
3813 ierr = DMDAVecGetArrayRead(user->
fda, user->
lZet, &zet); CHKERRQ(ierr);
3814 ierr = DMDAVecGetArrayRead(user->
da, user->
lAj, &jac); CHKERRQ(ierr);
3818 d_csi = 0.5 * (field_data[k][j][i+1] - field_data[k][j][i-1]);
3819 d_eta = 0.5 * (field_data[k][j+1][i] - field_data[k][j-1][i]);
3820 d_zet = 0.5 * (field_data[k+1][j][i] - field_data[k-1][j][i]);
3824 csi[k][j][i], eta[k][j][i], zet[k][j][i],
3825 d_csi, d_eta, d_zet,
3829 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lCsi, &csi); CHKERRQ(ierr);
3830 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lEta, &eta); CHKERRQ(ierr);
3831 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lZet, &zet); CHKERRQ(ierr);
3832 ierr = DMDAVecRestoreArrayRead(user->
da, user->
lAj, &jac); CHKERRQ(ierr);
3835 PetscFunctionReturn(0);
3845 PetscErrorCode ierr;
3846 Cmpnts ***csi, ***eta, ***zet;
3848 PetscFunctionBeginUser;
3851 ierr = DMDAVecGetArrayRead(user->
fda, user->
lCsi, &csi); CHKERRQ(ierr);
3852 ierr = DMDAVecGetArrayRead(user->
fda, user->
lEta, &eta); CHKERRQ(ierr);
3853 ierr = DMDAVecGetArrayRead(user->
fda, user->
lZet, &zet); CHKERRQ(ierr);
3854 ierr = DMDAVecGetArrayRead(user->
da, user->
lAj, &jac); CHKERRQ(ierr);
3857 Cmpnts deriv_csi, deriv_eta, deriv_zet;
3858 deriv_csi.
x = (field_data[k][j][i+1].
x - field_data[k][j][i-1].
x) * 0.5;
3859 deriv_csi.
y = (field_data[k][j][i+1].
y - field_data[k][j][i-1].
y) * 0.5;
3860 deriv_csi.
z = (field_data[k][j][i+1].
z - field_data[k][j][i-1].
z) * 0.5;
3862 deriv_eta.
x = (field_data[k][j+1][i].
x - field_data[k][j-1][i].
x) * 0.5;
3863 deriv_eta.
y = (field_data[k][j+1][i].
y - field_data[k][j-1][i].
y) * 0.5;
3864 deriv_eta.
z = (field_data[k][j+1][i].
z - field_data[k][j-1][i].
z) * 0.5;
3866 deriv_zet.
x = (field_data[k+1][j][i].
x - field_data[k-1][j][i].
x) * 0.5;
3867 deriv_zet.
y = (field_data[k+1][j][i].
y - field_data[k-1][j][i].
y) * 0.5;
3868 deriv_zet.
z = (field_data[k+1][j][i].
z - field_data[k-1][j][i].
z) * 0.5;
3872 deriv_csi, deriv_eta, deriv_zet,
3876 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lCsi, &csi); CHKERRQ(ierr);
3877 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lEta, &eta); CHKERRQ(ierr);
3878 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lZet, &zet); CHKERRQ(ierr);
3879 ierr = DMDAVecRestoreArrayRead(user->
da, user->
lAj, &jac); CHKERRQ(ierr);
3881 PetscFunctionReturn(0);
3896 PetscErrorCode ierr;
3897 PetscFunctionBeginUser;
3901 if (user->
Ucont) { ierr = VecDestroy(&user->
Ucont); CHKERRQ(ierr); }
3902 if (user->
lUcont) { ierr = VecDestroy(&user->
lUcont); CHKERRQ(ierr); }
3903 if (user->
Ucat) { ierr = VecDestroy(&user->
Ucat); CHKERRQ(ierr); }
3904 if (user->
lUcat) { ierr = VecDestroy(&user->
lUcat); CHKERRQ(ierr); }
3905 if (user->
P) { ierr = VecDestroy(&user->
P); CHKERRQ(ierr); }
3906 if (user->
lP) { ierr = VecDestroy(&user->
lP); CHKERRQ(ierr); }
3907 if (user->
Nvert) { ierr = VecDestroy(&user->
Nvert); CHKERRQ(ierr); }
3908 if (user->
lNvert) { ierr = VecDestroy(&user->
lNvert); CHKERRQ(ierr); }
3917 if (user->
Phi) { ierr = VecDestroy(&user->
Phi); CHKERRQ(ierr); }
3918 if (user->
lPhi) { ierr = VecDestroy(&user->
lPhi); CHKERRQ(ierr); }
3921 if (user->
Ucont_o) { ierr = VecDestroy(&user->
Ucont_o); CHKERRQ(ierr); }
3923 if (user->
Ucat_o) { ierr = VecDestroy(&user->
Ucat_o); CHKERRQ(ierr); }
3924 if (user->
P_o) { ierr = VecDestroy(&user->
P_o); CHKERRQ(ierr); }
3925 if (user->
Nvert_o) { ierr = VecDestroy(&user->
Nvert_o); CHKERRQ(ierr); }
3931 if (user->
Csi) { ierr = VecDestroy(&user->
Csi); CHKERRQ(ierr); }
3932 if (user->
Eta) { ierr = VecDestroy(&user->
Eta); CHKERRQ(ierr); }
3933 if (user->
Zet) { ierr = VecDestroy(&user->
Zet); CHKERRQ(ierr); }
3934 if (user->
Aj) { ierr = VecDestroy(&user->
Aj); CHKERRQ(ierr); }
3935 if (user->
lCsi) { ierr = VecDestroy(&user->
lCsi); CHKERRQ(ierr); }
3936 if (user->
lEta) { ierr = VecDestroy(&user->
lEta); CHKERRQ(ierr); }
3937 if (user->
lZet) { ierr = VecDestroy(&user->
lZet); CHKERRQ(ierr); }
3938 if (user->
lAj) { ierr = VecDestroy(&user->
lAj); CHKERRQ(ierr); }
3941 if (user->
ICsi) { ierr = VecDestroy(&user->
ICsi); CHKERRQ(ierr); }
3942 if (user->
IEta) { ierr = VecDestroy(&user->
IEta); CHKERRQ(ierr); }
3943 if (user->
IZet) { ierr = VecDestroy(&user->
IZet); CHKERRQ(ierr); }
3944 if (user->
JCsi) { ierr = VecDestroy(&user->
JCsi); CHKERRQ(ierr); }
3945 if (user->
JEta) { ierr = VecDestroy(&user->
JEta); CHKERRQ(ierr); }
3946 if (user->
JZet) { ierr = VecDestroy(&user->
JZet); CHKERRQ(ierr); }
3947 if (user->
KCsi) { ierr = VecDestroy(&user->
KCsi); CHKERRQ(ierr); }
3948 if (user->
KEta) { ierr = VecDestroy(&user->
KEta); CHKERRQ(ierr); }
3949 if (user->
KZet) { ierr = VecDestroy(&user->
KZet); CHKERRQ(ierr); }
3950 if (user->
IAj) { ierr = VecDestroy(&user->
IAj); CHKERRQ(ierr); }
3951 if (user->
JAj) { ierr = VecDestroy(&user->
JAj); CHKERRQ(ierr); }
3952 if (user->
KAj) { ierr = VecDestroy(&user->
KAj); CHKERRQ(ierr); }
3953 if (user->
lICsi) { ierr = VecDestroy(&user->
lICsi); CHKERRQ(ierr); }
3954 if (user->
lIEta) { ierr = VecDestroy(&user->
lIEta); CHKERRQ(ierr); }
3955 if (user->
lIZet) { ierr = VecDestroy(&user->
lIZet); CHKERRQ(ierr); }
3956 if (user->
lJCsi) { ierr = VecDestroy(&user->
lJCsi); CHKERRQ(ierr); }
3957 if (user->
lJEta) { ierr = VecDestroy(&user->
lJEta); CHKERRQ(ierr); }
3958 if (user->
lJZet) { ierr = VecDestroy(&user->
lJZet); CHKERRQ(ierr); }
3959 if (user->
lKCsi) { ierr = VecDestroy(&user->
lKCsi); CHKERRQ(ierr); }
3960 if (user->
lKEta) { ierr = VecDestroy(&user->
lKEta); CHKERRQ(ierr); }
3961 if (user->
lKZet) { ierr = VecDestroy(&user->
lKZet); CHKERRQ(ierr); }
3962 if (user->
lIAj) { ierr = VecDestroy(&user->
lIAj); CHKERRQ(ierr); }
3963 if (user->
lJAj) { ierr = VecDestroy(&user->
lJAj); CHKERRQ(ierr); }
3964 if (user->
lKAj) { ierr = VecDestroy(&user->
lKAj); CHKERRQ(ierr); }
3967 if (user->
Cent) { ierr = VecDestroy(&user->
Cent); CHKERRQ(ierr); }
3968 if (user->
lCent) { ierr = VecDestroy(&user->
lCent); CHKERRQ(ierr); }
3970 if (user->
Centx) { ierr = VecDestroy(&user->
Centx); CHKERRQ(ierr); }
3971 if (user->
Centy) { ierr = VecDestroy(&user->
Centy); CHKERRQ(ierr); }
3972 if (user->
Centz) { ierr = VecDestroy(&user->
Centz); CHKERRQ(ierr); }
3973 if (user->
lCentx) { ierr = VecDestroy(&user->
lCentx); CHKERRQ(ierr); }
3974 if (user->
lCenty) { ierr = VecDestroy(&user->
lCenty); CHKERRQ(ierr); }
3975 if (user->
lCentz) { ierr = VecDestroy(&user->
lCentz); CHKERRQ(ierr); }
3978 if (user->
Nu_t) { ierr = VecDestroy(&user->
Nu_t); CHKERRQ(ierr); }
3979 if (user->
lNu_t) { ierr = VecDestroy(&user->
lNu_t); CHKERRQ(ierr); }
3980 if (user->
CS) { ierr = VecDestroy(&user->
CS); CHKERRQ(ierr); }
3981 if (user->
lCs) { ierr = VecDestroy(&user->
lCs); CHKERRQ(ierr); }
3992 if (user->
Psi) { ierr = VecDestroy(&user->
Psi); CHKERRQ(ierr); }
3993 if (user->
lPsi) { ierr = VecDestroy(&user->
lPsi); CHKERRQ(ierr); }
3996 if (user->
Bcs.
Ubcs) { ierr = VecDestroy(&user->
Bcs.
Ubcs); CHKERRQ(ierr); }
3997 if (user->
Bcs.
Uch) { ierr = VecDestroy(&user->
Bcs.
Uch); CHKERRQ(ierr); }
4000 if (user->
P_nodal) { ierr = VecDestroy(&user->
P_nodal); CHKERRQ(ierr); }
4002 if (user->
Qcrit) { ierr = VecDestroy(&user->
Qcrit); CHKERRQ(ierr); }
4003 if (user->
lQcrit) { ierr = VecDestroy(&user->
lQcrit); CHKERRQ(ierr); }
4011 for (PetscInt w = 0; w < window_count; ++w) {
4029 if (user->
Rhs) { ierr = VecDestroy(&user->
Rhs); CHKERRQ(ierr); }
4030 if (user->
dUcont) { ierr = VecDestroy(&user->
dUcont); CHKERRQ(ierr); }
4031 if (user->
pUcont) { ierr = VecDestroy(&user->
pUcont); CHKERRQ(ierr); }
4032 if (user->
pRhs) { ierr = VecDestroy(&user->
pRhs); CHKERRQ(ierr); }
4035 if (user->
B) { ierr = VecDestroy(&user->
B); CHKERRQ(ierr); }
4036 if (user->
R) { ierr = VecDestroy(&user->
R); CHKERRQ(ierr); }
4040 PetscFunctionReturn(0);
4048 PetscErrorCode ierr;
4049 PetscFunctionBeginUser;
4055 PetscFunctionReturn(0);
4073 ierr = MatDestroy(&user->
A); CHKERRQ(ierr);
4077 ierr = MatDestroy(&user->
MR); CHKERRQ(ierr);
4081 ierr = MatDestroy(&user->
MP); CHKERRQ(ierr);
4085 ierr = KSPDestroy(&user->
ksp); CHKERRQ(ierr);
4089 ierr = MatNullSpaceDestroy(&user->
nullsp); CHKERRQ(ierr);
4095 ierr = AODestroy(&user->
ao); CHKERRQ(ierr);
4102 ierr = DMDestroy(&user->
post_swarm); CHKERRQ(ierr);
4106 ierr = DMDestroy(&user->
swarm); CHKERRQ(ierr);
4110 ierr = DMDestroy(&user->
fda6); CHKERRQ(ierr);
4114 ierr = DMDestroy(&user->
da); CHKERRQ(ierr);
4128 PetscFunctionReturn(0);
4139 PetscErrorCode ierr;
4140 PetscFunctionBeginUser;
4146 PetscFunctionReturn(0);
4169 for (PetscInt level = simCtx->
usermg.
mglevels - 1; level >= 0; level--) {
4177 ierr = PetscFree(user); CHKERRQ(ierr);
4189 ierr = PetscFree(simCtx->
usermg.
mgctx); CHKERRQ(ierr);
4199 ierr = DMDestroy(&simCtx->
usermg.
packer); CHKERRQ(ierr);
4216 ierr = PetscViewerDestroy(&simCtx->
logviewer); CHKERRQ(ierr);
4222 ierr = DMDestroy(&simCtx->
dm_swarm); CHKERRQ(ierr);
4228 ierr = PetscFree(simCtx->
bboxlist); CHKERRQ(ierr);
4237 ierr = PetscFree(simCtx->
bcs_files[i]); CHKERRQ(ierr);
4240 ierr = PetscFree(simCtx->
bcs_files); CHKERRQ(ierr);
4249 ierr = PetscFree(simCtx->
pps); CHKERRQ(ierr);
4257 if (simCtx->
ibm != NULL) {
4258 LOG_ALLOW(
GLOBAL,
LOG_WARNING,
" WARNING: simCtx->ibm is non-NULL but no destroy function exists. Potential memory leak.\n");
4260 if (simCtx->
ibmv != NULL) {
4261 LOG_ALLOW(
GLOBAL,
LOG_WARNING,
" WARNING: simCtx->ibmv is non-NULL but no destroy function exists. Potential memory leak.\n");
4263 if (simCtx->
fsi != NULL) {
4264 LOG_ALLOW(
GLOBAL,
LOG_WARNING,
" WARNING: simCtx->fsi is non-NULL but no destroy function exists. Potential memory leak.\n");
4271 for (PetscInt i = 0; i < simCtx->
nAllowed; i++) {
4273 ierr = PetscFree(simCtx->
allowedFuncs[i]); CHKERRQ(ierr);
4281 ierr = PetscFree(simCtx->
tracePIDs); CHKERRQ(ierr);
4312 ierr = PetscFree(simCtx); CHKERRQ(ierr);
4314 PetscFunctionReturn(0);
PetscErrorCode AnalyticalFieldDestroy(SimCtx *simCtx)
Release what AnalyticalSolutionEngine() keeps from step to step, if anything.
PetscErrorCode BoundarySystem_Initialize(UserCtx *user, const char *bcs_filename)
Initializes the entire boundary system.
PetscErrorCode PropagateBoundaryConfigToCoarserLevels(SimCtx *simCtx)
Propagates boundary condition configuration from finest to all coarser multigrid levels.
PetscErrorCode BoundarySystem_Destroy(UserCtx *user)
Cleans up and destroys all boundary system resources.
PetscErrorCode CalculateAllGridMetrics(SimCtx *simCtx)
Orchestrates the calculation of all grid metrics.
PetscErrorCode MetricDestroyFacePlanes(UserCtx *user)
Frees the face-plane fields MetricComputeFacePlanes() built, if any.
Configured initial values of particle-carried fields.
PetscErrorCode ParticleFieldPlanDestroy(ParticleFieldPlan **plan)
Free a plan and its compiled expressions.
PetscErrorCode ParticleFieldPlanCreate(const char *prefix, ParticleFieldPlan **plan)
Read a plan from the options database.
PetscErrorCode ParticleInletsDestroy(SimCtx *simCtx)
Release what ParticleInletsCreate() and InjectParticlesAtInlets() allocated.
PetscErrorCode ParticleInletsCreate(SimCtx *simCtx)
Read the inlets that inject particles from the options database.
@ FIELD_CAPABILITY_GHOST_UPDATE
@ FIELD_SYNC_COMPONENT_STAGGERED
unsigned int capabilities
const FieldDescriptor * descriptor
PetscErrorCode FieldGetView(UserCtx *user, FieldId field_id, FieldView *view)
Resolve the existing DM and global/local vectors for one field.
const char * canonical_name
FieldSyncClass sync_class
FieldId
Compile-time identity for a catalogued Eulerian field.
Non-owning runtime objects resolved for one field and UserCtx.
PetscErrorCode DefineAllGridDimensions(SimCtx *simCtx)
Orchestrates the parsing and setting of grid dimensions for all blocks.
PetscErrorCode CalculateOutletProperties(UserCtx *user)
Calculates the center and area of the primary OUTLET face.
PetscErrorCode BroadcastAllBoundingBoxes(UserCtx *user, BoundingBox **bboxlist)
Broadcasts the bounding box information collected on rank 0 to all other ranks.
PetscErrorCode ValidatePeriodicGeometry(UserCtx *user)
Validates that configured geometric periodic seams match by translation.
PetscErrorCode InitializeAllGridDMs(SimCtx *simCtx)
Orchestrates the creation of DMDA objects for every block and multigrid level.
PetscErrorCode AssignAllGridCoordinates(SimCtx *simCtx)
Orchestrates the assignment of physical coordinates to all DMDA objects.
PetscErrorCode CalculateInletProperties(UserCtx *user)
Calculates the center and area of the primary INLET face.
PetscErrorCode GatherAllBoundingBoxes(UserCtx *user, BoundingBox **allBBoxes)
Gathers local bounding boxes from all MPI processes to rank 0.
PetscErrorCode ParsePostProcessingSettings(SimCtx *simCtx)
Initializes post-processing settings from a config file and command-line overrides.
PetscErrorCode ParseScalingInformation(SimCtx *simCtx)
Parses physical scaling parameters from command-line options.
PetscErrorCode 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.
void set_allowed_functions(const char **functionList, int count)
Sets the global list of function names that are allowed to log.
PetscBool is_function_allowed(const char *functionName)
Checks if a given function is in the allow-list.
#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.
#define LOG_ALLOW(scope, level, fmt,...)
Logging macro that checks both the log level and whether the calling function is in the allowed-funct...
PetscErrorCode print_log_level(void)
Prints the current logging level to the console.
#define PROFILE_HELPER_BEGIN
Marks the beginning of a profiled helper: timed only when enabled by name.
#define PROFILE_HELPER_END
Alias of PROFILE_FUNCTION_END for a function that began with PROFILE_HELPER_BEGIN.
#define PROFILE_FUNCTION_END
Marks the end of a profiled code block.
#define LOG(scope, level, fmt,...)
Logging macro for PETSc-based applications with scope control.
PetscErrorCode LoadAllowedFunctionsFromFile(const char filename[], char ***funcsOut, PetscInt *nOut)
Load function names from a text file.
const char * InterpolationMethodToString(InterpolationMethod method)
Returns the display name of a grid-to-particle interpolation method.
PetscErrorCode ProfilingInitialize(SimCtx *simCtx)
Applies the profiling configuration from SimCtx to PICurv's PETSc log events.
@ LOG_ERROR
Critical errors that may halt the program.
@ 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 function: an always-on aggregate timer.
const char * ParticleInitializationToString(ParticleInitializationType ParticleInitialization)
Returns the canonical log token for a particle-initialization mode.
static LogLevel get_log_level(void)
Retrieves the current logging level from the environment variable LOG_LEVEL.
ParticleFieldId
Compile-time identity for a persistent solver-particle field.
@ PARTICLE_FIELD_ID_COUNT
PetscErrorCode ParticleFieldGetDescriptor(ParticleFieldId field_id, const ParticleFieldDescriptor **descriptor)
Return immutable metadata for a valid particle field ID.
Immutable metadata for one persistent particle field.
PetscErrorCode ComputeVectorFieldDerivatives(UserCtx *user, PetscInt i, PetscInt j, PetscInt k, Cmpnts ***field_data, Cmpnts *dudx, Cmpnts *dvdx, Cmpnts *dwdx)
Implementation of ComputeVectorFieldDerivatives().
int PicurvCheckLinkedPetscIndexWidth(int argc, char **argv, const char *executable_name)
Implementation of PicurvCheckLinkedPetscIndexWidth().
static const char * kReservedRunDirectories[]
Directory names the run tree owns; a log directory must never target one.
@ DIR_VERDICT_RELATIVE_ESCAPE
@ DIR_VERDICT_UNRESOLVABLE
@ DIR_VERDICT_UNEXPANDED_TILDE
@ DIR_VERDICT_EXTERNAL_ABSOLUTE
PetscErrorCode DestroyUserContext(UserCtx *user)
Implementation of DestroyUserContext().
static PetscBool LogDirectoryIsSafeToWipe(const char *log_dir, const char *output_dir, PetscBool authorized, const char **reason)
Final safety guard before the runtime deletes its log directory.
PetscErrorCode GetOwnedCellRange(const DMDALocalInfo *info_nodes, PetscInt dim, PetscInt *xs_cell_global_out, PetscInt *xm_cell_local_out)
Implementation of GetOwnedCellRange().
const char picurv_build_stamp[]
static PetscErrorCode ParseLESConfiguration(SimCtx *simCtx)
Reads every LES closure parameter from the generated control file.
#define PICURV_PETSC_MODE
PetscErrorCode SetupDomainRankInfo(SimCtx *simCtx)
Implementation of SetupDomainRankInfo().
#define PICURV_PETSC_INDICES
PetscErrorCode Deallocate3DArrayVector(Cmpnts ***array, PetscInt nz, PetscInt ny)
Implementation of Deallocate3DArrayVector().
PetscErrorCode SetupGridAndSolvers(SimCtx *simCtx)
Implementation of SetupGridAndSolvers().
#define PICURV_PETSC_STAMP_MARKER
static PetscInt Gidx(PetscInt i, PetscInt j, PetscInt k, UserCtx *user)
Convert logical indices into the flattened global index used by setup helpers.
PetscErrorCode SetupSimulationEnvironment(SimCtx *simCtx)
Implementation of SetupSimulationEnvironment().
static PetscBool NormalizePathLexically(const char *value, char *out, size_t size, char *stack)
Lexically normalize a path, resolving "." and ".." textually.
static PetscBool PathContainsOrEquals(const char *ancestor, const char *path)
Whether ancestor is the same directory as path, or contains it.
PetscErrorCode CreateAndInitializeAllVectors(SimCtx *simCtx)
Implementation of CreateAndInitializeAllVectors().
PetscErrorCode ComputeAndStoreNeighborRanks(UserCtx *user)
Implementation of ComputeAndStoreNeighborRanks().
PetscErrorCode Contra2Cart(UserCtx *user)
Implementation of Contra2Cart().
static const char picurv_petsc_build_stamp[]
#define PICURV_BUILD_STAMP_MARKER
PetscErrorCode PicurvCheckPetscIntRange(MPI_Comm comm, PetscInt64 entries, const char *object)
Implementation of PicurvCheckPetscIntRange().
void TransformScalarDerivativesToPhysical(PetscReal jacobian, Cmpnts csi_metrics, Cmpnts eta_metrics, Cmpnts zet_metrics, PetscReal dPhi_dcsi, PetscReal dPhi_deta, PetscReal dPhi_dzet, Cmpnts *gradPhi)
Implementation of TransformScalarDerivativesToPhysical().
static PetscErrorCode PetscMkdirRecursive(const char *path)
Create a directory path recursively using PETSc-compatible error handling.
#define PICURV_STRINGIZE(x)
static DirectoryVerdict ClassifyLogDirectory(const char *log_dir, const char *output_dir, const char **reason)
Classify a configured log directory against the working directory.
int PicurvHandleVersionArgument(int argc, char **argv, const char *executable_name)
Implementation of PicurvHandleVersionArgument().
static const char * PicurvExecutableName(int argc, char **argv, const char *fallback)
The name an executable reports itself by: the basename of argv[0].
PetscErrorCode DestroySolutionConvergenceState(SimCtx *simCtx)
Implementation of DestroySolutionConvergenceState().
static PetscBool DirectoryValueIsWellFormed(const char *value)
Whether a configured directory name is safe to write to a PETSc options line.
PetscErrorCode Allocate3DArrayScalar(PetscReal ****array, PetscInt nz, PetscInt ny, PetscInt nx)
Implementation of Allocate3DArrayScalar().
PetscErrorCode CreateSimulationContext(int argc, char **argv, SimCtx **p_simCtx)
Implementation of CreateSimulationContext().
PetscErrorCode InitializeSolutionConvergenceState(SimCtx *simCtx)
Implementation of InitializeSolutionConvergenceState().
PetscErrorCode SetDMDAProcLayout(DM dm, UserCtx *user)
Implementation of SetDMDAProcLayout().
static PetscErrorCode RepairPeriodicNormalFaceGhosts(UserCtx *user, DM dm, Vec local_vec, PetscInt dof, char face_direction, PetscBool component_staggered)
Repairs the adjacent normal ghost layer for periodic face-staggered data.
PetscErrorCode ComputeScalarFieldDerivatives(UserCtx *user, PetscInt i, PetscInt j, PetscInt k, PetscReal ***field_data, Cmpnts *grad)
Implementation of ComputeScalarFieldDerivatives().
PetscErrorCode ComputeDivergence(UserCtx *user)
Implementation of ComputeDivergence().
static PetscBool ResolveDirectoryPhysically(const char *value, const char *cwd, char *out, size_t size, char *scratch)
Resolve a directory that may not exist yet to an absolute physical path.
PetscErrorCode UpdateLocalGhosts(UserCtx *user, FieldId field_id)
Updates a catalogued field's local ghost representation.
static PetscBool DirectoriesOverlap(const char *first, const char *second)
Whether two configured directories denote the same location or nest.
PetscErrorCode BinarySearchInt64(PetscInt n, const PetscInt64 arr[], PetscInt64 key, PetscBool *found)
Implementation of BinarySearchInt64().
static PetscErrorCode AllocateContextHierarchy(SimCtx *simCtx)
Allocate the user-context objects required by every multigrid level.
PetscErrorCode Cart2Contra(UserCtx *user)
Convert a spatially varying Cartesian velocity field to contravariant fluxes.
PetscErrorCode DestroyUserVectors(UserCtx *user)
Implementation of DestroyUserVectors().
PetscErrorCode Allocate3DArrayVector(Cmpnts ****array, PetscInt nz, PetscInt ny, PetscInt nx)
Implementation of Allocate3DArrayVector().
PetscErrorCode SetupBoundaryConditions(SimCtx *simCtx)
Implementation of SetupBoundaryConditions().
static void TransformDerivativesToPhysical(PetscReal jacobian, Cmpnts csi_metrics, Cmpnts eta_metrics, Cmpnts zet_metrics, Cmpnts deriv_csi, Cmpnts deriv_eta, Cmpnts deriv_zet, Cmpnts *dudx, Cmpnts *dvdx, Cmpnts *dwdx)
Transform contravariant vector derivatives into physical Cartesian derivatives.
PetscErrorCode LESConfigSetDefaults(LESConfig *config)
Implementation of LESConfigSetDefaults().
PetscErrorCode SetupDomainCellDecompositionMap(UserCtx *user)
Implementation of SetupDomainCellDecompositionMap().
PetscErrorCode FinalizeSimulation(SimCtx *simCtx)
Implementation of FinalizeSimulation().
PetscErrorCode RepairPeriodicFieldGhosts(UserCtx *user, const FieldView *view, Vec local_vec)
Implementation of RepairPeriodicFieldGhosts().
static PetscBool DirectoryHitsReservedName(const char *value)
Whether a directory's first path segment collides with a reserved run directory.
PetscErrorCode Deallocate3DArrayScalar(PetscReal ***array, PetscInt nz, PetscInt ny)
Implementation of Deallocate3DArrayScalar().
PetscBool RuntimeWalltimeGuardParsePositiveSeconds(const char *text, PetscReal *seconds_out)
Implementation of RuntimeWalltimeGuardParsePositiveSeconds().
static PetscErrorCode ContravariantToCartesianInCell(Cmpnts ***lucont, Cmpnts ***lcsi, Cmpnts ***leta, Cmpnts ***lzet, PetscInt i, PetscInt j, PetscInt k, Cmpnts w, Cmpnts *ucat)
Cartesian velocity at a point of one cell from the cell's face fluxes.
Per-window PETSc accumulator storage and pointwise application.
PetscErrorCode PicurvWindowStorageCreate(UserCtx *user, const PicurvWindowDefinition *definition, PicurvWindowStorage *storage)
Allocates the accumulator state one window owns on one block.
PetscErrorCode PicurvWindowStorageDestroy(PicurvWindowStorage *storage)
Releases accumulator state previously created for one window.
Control ingress for the field-statistics pipeline.
PetscErrorCode DestroyFieldStatisticsConfig(SimCtx *simCtx)
Releases the window definitions resolved by ParseFieldStatisticsConfig() and the ensembles resolved b...
PetscErrorCode ParseFieldStatisticsConfig(SimCtx *simCtx)
Resolves field-statistics configuration from the control file.
PetscBool FieldStatisticsNeedsWorkspace(const struct SimCtx *simCtx)
Reports whether this process derives field statistics of any kind.
PicurvWindowDefinition definition
PetscBool inflowFluctuations
Some inlet adds synthetic fluctuations; their filter state is checkpointed.
PetscInt particlesPerCellMin
Fewest particles in any cell after the step.
PetscInt particleInletCount
Entries of particleInlets.
LESModelType
Identifies the subgrid-scale closure evaluated during a timestep.
PetscBool mom_nk_monitor_history
PetscInt particlesPerCellMax
Most particles in any cell after the step.
Vec Qcrit_nodal
Q-criterion averaged to grid nodes; the field a .vts can place correctly.
PetscInt fieldStatisticsWindowCount
char statistics_output_prefix[256]
basename for CSV output, e.g.
PetscReal yoshizawa_ci
Yoshizawa constant for the reported SGS kinetic energy.
#define RANK_NEIGHBOR_INDEX(di, dj, dk)
Index in RankNeighbors::rank of the neighbour offset (di, dj, dk), each -1, 0 or 1.
PetscBool profilingFinalSummary
char particle_output_prefix[256]
PetscInt dynamic_frequency
Recompute the dynamic coefficient every N steps.
PetscInt LV
Heart-valve flux corrections for immersed bodies; refused at setup.
PetscBool verifyGhostUpdates
-picurv_verify_ghost_updates: test-only cross-checks of skipped or partial ghost updates,...
PetscReal Turbulent_schmidt_number
BoundaryFaceConfig boundary_faces[6]
PetscInt64 searchLocatedCount
LESFilterWidthModel filter_width_model
How the grid filter width Delta is derived per cell.
PetscInt statisticsConsoleOutputFreq
#define PICURV_BUILD_DIRTY
PetscInt64 searchLostCount
PetscReal targetVolumetricFlux
Vec * solutionConvergencePeriodicPRef
PetscBool walltimeGuardActive
LESTestFilterKernel test_filter_kernel
Discrete test-filter stencil.
PetscReal mom_last_lambda_max
PetscReal walltimeGuardWarmupTotalSeconds
LESConfig les_config
Parameters of the LES closure selected by les.
PetscReal forceScalingFactor
PetscReal pseudo_cfl_reduction_factor
SimCtx * simCtx
Back-pointer to the master simulation context.
ParticleInitializationType
Enumerator to identify the particle initialization strategy.
@ PARTICLE_INIT_SURFACE_RANDOM
Random placement on the inlet face.
PetscReal * solutionConvergenceMeanSpeedHistory
PetscBool walltimeGuardHasEWMA
PetscInt nTracePIDs
Number of entries in tracePIDs (at most PICURV_MAX_TRACED_PARTICLES).
PetscBool runtimeMemoryLogEnabled
Enable the rank-reduced runtime memory log (log_dir/Runtime_Memory.csv).
PetscReal boundaryVelocityCorrection
PetscInt64 boundaryClampCount
PetscInt particlesLostLastStep
Particles removed this step because their search failed.
PetscBool inflowFluctuationsRestored
That state was read from the restart checkpoint.
PetscReal walltimeGuardMinSeconds
char allowedFile[PETSC_MAX_PATH_LEN]
Vec * solutionConvergencePeriodicUcatRef
PetscInt64 traversalStepsSum
PetscBool mom_last_converged
PetscReal iem_constant
IEM mixing constant C_IEM in Omega = C_IEM Gamma / Delta^2 (default 2.0).
PetscInt solutionConvergenceSamplesRecorded
PetscReal poissonSourceImbalance
PetscBool drivenFluxTargetLatched
PetscInt64 searchPopulation
char output_dir[PETSC_MAX_PATH_LEN]
PetscBool solutionConvergenceEnabled
PetscReal * solutionConvergenceMeanKEHistory
PetscReal walltimeGuardLatestStepSeconds
PetscInt occupiedCellCount
LESClipMode
Selects the admissible range imposed on the dynamic model coefficient.
char profilingTimestepMode[32]
PetscReal bulkVelocityCorrection
LESTestFilterKernel
Selects the discrete test-filter kernel used by the dynamic procedure.
@ LES_TEST_FILTER_SIMPSON_IK
@ LES_TEST_FILTER_VOLUME_WEIGHTED_BOX
static PetscBool ParticlesEnabled(const SimCtx *simCtx)
Whether the run carries particles: a seeded or restored population, or inlets that inject them.
PetscInt currentSettlementPass
PetscBool fieldStatisticsEnabled
PetscReal max_cs
Ceiling on Cs under LES_CLIP_CLAMP.
LESClipMode clip_mode
Admissible range for the coefficient.
PetscBool no_pseudo_cfl_backtrack
#define PICURV_GIT_COMMIT
PetscBool skipFinalCheckpoint
io.write_final_checkpoint false: no end-of-run bundle.
PetscInt RankCellInfoProcs[3]
DMDA process grid (m, n, p) of RankCellInfoMap: rank i + m (j + n k).
PetscInt rotatefsi
Refused at setup: immersed boundaries and moving bodies are not implemented.
Vec Ubcs
Physical Cartesian velocity at boundary faces. Full 3D array but only boundary-face entries are meani...
@ MOMENTUM_SOLVER_DUALTIME_PICARD_JAMESON_RK
@ MOMENTUM_SOLVER_EXPLICIT_RK
@ MOMENTUM_SOLVER_NEWTON_KRYLOV
PetscInt solutionConvergencePeriodSteps
PetscBool averaging_direction[3]
Averaged-over logical directions (xi, eta, zeta).
PetscReal wale_coefficient
Model constant C_w for WALE (Nicoud & Ducros 1999).
char * current_io_directory
struct PicurvExpression * expression
Compiled expression, or NULL when the field is not configured.
char grid_file[PETSC_MAX_PATH_LEN]
PetscReal particlesExitedScalarLastStep
Sum of Psi over the particles that left the domain this step.
char statistics_pipeline[1024]
e.g.
PetscInt64 bboxGuessFallbackCount
InterpolationMethod interpolationMethod
RankCellInfo * RankCellInfoMap
PetscReal psrc_z
Point source location for PARTICLE_INIT_POINT_SOURCE.
VerificationFieldConfig verificationDiffusivity
PetscInt mom_unconverged_streak
char profilingSelectedFuncsFile[PETSC_MAX_PATH_LEN]
char analysis_dir[PETSC_MAX_PATH_LEN]
char particleRestartMode[16]
PetscInt64 bboxGuessSuccessCount
struct PicurvWindow * fieldStatisticsWindows
char log_dir[PETSC_MAX_PATH_LEN]
PetscInt walltimeGuardCompletedSteps
PetscInt64 maxParticlePassDepth
char source_dir[PETSC_MAX_PATH_LEN]
PetscInt les_gradient_model
Add the Clark gradient (tensor-diffusivity) term to the viscous flux.
PetscInt64 maxTraversalSteps
PetscInt64 particlesLostCumulative
char eulerianSource[PETSC_MAX_PATH_LEN]
PetscBool walltimeGuardEnabled
PetscBool checkpointGeometryHashReady
PetscReal wall_roughness_height
PetscBool useProfilingSelectedFuncsCfg
PetscInt walltimeGuardWarmupSteps
ParticleInitializationType ParticleInitialization
PetscReal mom_dt_jameson_residual_norm_noise_allowance_factor
InterpolationMethod
Selects the grid-to-particle interpolation method.
PetscInt diagnostics_cadence
Steps between diagnostic rows.
PetscReal min_viscosity_ratio
Enforce nu + nu_t >= ratio * nu.
PetscReal particlesPerCellMean
Particles counted in cells divided by the cell count.
PetscInt wallfunction
Enable wall functions on WALL faces.
PetscInt drivingForceStep
LESAveragingMode
Selects the set over which the Germano contractions are averaged.
PetscReal drivenFluxMeasured
#define PICURV_BUILD_VERSION
PetscBool runtimeMemoryLogHasPrevious
True after the first process-memory sample.
char ** profilingSelectedFuncs
PetscBool diagnostics_enabled
Append per-step coefficient statistics to the run log directory.
PetscReal constant_cs
Fixed Cs for CONSTANT_SMAGORINSKY; unused by the dynamic model.
PetscInt64 particlesExitedCumulative
PetscInt solutionConvergenceWindowSteps
PetscInt particlesExitedLastStep
Particles removed this step because they left the domain.
PetscReal test_filter_width_ratio
Test-to-grid ratio per filtered direction; alpha is its square for the box, ratio^(4/3) for Simpson.
PetscReal pseudo_cfl_growth_factor
PetscBool outputParticles
PetscInt mom_max_unconverged_steps
PetscInt nProfilingSelectedFuncs
PetscInt particlesMigratedLastStep
PetscInt particleRandomSeed
Base seed for every particle RNG stream (-particle_random_seed).
char initialConditionDirectory[PETSC_MAX_PATH_LEN]
LESAveragingMode averaging_mode
Averaging set for the Germano contractions.
PetscInt64 * tracePIDs
Sorted, distinct IDs of the particles whose every stage is reported (-picurv_trace_particles); NULL w...
struct PicurvWindowStorage * fieldStatisticsStorage
PetscReal walltimeGuardWarmupAverageSeconds
PetscInt sourceRandomSeed
Seed of the draws in velocity and pressure sources (-source_random_seed).
PetscInt particleConsoleOutputFreq
PetscBool initialConditionStaged
SearchMetricsState searchMetrics
PetscBool skipInitialCheckpoint
io.write_initial_checkpoint false: no initial/branch_start bundle.
char checkpointGeometrySHA256[65]
PetscReal runtimeMemoryLogPreviousProcessMB
Previous local process memory sample in MB.
PetscReal walltimeGuardEWMASeconds
PetscReal vreman_coefficient
Model constant c for VREMAN (Vreman 2004: 2.5 Cs^2).
PetscInt mom_max_pseudo_steps
PetscInt migrationPassesLastStep
InitialConditionField
Selects the authoritative velocity representation in a staged file IC.
@ EXEC_MODE_POSTPROCESSOR
char _io_context_buffer[PETSC_MAX_PATH_LEN]
PetscReal walltimeGuardLimitSeconds
PetscBool ps_ksp_pic_monitor_true_residual
PetscBool profilingAllHelpers
-profiling_helpers all: every helper timer is enabled.
PetscReal walltimeGuardEstimatorAlpha
PetscInt les
Active LES closure; an LESModelType value.
Vec lQcrit
Cell-centred Q-criterion and its ghosted copy for nodal averaging.
@ SOLUTION_CONVERGENCE_TRANSIENT
@ SOLUTION_CONVERGENCE_PERIODIC_DETERMINISTIC
@ SOLUTION_CONVERGENCE_STATISTICAL_STEADY
@ SOLUTION_CONVERGENCE_STEADY_DETERMINISTIC
PetscReal mom_ratio_ema_alpha
SolutionConvergenceMode solutionConvergenceMode
char ** profilingHelpers
Helper functions whose timers are enabled (-profiling_helpers).
PetscReal particlesLostScalarLastStep
Sum of Psi over the particles removed this step as LOST.
PetscInt64 searchAttempts
InitialConditionField initialConditionField
Vec lInflowFluctuation
Inlet fluctuation filter state in the inlet faces' dummy planes.
PetscBool restartHistoryAvailable
PetscReal walltimeGuardMultiplier
PetscInt rotateframe
moveframe/rotateframe are refused at setup.
#define PICURV_MAX_TRACED_PARTICLES
Most particle IDs one run can trace (-picurv_trace_particles).
MomentumSolverType mom_solver_type
PetscInt64 maxTraversalFailCount
char PostprocessingControlFile[PETSC_MAX_PATH_LEN]
char restart_dir[PETSC_MAX_PATH_LEN]
PetscReal walltimeGuardJobStartEpochSeconds
PetscInt nProfilingHelpers
LESFilterWidthModel
Selects how a cell's grid filter width is derived from its metrics.
@ LES_FILTER_WIDTH_SCOTTI
@ LES_FILTER_WIDTH_CUBE_ROOT_VOLUME
PetscInt LoggingFrequency
VerificationFieldConfig verificationScalar
PetscReal drivingForceMagnitude
struct ParticleInlet * particleInlets
Inlet faces that inject particles, or NULL.
PetscReal lastStepWallSeconds
Slowest rank's wall time of the last completed step (0 before one).
PetscReal particleLoadImbalance
struct ParticleFieldPlan * particleFieldPlan
Configured initial particle-field values, or NULL.
PetscBool fieldStatisticsContinue
Vec Uch
Characteristic velocity for boundary conditions.
PetscInt runCsvWrittenCount
Entries of runCsvWritten in use.
Defines a 3D axis-aligned bounding box.
A 3D point or vector with PetscScalar components.
Every user-selectable parameter of the LES closure.
Context for Multigrid operations.
Holds all configuration parameters for a post-processing run.
A lean struct to hold the global cell ownership range for a single MPI rank.
The master context for the entire simulation.
User-defined context containing data specific to a single computational grid level.
User-level context for managing the entire multigrid hierarchy.
PetscErrorCode VerificationFieldsCreate(SimCtx *simCtx)
Reads and compiles the configured verification fields (-verification_*_expr).
PetscBool VerificationScalarOverrideActive(const SimCtx *simCtx)
Reports whether a verification-only scalar override is active.
PetscErrorCode VerificationFieldsDestroy(SimCtx *simCtx)
Releases the compiled verification fields.