35#ifndef PECLET_AMR_SEAM_RECON_HPP
36#define PECLET_AMR_SEAM_RECON_HPP
47#include "peclet/core/common/types.hpp"
65 std::vector<double>
d1I;
66 std::vector<double>
d1J;
82template <
unsigned Bits>
84 std::array<Index, 4>& cells) {
85 const unsigned Lc = ap.
levelOf(C);
88 const std::array<long, 3> lo = ap.
loOf(C);
89 const long sc = 1L << Lc, sh = sc >> 1;
90 std::array<long, 3> p = lo;
91 p[axis] = (dir > 0) ? lo[axis] + sc : lo[axis] - 1;
92 for (
int k = 0; k < 4; ++k) {
93 std::array<long, 3> q = p;
95 for (
int t = 0; t < 3; ++t) {
98 q[t] = lo[t] + (((k >> bit) & 1) ? sh : 0L);
102 if (c < 0 || Lq + 1 != Lc)
104 cells[
static_cast<std::size_t
>(k)] = c;
115template <
unsigned Bits,
class RegularFn,
class Flu
idFn>
122 std::vector<std::vector<detail::ScalarEnt>>
rec;
129 Index
sample(Index C, Index F,
int axis) {
132 const std::array<Index, 3> key{C, F,
static_cast<Index
>(axis)};
138 std::vector<detail::ScalarEnt> e;
141 id =
static_cast<Index
>(
rec.size());
142 rec.push_back(std::move(e));
143 dist.push_back(1.5 *
static_cast<double>(
ap.cellWidth(F, axis)));
144 ++
out.numSampleRecords;
151 Index
layer(Index C,
int axis,
int dir) {
154 const std::array<Index, 3> key{C,
static_cast<Index
>(axis),
static_cast<Index
>(dir)};
155 const auto it =
layerOf.find(key);
159 std::array<Index, 4> cells{};
162 for (
const Index c : cells)
165 std::vector<detail::ScalarEnt> e;
166 for (
const Index c : cells)
168 id =
static_cast<Index
>(
rec.size());
169 rec.push_back(std::move(e));
170 dist.push_back(0.75 *
static_cast<double>(
ap.cellWidth(C, axis)));
171 ++
out.numLayerRecords;
180 const unsigned Li =
ap.levelOf(i), Lj =
ap.levelOf(j);
181 Index rsI = -1, rsJ = -1, ruI = -1, ruJ = -1;
192 const Index uI =
ap.periodicNeighbor(i, a, -d);
194 const unsigned Lu =
ap.levelOf(uI);
198 ruI =
layer(i, a, -d);
200 const Index uJ =
ap.periodicNeighbor(j, a, d);
202 const unsigned Lu =
ap.levelOf(uJ);
206 ruJ =
layer(j, a, d);
208 if (rsI < 0 && rsJ < 0 && ruI < 0 && ruJ < 0) {
209 out.seam.push_back(-1);
212 out.seam.push_back(
out.numDescriptors());
213 out.sampI.push_back(rsI);
214 out.sampJ.push_back(rsJ);
215 out.uuRecI.push_back(ruI);
216 out.uuRecJ.push_back(ruJ);
217 out.d1I.push_back(0.5 *
static_cast<double>(
ap.cellWidth(i, a)));
218 out.d1J.push_back(0.5 *
static_cast<double>(
ap.cellWidth(j, a)));
223 const Index nRec =
static_cast<Index
>(
rec.size());
224 out.recStart.assign(
static_cast<std::size_t
>(nRec) + 1, 0);
225 for (Index r = 0; r < nRec; ++r)
226 out.recStart[
static_cast<std::size_t
>(r) + 1] =
227 out.recStart[
static_cast<std::size_t
>(r)] +
228 static_cast<Index
>(
rec[
static_cast<std::size_t
>(r)].size());
230 out.recCell.reserve(
static_cast<std::size_t
>(
out.recStart[
static_cast<std::size_t
>(nRec)]));
231 out.recW.reserve(
static_cast<std::size_t
>(
out.recStart[
static_cast<std::size_t
>(nRec)]));
232 for (Index r = 0; r < nRec; ++r)
233 for (
const auto& e :
rec[
static_cast<std::size_t
>(r)]) {
234 out.recCell.push_back(e.cell);
235 out.recW.push_back(e.w);
237 return std::move(
out);
261template <
unsigned Bits,
class RegularFn,
class Flu
idFn>
263 FluidFn&& fluidOk,
CfScheme scheme) {
266 std::remove_reference_t<FluidFn>>
267 b{ap, regularOk, fluidOk, scheme, {}, {}, {}, {}, {}};
268 for (Index i = 0; i < n; ++i)
270 i, [&](Index j,
int a,
int d,
double,
double,
double) { b.faceSlot(i, j, a, d); });
Cell-centered FV Poisson operator on one (periodic) block octree.
unsigned levelOf(Index slot) const
Octree level of an extended slot (local leaf or declared ghost).
void forEachFaceFull(Index i, Fn &&fn) const
Like forEachFaceNeighbor but exposes geometry for a consistent FV divergence/gradient: fn(neighbour,...
std::pair< Index, unsigned > probeSlot(const std::array< long, Dim > &p) const
Covering slot + level of a block-local probe (longs, possibly outside the block).
const Octree & octree() const
std::array< long, Dim > loOf(Index slot) const
Block-local lo corner of an extended slot as longs (ghosts may lie outside the block).
void cfAppendStencil(const AmrPoisson< 3, Bits > &ap, std::vector< Ent > &out, Index coarse, Index fine, int axis, double scale, FluidFn &&fluidOk, CfScheme scheme, const Ent &proto=Ent{})
Append the scheme's (coarse* − coarse_raw) substitution stencil for ONE directed C/F sub-face to out,...
bool seamFaceLayer(const AmrPoisson< 3, Bits > &ap, Index C, int axis, int dir, std::array< Index, 4 > &cells)
The four sub-face neighbour leaves across C's face (axis, dir), in forEachFaceFull's own sub-face ord...
SeamReconHost buildSeamRecon(const AmrPoisson< 3, Bits > &ap, RegularFn &®ularOk, FluidFn &&fluidOk, CfScheme scheme)
Build the seam-reconstruction tables over the LOCAL rows of ap (docs/amr_cf_convective....
CfScheme
Coarse/fine interface scheme for the collocated flow operators.
Host-side seam-reconstruction tables (docs/amr_cf_convective.md §5.2), built once per AmrFlow::setSol...
Index numDescriptors() const
Number of descriptors, i.e. of face slots that take the seam path (seam[slot] >= 0).
std::vector< Index > recStart
record CSR offsets, size nRec+1
std::vector< double > recW
record entries: weight
Index numSampleRecords
diagnostics: how many of the records are sample records
Index numLayerRecords
diagnostics: how many are layer records
std::vector< double > d1J
per descriptor: half width of j along the face axis (physical)
std::vector< Index > seam
per face slot: descriptor id, −1 = plain slot
std::vector< double > recDist
per record: dUU for UPSTREAM use (unused as a φ_U* sample)
std::vector< Index > sampI
per descriptor: sample record when i is the COARSE cell, else −1
std::vector< double > d1I
per descriptor: half width of i along the face axis (physical)
std::vector< Index > uuRecJ
per descriptor: upstream-probe record for up == j, else −1
std::vector< Index > sampJ
per descriptor: sample record when j is the COARSE cell, else −1
std::vector< Index > recCell
record entries: cell slot
std::vector< Index > uuRecI
per descriptor: upstream-probe record for up == i, else −1
The record tables of buildSeamRecon under construction: the descriptors (out), the record entries and...
std::vector< double > dist
const AmrPoisson< 3, Bits > & ap
Index layer(Index C, int axis, int dir)
The fine-layer record of C's (axis, dir) face (cached, -1 when withheld).
SeamReconHost pack()
Pack the records into the CSR of the result.
std::map< std::array< Index, 3 >, Index > sampleOf
Index sample(Index C, Index F, int axis)
The tangential-sample record of coarse C at fine F's column (cached, -1 when withheld).
std::vector< std::vector< detail::ScalarEnt > > rec
void faceSlot(Index i, Index j, int a, int d)
The descriptor of face slot (i, j, a, d) in forEachFaceFull order.
std::map< std::array< Index, 3 >, Index > layerOf