flow
Kokkos cut-cell IBM incompressible Navier-Stokes solver + pnm pore extraction
Loading...
Searching...
No Matches
mac_stencils.hpp
Go to the documentation of this file.
1
11#ifndef PECLET_FLOW_MAC_STENCILS_HPP
12#define PECLET_FLOW_MAC_STENCILS_HPP
13
14#include <Kokkos_Core.hpp>
15
16namespace peclet::flow {
17
18using SExec = Kokkos::DefaultExecutionSpace;
19using SMem = SExec::memory_space;
20using SField = Kokkos::View<double*, SMem>;
21using SConst = Kokkos::View<const double*, SMem>;
22
23struct I3 {
24 int x, y, z;
25};
26
27KOKKOS_INLINE_FUNCTION long L3(int x, int y, int z, I3 e) {
28 return static_cast<long>(x) + static_cast<long>(y) * e.x +
29 static_cast<long>(z) * static_cast<long>(e.x) * e.y;
30}
31
32// One Red-Black sweep colour of the implicit-diffusion smoother:
33// c[i] = (b[i] + beta*sum_neighbours) / (Ac + dcorr[i]). Call for colour 0 then 1.
34inline void diffSmoothColor(SField c, SConst b, I3 e, I3 og, int g, double beta, double Ac,
35 int color, SConst dcorr) {
36 SExec space;
37 const bool hasD = (dcorr.extent(0) != 0);
38 using MD = Kokkos::MDRangePolicy<SExec, Kokkos::Rank<3>>;
39 Kokkos::parallel_for(
40 "peclet::flow::diff", MD(space, {g, g, g}, {e.x - g, e.y - g, e.z - g}),
41 KOKKOS_LAMBDA(int x, int y, int z) {
42 if ((((x + og.x) + (y + og.y) + (z + og.z)) & 1) != color)
43 return;
44 const long i = L3(x, y, z, e), sx = 1, sy = e.x, sz = static_cast<long>(e.x) * e.y;
45 const double s = c(i + sx) + c(i - sx) + c(i + sy) + c(i - sy) + c(i + sz) + c(i - sz);
46 c(i) = (b(i) + beta * s) / (Ac + (hasD ? dcorr(i) : 0.0));
47 });
48}
49
50// One Red-Black sweep colour of the (unit-coefficient) Poisson smoother: phi[i] = (sum - d[i]) / 6.
51inline void poisSmoothColor(SField phi, SConst d, I3 e, I3 og, int g, int color) {
52 SExec space;
53 using MD = Kokkos::MDRangePolicy<SExec, Kokkos::Rank<3>>;
54 Kokkos::parallel_for(
55 "peclet::flow::pois", MD(space, {g, g, g}, {e.x - g, e.y - g, e.z - g}),
56 KOKKOS_LAMBDA(int x, int y, int z) {
57 if ((((x + og.x) + (y + og.y) + (z + og.z)) & 1) != color)
58 return;
59 const long i = L3(x, y, z, e), sx = 1, sy = e.x, sz = static_cast<long>(e.x) * e.y;
60 const double s =
61 phi(i + sx) + phi(i - sx) + phi(i + sy) + phi(i - sy) + phi(i + sz) + phi(i - sz);
62 phi(i) = (s - d(i)) / 6.0;
63 });
64}
65
66// MAC divergence d[i] = (u[i+sx]-u[i]) + (v[i+sy]-v[i]) + (w[i+sz]-w[i]) over inner cells.
67inline void divergence(SConst u, SConst v, SConst w, SField d, I3 e, int g) {
68 SExec space;
69 using MD = Kokkos::MDRangePolicy<SExec, Kokkos::Rank<3>>;
70 Kokkos::parallel_for(
71 "peclet::flow::diverg", MD(space, {g, g, g}, {e.x - g, e.y - g, e.z - g}),
72 KOKKOS_LAMBDA(int x, int y, int z) {
73 const long i = L3(x, y, z, e), sx = 1, sy = e.x, sz = static_cast<long>(e.x) * e.y;
74 d(i) = (u(i + sx) - u(i)) + (v(i + sy) - v(i)) + (w(i + sz) - w(i));
75 });
76}
77
78// Full Red-Black Gauss-Seidel sweep (both colours) of the Poisson smoother.
79inline void poisSweep(SField phi, SConst d, I3 e, I3 og, int g) {
80 poisSmoothColor(phi, d, e, og, g, 0);
81 poisSmoothColor(phi, d, e, og, g, 1);
82}
83
84} // namespace peclet::flow
85
86#endif // PECLET_FLOW_MAC_STENCILS_HPP
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)
Kokkos::View< const double *, SMem > SConst
void poisSmoothColor(SField phi, SConst d, I3 e, I3 og, int g, int color)
SExec::memory_space SMem
Kokkos::DefaultExecutionSpace SExec
Kokkos::View< double *, SMem > SField
void poisSweep(SField phi, SConst d, I3 e, I3 og, int g)