14#ifndef PECLET_AMR_FV_OP_HPP
15#define PECLET_AMR_FV_OP_HPP
20#include "peclet/core/common/view.hpp"
25template <
int Dim,
unsigned Bits>
29 "amr::device_laplacian", n, KOKKOS_LAMBDA(
const Index i) {
31 for (
int axis = 0; axis < Dim; ++axis)
32 for (
int dir = -1; dir <= 1; dir += 2) {
44template <
int Dim,
unsigned Bits>
46 View<double> lx,
double inv,
double omega) {
48 const double diag = 2.0 * Dim * inv;
51 "amr::device_jacobi_apply", n, KOKKOS_LAMBDA(
const Index i) {
53 for (
int axis = 0; axis < Dim; ++axis)
54 for (
int dir = -1; dir <= 1; dir += 2) {
62 "amr::device_jacobi_update", n,
63 KOKKOS_LAMBDA(
const Index i) { x(i) += omega * (lx(i) - b(i)) / diag; });
97inline FvCsrOpT<View<const double>, View<const Index>>
fvView(
const FvOp& op) {
98 FvCsrOpT<View<const double>, View<const Index>> v;
112inline void applyFv(
const FvOp& op, View<const double> u, View<double> Lu) {
113 const auto A =
fvView(op);
114 Kokkos::parallel_for(
115 "amr::fv_apply", op.
n, KOKKOS_LAMBDA(
const Index i) { Lu(i) = fvApplyRow(A, i, u); });
119inline void residualFv(
const FvOp& op, View<const double> u, View<const double> rhs,
121 const auto A =
fvView(op);
122 Kokkos::parallel_for(
123 "amr::fv_residual", op.
n,
124 KOKKOS_LAMBDA(
const Index i) { res(i) = rhs(i) - fvApplyRow(A, i, u); });
133inline void jacobiFv(
const FvOp& op, View<double> u, View<const double> rhs, View<double> tmp,
135 const auto A =
fvView(op);
136 Kokkos::parallel_for(
137 "amr::fv_jacobi_compute", op.
n,
138 KOKKOS_LAMBDA(
const Index i) { tmp(i) = fvPointSolve(A, i, u, rhs(i), u(i)); });
139 Kokkos::parallel_for(
140 "amr::fv_jacobi_update", op.
n,
141 KOKKOS_LAMBDA(
const Index i) { u(i) = (1.0 - omega) * u(i) + omega * tmp(i); });
154 double sx = 0.0, sv = 0.0;
161 Kokkos::parallel_reduce(
162 "amr::fv_rmean", op.
n,
163 KOKKOS_LAMBDA(
const Index i,
double& an,
double& ad) {
165 for (Index k = fs(i); k < fs(i + 1); ++k)
168 an += u(i) / invVol(i);
169 ad += 1.0 / invVol(i);
175 const double m = sx / sv;
176 Kokkos::parallel_for(
177 "amr::fv_rmean_sub", op.
n, KOKKOS_LAMBDA(
const Index i) {
179 for (Index k = fs(i); k < fs(i + 1); ++k)
189inline void quadDelta(View<const Index> qStart, View<const Index> qSlot, View<const double> qCoef,
190 View<const double> u, View<double> dq, Index n) {
191 Kokkos::parallel_for(
192 "amr::fv_quad_delta", n, KOKKOS_LAMBDA(
const Index i) {
194 for (Index k = qStart(i); k < qStart(i + 1); ++k)
195 acc += qCoef(k) * u(qSlot(k));
void laplacian(BlockOctreeView< Dim, Bits > dev, View< double > x, View< double > y, double inv)
y = inv · Σ_faces (x_nb − x_i) (= ∇² in spacing h0 with inv = 1/h0²), on device.
FvCsrOpT< View< const double >, View< const Index > > fvView(const FvOp &op)
View the assembled FV operator through the shared backend-agnostic FvCsrOpT, so the device kernels an...
void removeMeanFv(const FvOp &op, View< double > u)
Project u to volume-weighted-mean-zero over the ACTIVE (fluid) cells of the operator — the constant-n...
void jacobiSweep(BlockOctreeView< Dim, Bits > dev, View< double > x, View< const double > b, View< double > lx, double inv, double omega)
One weighted-Jacobi sweep of L u = b with L = ∇² (negative-definite, diagonal −2·Dim·inv),...
void residualFv(const FvOp &op, View< const double > u, View< const double > rhs, View< double > res)
res = rhs − H u.
void jacobiFv(const FvOp &op, View< double > u, View< const double > rhs, View< double > tmp, double omega)
One weighted-Jacobi sweep of H u = rhs (in place).
void applyFv(const FvOp &op, View< const double > u, View< double > Lu)
Hu = (c0·I + cD·L) u (consistent conservative FV Laplacian, c0=0/cD=1 ⇒ pure L).
void quadDelta(View< const Index > qStart, View< const Index > qSlot, View< const double > qCoef, View< const double > u, View< double > dq, Index n)
dq = (L_quad − L_std) u, the quadratic coarse-fine correction as its own SpMV over a precomputed CSR ...
Device mirror of a BlockOctree's leaf arrays + device-callable queries.
Index faceNeighbor(Index i, int axis, int dir) const
Leaf across leaf i's face on axis in direction dir (±1), or -1 if it lies outside the block.
View< Index > faceStart
CSR row offsets, size n+1.
View< double > bcDiag
Dirichlet boundary diagonal per cell (0 if periodic), size n.
View< double > invVol
1/V_i, size n
View< Index > faceNbr
neighbour leaf per face, size nFaces
View< double > faceW
w_f = openness·A_f/d_f per face, size nFaces