28#ifndef PECLET_VORO_FV_COLLOCATED_HPP
29#define PECLET_VORO_FV_COLLOCATED_HPP
32#include <Kokkos_Core.hpp>
42 using Exec = peclet::core::ExecSpace;
72 const int N =
m.
nCells, F =
m.nFaces, NC =
m.nCombined > 0 ?
m.nCombined : N;
93 sum = [&ex](Real v) {
return ex.sum(v); };
94 max = [&ex](Real v) {
return ex.max(v); };
100 const int nB =
m.nFaces -
m.nInterior, nI =
m.nInterior;
103 if (Uw.extent(0) == 0)
107 Kokkos::parallel_for(
108 "fv.ub", Kokkos::RangePolicy<Exec>(0, nB), KOKKOS_LAMBDA(
const int b) {
110 for (
int c = 0; c < 3; ++c)
111 un += Uw(3 * b + c) * mm.
normal(nI + b, c);
117 const int nB =
m.nFaces -
m.nInterior, nI =
m.nInterior;
119 Kokkos::parallel_for(
120 "fv.wall", Kokkos::RangePolicy<Exec>(0, nB),
121 KOKKOS_LAMBDA(
const int b) {
uf(nI + b) = bb(b); });
144 if (
wg.extent(0) == 0)
156 Kokkos::parallel_for(
157 "co.gradp", Kokkos::RangePolicy<Exec>(0, 3 *
m.nCells),
158 KOKKOS_LAMBDA(
const int i) { out(i) -= gc(i); });
169 if (divOut.extent(0) > 0)
170 Kokkos::deep_copy(divOut, dv);
171 const Real s = -Real(1) / dt;
172 Kokkos::parallel_for(
173 "co.rhsP", Kokkos::RangePolicy<Exec>(0,
m.nCells),
174 KOKKOS_LAMBDA(
const int i) { dv(i) *= s; });
177 Kokkos::parallel_for(
178 "co.corrF", Kokkos::RangePolicy<Exec>(0,
m.nFaces),
179 KOKKOS_LAMBDA(
const int f) { ufOut(f) -= dt * g(f); });
181 Kokkos::parallel_for(
182 "co.corrC", Kokkos::RangePolicy<Exec>(0, 3 *
m.nCells),
183 KOKKOS_LAMBDA(
const int i) { Ustar(i) -= dt * gc(i); });
185 Kokkos::parallel_for(
186 "co.pinc", Kokkos::RangePolicy<Exec>(0,
m.nCells),
187 KOKKOS_LAMBDA(
const int i) { pp(i) += ph(i); });
189 Kokkos::deep_copy(pp, ph);
197 Kokkos::deep_copy(
U, Uin);
198 Kokkos::deep_copy(
p, Real(0));
200 Kokkos::deep_copy(
p, Real(0));
212 const int N =
m.nCells, NC =
m.nCombined > 0 ?
m.nCombined : N;
219 if (
rhs3.extent(0) == 0) {
230 const bool hasWall =
m.
nFaces >
m.nInterior;
235 Kokkos::parallel_for(
236 "co.igradp", Kokkos::RangePolicy<Exec>(0, 3 * N),
237 KOKKOS_LAMBDA(
const int i) { aa(i) -= gc(i); });
241 if (
wg.extent(0) == 0)
245 const DV<Real> zero(
"co.zero",
m.nFaces);
248 Kokkos::parallel_for(
249 "co.wcorr", Kokkos::RangePolicy<Exec>(0, 3 * N),
250 KOKKOS_LAMBDA(
const int i) { aa(i) += WC(i) - AT(i); });
254 const bool hasW = Uw.extent(0) > 0;
255 const int nI =
m.nInterior;
256 Kokkos::parallel_for(
257 "co.rhs", Kokkos::RangePolicy<Exec>(0, N), KOKKOS_LAMBDA(
const int i) {
259 Real wall[3] = {0, 0, 0};
265 for (
int c = 0; c < 3; ++c)
266 wall[c] += w * Uw(3 * (f - nI) + c);
269 for (
int c = 0; c < 3; ++c)
270 R3(3 * i + c) = V * (UU(3 * i + c) / dt + aa(3 * i + c)) + wall[c];
274 for (
int c = 0; c < 3; ++c) {
276 Kokkos::parallel_for(
277 "co.gather", Kokkos::RangePolicy<Exec>(0, N),
278 KOKKOS_LAMBDA(
const int i) { rc(i) = R3(3 * i + c); });
280 Kokkos::parallel_for(
281 "co.scatter", Kokkos::RangePolicy<Exec>(0, N),
282 KOKKOS_LAMBDA(
const int i) { UU(3 * i + c) = UC(i); });
289 Kokkos::parallel_for(
290 "co.rot", Kokkos::RangePolicy<Exec>(0, N),
291 KOKKOS_LAMBDA(
const int i) { pp(i) -= nuL * dS(i); });
298 const int N3 = 3 *
m.nCells;
301 Kokkos::parallel_for(
302 "co.s1", Kokkos::RangePolicy<Exec>(0, N3),
303 KOKKOS_LAMBDA(
const int i) { V1(i) = UU(i) + dt * aa(i); });
306 Kokkos::parallel_for(
307 "co.s2", Kokkos::RangePolicy<Exec>(0, N3), KOKKOS_LAMBDA(
const int i) {
308 V2(i) = Real(0.75) * UU(i) + Real(0.25) * (V1(i) + dt * aa(i));
312 Kokkos::parallel_for(
313 "co.s3", Kokkos::RangePolicy<Exec>(0, N3),
314 KOKKOS_LAMBDA(
const int i) { UU(i) = (UU(i) + Real(2) * (V2(i) + dt * aa(i))) / Real(3); });
322 Kokkos::parallel_reduce(
323 "co.ke", Kokkos::RangePolicy<Exec>(0,
m.nCells),
324 KOKKOS_LAMBDA(
const int i, Real& acc) {
325 acc += mm.
cellVolume(i) * (UU(3 * i) * UU(3 * i) + UU(3 * i + 1) * UU(3 * i + 1) +
326 UU(3 * i + 2) * UU(3 * i + 2));
331 return Real(0.5) * e;
344 Kokkos::parallel_reduce(
345 "co.maxdiv", Kokkos::RangePolicy<Exec>(0,
m.nCells),
346 KOKKOS_LAMBDA(
const int i, Real& acc) {
347 const Real v = Kokkos::fabs(dv(i));
351 Kokkos::Max<Real>(mx));
352 return max ?
max(mx) : mx;
Track C, rung C2a (Voronoi methods plan, verdict V4): the staggered COVOLUME Navier–Stokes solver on ...
Track C, rung C1 (Voronoi methods plan): the FACE mesh of a published tessellation — one record per g...
Definition collocated.hpp:38
void vectorGreenGauss(const FaceMesh< Real > &m, const DV< Real > &U, const DV< Real > &out, const DV< Real > &Uwall=DV< Real >{})
Definition operators.hpp:161
void faceInterpTranspose(const FaceMesh< Real > &m, const DV< Real > &g, const DV< Real > &out, bool skew=false, const DV< Real > &scratch9=DV< Real >{}, bool wallPrescribed=false, const std::function< void(const DV< Real > &, int)> &exchange={})
Definition operators.hpp:272
void cellTendency(const FaceMesh< Real > &m, const DV< Real > &u, const DV< Real > &U, Real nu, const DV< Real > &out, const DV< Real > &force=DV< Real >{}, Real convScale=Real(1), const DV< Real > &Uwall=DV< Real >{}, const DV< Real > &wallGrad=DV< Real >{})
Definition covolume.hpp:70
void projectToFaces(const FaceMesh< Real > &m, const DV< Real > &ucell, const DV< Real > &out, const DV< Real > &gradU=DV< Real >{}, const DV< Real > &ub=DV< Real >{})
Definition operators.hpp:206
Kokkos::View< Real *, peclet::core::MemSpace > DV
Definition operators.hpp:26
void divergence(const FaceMesh< Real > &m, const DV< Real > &u, const DV< Real > &out)
(div u)_i from face-normal fluxes u (nFaces; boundary faces included, along the outward normal).
Definition operators.hpp:30
void faceGradient(const FaceMesh< Real > &m, const DV< Real > &p, const DV< Real > &out, const DV< Real > &pb=DV< Real >{})
Definition operators.hpp:46
void wallGradientLS(const FaceMesh< Real > &m, const DV< Real > &U, const DV< Real > &gradU, const DV< Real > &Uwall, const DV< Real > &out)
Definition operators.hpp:359
Track C, rung C1: the discrete operators of the staggered COVOLUME scheme on a face mesh (plan verdic...
Definition collocated.hpp:41
void setup(const FaceMesh< Real > &mesh, Real viscosity, bool amg=false)
Definition collocated.hpp:69
void cellGrad(const DV< Real > &q, const DV< Real > &out)
The cell gradient of a scalar q = the transpose of the constraint applied to grad_f q.
Definition collocated.hpp:137
Real maxFaceDivergence()
max_i |div u_f|_i of the transporting face flux (exactly projected)
Definition collocated.hpp:334
DV< Real > wcorr
Definition collocated.hpp:66
DV< Real > g9
Definition collocated.hpp:67
void step(Real dt)
Definition collocated.hpp:202
DV< Real > div
Definition collocated.hpp:67
DV< Real > aT
Definition collocated.hpp:66
bool skewCorrected
Definition collocated.hpp:47
DV< Real > uf
Definition collocated.hpp:49
DV< Real > U1
Definition collocated.hpp:67
DV< Real > wg
Definition collocated.hpp:52
bool incremental
Definition collocated.hpp:46
peclet::core::ExecSpace Exec
Definition collocated.hpp:42
DV< Real > gp
Definition collocated.hpp:67
Real nu
Definition collocated.hpp:44
DV< Real > phi
Definition collocated.hpp:67
std::function< void(const DV< Real > &, int)> exchange
Definition collocated.hpp:55
PressureSolver< Real > poisson
Definition collocated.hpp:123
DV< Real > divStar
Definition collocated.hpp:66
Real maxCellDivergence()
max_i |div (T U)|_i — the residual divergence of the CELL field (the "approximate" of ABC)
Definition collocated.hpp:336
void project(const DV< Real > &Ustar, const DV< Real > &ufOut, Real dt, const DV< Real > &divOut=DV< Real >{})
Definition collocated.hpp:162
DV< Real > p
Definition collocated.hpp:49
Real viscDt
Definition collocated.hpp:65
void setExchange(Ex &ex)
Install the distributed hooks on the solver and its pressure solver.
Definition collocated.hpp:91
DV< Real > ub
Definition collocated.hpp:50
DV< Real > U2
Definition collocated.hpp:67
DV< Real > Uwall
Definition collocated.hpp:50
void initialize(const DV< Real > &Uin)
Initialise from a cell field: U = Uin projected once (dt = 1, no pressure kept).
Definition collocated.hpp:196
DV< Real > uf1
Definition collocated.hpp:67
void applyWallFlux(const DV< Real > &uf) const
Impose the boundary fluxes on a face field.
Definition collocated.hpp:116
Real maxDivOf(const DV< Real > &flux)
Definition collocated.hpp:340
DV< Real > rhs3
Definition collocated.hpp:66
void stepImplicit(Real dt)
Definition collocated.hpp:211
bool implicitDiffusion
Definition collocated.hpp:61
void toFaces(const DV< Real > &Uc, const DV< Real > &out)
The constraint interpolation: face flux of the cell field.
Definition collocated.hpp:126
void tendency(const DV< Real > &Uin, const DV< Real > &ufin, const DV< Real > &out)
a = tendency of Uin transported by ufin, minus the current pressure gradient (incremental).
Definition collocated.hpp:142
Real convScale
Definition collocated.hpp:45
DV< Real > gphi
Definition collocated.hpp:67
void stepRK3(Real dt)
One SSP-RK3 step, flow's predictor/projection structure at every stage.
Definition collocated.hpp:297
DV< Real > uc
Definition collocated.hpp:66
DV< Real > a
Definition collocated.hpp:67
void setWallVelocity(const DV< Real > &Uw)
Definition collocated.hpp:99
bool wallQuadratic
Definition collocated.hpp:51
bool rotational
Definition collocated.hpp:62
std::function< Real(Real)> sum
Definition collocated.hpp:56
std::function< Real(Real)> max
Definition collocated.hpp:56
DV< Real > U
Definition collocated.hpp:49
DV< Real > force
Definition collocated.hpp:49
FaceMesh< Real > m
Definition collocated.hpp:43
PressureSolver< Real > visc
Definition collocated.hpp:64
Real kineticEnergy() const
½ Σ V_i |U_i|²
Definition collocated.hpp:318
DV< Real > uf2
Definition collocated.hpp:67
Kokkos::View< int *, Mem > cellFace
Definition mesh.hpp:49
KOKKOS_INLINE_FUNCTION Real normal(int f, int c) const
Definition mesh.hpp:55
int nCells
Definition mesh.hpp:35
KOKKOS_INLINE_FUNCTION int cellFacesBegin(int i) const
Definition mesh.hpp:53
KOKKOS_INLINE_FUNCTION int cellFacesEnd(int i) const
Definition mesh.hpp:54
Kokkos::View< Real *, Mem > cellVolume
Definition mesh.hpp:51
int nFaces
Definition mesh.hpp:35
Kokkos::View< Real *, Mem > faceArea
Definition mesh.hpp:42
Kokkos::View< Real *, Mem > faceHa
Definition mesh.hpp:45
Definition covolume.hpp:111