44 PetscFunctionBeginUser;
49 PetscFunctionReturn(0);
67 PetscFunctionBeginUser;
71 PetscFunctionReturn(0);
93 const DMDALocalInfo info = user->
info;
96 const PetscInt extent[3] = {info.mx, info.my, info.mz};
97 PetscReal ***mask = NULL;
100 PetscFunctionBeginUser;
102 PetscCall(VecSet(inclusion, 1.0));
104 PetscCall(DMDAVecGetArray(user->
da, inclusion, &mask));
105 for (PetscInt k = plan.
start[2]; k < plan.
end[2]; k++)
106 for (PetscInt j = plan.
start[1]; j < plan.
end[1]; j++)
107 for (PetscInt i = plan.
start[0]; i < plan.
end[0]; i++) {
108 const PetscInt coord[3] = {i, j, k};
110 for (PetscInt axis = 0; axis < 3; axis++) {
115 coord[axis] == extent[axis] - 2)) {
121 PetscCall(DMDAVecRestoreArray(user->
da, inclusion, &mask));
123 PetscFunctionReturn(0);
155 t.
xx = a * x.
xx + b * y.
xx;
156 t.
xy = a * x.
xy + b * y.
xy;
157 t.
xz = a * x.
xz + b * y.
xz;
158 t.
yy = a * x.
yy + b * y.
yy;
159 t.
yz = a * x.
yz + b * y.
yz;
160 t.
zz = a * x.
zz + b * y.
zz;
172 return t.
xx + t.
yy + t.
zz;
230 PetscFunctionBeginUser;
233 s.
xy = 0.5 * (dudx.
y + dvdx.
x);
234 s.
xz = 0.5 * (dudx.
z + dwdx.
x);
236 s.
yz = 0.5 * (dvdx.
z + dwdx.
y);
239 if (strain) *strain = s;
243 PetscFunctionReturn(0);
255 double dx = 0.0, dy = 0.0, dz = 0.0;
257 PetscFunctionBeginUser;
258 PetscCheck(delta != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
259 "Filter width destination cannot be NULL.");
260 PetscCheck(aj > 0.0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE,
261 "Cell Jacobian must be positive to define a filter width; received %g.", (
double)aj);
266 *delta = PetscPowReal(1.0 / aj, 1.0 / 3.0);
267 PetscFunctionReturn(0);
278 *delta = PetscMax(dx, PetscMax(dy, dz));
285 const double longest = PetscMax(dx, PetscMax(dy, dz));
286 const double shortest = PetscMin(dx, PetscMin(dy, dz));
287 const double middle = dx + dy + dz - longest - shortest;
288 const double ln_a1 = log(shortest / longest), ln_a2 = log(middle / longest);
289 const double shape = cosh(sqrt((4.0 / 27.0) *
290 (ln_a1 * ln_a1 - ln_a1 * ln_a2 + ln_a2 * ln_a2)));
291 *delta = PetscPowReal(PetscMax(dx * dy * dz,
LES_EPSILON), 1.0 / 3.0) * shape;
296 *delta = PetscPowReal(PetscMax(dx * dy * dz,
LES_EPSILON), 1.0 / 3.0);
300 PetscFunctionReturn(0);
327 PetscReal strain_magnitude_filtered,
334 strain_filtered, 0.0, strain_filtered);
340 const SymTensor grid_scale = strain_product_filtered;
343 2.0 * delta * delta, grid_scale);
363 PetscInt selected = 0;
364 PetscBool periodic[3];
366 PetscFunctionBeginUser;
368 PetscCheck(direction != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_NULL,
369 "Averaging direction destination cannot be NULL.");
372 for (PetscInt axis = 0; axis < 3; axis++) direction[axis] = PETSC_FALSE;
378 PetscFunctionReturn(0);
381 for (PetscInt axis = 0; axis < 3; axis++) direction[axis] = PETSC_TRUE;
383 PetscFunctionReturn(0);
387 for (PetscInt axis = 0; axis < 3; axis++) {
389 direction[axis] = PETSC_TRUE;
396 for (PetscInt axis = 0; axis < 3; axis++) {
397 if (periodic[axis]) {
398 direction[axis] = PETSC_TRUE;
403 PetscCheck(selected > 0, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE,
404 "Homogeneous LES averaging was requested, but this block declares no "
405 "periodic axis and the configuration names no direction. Name the "
406 "homogeneous directions explicitly or select local averaging.");
408 PetscFunctionReturn(0);
421 PetscReal result = coefficient;
429 if (result < 0.0) result = 0.0;
433 if (result < 0.0) result = 0.0;
438 if (limited) *limited = (PetscBool)(result != coefficient);
449 PetscReal strain_magnitude,
450 PetscReal molecular_viscosity,
451 PetscReal min_viscosity_ratio)
453 PetscReal
nu_t = coefficient * delta * delta * strain_magnitude;
457 const PetscReal floor = (min_viscosity_ratio - 1.0) * molecular_viscosity;
470 PetscReal delta, PetscReal coefficient)
473 const PetscReal g[3][3] = {{dudx.
x, dudx.
y, dudx.
z},
474 {dvdx.
x, dvdx.
y, dvdx.
z},
475 {dwdx.
x, dwdx.
y, dwdx.
z}};
476 PetscReal g2[3][3], sd[3][3], trace = 0.0, ss = 0.0, sdsd = 0.0, denominator;
478 for (PetscInt a = 0; a < 3; ++a)
479 for (PetscInt b = 0; b < 3; ++b) {
481 for (PetscInt c = 0; c < 3; ++c) g2[a][b] += g[a][c] * g[c][b];
483 for (PetscInt a = 0; a < 3; ++a) trace += g2[a][a];
484 for (PetscInt a = 0; a < 3; ++a)
485 for (PetscInt b = 0; b < 3; ++b) {
486 const PetscReal s = 0.5 * (g[a][b] + g[b][a]);
489 sd[a][b] = 0.5 * (g2[a][b] + g2[b][a]) - (a == b ? trace / 3.0 : 0.0);
491 sdsd += sd[a][b] * sd[a][b];
494 denominator = PetscPowReal(ss, 2.5) + PetscPowReal(sdsd, 1.25);
497 return coefficient * coefficient * delta * delta * PetscPowReal(sdsd, 1.5) / denominator;
507 const Cmpnts edges[3], PetscReal coefficient)
510 const Cmpnts gradient[3] = {dudx, dvdx, dwdx};
511 PetscReal beta[3][3] = {{0.0}}, alpha_sq = 0.0, b_beta;
518 for (PetscInt m = 0; m < 3; ++m) {
520 for (PetscInt a = 0; a < 3; ++a)
521 change[a] = edges[m].x * gradient[a].x + edges[m].y * gradient[a].y + edges[m].z * gradient[a].z;
522 for (PetscInt a = 0; a < 3; ++a)
523 for (PetscInt b = 0; b < 3; ++b) beta[a][b] += change[a] * change[b];
525 for (PetscInt a = 0; a < 3; ++a)
526 alpha_sq += gradient[a].x * gradient[a].x + gradient[a].y * gradient[a].y + gradient[a].z * gradient[a].z;
528 b_beta = beta[0][0] * beta[1][1] - beta[0][1] * beta[0][1]
529 + beta[0][0] * beta[2][2] - beta[0][2] * beta[0][2]
530 + beta[1][1] * beta[2][2] - beta[1][2] * beta[1][2];
535 return coefficient * PetscSqrtReal(b_beta / alpha_sq);
546 return 2.0 * yoshizawa_ci * delta * delta * strain_magnitude * strain_magnitude;
575 if (index == 0)
return periodic ? -2 : 1;
576 if (index == extent - 1)
return periodic ? extent + 1 : extent - 2;
584 Vec strain_diagonal, Vec strain_offdiagonal,
585 Vec strain_magnitude)
587 DM da = user->
da, fda = user->
fda;
590 PetscBool periodic[3];
591 Cmpnts ***diagonal = NULL, ***offdiagonal = NULL;
592 PetscReal ***magnitude = NULL;
594 PetscFunctionBeginUser;
601 PetscCall(DMDAVecGetArray(fda, strain_diagonal, &diagonal));
602 PetscCall(DMDAVecGetArray(fda, strain_offdiagonal, &offdiagonal));
603 PetscCall(DMDAVecGetArray(da, strain_magnitude, &magnitude));
607 for (PetscInt k = plan.
start[2] - 1; k <= plan.
end[2]; k++)
608 for (PetscInt j = plan.
start[1] - 1; j <= plan.
end[1]; j++)
609 for (PetscInt i = plan.
start[0] - 1; i <= plan.
end[0]; i++) {
616 PetscReal strain_abs;
621 diagonal[k][j][i].
x = strain.
xx;
622 diagonal[k][j][i].
y = strain.
yy;
623 diagonal[k][j][i].
z = strain.
zz;
624 offdiagonal[k][j][i].x = strain.
xy;
625 offdiagonal[k][j][i].y = strain.
xz;
626 offdiagonal[k][j][i].z = strain.
yz;
627 magnitude[k][j][i] = strain_abs;
630 PetscCall(DMDAVecRestoreArray(fda, strain_diagonal, &diagonal));
631 PetscCall(DMDAVecRestoreArray(fda, strain_offdiagonal, &offdiagonal));
632 PetscCall(DMDAVecRestoreArray(da, strain_magnitude, &magnitude));
635 PetscFunctionReturn(0);
648 s.
xy = offdiagonal.
x;
649 s.
xz = offdiagonal.
y;
650 s.
yz = offdiagonal.
z;
668 DM da = user->
da, fda = user->
fda;
670 PetscBool average_direction[3];
673 Vec lStrainDiag, lStrainOff, lStrainAbs, lLM, lMM, lCsq;
674 Vec lWallMask = NULL;
676 Cmpnts ***ucat = NULL, ***strain_diag = NULL, ***strain_off = NULL;
677 Cmpnts ***csi = NULL, ***eta = NULL, ***zet = NULL;
678 PetscReal ***strain_abs = NULL, ***nvert = NULL, ***aj = NULL;
679 PetscReal ***lm = NULL, ***mm = NULL, ***csq = NULL, ***cs_out = NULL;
683 PetscFunctionBeginUser;
687 "The dynamic procedure runs only for the dynamic Smagorinsky model. The "
688 "constant model prescribes its coefficient from configuration and holds "
689 "no coefficient field.");
694 PetscCall(VecSet(user->
CS, 0.0));
698 "Holding the dynamic coefficient at zero for the opening steps (step=%" PetscInt_FMT
").\n",
701 PetscFunctionReturn(0);
720 PetscCall(VecDuplicate(user->
lUcat, &lStrainDiag));
721 PetscCall(VecDuplicate(user->
lUcat, &lStrainOff));
722 PetscCall(VecDuplicate(user->
lNvert, &lStrainAbs));
723 PetscCall(VecDuplicate(user->
lNvert, &lLM));
724 PetscCall(VecDuplicate(user->
lNvert, &lMM));
725 PetscCall(VecDuplicate(user->
lNvert, &lCsq));
726 PetscCall(VecSet(lStrainDiag, 0.0));
727 PetscCall(VecSet(lStrainOff, 0.0));
728 PetscCall(VecSet(lStrainAbs, 0.0));
729 PetscCall(VecSet(lLM, 0.0));
730 PetscCall(VecSet(lMM, 0.0));
731 PetscCall(VecSet(lCsq, 0.0));
735 PetscCall(VecDuplicate(user->
lNvert, &lWallMask));
739 PetscCall(DMDAVecGetArray(fda, user->
lUcat, &ucat));
744 PetscCall(DMDAVecGetArrayRead(fda, lStrainDiag, &strain_diag));
745 PetscCall(DMDAVecGetArrayRead(fda, lStrainOff, &strain_off));
746 PetscCall(DMDAVecGetArrayRead(da, lStrainAbs, &strain_abs));
747 PetscCall(DMDAVecGetArrayRead(fda, user->
lCsi, &csi));
748 PetscCall(DMDAVecGetArrayRead(fda, user->
lEta, &eta));
749 PetscCall(DMDAVecGetArrayRead(fda, user->
lZet, &zet));
750 PetscCall(DMDAVecGetArrayRead(da, user->
lNvert, &nvert));
751 PetscCall(DMDAVecGetArrayRead(da, user->
lAj, &aj));
752 PetscCall(DMDAVecGetArray(da, lLM, &lm));
753 PetscCall(DMDAVecGetArray(da, lMM, &mm));
756 for (PetscInt k = plan.
start[2]; k < plan.
end[2]; k++)
757 for (PetscInt j = plan.
start[1]; j < plan.
end[1]; j++)
758 for (PetscInt i = plan.
start[0]; i < plan.
end[0]; i++) {
759 double velocity_x[3][3][3], velocity_y[3][3][3], velocity_z[3][3][3];
760 double strain_abs_stencil[3][3][3], weights[3][3][3];
761 SymTensor strain_stencil[3][3][3], product_stencil[3][3][3], velocity_product[3][3][3];
763 SymTensor strain_filtered, product_filtered, velocity_product_filtered;
765 PetscReal strain_abs_filtered, delta, volume;
774 for (PetscInt r = -1; r <= 1; r++)
775 for (PetscInt q = -1; q <= 1; q++)
776 for (PetscInt p = -1; p <= 1; p++) {
777 const PetscInt R = r + 1, Q = q + 1, P = p + 1;
778 const PetscInt KK = k + r, JJ = j + q, II = i + p;
780 const PetscReal strain_abs_here = strain_abs[KK][JJ][II];
782 velocity_x[R][Q][P] = ucat[KK][JJ][II].
x;
783 velocity_y[R][Q][P] = ucat[KK][JJ][II].
y;
784 velocity_z[R][Q][P] = ucat[KK][JJ][II].
z;
786 strain_stencil[R][Q][P] = strain;
787 strain_abs_stencil[R][Q][P] = strain_abs_here;
792 product_stencil[R][Q][P] =
SymTensorCombine(strain_abs_here, strain, 0.0, strain);
795 weights[R][Q][P] = aj[KK][JJ][II];
808 leonard =
LeonardStress(velocity_filtered, velocity_product_filtered);
811 csi[k][j][i], eta[k][j][i], zet[k][j][i], &delta));
813 model =
GermanoModelTensor(delta, alpha, strain_abs_filtered, strain_filtered, product_filtered);
820 volume = 1.0 / aj[k][j][i];
825 PetscCall(DMDAVecRestoreArrayRead(fda, lStrainDiag, &strain_diag));
826 PetscCall(DMDAVecRestoreArrayRead(fda, lStrainOff, &strain_off));
827 PetscCall(DMDAVecRestoreArray(da, lLM, &lm));
828 PetscCall(DMDAVecRestoreArray(da, lMM, &mm));
829 PetscCall(DMDAVecRestoreArray(fda, user->
lUcat, &ucat));
835 PetscObjectComm((PetscObject)da), lCsq, NULL));
838 PetscCall(DMDAVecGetArrayRead(da, lLM, &lm));
839 PetscCall(DMDAVecGetArrayRead(da, lMM, &mm));
840 PetscCall(DMDAVecGetArrayRead(da, lCsq, &csq));
841 PetscCall(DMDAVecGetArray(da, user->
CS, &cs_out));
843 for (PetscInt k = plan.
start[2]; k < plan.
end[2]; k++)
844 for (PetscInt j = plan.
start[1]; j < plan.
end[1]; j++)
845 for (PetscInt i = plan.
start[0]; i < plan.
end[0]; i++) {
846 PetscBool limited = PETSC_FALSE;
847 PetscReal weight, raw;
850 cs_out[k][j][i] = 0.0;
854 weight = 1.0 / aj[k][j][i];
868 PetscCall(DMDAVecRestoreArrayRead(da, lLM, &lm));
869 PetscCall(DMDAVecRestoreArrayRead(da, lMM, &mm));
870 PetscCall(DMDAVecRestoreArrayRead(da, lCsq, &csq));
871 PetscCall(DMDAVecRestoreArray(da, user->
CS, &cs_out));
872 PetscCall(DMDAVecRestoreArrayRead(fda, user->
lCsi, &csi));
873 PetscCall(DMDAVecRestoreArrayRead(fda, user->
lEta, &eta));
874 PetscCall(DMDAVecRestoreArrayRead(fda, user->
lZet, &zet));
875 PetscCall(DMDAVecRestoreArrayRead(da, user->
lNvert, &nvert));
876 PetscCall(DMDAVecRestoreArrayRead(da, user->
lAj, &aj));
878 PetscCall(VecDestroy(&lStrainDiag));
879 PetscCall(VecDestroy(&lStrainOff));
880 PetscCall(VecDestroy(&lStrainAbs));
881 PetscCall(VecDestroy(&lLM));
882 PetscCall(VecDestroy(&lMM));
883 PetscCall(VecDestroy(&lCsq));
884 if (lWallMask) PetscCall(VecDestroy(&lWallMask));
890 PetscFunctionReturn(0);
903 DM da = user->
da, fda = user->
fda;
905 const PetscReal molecular_viscosity = 1.0 / simCtx->
ren;
912 Cmpnts ***ucat = NULL, ***csi = NULL, ***eta = NULL, ***zet = NULL;
913 PetscReal ***coefficient = NULL, ***
nu_t = NULL, ***nvert = NULL, ***aj = NULL;
915 PetscFunctionBeginUser;
920 PetscCall(DMDAVecGetArrayRead(fda, user->
lUcat, &ucat));
921 PetscCall(DMDAVecGetArrayRead(fda, user->
lCsi, &csi));
922 PetscCall(DMDAVecGetArrayRead(fda, user->
lEta, &eta));
923 PetscCall(DMDAVecGetArrayRead(fda, user->
lZet, &zet));
924 PetscCall(DMDAVecGetArray(da, user->
Nu_t, &
nu_t));
925 PetscCall(DMDAVecGetArrayRead(da, user->
lNvert, &nvert));
926 PetscCall(DMDAVecGetArrayRead(da, user->
lAj, &aj));
927 if (coefficient_is_field) PetscCall(DMDAVecGetArrayRead(da, user->
lCs, &coefficient));
929 for (PetscInt k = plan.
start[2]; k < plan.
end[2]; k++)
930 for (PetscInt j = plan.
start[1]; j < plan.
end[1]; j++)
931 for (PetscInt i = plan.
start[0]; i < plan.
end[0]; i++) {
933 PetscReal strain_magnitude, delta, model_coefficient;
951 csi[k][j][i], eta[k][j][i], zet[k][j][i], &delta));
958 model_coefficient = coefficient_is_field ? coefficient[k][j][i] : prescribed_coefficient;
964 if (coefficient_is_field) PetscCall(DMDAVecRestoreArrayRead(da, user->
lCs, &coefficient));
965 PetscCall(DMDAVecRestoreArrayRead(fda, user->
lUcat, &ucat));
966 PetscCall(DMDAVecRestoreArrayRead(fda, user->
lCsi, &csi));
967 PetscCall(DMDAVecRestoreArrayRead(fda, user->
lEta, &eta));
968 PetscCall(DMDAVecRestoreArrayRead(fda, user->
lZet, &zet));
969 PetscCall(DMDAVecRestoreArray(da, user->
Nu_t, &
nu_t));
970 PetscCall(DMDAVecRestoreArrayRead(da, user->
lNvert, &nvert));
971 PetscCall(DMDAVecRestoreArrayRead(da, user->
lAj, &aj));
982 PetscFunctionReturn(0);
995 DM da = user->
da, fda = user->
fda;
1002 const PetscBool has_coefficient =
1008 PetscReal local_sum[7] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
1009 PetscReal global_sum[7];
1010 PetscReal local_max[2] = {0.0, 0.0}, global_max[2];
1011 PetscReal local_min_coefficient = PETSC_MAX_REAL, global_min_coefficient;
1012 PetscReal contraction[2], global_contraction[2];
1014 Cmpnts ***ucat = NULL, ***csi = NULL, ***eta = NULL, ***zet = NULL;
1015 PetscReal ***coefficient = NULL, ***
nu_t = NULL, ***nvert = NULL, ***aj = NULL;
1017 PetscFunctionBeginUser;
1025 PetscCall(PetscObjectGetComm((PetscObject)da, &comm));
1027 PetscCall(DMDAVecGetArrayRead(fda, user->
lUcat, &ucat));
1028 PetscCall(DMDAVecGetArrayRead(fda, user->
lCsi, &csi));
1029 PetscCall(DMDAVecGetArrayRead(fda, user->
lEta, &eta));
1030 PetscCall(DMDAVecGetArrayRead(fda, user->
lZet, &zet));
1031 PetscCall(DMDAVecGetArrayRead(da, user->
lNu_t, &
nu_t));
1032 PetscCall(DMDAVecGetArrayRead(da, user->
lNvert, &nvert));
1033 PetscCall(DMDAVecGetArrayRead(da, user->
lAj, &aj));
1034 if (dynamic) PetscCall(DMDAVecGetArrayRead(da, user->
lCs, &coefficient));
1036 for (PetscInt k = plan.
start[2]; k < plan.
end[2]; k++)
1037 for (PetscInt j = plan.
start[1]; j < plan.
end[1]; j++)
1038 for (PetscInt i = plan.
start[0]; i < plan.
end[0]; i++) {
1040 PetscReal strain_magnitude, delta, weight, value;
1044 weight = 1.0 / aj[k][j][i];
1045 value = dynamic ? coefficient[k][j][i]
1051 csi[k][j][i], eta[k][j][i], zet[k][j][i], &delta));
1053 local_sum[0] += weight;
1054 local_sum[3] += weight *
nu_t[k][j][i];
1056 local_max[1] = PetscMax(local_max[1],
nu_t[k][j][i]);
1057 if (has_coefficient) {
1058 local_sum[1] += weight * value;
1059 local_sum[2] += weight * value * value;
1060 local_max[0] = PetscMax(local_max[0], value);
1061 local_min_coefficient = PetscMin(local_min_coefficient, value);
1065 if (dynamic) PetscCall(DMDAVecRestoreArrayRead(da, user->
lCs, &coefficient));
1066 PetscCall(DMDAVecRestoreArrayRead(fda, user->
lUcat, &ucat));
1067 PetscCall(DMDAVecRestoreArrayRead(fda, user->
lCsi, &csi));
1068 PetscCall(DMDAVecRestoreArrayRead(fda, user->
lEta, &eta));
1069 PetscCall(DMDAVecRestoreArrayRead(fda, user->
lZet, &zet));
1070 PetscCall(DMDAVecRestoreArrayRead(da, user->
lNu_t, &
nu_t));
1071 PetscCall(DMDAVecRestoreArrayRead(da, user->
lNvert, &nvert));
1072 PetscCall(DMDAVecRestoreArrayRead(da, user->
lAj, &aj));
1079 PetscCallMPI(MPI_Allreduce(local_sum, global_sum, 7, MPIU_REAL, MPI_SUM, comm));
1080 PetscCallMPI(MPI_Allreduce(local_max, global_max, 2, MPIU_REAL, MPI_MAX, comm));
1081 PetscCallMPI(MPI_Allreduce(&local_min_coefficient, &global_min_coefficient, 1, MPIU_REAL, MPI_MIN, comm));
1082 PetscCallMPI(MPI_Allreduce(contraction, global_contraction, 2, MPIU_REAL, MPI_SUM, comm));
1084 if (simCtx->
rank == 0) {
1085 const PetscReal volume = (global_sum[0] > 0.0) ? global_sum[0] : 1.0;
1086 const PetscReal mean = global_sum[1] / volume;
1087 const PetscReal mean_square = global_sum[2] / volume;
1088 const PetscReal variance = PetscMax(mean_square - mean * mean, 0.0);
1089 const PetscReal molecular = 1.0 / simCtx->
ren;
1090 const PetscReal effective = (global_contraction[1] >
LES_EPSILON)
1091 ? (global_contraction[0] / global_contraction[1]) : 0.0;
1098 const PetscReal cs_effective = (effective >= 0.0) ? PetscSqrtReal(effective)
1099 : -PetscSqrtReal(-effective);
1100 const PetscReal cs_mean = (mean >= 0.0) ? PetscSqrtReal(mean) : -PetscSqrtReal(-mean);
1103 "step,time,cs_effective,cs_mean,coefficient_mean,"
1104 "coefficient_rms,coefficient_min,coefficient_max,"
1105 "nu_t_mean,nu_t_max,nu_t_over_nu_mean,k_sgs_mean,"
1106 "backscatter_fraction,limited_fraction,physical_time", &file));
1107 PetscReal physical_time = 0.0;
1110 "%d,%.6e,%.6e,%.6e,%.6e,%.6e,%.6e,%.6e,%.6e,%.6e,%.6e,%.6e,%.6e,%.6e,%.6e\n",
1111 (
int)simCtx->
step, (
double)simCtx->
ti,
1114 dynamic ? (
double)cs_effective : (double)NAN,
1115 has_coefficient ? (
double)cs_mean : (double)NAN,
1116 has_coefficient ? (
double)mean : (double)NAN,
1117 has_coefficient ? (
double)PetscSqrtReal(variance) : (double)NAN,
1118 has_coefficient ? (
double)global_min_coefficient : (double)NAN,
1119 has_coefficient ? (
double)global_max[0] : (double)NAN,
1120 (
double)(global_sum[3] / volume), (
double)global_max[1],
1121 (double)(global_sum[3] / volume / molecular),
1122 (double)(global_sum[4] / volume),
1123 (double)(global_sum[5] / volume), (double)(global_sum[6] / volume),
1124 (double)physical_time);
1125 PetscCheck(fclose(file) == 0, PETSC_COMM_SELF, PETSC_ERR_FILE_WRITE,
1126 "Unable to close the LES diagnostics file.");
1129 " LES coefficient: %s=%.4f, nu_t/nu (mean)=%.3e, backscatter=%.1f%%\n",
1130 dynamic ?
"Cs_effective" :
"Cs_mean",
1131 (double)(dynamic ? cs_effective : cs_mean),
1132 (
double)(global_sum[3] / volume / molecular),
1133 (
double)(100.0 * global_sum[5] / volume));
1137 PetscFunctionReturn(0);
PetscBool BoundaryFaceHasWallShear(const BoundaryFaceConfig *face)
Reports whether a boundary face is a wall that exerts shear on the flow.
PetscErrorCode UpdateDummyCells(UserCtx *user, FieldId field_id)
Fills the dummy cells on the non-periodic faces of one cell-centred field.
PetscErrorCode SynchronizePeriodicCellFields(UserCtx *user, PetscInt num_fields, const FieldId field_ids[])
Synchronizes periodic endpoint cells for a list of cell-centered fields.
double ApplyLESTestFilter(LESTestFilterKernel kernel, double values[3][3][3], double weights[3][3][3])
Applies a numerical "test filter" to a 3x3x3 stencil of data points.
PetscErrorCode ApplyLESTestFilterSymTensor(LESTestFilterKernel kernel, SymTensor values[3][3][3], double weights[3][3][3], SymTensor *filtered)
Applies the test filter to all six components of a symmetric tensor.
PetscErrorCode ComputeCellEdgeVectors(PetscReal ajc, Cmpnts csi, Cmpnts eta, Cmpnts zet, Cmpnts edges[3])
Computes a cell's edge vectors along its three grid directions.
PetscErrorCode ComputeCellDirectionalExtents(PetscReal ajc, Cmpnts csi, Cmpnts eta, Cmpnts zet, double *l_xi, double *l_eta, double *l_zeta)
Computes a cell's extent along each of its own grid directions.
FieldId
Compile-time identity for a catalogued Eulerian field.
PetscErrorCode PicurvPhysicalTime(const SimCtx *simCtx, PetscReal solver_time, PetscReal *physical)
Convert a solver time to physical seconds, t * L_ref / U_ref.
PetscReal SymTensorNormSq(SymTensor t)
Implementation of SymTensorNormSq().
PetscErrorCode ComputeEddyViscosityLES(UserCtx *user)
Implementation of ComputeEddyViscosityLES().
SymTensor SymTensorCombine(PetscReal a, SymTensor x, PetscReal b, SymTensor y)
Implementation of SymTensorCombine().
SymTensor SymTensorSelfOuter(Cmpnts v)
Implementation of SymTensorSelfOuter().
SymTensor SymTensorDeviator(SymTensor t)
Implementation of SymTensorDeviator().
PetscReal SubgridKineticEnergy(PetscReal yoshizawa_ci, PetscReal delta, PetscReal strain_magnitude)
Implementation of SubgridKineticEnergy().
PetscReal SymTensorTrace(SymTensor t)
Implementation of SymTensorTrace().
PetscReal EddyViscosityFromCoefficient(PetscReal coefficient, PetscReal delta, PetscReal strain_magnitude, PetscReal molecular_viscosity, PetscReal min_viscosity_ratio)
Implementation of EddyViscosityFromCoefficient().
SymTensor GermanoModelTensor(PetscReal delta, PetscReal alpha, PetscReal strain_magnitude_filtered, SymTensor strain_filtered, SymTensor strain_product_filtered)
Implementation of GermanoModelTensor().
PetscReal ClipModelCoefficient(PetscReal coefficient, const LESConfig *config, PetscBool *limited)
Implementation of ClipModelCoefficient().
PetscErrorCode ComputeCellFilterWidth(LESFilterWidthModel model, PetscReal aj, Cmpnts csi, Cmpnts eta, Cmpnts zet, PetscReal *delta)
Implementation of ComputeCellFilterWidth().
PetscErrorCode StrainRateFromGradients(Cmpnts dudx, Cmpnts dvdx, Cmpnts dwdx, SymTensor *strain, PetscReal *magnitude)
Implementation of StrainRateFromGradients().
PetscErrorCode ResolveLESAveragingDirections(UserCtx *user, PetscBool direction[3])
Implementation of ResolveLESAveragingDirections().
SymTensor LeonardStress(Cmpnts velocity_filtered, SymTensor velocity_product_filtered)
Implementation of LeonardStress().
PetscReal SymTensorContract(SymTensor a, SymTensor b)
Implementation of SymTensorContract().
static SymTensor LESStrainAt(Cmpnts diagonal, Cmpnts offdiagonal)
Rebuilds a symmetric strain tensor from its two scratch storage vectors.
static PetscErrorCode FinalizeSmagorinskyConstantField(UserCtx *user)
Synchronizes the completed Smagorinsky coefficient field.
PetscErrorCode LogLESDiagnostics(UserCtx *user)
Implementation of LogLESDiagnostics().
static PetscErrorCode ComputeStrainRateField(UserCtx *user, Cmpnts ***ucat, Vec strain_diagonal, Vec strain_offdiagonal, Vec strain_magnitude)
Fills the strain-rate scratch fields across the computed range and its halo.
static PetscInt LESStrainSampleIndex(PetscInt index, PetscInt extent, PetscBool periodic)
Maps a cell index to the index whose strain rate represents it.
PetscErrorCode ComputeSmagorinskyConstant(UserCtx *user)
Implementation of ComputeSmagorinskyConstant().
static const double LES_EPSILON
static PetscErrorCode LESResolveDomain(UserCtx *user, SpatialTargetPlan *plan)
Resolves the iteration domain the closure computes over.
static PetscErrorCode BuildWallModelExclusionMask(UserCtx *user, Vec inclusion)
Marks the first cells beside a modelled wall, so the procedure skips them.
PetscReal WALEEddyViscosity(Cmpnts dudx, Cmpnts dvdx, Cmpnts dwdx, PetscReal delta, PetscReal coefficient)
Implementation of WALEEddyViscosity().
PetscReal VremanEddyViscosity(Cmpnts dudx, Cmpnts dvdx, Cmpnts dwdx, const Cmpnts edges[3], PetscReal coefficient)
Implementation of VremanEddyViscosity().
#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.
@ LOG_INFO
Informational messages about program execution.
@ LOG_DEBUG
Detailed debugging information.
#define PROFILE_FUNCTION_BEGIN
Marks the beginning of a profiled function: an always-on aggregate timer.
PetscErrorCode ComputeVectorFieldDerivatives(UserCtx *user, PetscInt i, PetscInt j, PetscInt k, Cmpnts ***field_data, Cmpnts *dudx, Cmpnts *dvdx, Cmpnts *dwdx)
Computes the derivatives of a cell-centered vector field at a specific grid point.
PetscErrorCode UpdateLocalGhosts(UserCtx *user, FieldId field_id)
Updates the local vector (including ghost points) from its corresponding global vector.
static void GetPeriodicAxes(const SimCtx *simCtx, PetscBool periodic[3])
Which grid axes are periodic.
Spatial target resolution for the field-statistics pipeline.
PetscBool SpatialTargetPlanMaskAllows(const SpatialTargetPlan *plan, PetscReal nvert_value)
Reports whether a point passes the plan's mask.
@ PICURV_STATISTICS_MASK_FLUID
PetscInt end[3]
Exclusive end per dimension (i, j, k).
PetscInt start[3]
Inclusive start per dimension (i, j, k).
PetscErrorCode SpatialTargetPlanCreate(UserCtx *user, FieldId field_id, PicurvStatisticsMask mask, SpatialTargetPlan *plan)
Resolves the iteration domain for one field on one block.
PetscErrorCode PicurvSpatialRatioAverage(UserCtx *user, const SpatialTargetPlan *plan, Vec numerator, Vec denominator, Vec inclusion, const PetscBool average_direction[3], MPI_Comm comm, Vec ratio, PetscReal *reduced)
Averages two fields over a target domain and divides the results.
Resolved iteration domain for one field on one block.
PetscReal yoshizawa_ci
Yoshizawa constant for the reported SGS kinetic energy.
BoundaryFaceConfig boundary_faces[6]
LESFilterWidthModel filter_width_model
How the grid filter width Delta is derived per cell.
PetscReal contraction_mm
Volume-weighted sum of M_ij M_ij over fluid cells.
LESTestFilterKernel test_filter_kernel
Discrete test-filter stencil.
LESConfig les_config
Parameters of the LES closure selected by les.
SimCtx * simCtx
Back-pointer to the master simulation context.
PetscBool valid
Set once a dynamic update has populated this state.
@ LES_TEST_FILTER_SIMPSON_IK
PetscReal max_cs
Ceiling on Cs under LES_CLIP_CLAMP.
LESClipMode clip_mode
Admissible range for the coefficient.
LESDiagnosticsState les_diagnostics
Pre-clipping statistics from the last dynamic update.
PetscBool averaging_direction[3]
Averaged-over logical directions (xi, eta, zeta).
PetscReal wale_coefficient
Model constant C_w for WALE (Nicoud & Ducros 1999).
PetscReal limited_volume
Fluid volume whose coefficient the clip modified.
PetscReal fluid_volume
Total fluid volume sampled.
char analysis_dir[PETSC_MAX_PATH_LEN]
PetscReal contraction_lm
Volume-weighted sum of L_ij M_ij over fluid cells.
PetscInt diagnostics_cadence
Steps between diagnostic rows.
PetscReal min_viscosity_ratio
Enforce nu + nu_t >= ratio * nu.
PetscInt wallfunction
Enable wall functions on WALL faces.
@ LES_AVERAGING_HOMOGENEOUS
PetscBool diagnostics_enabled
Append per-step coefficient statistics to the run log directory.
PetscReal constant_cs
Fixed Cs for CONSTANT_SMAGORINSKY; unused by the dynamic model.
PetscReal test_filter_width_ratio
Test-to-grid ratio per filtered direction; alpha is its square for the box, ratio^(4/3) for Simpson.
LESAveragingMode averaging_mode
Averaging set for the Germano contractions.
PetscReal vreman_coefficient
Model constant c for VREMAN (Vreman 2004: 2.5 Cs^2).
PetscInt les
Active LES closure; an LESModelType value.
PetscReal backscatter_volume
Fluid volume whose raw coefficient was negative.
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
BCFace
Identifies the six logical faces of a structured computational block.
A 3D point or vector with PetscScalar components.
Every user-selectable parameter of the LES closure.
Pre-clipping volume statistics captured by one dynamic-coefficient update.
The master context for the entire simulation.
A symmetric second-order tensor stored by its six independent components.
User-defined context containing data specific to a single computational grid level.
double nu_t(double yplus)
Computes turbulent eddy viscosity ratio (ν_t / ν)