8#define __FUNCT__ "DimensionalizeField"
19 Vec target_vec = NULL;
20 PetscReal scale_factor = 1.0;
21 char field_type[64] =
"Unknown";
22 PetscBool is_swarm_field = PETSC_FALSE;
23 const char *swarm_field_name = NULL;
26 PetscBool found = PETSC_FALSE;
28 PetscFunctionBeginUser;
30 if (!user) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"UserCtx is NULL.");
31 if (!field_name) SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"field_name is NULL.");
37 ierr = DMGetCoordinates(user->
da, &target_vec); CHKERRQ(ierr);
41 ierr =
FieldGetView(user, field_id, &view); CHKERRQ(ierr);
47 PetscCheck(found, PETSC_COMM_SELF, PETSC_ERR_ARG_UNKNOWN_TYPE,
48 "DimensionalizeField: '%s' is in neither field catalog.", field_name);
50 is_swarm_field = PETSC_TRUE;
54 field_type,
sizeof(field_type)); CHKERRQ(ierr);
57 if (PetscAbsReal(scale_factor - 1.0) < PETSC_MACHINE_EPSILON) {
58 LOG(
GLOBAL,
LOG_DEBUG,
"DimensionalizeField: Scaling factor for '%s' is 1.0. Skipping operation.\n", field_name);
60 PetscFunctionReturn(0);
64 LOG(
GLOBAL,
LOG_INFO,
"Scaling '%s' field (%s) by factor %.4e.\n", field_name, field_type, scale_factor);
68 ierr = DMSwarmCreateGlobalVectorFromField(user->
swarm, swarm_field_name, &target_vec); CHKERRQ(ierr);
69 ierr = VecScale(target_vec, scale_factor); CHKERRQ(ierr);
70 ierr = DMSwarmDestroyGlobalVectorFromField(user->
swarm, swarm_field_name, &target_vec); CHKERRQ(ierr);
74 ierr = VecScale(target_vec, scale_factor); CHKERRQ(ierr);
76 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONGSTATE,
"Target vector for field '%s' was not found or is NULL.", field_name);
81 if (strcasecmp(field_name,
"Coordinates") == 0) {
86 PetscFunctionReturn(0);
92#define __FUNCT__ "ComputeNodalAverage"
103 Vec in_vec_local = NULL, out_vec_global = NULL;
104 DM dm_in = NULL, dm_out = NULL;
107 PetscFunctionBeginUser;
109 LOG_ALLOW(
GLOBAL,
LOG_INFO,
"-> KERNEL: Running ComputeNodalAverage on '%s' -> '%s'.\n", in_field_name, out_field_name);
112 if (strcasecmp(in_field_name,
"P") == 0) { in_vec_local = user->
lP; dm_in = user->
da; dof = 1; }
113 else if (strcasecmp(in_field_name,
"Ucat") == 0) { in_vec_local = user->
lUcat; dm_in = user->
fda; dof = 3; }
114 else if (strcasecmp(in_field_name,
"Psi") == 0) { in_vec_local = user->
lPsi; dm_in = user->
da; dof = 1; }
115 else if (strcasecmp(in_field_name,
"Qcrit") == 0) { in_vec_local = user->
lQcrit; dm_in = user->
da; dof = 1; }
118 else if (strcasecmp(in_field_name,
"PostScalar") == 0) { in_vec_local = user->
lPostScalar; dm_in = user->
da; dof = 1; }
119 else if (strcasecmp(in_field_name,
"PostVector") == 0) { in_vec_local = user->
lPostVector; dm_in = user->
fda; dof = 3; }
121 else SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
"Unknown input field name for nodal averaging: %s", in_field_name);
123 if (strcasecmp(out_field_name,
"P_nodal") == 0) { out_vec_global = user->
P_nodal; dm_out = user->
da; }
124 else if (strcasecmp(out_field_name,
"Ucat_nodal") == 0) { out_vec_global = user->
Ucat_nodal; dm_out = user->
fda; }
125 else if (strcasecmp(out_field_name,
"Psi_nodal") == 0) { out_vec_global = user->
Psi_nodal; dm_out = user->
da; }
126 else if (strcasecmp(out_field_name,
"Qcrit_nodal") == 0) { out_vec_global = user->
Qcrit_nodal; dm_out = user->
da; }
127 else if (strcasecmp(out_field_name,
"PostScalarNodal") == 0) { out_vec_global = user->
PostScalarNodal; dm_out = user->
da; }
128 else if (strcasecmp(out_field_name,
"PostVectorNodal") == 0) { out_vec_global = user->
PostVectorNodal; dm_out = user->
fda; }
130 else SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
"Unknown output field name for nodal averaging: %s", out_field_name);
142 ierr = DMDAGetLocalInfo(dm_out, &info); CHKERRQ(ierr);
145 const PetscInt i_end = PetscMin(info.xs + info.xm, info.mx - 1);
146 const PetscInt j_end = PetscMin(info.ys + info.ym, info.my - 1);
147 const PetscInt k_end = PetscMin(info.zs + info.zm, info.mz - 1);
150 const PetscReal ***l_in_arr;
151 PetscReal ***g_out_arr;
152 ierr = DMDAVecGetArrayRead(dm_in,in_vec_local, (
void*)&l_in_arr); CHKERRQ(ierr);
153 ierr = DMDAVecGetArray(dm_out,out_vec_global, (
void*)&g_out_arr); CHKERRQ(ierr);
157 for (PetscInt k = info.zs; k < k_end; k++) {
158 for (PetscInt j = info.ys; j < j_end; j++) {
159 for (PetscInt i = info.xs; i < i_end; i++) {
160 g_out_arr[k][j][i] = 0.125 * (l_in_arr[k][j][i] + l_in_arr[k][j][i+1] +
161 l_in_arr[k][j+1][i] + l_in_arr[k][j+1][i+1] +
162 l_in_arr[k+1][j][i] + l_in_arr[k+1][j][i+1] +
163 l_in_arr[k+1][j+1][i] + l_in_arr[k+1][j+1][i+1]);
167 ierr = DMDAVecRestoreArrayRead(dm_in,in_vec_local, (
void*)&l_in_arr); CHKERRQ(ierr);
168 ierr = DMDAVecRestoreArray(dm_out,out_vec_global, (
void*)&g_out_arr); CHKERRQ(ierr);
170 }
else if (dof == 3) {
173 ierr = DMDAVecGetArrayRead(dm_in,in_vec_local, (
void*)&l_in_arr); CHKERRQ(ierr);
174 ierr = DMDAVecGetArray(dm_out,out_vec_global, (
void*)&g_out_arr); CHKERRQ(ierr);
176 for (PetscInt k = info.zs; k < k_end; k++) {
177 for (PetscInt j = info.ys; j < j_end; j++) {
178 for (PetscInt i = info.xs; i < i_end; i++) {
179 g_out_arr[k][j][i].
x = 0.125 * (l_in_arr[k][j][i].
x + l_in_arr[k][j][i+1].
x +
180 l_in_arr[k][j+1][i].
x + l_in_arr[k][j+1][i+1].
x +
181 l_in_arr[k+1][j][i].
x + l_in_arr[k+1][j][i+1].
x +
182 l_in_arr[k+1][j+1][i].
x + l_in_arr[k+1][j+1][i+1].
x);
184 g_out_arr[k][j][i].
y = 0.125 * (l_in_arr[k][j][i].
y + l_in_arr[k][j][i+1].
y +
185 l_in_arr[k][j+1][i].
y + l_in_arr[k][j+1][i+1].
y +
186 l_in_arr[k+1][j][i].
y + l_in_arr[k+1][j][i+1].
y +
187 l_in_arr[k+1][j+1][i].
y + l_in_arr[k+1][j+1][i+1].
y);
189 g_out_arr[k][j][i].
z = 0.125 * (l_in_arr[k][j][i].
z + l_in_arr[k][j][i+1].
z +
190 l_in_arr[k][j+1][i].
z + l_in_arr[k][j+1][i+1].
z +
191 l_in_arr[k+1][j][i].
z + l_in_arr[k+1][j][i+1].
z +
192 l_in_arr[k+1][j+1][i].
z + l_in_arr[k+1][j+1][i+1].
z);
196 ierr = DMDAVecRestoreArrayRead(dm_in,in_vec_local, (
void*)&l_in_arr); CHKERRQ(ierr);
197 ierr = DMDAVecRestoreArray(dm_out,out_vec_global, (
void*)&g_out_arr); CHKERRQ(ierr);
200 PetscFunctionReturn(0);
205#define __FUNCT__ "ComputeWindowStatisticNodal"
213 const char *outputs, PetscInt output_index,
214 char *out_name,
size_t name_size,
215 Vec *out_vec, PetscInt *out_components)
222 PetscFunctionBeginUser;
224 PetscCheck(user != NULL && out_name != NULL && out_vec != NULL && out_components != NULL,
225 PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
"Context and outputs are required.");
228 PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE,
229 "No accumulated window state exists to derive.");
237 &derived); CHKERRQ(ierr);
256 ierr = PetscStrncpy(out_name, derived.
name, name_size); CHKERRQ(ierr);
261 PetscFunctionReturn(0);
265#define __FUNCT__ "ComputeWindowStatisticsSummary"
273 const char *output_prefix, PetscInt ti)
279 PetscReal lowest = 1.0, highest = 0.0;
280 PetscReal mean_tke = 0.0;
281 PetscBool has_tke = PETSC_FALSE;
282 PetscInt derived_count = 0;
283 char path[PETSC_MAX_PATH_LEN];
285 PetscFunctionBeginUser;
287 PetscCheck(user != NULL && output_prefix != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
288 "Context and output prefix are required.");
291 PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE,
292 "No accumulated window state exists to summarize.");
297 window->
sample_count, &lowest, &highest); CHKERRQ(ierr);
303 if (derived_count > 0) {
313 has_tke = PETSC_TRUE;
319 PetscReal time_scale = 1.0;
325 const PetscReal weight_scale =
328 if (simCtx->
rank == 0) {
330 PetscBool exists = PETSC_FALSE;
332 ierr = PetscSNPrintf(path,
sizeof(path),
"%s_statistics_%s.csv",
334 ierr = PetscTestFile(path,
'r', &exists); CHKERRQ(ierr);
335 csv = fopen(path, exists ?
"a" :
"w");
336 PetscCheck(csv != NULL, PETSC_COMM_SELF, PETSC_ERR_FILE_OPEN,
337 "Unable to open statistics summary '%s'.", path);
339 fprintf(csv,
"step,state,samples,total_weight,represented_time,"
340 "valid_fraction_min,valid_fraction_max,mean_tke\n");
342 fprintf(csv,
"%" PetscInt_FMT
",%s,%d,%.10e,%.10e,%.6f,%.6f,",
346 (
double)lowest, (
double)highest);
347 if (has_tke) fprintf(csv,
"%.10e\n", (
double)mean_tke);
348 else fprintf(csv,
"\n");
349 PetscCheck(fclose(csv) == 0, PETSC_COMM_SELF, PETSC_ERR_FILE_WRITE,
350 "Unable to close statistics summary '%s'.", path);
355 PetscFunctionReturn(0);
359#define __FUNCT__ "ComputeQCriterion"
370 const Cmpnts ***lucat, ***lcsi, ***leta, ***lzet;
371 const PetscReal***laj, ***lnvert;
374 PetscFunctionBeginUser;
387 ierr = DMDAGetLocalInfo(user->
da, &info); CHKERRQ(ierr);
389 ierr = DMDAVecGetArrayRead(user->
fda, user->
lUcat, (
void*)&lucat); CHKERRQ(ierr);
390 ierr = DMDAVecGetArrayRead(user->
fda, user->
lCsi, (
void*)&lcsi); CHKERRQ(ierr);
391 ierr = DMDAVecGetArrayRead(user->
fda, user->
lEta, (
void*)&leta); CHKERRQ(ierr);
392 ierr = DMDAVecGetArrayRead(user->
fda, user->
lZet, (
void*)&lzet); CHKERRQ(ierr);
393 ierr = DMDAVecGetArrayRead(user->
da, user->
lAj, (
void*)&laj); CHKERRQ(ierr);
394 ierr = DMDAVecGetArrayRead(user->
da, user->
lNvert, (
void*)&lnvert); CHKERRQ(ierr);
395 ierr = DMDAVecGetArray(user->
da, user->
Qcrit, (
void*)&gq); CHKERRQ(ierr);
398 PetscInt i_start = (info.xs == 0) ? 1 : info.xs;
399 PetscInt i_end = (info.xs + info.xm == info.mx) ? info.mx - 1 : info.xs + info.xm;
400 PetscInt j_start = (info.ys == 0) ? 1 : info.ys;
401 PetscInt j_end = (info.ys + info.ym == info.my) ? info.my - 1 : info.ys + info.ym;
402 PetscInt k_start = (info.zs == 0) ? 1 : info.zs;
403 PetscInt k_end = (info.zs + info.zm == info.mz) ? info.mz - 1 : info.zs + info.zm;
406 for (PetscInt k = k_start; k < k_end; k++) {
407 for (PetscInt j = j_start; j < j_end; j++) {
408 for (PetscInt i = i_start; i < i_end; i++) {
411 PetscReal uc = 0.5 * (lucat[k][j][i+1].
x - lucat[k][j][i-1].
x);
412 PetscReal vc = 0.5 * (lucat[k][j][i+1].
y - lucat[k][j][i-1].
y);
413 PetscReal wc = 0.5 * (lucat[k][j][i+1].
z - lucat[k][j][i-1].
z);
415 PetscReal ue = 0.5 * (lucat[k][j+1][i].
x - lucat[k][j-1][i].
x);
416 PetscReal ve = 0.5 * (lucat[k][j+1][i].
y - lucat[k][j-1][i].
y);
417 PetscReal we = 0.5 * (lucat[k][j+1][i].
z - lucat[k][j-1][i].
z);
419 PetscReal uz = 0.5 * (lucat[k+1][j][i].
x - lucat[k-1][j][i].
x);
420 PetscReal vz = 0.5 * (lucat[k+1][j][i].
y - lucat[k-1][j][i].
y);
421 PetscReal wz = 0.5 * (lucat[k+1][j][i].
z - lucat[k-1][j][i].
z);
424 PetscReal csi1 = 0.5 * (lcsi[k][j][i].
x + lcsi[k][j][i-1].
x) * laj[k][j][i];
425 PetscReal csi2 = 0.5 * (lcsi[k][j][i].
y + lcsi[k][j][i-1].
y) * laj[k][j][i];
426 PetscReal csi3 = 0.5 * (lcsi[k][j][i].
z + lcsi[k][j][i-1].
z) * laj[k][j][i];
428 PetscReal eta1 = 0.5 * (leta[k][j][i].
x + leta[k][j-1][i].
x) * laj[k][j][i];
429 PetscReal eta2 = 0.5 * (leta[k][j][i].
y + leta[k][j-1][i].
y) * laj[k][j][i];
430 PetscReal eta3 = 0.5 * (leta[k][j][i].
z + leta[k][j-1][i].
z) * laj[k][j][i];
432 PetscReal zet1 = 0.5 * (lzet[k][j][i].
x + lzet[k-1][j][i].
x) * laj[k][j][i];
433 PetscReal zet2 = 0.5 * (lzet[k][j][i].
y + lzet[k-1][j][i].
y) * laj[k][j][i];
434 PetscReal zet3 = 0.5 * (lzet[k][j][i].
z + lzet[k-1][j][i].
z) * laj[k][j][i];
437 PetscReal d11 = uc * csi1 + ue * eta1 + uz * zet1;
438 PetscReal d12 = uc * csi2 + ue * eta2 + uz * zet2;
439 PetscReal d13 = uc * csi3 + ue * eta3 + uz * zet3;
441 PetscReal d21 = vc * csi1 + ve * eta1 + vz * zet1;
442 PetscReal d22 = vc * csi2 + ve * eta2 + vz * zet2;
443 PetscReal d23 = vc * csi3 + ve * eta3 + vz * zet3;
445 PetscReal d31 = wc * csi1 + we * eta1 + wz * zet1;
446 PetscReal d32 = wc * csi2 + we * eta2 + wz * zet2;
447 PetscReal d33 = wc * csi3 + we * eta3 + wz * zet3;
451 PetscReal s12 = 0.5 * (d12 + d21);
452 PetscReal s13 = 0.5 * (d13 + d31);
454 PetscReal s23 = 0.5 * (d23 + d32);
458 PetscReal w12 = 0.5 * (d12 - d21);
459 PetscReal w13 = 0.5 * (d13 - d31);
460 PetscReal w23 = 0.5 * (d23 - d32);
463 PetscReal s_norm_sq = s11*s11 + s22*s22 + s33*s33 + 2.0*(s12*s12 + s13*s13 + s23*s23);
464 PetscReal w_norm_sq = 2.0 * (w12*w12 + w13*w13 + w23*w23);
466 gq[k][j][i] = 0.5 * (w_norm_sq - s_norm_sq);
468 if (lnvert[k][j][i] > 0.1) {
476 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lUcat, (
void*)&lucat); CHKERRQ(ierr);
477 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lCsi, (
void*)&lcsi); CHKERRQ(ierr);
478 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lEta, (
void*)&leta); CHKERRQ(ierr);
479 ierr = DMDAVecRestoreArrayRead(user->
fda, user->
lZet, (
void*)&lzet); CHKERRQ(ierr);
480 ierr = DMDAVecRestoreArrayRead(user->
da, user->
lAj, (
void*)&laj); CHKERRQ(ierr);
481 ierr = DMDAVecRestoreArrayRead(user->
da, user->
lNvert, (
void*)&lnvert); CHKERRQ(ierr);
482 ierr = DMDAVecRestoreArray(user->
da, user->
Qcrit, (
void*)&gq); CHKERRQ(ierr);
488 PetscReal length_scale = 1.0;
490 length_scale > 0.0) {
491 ierr = VecScale(user->
Qcrit, 1.0 / (length_scale * length_scale)); CHKERRQ(ierr);
504 PetscFunctionReturn(0);
508#define __FUNCT__ "NormalizeRelativeField"
520 PetscInt ip=1, jp=1, kp=1;
521 PetscReal p_ref = 0.0;
522 PetscReal p_ref_local = 0.0;
523 PetscInt found_local = 0, found_global = 0;
531 PetscFunctionBeginUser;
536 if (strcasecmp(relative_field_name,
"P") == 0) {
539 SETERRQ(PETSC_COMM_SELF, 1,
"NormalizeRelativeField only supports the primary 'P' field , not '%s' currently.", relative_field_name);
543 ierr = DMDAGetLocalInfo(user->
da, &info); CHKERRQ(ierr);
544 PetscCheck(ip >= 0 && ip < info.mx && jp >= 0 && jp < info.my &&
545 kp >= 0 && kp < info.mz,
546 PETSC_COMM_WORLD, PETSC_ERR_ARG_OUTOFRANGE,
547 "Reference point (%" PetscInt_FMT
", %" PetscInt_FMT
", %" PetscInt_FMT
548 ") lies outside the %" PetscInt_FMT
"x%" PetscInt_FMT
"x%" PetscInt_FMT
549 " pressure layout.", ip, jp, kp, info.mx, info.my, info.mz);
550 if (ip >= info.xs && ip < info.xs + info.xm &&
551 jp >= info.ys && jp < info.ys + info.ym &&
552 kp >= info.zs && kp < info.zs + info.zm) {
553 const PetscReal ***pressure = NULL;
555 ierr = DMDAVecGetArrayRead(user->
da, P_vec, &pressure); CHKERRQ(ierr);
556 p_ref_local = pressure[kp][jp][ip];
557 ierr = DMDAVecRestoreArrayRead(user->
da, P_vec, &pressure); CHKERRQ(ierr);
560 ierr = MPI_Allreduce(&p_ref_local, &p_ref, 1, MPIU_REAL, MPI_SUM,
561 PETSC_COMM_WORLD); CHKERRQ(ierr);
562 ierr = MPI_Allreduce(&found_local, &found_global, 1, MPIU_INT, MPI_SUM,
563 PETSC_COMM_WORLD); CHKERRQ(ierr);
564 PetscCheck(found_global == 1, PETSC_COMM_WORLD, PETSC_ERR_PLIB,
565 "Reference pressure point must have exactly one owner; found %" PetscInt_FMT
".",
568 "%s reference point (%" PetscInt_FMT
", %" PetscInt_FMT
", %" PetscInt_FMT
569 ") has value %g.\n", relative_field_name, ip, jp, kp, (
double)p_ref);
572 ierr = VecShift(P_vec, -p_ref); CHKERRQ(ierr);
576 PetscFunctionReturn(0);
583#define __FUNCT__ "ComputeSpecificKE"
592 const PetscScalar (*vel_arr)[3];
593 PetscScalar *ske_arr;
595 PetscFunctionBeginUser;
597 LOG_ALLOW(
GLOBAL,
LOG_INFO,
"-> KERNEL: Running ComputeSpecificKE ('%s' -> '%s').\n", velocity_field, ske_field);
600 ierr = DMSwarmGetLocalSize(user->
swarm, &n_local); CHKERRQ(ierr);
604 ierr = DMSwarmGetField(user->
swarm, velocity_field, NULL, NULL, (
void**)&vel_arr); CHKERRQ(ierr);
605 ierr = DMSwarmGetField(user->
post_swarm, ske_field, NULL, NULL, (
void**)&ske_arr); CHKERRQ(ierr);
608 for (PetscInt p = 0; p < n_local; p++) {
609 const PetscScalar u = vel_arr[p][0];
610 const PetscScalar v = vel_arr[p][1];
611 const PetscScalar w = vel_arr[p][2];
612 const PetscScalar vel_sq = u*u + v*v + w*w;
613 ske_arr[p] = 0.5 * vel_sq;
617 ierr = DMSwarmRestoreField(user->
swarm, velocity_field, NULL, NULL, (
void**)&vel_arr); CHKERRQ(ierr);
618 ierr = DMSwarmRestoreField(user->
post_swarm, ske_field, NULL, NULL, (
void**)&ske_arr); CHKERRQ(ierr);
621 PetscFunctionReturn(0);
625#define __FUNCT__ "ComputeDisplacement"
634 const PetscReal (*pos_arr)[3];
635 PetscScalar *disp_out;
638 PetscFunctionBeginUser;
642 ierr = DMSwarmGetLocalSize(user->
swarm, &n_local); CHKERRQ(ierr);
645 const PetscReal x0 = simCtx->
psrc_x;
646 const PetscReal y0 = simCtx->
psrc_y;
647 const PetscReal z0 = simCtx->
psrc_z;
650 ierr = DMSwarmGetField(user->
post_swarm, disp_field, NULL, NULL, (
void**)&disp_out); CHKERRQ(ierr);
652 for (PetscInt p = 0; p < n_local; p++) {
653 const PetscReal dx = pos_arr[p][0] - x0;
654 const PetscReal dy = pos_arr[p][1] - y0;
655 const PetscReal dz = pos_arr[p][2] - z0;
656 disp_out[p] = PetscSqrtReal(dx*dx + dy*dy + dz*dz);
660 ierr = DMSwarmRestoreField(user->
post_swarm, disp_field, NULL, NULL, (
void**)&disp_out); CHKERRQ(ierr);
663 PetscFunctionReturn(0);
PetscErrorCode SynchronizePeriodicCellFields(UserCtx *user, PetscInt num_fields, const FieldId field_ids[])
Synchronizes periodic endpoint cells for a list of cell-centered fields.
PetscErrorCode FieldIdFromName(const char *field_name, FieldId *field_id)
Resolve a user-facing field name once into its typed identity.
PetscErrorCode FieldDimensionReferenceScale(const ScalingCtx *scaling, FieldDimension dimension, PetscReal *scale)
Return the factor that turns a solver value of one dimension into physical units.
PetscErrorCode FieldGetView(UserCtx *user, FieldId field_id, FieldView *view)
Resolve the existing DM and global/local vectors for one field.
PetscErrorCode FieldTryIdFromName(const char *field_name, FieldId *field_id, PetscBool *found)
Look a name up without treating an unknown name as an error.
FieldId
Compile-time identity for a catalogued Eulerian field.
Physical dimension as exponents of the reference length, velocity, and density.
Non-owning runtime objects resolved for one field and UserCtx.
PetscErrorCode PicurvFieldReferenceScale(SimCtx *simCtx, const char *field_name, PetscReal *scale, char *description, size_t description_length)
Physical scale one field is multiplied by to leave non-dimensional form.
PetscBool is_function_allowed(const char *functionName)
Checks if a given function is in the allow-list.
#define GLOBAL
Scope for global logging across all processes.
#define LOG_ALLOW(scope, level, fmt,...)
Logging macro that checks both the log level and whether the calling function is in the allowed-funct...
#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 get_log_level()
Retrieves the current logging level from the environment variable LOG_LEVEL.
PetscErrorCode LOG_FIELD_ANATOMY(UserCtx *user, FieldId field_id, const char *stage_name)
Logs the anatomy of a specified field at key boundary locations, respecting the solver's specific gri...
@ LOG_INFO
Informational messages about program execution.
@ 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 code block (typically a function).
Typed identities and metadata for persistent solver-particle fields.
const char * ParticleFieldName(ParticleFieldId field_id)
Return the canonical PETSc DMSwarm name for an ID.
ParticleFieldId
Compile-time identity for a persistent solver-particle field.
@ PARTICLE_FIELD_ID_POSITION
@ PARTICLE_FIELD_ID_INVALID
PetscErrorCode ParticleFieldGetDescriptor(ParticleFieldId field_id, const ParticleFieldDescriptor **descriptor)
Return immutable metadata for a valid particle field ID.
const char * canonical_name
PetscErrorCode ParticleFieldTryIdFromName(const char *field_name, ParticleFieldId *field_id, PetscBool *found)
Look a name up without treating an unknown name as an error.
Immutable metadata for one persistent particle field.
PetscErrorCode ComputeQCriterion(UserCtx *user)
Implementation of ComputeQCriterion().
PetscErrorCode ComputeSpecificKE(UserCtx *user, const char *velocity_field, const char *ske_field)
Internal helper implementation: ComputeSpecificKE().
PetscErrorCode ComputeDisplacement(UserCtx *user, const char *disp_field)
Internal helper implementation: ComputeDisplacement().
PetscErrorCode NormalizeRelativeField(UserCtx *user, const char *relative_field_name)
Implementation of NormalizeRelativeField().
PetscErrorCode ComputeWindowStatisticsSummary(UserCtx *user, PetscInt window_index, const char *output_prefix, PetscInt ti)
Implementation of ComputeWindowStatisticsSummary().
PetscErrorCode DimensionalizeField(UserCtx *user, const char *field_name)
Implementation of DimensionalizeField().
PetscErrorCode ComputeNodalAverage(UserCtx *user, const char *in_field_name, const char *out_field_name)
Implementation of ComputeNodalAverage().
PetscErrorCode ComputeWindowStatisticNodal(UserCtx *user, PetscInt window_index, const char *outputs, PetscInt output_index, char *out_name, size_t name_size, Vec *out_vec, PetscInt *out_components)
Implementation of ComputeWindowStatisticNodal().
PetscErrorCode UpdateLocalGhosts(UserCtx *user, FieldId field_id)
Updates the local vector (including ghost points) from its corresponding global vector.
Per-window PETSc accumulator storage and pointwise application.
PetscInt components
One or three.
char name[96]
Output field name, window qualified.
PetscErrorCode PicurvWindowDerive(UserCtx *user, const PicurvWindowDefinition *definition, const PicurvWindowStorage *storage, const char *outputs, PetscInt index, Vec scalar_target, Vec vector_target, PicurvDerivedField *field)
Derives one output field from centered accumulator state.
PetscErrorCode PicurvWindowDerivedCount(const PicurvWindowDefinition *definition, const PicurvWindowStorage *storage, const char *outputs, PetscInt *count)
Reports how many derived fields a requested output set produces.
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.
PetscErrorCode PicurvWindowSpatialMean(UserCtx *user, const PicurvWindowDefinition *definition, const PicurvWindowStorage *storage, Vec field, PetscReal *mean)
Reports the spatial mean of a derived field over the points a window sampled.
One derived output field, resolved by enumeration index.
Independent accumulator state for one window on one block.
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.
PicurvWindowDefinition definition
PetscBool FieldStatisticsIsActive(const struct SimCtx *simCtx)
Reports whether this run has live field-statistics state.
@ PICURV_WEIGHTING_PHYSICAL_TIME
Weight is the represented interval.
PetscReal represented_time
Physical time the window covers.
PicurvWeighting weighting
Runtime state of one window.
The scientifically immutable definition of one window.
Vec Qcrit_nodal
Q-criterion averaged to grid nodes; the field a .vts can place correctly.
SimCtx * simCtx
Back-pointer to the master simulation context.
PetscBool dimensionalize
Whether derived output leaves non-dimensional form, from global_operations.dimensionalize.
PetscReal psrc_z
Point source location for PARTICLE_INIT_POINT_SOURCE.
struct PicurvWindow * fieldStatisticsWindows
struct PicurvWindowStorage * fieldStatisticsStorage
Vec lQcrit
Cell-centred Q-criterion and its ghosted copy for nodal averaging.
A 3D point or vector with PetscScalar components.
Holds all configuration parameters for a post-processing run.
The master context for the entire simulation.
User-defined context containing data specific to a single computational grid level.