flow 1.3.0
Kokkos cut-cell IBM incompressible Navier-Stokes solver + pnm pore extraction
Loading...
Searching...
No Matches
grid_layout.hpp
Go to the documentation of this file.
1
12#ifndef PECLET_FLOW_GRID_LAYOUT_HPP
13#define PECLET_FLOW_GRID_LAYOUT_HPP
14
15#include "colocated_advection.hpp" // cadv::advect / advect_fou / fou_operator
16#include "mac_ibm.hpp" // peclet::flow::Off3
17#include "staggered_advection.hpp" // sadv::advect / advect_fou / fou_operator
18
19namespace peclet::flow {
20
21// A GridLayout policy supplies the two grid-position-dependent pieces the orchestrator needs:
22// - offset(c): where component c's velocity unknown sits (drives the cut-cell IBM overlay /
23// openness /
24// volume-fraction kernels);
25// - advect / advect_fou / fou_operator: the conservative momentum advection for that
26// control-volume
27// placement (forwarded to the sadv:: or cadv:: free functions).
28// The policy is stateless; the advection methods are KOKKOS_INLINE_FUNCTION so they inline on
29// device.
30
31// Staggered MAC grid: component c (0=u,1=v,2=w) lives on the low face along axis c (offset -1/2
32// there), i.e. u@(i-1/2,j,k), v@(i,j-1/2,k), w@(i,j,k-1/2). This is the existing flow grid; the
33// offsets reproduce the previously hard-coded {-0.5,0,0}/{0,-0.5,0}/{0,0,-0.5} arrays exactly
34// (bit-identical).
35struct Staggered {
36 static constexpr const char* name = "staggered";
37 static constexpr bool collocated = false; // stored velocity IS the face velocity (MAC)
38 static constexpr Off3 offset(int c) {
39 return c == 0 ? Off3{-0.5f, 0.0f, 0.0f}
40 : c == 1 ? Off3{0.0f, -0.5f, 0.0f}
41 : Off3{0.0f, 0.0f, -0.5f};
42 }
43 // A cell-centred VOLUMETRIC field (per-cell body force, drag coefficient) at component c's
44 // unknown, `s` = strideOf(c): the face between cells i - s and i, so the second-order face mean.
45 // Surface forces (pressure, viscous stress, surface tension) never come through here -- they are
46 // face integrals over the unknown's control volume (suite docs/decisions/flow.md, "Volumetric
47 // forces at the velocity location").
48 template <class A>
49 KOKKOS_INLINE_FUNCTION static double atVelocity(const A& f, long i, long s) {
50 return 0.5 * ((double)f(i) + (double)f(i - s));
51 }
52 // `uf` (the projected-face-field advecting velocity, see Colocated below) is meaningless here:
53 // the stored staggered velocity IS the face velocity, and after the projection it IS the
54 // divergence-free one. Accepted and ignored so the call sites stay grid-agnostic.
55 template <class A>
56 KOKKOS_INLINE_FUNCTION static double advect(int c, int x, int y, int z, A U, A V, A W, A F,
57 bool /*uf*/) {
58 return sadv::advect(c, x, y, z, U, V, W, F);
59 }
60 template <class A>
61 KOKKOS_INLINE_FUNCTION static double advect_sou(int c, int x, int y, int z, A U, A V, A W, A F,
62 bool /*uf*/) {
63 return sadv::advect_sou(c, x, y, z, U, V, W, F);
64 }
65 template <class A>
66 KOKKOS_INLINE_FUNCTION static double advect_fou(int c, int x, int y, int z, A U, A V, A W, A F,
67 bool /*uf*/) {
68 return sadv::advect_fou(c, x, y, z, U, V, W, F);
69 }
70 template <class A>
71 KOKKOS_INLINE_FUNCTION static void fou_operator(int c, int x, int y, int z, A U, A V, A W,
72 double dt, double& cC, double& cxm, double& cxp,
73 double& cym, double& cyp, double& czm,
74 double& czp, bool /*uf*/) {
75 sadv::fou_operator(c, x, y, z, U, V, W, dt, cC, cxm, cxp, cym, cyp, czm, czp);
76 }
77};
78
79// Collocated (cell-centered) grid: all three components live at the cell center (offset 0),
80// advected on the cell control volume (cadv) by the projected divergence-free MAC face field the
81// approximate (ABC) projection produced last step — the cell->face average only until that field
82// exists, or under the `set_uf_advection(False)` ablation.
83struct Colocated {
84 static constexpr const char* name = "colocated";
85 static constexpr bool collocated = true; // cell-centered velocity; approximate (MAC) projection
86 static constexpr Off3 offset(int /*c*/) { return Off3{0.0f, 0.0f, 0.0f}; }
87 // A cell-centred volumetric field at the (cell-centred) unknown: the cell value itself.
88 template <class A>
89 KOKKOS_INLINE_FUNCTION static double atVelocity(const A& f, long i, long /*s*/) {
90 return (double)f(i);
91 }
92 // `uf == true`: U/V/W are the projected divergence-free MAC face field (low-face convention),
93 // read verbatim at the control volume's faces; `false`: they are the cell velocities and the
94 // face value is their average. See colocated_advection.hpp and Solver::ufAdvVelocity().
95 template <class A>
96 KOKKOS_INLINE_FUNCTION static double advect(int c, int x, int y, int z, A U, A V, A W, A F,
97 bool uf) {
98 return cadv::advect(c, x, y, z, U, V, W, F, uf);
99 }
100 template <class A>
101 KOKKOS_INLINE_FUNCTION static double advect_sou(int c, int x, int y, int z, A U, A V, A W, A F,
102 bool uf) {
103 return cadv::advect_sou(c, x, y, z, U, V, W, F, uf);
104 }
105 template <class A>
106 KOKKOS_INLINE_FUNCTION static double advect_fou(int c, int x, int y, int z, A U, A V, A W, A F,
107 bool uf) {
108 return cadv::advect_fou(c, x, y, z, U, V, W, F, uf);
109 }
110 template <class A>
111 KOKKOS_INLINE_FUNCTION static void fou_operator(int c, int x, int y, int z, A U, A V, A W,
112 double dt, double& cC, double& cxm, double& cxp,
113 double& cym, double& cyp, double& czm,
114 double& czp, bool uf) {
115 cadv::fou_operator(c, x, y, z, U, V, W, dt, cC, cxm, cxp, cym, cyp, czm, czp, uf);
116 }
117};
118
119} // namespace peclet::flow
120
121#endif // PECLET_FLOW_GRID_LAYOUT_HPP
flow — collocated (cell-centered) momentum advection (Koren TVD + FOU).
flow — portable (Kokkos) IBM geometric fields + variable-coefficient RB-GS smoother.
void fou_operator(int comp, int x, int y, int z, A U, A V, A W, double dt, double &cC, double &cxm, double &cxp, double &cym, double &cyp, double &czm, double &czp, bool uf)
double advect(int comp, int x, int y, int z, A U, A V, A W, A PHI, bool uf)
double advect_sou(int comp, int x, int y, int z, A U, A V, A W, A PHI, bool uf)
double advect_fou(int comp, int x, int y, int z, A U, A V, A W, A PHI, bool uf)
double advect(int comp, int x, int y, int z, A U, A V, A W, A PHI)
double advect_sou(int comp, int x, int y, int z, A U, A V, A W, A PHI)
void fou_operator(int comp, int x, int y, int z, A U, A V, A W, double dt, double &cC, double &cxm, double &cxp, double &cym, double &cyp, double &czm, double &czp)
double advect_fou(int comp, int x, int y, int z, A U, A V, A W, A PHI)
flow — portable (Kokkos) staggered MAC momentum advection (Koren TVD + FOU).
static double atVelocity(const A &f, long i, long)
static double advect_fou(int c, int x, int y, int z, A U, A V, A W, A F, bool uf)
static constexpr const char * name
static constexpr Off3 offset(int)
static void fou_operator(int c, int x, int y, int z, A U, A V, A W, double dt, double &cC, double &cxm, double &cxp, double &cym, double &cyp, double &czm, double &czp, bool uf)
static double advect_sou(int c, int x, int y, int z, A U, A V, A W, A F, bool uf)
static constexpr bool collocated
static double advect(int c, int x, int y, int z, A U, A V, A W, A F, bool uf)
static constexpr const char * name
static double advect(int c, int x, int y, int z, A U, A V, A W, A F, bool)
static void fou_operator(int c, int x, int y, int z, A U, A V, A W, double dt, double &cC, double &cxm, double &cxp, double &cym, double &cyp, double &czm, double &czp, bool)
static double advect_sou(int c, int x, int y, int z, A U, A V, A W, A F, bool)
static constexpr bool collocated
static constexpr Off3 offset(int c)
static double atVelocity(const A &f, long i, long s)
static double advect_fou(int c, int x, int y, int z, A U, A V, A W, A F, bool)
static constexpr double F
static constexpr double U