flow 1.4.0
Kokkos cut-cell IBM incompressible Navier-Stokes solver + pnm pore extraction
Loading...
Searching...
No Matches
mac_bc.hpp
Go to the documentation of this file.
1
10#ifndef PECLET_FLOW_MAC_BC_HPP
11#define PECLET_FLOW_MAC_BC_HPP
12
13#include <Kokkos_Core.hpp>
14
15#include "policy.hpp"
16
17namespace peclet::flow {
18
19using BExec = Kokkos::DefaultExecutionSpace;
20using BMem = BExec::memory_space;
21using BField = Kokkos::View<double*, BMem>;
22
23struct B3 {
24 int x, y, z;
25};
26
27namespace bcdetail {
28KOKKOS_INLINE_FUNCTION void axisDims(B3 ext, int (&dims)[3], long (&strides)[3]) {
29 dims[0] = ext.x;
30 dims[1] = ext.y;
31 dims[2] = ext.z;
32 strides[0] = 1;
33 strides[1] = ext.x;
34 strides[2] = static_cast<long>(ext.x) * ext.y;
35}
36// One column of bcVelocityComp: the ghosts of component `comp` on face (axis a, side s) along the
37// column `at(ia)` (ia = the index along a, na = the extent along a), wall velocity `wc`.
38template <class At>
39KOKKOS_INLINE_FUNCTION void velFaceColumn(const At& at, int na, int g, int a, int s, int comp,
40 double wc, int fold) {
41 const int bf = (s == 0) ? g : (na - g);
42 if (comp == a) { // normal: Dirichlet face + odd reflection
43 at(bf) = wc;
44 if (s == 0)
45 for (int ia = 0; ia < g; ++ia)
46 at(ia) = 2.0 * wc - at(2 * bf - ia);
47 else
48 for (int ia = na - g + 1; ia < na; ++ia)
49 at(ia) = 2.0 * wc - at(2 * bf - ia);
50 } else if (fold) { // tangential implicit: drop wall face
51 if (s == 0)
52 for (int ia = 0; ia < g; ++ia)
53 at(ia) = 0.0;
54 else
55 for (int ia = na - g; ia < na; ++ia)
56 at(ia) = 0.0;
57 } else { // tangential explicit: cell-centred reflection about bf-0.5
58 if (s == 0)
59 for (int ia = 0; ia < g; ++ia)
60 at(ia) = 2.0 * wc - at(2 * bf - 1 - ia);
61 else
62 for (int ia = na - g; ia < na; ++ia)
63 at(ia) = 2.0 * wc - at(2 * bf - 1 - ia);
64 }
65}
66} // namespace bcdetail
67
68// Fill component comp (0=u,1=v,2=w) ghosts for one domain face (axis a, side s=0 low/1 high) with a
69// scalar wall velocity. fold=1 drops the tangential wall face (ghost=0, implicit diffusion).
70inline void bcVelocityComp(BField f, B3 ext, int g, int a, int s, int comp, double wall, int fold,
71 BField prof = BField(), int prof_nc = 0) {
72 BExec space;
73 int dims[3];
74 long strides[3];
75 bcdetail::axisDims(ext, dims, strides);
76 const int b = (a + 1) % 3, c = (a + 2) % 3;
77 const long sa = strides[a], sb = strides[b], sc = strides[c];
78 const int na = dims[a];
79 const bool hasProf =
80 prof.extent(0) > 0; // per-position inlet profile (resampled to the face grid)
81 using MD = MDRange2<BExec>;
82 Kokkos::parallel_for(
83 "peclet::flow::bc_vel", MD(space, {0, 0}, {dims[b], dims[c]}), KOKKOS_LAMBDA(int p0, int p1) {
84 const long base = static_cast<long>(p0) * sb + static_cast<long>(p1) * sc;
85 const double wc = hasProf ? prof((static_cast<long>(p0) * prof_nc + p1) * 3 + comp) : wall;
86 auto at = [&](int ia) -> double& { return f(base + static_cast<long>(ia) * sa); };
87 bcdetail::velFaceColumn(at, na, g, a, s, comp, wc, fold);
88 });
89}
90
91// §14 H-3(e): up to six bcVelocityComp applications on ONE axis a -- (field, component, side, wall
92// velocity or inlet profile) -- in one launch over the face's perpendicular plane. Each column runs
93// the applications in table order, so for every field the faces keep their sequential order
94// (s = 0 before s = 1) and different fields are independent: bit-identical to the separate launches
95// in that order. The caller merges only faces whose ghost planes are disjoint (ext_a > 2g).
96struct BcVelFace {
97 BField f, prof; // the field; the resampled inlet profile (empty: the scalar `wall`)
98 double wall = 0.0;
99 int comp = 0, s = 0, profNc = 0;
100};
102 static constexpr int kMax = 6;
104 int n = 0;
105};
106inline void bcVelocityFaces(const BcVelFaces& J, B3 ext, int g, int a, int fold) {
107 BExec space;
108 int dims[3];
109 long strides[3];
110 bcdetail::axisDims(ext, dims, strides);
111 const int b = (a + 1) % 3, c = (a + 2) % 3;
112 const long sa = strides[a], sb = strides[b], sc = strides[c];
113 const int na = dims[a];
114 using MD = MDRange2<BExec>;
115 Kokkos::parallel_for(
116 "peclet::flow::bc_vel", MD(space, {0, 0}, {dims[b], dims[c]}), KOKKOS_LAMBDA(int p0, int p1) {
117 const long base = static_cast<long>(p0) * sb + static_cast<long>(p1) * sc;
118 for (int k = 0; k < J.n; ++k) {
119 const BcVelFace& q = J.j[k];
120 const double wc = (q.prof.extent(0) > 0)
121 ? q.prof((static_cast<long>(p0) * q.profNc + p1) * 3 + q.comp)
122 : q.wall;
123 auto at = [&](int ia) -> double& { return q.f(base + static_cast<long>(ia) * sa); };
124 bcdetail::velFaceColumn(at, na, g, a, q.s, q.comp, wc, fold);
125 }
126 });
127}
128
129// FREE-SLIP / SYMMETRY face (BC type 4) for component comp on one domain face (staggered).
130// * normal component (comp == a): impermeable -- the boundary face is held at 0 and the ghosts
131// are the odd reflection about it, exactly the no-slip wall with wall velocity 0;
132// * tangential components: zero normal derivative. Explicit (fold=0): the EVEN reflection about
133// the face, ghost(ia) = inner(mirror) -- exact for any profile symmetric about the face, so a
134// half-channel with this face reproduces the full channel pointwise. Implicit (fold=1): the
135// face is dropped (ghost = 0) and setupBcDiffusion folds -beta onto the diagonal (the mirror
136// neighbour equals the cell itself, so the face's beta*(ghost - inner) vanishes) -- the same
137// fold the outflow's zero-gradient tangential treatment uses.
138inline void bcSlipComp(BField f, B3 ext, int g, int a, int s, int comp, int fold) {
139 if (comp == a) {
140 bcVelocityComp(f, ext, g, a, s, comp, 0.0, fold);
141 return;
142 }
143 BExec space;
144 int dims[3];
145 long strides[3];
146 bcdetail::axisDims(ext, dims, strides);
147 const int b = (a + 1) % 3, c = (a + 2) % 3;
148 const long sa = strides[a], sb = strides[b], sc = strides[c];
149 const int na = dims[a];
150 const int bf = (s == 0) ? g : (na - g);
151 using MD = MDRange2<BExec>;
152 Kokkos::parallel_for(
153 "peclet::flow::bc_slip", MD(space, {0, 0}, {dims[b], dims[c]}),
154 KOKKOS_LAMBDA(int p0, int p1) {
155 const long base = static_cast<long>(p0) * sb + static_cast<long>(p1) * sc;
156 auto at = [&](int ia) -> double& { return f(base + static_cast<long>(ia) * sa); };
157 if (s == 0)
158 for (int ia = 0; ia < g; ++ia)
159 at(ia) = fold ? 0.0 : at(2 * bf - 1 - ia); // even reflection about bf-0.5
160 else
161 for (int ia = na - g; ia < na; ++ia)
162 at(ia) = fold ? 0.0 : at(2 * bf - 1 - ia);
163 });
164}
165
166// Even (mirror) reflection of a cell-centered field about one domain face: ghost(ia) =
167// inner(mirror). The collocated tangential free-slip ghost (a symmetric profile is reproduced
168// exactly, which bcNeumannGhost's copy of the boundary cell into every layer is not).
169inline void bcMirrorGhost(BField f, B3 ext, int g, int a, int s) {
170 BExec space;
171 int dims[3];
172 long strides[3];
173 bcdetail::axisDims(ext, dims, strides);
174 const int b = (a + 1) % 3, c = (a + 2) % 3;
175 const long sa = strides[a], sb = strides[b], sc = strides[c];
176 const int na = dims[a];
177 using MD = MDRange2<BExec>;
178 Kokkos::parallel_for(
179 "peclet::flow::bc_mirror_ghost", MD(space, {0, 0}, {dims[b], dims[c]}),
180 KOKKOS_LAMBDA(int p0, int p1) {
181 const long base = static_cast<long>(p0) * sb + static_cast<long>(p1) * sc;
182 auto at = [&](int ia) -> double& { return f(base + static_cast<long>(ia) * sa); };
183 if (s == 0)
184 for (int ia = 0; ia < g; ++ia)
185 at(ia) = at(2 * g - 1 - ia); // mirror about g-1/2
186 else
187 for (int ia = na - g; ia < na; ++ia)
188 at(ia) = at(2 * (na - g) - 1 - ia); // about na-g-1/2
189 });
190}
191
192// Collocated (cell-centered) velocity Dirichlet / no-slip ghost on one domain face. The wall sits
193// at the boundary FACE (between the last inner cell and the first ghost), so EVERY component is
194// reflected about it
195// -- ghost = 2*wc - mirror(interior) makes the face-interpolated value equal `wc`. No
196// normal/tangential split and no implicit fold: explicit reflection, re-imposed each smoother sweep
197// (converges to no-slip). `wc` is the scalar `wall`, or a per-position value from `prof` (the
198// resampled inlet profile, indexed (p0*prof_nc+p1)*3+comp over the face's perpendicular plane) when
199// one is supplied (e.g. the BFS step inlet).
200inline void bcVelocityColocated(BField f, B3 ext, int g, int a, int s, double wall, int comp = 0,
201 BField prof = BField(), int prof_nc = 0) {
202 BExec space;
203 int dims[3];
204 long strides[3];
205 bcdetail::axisDims(ext, dims, strides);
206 const int b = (a + 1) % 3, c = (a + 2) % 3;
207 const long sa = strides[a], sb = strides[b], sc = strides[c];
208 const int na = dims[a];
209 const bool hasProf = prof.extent(0) > 0;
210 using MD = MDRange2<BExec>;
211 Kokkos::parallel_for(
212 "peclet::flow::bc_vel_coloc", MD(space, {0, 0}, {dims[b], dims[c]}),
213 KOKKOS_LAMBDA(int p0, int p1) {
214 const long base = static_cast<long>(p0) * sb + static_cast<long>(p1) * sc;
215 const double wc = hasProf ? prof((static_cast<long>(p0) * prof_nc + p1) * 3 + comp) : wall;
216 auto at = [&](int ia) -> double& { return f(base + static_cast<long>(ia) * sa); };
217 if (s == 0)
218 for (int ia = 0; ia < g; ++ia)
219 at(ia) = 2.0 * wc - at(2 * g - 1 - ia); // mirror about g-1/2
220 else
221 for (int ia = na - g; ia < na; ++ia)
222 at(ia) = 2.0 * wc - at(2 * (na - g) - 1 - ia); // about na-g-1/2
223 });
224}
225
226// A0 cell bodies (doc/vof_step_performance_design.md §5.2) of the two pressure ghost policies
227// below: one transverse position `base` of the face, its ghost layers [lo, hi] along the stride sa.
228template <class FV>
229KOKKOS_INLINE_FUNCTION void bcNeumannGhostCell(const FV& f, long base, long sa, int bic, int lo,
230 int hi) {
231 const double pin = f(base + static_cast<long>(bic) * sa);
232 for (int ia = lo; ia <= hi; ++ia)
233 f(base + static_cast<long>(ia) * sa) = pin;
234}
235template <class FV>
236KOKKOS_INLINE_FUNCTION void bcZeroPressureGhostCell(const FV& phi, long base, long sa, int lo,
237 int hi) {
238 for (int ia = lo; ia <= hi; ++ia)
239 phi(base + (long)ia * sa) = 0.0;
240}
241
242// Zero-gradient (Neumann) ghost on one domain face: every ghost layer = the boundary-adjacent inner
243// cell (cell-centered). Used for the collocated pressure increment phi at walls so the
244// cell-centered correction carries no spurious normal acceleration (the same role pressureBcGhost
245// plays for P in the predictor).
246template <class FV>
247inline void bcNeumannGhostT(FV f, B3 ext, int g, int a, int s) {
248 BExec space;
249 int dims[3];
250 long strides[3];
251 bcdetail::axisDims(ext, dims, strides);
252 const int b = (a + 1) % 3, c = (a + 2) % 3;
253 const long sa = strides[a], sb = strides[b], sc = strides[c];
254 const int na = dims[a];
255 const int bic = (s == 0) ? g : (na - g - 1);
256 const int lo = (s == 0) ? 0 : (na - g), hi = (s == 0) ? (g - 1) : (na - 1);
257 using MD = MDRange2<BExec>;
258 Kokkos::parallel_for(
259 "peclet::flow::bc_neumann_ghost", MD(space, {0, 0}, {dims[b], dims[c]}),
260 KOKKOS_LAMBDA(int p0, int p1) {
261 bcNeumannGhostCell(f, static_cast<long>(p0) * sb + static_cast<long>(p1) * sc, sa, bic, lo,
262 hi);
263 });
264}
265inline void bcNeumannGhost(BField f, B3 ext, int g, int a, int s) {
266 bcNeumannGhostT(f, ext, g, a, s);
267}
268
269// Zero-gradient (Neumann) outflow velocity ghost for component comp on one face.
270inline void bcOutflowComp(BField f, B3 ext, int g, int a, int s, int comp, int fold) {
271 BExec space;
272 int dims[3];
273 long strides[3];
274 bcdetail::axisDims(ext, dims, strides);
275 const int b = (a + 1) % 3, c = (a + 2) % 3;
276 const long sa = strides[a], sb = strides[b], sc = strides[c];
277 const int na = dims[a];
278 using MD = MDRange2<BExec>;
279 Kokkos::parallel_for(
280 "peclet::flow::bc_outflow", MD(space, {0, 0}, {dims[b], dims[c]}),
281 KOKKOS_LAMBDA(int p0, int p1) {
282 const long base = static_cast<long>(p0) * sb + static_cast<long>(p1) * sc;
283 auto at = [&](int ia) -> double& { return f(base + static_cast<long>(ia) * sa); };
284 if (s == 0) {
285 const int src = (comp == a) ? g + 1 : g;
286 const int last = (comp == a) ? g : g - 1;
287 const double v = fold ? 0.0 : at(src);
288 for (int ia = 0; ia <= last; ++ia)
289 at(ia) = v;
290 } else {
291 const int src = na - g - 1;
292 const double v = fold ? 0.0 : at(src);
293 for (int ia = na - g; ia < na; ++ia)
294 at(ia) = v;
295 }
296 });
297}
298
299// Implicit-diffusion face-fold accumulation at the boundary-adjacent inner cell.
300inline void bcDiffusionFold(BField dcorr, BField brhs, B3 ext, int g, int a, int s, double dval,
301 double bval) {
302 BExec space;
303 int dims[3];
304 long strides[3];
305 bcdetail::axisDims(ext, dims, strides);
306 const int b = (a + 1) % 3, c = (a + 2) % 3;
307 const long sa = strides[a], sb = strides[b], sc = strides[c];
308 const int bic = (s == 0) ? g : (dims[a] - g - 1);
309 using MD = MDRange2<BExec>;
310 Kokkos::parallel_for(
311 "peclet::flow::bc_fold", MD(space, {0, 0}, {dims[b], dims[c]}),
312 KOKKOS_LAMBDA(int p0, int p1) {
313 const long i =
314 static_cast<long>(p0) * sb + static_cast<long>(p1) * sc + static_cast<long>(bic) * sa;
315 dcorr(i) += dval;
316 brhs(i) += bval;
317 });
318}
319
320// Hold the pressure ghost at 0 on an outflow face (Dirichlet p=0; the open face couples to it).
321inline void bcZeroPressureGhost(BField phi, B3 ext, int g, int a, int s) {
322 BExec space;
323 int dims[3];
324 long strides[3];
325 bcdetail::axisDims(ext, dims, strides);
326 const int b = (a + 1) % 3, c = (a + 2) % 3;
327 const long sa = strides[a], sb = strides[b], sc = strides[c];
328 const int na = dims[a];
329 const int lo = (s == 0) ? 0 : (na - g), hi = (s == 0) ? (g - 1) : (na - 1);
330 using MD = MDRange2<BExec>;
331 Kokkos::parallel_for(
332 "peclet::flow::bc_zero_p_ghost", MD(space, {0, 0}, {dims[b], dims[c]}),
333 KOKKOS_LAMBDA(int p0, int p1) {
334 bcZeroPressureGhostCell(phi, (long)p0 * sb + (long)p1 * sc, sa, lo, hi);
335 });
336}
337
338// Projection correction of the high-side outflow normal face (index na-g) that correct_k misses:
339// f -= phi[bf] - phi[bf-sa] (with the Dirichlet ghost phi[bf]=0 -> += phi_inner).
340// (correct_outflow_k.)
341//
342// PHASE 2 (doc/anisotropic_metric.md §3): `wa` is the per-axis pressure weight w_a = 1/h_a'^2 of
343// the face's own axis, applied OUTSIDE the existing expression exactly as in the interior
344// kernels (projectCorrect and friends) this face continues. 1.0 on the isotropic path (exact).
345inline void bcCorrectOutflow(BField f, BField phi, B3 ext, int g, int a, double wa = 1.0) {
346 BExec space;
347 int dims[3];
348 long strides[3];
349 bcdetail::axisDims(ext, dims, strides);
350 const int b = (a + 1) % 3, c = (a + 2) % 3;
351 const long sa = strides[a], sb = strides[b], sc = strides[c];
352 using MD = MDRange2<BExec>;
353 Kokkos::parallel_for(
354 "peclet::flow::bc_correct_outflow", MD(space, {0, 0}, {dims[b], dims[c]}),
355 KOKKOS_LAMBDA(int p0, int p1) {
356 const long bf = (long)p0 * sb + (long)p1 * sc + (long)(dims[a] - g) * sa;
357 f(bf) -= wa * (phi(bf) - phi(bf - sa));
358 });
359}
360
361// VARIABLE-DENSITY sibling of bcCorrectOutflow (WO-R item 4; the gap
362// doc/variable_density_projection.md section 4 listed as "revisit with a two-phase outflow case").
363//
364// Every other face of the staggered correction carries the mobility factor rho0/rho_f
365// (projectCorrectVar); the outflow face did not, so at a density ratio r the outflow face was
366// corrected by a factor r too much or too little relative to its neighbours. Constant density
367// hides it exactly (rho_f == rho0 makes the factor 1), which is why the channel/BFS validations
368// never saw it.
369//
370// rho_f is the SAME arithmetic face mean the operator coefficient and every other corrected face
371// use (buildRhoCoeff / projectCorrectVar). At the outflow face the outer cell is a ghost whose rho
372// the Neumann property policy (fillPropGhosts) set to the inner cell's rho, so this evaluates to
373// the inner cell's rho — the statement WO-R makes — while remaining literally the same expression
374// as the interior kernel, which is what keeps the two consistent if the ghost policy ever changes.
375inline void bcCorrectOutflowVar(BField f, BField phi, BField rho, double rho0, B3 ext, int g, int a,
376 bool harmonic, double wa = 1.0) {
377 BExec space;
378 int dims[3];
379 long strides[3];
380 bcdetail::axisDims(ext, dims, strides);
381 const int b = (a + 1) % 3, c = (a + 2) % 3;
382 const long sa = strides[a], sb = strides[b], sc = strides[c];
383 using MD = MDRange2<BExec>;
384 Kokkos::parallel_for(
385 "peclet::flow::bc_correct_outflow_var", MD(space, {0, 0}, {dims[b], dims[c]}),
386 KOKKOS_LAMBDA(int p0, int p1) {
387 const long bf = (long)p0 * sb + (long)p1 * sc + (long)(dims[a] - g) * sa;
388 const double ra = rho(bf), rb = rho(bf - sa);
389 // matched to projectCorrectVar / projectCorrectVarHarm (the harmonic knob is a measured
390 // ablation, set_rho_face_harmonic; it must switch BOTH or the outflow face disagrees with
391 // the interior it is continuing)
392 const double rf = harmonic ? (2.0 * ra * rb / (ra + rb)) : (0.5 * (ra + rb));
393 f(bf) -= wa * (rho0 / rf * (phi(bf) - phi(bf - sa)));
394 });
395}
396
397// Save / restore the HIGH-side domain-face plane of a field over the block's INNER transverse
398// range. SCALING_ISSUES #3/#8: that face is the first GHOST index along axis `a`, and the
399// distributed halo wraps periodically on every axis, so after an exchange it carries the OPPOSITE
400// boundary's value -- which destroys the mass-conserving outflow correction the projection wrote
401// there and that `fillVelGhostsTo(..., doOutflow = false)` exists to preserve.
402//
403// INNER transverse range ONLY: the plane's transverse ghost rows are not this rank's to restore
404// (the saved plane has no values for them). They are NOT right after the exchange either: they are
405// edge ghosts, wrapped along `a` too (review S1) -- bcHighFacePlaneToLastInner below repairs them
406// for the one caller that reads them, the full-stress prelude.
407inline void bcSaveHighFacePlaneInner(BField dst, BField src, B3 ext, int g, int a) {
408 BExec space;
409 int dims[3];
410 long strides[3];
411 bcdetail::axisDims(ext, dims, strides);
412 const int b = (a + 1) % 3, c = (a + 2) % 3;
413 const long sa = strides[a], sb = strides[b], sc = strides[c];
414 const int bf = dims[a] - g, nb = dims[b] - 2 * g, nc = dims[c] - 2 * g;
415 using MD = MDRange2<BExec>;
416 Kokkos::parallel_for(
417 "peclet::flow::bc_save_high_face", MD(space, {0, 0}, {nb, nc}),
418 KOKKOS_LAMBDA(int p0, int p1) {
419 dst((long)p0 + (long)p1 * nb) =
420 src((long)(p0 + g) * sb + (long)(p1 + g) * sc + (long)bf * sa);
421 });
422}
423inline void bcRestoreHighFacePlaneInner(BField dst, BField src, B3 ext, int g, int a) {
424 BExec space;
425 int dims[3];
426 long strides[3];
427 bcdetail::axisDims(ext, dims, strides);
428 const int b = (a + 1) % 3, c = (a + 2) % 3;
429 const long sa = strides[a], sb = strides[b], sc = strides[c];
430 const int bf = dims[a] - g, nb = dims[b] - 2 * g, nc = dims[c] - 2 * g;
431 using MD = MDRange2<BExec>;
432 Kokkos::parallel_for(
433 "peclet::flow::bc_restore_high_face", MD(space, {0, 0}, {nb, nc}),
434 KOKKOS_LAMBDA(int p0, int p1) {
435 dst((long)(p0 + g) * sb + (long)(p1 + g) * sc + (long)bf * sa) =
436 src((long)p0 + (long)p1 * nb);
437 });
438}
439
440// The TRANSVERSE ghost ring of that face plane (review S1, validation/REVIEW_FULLSTRESS.md): it is
441// an EDGE ghost, and the exchange fills an edge from the DIAGONAL neighbour's inner cells, wrapped
442// along `a` too -- so it carries the opposite boundary's value as well, and the restore above
443// (inner range only) does not reach it. The single-rank fill gives the periodic image of the face
444// plane there. The fix rides on one more exchange of a scratch field: copy the face plane (inner
445// transverse range) into the scratch's LAST INNER plane along `a`, exchange the scratch on every
446// rank, and copy the scratch's transverse ghost ring of that plane back onto the face plane's.
447// Both halves run only on a rank whose block touches the high `a` face; the neighbour that
448// supplies a transverse ghost of that plane owns the same global last inner plane, so it touches
449// the face too.
450inline void bcHighFacePlaneToLastInner(BField scratch, BField src, B3 ext, int g, int a) {
451 BExec space;
452 int dims[3];
453 long strides[3];
454 bcdetail::axisDims(ext, dims, strides);
455 const int b = (a + 1) % 3, c = (a + 2) % 3;
456 const long sa = strides[a], sb = strides[b], sc = strides[c];
457 const int bf = dims[a] - g, nb = dims[b] - 2 * g, nc = dims[c] - 2 * g;
458 using MD = MDRange2<BExec>;
459 Kokkos::parallel_for(
460 "peclet::flow::bc_face_to_last_inner", MD(space, {0, 0}, {nb, nc}),
461 KOKKOS_LAMBDA(int p0, int p1) {
462 const long t = (long)(p0 + g) * sb + (long)(p1 + g) * sc;
463 scratch(t + (long)(bf - 1) * sa) = src(t + (long)bf * sa);
464 });
465}
466inline void bcHighFacePlaneEdgesFromLastInner(BField dst, BField scratch, B3 ext, int g, int a) {
467 BExec space;
468 int dims[3];
469 long strides[3];
470 bcdetail::axisDims(ext, dims, strides);
471 const int b = (a + 1) % 3, c = (a + 2) % 3;
472 const long sa = strides[a], sb = strides[b], sc = strides[c];
473 const int bf = dims[a] - g, db = dims[b], dc = dims[c];
474 using MD = MDRange2<BExec>;
475 Kokkos::parallel_for(
476 "peclet::flow::bc_face_edges_from_last_inner", MD(space, {0, 0}, {db, dc}),
477 KOKKOS_LAMBDA(int p0, int p1) {
478 if (p0 >= g && p0 < db - g && p1 >= g && p1 < dc - g)
479 return; // the inner transverse range: the restored face itself
480 const long t = (long)p0 * sb + (long)p1 * sc;
481 dst(t + (long)bf * sa) = scratch(t + (long)(bf - 1) * sa);
482 });
483}
484
485// Set the a-component face openness on a domain face to `val` (Neumann wall/inflow -> 0; the
486// periodic fill would otherwise wrap the wrong value into an outflow face from the opposite
487// boundary -> set it open = 1).
488inline void bcSetOpenness(BField oa, B3 ext, int g, int a, int s, double val) {
489 BExec space;
490 int dims[3];
491 long strides[3];
492 bcdetail::axisDims(ext, dims, strides);
493 const int b = (a + 1) % 3, c = (a + 2) % 3;
494 const long sa = strides[a], sb = strides[b], sc = strides[c];
495 const int bf = (s == 0) ? g : (dims[a] - g);
496 using MD = MDRange2<BExec>;
497 Kokkos::parallel_for(
498 "peclet::flow::bc_setopen", MD(space, {0, 0}, {dims[b], dims[c]}),
499 KOKKOS_LAMBDA(int p0, int p1) {
500 oa(static_cast<long>(p0) * sb + static_cast<long>(p1) * sc + static_cast<long>(bf) * sa) =
501 val;
502 });
503}
504inline void bcZeroOpenness(BField oa, B3 ext, int g, int a, int s) {
505 bcSetOpenness(oa, ext, g, a, s, 0.0);
506}
507
508} // namespace peclet::flow
509
510#endif // PECLET_FLOW_MAC_BC_HPP
void axisDims(B3 ext, int(&dims)[3], long(&strides)[3])
Definition mac_bc.hpp:28
void velFaceColumn(const At &at, int na, int g, int a, int s, int comp, double wc, int fold)
Definition mac_bc.hpp:39
void bcNeumannGhostCell(const FV &f, long base, long sa, int bic, int lo, int hi)
Definition mac_bc.hpp:229
void bcCorrectOutflow(BField f, BField phi, B3 ext, int g, int a, double wa=1.0)
Definition mac_bc.hpp:345
void bcRestoreHighFacePlaneInner(BField dst, BField src, B3 ext, int g, int a)
Definition mac_bc.hpp:423
void bcSetOpenness(BField oa, B3 ext, int g, int a, int s, double val)
Definition mac_bc.hpp:488
void bcZeroPressureGhost(BField phi, B3 ext, int g, int a, int s)
Definition mac_bc.hpp:321
Kokkos::View< double *, BMem > BField
Definition mac_bc.hpp:21
void bcZeroOpenness(BField oa, B3 ext, int g, int a, int s)
Definition mac_bc.hpp:504
void bcDiffusionFold(BField dcorr, BField brhs, B3 ext, int g, int a, int s, double dval, double bval)
Definition mac_bc.hpp:300
BExec::memory_space BMem
Definition mac_bc.hpp:20
void bcVelocityColocated(BField f, B3 ext, int g, int a, int s, double wall, int comp=0, BField prof=BField(), int prof_nc=0)
Definition mac_bc.hpp:200
void bcSaveHighFacePlaneInner(BField dst, BField src, B3 ext, int g, int a)
Definition mac_bc.hpp:407
void bcZeroPressureGhostCell(const FV &phi, long base, long sa, int lo, int hi)
Definition mac_bc.hpp:236
Kokkos::DefaultExecutionSpace BExec
Definition mac_bc.hpp:19
void bcVelocityComp(BField f, B3 ext, int g, int a, int s, int comp, double wall, int fold, BField prof=BField(), int prof_nc=0)
Definition mac_bc.hpp:70
void bcMirrorGhost(BField f, B3 ext, int g, int a, int s)
Definition mac_bc.hpp:169
void bcVelocityFaces(const BcVelFaces &J, B3 ext, int g, int a, int fold)
Definition mac_bc.hpp:106
void bcHighFacePlaneEdgesFromLastInner(BField dst, BField scratch, B3 ext, int g, int a)
Definition mac_bc.hpp:466
void bcNeumannGhostT(FV f, B3 ext, int g, int a, int s)
Definition mac_bc.hpp:247
void bcCorrectOutflowVar(BField f, BField phi, BField rho, double rho0, B3 ext, int g, int a, bool harmonic, double wa=1.0)
Definition mac_bc.hpp:375
void bcOutflowComp(BField f, B3 ext, int g, int a, int s, int comp, int fold)
Definition mac_bc.hpp:270
void bcNeumannGhost(BField f, B3 ext, int g, int a, int s)
Definition mac_bc.hpp:265
Kokkos::MDRangePolicy< Exec, Kokkos::Rank< 2, Kokkos::Iterate::Left, Kokkos::Iterate::Left > > MDRange2
2-D range, first index fastest (both the tile order and the order within a tile).
Definition policy.hpp:31
void bcHighFacePlaneToLastInner(BField scratch, BField src, B3 ext, int g, int a)
Definition mac_bc.hpp:450
void bcSlipComp(BField f, B3 ext, int g, int a, int s, int comp, int fold)
Definition mac_bc.hpp:138
Definition prof.py:1
flow — the multidimensional iteration policies: iteration order follows storage.
BcVelFace j[kMax]
Definition mac_bc.hpp:103
static constexpr int kMax
Definition mac_bc.hpp:102
static double val(long gi)
Definition symconv.cpp:27
Kokkos::View< float *, IMem > FV