10#define TMP_BUF_SIZE 128
64 PetscReal *in = (PetscReal *)invec;
65 PetscReal *inout = (PetscReal *)inoutvec;
103 const char *env = getenv(
"LOG_LEVEL");
107 else if (strcmp(env,
"DEBUG") == 0) {
110 else if (strcmp(env,
"INFO") == 0) {
113 else if (strcmp(env,
"WARNING") == 0) {
116 else if (strcmp(env,
"VERBOSE") == 0) {
119 else if (strcmp(env,
"TRACE") == 0) {
124 if (PetscGlobalRank == 0) {
125 fprintf(stderr,
"[WARNING] Unrecognized LOG_LEVEL '%s'; using ERROR. Valid levels: ERROR, WARNING, INFO, DEBUG, TRACE, VERBOSE.\n", env);
143 const char *level_name;
145 PetscFunctionBeginUser;
148 rank = PetscGlobalRank;
152 level_name = (level ==
LOG_ERROR) ?
"ERROR" :
161 ierr = PetscPrintf(PETSC_COMM_SELF,
162 "Current log level: %s (%d) | rank: %d\n",
163 level_name, level, (
int)rank);
167 PetscFunctionReturn(PETSC_SUCCESS);
194 for (
int i = 0; i < count; ++i) {
236 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"LOG_CELL_VERTICES - Input parameter 'cell' is NULL.");
240 for(
int i = 0; i < 8; i++){
263 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
" Input array 'd' is NULL.");
266 PetscPrintf(PETSC_COMM_SELF,
" Face Distances:\n");
267 PetscPrintf(PETSC_COMM_SELF,
" LEFT(%d): %.15f\n",
LEFT, d[
LEFT]);
268 PetscPrintf(PETSC_COMM_SELF,
" RIGHT(%d): %.15f\n",
RIGHT, d[
RIGHT]);
269 PetscPrintf(PETSC_COMM_SELF,
" BOTTOM(%d): %.15f\n",
BOTTOM, d[
BOTTOM]);
270 PetscPrintf(PETSC_COMM_SELF,
" TOP(%d): %.15f\n",
TOP, d[
TOP]);
271 PetscPrintf(PETSC_COMM_SELF,
" FRONT(%d): %.15f\n",
FRONT, d[
FRONT]);
272 PetscPrintf(PETSC_COMM_SELF,
" BACK(%d): %.15f\n",
BACK, d[
BACK]);
281static void IntToStr(
int value,
char *buf,
size_t bufsize)
284 snprintf(buf, bufsize,
"%d", value);
291static void Int64ToStr(PetscInt64 value,
char *buf,
size_t bufsize)
294 snprintf(buf, bufsize,
"%" PetscInt64_FMT, value);
301static void CellToStr(
const PetscInt *cell,
char *buf,
size_t bufsize)
304 snprintf(buf, bufsize,
"(%" PetscInt_FMT
", %" PetscInt_FMT
", %" PetscInt_FMT
")", cell[0], cell[1], cell[2]);
314 snprintf(buf, bufsize,
"(%.4f, %.4f, %.4f)", arr[0], arr[1], arr[2]);
325 const PetscMPIInt *ranks,
326 const PetscInt64 *pids,
327 const PetscInt *cellIDs,
328 const PetscReal *positions,
329 const PetscReal *velocities,
330 const PetscReal *weights,
336 widths[0] = (int)strlen(
"Rank");
337 widths[1] = (int)strlen(
"PID");
338 widths[2] = (int)strlen(
"Cell (i,j,k)");
339 widths[3] = (int)strlen(
"Position (x,y,z)");
340 widths[4] = (int)strlen(
"Velocity (x,y,z)");
341 widths[5] = (int)strlen(
"Weights (a1,a2,a3)");
343 for (PetscInt r = 0; r < nRows; r++) {
344 const PetscInt i = rows[r];
370 snprintf(fmtStr, bufSize,
371 "| %%-%dd | %%-%d" PetscInt64_FMT
" | %%-%ds | %%-%ds | %%-%ds | %%-%ds |\n",
372 widths[0], widths[1], widths[2], widths[3], widths[4], widths[5]);
382 snprintf(headerStr, bufSize,
383 "| %-*s | %-*s | %-*s | %-*s | %-*s | %-*s |\n",
386 widths[2],
"Cell (i,j,k)",
387 widths[3],
"Position (x,y,z)",
388 widths[4],
"Velocity (x,y,z)",
389 widths[5],
"Weights (a1,a2,a3)");
402 DM swarm = user->
swarm;
404 PetscInt localNumParticles;
405 PetscReal *positions = NULL;
406 PetscInt64 *particleIDs = NULL;
407 PetscMPIInt *particleRanks = NULL;
408 PetscInt *cellIDs = NULL;
409 PetscReal *weights = NULL;
410 PetscReal *velocities = NULL;
413 const PetscInt interval = (printInterval > 0) ? printInterval : 1;
415 ierr = DMSwarmGetLocalSize(swarm, &localNumParticles); CHKERRQ(ierr);
426 if (particleIDs[i] % interval == 0) rows[nRows++] = i;
432 positions, velocities, weights, widths); CHKERRQ(ierr);
433 ierr = MPI_Allreduce(MPI_IN_PLACE, widths, 6, MPI_INT, MPI_MAX, PETSC_COMM_WORLD); CHKERRMPI(ierr);
442 ierr = PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"--------------------------------------------------------------------------------------------------------------\n"); CHKERRQ(ierr);
443 ierr = PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"%s", headerFmt); CHKERRQ(ierr);
444 ierr = PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"--------------------------------------------------------------------------------------------------------------\n"); CHKERRQ(ierr);
447 for (PetscInt r = 0; r < nRows; r++) {
448 const PetscInt i = rows[r];
454 snprintf(rowStr,
sizeof(rowStr), rowFmt, particleRanks[i], particleIDs[i], cellStr, posStr, velStr, wtStr);
455 ierr = PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"%s", rowStr); CHKERRQ(ierr);
457 ierr = PetscSynchronizedFlush(PETSC_COMM_WORLD, PETSC_STDOUT); CHKERRQ(ierr);
460 PetscInt64 counts[2] = {(PetscInt64)localNumParticles, (PetscInt64)nRows};
461 ierr = MPI_Allreduce(MPI_IN_PLACE, counts, 2, MPIU_INT64, MPI_SUM, PETSC_COMM_WORLD); CHKERRMPI(ierr);
462 ierr = PetscPrintf(PETSC_COMM_WORLD,
"--------------------------------------------------------------------------------------------------------------\n"); CHKERRQ(ierr);
463 ierr = PetscPrintf(PETSC_COMM_WORLD,
"%lld row(s) of %lld particle(s): IDs that are multiples of %" PetscInt_FMT
", at most %d per rank.\n\n",
505 completed_step > 0 &&
522 PetscFunctionBeginUser;
527 PetscFunctionReturn(0);
541 while (*p && isspace((
unsigned char)*p))
545 memmove(s, p, strlen(p) + 1);
548 size_t len = strlen(s);
549 while (len > 0 && isspace((
unsigned char)s[len - 1]))
569 char line[PETSC_MAX_PATH_LEN];
577 fp = fopen(filename,
"r");
578 if (!fp) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN,
579 "Cannot open %s", filename);
582 ierr = PetscMalloc1(cap, &funcs); CHKERRQ(ierr);
585 while (fgets(line,
sizeof line, fp)) {
587 char *hash = strchr(line,
'#');
588 if (hash) *hash =
'\0';
591 if (!*line)
continue;
596 ierr = PetscRealloc(cap *
sizeof(*funcs), (
void **)&funcs); CHKERRQ(ierr);
600 ierr = PetscStrallocpy(line, &funcs[n++]); CHKERRQ(ierr);
609 PetscFunctionReturn(0);
625 for (PetscInt i = 0; i < n; ++i) {
626 ierr = PetscFree(funcs[i]); CHKERRQ(ierr);
628 ierr = PetscFree(funcs); CHKERRQ(ierr);
631 PetscFunctionReturn(0);
650 default: name =
"Unknown Face";
break;
666 switch(ParticleInitialization){
670 default: name =
"Unknown Particle Initialization";
break;
690 case VREMAN: name =
"Vreman";
break;
691 case WALE: name =
"WALE";
break;
692 default: name =
"Unknown LES Flag";
break;
715 default: name =
"unknown";
break;
734 default: name =
"unknown";
break;
754 default: name =
"unknown";
break;
774 default: name =
"unknown";
break;
796 default: name =
"unknown";
break;
816 default: name =
"Unknown Momentum Solver Type";
break;
832 case WALL: name =
"WALL";
break;
833 case INLET: name =
"INLET";
break;
834 case OUTLET: name =
"OUTLET";
break;
835 case FARFIELD: name =
"FARFIELD";
break;
836 case PERIODIC: name =
"PERIODIC";
break;
837 case INTERFACE: name =
"INTERFACE";
break;
838 default: name =
"Unknown BC Type";
break;
857 default: name =
"Unknown particle boundary policy";
break;
875 case INTERP_FACE_FLUX: name =
"FaceFlux (divergence-free velocity from face fluxes)";
break;
876 default: name =
"Unknown interpolation method";
break;
891 switch (handler_type) {
915 default: name =
"UNKNOWN_HANDLER";
break;
933 PetscFunctionBeginUser;
935 rank = PetscGlobalRank;
942 ierr = PetscFree(monctx); CHKERRQ(ierr);
945 PetscFunctionReturn(0);
959 PetscReal trnorm = 0.0, relnorm;
964 PetscFunctionBeginUser;
966 rank = PetscGlobalRank;
973 ierr = KSPGetRhs(ksp, &b); CHKERRQ(ierr);
976 ierr = KSPGetSolution(ksp, &x); CHKERRQ(ierr);
977 ierr = VecDuplicate(x, &monctx->
residual_work[0]); CHKERRQ(ierr);
978 ierr = VecDuplicate(b, &monctx->
residual_work[1]); CHKERRQ(ierr);
981 ierr = VecNorm(r, NORM_2, &trnorm); CHKERRQ(ierr);
985 ierr = VecNorm(b, NORM_2, &monctx->
bnorm); CHKERRQ(ierr);
990 const PetscBool have_rel = (PetscBool)(monctx->
true_residual && monctx->
bnorm > 1.e-15);
991 relnorm = have_rel ? trnorm / monctx->
bnorm : 0.0;
995 ierr = PetscFPrintf(PETSC_COMM_SELF, monctx->
file_handle,
"%d,%d,%d,%.5e,", (
int)monctx->
step, (
int)monctx->
block_id, (
int)it, (
double)rnorm); CHKERRQ(ierr);
996 if (monctx->
true_residual) { ierr = PetscFPrintf(PETSC_COMM_SELF, monctx->
file_handle,
"%.5e", (
double)trnorm); CHKERRQ(ierr); }
997 ierr = PetscFPrintf(PETSC_COMM_SELF, monctx->
file_handle,
","); CHKERRQ(ierr);
998 if (have_rel) { ierr = PetscFPrintf(PETSC_COMM_SELF, monctx->
file_handle,
"%.5e", (
double)relnorm); CHKERRQ(ierr); }
999 ierr = PetscFPrintf(PETSC_COMM_SELF, monctx->
file_handle,
"\n"); CHKERRQ(ierr);
1003 if (have_rel) sprintf(norm_buf,
"ts: %-5d | block: %-2d | iter: %-3d | Unprecond Norm: %12.5e | True Norm: %12.5e | Rel Norm: %12.5e",(
int)monctx->
step, (
int)monctx->
block_id, (
int)it, (
double)rnorm, (
double)trnorm, (
double)relnorm);
1004 else sprintf(norm_buf,
"ts: %-5d | block: %-2d | iter: %-3d | Unprecond Norm: %12.5e | True Norm: %12.5e",(
int)monctx->
step, (
int)monctx->
block_id, (
int)it, (
double)rnorm, (
double)trnorm);
1005 ierr = PetscFPrintf(PETSC_COMM_SELF, stdout,
"%s\n", norm_buf); CHKERRQ(ierr);
1010 PetscFunctionReturn(0);
1013#define SOLUTION_CONVERGENCE_FLUID_THRESHOLD 0.1
1014#define SOLUTION_CONVERGENCE_REL_EPS 1.0e-30
1077 PetscReal local[3] = {0.0, 0.0, 0.0};
1078 PetscReal global[3] = {0.0, 0.0, 0.0};
1081 PetscFunctionBeginUser;
1083 if (!simCtx || !mean_speed_out || !mean_ke_out) {
1084 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"ComputeCurrentFlowObservables received a NULL argument.");
1089 for (PetscInt bi = 0; bi < simCtx->
block_number; ++bi) {
1090 const DMDALocalInfo info = user[bi].
info;
1094 const PetscInt i_start = PetscMax(info.xs, 1), i_end = PetscMin(info.xs + info.xm, info.mx - 1);
1095 const PetscInt j_start = PetscMax(info.ys, 1), j_end = PetscMin(info.ys + info.ym, info.my - 1);
1096 const PetscInt k_start = PetscMax(info.zs, 1), k_end = PetscMin(info.zs + info.zm, info.mz - 1);
1098 PetscReal ***aj = NULL;
1099 PetscReal ***nvert = NULL;
1101 PetscCall(DMDAVecGetArrayRead(user[bi].fda, user[bi].Ucat, &ucat));
1102 PetscCall(DMDAVecGetArrayRead(user[bi].da, user[bi].Aj, &aj));
1103 PetscCall(DMDAVecGetArrayRead(user[bi].da, user[bi].Nvert, &nvert));
1105 for (PetscInt k = k_start; k < k_end; ++k) {
1106 for (PetscInt j = j_start; j < j_end; ++j) {
1107 for (PetscInt i = i_start; i < i_end; ++i) {
1108 PetscReal jac = aj[k][j][i];
1109 PetscReal cell_volume = 0.0;
1110 PetscReal speed = 0.0;
1114 if (PetscAbsReal(jac) <= 1.0e-14)
continue;
1116 cell_volume = 1.0 / jac;
1117 speed = PetscSqrtReal(ucat[k][j][i].x * ucat[k][j][i].x +
1118 ucat[k][j][i].y * ucat[k][j][i].y +
1119 ucat[k][j][i].z * ucat[k][j][i].z);
1120 ke = 0.5 * speed * speed;
1122 local[0] += cell_volume;
1123 local[1] += speed * cell_volume;
1124 local[2] += ke * cell_volume;
1129 PetscCall(DMDAVecRestoreArrayRead(user[bi].da, user[bi].Nvert, &nvert));
1130 PetscCall(DMDAVecRestoreArrayRead(user[bi].da, user[bi].Aj, &aj));
1131 PetscCall(DMDAVecRestoreArrayRead(user[bi].fda, user[bi].Ucat, &ucat));
1134 PetscCallMPI(MPI_Allreduce(local, global, 3, MPIU_REAL, MPI_SUM, PETSC_COMM_WORLD));
1136 if (global[0] <= 0.0) {
1137 *mean_speed_out = 0.0;
1140 *mean_speed_out = global[1] / global[0];
1141 *mean_ke_out = global[2] / global[0];
1145 PetscFunctionReturn(0);
1194 PetscBool periodic_mode,
1195 PetscInt phase_step,
1196 PetscInt samples_before,
1197 PetscBool *has_reference_out,
1198 PetscReal *u_abs_l2_out,
1199 PetscReal *u_rel_l2_out,
1200 PetscReal *p_abs_l2_out,
1201 PetscReal *p_rel_l2_out,
1202 PetscReal *mean_speed_out,
1203 PetscReal *mean_speed_ref_out,
1204 PetscReal *mean_speed_abs_out,
1205 PetscReal *mean_speed_rel_out,
1206 PetscReal *mean_ke_out,
1207 PetscReal *mean_ke_ref_out,
1208 PetscReal *mean_ke_abs_out,
1209 PetscReal *mean_ke_rel_out)
1215 PetscReal current_pressure_mean = 0.0;
1216 PetscReal reference_pressure_mean = 0.0;
1219 PetscFunctionBeginUser;
1221 if (!simCtx || !has_reference_out || !u_abs_l2_out || !u_rel_l2_out || !p_abs_l2_out || !p_rel_l2_out ||
1222 !mean_speed_out || !mean_speed_ref_out || !mean_speed_abs_out || !mean_speed_rel_out ||
1223 !mean_ke_out || !mean_ke_ref_out || !mean_ke_abs_out || !mean_ke_rel_out) {
1224 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"ComputeDeterministicSolutionMetrics received a NULL output pointer.");
1227 *has_reference_out = periodic_mode
1230 phase_step < simCtx->solutionConvergencePeriodSteps &&
1232 : (PetscBool)(samples_before > 0);
1234 *u_abs_l2_out = 0.0;
1235 *u_rel_l2_out = 0.0;
1236 *p_abs_l2_out = 0.0;
1237 *p_rel_l2_out = 0.0;
1238 *mean_speed_out = 0.0;
1239 *mean_speed_ref_out = 0.0;
1240 *mean_speed_abs_out = 0.0;
1241 *mean_speed_rel_out = 0.0;
1243 *mean_ke_ref_out = 0.0;
1244 *mean_ke_abs_out = 0.0;
1245 *mean_ke_rel_out = 0.0;
1249 for (PetscInt bi = 0; bi < simCtx->
block_number; ++bi) {
1250 const DMDALocalInfo info = user[bi].
info;
1254 const PetscInt i_start = PetscMax(info.xs, 1), i_end = PetscMin(info.xs + info.xm, info.mx - 1);
1255 const PetscInt j_start = PetscMax(info.ys, 1), j_end = PetscMin(info.ys + info.ym, info.my - 1);
1256 const PetscInt k_start = PetscMax(info.zs, 1), k_end = PetscMin(info.zs + info.zm, info.mz - 1);
1258 Cmpnts ***ucat_ref = NULL;
1259 PetscReal ***pressure = NULL;
1260 PetscReal ***pressure_ref = NULL;
1261 PetscReal ***aj = NULL;
1262 PetscReal ***nvert = NULL;
1263 Vec ucat_reference_vec = NULL;
1264 Vec pressure_reference_vec = NULL;
1266 if (*has_reference_out) {
1267 if (periodic_mode) {
1271 ucat_reference_vec = user[bi].
Ucat_o;
1272 pressure_reference_vec = user[bi].
P_o;
1276 PetscCall(DMDAVecGetArrayRead(user[bi].fda, user[bi].Ucat, &ucat));
1277 PetscCall(DMDAVecGetArrayRead(user[bi].da, user[bi].P, &pressure));
1278 PetscCall(DMDAVecGetArrayRead(user[bi].da, user[bi].Aj, &aj));
1279 PetscCall(DMDAVecGetArrayRead(user[bi].da, user[bi].Nvert, &nvert));
1280 if (*has_reference_out) {
1281 PetscCall(DMDAVecGetArrayRead(user[bi].fda, ucat_reference_vec, &ucat_ref));
1282 PetscCall(DMDAVecGetArrayRead(user[bi].da, pressure_reference_vec, &pressure_ref));
1285 for (PetscInt k = k_start; k < k_end; ++k) {
1286 for (PetscInt j = j_start; j < j_end; ++j) {
1287 for (PetscInt i = i_start; i < i_end; ++i) {
1288 PetscReal jac = aj[k][j][i];
1289 PetscReal cell_volume = 0.0;
1290 PetscReal speed = 0.0;
1294 if (PetscAbsReal(jac) <= 1.0e-14)
continue;
1296 cell_volume = 1.0 / jac;
1297 speed = PetscSqrtReal(ucat[k][j][i].x * ucat[k][j][i].x +
1298 ucat[k][j][i].y * ucat[k][j][i].y +
1299 ucat[k][j][i].z * ucat[k][j][i].z);
1300 ke = 0.5 * speed * speed;
1306 ucat[k][j][i].
y * ucat[k][j][i].
y +
1307 ucat[k][j][i].
z * ucat[k][j][i].
z) * cell_volume;
1309 if (*has_reference_out) {
1310 PetscReal ref_speed = PetscSqrtReal(ucat_ref[k][j][i].x * ucat_ref[k][j][i].x +
1311 ucat_ref[k][j][i].y * ucat_ref[k][j][i].y +
1312 ucat_ref[k][j][i].z * ucat_ref[k][j][i].z);
1313 PetscReal ref_ke = 0.5 * ref_speed * ref_speed;
1314 PetscReal dux = ucat[k][j][i].
x - ucat_ref[k][j][i].
x;
1315 PetscReal duy = ucat[k][j][i].
y - ucat_ref[k][j][i].
y;
1316 PetscReal duz = ucat[k][j][i].
z - ucat_ref[k][j][i].
z;
1320 local_pass1.
delta_u_norm_sq += (dux * dux + duy * duy + duz * duz) * cell_volume;
1328 if (*has_reference_out) {
1329 PetscCall(DMDAVecRestoreArrayRead(user[bi].da, pressure_reference_vec, &pressure_ref));
1330 PetscCall(DMDAVecRestoreArrayRead(user[bi].fda, ucat_reference_vec, &ucat_ref));
1332 PetscCall(DMDAVecRestoreArrayRead(user[bi].da, user[bi].Nvert, &nvert));
1333 PetscCall(DMDAVecRestoreArrayRead(user[bi].da, user[bi].Aj, &aj));
1334 PetscCall(DMDAVecRestoreArrayRead(user[bi].da, user[bi].P, &pressure));
1335 PetscCall(DMDAVecRestoreArrayRead(user[bi].fda, user[bi].Ucat, &ucat));
1338 PetscCallMPI(MPI_Allreduce(&local_pass1, &global_pass1,
1340 MPIU_REAL, MPI_SUM, PETSC_COMM_WORLD));
1350 *mean_speed_abs_out = PetscAbsReal(*mean_speed_out - *mean_speed_ref_out);
1353 *mean_ke_abs_out = PetscAbsReal(*mean_ke_out - *mean_ke_ref_out);
1359 for (PetscInt bi = 0; bi < simCtx->
block_number; ++bi) {
1360 const DMDALocalInfo info = user[bi].
info;
1364 const PetscInt i_start = PetscMax(info.xs, 1), i_end = PetscMin(info.xs + info.xm, info.mx - 1);
1365 const PetscInt j_start = PetscMax(info.ys, 1), j_end = PetscMin(info.ys + info.ym, info.my - 1);
1366 const PetscInt k_start = PetscMax(info.zs, 1), k_end = PetscMin(info.zs + info.zm, info.mz - 1);
1367 PetscReal ***pressure = NULL;
1368 PetscReal ***pressure_ref = NULL;
1369 PetscReal ***aj = NULL;
1370 PetscReal ***nvert = NULL;
1373 PetscCall(DMDAVecGetArrayRead(user[bi].da, user[bi].P, &pressure));
1374 PetscCall(DMDAVecGetArrayRead(user[bi].da, pressure_reference_vec, &pressure_ref));
1375 PetscCall(DMDAVecGetArrayRead(user[bi].da, user[bi].Aj, &aj));
1376 PetscCall(DMDAVecGetArrayRead(user[bi].da, user[bi].Nvert, &nvert));
1378 for (PetscInt k = k_start; k < k_end; ++k) {
1379 for (PetscInt j = j_start; j < j_end; ++j) {
1380 for (PetscInt i = i_start; i < i_end; ++i) {
1381 PetscReal jac = aj[k][j][i];
1382 PetscReal cell_volume = 0.0;
1383 PetscReal current_pressure = 0.0;
1384 PetscReal reference_pressure = 0.0;
1385 PetscReal delta_pressure = 0.0;
1388 if (PetscAbsReal(jac) <= 1.0e-14)
continue;
1390 cell_volume = 1.0 / jac;
1391 current_pressure = pressure[k][j][i] - current_pressure_mean;
1392 reference_pressure = pressure_ref[k][j][i] - reference_pressure_mean;
1393 delta_pressure = current_pressure - reference_pressure;
1401 PetscCall(DMDAVecRestoreArrayRead(user[bi].da, user[bi].Nvert, &nvert));
1402 PetscCall(DMDAVecRestoreArrayRead(user[bi].da, user[bi].Aj, &aj));
1403 PetscCall(DMDAVecRestoreArrayRead(user[bi].da, pressure_reference_vec, &pressure_ref));
1404 PetscCall(DMDAVecRestoreArrayRead(user[bi].da, user[bi].P, &pressure));
1407 PetscCallMPI(MPI_Allreduce(&local_pass2, &global_pass2,
1409 MPIU_REAL, MPI_SUM, PETSC_COMM_WORLD));
1417 PetscFunctionReturn(0);
1440 PetscInt samples_available,
1441 PetscInt offset_from_latest)
1447 if (!history || capacity <= 0 || samples_available <= 0 || offset_from_latest < 0) {
1452 count = PetscMin(samples_available, capacity);
1455 index = (samples_available - 1 - offset_from_latest) % capacity;
1456 if (index < 0) index += capacity;
1458 return history[index];
1477 PetscInt samples_before,
1478 PetscReal mean_speed,
1481 PetscInt history_capacity = 0;
1484 PetscFunctionBeginUser;
1487 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"Statistical solution-convergence history is not allocated.");
1491 if (history_capacity <= 0) {
1492 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE,
"Statistical solution-convergence history capacity must be positive.");
1495 slot = samples_before % history_capacity;
1500 PetscFunctionReturn(0);
1559 PetscInt samples_available,
1560 PetscBool *has_reference_out,
1561 PetscReal *mean_speed_window_out,
1562 PetscReal *mean_speed_window_prev_out,
1563 PetscReal *mean_speed_window_abs_out,
1564 PetscReal *mean_speed_window_rel_out,
1565 PetscReal *mean_speed_rms_window_out,
1566 PetscReal *mean_speed_rms_window_prev_out,
1567 PetscReal *mean_speed_rms_window_abs_out,
1568 PetscReal *mean_speed_rms_window_rel_out,
1569 PetscReal *mean_ke_window_out,
1570 PetscReal *mean_ke_window_prev_out,
1571 PetscReal *mean_ke_window_abs_out,
1572 PetscReal *mean_ke_window_rel_out,
1573 PetscReal *mean_ke_rms_window_out,
1574 PetscReal *mean_ke_rms_window_prev_out,
1575 PetscReal *mean_ke_rms_window_abs_out,
1576 PetscReal *mean_ke_rms_window_rel_out)
1579 PetscInt history_capacity = 0;
1580 PetscReal speed_sum = 0.0;
1581 PetscReal speed_sum_sq = 0.0;
1582 PetscReal speed_prev_sum = 0.0;
1583 PetscReal speed_prev_sum_sq = 0.0;
1584 PetscReal ke_sum = 0.0;
1585 PetscReal ke_sum_sq = 0.0;
1586 PetscReal ke_prev_sum = 0.0;
1587 PetscReal ke_prev_sum_sq = 0.0;
1589 PetscFunctionBeginUser;
1591 if (!simCtx || !has_reference_out || !mean_speed_window_out || !mean_speed_window_prev_out ||
1592 !mean_speed_window_abs_out || !mean_speed_window_rel_out || !mean_speed_rms_window_out ||
1593 !mean_speed_rms_window_prev_out || !mean_speed_rms_window_abs_out || !mean_speed_rms_window_rel_out ||
1594 !mean_ke_window_out || !mean_ke_window_prev_out || !mean_ke_window_abs_out || !mean_ke_window_rel_out ||
1595 !mean_ke_rms_window_out || !mean_ke_rms_window_prev_out || !mean_ke_rms_window_abs_out ||
1596 !mean_ke_rms_window_rel_out) {
1597 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"ComputeStatisticalWindowMetrics received a NULL output pointer.");
1600 *has_reference_out = PETSC_FALSE;
1601 *mean_speed_window_out = 0.0;
1602 *mean_speed_window_prev_out = 0.0;
1603 *mean_speed_window_abs_out = 0.0;
1604 *mean_speed_window_rel_out = 0.0;
1605 *mean_speed_rms_window_out = 0.0;
1606 *mean_speed_rms_window_prev_out = 0.0;
1607 *mean_speed_rms_window_abs_out = 0.0;
1608 *mean_speed_rms_window_rel_out = 0.0;
1609 *mean_ke_window_out = 0.0;
1610 *mean_ke_window_prev_out = 0.0;
1611 *mean_ke_window_abs_out = 0.0;
1612 *mean_ke_window_rel_out = 0.0;
1613 *mean_ke_rms_window_out = 0.0;
1614 *mean_ke_rms_window_prev_out = 0.0;
1615 *mean_ke_rms_window_abs_out = 0.0;
1616 *mean_ke_rms_window_rel_out = 0.0;
1619 history_capacity = 2 * w;
1622 for (PetscInt idx = 0; idx < w; ++idx) {
1631 speed_sum += speed_value;
1632 speed_sum_sq += speed_value * speed_value;
1634 ke_sum_sq += ke_value * ke_value;
1637 *mean_speed_window_out = speed_sum / (PetscReal)w;
1638 *mean_speed_rms_window_out = PetscSqrtReal(PetscMax(0.0, speed_sum_sq / (PetscReal)w -
1639 (*mean_speed_window_out) * (*mean_speed_window_out)));
1640 *mean_ke_window_out = ke_sum / (PetscReal)w;
1641 *mean_ke_rms_window_out = PetscSqrtReal(PetscMax(0.0, ke_sum_sq / (PetscReal)w -
1642 (*mean_ke_window_out) * (*mean_ke_window_out)));
1646 for (PetscInt idx = w; idx < 2 * w; ++idx) {
1655 speed_prev_sum += speed_value;
1656 speed_prev_sum_sq += speed_value * speed_value;
1657 ke_prev_sum += ke_value;
1658 ke_prev_sum_sq += ke_value * ke_value;
1661 *has_reference_out = PETSC_TRUE;
1662 *mean_speed_window_prev_out = speed_prev_sum / (PetscReal)w;
1663 *mean_speed_window_abs_out = PetscAbsReal(*mean_speed_window_out - *mean_speed_window_prev_out);
1665 *mean_speed_rms_window_prev_out = PetscSqrtReal(PetscMax(0.0, speed_prev_sum_sq / (PetscReal)w -
1666 (*mean_speed_window_prev_out) * (*mean_speed_window_prev_out)));
1667 *mean_speed_rms_window_abs_out = PetscAbsReal(*mean_speed_rms_window_out - *mean_speed_rms_window_prev_out);
1670 *mean_ke_window_prev_out = ke_prev_sum / (PetscReal)w;
1671 *mean_ke_window_abs_out = PetscAbsReal(*mean_ke_window_out - *mean_ke_window_prev_out);
1673 *mean_ke_rms_window_prev_out = PetscSqrtReal(PetscMax(0.0, ke_prev_sum_sq / (PetscReal)w -
1674 (*mean_ke_window_prev_out) * (*mean_ke_window_prev_out)));
1675 *mean_ke_rms_window_abs_out = PetscAbsReal(*mean_ke_rms_window_out - *mean_ke_rms_window_prev_out);
1679 PetscFunctionReturn(0);
1702 default: name =
"unknown";
break;
1716 PetscMPIInt rank = 0;
1717 PetscBool has_reference = PETSC_FALSE;
1718 PetscInt phase_step = -1;
1719 PetscInt samples_before = 0;
1720 PetscReal u_abs_l2 = 0.0, u_rel_l2 = 0.0, p_abs_l2 = 0.0, p_rel_l2 = 0.0;
1721 PetscReal mean_speed = 0.0, mean_speed_reference = 0.0, mean_speed_abs_drift = 0.0, mean_speed_rel_drift = 0.0;
1722 PetscReal mean_ke = 0.0, mean_ke_reference = 0.0, mean_ke_abs_drift = 0.0, mean_ke_rel_drift = 0.0;
1723 PetscReal mean_speed_window = 0.0, mean_speed_window_prev = 0.0, mean_speed_window_abs_drift = 0.0, mean_speed_window_rel_drift = 0.0;
1724 PetscReal mean_speed_rms_window = 0.0, mean_speed_rms_window_prev = 0.0, mean_speed_rms_window_abs_drift = 0.0, mean_speed_rms_window_rel_drift = 0.0;
1725 PetscReal mean_ke_window = 0.0, mean_ke_window_prev = 0.0, mean_ke_window_abs_drift = 0.0, mean_ke_window_rel_drift = 0.0;
1726 PetscReal mean_ke_rms_window = 0.0, mean_ke_rms_window_prev = 0.0, mean_ke_rms_window_abs_drift = 0.0, mean_ke_rms_window_rel_drift = 0.0;
1728 PetscFunctionBeginUser;
1741 &u_abs_l2, &u_rel_l2,
1742 &p_abs_l2, &p_rel_l2,
1743 &mean_speed, &mean_speed_reference,
1744 &mean_speed_abs_drift, &mean_speed_rel_drift,
1745 &mean_ke, &mean_ke_reference,
1746 &mean_ke_abs_drift, &mean_ke_rel_drift));
1752 &u_abs_l2, &u_rel_l2,
1753 &p_abs_l2, &p_rel_l2,
1754 &mean_speed, &mean_speed_reference,
1755 &mean_speed_abs_drift, &mean_speed_rel_drift,
1756 &mean_ke, &mean_ke_reference,
1757 &mean_ke_abs_drift, &mean_ke_rel_drift));
1764 &mean_speed_window, &mean_speed_window_prev,
1765 &mean_speed_window_abs_drift, &mean_speed_window_rel_drift,
1766 &mean_speed_rms_window, &mean_speed_rms_window_prev,
1767 &mean_speed_rms_window_abs_drift, &mean_speed_rms_window_rel_drift,
1768 &mean_ke_window, &mean_ke_window_prev,
1769 &mean_ke_window_abs_drift, &mean_ke_window_rel_drift,
1770 &mean_ke_rms_window, &mean_ke_rms_window_prev,
1771 &mean_ke_rms_window_abs_drift, &mean_ke_rms_window_rel_drift));
1774 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG,
"Unknown solution convergence mode %d.", (
int)simCtx->
solutionConvergenceMode);
1777 rank = simCtx->
rank;
1781 const char *header = NULL;
1786 header =
"step,time,mode,ref,ph,per,u_abs_l2,u_rel_l2,p_abs_l2,p_rel_l2,"
1787 "mean_speed,spd_ref,spd_abs,spd_rel,mean_ke,ke_ref,ke_abs,ke_rel";
1790 header =
"step,time,mode,ref,win,mean_speed,mean_ke,spd_win,spd_win_prev,spd_win_abs,spd_win_rel,"
1791 "spd_rms_win,spd_rms_abs,spd_rms_rel,ke_win,ke_win_prev,ke_win_abs,ke_win_rel,"
1792 "ke_rms_win,ke_rms_abs,ke_rms_rel";
1795 header =
"step,time,mode,ref,u_abs_l2,u_rel_l2,p_abs_l2,p_rel_l2,"
1796 "mean_speed,spd_ref,spd_abs,spd_rel,mean_ke,ke_ref,ke_abs,ke_rel";
1805 "%d,%.10e,%s,%d,%.10e,%.10e,%.10e,%.10e,%.10e,%.10e,%.10e,%.10e,%.10e,%.10e,%.10e,%.10e\n",
1806 (
int)simCtx->
step, (
double)simCtx->
ti, mode_str, has_reference ? 1 : 0,
1807 (double)u_abs_l2, (
double)u_rel_l2, (double)p_abs_l2, (
double)p_rel_l2,
1808 (double)mean_speed, (
double)mean_speed_reference,
1809 (double)mean_speed_abs_drift, (
double)mean_speed_rel_drift,
1810 (double)mean_ke, (
double)mean_ke_reference,
1811 (double)mean_ke_abs_drift, (
double)mean_ke_rel_drift);
1815 "%d,%.10e,%s,%d,%d,%d,%.10e,%.10e,%.10e,%.10e,%.10e,%.10e,%.10e,%.10e,%.10e,%.10e,%.10e,%.10e\n",
1816 (
int)simCtx->
step, (
double)simCtx->
ti, mode_str, has_reference ? 1 : 0,
1818 (double)u_abs_l2, (
double)u_rel_l2, (double)p_abs_l2, (
double)p_rel_l2,
1819 (double)mean_speed, (
double)mean_speed_reference,
1820 (double)mean_speed_abs_drift, (
double)mean_speed_rel_drift,
1821 (double)mean_ke, (
double)mean_ke_reference,
1822 (double)mean_ke_abs_drift, (
double)mean_ke_rel_drift);
1826 "%d,%.10e,%s,%d,%d,%.10e,%.10e,%.10e,%.10e,%.10e,%.10e,%.10e,%.10e,%.10e,%.10e,%.10e,%.10e,%.10e,%.10e,%.10e,%.10e\n",
1827 (
int)simCtx->
step, (
double)simCtx->
ti, mode_str, has_reference ? 1 : 0,
1829 (
double)mean_speed, (double)mean_ke,
1830 (
double)mean_speed_window, (double)mean_speed_window_prev,
1831 (
double)mean_speed_window_abs_drift, (double)mean_speed_window_rel_drift,
1832 (
double)mean_speed_rms_window,
1833 (double)mean_speed_rms_window_abs_drift, (
double)mean_speed_rms_window_rel_drift,
1834 (double)mean_ke_window, (
double)mean_ke_window_prev,
1835 (double)mean_ke_window_abs_drift, (
double)mean_ke_window_rel_drift,
1836 (double)mean_ke_rms_window,
1837 (
double)mean_ke_rms_window_abs_drift, (double)mean_ke_rms_window_rel_drift);
1845 phase_step >= 0 && phase_step < simCtx->solutionConvergencePeriodSteps) {
1847 for (PetscInt bi = 0; bi < simCtx->
block_number; ++bi) {
1848 PetscCall(VecCopy(user[bi].Ucat, user[bi].solutionConvergencePeriodicUcatRef[phase_step]));
1849 PetscCall(VecCopy(user[bi].P, user[bi].solutionConvergencePeriodicPRef[phase_step]));
1856 PetscFunctionReturn(0);
1868 PetscErrorCode ierr;
1871 const PetscInt bi = user->
_this;
1872 const PetscInt ti = simCtx->
step;
1874 PetscFunctionBeginUser;
1876 rank = simCtx->
rank;
1881 PetscReal physical_time = 0.0;
1883 "step,block,max_divergence,max_divergence_k,max_divergence_j,max_divergence_i,"
1884 "max_divergence_index,poisson_source_imbalance,flux_in,flux_out,net_flux,time,physical_time",
1887 fprintf(f,
"%d,%d,%.10e,%d,%d,%d,%d,%.10e,%.10e,%.10e,%.10e,%.10e,%.10e\n",
1888 (
int)ti, (
int)bi, (
double)simCtx->
MaxDiv,
1896 PetscFunctionReturn(0);
1913 case LOST: name =
"LOST";
break;
1915 case EXITED: name =
"EXITED";
break;
1916 default: name =
"UNKNOWN_LEVEL";
break;
1946 for (PetscInt i = 0; i < n; ++i)
if (names[i] && strcmp(names[i], name) == 0)
return PETSC_TRUE;
1965 PetscLogHandler handler = NULL;
1967 PetscFunctionBeginUser;
1973 PetscCall(PetscLogGetDefaultHandler(&handler));
1974 if (!handler) PetscCall(PetscLogDefaultBegin());
1975 PetscFunctionReturn(0);
1986 PetscLogEvent registered = -1;
1990 if (!PetscInitializeCalled || PetscFinalizeCalled)
return;
1996 if (PetscLogEventSetActiveAll(registered, PETSC_FALSE) != 0)
return;
1998 *
event = registered;
2017 PetscLogState state = NULL;
2018 PetscInt nevents = 0;
2020 PetscFunctionBeginUser;
2021 if (!simCtx) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"SimCtx cannot be null for ProfilingInitialize");
2030 PetscCall(PetscLogGetState(&state));
2031 PetscCall(PetscLogStateGetNumEvents(state, &nevents));
2032 for (PetscLogEvent e = 0; e < nevents; ++e) {
2033 PetscLogEventInfo info;
2034 PetscCall(PetscLogStateEventGetInfo(state, e, &info));
2043 PetscFunctionReturn(0);
2051 PetscEventPerfInfo info;
2053 PetscFunctionBeginUser;
2054 PetscCall(PetscLogEventGetPerfInfo(PETSC_DETERMINE, event, &info));
2056 *count = info.count;
2057 PetscFunctionReturn(0);
2065 PetscLogState state = NULL;
2066 PetscInt nevents = 0;
2068 PetscFunctionBeginUser;
2069 PetscCall(PetscLogGetState(&state));
2070 if (!state) PetscFunctionReturn(0);
2071 PetscCall(PetscLogStateGetNumEvents(state, &nevents));
2078 PetscFunctionReturn(0);
2089 PetscFunctionBeginUser;
2091 PetscFunctionReturn(0);
2103 PetscLogState state = NULL;
2104 PetscInt nevents = 0;
2107 PetscFunctionBeginUser;
2108 if (!simCtx) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"SimCtx cannot be null for ProfilingLogTimestepSummary");
2111 PetscCall(PetscLogGetState(&state));
2112 PetscCall(PetscLogStateGetNumEvents(state, &nevents));
2117 if (step == simCtx->
StartStep + 1 && !all) {
2119 PetscBool ran = PETSC_FALSE;
2120 for (PetscLogEvent e = 0; e < nevents && !ran; ++e) {
2121 PetscLogEventInfo info;
2122 PetscLogDouble time = 0.0;
2124 PetscCall(PetscLogStateEventGetInfo(state, e, &info));
2127 ran = (PetscBool)(count > 0);
2131 "profiling.timestep_output.functions lists '%s', which recorded no call in the first "
2132 "step. It is not an instrumented function; the final summary lists the names that are.\n",
2138 for (PetscLogEvent e = 0; e < nevents; ++e) {
2139 PetscLogEventInfo info;
2140 PetscLogDouble time = 0.0, since_time;
2141 int count = 0, since_count;
2142 PetscCall(PetscLogStateEventGetInfo(state, e, &info));
2149 if (since_count <= 0 || simCtx->rank != 0)
continue;
2157 PetscFPrintf(PETSC_COMM_SELF, f,
"%d,%s,%d,%.6f\n", (
int)step, info.name, since_count, (
double)since_time);
2161 PetscFunctionReturn(0);
2172 PetscErrorCode ierr;
2173 PetscLogDouble process_current_bytes = 0.0;
2174 PetscLogDouble process_peak_bytes = 0.0;
2175 PetscLogDouble petsc_current_bytes = 0.0;
2176 PetscLogDouble petsc_peak_bytes = 0.0;
2177 PetscReal local_values[5];
2178 PetscReal global_values[5];
2179 PetscReal process_current_mb = 0.0;
2180 PetscReal process_peak_mb = 0.0;
2181 PetscReal petsc_current_mb = 0.0;
2182 PetscReal petsc_peak_mb = 0.0;
2183 PetscReal process_change_mb = 0.0;
2186 PetscFunctionBeginUser;
2188 if (!simCtx) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"SimCtx cannot be null for RuntimeMemoryLogSample");
2191 ierr = PetscMemoryGetCurrentUsage(&process_current_bytes); CHKERRQ(ierr);
2192 ierr = PetscMemoryGetMaximumUsage(&process_peak_bytes); CHKERRQ(ierr);
2193 ierr = PetscMallocGetCurrentUsage(&petsc_current_bytes); CHKERRQ(ierr);
2194 ierr = PetscMallocGetMaximumUsage(&petsc_peak_bytes); CHKERRQ(ierr);
2196 process_current_mb = (PetscReal)(process_current_bytes / (1024.0 * 1024.0));
2197 process_peak_mb = (PetscReal)(process_peak_bytes / (1024.0 * 1024.0));
2198 petsc_current_mb = (PetscReal)(petsc_current_bytes / (1024.0 * 1024.0));
2199 petsc_peak_mb = (PetscReal)(petsc_peak_bytes / (1024.0 * 1024.0));
2204 local_values[0] = process_current_mb;
2205 local_values[1] = process_peak_mb;
2206 local_values[2] = petsc_current_mb;
2207 local_values[3] = petsc_peak_mb;
2208 local_values[4] = process_change_mb;
2209 ierr = MPI_Allreduce(local_values, global_values, 5, MPIU_REAL, MPI_MAX, PETSC_COMM_WORLD); CHKERRMPI(ierr);
2214 if (simCtx->
rank == 0) {
2217 "step,event,process_current_mb_max,process_peak_mb_max,petsc_allocated_mb_max,"
2218 "petsc_peak_allocated_mb_max,process_change_mb_max,reason,step_wall_s",
2221 fprintf(f,
"%" PetscInt_FMT
",%s,%.3f,%.3f,%.3f,%.3f,%.3f,%s,",
2222 step, event ? event :
"-",
2223 (double)global_values[0], (
double)global_values[1], (double)global_values[2],
2224 (
double)global_values[3], (double)global_values[4],
2225 (reason && reason[0]) ? reason :
"-");
2227 if (event && strcmp(event,
"Step") == 0) fprintf(f,
"%.6f", (
double)simCtx->
lastStepWallSeconds);
2229 if ((event && (strcmp(event,
"Shutdown") == 0 || strcmp(event,
"Final") == 0))) {
2236 PetscFunctionReturn(0);
2254 return strcmp(*(
const char *
const *)a, *(
const char *
const *)b);
2279 const PetscLogDouble *times,
const long long *counts)
2281 PetscMPIInt rank, size, local_len = 0, total_len = 0, *lens = NULL, *displs = NULL;
2282 char *local_names = NULL, *all_names = NULL;
2283 const char **unique = NULL;
2284 PetscInt nall = 0, nunique = 0;
2285 struct {
double value;
int rank; } *local_time = NULL, *min_time = NULL, *max_time = NULL;
2286 struct {
double value;
int rank; } *local_count = NULL, *min_count = NULL, *max_count = NULL;
2287 double *local_seconds = NULL, *sum_time = NULL;
2288 long long *local_calls = NULL, *sum_calls = NULL;
2290 PetscFunctionBeginUser;
2291 rank = PetscGlobalRank;
2292 size = PetscGlobalSize;
2295 for (PetscInt i = 0; i < nlocal; ++i) local_len += (PetscMPIInt)strlen(names[i]) + 1;
2296 PetscCall(PetscMalloc1(local_len + 1, &local_names));
2297 for (PetscInt i = 0, off = 0; i < nlocal; ++i) { strcpy(local_names + off, names[i]); off += (PetscInt)strlen(names[i]) + 1; }
2298 PetscCall(PetscMalloc2(size, &lens, size, &displs));
2299 PetscCallMPI(MPI_Allgather(&local_len, 1, MPI_INT, lens, 1, MPI_INT, PETSC_COMM_WORLD));
2300 for (PetscMPIInt r = 0; r < size; ++r) { displs[r] = total_len; total_len += lens[r]; }
2301 PetscCall(PetscMalloc1(total_len + 1, &all_names));
2302 PetscCallMPI(MPI_Allgatherv(local_names, local_len, MPI_CHAR, all_names, lens, displs, MPI_CHAR, PETSC_COMM_WORLD));
2303 for (PetscMPIInt off = 0; off < total_len; off += (PetscMPIInt)strlen(all_names + off) + 1) nall++;
2304 PetscCall(PetscMalloc1(nall + 1, &unique));
2305 for (PetscMPIInt off = 0; off < total_len; off += (PetscMPIInt)strlen(all_names + off) + 1) unique[nunique++] = all_names + off;
2309 for (PetscInt i = 0; i < nunique; ++i)
if (kept == 0 || strcmp(unique[kept - 1], unique[i]) != 0) unique[kept++] = unique[i];
2314 PetscCall(PetscMalloc4(nunique + 1, &local_time, nunique + 1, &min_time, nunique + 1, &max_time, nunique + 1, &sum_time));
2315 PetscCall(PetscMalloc3(nunique + 1, &local_seconds, nunique + 1, &local_calls, nunique + 1, &sum_calls));
2316 PetscCall(PetscMalloc3(nunique + 1, &local_count, nunique + 1, &min_count, nunique + 1, &max_count));
2317 for (PetscInt u = 0; u < nunique; ++u) {
2320 for (PetscInt i = 0; i < nlocal; ++i)
if (strcmp(names[i], unique[u]) == 0) { t += times[i]; c += counts[i]; }
2321 local_seconds[u] = t; local_time[u].value = t; local_time[u].rank = (int)rank;
2322 local_calls[u] = c; local_count[u].value = (double)c; local_count[u].rank = (int)rank;
2324 PetscCallMPI(MPI_Reduce(local_time, min_time, (
int)nunique, MPI_DOUBLE_INT, MPI_MINLOC, 0, PETSC_COMM_WORLD));
2325 PetscCallMPI(MPI_Reduce(local_time, max_time, (
int)nunique, MPI_DOUBLE_INT, MPI_MAXLOC, 0, PETSC_COMM_WORLD));
2326 PetscCallMPI(MPI_Reduce(local_seconds, sum_time, (
int)nunique, MPI_DOUBLE, MPI_SUM, 0, PETSC_COMM_WORLD));
2327 PetscCallMPI(MPI_Reduce(local_calls, sum_calls, (
int)nunique, MPI_LONG_LONG, MPI_SUM, 0, PETSC_COMM_WORLD));
2328 PetscCallMPI(MPI_Reduce(local_count, min_count, (
int)nunique, MPI_DOUBLE_INT, MPI_MINLOC, 0, PETSC_COMM_WORLD));
2329 PetscCallMPI(MPI_Reduce(local_count, max_count, (
int)nunique, MPI_DOUBLE_INT, MPI_MAXLOC, 0, PETSC_COMM_WORLD));
2334 PetscCall(PetscMalloc1(nunique + 1, &rows));
2335 for (PetscInt u = 0; u < nunique; ++u) {
2336 if (sum_calls[u] == 0)
continue;
2337 rows[nrows].
name = unique[u];
2338 rows[nrows].
mean_time = sum_time[u] / size;
2339 rows[nrows].
min_time = min_time[u].value;
2340 rows[nrows].
min_rank = min_time[u].rank;
2341 rows[nrows].
max_time = max_time[u].value;
2342 rows[nrows].
max_rank = max_time[u].rank;
2344 rows[nrows].
min_calls = min_count[u].value;
2346 rows[nrows].
max_calls = max_count[u].value;
2353 for (PetscInt i = 0; i < nrows; ++i) {
2355 PetscFPrintf(PETSC_COMM_SELF, f,
"%s,%s,%.6f,%d,%.6f,%.6f,%d,%lld,%.6f,%.0f,%d,%.0f,%d\n",
2356 section, rows[i].name,
2357 rows[i].max_time, rows[i].max_rank, rows[i].mean_time,
2358 rows[i].min_time, rows[i].min_rank, rows[i].call_count, avg_time_ms,
2359 rows[i].min_calls, rows[i].min_calls_rank, rows[i].max_calls, rows[i].max_calls_rank);
2361 PetscCall(PetscFree(rows));
2364 PetscCall(PetscFree4(local_time, min_time, max_time, sum_time));
2365 PetscCall(PetscFree3(local_seconds, local_calls, sum_calls));
2366 PetscCall(PetscFree3(local_count, min_count, max_count));
2367 PetscCall(PetscFree(unique));
2368 PetscCall(PetscFree(all_names));
2369 PetscCall(PetscFree2(lens, displs));
2370 PetscCall(PetscFree(local_names));
2371 PetscFunctionReturn(0);
2382 PetscLogState state = NULL;
2383 PetscInt nevents = 0, npicurv = 0, npetsc = 0;
2384 const char **picurv_names = NULL, **petsc_names = NULL;
2385 PetscLogDouble *picurv_times = NULL, *petsc_times = NULL;
2386 long long *picurv_counts = NULL, *petsc_counts = NULL;
2389 PetscFunctionBeginUser;
2393 PetscCall(PetscLogGetState(&state));
2394 if (state) PetscCall(PetscLogStateGetNumEvents(state, &nevents));
2395 PetscCall(PetscMalloc3(nevents + 1, &picurv_names, nevents + 1, &picurv_times, nevents + 1, &picurv_counts));
2396 PetscCall(PetscMalloc3(nevents + 1, &petsc_names, nevents + 1, &petsc_times, nevents + 1, &petsc_counts));
2397 for (PetscLogEvent e = 0; e < nevents; ++e) {
2398 PetscLogEventInfo info;
2399 PetscLogDouble time = 0.0;
2401 PetscCall(PetscLogStateEventGetInfo(state, e, &info));
2403 if (count <= 0)
continue;
2405 picurv_names[npicurv] = info.name; picurv_times[npicurv] = time; picurv_counts[npicurv++] = count;
2407 petsc_names[npetsc] = info.name; petsc_times[npetsc] = time; petsc_counts[npetsc++] = count;
2411 if (!simCtx->
rank) {
2412 char exec_mode_modifier[32] =
"Unknown";
2414 if (simCtx->
exec_mode ==
EXEC_MODE_SOLVER) PetscCall(PetscStrncpy(exec_mode_modifier,
"Solver",
sizeof(exec_mode_modifier)));
2416 PetscCall(PetscSNPrintf(filen,
sizeof(filen),
"ProfilingSummary_%s.csv", exec_mode_modifier));
2419 "section,function,max_time_s,max_rank,mean_time_s,min_time_s,min_rank,calls,avg_time_per_call_ms,"
2420 "min_calls_per_rank,min_calls_rank,max_calls_per_rank,max_calls_rank",
2422 fprintf(f,
"# Total time per rank over %d rank(s). Section 'petsc' times are inclusive and run inside the "
2423 "'picurv' functions, so the two sections must not be added together.\n", (
int)simCtx->
size);
2429 PetscCall(PetscFree3(picurv_names, picurv_times, picurv_counts));
2430 PetscCall(PetscFree3(petsc_names, petsc_times, petsc_counts));
2433 PetscFunctionReturn(0);
2446void PrintProgressBar(PetscInt step, PetscInt startStep, PetscInt totalSteps, PetscReal currentTime,
2447 PetscReal seconds_per_step, PetscInt64 lost_cumulative)
2453 const int barWidth = 50;
2457 PetscReal progress = (PetscReal)(step - startStep + 1) / totalSteps;
2459 if (progress > 1.0) progress = 1.0;
2461 int pos = (int)(barWidth * progress);
2465 PetscPrintf(PETSC_COMM_SELF,
"\rProgress: [");
2467 for (
int i = 0; i < barWidth; ++i) {
2469 PetscPrintf(PETSC_COMM_SELF,
"=");
2470 }
else if (i == pos) {
2471 PetscPrintf(PETSC_COMM_SELF,
">");
2473 PetscPrintf(PETSC_COMM_SELF,
" ");
2478 PetscPrintf(PETSC_COMM_SELF,
"] %3d%% (Step %" PetscInt_FMT
"/%" PetscInt_FMT
", t=%.4f)",
2479 (
int)(progress * 100.0),
2481 startStep + totalSteps,
2483 if (seconds_per_step > 0.0) {
2484 const PetscInt remaining = PetscMax(0, startStep + totalSteps - (step + 1));
2485 const long long eta = (
long long)(seconds_per_step * (PetscReal)remaining + 0.5);
2486 PetscPrintf(PETSC_COMM_SELF,
" | %.3g s/step | ETA %lld:%02lld:%02lld",
2487 (
double)seconds_per_step, eta / 3600, (eta / 60) % 60, eta % 60);
2489 if (lost_cumulative >= 0) PetscPrintf(PETSC_COMM_SELF,
" | lost %lld", (
long long)lost_cumulative);
2503 PetscErrorCode ierr;
2508 Vec fieldVec = NULL;
2512 const char *fieldName = NULL;
2513 const char *data_layout = NULL;
2515 PetscFunctionBeginUser;
2518 ierr =
FieldGetView(user, field_id, &view); CHKERRQ(ierr);
2529 PetscInt i_start, i_end, j_start, j_end, k_start, k_end;
2535 i_start = PetscMax(info.xs, 1); i_end = PetscMin(info.xs + info.xm, user->
IM);
2536 j_start = PetscMax(info.ys, 1); j_end = PetscMin(info.ys + info.ym, user->
JM);
2537 k_start = PetscMax(info.zs, 1); k_end = PetscMin(info.zs + info.zm, user->
KM);
2542 i_start = PetscMax(info.xs, 0); i_end = PetscMin(info.xs + info.xm, user->
IM);
2543 j_start = PetscMax(info.ys, 0); j_end = PetscMin(info.ys + info.ym, user->
JM);
2544 k_start = PetscMax(info.zs, 0); k_end = PetscMin(info.zs + info.zm, user->
KM);
2548 ierr = MPI_Barrier(PETSC_COMM_WORLD); CHKERRQ(ierr);
2550 PetscPrintf(PETSC_COMM_SELF,
"\n--- Field Ranges: [%s] (Layout: %s) ---\n", fieldName, data_layout);
2555 PetscReal localMin = PETSC_MAX_REAL, localMax = PETSC_MIN_REAL;
2556 PetscReal globalMin, globalMax;
2557 const PetscScalar ***array;
2559 ierr = DMDAVecGetArrayRead(dm, fieldVec, &array); CHKERRQ(ierr);
2560 for (k = k_start; k < k_end; k++) {
2561 for (j = j_start; j < j_end; j++) {
2562 for (i = i_start; i < i_end; i++) {
2563 localMin = PetscMin(localMin, array[k][j][i]);
2564 localMax = PetscMax(localMax, array[k][j][i]);
2568 ierr = DMDAVecRestoreArrayRead(dm, fieldVec, &array); CHKERRQ(ierr);
2570 ierr = MPI_Allreduce(&localMin, &globalMin, 1, MPIU_REAL, MPI_MIN, PETSC_COMM_WORLD); CHKERRQ(ierr);
2571 ierr = MPI_Allreduce(&localMax, &globalMax, 1, MPIU_REAL, MPI_MAX, PETSC_COMM_WORLD); CHKERRQ(ierr);
2573 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
" [Rank %d] Local Range: [ %11.4e , %11.4e ]\n", user->
simCtx->
rank, localMin, localMax);
2574 ierr = PetscSynchronizedFlush(PETSC_COMM_WORLD, PETSC_STDOUT); CHKERRQ(ierr);
2576 PetscPrintf(PETSC_COMM_SELF,
" Global Range: [ %11.4e , %11.4e ]\n", globalMin, globalMax);
2579 }
else if (dof == 3) {
2580 Cmpnts localMin = {PETSC_MAX_REAL, PETSC_MAX_REAL, PETSC_MAX_REAL};
2581 Cmpnts localMax = {PETSC_MIN_REAL, PETSC_MIN_REAL, PETSC_MIN_REAL};
2582 Cmpnts globalMin, globalMax;
2585 ierr = DMDAVecGetArrayRead(dm, fieldVec, &array); CHKERRQ(ierr);
2586 for (k = k_start; k < k_end; k++) {
2587 for (j = j_start; j < j_end; j++) {
2588 for (i = i_start; i < i_end; i++) {
2589 localMin.
x = PetscMin(localMin.
x, array[k][j][i].
x);
2590 localMin.
y = PetscMin(localMin.
y, array[k][j][i].
y);
2591 localMin.
z = PetscMin(localMin.
z, array[k][j][i].
z);
2592 localMax.
x = PetscMax(localMax.
x, array[k][j][i].
x);
2593 localMax.
y = PetscMax(localMax.
y, array[k][j][i].
y);
2594 localMax.
z = PetscMax(localMax.
z, array[k][j][i].
z);
2598 ierr = DMDAVecRestoreArrayRead(dm, fieldVec, &array); CHKERRQ(ierr);
2600 ierr = MPI_Allreduce(&localMin, &globalMin, 3, MPIU_REAL, MPI_MIN, PETSC_COMM_WORLD); CHKERRQ(ierr);
2601 ierr = MPI_Allreduce(&localMax, &globalMax, 3, MPIU_REAL, MPI_MAX, PETSC_COMM_WORLD); CHKERRQ(ierr);
2603 ierr = PetscSynchronizedPrintf(PETSC_COMM_WORLD,
" [Rank %d] Local X-Range: [ %11.4e , %11.4e ]\n", user->
simCtx->
rank, localMin.
x, localMax.
x);
2604 ierr = PetscSynchronizedPrintf(PETSC_COMM_WORLD,
" [Rank %d] Local Y-Range: [ %11.4e , %11.4e ]\n", user->
simCtx->
rank, localMin.
y, localMax.
y);
2605 ierr = PetscSynchronizedPrintf(PETSC_COMM_WORLD,
" [Rank %d] Local Z-Range: [ %11.4e , %11.4e ]\n", user->
simCtx->
rank, localMin.
z, localMax.
z);
2606 ierr = PetscSynchronizedFlush(PETSC_COMM_WORLD, PETSC_STDOUT); CHKERRQ(ierr);
2609 PetscPrintf(PETSC_COMM_SELF,
" [Global] X-Range: [ %11.4e , %11.4e ]\n", globalMin.
x, globalMax.
x);
2610 PetscPrintf(PETSC_COMM_SELF,
" [Global] Y-Range: [ %11.4e , %11.4e ]\n", globalMin.
y, globalMax.
y);
2611 PetscPrintf(PETSC_COMM_SELF,
" [Global] Z-Range: [ %11.4e , %11.4e ]\n", globalMin.
z, globalMax.
z);
2615 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
"LogFieldStatistics only supports fields with 1 or 3 components, but field '%s' has %" PetscInt_FMT
".", fieldName, dof);
2619 ierr = MPI_Barrier(PETSC_COMM_WORLD); CHKERRQ(ierr);
2621 PetscPrintf(PETSC_COMM_SELF,
"--------------------------------------------\n\n");
2625 PetscFunctionReturn(0);
2632 const char *stage_name, DM dm,
2633 Vec vec_local, PetscInt dof,
2636 PetscErrorCode ierr;
2640 char dominant_dir =
'\0';
2642 PetscFunctionBeginUser;
2644 PetscCheck(user != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"UserCtx cannot be NULL.");
2645 PetscCheck(field_name != NULL && stage_name != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
2646 "Field and stage labels cannot be NULL.");
2647 PetscCheck(dm != NULL && vec_local != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE,
2648 "Field '%s' has no available DM/local vector for anatomy logging.", field_name);
2649 PetscCheck(dof == 1 || dof == 3, PETSC_COMM_SELF, PETSC_ERR_SUP,
2650 "Field anatomy logging supports one- or three-component fields; '%s' has %" PetscInt_FMT
".",
2662 ierr = PetscBarrier(NULL);
2663 PetscPrintf(PETSC_COMM_WORLD,
"\n--- Field Anatomy Log: [%s] | Stage: [%s] | Layout: [%s] ---\n", field_name, stage_name, data_layout);
2666 PetscInt im_phys = user->
IM;
2667 PetscInt jm_phys = user->
JM;
2668 PetscInt km_phys = user->
KM;
2671 PetscInt i_mid = (PetscInt)(info.xs + 0.5 * info.xm) - 1;
2672 PetscInt j_mid = (PetscInt)(info.ys + 0.5 * info.ym) - 1;
2673 PetscInt k_mid = (PetscInt)(info.zs + 0.5 * info.zm) - 1;
2682 ierr = DMDAVecGetArrayRead(dm, vec_local, (
void*)&l_arr); CHKERRQ(ierr);
2687 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, I-DIR]: Idx %2d (Ghost for Cell[k][j][0]) = ", rank, 0);
2688 if(dof==1) PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"(%.5f)\n", ((
const PetscReal***)l_arr)[k_mid][j_mid][0]);
2689 else PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"(%.5f, %.5f, %.5f)\n", ((
const Cmpnts***)l_arr)[k_mid][j_mid][0].x, ((
const Cmpnts***)l_arr)[k_mid][j_mid][0].y, ((
const Cmpnts***)l_arr)[k_mid][j_mid][0].z);
2691 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, I-DIR]: Idx %2d (Value for Cell[k][j][0]) = ", rank, 1);
2692 if(dof==1) PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"(%.5f)\n", ((
const PetscReal***)l_arr)[k_mid][j_mid][1]);
2693 else PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"(%.5f, %.5f, %.5f)\n", ((
const Cmpnts***)l_arr)[k_mid][j_mid][1].x, ((
const Cmpnts***)l_arr)[k_mid][j_mid][1].y, ((
const Cmpnts***)l_arr)[k_mid][j_mid][1].z);
2695 if (info.xs + info.xm == info.mx) {
2696 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, I-DIR]: Idx %2" PetscInt_FMT
" (Value for Cell[k][j][%" PetscInt_FMT
"]) = ", rank, im_phys - 1, im_phys - 2);
2697 if(dof==1) PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"(%.5f)\n", ((
const PetscReal***)l_arr)[k_mid][j_mid][im_phys - 1]);
2698 else PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"(%.5f, %.5f, %.5f)\n", ((
const Cmpnts***)l_arr)[k_mid][j_mid][im_phys - 1].x, ((
const Cmpnts***)l_arr)[k_mid][j_mid][im_phys - 1].y, ((
const Cmpnts***)l_arr)[k_mid][j_mid][im_phys - 1].z);
2700 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, I-DIR]: Idx %2" PetscInt_FMT
" (Ghost for Cell[k][j][%" PetscInt_FMT
"]) = ", rank, im_phys, im_phys - 2);
2701 if(dof==1) PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"(%.5f)\n", ((
const PetscReal***)l_arr)[k_mid][j_mid][im_phys]);
2702 else PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"(%.5f, %.5f, %.5f)\n", ((
const Cmpnts***)l_arr)[k_mid][j_mid][im_phys].x, ((
const Cmpnts***)l_arr)[k_mid][j_mid][im_phys].y, ((
const Cmpnts***)l_arr)[k_mid][j_mid][im_phys].z);
2707 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, J-DIR]: Jdx %2d (Ghost for Cell[k][0][i]) = ", rank, 0);
2708 if(dof==1) PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"(%.5f)\n", ((
const PetscReal***)l_arr)[k_mid][0][i_mid]);
2709 else PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"(%.5f, %.5f, %.5f)\n", ((
const Cmpnts***)l_arr)[k_mid][0][i_mid].x, ((
const Cmpnts***)l_arr)[k_mid][0][i_mid].y, ((
const Cmpnts***)l_arr)[k_mid][0][i_mid].z);
2711 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, J-DIR]: Jdx %2d (Value for Cell[k][0][i]) = ", rank, 1);
2712 if(dof==1) PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"(%.5f)\n", ((
const PetscReal***)l_arr)[k_mid][1][i_mid]);
2713 else PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"(%.5f, %.5f, %.5f)\n", ((
const Cmpnts***)l_arr)[k_mid][1][i_mid].x, ((
const Cmpnts***)l_arr)[k_mid][1][i_mid].y, ((
const Cmpnts***)l_arr)[k_mid][1][i_mid].z);
2716 if (info.ys + info.ym == info.my) {
2717 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, J-DIR]: Jdx %2" PetscInt_FMT
" (Value for Cell[k][%" PetscInt_FMT
"][i]) = ", rank, jm_phys - 1, jm_phys - 2);
2718 if(dof==1) PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"(%.5f)\n", ((
const PetscReal***)l_arr)[k_mid][jm_phys - 1][i_mid]);
2719 else PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"(%.5f, %.5f, %.5f)\n", ((
const Cmpnts***)l_arr)[k_mid][jm_phys - 1][i_mid].x, ((
const Cmpnts***)l_arr)[k_mid][jm_phys - 1][i_mid].y, ((
const Cmpnts***)l_arr)[k_mid][jm_phys - 1][i_mid].z);
2721 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, J-DIR]: Jdx %2" PetscInt_FMT
" (Ghost for Cell[k][%" PetscInt_FMT
"][i]) = ", rank, jm_phys, jm_phys - 2);
2722 if(dof==1) PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"(%.5f)\n", ((
const PetscReal***)l_arr)[k_mid][jm_phys][i_mid]);
2723 else PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"(%.5f, %.5f, %.5f)\n", ((
const Cmpnts***)l_arr)[k_mid][jm_phys][i_mid].x, ((
const Cmpnts***)l_arr)[k_mid][jm_phys][i_mid].y, ((
const Cmpnts***)l_arr)[k_mid][jm_phys][i_mid].z);
2728 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, K-DIR]: Kdx %2d (Ghost for Cell[0][j][i]) = ", rank, 0);
2729 if(dof==1) PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"(%.5f)\n", ((
const PetscReal***)l_arr)[0][j_mid][i_mid]);
2730 else PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"(%.5f, %.5f, %.5f)\n", ((
const Cmpnts***)l_arr)[0][j_mid][i_mid].x, ((
const Cmpnts***)l_arr)[0][j_mid][i_mid].y, ((
const Cmpnts***)l_arr)[0][j_mid][i_mid].z);
2731 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, K-DIR]: Kdx %2d (Value for Cell[0][j][i]) = ", rank, 1);
2732 if(dof==1) PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"(%.5f)\n", ((
const PetscReal***)l_arr)[1][j_mid][i_mid]);
2733 else PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"(%.5f, %.5f, %.5f)\n", ((
const Cmpnts***)l_arr)[1][j_mid][i_mid].x, ((
const Cmpnts***)l_arr)[1][j_mid][i_mid].y, ((
const Cmpnts***)l_arr)[1][j_mid][i_mid].z);
2735 if (info.zs + info.zm == info.mz) {
2736 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, K-DIR]: Kdx %2" PetscInt_FMT
" (Value for Cell[%" PetscInt_FMT
"][j][i]) = ", rank, km_phys - 1, km_phys - 2);
2737 if(dof==1) PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"(%.5f)\n", ((
const PetscReal***)l_arr)[km_phys - 1][j_mid][i_mid]);
2738 else PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"(%.5f, %.5f, %.5f)\n", ((
const Cmpnts***)l_arr)[km_phys - 1][j_mid][i_mid].x, ((
const Cmpnts***)l_arr)[km_phys - 1][j_mid][i_mid].y, ((
const Cmpnts***)l_arr)[km_phys - 1][j_mid][i_mid].z);
2739 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, K-DIR]: Kdx %2" PetscInt_FMT
" (Ghost for Cell[%" PetscInt_FMT
"][j][i]) = ", rank, km_phys, km_phys - 2);
2740 if(dof==1) PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"(%.5f)\n", ((
const PetscReal***)l_arr)[km_phys][j_mid][i_mid]);
2741 else PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"(%.5f, %.5f, %.5f)\n", ((
const Cmpnts***)l_arr)[km_phys][j_mid][i_mid].x, ((
const Cmpnts***)l_arr)[km_phys][j_mid][i_mid].y, ((
const Cmpnts***)l_arr)[km_phys][j_mid][i_mid].z);
2743 ierr = DMDAVecRestoreArrayRead(dm, vec_local, (
void*)&l_arr); CHKERRQ(ierr);
2753 ierr = DMDAVecGetArrayRead(dm, vec_local, (
void*)&l_arr); CHKERRQ(ierr);
2757 if (dominant_dir ==
'x') {
2758 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, I-DIR]: Idx %2d (First Phys. X-Face) = (%.5f, %.5f, %.5f)\n", rank, 0, l_arr[k_mid][j_mid][0].x, l_arr[k_mid][j_mid][0].y, l_arr[k_mid][j_mid][0].z);
2759 }
else if (dominant_dir ==
'y' || dominant_dir ==
'z') {
2760 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, I-DIR]: Idx %2d (Ghost for Cell[k][j][0]) = (%.5f, %.5f, %.5f)\n", rank, 0, l_arr[k_mid][j_mid][0].x, l_arr[k_mid][j_mid][0].y, l_arr[k_mid][j_mid][0].z);
2761 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, I-DIR]: Idx %2d (Value for Cell[k][j][0]) = (%.5f, %.5f, %.5f)\n", rank, 1, l_arr[k_mid][j_mid][1].x, l_arr[k_mid][j_mid][1].y, l_arr[k_mid][j_mid][1].z);
2762 }
else if (dominant_dir ==
'm') {
2763 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, I-DIR]: u-comp @ Idx %2d (1st X-Face) = %.5f\n", rank, 0, l_arr[k_mid][j_mid][0].x);
2766 if (info.xs + info.xm == info.mx) {
2767 if (dominant_dir ==
'x') {
2768 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, I-DIR]: Idx %2" PetscInt_FMT
" (Last Phys. X-Face) = (%.5f, %.5f, %.5f)\n", rank, im_phys - 1, l_arr[k_mid][j_mid][im_phys - 1].x, l_arr[k_mid][j_mid][im_phys-1].y, l_arr[k_mid][j_mid][im_phys - 1].z);
2769 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, I-DIR]: Idx %2" PetscInt_FMT
" (Ghost Location) = (%.5f, %.5f, %.5f)\n", rank, im_phys, l_arr[k_mid][j_mid][im_phys].x, l_arr[k_mid][j_mid][im_phys].y, l_arr[k_mid][j_mid][im_phys].z);
2770 }
else if (dominant_dir ==
'y' || dominant_dir ==
'z') {
2771 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, I-DIR]: Idx %2" PetscInt_FMT
" (Value for Cell[k][j][%" PetscInt_FMT
"]) = (%.5f, %.5f, %.5f)\n", rank, im_phys - 1, im_phys - 2, l_arr[k_mid][j_mid][im_phys - 1].x, l_arr[k_mid][j_mid][im_phys - 1].y, l_arr[k_mid][j_mid][im_phys-1].z);
2772 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, I-DIR]: Idx %2" PetscInt_FMT
" (Ghost for Cell[k][j][%" PetscInt_FMT
"]) = (%.5f, %.5f, %.5f)\n", rank, im_phys, im_phys - 2, l_arr[k_mid][j_mid][im_phys].x, l_arr[k_mid][j_mid][im_phys].y, l_arr[k_mid][j_mid][im_phys].z);
2773 }
else if (dominant_dir ==
'm') {
2774 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, I-DIR]: u-comp @ Idx %2" PetscInt_FMT
" (Last X-Face) = %.5f\n", rank, im_phys - 1, l_arr[k_mid][j_mid][im_phys - 1].x);
2775 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, I-DIR]: u-comp @ Idx %2" PetscInt_FMT
" (Ghost Location) = %.5f\n", rank, im_phys, l_arr[k_mid][j_mid][im_phys].x);
2781 if (dominant_dir ==
'y') {
2782 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, J-DIR]: Jdx %2d (First Phys. Y-Face) = (%.5f, %.5f, %.5f)\n", rank, 0, l_arr[k_mid][0][i_mid].x, l_arr[k_mid][0][i_mid].y, l_arr[k_mid][0][i_mid].z);
2783 }
else if (dominant_dir ==
'x' || dominant_dir ==
'z') {
2784 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, J-DIR]: Jdx %2d (Ghost for Cell[k][0][i]) = (%.5f, %.5f, %.5f)\n", rank, 0, l_arr[k_mid][0][i_mid].x, l_arr[k_mid][0][i_mid].y, l_arr[k_mid][0][i_mid].z);
2785 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, J-DIR]: Jdx %2d (Value for Cell[k][0][i]) = (%.5f, %.5f, %.5f)\n", rank, 1, l_arr[k_mid][1][i_mid].x, l_arr[k_mid][1][i_mid].y, l_arr[k_mid][1][i_mid].z);
2786 }
else if (dominant_dir ==
'm') {
2787 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, J-DIR]: v-comp @ Jdx %2d (1st Y-Face) = %.5f\n", rank, 0, l_arr[k_mid][0][i_mid].y);
2790 if (info.ys + info.ym == info.my) {
2791 if (dominant_dir ==
'y') {
2792 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, J-DIR]: Jdx %2" PetscInt_FMT
" (Last Phys. Y-Face) = (%.5f, %.5f, %.5f)\n", rank, jm_phys - 1, l_arr[k_mid][jm_phys - 1][i_mid].x, l_arr[k_mid][jm_phys - 1][i_mid].y, l_arr[k_mid][jm_phys - 1][i_mid].z);
2793 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, J-DIR]: Jdx %2" PetscInt_FMT
" (Ghost Location) = (%.5f, %.5f, %.5f)\n", rank, jm_phys, l_arr[k_mid][jm_phys][i_mid].x, l_arr[k_mid][jm_phys][i_mid].y, l_arr[k_mid][jm_phys][i_mid].z);
2794 }
else if (dominant_dir ==
'x' || dominant_dir ==
'z') {
2795 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, J-DIR]: Jdx %2" PetscInt_FMT
" (Value for Cell[k][%" PetscInt_FMT
"][i]) = (%.5f, %.5f, %.5f)\n", rank, jm_phys-1, jm_phys-2, l_arr[k_mid][jm_phys - 1][i_mid].x, l_arr[k_mid][jm_phys - 1][i_mid].y, l_arr[k_mid][jm_phys - 1][i_mid].z);
2796 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, J-DIR]: Jdx %2" PetscInt_FMT
" (Ghost for Cell[k][%" PetscInt_FMT
"][i]) = (%.5f, %.5f, %.5f)\n", rank, jm_phys, jm_phys-2, l_arr[k_mid][jm_phys][i_mid].x, l_arr[k_mid][jm_phys][i_mid].y, l_arr[k_mid][jm_phys][i_mid].z);
2797 }
else if (dominant_dir ==
'm') {
2798 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, J-DIR]: v-comp @ Jdx %2" PetscInt_FMT
" (Last Y-Face) = %.5f\n", rank, jm_phys - 1, l_arr[k_mid][jm_phys - 1][i_mid].y);
2799 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, J-DIR]: v-comp @ Jdx %2" PetscInt_FMT
" (Ghost Location) = %.5f\n", rank, jm_phys, l_arr[k_mid][jm_phys][i_mid].y);
2805 if (dominant_dir ==
'z') {
2806 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, K-DIR]: Kdx %2d (First Phys. Z-Face) = (%.5f, %.5f, %.5f)\n", rank, 0, l_arr[0][j_mid][i_mid].x, l_arr[0][j_mid][i_mid].y, l_arr[0][j_mid][i_mid].z);
2807 }
else if (dominant_dir ==
'x' || dominant_dir ==
'y') {
2808 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, K-DIR]: Kdx %2d (Ghost for Cell[0][j][i]) = (%.5f, %.5f, %.5f)\n", rank, 0, l_arr[0][j_mid][i_mid].x, l_arr[0][j_mid][i_mid].y, l_arr[0][j_mid][i_mid].z);
2809 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, K-DIR]: Kdx %2d (Value for Cell[0][j][i]) = (%.5f, %.5f, %.5f)\n", rank, 1, l_arr[1][j_mid][i_mid].x, l_arr[1][j_mid][i_mid].y, l_arr[1][j_mid][i_mid].z);
2810 }
else if (dominant_dir ==
'm') {
2811 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, K-DIR]: w-comp @ Idx %2d (1st Z-Face) = %.5f\n", rank, 0, l_arr[0][j_mid][i_mid].z);
2814 if (info.zs + info.zm == info.mz) {
2815 if (dominant_dir ==
'z') {
2816 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, K-DIR]: Idx %2" PetscInt_FMT
" (Last Phys. Z-Face) = (%.5f, %.5f, %.5f)\n", rank, km_phys - 1, l_arr[km_phys - 1][j_mid][i_mid].x, l_arr[km_phys - 1][j_mid][i_mid].y, l_arr[km_phys - 1][j_mid][i_mid].z);
2817 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, K-DIR]: Idx %2" PetscInt_FMT
" (Ghost Location) = (%.5f, %.5f, %.5f)\n", rank, km_phys, l_arr[km_phys][j_mid][i_mid].x, l_arr[km_phys][j_mid][i_mid].y, l_arr[km_phys][j_mid][i_mid].z);
2818 }
else if (dominant_dir ==
'x' || dominant_dir ==
'y') {
2819 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, K-DIR]: Idx %2" PetscInt_FMT
" (Value for Cell[%" PetscInt_FMT
"][j][i]) = (%.5f, %.5f, %.5f)\n", rank, km_phys-1, km_phys-2, l_arr[km_phys-1][j_mid][i_mid].x, l_arr[km_phys-1][j_mid][i_mid].y, l_arr[km_phys - 1][j_mid][i_mid].z);
2820 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, K-DIR]: Idx %2" PetscInt_FMT
" (Ghost for Cell[%" PetscInt_FMT
"][j][i]) = (%.5f, %.5f, %.5f)\n", rank, km_phys, km_phys-2, l_arr[km_phys][j_mid][i_mid].x, l_arr[km_phys][j_mid][i_mid].y, l_arr[km_phys][j_mid][i_mid].z);
2821 }
else if (dominant_dir ==
'm') {
2822 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, K-DIR]: w-comp @ Idx %2" PetscInt_FMT
" (Last Z-Face) = %.5f\n", rank, km_phys - 1, l_arr[km_phys - 1][j_mid][i_mid].z);
2823 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, K-DIR]: w-comp @ Idx %2" PetscInt_FMT
" (Ghost Loc.) = %.5f\n", rank, km_phys, l_arr[km_phys][j_mid][i_mid].z);
2827 ierr = DMDAVecRestoreArrayRead(dm, vec_local, (
void*)&l_arr); CHKERRQ(ierr);
2834 const PetscReal ***l_arr;
2835 ierr = DMDAVecGetArrayRead(dm, vec_local, (
void*)&l_arr); CHKERRQ(ierr);
2838 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, I-DIR]: Idx %2d (First Phys. Node) = %.5f\n", rank, 0, l_arr[k_mid][j_mid][0]);
2839 if (info.xs + info.xm == info.mx) {
2840 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, I-DIR]: Idx %2" PetscInt_FMT
" (Last Phys. Node) = %.5f\n", rank, im_phys - 1, l_arr[k_mid][j_mid][im_phys - 1]);
2841 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, I-DIR]: Idx %2" PetscInt_FMT
" (Unused/Ghost Loc) = %.5f\n", rank, im_phys, l_arr[k_mid][j_mid][im_phys]);
2844 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, J-DIR]: Jdx %2d (First Phys. Node) = %.5f\n", rank, 0, l_arr[k_mid][0][i_mid]);
2845 if (info.ys + info.ym == info.my) {
2846 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, J-DIR]: Jdx %2" PetscInt_FMT
" (Last Phys. Node) = %.5f\n", rank, jm_phys - 1, l_arr[k_mid][jm_phys - 1][i_mid]);
2847 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, J-DIR]: Jdx %2" PetscInt_FMT
" (Unused/Ghost Loc) = %.5f\n", rank, jm_phys, l_arr[k_mid][jm_phys][i_mid]);
2850 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, K-DIR]: Kdx %2d (First Phys. Node) = %.5f\n", rank, 0, l_arr[0][j_mid][i_mid]);
2851 if (info.zs + info.zm == info.mz) {
2852 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, K-DIR]: Kdx %2" PetscInt_FMT
" (Last Phys. Node) = %.5f\n", rank, km_phys - 1, l_arr[km_phys - 1][j_mid][i_mid]);
2853 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, K-DIR]: Kdx %2" PetscInt_FMT
" (Unused/Ghost Loc) = %.5f\n", rank, km_phys, l_arr[km_phys][j_mid][i_mid]);
2855 ierr = DMDAVecRestoreArrayRead(dm, vec_local, (
void*)&l_arr); CHKERRQ(ierr);
2858 ierr = DMDAVecGetArrayRead(dm, vec_local, (
void*)&l_arr); CHKERRQ(ierr);
2862 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, I-DIR]: Idx %2d (First Phys. Node) = (%.5f, %.5f, %.5f)\n", rank, 0, l_arr[k_mid][j_mid][0].x, l_arr[k_mid][j_mid][0].y, l_arr[k_mid][j_mid][0].z);
2864 if (info.xs + info.xm == info.mx) {
2865 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, I-DIR]: Idx %2" PetscInt_FMT
" (Last Phys. Node) = (%.5f, %.5f, %.5f)\n", rank, im_phys - 1, l_arr[k_mid][j_mid][im_phys - 1].x, l_arr[k_mid][j_mid][im_phys - 1].y, l_arr[k_mid][j_mid][im_phys - 1].z);
2866 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, I-DIR]: Idx %2" PetscInt_FMT
" (Unused/Ghost Loc) = (%.5f, %.5f, %.5f)\n", rank, im_phys, l_arr[k_mid][j_mid][im_phys].x, l_arr[k_mid][j_mid][im_phys].y, l_arr[k_mid][j_mid][im_phys].z);
2870 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, J-DIR]: Jdx %2d (First Phys. Node) = (%.5f, %.5f, %.5f)\n", rank, 0, l_arr[k_mid][0][i_mid].x, l_arr[k_mid][0][i_mid].y, l_arr[k_mid][0][i_mid].z);
2872 if (info.ys + info.ym == info.my) {
2873 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, J-DIR]: Jdx %2" PetscInt_FMT
" (Last Phys. Node) = (%.5f, %.5f, %.5f)\n", rank, jm_phys - 1, l_arr[k_mid][jm_phys - 1][i_mid].x, l_arr[k_mid][jm_phys - 1][i_mid].y, l_arr[k_mid][jm_phys - 1][i_mid].z);
2874 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, J-DIR]: Jdx %2" PetscInt_FMT
" (Unused/Ghost Loc) = (%.5f, %.5f, %.5f)\n", rank, jm_phys, l_arr[k_mid][jm_phys][i_mid].x, l_arr[k_mid][jm_phys][i_mid].y, l_arr[k_mid][jm_phys][i_mid].z);
2878 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, K-DIR]: Kdx %2d (First Phys. Node) = (%.5f, %.5f, %.5f)\n", rank, 0, l_arr[0][j_mid][i_mid].x, l_arr[0][j_mid][i_mid].y, l_arr[0][j_mid][i_mid].z);
2880 if(info.zs + info.zm == info.mz) {
2881 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, K-DIR]: Kdx %2" PetscInt_FMT
" (Last Phys. Node) = (%.5f, %.5f, %.5f)\n", rank, km_phys - 1, l_arr[km_phys - 1][j_mid][i_mid].x, l_arr[km_phys - 1][j_mid][i_mid].y, l_arr[km_phys - 1][j_mid][i_mid].z);
2882 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"[Rank %d, K-DIR]: Kdx %2" PetscInt_FMT
" (Unused/Ghost Loc) = (%.5f, %.5f, %.5f)\n", rank, km_phys, l_arr[km_phys][j_mid][i_mid].x, l_arr[km_phys][j_mid][i_mid].y, l_arr[km_phys][j_mid][i_mid].z);
2884 ierr = DMDAVecRestoreArrayRead(dm, vec_local, (
void*)&l_arr); CHKERRQ(ierr);
2888 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
2889 "LOG_FIELD_ANATOMY encountered unsupported layout %d for field '%s'.",
2890 (
int)layout, field_name);
2893 ierr = PetscSynchronizedFlush(PETSC_COMM_WORLD, PETSC_STDOUT); CHKERRQ(ierr);
2894 ierr = PetscBarrier(NULL);
2896 PetscFunctionReturn(0);
2907 PetscFunctionBeginUser;
2914 PetscFunctionReturn(0);
2950 PetscFunctionBeginUser;
2952 PetscCheck(simCtx != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"SimCtx cannot be NULL.");
2955 LOG(
GLOBAL,
LOG_INFO,
"Statistics windows at step %" PetscInt_FMT
" (%" PetscInt_FMT
" window(s)):\n",
2960 char coverage[32] =
"";
2963 PetscCall(PetscSNPrintf(progress,
sizeof(progress),
"%5.1f%%",
2966 PetscCall(PetscSNPrintf(progress,
sizeof(progress),
" open"));
2974 PetscReal lowest = 1.0, highest = 0.0;
2979 PetscCall(PetscSNPrintf(coverage,
sizeof(coverage),
" valid=[%.2f,%.2f]",
2980 (
double)lowest, (
double)highest));
2984 " %-24s %-8s samples=%-8" PetscInt_FMT
" weight=%-12.6g represented=%-12.6g progress=%s%s\n",
2990 PetscFunctionReturn(0);
3001 PetscFunctionBeginUser;
3003 PetscCheck(user != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"UserCtx cannot be NULL.");
3006 PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE,
3007 "Corner anatomy logging expects a corner-staging field identity.");
3015 PetscFunctionReturn(0);
3028 PetscErrorCode ierr;
3029 DM swarm = user->
swarm;
3030 Vec positionVec, analyticalvelocityVec, velocityVec, errorVec;
3031 PetscReal Interpolation_error = 0.0;
3032 PetscReal Maximum_Interpolation_error = 0.0;
3033 PetscReal AnalyticalSolution_magnitude = 0.0;
3034 PetscReal ErrorPercentage = 0.0;
3040 ierr = VecDuplicate(positionVec, &analyticalvelocityVec); CHKERRQ(ierr);
3041 ierr = VecCopy(positionVec, analyticalvelocityVec); CHKERRQ(ierr);
3046 ierr = VecDuplicate(analyticalvelocityVec, &errorVec); CHKERRQ(ierr);
3047 ierr = VecCopy(analyticalvelocityVec, errorVec); CHKERRQ(ierr);
3049 ierr = VecNorm(analyticalvelocityVec, NORM_2, &AnalyticalSolution_magnitude); CHKERRQ(ierr);
3052 ierr = VecAXPY(errorVec, -1.0, velocityVec); CHKERRQ(ierr);
3053 ierr = VecNorm(errorVec, NORM_2, &Interpolation_error); CHKERRQ(ierr);
3054 ierr = VecNorm(errorVec,NORM_INFINITY,&Maximum_Interpolation_error); CHKERRQ(ierr);
3056 ErrorPercentage = (AnalyticalSolution_magnitude > 0) ?
3057 (Interpolation_error / AnalyticalSolution_magnitude * 100.0) : 0.0;
3060 if (simCtx->
rank == 0) {
3063 "step,time,L2_error,Linf_error,L2_analytical,error_pct,physical_time",
PICURV_CSV_APPEND,
3064 PETSC_FALSE, &f); CHKERRQ(ierr);
3067 PetscReal t = simCtx->
ti;
3068 PetscReal physical_time = 0.0;
3070 fprintf(f,
"%d,%.6e,%.6e,%.6e,%.6e,%.4f,%.6e\n",
3071 (
int)simCtx->
step, t,
3072 Interpolation_error, Maximum_Interpolation_error,
3073 AnalyticalSolution_magnitude, ErrorPercentage, physical_time);
3081 PetscPrintf(PETSC_COMM_WORLD,
"Interpolation error (%%): %g\n", ErrorPercentage);
3083 PetscPrintf(PETSC_COMM_WORLD,
"Maximum Interpolation error: %g\n", Maximum_Interpolation_error);
3086 ierr = VecDestroy(&analyticalvelocityVec); CHKERRQ(ierr);
3087 ierr = VecDestroy(&errorVec); CHKERRQ(ierr);
3103 PetscErrorCode ierr;
3106 PetscInt xs, xe, ys, ye, zs, ze, mx, my, mz;
3107 PetscInt lxs, lxe, lys, lye, lzs, lze;
3108 Vec reference_vec = NULL;
3109 PetscReal ***psi = NULL;
3110 PetscReal ***psi_ref = NULL;
3111 PetscReal ***aj = NULL;
3112 PetscReal ***count = NULL;
3113 PetscReal *particle_psi = NULL;
3114 PetscInt nlocal = 0;
3115 PetscReal local_l1 = 0.0, global_l1 = 0.0;
3116 PetscReal local_l2_sq = 0.0, global_l2_sq = 0.0;
3117 PetscReal local_linf = 0.0, global_linf = 0.0;
3118 PetscReal local_ref_l2_sq = 0.0, global_ref_l2_sq = 0.0;
3119 PetscReal local_grid_integral = 0.0, global_grid_integral = 0.0;
3120 PetscReal local_domain_volume = 0.0, global_domain_volume = 0.0;
3121 PetscReal local_particle_sum = 0.0, global_particle_sum = 0.0;
3122 PetscInt64 local_particle_count = 0, global_particle_count = 0;
3123 PetscInt64 local_cell_count = 0, global_cell_count = 0;
3124 PetscInt64 local_occupied_count = 0, global_occupied_count = 0;
3125 PetscReal particle_integral = 0.0;
3126 PetscReal occupancy_fraction = 0.0;
3127 PetscReal mean_particles_per_occupied_cell = 0.0;
3128 PetscReal l2_error = 0.0;
3129 PetscReal relative_l2_error = 0.0;
3131 PetscFunctionBeginUser;
3133 if (!user) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"UserCtx cannot be NULL.");
3137 PetscFunctionReturn(0);
3141 xs = info.xs; xe = info.xs + info.xm;
3142 ys = info.ys; ye = info.ys + info.ym;
3143 zs = info.zs; ze = info.zs + info.zm;
3144 mx = info.mx; my = info.my; mz = info.mz;
3145 lxs = (xs == 0) ? xs + 1 : xs; lxe = (xe == mx) ? xe - 1 : xe;
3146 lys = (ys == 0) ? ys + 1 : ys; lye = (ye == my) ? ye - 1 : ye;
3147 lzs = (zs == 0) ? zs + 1 : zs; lze = (ze == mz) ? ze - 1 : ze;
3149 ierr = VecDuplicate(user->
Psi, &reference_vec); CHKERRQ(ierr);
3152 ierr = DMDAVecGetArrayRead(user->
da, user->
Psi, &psi); CHKERRQ(ierr);
3153 ierr = DMDAVecGetArrayRead(user->
da, reference_vec, &psi_ref); CHKERRQ(ierr);
3154 ierr = DMDAVecGetArrayRead(user->
da, user->
Aj, &aj); CHKERRQ(ierr);
3155 ierr = DMDAVecGetArrayRead(user->
da, user->
ParticleCount, &count); CHKERRQ(ierr);
3157 for (PetscInt k = lzs; k < lze; ++k) {
3158 for (PetscInt j = lys; j < lye; ++j) {
3159 for (PetscInt i = lxs; i < lxe; ++i) {
3160 const PetscReal cell_volume = (PetscAbsReal(aj[k][j][i]) > 1.0e-14) ? (1.0 / aj[k][j][i]) : 0.0;
3161 const PetscReal err = psi[k][j][i] - psi_ref[k][j][i];
3162 local_cell_count += 1;
3163 local_domain_volume += cell_volume;
3164 local_grid_integral += psi[k][j][i] * cell_volume;
3165 local_l1 += PetscAbsReal(err) * cell_volume;
3166 local_l2_sq += err * err * cell_volume;
3167 local_ref_l2_sq += psi_ref[k][j][i] * psi_ref[k][j][i] * cell_volume;
3168 local_linf = PetscMax(local_linf, PetscAbsReal(err));
3169 if (count[k][j][i] > 0.0) local_occupied_count += 1;
3174 ierr = DMDAVecRestoreArrayRead(user->
da, user->
ParticleCount, &count); CHKERRQ(ierr);
3175 ierr = DMDAVecRestoreArrayRead(user->
da, user->
Aj, &aj); CHKERRQ(ierr);
3176 ierr = DMDAVecRestoreArrayRead(user->
da, reference_vec, &psi_ref); CHKERRQ(ierr);
3177 ierr = DMDAVecRestoreArrayRead(user->
da, user->
Psi, &psi); CHKERRQ(ierr);
3178 ierr = VecDestroy(&reference_vec); CHKERRQ(ierr);
3180 ierr = DMSwarmGetLocalSize(user->
swarm, &nlocal); CHKERRQ(ierr);
3181 local_particle_count = (PetscInt64)nlocal;
3184 for (PetscInt p = 0; p < nlocal; ++p) local_particle_sum += particle_psi[p];
3188 ierr = MPI_Allreduce(&local_l1, &global_l1, 1, MPIU_REAL, MPI_SUM, PETSC_COMM_WORLD); CHKERRMPI(ierr);
3189 ierr = MPI_Allreduce(&local_l2_sq, &global_l2_sq, 1, MPIU_REAL, MPI_SUM, PETSC_COMM_WORLD); CHKERRMPI(ierr);
3190 ierr = MPI_Allreduce(&local_linf, &global_linf, 1, MPIU_REAL, MPI_MAX, PETSC_COMM_WORLD); CHKERRMPI(ierr);
3191 ierr = MPI_Allreduce(&local_ref_l2_sq, &global_ref_l2_sq, 1, MPIU_REAL, MPI_SUM, PETSC_COMM_WORLD); CHKERRMPI(ierr);
3192 ierr = MPI_Allreduce(&local_grid_integral, &global_grid_integral, 1, MPIU_REAL, MPI_SUM, PETSC_COMM_WORLD); CHKERRMPI(ierr);
3193 ierr = MPI_Allreduce(&local_domain_volume, &global_domain_volume, 1, MPIU_REAL, MPI_SUM, PETSC_COMM_WORLD); CHKERRMPI(ierr);
3194 ierr = MPI_Allreduce(&local_particle_sum, &global_particle_sum, 1, MPIU_REAL, MPI_SUM, PETSC_COMM_WORLD); CHKERRMPI(ierr);
3195 ierr = MPI_Allreduce(&local_particle_count, &global_particle_count, 1, MPIU_INT64, MPI_SUM, PETSC_COMM_WORLD); CHKERRMPI(ierr);
3196 ierr = MPI_Allreduce(&local_cell_count, &global_cell_count, 1, MPIU_INT64, MPI_SUM, PETSC_COMM_WORLD); CHKERRMPI(ierr);
3197 ierr = MPI_Allreduce(&local_occupied_count, &global_occupied_count, 1, MPIU_INT64, MPI_SUM, PETSC_COMM_WORLD); CHKERRMPI(ierr);
3199 l2_error = PetscSqrtReal(global_l2_sq);
3200 relative_l2_error = (global_ref_l2_sq > 0.0) ? (l2_error / PetscSqrtReal(global_ref_l2_sq)) : 0.0;
3201 occupancy_fraction = (global_cell_count > 0) ? ((PetscReal)global_occupied_count / (PetscReal)global_cell_count) : 0.0;
3202 mean_particles_per_occupied_cell =
3203 (global_occupied_count > 0) ? ((PetscReal)global_particle_count / (PetscReal)global_occupied_count) : 0.0;
3205 (global_particle_count > 0) ? (global_domain_volume * global_particle_sum / (PetscReal)global_particle_count) : 0.0;
3207 if (simCtx->
rank == 0) {
3210 "step,time,total_particles,total_cells,occupied_cells,occupancy_fraction,"
3211 "mean_particles_per_occupied_cell,particle_integral,grid_integral,"
3212 "conservation_error_abs,L1_error,L2_error,Linf_error,relative_L2_error,"
3215 PetscReal physical_time = 0.0;
3217 fprintf(f,
"%d,%.6e,%lld,%lld,%lld,%.6e,%.6e,%.6e,%.6e,%.6e,%.6e,%.6e,%.6e,%.6e,%.6e\n",
3220 (
long long)global_particle_count,
3221 (
long long)global_cell_count,
3222 (
long long)global_occupied_count,
3223 (
double)occupancy_fraction,
3224 (
double)mean_particles_per_occupied_cell,
3225 (
double)particle_integral,
3226 (
double)global_grid_integral,
3227 (
double)PetscAbsReal(global_grid_integral - particle_integral),
3230 (
double)global_linf,
3231 (
double)relative_l2_error,
3232 (
double)physical_time);
3243 PetscFunctionReturn(0);
3254 PetscFunctionBeginUser;
3256 if (!simCtx) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"SimCtx cannot be NULL for ResetSearchMetrics.");
3279 PetscFunctionReturn(0);
3290 PetscErrorCode ierr;
3292 PetscInt totalParticles = 0;
3295 PetscReal meanTraversalSteps = 0.0;
3296 PetscReal searchFailureFraction = 0.0;
3297 PetscReal searchWorkIndex = 0.0;
3298 PetscReal reSearchFraction = 0.0;
3299 long long searchAttempts = 0;
3300 long long searchPopulation = 0;
3301 long long searchLocatedCount = 0;
3302 long long searchLostCount = 0;
3303 long long traversalStepsSum = 0;
3304 long long reSearchCount = 0;
3305 long long tieBreakCount = 0;
3306 long long boundaryClampCount = 0;
3307 long long bboxGuessSuccessCount = 0;
3308 long long bboxGuessFallbackCount = 0;
3309 long long maxTraversalFailCount = 0;
3310 long long maxTraversalSteps = 0;
3311 long long maxPassDepth = 0;
3312 long long searchExitedCount = 0;
3313 long long blockedWalkRetryCount = 0;
3314 long long reflectionCount = 0;
3315 long long reflectionFallbackCount = 0;
3316 long long wrapCount = 0;
3317 MPI_Op reduction_op = MPI_OP_NULL;
3319 PetscFunctionBeginUser;
3321 if (!user || !user->
simCtx) {
3322 SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"UserCtx and SimCtx are required for LOG_SEARCH_METRICS.");
3328 PetscFunctionReturn(0);
3331 ierr = DMSwarmGetSize(user->
swarm, &totalParticles); CHKERRQ(ierr);
3353 ierr = MPI_Allreduce(local_metrics, global_metrics,
SEARCH_METRIC_REDUCTION_LEN, MPIU_REAL, reduction_op, PETSC_COMM_WORLD); CHKERRMPI(ierr);
3354 ierr = MPI_Op_free(&reduction_op); CHKERRMPI(ierr);
3355 reduction_op = MPI_OP_NULL;
3376 if (searchAttempts > 0) {
3377 meanTraversalSteps = (PetscReal)traversalStepsSum / (PetscReal)searchAttempts;
3379 if (searchPopulation > 0) {
3380 searchFailureFraction = (PetscReal)searchLostCount / (PetscReal)searchPopulation;
3381 searchWorkIndex = (PetscReal)traversalStepsSum / (PetscReal)searchPopulation;
3382 reSearchFraction = (PetscReal)reSearchCount / (PetscReal)searchPopulation;
3385 if (simCtx->
rank == 0) {
3387 PetscReal searchPhysicalTime = 0.0;
3391 "step,time,total_particles,lost,lost_cumulative,migrated,migration_passes,search_attempts,"
3392 "mean_traversal_steps,max_traversal_steps,tie_break_count,boundary_clamp_count,"
3393 "bbox_guess_success_count,bbox_guess_fallback_count,max_particle_pass_depth,load_imbalance,"
3394 "search_population,search_located_count,search_lost_count,traversal_steps_sum,re_search_count,"
3395 "max_traversal_fail_count,search_failure_fraction,search_work_index,re_search_fraction,"
3396 "physical_time,lost_psi_sum,exited,exited_cumulative,exited_psi_sum,search_exited_count,"
3397 "blocked_walk_retry_count,reflections,reflection_fallbacks,wraps,occupied_cells,"
3398 "particles_per_cell_min,particles_per_cell_mean,particles_per_cell_max",
3402 "%d,%.6e,%d,%d,%lld,%d,%d,%lld,%.6e,%lld,%lld,%lld,%lld,%lld,%lld,%.6e,%lld,%lld,%lld,%lld,%lld,%lld,%.6e,%.6e,%.6e,%.6e,%.10e,"
3403 "%d,%lld,%.10e,%lld,%lld,%lld,%lld,%lld,%d,%d,%.6e,%d\n",
3406 (
int)totalParticles,
3412 (
double)meanTraversalSteps,
3416 bboxGuessSuccessCount,
3417 bboxGuessFallbackCount,
3425 maxTraversalFailCount,
3426 (
double)searchFailureFraction,
3427 (
double)searchWorkIndex,
3428 (
double)reSearchFraction,
3429 (
double)searchPhysicalTime,
3435 blockedWalkRetryCount,
3437 reflectionFallbackCount,
3448 if (reflectionCount > 0 || blockedWalkRetryCount > 0 || wrapCount > 0) {
3449 LOG_ALLOW(
GLOBAL,
LOG_INFO,
"Step %d boundary events: %lld wall reflections, %lld periodic wraps, %lld blocked walks searched again.\n",
3450 (
int)simCtx->
step, reflectionCount, wrapCount, blockedWalkRetryCount);
3452 if (reflectionFallbackCount > 0) {
3453 LOG_ALLOW(
GLOBAL,
LOG_WARNING,
"Step %d: %lld particles reached the reflection cap and were placed just inside their boundary cell.\n",
3454 (
int)simCtx->
step, reflectionFallbackCount);
3458 "Search metrics: sff=%.3e swi=%.3e re_search=%.3e lost(step/total)=%d/%lld exited(step/total)=%d/%lld blocked_retries=%lld migrated=%d passes=%d traversal(mean/max)=%.2f/%lld tie_breaks=%lld max_pass_depth=%lld\n",
3459 (
double)searchFailureFraction,
3460 (
double)searchWorkIndex,
3461 (
double)reSearchFraction,
3466 blockedWalkRetryCount,
3469 (
double)meanTraversalSteps,
3475 PetscFunctionReturn(0);
3486 PetscErrorCode ierr;
3490 PetscFunctionBeginUser;
3492 size = simCtx->
size;
3495 PetscInt nLocal, nGlobal, nLocalMax;
3496 ierr = DMSwarmGetLocalSize(user->
swarm, &nLocal); CHKERRQ(ierr);
3497 ierr = DMSwarmGetSize(user->
swarm, &nGlobal); CHKERRQ(ierr);
3498 ierr = MPI_Allreduce(&nLocal, &nLocalMax, 1, MPIU_INT, MPI_MAX, PETSC_COMM_WORLD); CHKERRQ(ierr);
3500 PetscReal avg_per_rank = (size > 0) ? ((PetscReal)nGlobal / size) : 0.0;
3508 const DMDALocalInfo *info = &user->
info;
3509 const PetscScalar ***count_array;
3510 PetscInt64 sums[3] = {0, 0, 0};
3511 PetscInt64 extremes[2] = {PETSC_INT64_MAX, PETSC_INT64_MAX};
3512 const PetscInt i_lo = PetscMax(info->xs, 1), i_hi = PetscMin(info->xs + info->xm, info->mx - 1);
3513 const PetscInt j_lo = PetscMax(info->ys, 1), j_hi = PetscMin(info->ys + info->ym, info->my - 1);
3514 const PetscInt k_lo = PetscMax(info->zs, 1), k_hi = PetscMin(info->zs + info->zm, info->mz - 1);
3516 ierr = DMDAVecGetArrayRead(user->
da, user->
ParticleCount, (
void *)&count_array); CHKERRQ(ierr);
3517 for (PetscInt k = k_lo; k < k_hi; ++k) {
3518 for (PetscInt j = j_lo; j < j_hi; ++j) {
3519 for (PetscInt i = i_lo; i < i_hi; ++i) {
3520 const PetscInt64 n = (PetscInt64)(PetscRealPart(count_array[k][j][i]) + 0.5);
3524 extremes[0] = PetscMin(extremes[0], n);
3525 extremes[1] = PetscMin(extremes[1], -n);
3529 ierr = DMDAVecRestoreArrayRead(user->
da, user->
ParticleCount, (
void *)&count_array); CHKERRQ(ierr);
3531 ierr = MPI_Allreduce(MPI_IN_PLACE, sums, 3, MPIU_INT64, MPI_SUM, PETSC_COMM_WORLD); CHKERRMPI(ierr);
3532 ierr = MPI_Allreduce(MPI_IN_PLACE, extremes, 2, MPIU_INT64, MPI_MIN, PETSC_COMM_WORLD); CHKERRMPI(ierr);
3538 LOG_ALLOW(
GLOBAL,
LOG_INFO,
"Advanced Metrics: Imbalance=%.2f, OccupiedCells=%" PetscInt_FMT
", ParticlesPerCell min/mean/max=%" PetscInt_FMT
"/%.3f/%" PetscInt_FMT
"\n",
3543 PetscFunctionReturn(0);
3555 char path[PETSC_MAX_PATH_LEN + 128];
3556 FILE *handle = NULL;
3557 uint64_t key = 0xCBF29CE484222325ULL;
3558 PetscBool first_write = PETSC_TRUE;
3560 PetscFunctionBeginUser;
3562 PetscCheck(simCtx && dir && filename && header && file, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
3563 "A diagnostics CSV needs a context, a directory, a name, a header, and somewhere to "
3564 "return the handle.");
3567 PetscCall(PetscSNPrintf(path,
sizeof(path),
"%s/%s", dir, filename));
3568 for (
const char *c = path; *c; ++c) key = (key ^ (uint64_t)(
unsigned char)*c) * 0x100000001B3ULL;
3570 if (simCtx->
runCsvWritten[n] == key) first_write = PETSC_FALSE;
3576 PetscCheck(!required, PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN,
"Unable to open diagnostics file '%s'.", path);
3579 PetscFunctionReturn(0);
3583 if (ftell(handle) == 0) fprintf(handle,
"%s\n", header);
3587 fprintf(handle,
"# Continuation from step %" PetscInt_FMT
"\n", simCtx->
StartStep);
3592 PetscFunctionReturn(0);
PetscErrorCode SetAnalyticalSolutionForParticles(Vec tempVec, SimCtx *simCtx)
Evaluates the analytical velocity at particle positions.
const FieldDescriptor * descriptor
PetscErrorCode FieldGetView(UserCtx *user, FieldId field_id, FieldView *view)
Resolve the existing DM and global/local vectors for one field.
FieldLayout
Logical storage topology of a field.
@ FIELD_LAYOUT_CELL_CENTERED
@ FIELD_LAYOUT_COMPONENT_STAGGERED
@ FIELD_LAYOUT_NODE_CENTERED
const char * canonical_name
const char * FieldLayoutName(FieldLayout layout)
Return a stable printable label for a field layout.
FieldId
Compile-time identity for a catalogued Eulerian field.
@ FIELD_ID_CELL_SCALAR_AT_CORNER
@ FIELD_ID_CELL_VECTOR_AT_CORNER
Non-owning runtime objects resolved for one field and UserCtx.
PetscErrorCode PicurvPhysicalTime(const SimCtx *simCtx, PetscReal solver_time, PetscReal *physical)
Convert a solver time to physical seconds, t * L_ref / U_ref.
static PetscErrorCode _ProfilingEventTotals(PetscLogEvent event, PetscLogDouble *time, int *count)
Read an event's running total time and call count on this rank (main stage).
static void BuildHeaderString(char *headerStr, size_t bufSize, const int widths[6])
PetscErrorCode LOG_FIELD_MIN_MAX(UserCtx *user, FieldId field_id)
Implementation of LOG_FIELD_MIN_MAX().
const char * LESTestFilterKernelToString(LESTestFilterKernel kernel)
Implementation of LESTestFilterKernelToString().
PetscReal reference_ke_sum
PetscErrorCode EmitStatisticsConsoleSnapshot(UserCtx *user, const SimCtx *simCtx, PetscInt step)
Implementation of EmitStatisticsConsoleSnapshot().
void set_allowed_functions(const char **functionList, int count)
Implementation of set_allowed_functions().
static PetscErrorCode AppendStatisticalObservableSample(SimCtx *simCtx, PetscInt samples_before, PetscReal mean_speed, PetscReal mean_ke)
Appends one timestep's scalar observables to the statistical history.
PetscReal current_pressure_sum
static PetscErrorCode LogFieldAnatomyView(UserCtx *user, const char *field_name, const char *stage_name, DM dm, Vec vec_local, PetscInt dof, FieldLayout layout)
Shared architecture-aware anatomy logger for catalog and transient fields.
PetscErrorCode PicurvOpenRunCsv(SimCtx *simCtx, const char *dir, const char *filename, const char *header, PicurvCsvLifecycle lifecycle, PetscBool required, FILE **file)
Implementation of PicurvOpenRunCsv().
PetscBool ShouldEmitPeriodicStatisticsConsoleSnapshot(const SimCtx *simCtx, PetscInt completed_step)
Implementation of ShouldEmitPeriodicStatisticsConsoleSnapshot().
const char * BCHandlerTypeToString(BCHandlerType handler_type)
Implementation of BCHandlerTypeToString().
PetscBool is_function_allowed(const char *functionName)
Implementation of is_function_allowed().
const LogLevel *const _picurv_log_level
Read-only view of the cached logging level; -1 until the first get_log_level() call.
PetscErrorCode DualMonitorDestroy(void **ctx)
Implementation of DualMonitorDestroy().
static PetscErrorCode ComputeMaxColumnWidths(PetscInt nRows, const PetscInt *rows, const PetscMPIInt *ranks, const PetscInt64 *pids, const PetscInt *cellIDs, const PetscReal *positions, const PetscReal *velocities, const PetscReal *weights, int widths[6])
static int _CompareProfiledFunctionRanks(const void *a, const void *b)
Order final-summary rows by their slowest rank's total time, descending.
static char ** gAllowedFunctions
Global/static array of function names allowed to log.
void _ProfilingRegister(const char *func_name, PetscBool helper, PetscLogEvent *event)
Implementation of _ProfilingRegister().
static LogLevel current_log_level
Static variable to cache the current logging level.
PetscErrorCode LOG_INTERPOLATION_ERROR(UserCtx *user)
Implementation of LOG_INTERPOLATION_ERROR().
static PetscReal SolutionConvergenceHistoryGet(const PetscReal *history, PetscInt capacity, PetscInt samples_available, PetscInt offset_from_latest)
Reads one sample from the statistical ring buffer by age.
const char * ParticleBoundaryPolicyToString(ParticleBoundaryPolicy policy)
Implementation of ParticleBoundaryPolicyToString().
static PetscLogDouble * g_profile_step_time
static PetscInt g_profile_nselected
PetscBool ShouldEmitPeriodicParticleConsoleSnapshot(const SimCtx *simCtx, PetscInt completed_step)
Implementation of ShouldEmitPeriodicParticleConsoleSnapshot().
static char ** g_profile_selected
const char * BCFaceToString(BCFace face)
Implementation of BCFaceToString().
static int * g_profile_step_count
PetscErrorCode FreeAllowedFunctions(char **funcs, PetscInt n)
Implementation of FreeAllowedFunctions().
PetscBool IsParticleConsoleSnapshotEnabled(const SimCtx *simCtx)
Implementation of IsParticleConsoleSnapshotEnabled().
PetscErrorCode print_log_level(void)
Implementation of print_log_level().
PetscReal reference_pressure_sum
static PetscReal SolutionConvergenceSafeRelative(PetscReal numerator, PetscReal denominator)
Forms a guarded relative metric for solution-convergence logging.
PetscErrorCode EmitParticleConsoleSnapshot(UserCtx *user, SimCtx *simCtx, PetscInt step)
Implementation of EmitParticleConsoleSnapshot().
static PetscInt g_profile_step_capacity
void PrintProgressBar(PetscInt step, PetscInt startStep, PetscInt totalSteps, PetscReal currentTime, PetscReal seconds_per_step, PetscInt64 lost_cumulative)
Implementation of PrintProgressBar().
PetscErrorCode ProfilingFinalize(SimCtx *simCtx)
Implementation of ProfilingFinalize().
static void trim(char *s)
Remove leading and trailing whitespace from a mutable configuration string.
PetscErrorCode LoadAllowedFunctionsFromFile(const char filename[], char ***funcsOut, PetscInt *nOut)
Implementation of LoadAllowedFunctionsFromFile().
#define SOLUTION_CONVERGENCE_REL_EPS
PetscReal delta_pressure_norm_sq
static PetscClassId g_profile_class_helper
PetscReal delta_u_norm_sq
static int gNumAllowed
Number of entries in the gAllowedFunctions array.
static const char * SolutionConvergenceModeToString(SolutionConvergenceMode mode)
Maps the internal solution-convergence mode enum to its log label.
static void BuildRowFormatString(const int widths[6], char *fmtStr, size_t bufSize)
static PetscBool g_profile_all_helpers
const char * WallFunctionModelToString(WallFunctionModel model)
Implementation of WallFunctionModelToString().
PetscReal current_pressure_norm_sq
static void CellToStr(const PetscInt *cell, char *buf, size_t bufsize)
PetscReal current_u_norm_sq
PetscErrorCode RuntimeMemoryLogSample(SimCtx *simCtx, PetscInt step, const char *event, const char *reason)
Implementation of RuntimeMemoryLogSample().
PetscErrorCode ProfilingLogTimestepSummary(SimCtx *simCtx, PetscInt step)
Implementation of ProfilingLogTimestepSummary().
const char * LESFilterWidthModelToString(LESFilterWidthModel model)
Implementation of LESFilterWidthModelToString().
PetscErrorCode LOG_FACE_DISTANCES(PetscReal *d)
Implementation of LOG_FACE_DISTANCES().
PetscErrorCode LOG_PARTICLE_FIELDS(UserCtx *user, PetscInt printInterval)
Implementation of LOG_PARTICLE_FIELDS().
static void TripleRealToStr(const PetscReal *arr, char *buf, size_t bufsize)
static PetscErrorCode _ProfilingSnapshotStep(void)
Record every event's running totals as the start of the next step.
static void Int64ToStr(PetscInt64 value, char *buf, size_t bufsize)
const char * BCTypeToString(BCType type)
Implementation of BCTypeToString().
PetscReal current_speed_sum
static PetscBool _ProfilingHelperEnabled(const char *name)
Whether a helper function's timer is enabled.
static PetscBool _ProfilingNameListed(const char *name, char **names, PetscInt n)
Whether a name appears in a list of names.
PetscErrorCode CalculateAdvancedParticleMetrics(UserCtx *user)
Implementation of CalculateAdvancedParticleMetrics().
const char * ParticleLocationStatusToString(ParticleLocationStatus level)
Implementation of ParticleLocationStatusToString().
PetscErrorCode LOG_SCATTER_METRICS(UserCtx *user)
Implementation of LOG_SCATTER_METRICS().
static PetscErrorCode _ProfilingEnsureStarted(void)
Register the two PICurv event classes and start PETSc's default log handler, once.
PetscErrorCode LOG_SOLUTION_CONVERGENCE(SimCtx *simCtx)
Implementation of LOG_SOLUTION_CONVERGENCE().
PetscErrorCode DualKSPMonitor(KSP ksp, PetscInt it, PetscReal rnorm, void *ctx)
Implementation of DualKSPMonitor().
static PetscErrorCode _ProfilingReduceSection(FILE *f, const char *section, PetscInt nlocal, const char **names, const PetscLogDouble *times, const long long *counts)
Reduce one section of the final summary across ranks and print it on rank 0.
PetscErrorCode LOG_CONTINUITY_METRICS(UserCtx *user)
Implementation of LOG_CONTINUITY_METRICS().
PetscErrorCode LOG_CORNER_FIELD_ANATOMY(UserCtx *user, FieldId corner_field_id, const char *stage_name)
Emits anatomy for the transient scalar or vector corner-staging field.
const char * LESAveragingModeToString(LESAveragingMode mode)
Implementation of LESAveragingModeToString().
PetscErrorCode LOG_FIELD_ANATOMY(UserCtx *user, FieldId field_id, const char *stage_name)
Resolves a persistent field view and emits its layout-aware boundary anatomy.
static PetscErrorCode ComputeStatisticalWindowMetrics(const SimCtx *simCtx, PetscInt samples_available, PetscBool *has_reference_out, PetscReal *mean_speed_window_out, PetscReal *mean_speed_window_prev_out, PetscReal *mean_speed_window_abs_out, PetscReal *mean_speed_window_rel_out, PetscReal *mean_speed_rms_window_out, PetscReal *mean_speed_rms_window_prev_out, PetscReal *mean_speed_rms_window_abs_out, PetscReal *mean_speed_rms_window_rel_out, PetscReal *mean_ke_window_out, PetscReal *mean_ke_window_prev_out, PetscReal *mean_ke_window_abs_out, PetscReal *mean_ke_window_rel_out, PetscReal *mean_ke_rms_window_out, PetscReal *mean_ke_rms_window_prev_out, PetscReal *mean_ke_rms_window_abs_out, PetscReal *mean_ke_rms_window_rel_out)
Computes adjacent-window drift metrics for statistical steady mode.
PetscErrorCode LOG_SEARCH_METRICS(UserCtx *user)
Implementation of LOG_SEARCH_METRICS().
const char * InterpolationMethodToString(InterpolationMethod method)
Implementation of InterpolationMethodToString().
const PetscBool *const _picurv_profile_helpers_on
Read-only view: whether profiling.helpers enables any helper timer.
PetscErrorCode ProfilingInitialize(SimCtx *simCtx)
Implementation of ProfilingInitialize().
static PetscClassId g_profile_class_function
const char * LESModelToString(LESModelType LESFlag)
Implementation of LESModelToString().
PetscErrorCode LOG_CELL_VERTICES(const Cell *cell, PetscMPIInt rank)
Implementation of LOG_CELL_VERTICES().
static void IntToStr(int value, char *buf, size_t bufsize)
LogLevel _ResolveLogLevel(void)
Implementation of _ResolveLogLevel().
static PetscErrorCode ComputeDeterministicSolutionMetrics(SimCtx *simCtx, PetscBool periodic_mode, PetscInt phase_step, PetscInt samples_before, PetscBool *has_reference_out, PetscReal *u_abs_l2_out, PetscReal *u_rel_l2_out, PetscReal *p_abs_l2_out, PetscReal *p_rel_l2_out, PetscReal *mean_speed_out, PetscReal *mean_speed_ref_out, PetscReal *mean_speed_abs_out, PetscReal *mean_speed_rel_out, PetscReal *mean_ke_out, PetscReal *mean_ke_ref_out, PetscReal *mean_ke_abs_out, PetscReal *mean_ke_rel_out)
Computes deterministic solution-drift metrics for the current step.
PetscErrorCode ProfilingResetTimestepCounters(void)
Implementation of ProfilingResetTimestepCounters().
PetscBool IsStatisticsConsoleSnapshotEnabled(const SimCtx *simCtx)
Implementation of IsStatisticsConsoleSnapshotEnabled().
PetscErrorCode ResetSearchMetrics(SimCtx *simCtx)
Implementation of ResetSearchMetrics().
const char * LESClipModeToString(LESClipMode mode)
Implementation of LESClipModeToString().
const char * MomentumSolverTypeToString(MomentumSolverType SolverFlag)
Implementation of MomentumSolverTypeToString().
static PetscBool _ProfilingIsPicurvClass(PetscClassId classid)
Whether a PETSc event belongs to one of PICurv's classes.
@ SEARCH_METRIC_SUM_SEARCH_LOCATED
@ SEARCH_METRIC_SUM_WRAPS
@ SEARCH_METRIC_SUM_MAX_TRAVERSAL_FAILS
@ SEARCH_METRIC_REDUCTION_LEN
@ SEARCH_METRIC_SUM_BBOX_GUESS_FALLBACK
@ SEARCH_METRIC_SUM_RESEARCH
@ SEARCH_METRIC_SUM_SEARCH_EXITED
@ SEARCH_METRIC_SUM_REFLECTIONS
@ SEARCH_METRIC_SUM_TRAVERSAL_STEPS
@ SEARCH_METRIC_SUM_BLOCKED_RETRY
@ SEARCH_METRIC_MAX_TRAVERSAL_STEPS
@ SEARCH_METRIC_SUM_BOUNDARY_CLAMPS
@ SEARCH_METRIC_SUM_SEARCH_POPULATION
@ SEARCH_METRIC_MAX_PASS_DEPTH
@ SEARCH_METRIC_SUM_TIE_BREAKS
@ SEARCH_METRIC_SUM_SEARCH_LOST
@ SEARCH_METRIC_SUM_REFLECTION_FALLBACKS
@ SEARCH_METRIC_SUM_BBOX_GUESS_SUCCESS
@ SEARCH_METRIC_SUM_SEARCH_ATTEMPTS
static PetscErrorCode ComputeCurrentFlowObservables(SimCtx *simCtx, PetscReal *mean_speed_out, PetscReal *mean_ke_out)
Computes instantaneous global flow observables for statistical mode.
#define SOLUTION_CONVERGENCE_FLUID_THRESHOLD
static char ** g_profile_helpers
static PetscBool g_profile_any_helpers
const char * ParticleInitializationToString(ParticleInitializationType ParticleInitialization)
Implementation of ParticleInitializationToString().
static int _CompareNames(const void *a, const void *b)
Order C strings, for qsort over const char * arrays.
static void SearchMetricsReduceOp(void *invec, void *inoutvec, int *len, MPI_Datatype *datatype)
Internal reduction callback for packed search metrics.
PetscReal reference_speed_sum
static PetscInt g_profile_nhelpers
Logging utilities and macros for PETSc-based applications.
PicurvCsvLifecycle
What a run's first write does to an existing CSV record (see PicurvOpenRunCsv()).
@ PICURV_CSV_TRUNCATE_ON_FRESH
A fresh run's first write empties the file; a continued run appends.
@ PICURV_CSV_APPEND
Every run appends: earlier runs' rows are kept.
#define LOCAL
Logging scope definitions for controlling message output.
#define GLOBAL
Scope for global logging across all processes.
static PetscErrorCode PicurvOpenDiagnosticsCsv(SimCtx *simCtx, const char *dir, const char *filename, const char *header, FILE **file)
Opens a per-step diagnostics CSV: PicurvOpenRunCsv() with the common settings.
#define LOG_ALLOW(scope, level, fmt,...)
Logging macro that checks both the log level and whether the calling function is in the allowed-funct...
#define PROFILE_HELPER_BEGIN
Marks the beginning of a profiled helper: timed only when enabled by name.
#define PROFILE_HELPER_END
Alias of PROFILE_FUNCTION_END for a function that began with PROFILE_HELPER_BEGIN.
#define PROFILE_FUNCTION_END
Marks the end of a profiled code block.
#define LOG(scope, level, fmt,...)
Logging macro for PETSc-based applications with scope control.
LogLevel
Enumeration of logging levels.
@ LOG_ERROR
Critical errors that may halt the program.
@ LOG_TRACE
Very fine-grained tracing information for in-depth debugging.
@ LOG_INFO
Informational messages about program execution.
@ LOG_WARNING
Non-critical issues that warrant attention.
@ LOG_DEBUG
Detailed debugging information.
@ LOG_VERBOSE
Extremely detailed logs, typically for development use only.
#define PROFILE_FUNCTION_BEGIN
Marks the beginning of a profiled function: an always-on aggregate timer.
static LogLevel get_log_level(void)
Retrieves the current logging level from the environment variable LOG_LEVEL.
Context for a dual-purpose KSP monitor.
Typed identities and metadata for persistent solver-particle fields.
const char * ParticleFieldName(ParticleFieldId field_id)
Return the canonical PETSc DMSwarm name for an ID.
@ PARTICLE_FIELD_ID_WEIGHT
@ PARTICLE_FIELD_ID_POSITION
@ PARTICLE_FIELD_ID_CELL_ID
@ PARTICLE_FIELD_ID_VELOCITY
Per-window PETSc accumulator storage and pointwise application.
PetscErrorCode PicurvWindowValidFractionRange(UserCtx *user, const PicurvWindowDefinition *definition, const PicurvWindowStorage *storage, PetscInt sample_count, PetscReal *minimum, PetscReal *maximum)
Reports the range of per-point valid fraction across a window's domain.
Window lifecycle, scheduling, and weighting for the field-statistics pipeline.
const char * PicurvWindowStateName(PicurvWindowState state)
Returns a stable human-readable name for a window state.
PetscBool bounded
False for an open-ended window.
PicurvWindowDefinition definition
PetscBool FieldStatisticsIsActive(const struct SimCtx *simCtx)
Reports whether this run has live field-statistics state.
PetscReal PicurvWindowProgress(const PicurvWindow *window)
Reports the fraction of a bounded window's span that has been represented.
PetscReal represented_time
Physical time the window covers.
Runtime state of one window.
PetscInt particlesPerCellMin
Fewest particles in any cell after the step.
LESModelType
Identifies the subgrid-scale closure evaluated during a timestep.
PetscInt particlesPerCellMax
Most particles in any cell after the step.
PetscInt fieldStatisticsWindowCount
BCType
Defines the general mathematical/physical Category of a boundary.
PetscBool profilingFinalSummary
PetscInt64 searchLocatedCount
PetscInt64 reflectionCount
PetscInt statisticsConsoleOutputFreq
PetscInt64 searchLostCount
Vec * solutionConvergencePeriodicPRef
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.
@ PARTICLE_INIT_POINT_SOURCE
All particles at a fixed (psrc_x,psrc_y,psrc_z) — for validation.
@ PARTICLE_INIT_VOLUME
Random volumetric distribution across the domain.
ParticleLocationStatus
Defines the state of a particle with respect to its location and migration status during the iterativ...
@ LOST
The search failed for a particle believed to be inside the domain.
@ EXITED
The particle crossed a domain-boundary face whose particle policy removes it.
PetscReal * solutionConvergenceMeanSpeedHistory
PetscBool runtimeMemoryLogEnabled
Enable the rank-reduced runtime memory log (log_dir/Runtime_Memory.csv).
PetscInt64 boundaryClampCount
PetscInt particlesLostLastStep
Particles removed this step because their search failed.
Vec * solutionConvergencePeriodicUcatRef
ParticleBoundaryPolicy
What happens to a particle that crosses a domain-boundary face.
@ PARTICLE_BOUNDARY_REMOVE
The particle leaves the domain (EXITED) and is removed.
@ PARTICLE_BOUNDARY_REFLECT
The particle is mirrored about the face plane and stays.
@ PARTICLE_BOUNDARY_WRAP
Periodic faces: the particle re-enters through the paired face.
PetscInt64 traversalStepsSum
BCHandlerType
Defines the specific computational "strategy" for a boundary handler.
@ BC_HANDLER_PERIODIC_GEOMETRIC
@ BC_HANDLER_PERIODIC_DRIVEN_INITIAL_FLUX
@ BC_HANDLER_INTERFACE_OVERSET
@ BC_HANDLER_PERIODIC_DRIVEN_CONSTANT_FLUX
@ BC_HANDLER_INLET_PRESCRIBED_VELOCITY
@ BC_HANDLER_OUTLET_CONSERVATION
@ BC_HANDLER_WALL_FREE_SLIP
@ BC_HANDLER_FARFIELD_NONREFLECTING
@ BC_HANDLER_OUTLET_PRESSURE
PetscInt solutionConvergenceSamplesRecorded
PetscReal poissonSourceImbalance
PetscInt64 searchPopulation
PetscBool solutionConvergenceEnabled
PetscReal * solutionConvergenceMeanKEHistory
PetscInt occupiedCellCount
LESClipMode
Selects the admissible range imposed on the dynamic model coefficient.
char profilingTimestepMode[32]
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.
WallFunctionModel
Selects the wall model applied on WALL faces.
PetscInt currentSettlementPass
PetscInt64 searchExitedCount
MomentumSolverType
Enumerator to identify the implemented momentum solver strategies.
@ MOMENTUM_SOLVER_DUALTIME_PICARD_JAMESON_RK
@ MOMENTUM_SOLVER_EXPLICIT_RK
@ MOMENTUM_SOLVER_NEWTON_KRYLOV
PetscInt solutionConvergencePeriodSteps
PetscReal particlesExitedScalarLastStep
Sum of Psi over the particles that left the domain this step.
PetscInt64 bboxGuessFallbackCount
char analysis_dir[PETSC_MAX_PATH_LEN]
uint64_t runCsvWritten[256]
Rank 0 only: path hashes of the CSV records this run has opened (see PicurvOpenRunCsv()).
PetscInt64 bboxGuessSuccessCount
struct PicurvWindow * fieldStatisticsWindows
char log_dir[PETSC_MAX_PATH_LEN]
PetscInt64 maxParticlePassDepth
PetscInt64 maxTraversalSteps
PetscInt64 particlesLostCumulative
InterpolationMethod
Selects the grid-to-particle interpolation method.
#define PICURV_RUN_CSV_CAPACITY
Most distinct CSV records one run opens through PicurvOpenRunCsv(): about twenty, plus a few per bloc...
PetscReal particlesPerCellMean
Particles counted in cells divided by the cell count.
LESAveragingMode
Selects the set over which the Germano contractions are averaged.
@ LES_AVERAGING_HOMOGENEOUS
PetscBool runtimeMemoryLogHasPrevious
True after the first process-memory sample.
char ** profilingSelectedFuncs
PetscInt64 particlesExitedCumulative
PetscInt solutionConvergenceWindowSteps
PetscInt particlesExitedLastStep
Particles removed this step because they left the domain.
PetscInt nProfilingSelectedFuncs
PetscInt particlesMigratedLastStep
struct PicurvWindowStorage * fieldStatisticsStorage
PetscInt particleConsoleOutputFreq
SearchMetricsState searchMetrics
PetscReal runtimeMemoryLogPreviousProcessMB
Previous local process memory sample in MB.
PetscInt migrationPassesLastStep
@ EXEC_MODE_POSTPROCESSOR
PetscBool profilingAllHelpers
-profiling_helpers all: every helper timer is enabled.
SolutionConvergenceMode
Selects the runtime solution-convergence diagnostics mode.
@ SOLUTION_CONVERGENCE_TRANSIENT
@ SOLUTION_CONVERGENCE_PERIODIC_DETERMINISTIC
@ SOLUTION_CONVERGENCE_STATISTICAL_STEADY
@ SOLUTION_CONVERGENCE_STEADY_DETERMINISTIC
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
PetscInt64 reflectionFallbackCount
PetscInt64 blockedWalkRetryCount
PetscInt64 maxTraversalFailCount
PetscInt nProfilingHelpers
LESFilterWidthModel
Selects how a cell's grid filter width is derived from its metrics.
@ LES_FILTER_WIDTH_SCOTTI
@ LES_FILTER_WIDTH_GEOMETRIC_MEAN
@ LES_FILTER_WIDTH_CUBE_ROOT_VOLUME
@ LES_FILTER_WIDTH_MAX_EDGE
PetscInt LoggingFrequency
Cmpnts vertices[8]
Coordinates of the eight vertices of the cell.
PetscReal lastStepWallSeconds
Slowest rank's wall time of the last completed step (0 before one).
PetscReal particleLoadImbalance
PetscInt runCsvWrittenCount
Entries of runCsvWritten in use.
BCFace
Identifies the six logical faces of a structured computational block.
#define PICURV_SNAPSHOT_ROWS_PER_RANK
Most rows one rank contributes to a particle console snapshot (io.particle_log_interval samples IDs).
Defines the vertices of a single hexahedral grid cell.
A 3D point or vector with PetscScalar components.
The master context for the entire simulation.
User-defined context containing data specific to a single computational grid level.
PetscBool VerificationScalarOverrideActive(const SimCtx *simCtx)
Reports whether a verification-only scalar override is active.
PetscErrorCode SetVerificationScalarAtCellCenters(UserCtx *user, Vec targetVec)
Writes the configured verification scalar profile at physical cell centers into a scalar Vec.