9#ifndef PECLET_FLOW_FLOW_IBM_CORE_HPP
10#define PECLET_FLOW_FLOW_IBM_CORE_HPP
24 for (
int a = 0; a < 3; ++a) {
25 m.a[a] = u_.org[a] + 0.5 * u_.h[a];
27 m.velToInt[a] = u_.velToInt(a);
29 m.dToInt = u_.lenToInt();
30 m.angToInt = u_.angVelToInt();
36 const std::array<double, 3>& origin,
const std::array<long, 3>&
globalCells) {
43 const std::array<double, 3>& origin,
48 for (
int a = 0; a < 3; ++a) {
49 if (!(extent[a] > 0.0))
50 throw std::runtime_error(
"physical domain: every extent component must be > 0");
52 throw std::runtime_error(
"physical domain: every cell count must be > 0");
55 for (
int a = 0; a < 3; ++a)
56 hh[a] = extent[a] / (
double)c[a];
68 for (
int a = 1; a < 3; ++a)
69 if (std::fabs(hh[a] - hh[0]) > 1e-12 * std::fabs(hh[0]))
72 for (
int a = 1; a < 3; ++a)
75 for (
int a = 0; a < 3; ++a) {
77 u_.ext[a] = extent[a];
78 u_.org[a] = origin[a];
81 u_.hRef = std::min(hh[0], std::min(hh[1], hh[2]));
82 for (
int a = 0; a < 3; ++a) {
83 u_.hp[a] = iso ? 1.0 : u_.h[a] / u_.hRef;
84 u_.w[a] = iso ? 1.0 : 1.0 / (u_.hp[a] * u_.hp[a]);
86 u_.vol = iso ? 1.0 : u_.hp[0] * u_.hp[1] * u_.hp[2];
104 std::snprintf(msg,
sizeof msg,
105 "%s: this entry point requires ISOTROPIC cells, but extent/cells gives "
106 "dx=%.17g dy=%.17g dz=%.17g (hRef=%.17g, h'=(%.17g, %.17g, %.17g)).",
107 what, u_.h[0], u_.h[1], u_.h[2], u_.hRef, u_.hp[0], u_.hp[1], u_.hp[2]);
108 throw std::runtime_error(msg);
123 return {u_.h[0], u_.h[1], u_.h[2]};
128 return {u_.org[0], u_.org[1], u_.org[2]};
134 return {u_.ext[0], u_.ext[1], u_.ext[2]};
136 return {(double)gc[0], (
double)gc[1], (double)gc[2]};
141 if (u_.physical && u_.cells[0] > 0)
142 return {u_.cells[0], u_.cells[1], u_.cells[2]};
143#ifdef PECLET_FLOW_MPI
145 return {gnx_, gny_, gnz_};
147 return {nx_, ny_, nz_};
152 if (axis < 0 || axis > 2)
153 throw std::runtime_error(
"cell_centers: axis must be 0, 1 or 2");
154 const int n[3] = {nx_, ny_, nz_};
155 const int og[3] = {og_.x, og_.y, og_.z};
156 std::vector<double> c((std::size_t)n[axis]);
157 for (
int i = 0; i < n[axis]; ++i)
158 c[(std::size_t)i] = u_.org[axis] + ((double)(og[axis] + i) + 0.5) * u_.h[axis];
169 u_.hpMax = std::max(u_.hp[0], std::max(u_.hp[1], u_.hp[2]));
171 rho_ = rhoPhys_ * u_.rhoToInt();
172 mu_ = muPhys_ * u_.muToInt();
173 const double dtInt = dtPhys_ * u_.timeToInt();
176 for (
int a = 0; a < 3; ++a)
177 f_[a] = fPhys_[a] * u_.forceToInt(a);
178 sigmaCsf_ = sigmaPhys_ * u_.sigmaToInt();
181 if (vofBlocks_ && vofBlocks_->csfEnabled)
182 vofBlocks_->sigma = sigmaCsf_;
183 slipLambda_ = slipPhys_ * u_.lenToInt();
184 for (
auto& sc : scalars_)
185 sc.D = sc.Dphys * u_.diffToInt();
187 for (
auto& cl : closures_)
189 for (
int face = 0; face < 6; ++face) {
190 for (
int a = 0; a < 3; ++a)
191 bcVel_[face][a] = bcVelPhys_[face][a] * u_.velToInt(a);
192 if (!bcProfRaw_[face].empty())
203 const vof::VofMetric g = u_.vofMetric();
208 pcAreaMc_.metric = g;
210 vofBlocks_->setMetric(g);
221 n_ = (std::size_t)e_.
x * e_.y * e_.z;
223 n1_ = (std::size_t)e1_.
x * e1_.y * e1_.z;
241 for (
int c = 0; c < 3; ++c) {
244 C[c].AC =
FV(
"AC", n_);
245 C[c].AW =
FV(
"AW", n_);
246 C[c].AE =
FV(
"AE", n_);
247 C[c].AS =
FV(
"AS", n_);
248 C[c].AN =
FV(
"AN", n_);
249 C[c].AB =
FV(
"AB", n_);
250 C[c].AT =
FV(
"AT", n_);
251 C[c].inhom =
CCField(
"inhom", n_);
252 C[c].rscale =
CCField(
"rscale", n_);
253 C[c].mask =
CCField(
"mask", n_);
254 bcDcorr_[c] =
CCField(
"dcorr", n_);
255 bcBrhs_[c] =
CCField(
"brhs", n_);
256 const int maxCut =
nx *
ny *
nz;
259 C[c].ov =
IbmOverlay{Kokkos::View<int*, CCMem>(
"ci", maxCut),
260 Kokkos::View<int*, CCMem>(
"nb", maxCut),
262 Kokkos::View<int*, CCMem>(
"dc", (std::size_t)maxCut * 6),
263 FV(
"K", (std::size_t)maxCut * 6),
264 FV(
"M", (std::size_t)maxCut * 6),
265 FV(
"X", (std::size_t)maxCut * 6),
266 FV(
"Nbc", (std::size_t)maxCut * 6),
267 FV(
"R", (std::size_t)maxCut * 6)};
268 C[c].idMap = Kokkos::View<int*, CCMem>(
"idMap", n_);
269 C[c].counter = Kokkos::View<int, CCMem>(
"cnt");
271 prev_[c] =
CCField(
"uPrev", n_);
273 if constexpr (Grid::collocated) {
289 fields_.adopt(
"u", C[0].u,
G, peclet::core::Centering::FaceX);
290 fields_.adopt(
"v", C[1].u,
G, peclet::core::Centering::FaceY);
291 fields_.adopt(
"w", C[2].u,
G, peclet::core::Centering::FaceZ);
292 fields_.adopt(
"p", P_,
G, peclet::core::Centering::Cell);
293 fields_.adopt(
"sdf", sdf_,
G, peclet::core::Centering::Cell);
299 if (u_.physical && !u_.rhoRefSet) {
305 const double ri = r * u_.rhoToInt();
315 const double mi = m * u_.muToInt();
325 if (u_.physical && !u_.tRefSet) {
328 const double before = dt_;
334 const double di = d * u_.timeToInt();
344 fPhys_ = {fx, fy, fz};
345 for (
int a = 0; a < 3; ++a)
346 f_[a] = fPhys_[a] * u_.forceToInt(a);
352 superficialAxis_ = -1;
355 if (axis < 0 || axis > 2)
356 throw std::invalid_argument(
"set_superficial_velocity: axis must be 0, 1 or 2");
357 if constexpr (Grid::collocated)
358 throw std::runtime_error(
359 "set_superficial_velocity: staggered Solver only (the collocated grid would have to "
360 "shift the projected face field and the cell velocity consistently; not implemented)");
361 superficialAxis_ = axis;
362 superficialVelPhys_ = velocity;
363 if (superficialShift_.data() ==
nullptr)
364 superficialShift_ = Kokkos::View<double, CCMem>(
"superficial_shift");
365 Kokkos::deep_copy(superficialShift_, 0.0);
370 if (superficialAxis_ < 0 || superficialShift_.data() ==
nullptr)
373 Kokkos::deep_copy(h, superficialShift_);
374 return h * u_.velToPhys(superficialAxis_);
384 velTol_ = rtol > 0.0 ? rtol : 0.0;
385 velMinIters_ = minIters < 1 ? 1 : minIters;
390 return lastMomentumSweeps_;
400 int minBlockExtent) {
401 vmgAutoCells_ = cellsPerRank;
402 if (minGlobalCells >= 0)
403 vmgAutoMinGlobal_ = minGlobalCells;
404 if (minBlockExtent >= 0)
405 vmgAutoMinExtent_ = minBlockExtent;
410 useVelocityCheb_ = on;
411 velChebMaxit_ = maxit < 1 ? 1 : maxit;
416 vmgExplicit_ =
false;
417 useVelocityCheb_ =
false;
418 useVelocityMg_ =
false;
424 return useVelocityCheb_;
430 vmgChebDegree_ = degree;
431 vmgChebEigRatio_ = eig_ratio;
432 vmg_.setChebyshevSmoother(on, degree, eig_ratio);
442 if (velResTol_ >= 0.0)
444 return useChebyshev_ ? chebRtol_ : pcgRtol_;
450 return lastMomentumResid_;
455 mg_.setMeanRemovalScope(all);
480 outerIters_ = iters < 1 ? 1 : iters;
490 return lastOuterIters_;
499 vmgLevels_ = levels < 1 ? 1 : levels;
500 vmgVcycles_ = vcycles < 1 ? 1 : vcycles;
505 throw std::invalid_argument(
507 ": the velocity multigrid takes a SCALAR viscosity and would silently solve the momentum "
508 "equation with the constant set_mu value, ignoring the variable viscosity (a 'mu' "
509 "closure or set_property_mode('variable')). Use set_velocity_solver('gauss_seidel') or "
510 "'auto' (the AUTO rule already keeps variable viscosity on the red-black smoother).");
515 return useVelocityMg_;
520 pressAgglomMode_ = mode;
521 if (cutcellPressure_)
522 mg_.setAgglomerationMode(mode);
527 mg_.setBottomSolver(engine);
533 if (enabled != mg_.lineRelaxation()) {
534 chebBoundsSet_ =
false;
538 mg_.setLineRelaxation(enabled);
544 if (enabled != mg_.symmetricVcycle()) {
545 chebBoundsSet_ =
false;
549 mg_.setSymmetricVcycle(enabled);
554 mg_.setVcyclePrecision(mode);
559 return mg_.lastVcycleFp32();
564 mg_.debugSetFp32Fault(kind, at);
569 return mg_.vcycleRestarts();
579 mg_.setTelescope(on);
584 return mg_.telescope();
589 mg_.setTelescopeForceLevel(level);
594 return mg_.telescopeCount();
599 return mg_.prefactorLaunches();
605 if (cutcellPressure_)
606 mg_.setGraphAmgBottom(on);
612 nLevels_ = levels < 0 ? 1 : levels;
617 backflowBeta_ = beta < 0.0 ? 0.0 : beta;
632 chebBoundsSet_ =
false;
640 throw std::runtime_error(
641 "set_pressure_pcg(False): MG-PCG is the default/terminal pressure driver, so it cannot be "
642 "deselected on its own — select the driver you want instead "
643 "(set_pressure_chebyshev(True, ...) or set_pressure_fcg(True, ...)).");
644 useChebyshev_ =
false;
646 chebBoundsSet_ =
false;
651 cgContrastPending_ =
true;
656 if (on && ghostProjection_)
657 throw std::runtime_error(
658 "set_pressure_fcg: the ghost-projection operator is nonsymmetric and is solved by "
659 "BiCGStab; FCG does not apply");
662 useChebyshev_ =
false;
665 cgContrastPending_ =
true;
670 if constexpr (Grid::collocated) {
676 if (on && faceInterp_ != 0)
681 if (on && geometryBuilt_)
682 throw std::runtime_error(
683 "set_ghost_projection / set_collocated_scheme('ghost'): call BEFORE set_solid -- the "
684 "ghost overlay is built with the geometry");
685 if (on && (porous_ || varRho_ || hasBc_ || useChebyshev_))
686 throw std::runtime_error(
687 "set_ghost_projection: incompatible with porous/variable-rho/domain-BC/Chebyshev (v1)");
688 if (matrixOrder < 1 || matrixOrder > 2 || rhsOrder < 1 || rhsOrder > 2)
689 throw std::runtime_error(
"set_ghost_projection: matrix_order/rhs_order must be 1 or 2");
690 if (on && distributed_ && (hasExactCross_ || hasOpenOverride_))
691 throw std::runtime_error(
692 "set_ghost_projection: exact-crossings/openness-override are single-rank only");
693 ghostProjection_ = on;
694 colSchemeAuto_ =
false;
695 gpMatrixOrder_ = matrixOrder;
696 gpRhsOrder_ = rhsOrder;
703 const std::size_t n = (std::size_t)nx_ * ny_ * nz_;
705 hasExactCross_ =
false;
708 if (t.size() != 9 * n)
709 throw std::runtime_error(
"set_exact_crossings: expected 9*nx*ny*nz values");
710#ifdef PECLET_FLOW_MPI
712 throw std::runtime_error(
"set_exact_crossings: single-rank only");
714 for (
int c = 0; c < 3; ++c)
715 for (
int k = 0; k < 3; ++k) {
716 tEx_[c][k] =
CCField(
"tEx", n);
719 Kokkos::View<
const double*, Kokkos::HostSpace, Kokkos::MemoryTraits<Kokkos::Unmanaged>>(
720 t.data() + ((std::size_t)c * 3 + k) * n, n));
722 hasExactCross_ =
true;
727 const std::vector<double>& oz) {
729 const std::size_t n = (std::size_t)nx_ * ny_ * nz_;
731 hasOpenOverride_ =
false;
734 if (ox.size() != n || oy.size() != n || oz.size() != n)
735 throw std::runtime_error(
"set_openness_override: expected nx*ny*nz values per field");
736#ifdef PECLET_FLOW_MPI
738 throw std::runtime_error(
"set_openness_override: single-rank only");
743 hasOpenOverride_ =
true;
758 if (mode < 0 || mode > 2)
759 throw std::runtime_error(
"set_pressure_initial_guess: 'auto' | 'zero' | 'projected'");
760 if (history != 1 && history != 2)
761 throw std::runtime_error(
"set_pressure_initial_guess: history must be 1 or 2");
763 pguessHistMax_ = history;
773 return "the Chebyshev driver (not a Krylov driver; set_pressure_pcg or set_pressure_fcg)";
774 if (ghostProjection_)
775 return "the ghost projection (its BiCGStab driver)";
777 return "set_pressure_warmstart(True)";
783 if (mode != 0 && mode != 9 && (mode < 5 || mode > 7))
784 throw std::runtime_error(
785 "set_face_interp: mode " + std::to_string(mode) +
786 " is not one of 0 (plain), 5/6/7 (embed rungs) or 9 (gauge-exact); use "
787 "set_collocated_scheme('plain' | 'gauge-exact' | 'embed' | 'ghost')");
788 if (ghostProjection_ && mode != 0)
789 throw std::runtime_error(
790 "set_face_interp: incompatible with the ghost projection (set_ghost_projection(False) "
791 "first, or use set_collocated_scheme which handles the transition)");
793 colSchemeAuto_ =
false;
803 if (name !=
"ghost" && ghostProjection_) {
804 ghostProjection_ =
false;
807 if (name ==
"gauge-exact") {
809 }
else if (name ==
"plain") {
811 }
else if (name ==
"embed") {
813 }
else if (name ==
"ghost") {
823 throw std::runtime_error(
824 "set_collocated_scheme: expected 'ghost', 'gauge-exact', 'plain' or 'embed', got '" + name +
846 if (order < 1 || order > 2)
847 throw std::runtime_error(
"set_aperture_order: order must be 1 or 2");
848 apertureOrder_ = order;
853 return apertureOrder_;
869 throw std::runtime_error(
870 "set_comm_avoiding: call BEFORE init_mpi -- the momentum half is latched with the halo "
873 mg_.setCommAvoiding(mask);
884 throw std::runtime_error(
"set_multigrid_aspect_threshold: theta must be > 1");
885 aspectTheta_ = theta;
886 mg_.setAspectThreshold(theta);
887 vmg_.setAspectThreshold(theta);
897 mg_.setStrictPressure(on);
902 return mg_.strictPressure();
907 mg_.setCoarseGhost(on);
912 return mg_.coarseGhost();
917 mg_.setAgglomerationExtent(cells);
922 return mg_.agglomerationExtent();
928 throw std::runtime_error(
929 "set_decomposition: call BEFORE init_mpi -- the decomposition is built there");
931 throw std::invalid_argument(
932 "set_decomposition: levels must be >= 0 (0 = auto, 1 = the legacy aligned ORB, >= 2 = "
933 "coarse-first at that depth)");
934 if (!(maxImbalance > 1.0))
935 throw std::invalid_argument(
936 "set_decomposition: max_imbalance must be > 1.0 (the largest / smallest block cell-count "
937 "ratio a candidate may reach; default 1.05)");
938 decompLevels_ = levels;
939 decompMaxImbalance_ = maxImbalance;
944 return decompLevels_;
949 return decompMaxImbalance_;
955 if (mode < 0 || mode > 2)
956 throw std::runtime_error(
"set_fluid_only_constraint: mode must be 0, 1 or 2");
957 fluidOnlyMode_ = mode;
959 colSchemeAuto_ =
false;
970 if constexpr (Grid::collocated) {
971 for (
int c = 0; c < 3; ++c)
973 if (faceInterp_ == 5 || faceInterp_ == 7)
979 faceFieldValid_ =
true;
986 const std::vector<double>& ww) {
988 const std::vector<double>* src[3] = {&uu, &vv, &ww};
989 std::vector<double> scaled[3];
990 for (
int c = 0; c < 3; ++c) {
991 const double k = u_.velToInt(c);
994 scaled[c].resize(src[c]->size());
995 for (std::size_t i = 0; i < src[c]->size(); ++i)
996 scaled[c][i] = (*src[c])[i] * k;
1000 const int ex = e_.x, ey = e_.y,
nx = nx_,
ny = ny_,
nz = nz_, g =
G;
1001 for (
int c = 0; c < 3; ++c) {
1005 CCField din(
"peclet::flow::vel_in_d",
static_cast<std::size_t
>(nx_) * ny_ * nz_);
1008 Kokkos::View<
const double*, Kokkos::HostSpace, Kokkos::MemoryTraits<Kokkos::Unmanaged>>(
1009 src[c]->data(), src[c]->size()));
1011 Kokkos::parallel_for(
1013 KOKKOS_LAMBDA(
int x,
int y,
int z) {
1014 u((
long)(x + g) + (
long)(y + g) * ex + (
long)(z + g) * (
long)ex * ey) =
1015 din((std::size_t)x + (std::size_t)y *
nx + (std::size_t)z * (std::size_t)
nx *
ny);
1022template <
class Gr
id>
1027template <
class Gr
id>
1032template <
class Gr
id>
1037template <
class Gr
id>
1039 return advectsMomentum() && (implicitFou_ || (hasBc_ && (!useVelocityMg_ || hasSolid_)));
1042template <
class Gr
id>
1045 (hasSolid_ || (!useVelocityMg_ && (
implicitAdv() || varProps_ || varRho_ || hasDrag_)));
1048template <
class Gr
id>
1050 return hasBc_ && useVelocityMg_ && hasSolid_ && !varProps_ && !varRho_ && !hasDrag_;
1053template <
class Gr
id>
1055 return (c == 0) ? 1 : (c == 1) ? e_.x : (long)e_.x * e_.y;
1058template <
class Gr
id>
1062 const double idiag = rho_ / dt_, bx = mu_ * u_.w[0], by = mu_ * u_.w[1], bz = mu_ * u_.w[2];
1067 for (
int c = 0; c < 3; ++c) {
1068 Kokkos::deep_copy(
CCExec(), C[c].rscale, 1.0);
1069 Kokkos::deep_copy(
CCExec(), C[c].inhom, 0.0);
1078 ibmBuildDiffusion(C[c].
AC, C[c].AW, C[c].AE, C[c].AS, C[c].AN, C[c].AB, C[c].AT, e_.x, e_.y,
1079 e_.z, bx, by, bz, idiag);
1080 ibmModifyStencil(C[c].
AC, C[c].AW, C[c].AE, C[c].AS, C[c].AN, C[c].AB, C[c].AT, C[c].inhom,
1081 C[c].rscale, C[c].ov, C[c].nCut, 0.0f,
wallVelView(c));
1087template <
class Gr
id>
1093 "peclet::flow::copyInner",
C3{0, 0, 0},
C3{nx_, ny_, nz_},
1094 KOKKOS_LAMBDA(
int ix,
int iy,
int iz) {
1096 (long)(ix + dg) + (long)(iy + dg) * de.
x + (long)(iz + dg) * (long)de.
x * de.
y;
1098 (long)(ix + sg) + (long)(iy + sg) * se.
x + (long)(iz + sg) * (long)se.
x * se.
y;
1103template <
class Gr
id>
1106 "peclet::flow::copyBlockShifted",
C3{0, 0, 0},
C3{de.
x, de.
y, de.
z},
1107 KOKKOS_LAMBDA(
int x,
int y,
int z) {
1108 const long di = (long)x + (
long)y * de.
x + (long)z * (
long)de.
x * de.
y;
1110 (long)(x + off) + (long)(y + off) * se.
x + (long)(z + off) * (long)se.
x * se.
y;
1115template <
class Gr
id>
1117#ifdef PECLET_FLOW_MPI
1119 velDev_->exchange(f);
1126template <
class Gr
id>
1128#ifdef PECLET_FLOW_MPI
1130 velDev_->exchange(f);
1136 const int Nx = nx_, Ny = ny_, Nz = nz_;
1137 const long sx = 1, sy = e.x, sz = (long)e.x * e.y;
1139 Kokkos::parallel_for(
1140 "peclet::flow::ibm_facefill", Kokkos::RangePolicy<CCExec>(space, 0, (
long)nx_ * ny_ * nz_),
1141 KOKKOS_LAMBDA(
long n) {
1142 const int ix = (int)(n % Nx), iy = (int)((n / Nx) % Ny), iz = (int)(n / ((
long)Nx * Ny));
1143 const long i = (long)(ix +
G) * sx + (long)(iy +
G) * sy + (long)(iz +
G) * sz;
1145 ff(i + (
long)Nx * sx) = ff(i);
1146 else if (ix >= Nx -
G)
1147 ff(i - (
long)Nx * sx) = ff(i);
1149 ff(i + (
long)Ny * sy) = ff(i);
1150 else if (iy >= Ny -
G)
1151 ff(i - (
long)Ny * sy) = ff(i);
1153 ff(i + (
long)Nz * sz) = ff(i);
1154 else if (iz >= Nz -
G)
1155 ff(i - (
long)Nz * sz) = ff(i);
1159template <
class Gr
id>
1163 int N3[3] = {nx_, ny_, nz_};
1164 int dims[3] = {e.x, e.y, e.z};
1165 long st[3] = {1, e.x, (long)e.x * e.y};
1166 const int a = axis, b = (axis + 1) % 3, c = (axis + 2) % 3;
1167 const long sa = st[a], sb = st[b], sc = st[c];
1168 const int N = N3[a];
1170 Kokkos::parallel_for(
1171 "peclet::flow::ibm_pfill",
MDRange2<CCExec>(space, {0, 0}, {dims[b], dims[c]}),
1172 KOKKOS_LAMBDA(
int p0,
int p1) {
1173 const long base = (long)p0 * sb + (
long)p1 * sc;
1174 for (
int gl = 0; gl <
G; ++gl) {
1175 ff(base + (
long)gl * sa) = ff(base + (
long)(gl +
N) * sa);
1176 ff(base + (
long)(
G +
N + gl) * sa) = ff(base + (
long)(
G + gl) * sa);
1191template <
class Gr
id>
1193 const bool px = axes & 1, py = axes & 2, pz = axes & 4;
1194 const int nx = nx_,
ny = ny_,
nz = nz_;
1195 if ((px &&
nx <
G) || (py &&
ny <
G) || (pz &&
nz <
G)) {
1198 for (
int a = 0; a < 3; ++a)
1199 if (axes & (1 << a))
1205 const long exy = (long)e.x * e.y;
1208 const int z0 = pz ?
G : 0, zn = pz ?
nz : e.z;
1209 const int y0 = py ?
G : 0, yn = py ?
ny : e.y;
1210 const long nZ = pz ? 2L *
G * exy : 0, nY = py ? (long)zn * 2 *
G * e.x : 0,
1211 nX = px ? (long)zn * yn * 2 *
G : 0;
1213 if constexpr (std::is_same_v<typename CCExec::memory_space, Kokkos::HostSpace>) {
1216 const long rZ = pz ? 2L *
G * e.y : 0, rY = py ? (long)zn * 2 *
G : 0,
1217 rX = px ? (long)zn * yn : 0;
1218 auto copyRow = [=](
long dst,
long src) {
1220 for (
int x = 0; x <
G; ++x)
1221 ff(dst + x) = ff(src + x +
nx);
1222 for (
int x =
G; x <
G +
nx; ++x)
1223 ff(dst + x) = ff(src + x);
1224 for (
int x =
G +
nx; x < e.x; ++x)
1225 ff(dst + x) = ff(src + x -
nx);
1227 for (
int x = 0; x < e.x; ++x)
1228 ff(dst + x) = ff(src + x);
1231 auto row = [=](
long t) {
1233 const int l = (int)(t / e.y), y = (int)(t - (
long)l * e.y);
1234 const int z = l <
G ? l :
nz + l;
1235 const int sy = !py ? y : (y <
G ? y +
ny : (y >=
G +
ny ? y -
ny : y));
1236 const int sz = z <
G ? z +
nz : z -
nz;
1237 copyRow((
long)y * e.x + (
long)z * exy, (
long)sy * e.x + (
long)sz * exy);
1238 }
else if (t < rZ + rY) {
1239 const long t2 = t - rZ;
1240 const int zi = (int)(t2 / (2 *
G)), l = (int)(t2 - (
long)zi * 2 *
G);
1241 const int y = l <
G ? l :
ny + l, z = z0 + zi;
1242 const int sy = y <
G ? y +
ny : y -
ny;
1243 copyRow((
long)y * e.x + (
long)z * exy, (
long)sy * e.x + (
long)z * exy);
1245 const long t3 = t - rZ - rY;
1246 const int zi = (int)(t3 / yn), yi = (int)(t3 - (
long)zi * yn);
1247 const long base = (long)(y0 + yi) * e.x + (long)(z0 + zi) * exy;
1248 for (
int x = 0; x <
G; ++x)
1249 ff(base + x) = ff(base + x +
nx);
1250 for (
int x =
G +
nx; x < e.x; ++x)
1251 ff(base + x) = ff(base + x -
nx);
1256 for (
long t = 0; t < rZ + rY + rX; ++t)
1260 Kokkos::parallel_for(
"peclet::flow::ibm_pfill3",
1261 Kokkos::RangePolicy<CCExec>(space, 0, rZ + rY + rX), row);
1264 Kokkos::parallel_for(
1265 "peclet::flow::ibm_pfill3", Kokkos::RangePolicy<CCExec>(space, 0, nZ + nY + nX),
1266 KOKKOS_LAMBDA(
long t) {
1269 const int l = (int)(t / exy);
1270 const long r = t - (long)l * exy;
1273 z = l <
G ? l :
nz + l;
1274 }
else if (t < nZ + nY) {
1275 const long t2 = t - nZ, rw = 2L *
G * e.x;
1276 const long zi = t2 / rw, r = t2 - zi * rw;
1277 const int l = (int)(r / e.x);
1279 y = l <
G ? l :
ny + l;
1282 const long t3 = t - nZ - nY, rw = (long)yn * 2 *
G;
1283 const long zi = t3 / rw, r = t3 - zi * rw;
1284 const int l = (int)(r % (2 *
G));
1285 x = l <
G ? l :
nx + l;
1286 y = y0 + (int)(r / (2 *
G));
1289 const int sx = !px ? x : (x <
G ? x +
nx : (x >=
G +
nx ? x -
nx : x));
1290 const int sy = !py ? y : (y <
G ? y +
ny : (y >=
G +
ny ? y -
ny : y));
1291 const int sz = !pz ? z : (z <
G ? z +
nz : (z >=
G +
nz ? z -
nz : z));
1292 ff((
long)x + (
long)y * e.x + (
long)z * exy) =
1293 ff((
long)sx + (
long)sy * e.x + (
long)sz * exy);
1297template <
class Gr
id>
1299 int axes = 0, n = 0, last = -1;
1300 for (
int a = 0; a < 3; ++a)
1301 if (bc_[2 * a] == 0 && bc_[2 * a + 1] == 0) {
1312template <
class Gr
id>
1314 return advWallVel_ && !Grid::collocated && hasScene_ && hasMotion_ &&
advectsMomentum() &&
1315 uBc_[0].extent(0) == n_ && C[0].mask.extent(0) == n_;
1318template <
class Gr
id>
1323 for (
int c = 0; c < 3; ++c) {
1324 if (uwAdv_[c].extent(0) != n_)
1325 uwAdv_[c] =
CCField(
"uwAdv", n_);
1326 Kokkos::deep_copy(uwAdv_[c], C[c].u);
1329 Kokkos::parallel_for(
1330 "peclet::flow::adv_wall_inputs", Kokkos::RangePolicy<CCExec>(space, 0, (
long)n_),
1331 KOKKOS_LAMBDA(
long i) {
1340template <
class Gr
id>
1345template <
class Gr
id>
1347 return CCConst(c == 0 ? uf_ : (c == 1 ? vf_ : wf_));
1350template <
class Gr
id>
1352 return (hasOutflow_ && ufOpen_[c].extent(0) == n_) ?
CCConst(ufOpen_[c]) :
advFaceView(c);
1355template <
class Gr
id>
1357 if constexpr (Grid::collocated) {
1360 CCField src[3] = {uf_, vf_, wf_};
1361 for (
int a = 0; a < 3; ++a) {
1362 if (ufOpen_[a].extent(0) != n_)
1363 ufOpen_[a] =
CCField(
"peclet::flow::ufOpen", n_);
1364 Kokkos::deep_copy(ufOpen_[a], src[a]);
1366 B3 e{e_.x, e_.y, e_.z};
1367 for (
int a = 0; a < 3; ++a)
1368 if (bc_[2 * a + 1] == 3 && touchesGlobalFace(2 * a + 1))
1373template <
class Gr
id>
1375 return Grid::collocated && ufAdvect_ && faceFieldValid_;
1378template <
class Gr
id>
1383template <
class Gr
id>
1388template <
class Gr
id>
1390 const bool want = !Grid::collocated && hasScene_ && adv;
1391 if (want && advRhs_[c].extent(0) != n_)
1392 advRhs_[c] =
CCField(
"advRhs", n_);
1397template <
class Gr
id>
1400 const double idiag = rho_ / dt_, fouw = rho_, bx = mu_ * u_.w[0], by = mu_ * u_.w[1],
1403 ibmBuildDiffusion(C[c].
AC, C[c].AW, C[c].AE, C[c].AS, C[c].AN, C[c].AB, C[c].AT, e.x, e.y, e.z,
1406 FV AC = C[c].AC, AW = C[c].AW, AE = C[c].AE, AS = C[c].AS, AN = C[c].AN, AB = C[c].AB,
1416 Kokkos::parallel_for(
1417 "advstencil", MD(space, {
G,
G,
G}, {e.x -
G, e.y -
G, e.z -
G}),
1418 KOKKOS_LAMBDA(
int x,
int y,
int z) {
1419 const long i = (long)x + (
long)y * e.x + (long)z * (
long)e.x * e.y;
1420 double cC =
AC(i), cxm = AW(i), cxp = AE(i), cym = AS(i), cyp = AN(i), czm = AB(i),
1423 Grid::fou_operator(c, x, y, z, Ua, Va, Wa, fouw, cC, cxm, cxp, cym, cyp, czm, czp, ufa);
1433 Kokkos::deep_copy(C[c].rscale, 1.0);
1434 Kokkos::deep_copy(C[c].inhom, 0.0);
1435 ibmModifyStencil(C[c].
AC, C[c].AW, C[c].AE, C[c].AS, C[c].AN, C[c].AB, C[c].AT, C[c].inhom,
1436 C[c].rscale, C[c].ov, C[c].nCut, 0.0f,
wallVelView(c));
1441template <
class Gr
id>
1449 if (!varRho_ && porous_ && porousCons_)
1460 FV AC = C[c].AC, AW = C[c].AW, AE = C[c].AE, AS = C[c].AS, AN = C[c].AN, AB = C[c].AB,
1470 const double rhoC = rho_;
1474 Kokkos::parallel_for(
1475 "advstencil_var", MD(space, {
G,
G,
G}, {e.x -
G, e.y -
G, e.z -
G}),
1476 KOKKOS_LAMBDA(
int x,
int y,
int z) {
1477 const long i = (long)x + (
long)y * e.x + (long)z * (
long)e.x * e.y;
1478 double cC =
AC(i), cxm = AW(i), cxp = AE(i), cym = AS(i), cyp = AN(i), czm = AB(i),
1481 const double fouw = vr ? 0.5 * (rf(i) + rf(i - sc)) : rhoC;
1482 Grid::fou_operator(c, x, y, z, Ua, Va, Wa, fouw, cC, cxm, cxp, cym, cyp, czm, czp, ufa);
1491 Kokkos::deep_copy(C[c].rscale, 1.0);
1492 Kokkos::deep_copy(C[c].inhom, 0.0);
1493 ibmModifyStencil(C[c].
AC, C[c].AW, C[c].AE, C[c].AS, C[c].AN, C[c].AB, C[c].AT, C[c].inhom,
1494 C[c].rscale, C[c].ov, C[c].nCut, 0.0f,
wallVelView(c));
1499template <
class Gr
id>
1504 Kokkos::parallel_reduce(
1506 KOKKOS_LAMBDA(
int x,
int y,
int z,
double& acc) {
1507 const long i = (long)x + (
long)y * e.x + (long)z * (
long)e.x * e.y;
1508 const double d = Kokkos::fabs(a(i) - b(i));
1512 Kokkos::Max<double>(m));
1516template <
class Gr
id>
1517template <
class Fill,
class Color,
class ColorDu>
1519 std::function<
double()> resid,
double bnorm) {
1521 int used = velIters_;
1523 const bool useRes = vtol > 0.0 && resid;
1524 auto gmax = [&](
double v) {
1525#ifdef PECLET_FLOW_MPI
1528 MPI_Allreduce(&v, &g, 1, MPI_DOUBLE, MPI_MAX, comm_);
1534 double scale = 0.0, rPrev = -1.0;
1542 (void)gmax(resid());
1544 scale = std::max(gmax(bnorm >= 0.0 ? bnorm : lastBNorm_), gmax(lastAxNorm_));
1552 bool ghostsCurrent = useRes;
1553 for (
int it = 0; it < velIters_; ++it) {
1556 ghostsCurrent =
false;
1562 if (it == 0 || (it + 1) % 4 == 0 || it + 1 == velIters_) {
1564 const double r = gmax(resid());
1565 const double ratio = scale > 0 ? r / scale : 0.0;
1569 const bool floor = r <= 1e-14 * scale || (rPrev >= 0.0 && r >= rPrev);
1571 if (r <= vtol * scale || floor || it + 1 == velIters_) {
1572 lastMomentumResid_ = std::max(lastMomentumResid_, ratio);
1576 ghostsCurrent =
true;
1578 }
else if (velTol_ > 0.0) {
1579 double du = sweepColorDu(1);
1580#ifdef PECLET_FLOW_MPI
1583 MPI_Allreduce(&du, &gd, 1, MPI_DOUBLE, MPI_MAX, comm_);
1589 if (it + 1 >= velMinIters_ && du <= velTol_ * du0) {
1597 lastMomentumSweeps_ += used;
1600template <
class Gr
id>
1602#ifdef PECLET_FLOW_MPI
1609template <
class Gr
id>
1612 const int t = bc_[2 * c];
1613 if ((t == 1 || t == 2 || t == 4) && touchesGlobalFace(2 * c))
1619template <
class Gr
id>
1627template <
class Gr
id>
1631 if (velRes_.extent(0) != n_)
1632 velRes_ =
CCField(
"velRes", n_);
1633 return [
this, c, exchange]() {
1634#ifdef PECLET_FLOW_MPI
1635 if (exchange && distributed_)
1636 velDev_->exchange(C[c].u);
1642 double rmax = 0.0, bdmax = 0.0, bmax = 0.0;
1646 lastAxNorm_ = bdmax;
1652template <
class Gr
id>
1657 if (velRes_.extent(0) != n_)
1658 velRes_ =
CCField(
"velRes", n_);
1659 const bool an = u_.aniso;
1660 return [
this, c, bx, by, bz, Ac, an]() {
1661 const I3 e{e_.x, e_.y, e_.z};
1662 double rmax = 0.0, bdmax = 0.0, bmax = 0.0;
1665 lastAxNorm_ = bdmax;
1671template <
class Gr
id>
1677template <
class Gr
id>
1679 if (chebD_.extent(0) != n_)
1680 chebD_ =
CCField(
"chebD", n_);
1681 if (velRes_.extent(0) != n_)
1682 velRes_ =
CCField(
"velRes", n_);
1683 Kokkos::deep_copy(chebD_, 0.0);
1685 auto gmax = [&](
double v) {
1686#ifdef PECLET_FLOW_MPI
1689 MPI_Allreduce(&v, &g, 1, MPI_DOUBLE, MPI_MAX, comm_);
1696#ifdef PECLET_FLOW_MPI
1698 velDev_->exchange(C[c].u);
1704 auto residual = [&] {
1713 double lo = 0.0, hi = 0.0;
1720 if (!(hi > lo) || !(lo > 0.0)) {
1726 const bool useRes = vtol > 0.0;
1728 double scale = 0.0, rPrev = -1.0;
1738 int used = velChebMaxit_;
1739 for (
int it = 0; it < velChebMaxit_; ++it) {
1742 if (useRes && (it == 0 || (it + 1) % 4 == 0 || it + 1 == velChebMaxit_)) {
1749 const bool floor = r <= 1e-14 * scale;
1751 if (r <= vtol * scale || floor) {
1752 lastMomentumResid_ = std::max(lastMomentumResid_, scale > 0 ? r / scale : 0.0);
1757 double alpha = 0.0, beta = 0.0;
1758 cb.
next(it, alpha, beta);
1762 lastMomentumSweeps_ += used;
1765template <
class Gr
id>
1767 if constexpr (Grid::collocated) {
1775 FPC(C[c].AE),
FPC(C[c].AS),
FPC(C[c].AN),
FPC(C[c].AB),
1776 FPC(C[c].AT),
CCConst(C[c].mask), e_, og_,
G, col);
1780 FPC(C[c].AW),
FPC(C[c].AE),
FPC(C[c].AS),
1781 FPC(C[c].AN),
FPC(C[c].AB),
FPC(C[c].AT),
1782 CCConst(C[c].mask), e_, og_,
G, col);
1793 const Off3 off = Grid::offset(c);
1794 ibmVolfrac(vmgTheta_,
CCConst(sdf_), e_, off, u_.aniso, u_.hp[0], u_.hp[1], u_.hp[2], u_.w[0],
1797 vmg_.setFineStencil(
FPC(C[c].
AC),
FPC(C[c].AW),
FPC(C[c].AE),
FPC(C[c].AS),
FPC(C[c].AN),
1798 FPC(C[c].AB),
FPC(C[c].AT));
1807 lastMomentumSweeps_ += vmg_.solve(
CCConst(C[c].b), C[c].u, vmgVcycles_, 2, 2, 8, velTol_,
1809 lastMomentumResid_ = std::max(lastMomentumResid_, vmg_.lastResidualRatio());
1823 FPC(C[c].AE),
FPC(C[c].AS),
FPC(C[c].AN),
FPC(C[c].AB),
1824 FPC(C[c].AT),
CCConst(C[c].mask), e_, og_,
G, col);
1828 FPC(C[c].AE),
FPC(C[c].AS),
FPC(C[c].AN),
1839 vmg_.setDomainBcOp(c, mu_, rho_ / dt_);
1847 lastMomentumSweeps_ += vmg_.solve(
CCConst(C[c].b), C[c].u, vmgVcycles_, 2, 2, 8, velTol_,
1849 lastMomentumResid_ = std::max(lastMomentumResid_, vmg_.lastResidualRatio());
1856 const I3 e{e_.x, e_.y, e_.z}, og{og_.x, og_.y, og_.z};
1859 const double bx = mu_ * u_.w[0], by = mu_ * u_.w[1], bz = mu_ * u_.w[2];
1860 const double Ac = rho_ / dt_ + 2.0 * ((bx + by) + bz);
1861 const bool an = u_.aniso;
1864 diffSmoothColor(C[c].u,
CCConst(C[c].b), e, og,
G, bx, by, bz, Ac, col,
1868 return diffSmoothColorDu(C[c].u,
CCConst(C[c].b), e, og,
G, bx, by, bz, Ac, col,
1874 if (useVelocityCheb_) {
1882 if (useVelocityMg_) {
1884 vmg_.setFineStencil(
FPC(C[c].
AC),
FPC(C[c].AW),
FPC(C[c].AE),
FPC(C[c].AS),
FPC(C[c].AN),
1885 FPC(C[c].AB),
FPC(C[c].AT));
1890 vmg_.buildUpwindCoarse(c, mu_, rho_ / dt_, rho_);
1896 ibmVolfrac(vmgTheta_,
CCConst(sdf_), e_, off, u_.aniso, u_.hp[0], u_.hp[1], u_.hp[2], u_.w[0],
1902 lastMomentumSweeps_ += vmg_.solve(
CCConst(C[c].b), C[c].u, vmgVcycles_, 2, 2, 8, velTol_,
1904 lastMomentumResid_ = std::max(lastMomentumResid_, vmg_.lastResidualRatio());
1910#ifdef PECLET_FLOW_MPI
1911 if (distributed_ && caMomentum_) {
1928 if (momStencilDirty_[c] || perStepStencil) {
1929 for (
FV* a : {&C[c].AC, &C[c].AW, &C[c].AE, &C[c].AS, &C[c].AN, &C[c].AB, &C[c].AT})
1930 velDevF_->exchange(*a);
1931 velDev_->exchange(C[c].mask);
1932 momStencilDirty_[c] =
false;
1934 velDev_->exchange(C[c].b);
1935 const C3 lo{
G + 1,
G + 1,
G + 1}, hi{e_.x -
G - 1, e_.y -
G - 1, e_.z -
G - 1};
1936 const C3 rlo{
G - 1,
G - 1,
G - 1}, rhi{e_.x -
G + 1, e_.y -
G + 1, e_.z -
G + 1};
1937 const C3 z0{0, 0, 0};
1942 velDev_->exchangeBegin(C[c].u);
1944 FPC(C[c].AE),
FPC(C[c].AS),
FPC(C[c].AN),
FPC(C[c].AB),
1945 FPC(C[c].AT),
CCConst(C[c].mask), e_, og_, col, lo, hi, z0, z0);
1946 velDev_->exchangeEnd(C[c].u);
1948 FPC(C[c].AE),
FPC(C[c].AS),
FPC(C[c].AN),
FPC(C[c].AB),
1949 FPC(C[c].AT),
CCConst(C[c].mask), e_, og_, col, rlo, rhi, lo,
1953 FPC(C[c].AS),
FPC(C[c].AN),
FPC(C[c].AB),
FPC(C[c].AT),
1954 CCConst(C[c].mask), e_, og_,
G, col);
1959 FPC(C[c].AE),
FPC(C[c].AS),
FPC(C[c].AN),
FPC(C[c].AB),
1960 FPC(C[c].AT),
CCConst(C[c].mask), e_, og_,
G, col);
1975 const C3 ilo{
G,
G,
G}, ihi{e_.x -
G, e_.y -
G, e_.z -
G};
1976 const C3 lo{
G + 1,
G + 1,
G + 1}, hi{e_.x -
G - 1, e_.y -
G - 1, e_.z -
G - 1};
1977 const C3 z0{0, 0, 0};
1981 velDev_->exchangeBegin(C[c].u);
1983 FPC(C[c].AS),
FPC(C[c].AN),
FPC(C[c].AB),
FPC(C[c].AT),
1984 CCConst(C[c].mask), e_, og_, col, lo, hi, z0, z0);
1985 velDev_->exchangeEnd(C[c].u);
1987 FPC(C[c].AS),
FPC(C[c].AN),
FPC(C[c].AB),
FPC(C[c].AT),
1988 CCConst(C[c].mask), e_, og_, col, ilo, ihi, lo, hi);
1991 velDev_->exchangeBegin(C[c].u);
1994 FPC(C[c].AN),
FPC(C[c].AB),
FPC(C[c].AT),
CCConst(C[c].mask), e_, og_, col, lo, hi,
1996 velDev_->exchangeEnd(C[c].u);
1999 FPC(C[c].AN),
FPC(C[c].AB),
FPC(C[c].AT),
CCConst(C[c].mask), e_, og_, col, ilo, ihi,
2001 return di > ds ? di : ds;
2010 FPC(C[c].AE),
FPC(C[c].AS),
FPC(C[c].AN),
FPC(C[c].AB),
2011 FPC(C[c].AT),
CCConst(C[c].mask), e_, og_,
G, col);
2015 FPC(C[c].AE),
FPC(C[c].AS),
FPC(C[c].AN),
2022template <
class Gr
id>
2025 CCField u = C[c].u, m = C[c].mask;
2026 Kokkos::parallel_for(
2027 "vmask", Kokkos::RangePolicy<CCExec>(space, 0, n_), KOKKOS_LAMBDA(std::size_t i) {
2033template <
class Gr
id>
2039 Kokkos::parallel_reduce(
2041 KOKKOS_LAMBDA(
int x,
int y,
int z,
double& acc) {
2042 const long i = (long)x + (
long)y * e.x + (long)z * (
long)e.x * e.y;
2046 Kokkos::Min<double>(m));
2047#ifdef PECLET_FLOW_MPI
2050 MPI_Allreduce(&m, &g, 1, MPI_DOUBLE, MPI_MIN, comm_);
2057template <
class Gr
id>
2062 Kokkos::parallel_reduce(
2064 KOKKOS_LAMBDA(
int x,
int y,
int z,
double& acc) {
2065 const long i = (long)x + (
long)y * e.x + (long)z * (
long)e.x * e.y;
2066 const double a = Kokkos::fabs(f(i));
2070 Kokkos::Max<double>(m));
2074template <
class Gr
id>
2076 auto h = Kokkos::create_mirror_view(fld);
2077 Kokkos::deep_copy(h, fld);
2078 std::vector<double> out((std::size_t)nx_ * ny_ * nz_);
2079 for (
int z = 0; z < nz_; ++z)
2080 for (
int y = 0; y < ny_; ++y)
2081 for (
int x = 0; x < nx_; ++x)
2082 out[(std::size_t)x + (std::size_t)y * nx_ + (std::size_t)z * (std::size_t)nx_ * ny_] =
2083 h((
long)(x +
G) + (
long)(y +
G) * e_.x + (
long)(z +
G) * (
long)e_.x * e_.y);
2087template <
class Gr
id>
2089 if (in.size() != (std::size_t)nx_ * ny_ * nz_)
2090 throw std::runtime_error(
"flow::setField: array size does not match the inner grid");
2091 auto h = Kokkos::create_mirror_view(fld);
2092 Kokkos::deep_copy(h, fld);
2093 for (
int z = 0; z < nz_; ++z)
2094 for (
int y = 0; y < ny_; ++y)
2095 for (
int x = 0; x < nx_; ++x)
2096 h((
long)(x +
G) + (
long)(y +
G) * e_.x + (
long)(z +
G) * (
long)e_.x * e_.y) =
2097 in[(std::size_t)x + (std::size_t)y * nx_ + (std::size_t)z * (std::size_t)nx_ * ny_];
2098 Kokkos::deep_copy(fld, h);
2101template <
class Gr
id>
2103 if (fields_.has(name))
2104 return fields_.at(name).data;
2105 return fields_.add(name, n_,
G, peclet::core::Centering::Cell).data;
2108template <
class Gr
id>
2110 return fields_.has(name);
2113template <
class Gr
id>
2115 return fields_.at(name).data;
2118template <
class Gr
id>
2120 return fields_.names();
2123template <
class Gr
id>
2128template <
class Gr
id>
2130#ifdef PECLET_FLOW_MPI
2131 if (distributed_ && velHalo_) {
2132 CCField f = fields_.at(name).data;
2133 auto h = Kokkos::create_mirror_view(f);
2134 Kokkos::deep_copy(h, f);
2135 peclet::core::halo::GridFieldView<double> view{h.data()};
2136 velHalo_->reverseAdd(view);
2137 Kokkos::deep_copy(f, h);
2144template <
class Gr
id>
2149template <
class Gr
id>
2152 if (name ==
"u" || name ==
"v" || name ==
"w" || name ==
"p" || name ==
"phi")
2158 else if (name ==
"p_balanced")
2162template <
class Gr
id>
2164 return {e_.x, e_.y, e_.z};
2167template <
class Gr
id>
2172template <
class Gr
id>
2174#ifdef PECLET_FLOW_MPI
2176 return {gnx_, gny_, gnz_};
2178 return {nx_, ny_, nz_};
2181template <
class Gr
id>
2183 return {og_.x, og_.y, og_.z};
2186template <
class Gr
id>
2188 rhoFaceHarmonic_ = on;
2189 bfpChebSet_ =
false;
2192template <
class Gr
id>
2194 exactResidual_ = on;
2195 mg_.setExactResidual(on);
2198template <
class Gr
id>
2200 outflowOpCoeff_ = on;
2203template <
class Gr
id>
2205 return outflowOpCoeff_;
2208template <
class Gr
id>
2210 return exactResidual_;
2213template <
class Gr
id>
2215 return rhoFaceHarmonic_;
2218template <
class Gr
id>
2220 outflowRhoCorr_ = on;
2223template <
class Gr
id>
2225 return outflowRhoCorr_;
2228template <
class Gr
id>
2229CCField Solver<Grid>::ensureTarget(
const std::string& name) {
2230 if (name ==
"force_x" || name ==
"force_y" || name ==
"force_z")
2231 ensureCellForceAll();
2232 return addField(name);
2235template <
class Gr
id>
2236void Solver<Grid>::ensureCellForceAll() {
2237 static const char* fn[3] = {
"force_x",
"force_y",
"force_z"};
2238 for (
int c = 0; c < 3; ++c)
2239 cellForce_[c] = addField(fn[c]);
2240 hasCellForce_ =
true;
int pressureBottomExtent() const
void setPressureLineRelaxation(bool enabled)
void setPressureMeanRemoval(bool all)
double multigridAspectThreshold() const
bool pressureVcycleFp32() const
std::array< int, 3 > globalResolution() const
void setPhysicalDomain(const std::array< double, 3 > &extent, const std::array< double, 3 > &origin, const std::array< long, 3 > &globalCells)
Arm the physical domain.
void fillVelGhosts(int comp, int fold)
void setIncrementalPressure(bool on)
std::function< double()> constCoeffResidual(int c, double bx, double by, double bz, double Ac)
void setVelocityTolerance(double rtol, int minIters)
double stencilBnorm(int c)
bool pressureCoarseGhost() const
void scatterInner(CCField fld, const std::vector< double > &in)
bool advectsMomentum() const
void buildOpenFaceField()
Build ufOpen_ = the face field with each open (outflow) domain face overwritten by its zero-gradient ...
void fillGhosts(CCField f)
long lastOuterIterations() const
long pressurePrefactorCount() const
double decompositionMaxImbalance() const
void fillDomainPeriodic(CCField f)
void setPressureCoarseGhost(bool on)
Neumann (zero-gradient) coarse ghost on wall/inflow faces before the pressure MG's prolongation — the...
bool advWallInputs() const
R0 helper: allocate (once) and arm the per-component advective-term stash the reaction-force budget c...
void setUfAdvection(bool on)
Advect the collocated momentum with the PROJECTED, divergence-free MAC face field uf_/vf_/wf_ (DEFAUL...
void fillPropGhosts(CCField f, bool edges=false)
void seedFaceFieldFromCells()
void setFaceInterp(int mode)
std::vector< double > getField(const std::string &name)
void setOutflowRhoCorrection(bool on)
void setVelocityChebyshev(bool on, int maxit=400)
void setOpennessOverride(const std::vector< double > &ox, const std::vector< double > &oy, const std::vector< double > &oz)
void setOuterTolerance(double tol)
CCField addField(const std::string &name)
double lastMomentumResidual() const
std::array< double, 3 > domainOrigin() const
Physical lower corner of the GLOBAL inner grid.
void setPressureGraphAmg(bool on)
VelocityMG::Comm vmgComm() const
double velocityResidualTolerance() const
void setVelocitySolverAuto()
void setPressureTelescope(bool on)
void setPressureStrict(bool on)
Throw instead of reporting when the pressure preconditioner returns a non-finite correction (ISSUES s...
void fillGhostsFaces(CCField f)
bool advectionWallVelocity() const
void exchangeFieldAdd(const std::string &name)
CCConst advVelView(int c) const
The velocity view the advection operators must read for component c: the wall-corrected scratch while...
void exchangeField(const std::string &name)
void setAdvection(bool on)
std::array< long, 3 > globalCells() const
The GLOBAL cell counts (this rank's block single-rank).
void setPressureExactResidual(bool on)
WO-R2 item 3 — the exact (matrix-free, double, flux-form) level-0 operator apply in the residual and ...
void uploadVelocity(const std::vector< double > &uu, const std::vector< double > &vv, const std::vector< double > &ww)
Upload an initial velocity field in the caller's PHYSICAL units (converted per component to the index...
bool outflowRhoCorrection() const
void copyInner(CCField dst, C3 de, int dg, CCConst src, C3 se, int sg)
void requireNoGeometry(const char *who) const
void applyVelocityBcCompTo(CCField f, int comp, int fold, bool doOutflow)
void setPressureVcycleSymmetric(bool enabled)
double maxAbsDiffInner(CCConst a, CCConst b)
void fillPeriodicAxes(CCField f, int axes)
void requireIsotropic(const char *what) const
Phase 2 §7 — refuse an ANISOTROPIC domain in a consumer this phase does not carry.
void setBackflowStab(double beta)
std::array< double, 3 > spacing() const
Cell size per axis (equal on every axis unless the Phase 2 anisotropic path is armed – see unitScales...
bool velocityChebyshevActive() const
void setVelocityIterations(int it)
double finishResidual(int c)
bool ufAdvVelocity() const
Are the advection operators reading the projected face field this step?
void setPressureChebyshev(bool on, int maxit, double rtol)
const UnitScales & unitScales() const
bool rhoFaceHarmonic() const
CCConst openFaceView(int c) const
Component c of the face field AS THE ADVECTION AND THE DIVERGENCE DIAGNOSTIC MUST READ IT: advFaceVie...
bool pressureStrict() const
Solver(int nx, int ny, int nz)
void setPressureInitialGuess(int mode, int history)
void addDragDiagonal(int c)
void setGhostProjection(bool on, int matrixOrder=2, int rhsOrder=2)
CCConst advFaceView(int c) const
Component c of the collocated MAC face field (uf_/vf_/wf_), flow's low-face convention: entry i is th...
int apertureOrder() const
long lastMomentumSweeps() const
void setPressureLevels(int levels)
std::array< int, 3 > blockOrigin() const
void setFluidOnlyConstraint(int mode)
void setRotationalPressure(bool on)
void setDeferredCorrection(bool on)
void resampleBcProfile(int face)
void setPressureVcyclePrecision(int mode)
int pressureGuessCount() const
SceneMap sceneMap() const
void setCommAvoiding(int mask)
Communication-avoiding red-black smoothing: kCaMomentum | kCaMg.
void fillAxis(CCField f, int axis)
void setAdvectionWallVelocity(bool on)
A0 — wall velocity (not zeros) in the advection inputs' masked rows. DEFAULT true.
void setField(const std::string &name, const std::vector< double > &v)
void setApertureOrder(int order)
double lastSuperficialVelocityShift() const
The shift the last step() applied (caller's velocity units; 0 when off).
void setBodyForce(double fx, double fy, double fz)
Body force per unit volume, in the caller's units (e.g. a mean pressure gradient, or rho*g).
void closureRefreshUnits(Closure &cl)
Re-derive a closure's internal p / tabY from its physical pPhys / tabYPhys with the current reference...
void chebSolveComp(int c)
std::array< int, 3 > blockShape() const
void setRhoFaceHarmonic(bool on)
bool pressureExactResidual() const
long strideOf(int c) const
void fillVelGhostsTo(CCField f, int comp, int fold, bool doOutflow=true, bool faceEdges=false)
bool hasField(const std::string &name) const
void debugSetPressureFp32Fault(int kind, int at)
void setAdvectionScheme(int s)
void throwVelocityMgVariableMu(const char *who) const
int pressureTelescopeCount() const
void setPressurePcg(bool on, int maxit, double rtol)
void setVelocityMultigridAuto(long cellsPerRank, long minGlobalCells=-1, int minBlockExtent=-1)
void allocateBlock(int nx, int ny, int nz)
const char * projectedGuessIneligible() const
int pressureVcycleRestarts() const
void setVelocityMultigrid(bool on, int levels, int vcycles)
void setRotationalWeight(double w)
void setMu(double m)
Dynamic viscosity, in the caller's units.
void setDecomposition(int levels, double maxImbalance=1.05)
How the shared level-0 MPI decomposition is built.
void setExactCrossings(const std::vector< double > &t)
void setPressureWarmstart(bool on)
void velSweepLoop(Fill &&fill, Color &&sweepColor, ColorDu &&sweepColorDu, std::function< double()> resid=nullptr, double bnorm=0.0)
void setPressureIterations(int it)
Kokkos::View< MReal *, CCMem > FV
bool velocityMgChebyshev() const
int heldResidualPlane(int c) const
void refreshUnitDerived()
Re-derive every internal (index-unit) quantity from the stored physical inputs.
void setPressureBottomSolver(int engine)
void buildAdvStencil(int c)
void setPressureTelescopeForceLevel(int level)
CCField fieldView(const std::string &name)
void pushVofMetric()
Hand the anisotropic cell metric to every VoF driver that exists (Phase 3).
void setCollocatedScheme(const std::string &name)
void setVelocityMgChebyshev(bool on, int degree=0, double eig_ratio=10.0)
void setPressureBottomExtent(int cells)
The set_pressure_bottom("auto") criterion: agglomerate once the coarsest GLOBAL grid exceeds this man...
void buildAdvStencilVar(int c)
bool ensureAdvStash(int c, bool adv)
bool bcStencilPath() const
void setOutflowOperatorCoefficient(bool on)
WO-R2 item 1 ABLATION: set_outflow_operator_coefficient(False) restores the pre-WO-R2 operator,...
void setImplicitAdvection(bool on)
void setVelocityResidualTolerance(double rtol)
vof::SharpFaceProps makeSharpFaceProps(int c, vof::SvRole role)
std::function< double()> stencilResidual(int c, bool exchange=false)
bool mixedVelocityMg() const
void setPressureBottomMode(int mode)
VarFaceProps makeFaceProps(int c)
void setRotationalWallWeight(double w0)
bool pressureTelescope() const
double reduceMaxAbsInner(CCConst f)
void setRho(double r)
Fluid density, in the caller's units.
void setRotationalFilter(bool on, double eps=0.05)
bool velocityMultigridActive() const
std::array< double, 3 > domainExtent() const
Physical extent of the GLOBAL inner grid (cell counts without a physical domain).
std::vector< std::string > fieldNames() const
std::vector< double > gatherInner(CCField fld)
void setSuperficialVelocity(bool on, int axis, double velocity)
Hold the SUPERFICIAL velocity along a periodic axis: at the end of every step() one uniform shift is ...
std::vector< double > cellCentres(int axis) const
Physical cell-centre coordinates of THIS rank's inner block along axis (nx/ny/nz values).
void copyBlockShifted(CCField dst, C3 de, CCConst src, C3 se, int off)
void pcRefreshUnits()
Re-derive the INTERNAL phase-change constants (pcRhoG_ ... pcRcpL_) from the caller's physical ones (...
int decompositionLevels() const
CCConst wallVelView(int c) const
bool outflowOperatorCoefficient() const
void setPressureFcg(bool on, int maxit, double rtol)
void setMultigridAspectThreshold(double theta)
The anisotropic-coarsening aspect threshold theta shared by the pressure and velocity multigrids (doc...
void setOuterIterations(int iters)
bool hasPhysicalDomain() const
void zeroPlane(CCField m, C3 e, int axis, int idx)
Kokkos::DefaultExecutionSpace CCExec
void residualVarPinMax(CCConst x, CCConst b, FPC AC, FPC AW, FPC AE, FPC AS, FPC AN, FPC AB, FPC AT, CCConst pin, C3 e, int g, int holdAxis, int holdIdx, double &rmax, double &bdmax, double &bmax)
Kokkos::MDRangePolicy< Exec, Kokkos::Rank< 3, Kokkos::Iterate::Left, Kokkos::Iterate::Left > > MDRange3
3-D range, x (the first index) fastest (both the tile order and the order within a tile).
void ibmChebUpdate(CCField x, CCField d, CCConst r, FPC AC, CCConst solidmask, C3 e, int g, double alpha, double beta)
One Chebyshev update on the Jacobi-preconditioned system: d <- beta*d + alpha*r/AC ; x += d.
void ibmCleanFluidMask(CCField m, CCConst sdf, C3 ext, Off3 off)
Kokkos::View< const double *, CCMem > CCConst
void ibmStencilJacobiBounds(MC AC, MC AW, MC AE, MC AS, MC AN, MC AB, MC AT, CCConst solidmask, C3 e, int g, double &lo, double &hi)
Gershgorin bounds [lo, hi] on the spectrum of the Jacobi-preconditioned cut-cell Helmholtz diag(AC)^-...
void ibmBuildDiffusionVar(MV AC, MV AW, MV AE, MV AS, MV AN, MV AB, MV AT, int ex, int ey, int ez, int g, FaceProps fp, double wx=1.0, double wy=1.0, double wz=1.0)
void ibmModifyStencil(MV AC, MV AW, MV AE, MV AS, MV AN, MV AB, MV AT, Kokkos::View< double *, IMem > a_inhom, Kokkos::View< double *, IMem > rhs_scale, const OV &ibm, int numActive, typename OV::value_type u_bc_val, Kokkos::View< const double *, IMem > u_bc=Kokkos::View< const double *, IMem >())
void ibmVolfrac(CCField theta, CCConst sdf, C3 ext, Off3 off, bool aniso=false, double hpx=1.0, double hpy=1.0, double hpz=1.0, double wx=1.0, double wy=1.0, double wz=1.0)
void residualVarPin(CCField r, CCConst x, CCConst b, FPC AC, FPC AW, FPC AE, FPC AS, FPC AN, FPC AB, FPC AT, CCConst pin, C3 e, int g)
double diffSmoothColorDu(SField c, SConst b, I3 e, I3 og, int g, double bx, double by, double bz, double Ac, int color, SConst dcorr, bool aniso)
Kokkos::View< const MReal *, CCMem > FPC
void centerToFaceWallAware(CCField uf, CCField vf, CCField wf, CCConst U, CCConst V, CCConst W, CCConst sdf, CCConst xcx, CCConst xcy, CCConst xcz, bool useCen, C3 e, int g)
double maxAbsInner(CCConst a, C3 e, int g)
Kokkos::View< double *, CCMem > CCField
void ccFor3(const char *name, C3 lo, C3 hi, F f)
void centerToFace(CCField uf, CCField vf, CCField wf, CCConst U, CCConst V, CCConst W, C3 e, int g)
IbmOverlayT< IMem, mreal > IbmOverlay
double maxAbsDiffInner(CCConst a, CCConst b, C3 e, int g)
void ibmRbgsStencilColorBox(CCField x, CCConst b, MC AC, MC AW, MC AE, MC AS, MC AN, MC AB, MC AT, CCConst solidmask, C3 ext, C3 og, int color, C3 rlo, C3 rhi, C3 slo, C3 shi)
double ibmRbgsStencilColorDuBox(CCField x, CCConst b, MC AC, MC AW, MC AE, MC AS, MC AN, MC AB, MC AT, CCConst solidmask, C3 ext, C3 og, int color, C3 rlo, C3 rhi, C3 slo, C3 shi)
void ibmBuildDiffusion(MV AC, MV AW, MV AE, MV AS, MV AN, MV AB, MV AT, int ex, int ey, int ez, double bx, double by, double bz, double idiag)
double ibmRbgsStencilColorDu(CCField x, CCConst b, MC AC, MC AW, MC AE, MC AS, MC AN, MC AB, MC AT, CCConst solidmask, C3 ext, C3 og, int g, int color)
bool hostRunSerial(long cells)
void bcNeumannGhost(BField f, B3 ext, int g, int a, int s)
void ibmRbgsStencilColor(CCField x, CCConst b, MC AC, MC AW, MC AE, MC AS, MC AN, MC AB, MC AT, CCConst solidmask, C3 ext, C3 og, int g, int color)
void diffResidualMax(SConst c, SConst b, I3 e, int g, double bx, double by, double bz, double Ac, SConst dcorr, bool aniso, int holdAxis, int holdIdx, double &rmax, double &bdmax, double &bmax)
Kokkos::MDRangePolicy< Exec, Kokkos::Rank< 2, Kokkos::Iterate::Left, Kokkos::Iterate::Left > > MDRange2
2-D range, first index fastest (both the tile order and the order within a tile).
void diffSmoothColor(SField c, SConst b, I3 e, I3 og, int g, double bx, double by, double bz, double Ac, int color, SConst dcorr, bool aniso)
The Chebyshev coefficient recurrence (Golub-Varga; the form multigrid Chebyshev smoothers use).
void next(int it, double &alpha, double &beta)
Coefficients for iteration it (0-based). Advances the recurrence.
The map between the solver's INDEX coordinates and the coordinate system the analytic scene is writte...
static constexpr double AC
Kokkos::View< float *, IMem > FV
static constexpr double U