37KOKKOS_INLINE_FUNCTION
void lineAxesOf(
int s,
int& a,
int& b) {
46 static constexpr double kEps = 64.0 * std::numeric_limits<double>::epsilon();
52 KOKKOS_INLINE_FUNCTION
const OpV&
afs()
const {
return s == 0 ?
AFX : (
s == 1 ?
AFY :
AFZ); }
54 KOKKOS_INLINE_FUNCTION
bool coef(
long i,
double& d,
double& l,
double& u)
const {
55 const double ac =
AC(i);
67 KOKKOS_INLINE_FUNCTION
double res(
long i,
const CcNbrs& w)
const {
68 return b(i) -
cutcellApplyFaceCell(
x,
AC,
AFX,
AFY,
AFZ, i,
sx,
sy,
sz, w.xp, w.xm, w.yp, w.ym,
76 static constexpr VReal kEps = 64.0f * std::numeric_limits<VReal>::epsilon();
81 KOKKOS_INLINE_FUNCTION
const VConst&
ws()
const {
return s == 0 ?
WX : (
s == 1 ?
WY :
WZ); }
96 return b(i) -
fp32Flux(
x,
WX,
WY,
WZ, i,
sx,
sy,
sz, w.xp, w.xm, w.yp, w.ym, w.zp, w.zm);
108 KOKKOS_INLINE_FUNCTION
typename SV::reference_type
c(
int k)
const {
return cv(
i0 + (
long)k *
t); }
109 KOKKOS_INLINE_FUNCTION
typename SV::reference_type
y(
int k)
const {
return yv(
i0 + (
long)k *
t); }
110 KOKKOS_INLINE_FUNCTION
typename SV::reference_type
z(
int k)
const {
return zv(
i0 + (
long)k *
t); }
115 KOKKOS_INLINE_FUNCTION Real&
c(
int k) {
return cv[k]; }
116 KOKKOS_INLINE_FUNCTION Real&
y(
int k) {
return yv[k]; }
117 KOKKOS_INLINE_FUNCTION Real&
z(
int k) {
return zv[k]; }
122template <
class Row,
class Store>
124 int g,
int wrapMask,
bool periodic) {
125 using Real =
typename Row::Real;
126 const Real eps = Row::kEps;
130 Real alpha = Real(0), beta = Real(0);
136 R.coef(i0 + (
long)(m - 1) * t, d, l, u);
138 sm = !(alpha == Real(0) && beta == Real(0));
140 Real gamma = Real(0);
141 Real cPrev = Real(0), yPrev = Real(0), zPrev = Real(0);
142 for (
int k = 0; k < m; ++k) {
143 const long i = i0 + (long)k * t;
147 if (
R.coef(i, d, l, u)) {
164 dp = d - alpha * beta / gamma;
166 const Real zr = !sm ? Real(0) : (k == 0 ? gamma : (k == m - 1 ? alpha : Real(0)));
176 yk = (r - l * yPrev) / p;
177 zk = (zr - l * zPrev) / p;
179 const Real ck = u / p;
188 for (
int k = m - 2; k >= 0; --k) {
189 S.y(k) -= S.c(k) * S.y(k + 1);
191 S.z(k) -= S.c(k) * S.z(k + 1);
195 const Real den = Real(1) + S.z(0) + beta * S.z(m - 1) / gamma;
196 if (!(Kokkos::fabs(den) < eps))
197 f = (S.y(0) + beta * S.y(m - 1) / gamma) / den;
199 for (
int k = 0; k < m; ++k) {
200 const long i = i0 + (long)k * t;
202 R.x(i) =
R.x(i) + (S.y(k) - f * S.z(k));
204 R.x(i) =
R.x(i) + S.y(k);
209template <
class Row,
class SV>
210KOKKOS_INLINE_FUNCTION
void lineColumn(
const Row&
R,
const SV& c,
const SV& y,
const SV& z,
int la,
211 int lb,
C3 n,
int g,
int wrapMask,
bool periodic) {
212 using Real =
typename Row::Real;
215 const int m =
R.s == 0 ? n.x : (
R.s == 1 ? n.y : n.z);
220 const long i0 = (long)
l3[0] + (
long)
l3[1] *
R.sy + (long)
l3[2] *
R.sz;
231template <
class Row,
class SV>
233 int wrapMask,
bool periodic,
int color,
const char* name,
234 const char* serialName) {
235 const C3 n{e.x - 2 * g, e.y - 2 * g, e.z - 2 * g};
238 const int ea = a == 0 ? e.x : e.y, eb = b == 1 ? e.y : e.z;
239 const int oga = a == 0 ? og.x : og.y, ogb = b == 1 ? og.y : og.z;
241 if constexpr (std::is_same_v<typename CCExec::memory_space, Kokkos::HostSpace>) {
242 const int nb = eb - 2 * g;
243 const long cells = (long)n.x * n.y * n.z;
244 auto row = KOKKOS_LAMBDA(
long q) {
245 const int lb = g + (int)q;
246 const int P = (color + oga + ogb + lb) & 1;
247 for (
int la = g + ((P ^ (g & 1)) & 1); la < ea - g; la += 2)
248 lineColumn(
R, c, y, z, la, lb, n, g, wrapMask, periodic);
252 for (
long q = 0; q < (long)nb; ++q)
256 Kokkos::parallel_for(name, Kokkos::RangePolicy<CCExec>(space, 0, (
long)nb), row);
259 Kokkos::parallel_for(
260 name,
MDRange2<CCExec>(space, {g, g}, {ea - g, eb - g}), KOKKOS_LAMBDA(
int la,
int lb) {
261 if (((oga + la + ogb + lb) & 1) != color)
263 lineColumn(
R, c, y, z, la, lb, n, g, wrapMask, periodic);
271 int wrapMask,
int color) {
272 const long sx = 1, sy = e.x, sz = (long)e.x * e.y;
273 const long t = s == 0 ? sx : (s == 1 ? sy : sz);
274 const LineRowFp64<OpV> R{x, b,
AC, AFX, AFY, AFZ, sx, sy, sz, t, s};
275 lineRelaxColor(
R, c, y, z, e, og, g, wrapMask, periodic, color,
"peclet::flow::cc_line_smooth",
276 "peclet::flow::cc_line_smooth@serial");
282 int wrapMask,
int color) {
283 const long sx = 1, sy = e.x, sz = (long)e.x * e.y;
284 const long t = s == 0 ? sx : (s == 1 ? sy : sz);
285 const LineRowFp32 R{x, b, WX, WY, WZ, sx, sy, sz, t, s};
286 lineRelaxColor(
R, c, y, z, e, og, g, wrapMask, periodic, color,
287 "peclet::flow::cc_line_smooth_f32",
"peclet::flow::cc_line_smooth_f32@serial");
Kokkos::DefaultExecutionSpace CCExec
CcNbrs ccMaskNbrs(int lx, int ly, int lz, C3 n, int g, long i, long sy, long sz, int m)
void lineColumn(const Row &R, const SV &c, const SV &y, const SV &z, int la, int lb, C3 n, int g, int wrapMask, bool periodic)
void lineRelaxColor(const Row &R, const SV &c, const SV &y, const SV &z, C3 e, C3 og, int g, int wrapMask, bool periodic, int color, const char *name, const char *serialName)
Kokkos::View< const double *, CCMem > CCConst
void lineColumnSolve(const Row &R, Store &S, long i0, int m, int l3[3], C3 n, int g, int wrapMask, bool periodic)
VReal fp32Diag(const WV &WX, const WV &WY, const WV &WZ, long i, long sx, long sy, long sz)
Kokkos::View< VReal *, CCMem > VField
VReal fp32Flux(const XV &x, const WV &WX, const WV &WY, const WV &WZ, long i, long sx, long sy, long sz, long xp, long xm, long yp, long ym, long zp, long zm)
void lineRelaxColorFace(CCField x, CCConst b, OpV AC, OpV AFX, OpV AFY, OpV AFZ, CCField c, CCField y, CCField z, C3 e, C3 og, int g, int s, bool periodic, int wrapMask, int color)
Kokkos::View< double *, CCMem > CCField
void lineRelaxColorFp32(VField x, VConst b, VConst WX, VConst WY, VConst WZ, VField c, VField y, VField z, C3 e, C3 og, int g, int s, bool periodic, int wrapMask, int color)
void lineAxesOf(int s, int &a, int &b)
bool hostRunSerial(long cells)
double cutcellApplyFaceCell(const XV &x, const OpV &AC, const OpV &AFX, const OpV &AFY, const OpV &AFZ, long i, long sx, long sy, long sz, long xp, long xm, long yp, long ym, long zp, long zm)
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).
Kokkos::View< const VReal *, CCMem > VConst
const VConst & ws() const
VReal res(long i, const CcNbrs &w) const
static constexpr VReal kEps
bool coef(long i, VReal &d, VReal &l, VReal &u) const
static constexpr double kEps
bool coef(long i, double &d, double &l, double &u) const
double res(long i, const CcNbrs &w) const
SV::reference_type y(int k) const
SV::reference_type z(int k) const
SV::reference_type c(int k) const
static constexpr double AC
Kokkos::View< double *, peclet::flow::CCMem > OpV
static long l3(int x, int y, int z, C3 e)
static constexpr double R