11#ifndef PECLET_FLOW_MAC_STENCILS_HPP
12#define PECLET_FLOW_MAC_STENCILS_HPP
14#include <Kokkos_Core.hpp>
19using SExec = Kokkos::DefaultExecutionSpace;
20using SMem = SExec::memory_space;
21using SField = Kokkos::View<double*, SMem>;
22using SConst = Kokkos::View<const double*, SMem>;
29 return static_cast<long>(x) +
static_cast<long>(y) * e.x +
30 static_cast<long>(z) *
static_cast<long>(e.x) * e.y;
41 if constexpr (std::is_same_v<typename SExec::memory_space, Kokkos::HostSpace>) {
42 const int nyi = e.y - 2 * g,
nzi = e.z - 2 * g;
44 "peclet::flow::diff", Kokkos::RangePolicy<SExec>(
space, 0, (
long)
nyi *
nzi),
46 const int y = g + (int)(
t %
nyi), z = g + (int)(
t /
nyi);
47 const long sx = 1,
sy = e.x,
sz =
static_cast<long>(e.x) * e.y;
48 const int P = (
color + og.x + og.y + y + og.z + z) & 1;
49 for (
int x = g + ((
P ^ (g & 1)) & 1); x < e.x - g; x += 2) {
50 const long i =
L3(x, y, z, e);
58 using MD = Kokkos::MDRangePolicy<SExec, Kokkos::Rank<3>>;
60 "peclet::flow::diff",
MD(
space, {g, g, g}, {e.x - g, e.y - g, e.z - g}),
62 if ((((x + og.x) + (y + og.y) + (z + og.z)) & 1) !=
color)
64 const long i =
L3(x, y, z, e),
sx = 1,
sy = e.x,
sz =
static_cast<long>(e.x) * e.y;
65 const double s = c(
i +
sx) + c(
i -
sx) + c(
i +
sy) + c(
i -
sy) + c(
i +
sz) + c(
i -
sz);
77 if constexpr (std::is_same_v<typename SExec::memory_space, Kokkos::HostSpace>) {
78 const int nyi = e.y - 2 * g,
nzi = e.z - 2 * g;
79 Kokkos::parallel_reduce(
80 "peclet::flow::diff_du", Kokkos::RangePolicy<SExec>(
space, 0, (
long)
nyi *
nzi),
82 const int y = g + (int)(
t %
nyi), z = g + (int)(
t /
nyi);
83 const long sx = 1,
sy = e.x,
sz =
static_cast<long>(e.x) * e.y;
84 const int P = (
color + og.x + og.y + y + og.z + z) & 1;
85 for (
int x = g + ((
P ^ (g & 1)) & 1); x < e.x - g; x += 2) {
86 const long i =
L3(x, y, z, e);
90 const double d = Kokkos::fabs(
cn - c(
i));
96 Kokkos::Max<double>(du));
99 using MD = Kokkos::MDRangePolicy<SExec, Kokkos::Rank<3>>;
100 Kokkos::parallel_reduce(
101 "peclet::flow::diff_du",
MD(
space, {g, g, g}, {e.x - g, e.y - g, e.z - g}),
103 if ((((x + og.x) + (y + og.y) + (z + og.z)) & 1) !=
color)
105 const long i =
L3(x, y, z, e),
sx = 1,
sy = e.x,
sz =
static_cast<long>(e.x) * e.y;
106 const double s = c(
i +
sx) + c(
i -
sx) + c(
i +
sy) + c(
i -
sy) + c(
i +
sz) + c(
i -
sz);
108 const double d = Kokkos::fabs(
cn - c(
i));
113 Kokkos::Max<double>(du));
120 using MD = Kokkos::MDRangePolicy<SExec, Kokkos::Rank<3>>;
121 Kokkos::parallel_for(
122 "peclet::flow::pois",
MD(
space, {g, g, g}, {e.x - g, e.y - g, e.z - g}),
124 if ((((x + og.x) + (y + og.y) + (z + og.z)) & 1) !=
color)
126 const long i =
L3(x, y, z, e),
sx = 1,
sy = e.x,
sz =
static_cast<long>(e.x) * e.y;
129 phi(
i) = (s - d(
i)) / 6.0;
136 using MD = Kokkos::MDRangePolicy<SExec, Kokkos::Rank<3>>;
137 Kokkos::parallel_for(
138 "peclet::flow::diverg",
MD(
space, {g, g, g}, {e.x - g, e.y - g, e.z - g}),
140 const long i =
L3(x, y, z, e),
sx = 1,
sy = e.x,
sz =
static_cast<long>(e.x) * e.y;
141 d(
i) = (u(
i +
sx) - u(
i)) + (v(
i +
sy) - v(
i)) + (w(
i +
sz) - w(
i));
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 diffSmoothColor(SField c, SConst b, I3 e, I3 og, int g, double beta, double Ac, int color, SConst dcorr)
double diffSmoothColorDu(SField c, SConst b, I3 e, I3 og, int g, double beta, double Ac, int color, SConst dcorr)
void ibmFillEntry(const OV &o, int list_idx, int c_idx, float sdf_c, const float sdf_n[6], int bc_type, const float *thEx)
Kokkos::View< const double *, SMem > SConst
void poisSmoothColor(SField phi, SConst d, I3 e, I3 og, int g, int color)
Kokkos::DefaultExecutionSpace SExec
Kokkos::View< double *, SMem > SField
void poisSweep(SField phi, SConst d, I3 e, I3 og, int g)