8#ifndef PECLET_FLOW_MAC_TRANSFER_HPP
9#define PECLET_FLOW_MAC_TRANSFER_HPP
11#include <Kokkos_Core.hpp>
12#include <Kokkos_MathematicalFunctions.hpp>
18using TExec = Kokkos::DefaultExecutionSpace;
19using TMem = TExec::memory_space;
20using TField = Kokkos::View<double*, TMem>;
21using TConst = Kokkos::View<const double*, TMem>;
32 "peclet::flow::restrict", MD(space, {0, 0, 0}, {cinner.
x, cinner.
y, cinner.
z}),
33 KOKKOS_LAMBDA(
int icx,
int icy,
int icz) {
34 const long fsy = fext.
x, fsz =
static_cast<long>(fext.
x) * fext.
y;
36 for (
int dz = 0; dz < ratio.z; ++dz)
37 for (
int dy = 0; dy < ratio.y; ++dy)
38 for (
int dx = 0; dx < ratio.x; ++dx) {
39 const int fx = ratio.x * icx + dx + g, fy = ratio.y * icy + dy + g,
40 fz = ratio.z * icz + dz + g;
41 sum += fine(
static_cast<long>(fx) +
static_cast<long>(fy) * fsy +
42 static_cast<long>(fz) * fsz);
44 const long ci =
static_cast<long>(icx + g) +
static_cast<long>(icy + g) * cext.
x +
45 static_cast<long>(icz + g) *
static_cast<long>(cext.
x) * cext.
y;
46 coarse(ci) = sum /
static_cast<double>(ratio.x * ratio.y * ratio.z);
50KOKKOS_INLINE_FUNCTION
double trilerp(
TConst c,
double x,
double y,
double z,
T3 cext) {
51 const double fx = Kokkos::floor(x), fy = Kokkos::floor(y), fz = Kokkos::floor(z);
52 const double wx = x - fx, wy = y - fy, wz = z - fz;
53 const int x0 = (int)fx, y0 = (
int)fy, z0 = (int)fz;
54 const long sy = cext.
x, sz =
static_cast<long>(cext.
x) * cext.
y;
55 auto F = [&](
int xx,
int yy,
int zz) {
56 return c(
static_cast<long>(xx) +
static_cast<long>(yy) * sy +
static_cast<long>(zz) * sz);
58 const double c00 =
F(x0, y0, z0) * (1 - wx) +
F(x0 + 1, y0, z0) * wx;
59 const double c10 =
F(x0, y0 + 1, z0) * (1 - wx) +
F(x0 + 1, y0 + 1, z0) * wx;
60 const double c01 =
F(x0, y0, z0 + 1) * (1 - wx) +
F(x0 + 1, y0, z0 + 1) * wx;
61 const double c11 =
F(x0, y0 + 1, z0 + 1) * (1 - wx) +
F(x0 + 1, y0 + 1, z0 + 1) * wx;
62 const double c0 = c00 * (1 - wy) + c10 * wy;
63 const double c1 = c01 * (1 - wy) + c11 * wy;
64 return c0 * (1 - wz) + c1 * wz;
73 "peclet::flow::prolong", MD(space, {0, 0, 0}, {finner.
x, finner.
y, finner.
z}),
74 KOKKOS_LAMBDA(
int ifx,
int ify,
int ifz) {
75 const double cx = ratio.x == 2 ? 0.5 * ifx - 0.25 + g : (double)(ifx + g);
76 const double cy = ratio.y == 2 ? 0.5 * ify - 0.25 + g : (double)(ify + g);
77 const double cz = ratio.z == 2 ? 0.5 * ifz - 0.25 + g : (double)(ifz + g);
78 const long fi =
static_cast<long>(ifx + g) +
static_cast<long>(ify + g) * fext.
x +
79 static_cast<long>(ifz + g) *
static_cast<long>(fext.
x) * fext.
y;
80 fine(fi) +=
trilerp(coarse, cx, cy, cz, cext);
89 "peclet::flow::correct", MD(space, {g, g, g}, {e.x - g, e.y - g, e.z - g}),
90 KOKKOS_LAMBDA(
int x,
int y,
int z) {
91 const long i =
static_cast<long>(x) +
static_cast<long>(y) * e.x +
92 static_cast<long>(z) *
static_cast<long>(e.x) * e.y;
93 const long sx = 1, sy = e.x, sz =
static_cast<long>(e.x) * e.y;
94 u(i) -= phi(i) - phi(i - sx);
95 v(i) -= phi(i) - phi(i - sy);
96 w(i) -= phi(i) - phi(i - sz);
Kokkos::View< const double *, TMem > TConst
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 correct(TField u, TField v, TField w, TConst phi, T3 e, int g)
Kokkos::DefaultExecutionSpace TExec
Kokkos::View< double *, TMem > TField
void restrict_(TField coarse, TConst fine, T3 cext, T3 fext, int g, T3 cinner, T3 ratio)
void prolong(TField fine, TConst coarse, T3 fext, T3 cext, int g, T3 finner, T3 ratio)
double trilerp(TConst c, double x, double y, double z, T3 cext)
flow — the multidimensional iteration policies: iteration order follows storage.
static constexpr double F