flow 1.3.0
Kokkos cut-cell IBM incompressible Navier-Stokes solver + pnm pore extraction
Loading...
Searching...
No Matches
mac_cheb_momentum.hpp
Go to the documentation of this file.
1
24#ifndef PECLET_FLOW_MAC_CHEB_MOMENTUM_HPP
25#define PECLET_FLOW_MAC_CHEB_MOMENTUM_HPP
26
27#include <Kokkos_Core.hpp>
28
29#include "mac_cutcell_mg.hpp" // FPC
30#include "mac_ibm.hpp" // CCField/CCConst/CCExec/C3
31#include "policy.hpp"
32
33namespace peclet::flow {
34
40template <class MC>
41inline void ibmStencilJacobiBounds(MC AC, MC AW, MC AE, MC AS, MC AN, MC AB, MC AT,
42 CCConst solidmask, C3 e, int g, double& lo, double& hi) {
44 const bool hasMask = (solidmask.extent(0) != 0);
45 using MD = MDRange3<CCExec>;
46 const MD pol(space, {g, g, g}, {e.x - g, e.y - g, e.z - g});
47 double rlo = 0.0, rhi = 0.0;
48 Kokkos::parallel_reduce(
49 "peclet::flow::cheb_bounds_lo", pol,
50 KOKKOS_LAMBDA(int lx, int ly, int lz, double& m) {
51 const long i = (long)lx + (long)ly * e.x + (long)lz * (long)e.x * e.y;
52 if (hasMask && solidmask(i) > 0.5)
53 return;
54 const double ac = (double)AC(i);
55 if (Kokkos::fabs(ac) < 1e-30)
56 return;
57 const double off = (double)AW(i) + (double)AE(i) + (double)AS(i) + (double)AN(i) +
58 (double)AB(i) + (double)AT(i);
59 const double v = (ac + off) / ac; // row sum / diagonal
60 if (v < m)
61 m = v;
62 },
63 Kokkos::Min<double>(rlo));
64 Kokkos::parallel_reduce(
65 "peclet::flow::cheb_bounds_hi", pol,
66 KOKKOS_LAMBDA(int lx, int ly, int lz, double& m) {
67 const long i = (long)lx + (long)ly * e.x + (long)lz * (long)e.x * e.y;
68 if (hasMask && solidmask(i) > 0.5)
69 return;
70 const double ac = (double)AC(i);
71 if (Kokkos::fabs(ac) < 1e-30)
72 return;
73 const double off = (double)AW(i) + (double)AE(i) + (double)AS(i) + (double)AN(i) +
74 (double)AB(i) + (double)AT(i);
75 const double v = (ac - off) / ac;
76 if (v > m)
77 m = v;
78 },
79 Kokkos::Max<double>(rhi));
80 lo = rlo;
81 hi = rhi;
82}
83
88inline void ibmChebUpdate(CCField x, CCField d, CCConst r, FPC AC, CCConst solidmask, C3 e, int g,
89 double alpha, double beta) {
91 const bool hasMask = (solidmask.extent(0) != 0);
92 using MD = MDRange3<CCExec>;
93 Kokkos::parallel_for(
94 "peclet::flow::cheb_update", MD(space, {g, g, g}, {e.x - g, e.y - g, e.z - g}),
95 KOKKOS_LAMBDA(int lx, int ly, int lz) {
96 const long i = (long)lx + (long)ly * e.x + (long)lz * (long)e.x * e.y;
97 if (hasMask && solidmask(i) > 0.5) {
98 d(i) = 0.0;
99 x(i) = 0.0;
100 return;
101 }
102 const double ac = (double)AC(i);
103 if (Kokkos::fabs(ac) < 1e-30)
104 return;
105 const double dn = beta * d(i) + alpha * r(i) / ac;
106 d(i) = dn;
107 x(i) += dn;
108 });
109}
110
116 double theta, delta, sigma, rho;
117 ChebCoeffs(double lo, double hi)
118 : theta(0.5 * (hi + lo)), delta(0.5 * (hi - lo)), sigma(theta / delta), rho(1.0 / sigma) {}
120 void next(int it, double& alpha, double& beta) {
121 if (it == 0) {
122 alpha = 1.0 / theta;
123 beta = 0.0;
124 return;
125 }
126 const double rPrev = rho;
127 rho = 1.0 / (2.0 * sigma - rPrev);
128 alpha = 2.0 * rho / delta;
129 beta = rho * rPrev;
130 }
131};
132
133} // namespace peclet::flow
134
135#endif // PECLET_FLOW_MAC_CHEB_MOMENTUM_HPP
flow — portable (Kokkos) geometric multigrid for the cut-cell (variable-openness) pressure Poisson.
flow — portable (Kokkos) IBM geometric fields + variable-coefficient RB-GS smoother.
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.
Kokkos::View< const MReal *, CCMem > FPC
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)^-...
Kokkos::View< double *, CCMem > CCField
Kokkos::DefaultExecutionSpace CCExec
Kokkos::View< const double *, CCMem > CCConst
flow — the multidimensional iteration policies: iteration order follows storage.
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.
ChebCoeffs(double lo, double hi)
static constexpr double AC