11#ifndef PECLET_FLOW_MAC_STENCILS_HPP
12#define PECLET_FLOW_MAC_STENCILS_HPP
14#include <Kokkos_Core.hpp>
21using SExec = Kokkos::DefaultExecutionSpace;
22using SMem = SExec::memory_space;
23using SField = Kokkos::View<double*, SMem>;
24using SConst = Kokkos::View<const double*, SMem>;
31 return static_cast<long>(x) +
static_cast<long>(y) * e.x +
32 static_cast<long>(z) *
static_cast<long>(e.x) * e.y;
50 if constexpr (std::is_same_v<typename SExec::memory_space, Kokkos::HostSpace>) {
51 const int nyi = e.y - 2 * g,
nzi = e.z - 2 * g;
53 "peclet::flow::diff", Kokkos::RangePolicy<SExec>(
space, 0, (
long)
nyi *
nzi),
55 const int y = g + (int)(t %
nyi), z = g + (int)(t /
nyi);
56 const long sx = 1, sy = e.x, sz =
static_cast<long>(e.x) * e.y;
57 const int P = (
color + og.x + og.y + y + og.z + z) & 1;
58 for (
int x = g + ((P ^ (g & 1)) & 1); x < e.x - g; x += 2) {
59 const long i =
L3(x, y, z, e);
64 const double nE = c(i +
sx),
nW = c(i -
sx),
nN = c(i + sy),
nS = c(i - sy),
65 nT = c(i + sz),
nB = c(i - sz);
78 "peclet::flow::diff",
MD(
space, {g, g, g}, {e.x - g, e.y - g, e.z - g}),
80 if ((((x + og.x) + (y + og.y) + (z + og.z)) & 1) !=
color)
82 const long i =
L3(x, y, z, e),
sx = 1, sy = e.x, sz =
static_cast<long>(e.x) * e.y;
84 const double nE = c(i +
sx),
nW = c(i -
sx),
nN = c(i + sy),
nS = c(i - sy),
nT = c(i + sz),
99 diffSmoothColorT<true>(c, b, e, og, g,
bx,
by,
bz,
Ac,
color,
dcorr);
101 diffSmoothColorT<false>(c, b, e, og, g,
bx,
by,
bz,
Ac,
color,
dcorr);
107 diffSmoothColorT<false>(c, b, e, og, g, beta, beta, beta,
Ac,
color,
dcorr);
117 const bool hasD = (
dcorr.extent(0) != 0);
119 Kokkos::parallel_for(
120 "peclet::flow::diff_resid",
MD(
space, {g, g, g}, {e.x - g, e.y - g, e.z - g}),
122 const long i =
L3(x, y, z, e),
sx = 1, sy = e.x, sz =
static_cast<long>(e.x) * e.y;
124 const double nE = c(i +
sx),
nW = c(i -
sx),
nN = c(i + sy),
nS = c(i - sy),
nT = c(i + sz),
131 r(i) = b(i) - ((
Ac + (
hasD ?
dcorr(i) : 0.0)) * c(i) - sum);
156 const bool hasD = (
dcorr.extent(0) != 0);
158 if constexpr (std::is_same_v<typename SExec::memory_space, Kokkos::HostSpace>) {
159 const int nyi = e.y - 2 * g,
nzi = e.z - 2 * g;
160 Kokkos::parallel_reduce(
161 "peclet::flow::diff_du", Kokkos::RangePolicy<SExec>(
space, 0, (
long)
nyi *
nzi),
163 const int y = g + (int)(t %
nyi), z = g + (int)(t /
nyi);
164 const long sx = 1, sy = e.x, sz =
static_cast<long>(e.x) * e.y;
165 const int P = (
color + og.x + og.y + y + og.z + z) & 1;
166 for (
int x = g + ((P ^ (g & 1)) & 1); x < e.x - g; x += 2) {
167 const long i =
L3(x, y, z, e);
172 const double nE = c(i +
sx),
nW = c(i -
sx),
nN = c(i + sy),
nS = c(i - sy),
173 nT = c(i + sz),
nB = c(i - sz);
179 const double cn = (b(i) + s) / (
Ac + (
hasD ?
dcorr(i) : 0.0));
180 const double d = Kokkos::fabs(
cn - c(i));
186 Kokkos::Max<double>(du));
190 Kokkos::parallel_reduce(
191 "peclet::flow::diff_du",
MD(
space, {g, g, g}, {e.x - g, e.y - g, e.z - g}),
193 if ((((x + og.x) + (y + og.y) + (z + og.z)) & 1) !=
color)
195 const long i =
L3(x, y, z, e),
sx = 1, sy = e.x, sz =
static_cast<long>(e.x) * e.y;
197 const double nE = c(i +
sx),
nW = c(i -
sx),
nN = c(i + sy),
nS = c(i - sy),
nT = c(i + sz),
204 const double cn = (b(i) + s) / (
Ac + (
hasD ?
dcorr(i) : 0.0));
205 const double d = Kokkos::fabs(
cn - c(i));
210 Kokkos::Max<double>(du));
217 return aniso ?
diffSmoothColorDuT<true>(c, b, e, og, g,
bx,
by,
bz,
Ac,
color,
dcorr)
218 :
diffSmoothColorDuT<false>(c, b, e, og, g,
bx,
by,
bz,
Ac,
color,
dcorr);
224 return diffSmoothColorDuT<false>(c, b, e, og, g, beta, beta, beta,
Ac,
color,
dcorr);
231 Kokkos::parallel_for(
232 "peclet::flow::pois",
MD(
space, {g, g, g}, {e.x - g, e.y - g, e.z - g}),
234 if ((((x + og.x) + (y + og.y) + (z + og.z)) & 1) !=
color)
236 const long i =
L3(x, y, z, e),
sx = 1, sy = e.x, sz =
static_cast<long>(e.x) * e.y;
238 phi(i +
sx) + phi(i -
sx) + phi(i + sy) + phi(i - sy) + phi(i + sz) + phi(i - sz);
239 phi(i) = (s - d(i)) / 6.0;
247 Kokkos::parallel_for(
248 "peclet::flow::diverg",
MD(
space, {g, g, g}, {e.x - g, e.y - g, e.z - g}),
250 const long i =
L3(x, y, z, e),
sx = 1, sy = e.x, sz =
static_cast<long>(e.x) * e.y;
251 d(i) = (u(i +
sx) - u(i)) + (v(i + sy) - v(i)) + (w(i + sz) - w(i));
void diffResidualT(SField r, SConst c, SConst b, I3 e, int g, double bx, double by, double bz, double Ac, SConst dcorr)
long L3(int x, int y, int z, I3 e)
void divergence(SConst u, SConst v, SConst w, SField d, I3 e, int g)
void diffSmoothColorT(SField c, SConst b, I3 e, I3 og, int g, double bx, double by, double bz, double Ac, int color, SConst dcorr)
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)
double diffSmoothColorDuT(SField c, SConst b, I3 e, I3 og, int g, double bx, double by, double bz, double Ac, int color, SConst dcorr)
void diffResidual(SField r, SConst c, SConst b, I3 e, int g, double bx, double by, double bz, double Ac, SConst dcorr, bool aniso)
Kokkos::View< const double *, SMem > SConst
void poisSmoothColor(SField phi, SConst d, I3 e, I3 og, int g, int color)
Kokkos::DefaultExecutionSpace SExec
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)
Kokkos::View< double *, SMem > SField
void poisSweep(SField phi, SConst d, I3 e, I3 og, int g)
flow — the multidimensional iteration policies: iteration order follows storage.