8#ifndef PECLET_FLOW_FLOW_IBM_DIAGNOSTICS_HPP
9#define PECLET_FLOW_FLOW_IBM_DIAGNOSTICS_HPP
20 const int dims[3] = {e.x, e.y, e.z};
21 const long st[3] = {1, e.x, (long)e.x * e.y};
29 const double rho = u_.rhoRef * rho_;
30 for (
int a = 0; a < 3; ++a)
31 for (
int s = 0; s < 2; ++s) {
32 if (bc_[2 * a + s] != 3 || !touchesGlobalFace(2 * a + s))
34 const int b = (a + 1) % 3, c = (a + 2) % 3;
35 const double ka = u_.velToPhys(a), kb = u_.velToPhys(b), kc = u_.velToPhys(c);
36 const long sa = st[a], sb = st[b], sc = st[c];
37 const int bf = (s == 0) ?
G : (dims[a] -
G);
38 const int bic = (s == 0) ?
G : (dims[a] -
G - 1);
39 const double sgn = (s == 0) ? 1.0 : -1.0;
43 double mx = 0.0, en = 0.0;
45 Kokkos::parallel_reduce(
46 "peclet::flow::backflow_census", MD(space, {
G,
G}, {dims[b] -
G, dims[c] -
G}),
47 KOKKOS_LAMBDA(
int p0,
int p1,
double& lmx,
double& len,
long& lnr) {
48 const long base = (long)p0 * sb + (
long)p1 * sc;
49 const double back = sgn * un(base + (
long)bf * sa);
51 const long ic = base + (long)bic * sa;
52 const double tb = kb * ub(ic), tc = kc * uc(ic);
53 const double bp = ka * back;
54 lmx = Kokkos::fmax(lmx, bp);
55 len += rho * bp * 0.5 * (bp * bp + tb * tb + tc * tc);
59 Kokkos::Max<double>(mx), Kokkos::Sum<double>(en), Kokkos::Sum<long>(nrev));
60 ob.maxReverse = std::max(ob.maxReverse, mx);
61 ob.energyInflux += en;
63 ob.total += (long)(dims[b] - 2 *
G) * (dims[c] - 2 *
G);
67 double d[2] = {ob.energyInflux, 0.0}, dg[2];
68 MPI_Allreduce(&ob.maxReverse, &d[1], 1, MPI_DOUBLE, MPI_MAX, comm_);
69 MPI_Allreduce(&d[0], &dg[0], 1, MPI_DOUBLE, MPI_SUM, comm_);
70 long l[2] = {ob.reversed, ob.total}, lg[2];
71 MPI_Allreduce(l, lg, 2, MPI_LONG, MPI_SUM, comm_);
73 ob.energyInflux = dg[0];
78 ob.fraction = ob.total > 0 ? (double)ob.reversed / (
double)ob.total : 0.0;
85 const double k = u_.velToPhys(c);
95 const double k = u_.velToInt(c);
97 std::vector<double> vi(v.size());
98 for (std::size_t i = 0; i < v.size(); ++i)
110 std::vector<double> out;
111 if constexpr (Grid::collocated) {
112 CCField fa[3] = {uf_, vf_, wf_};
117 const double k = u_.velToPhys(c);
119 for (
double& x : out)
126 CCField o[3] = {ox_, oy_, oz_};
132 auto h = Kokkos::create_mirror_view(C[c].
AC);
133 Kokkos::deep_copy(h, C[c].
AC);
134 std::vector<double> out((std::size_t)nx_ * ny_ * nz_);
135 for (
int z = 0; z < nz_; ++z)
136 for (
int y = 0; y < ny_; ++y)
137 for (
int x = 0; x < nx_; ++x)
138 out[(std::size_t)x + (std::size_t)y * nx_ + (std::size_t)z * (std::size_t)nx_ * ny_] =
139 (
double)h((
long)(x +
G) + (
long)(y +
G) * e_.x + (
long)(z +
G) * (
long)e_.x * e_.y);
145 const bool gp = ghostProjection_ && oxb_.extent(0) > 0;
146 CCField o[3] = {gp ? oxb_ : ox_, gp ? oyb_ : oy_, gp ? ozb_ : oz_};
155 std::vector<double> out =
gatherInner(incremental_ ? P_ : phi_);
157 const double ct = (incremental_ ? 1.0 : rho_ / dt_) * u_.pToPhys();
159 for (
double& x : out)
171 if (!cutcellPressure_)
173 if constexpr (Grid::collocated)
180 for (
int c = 0; c < 3; ++c)
186#ifdef PECLET_FLOW_MPI
189 MPI_Allreduce(&m, &g, 1, MPI_DOUBLE, MPI_MAX, comm_);
203 if (!cutcellPressure_)
205 if constexpr (Grid::collocated) {
219 if (ghostProjection_ && gpNRows_ >= 0) {
223 gpDivergDelta(div_, du, dv, dw, gpOv_, gpNRows_,
C3{nx_, ny_, nz_}, e_,
G, distributed_);
227 for (
int c = 0; c < 3; ++c)
229 if (ghostProjection_ && gpNRows_ >= 0) {
236 C3{nx_, ny_, nz_}, e_,
G, distributed_);
246#ifdef PECLET_FLOW_MPI
249 MPI_Allreduce(&m, &g, 1, MPI_DOUBLE, MPI_MAX, comm_);
258 if (!porous_ || !cutcellPressure_)
260 for (
int c = 0; c < 3; ++c)
269 CCField d = div_, dd = depsdt_;
270 const bool useDt = porousDepsDt_;
272 Kokkos::parallel_for(
273 "peclet::flow::porous_resid", MD(space, {
G,
G,
G}, {e.x -
G, e.y -
G, e.z -
G}),
274 KOKKOS_LAMBDA(
int x,
int y,
int z) {
275 const long i = (long)x + (
long)y * e.x + (long)z * e.x * e.y;
281#ifdef PECLET_FLOW_MPI
284 MPI_Allreduce(&m, &g, 1, MPI_DOUBLE, MPI_MAX, comm_);
293 return lastPressureIters_;
298 std::vector<std::array<int, 3>> out;
299 for (
const C3& r : mg_.levelRatios())
300 out.push_back({r.x, r.y, r.z});
306 return lastPressureFailed_;
311 using peclet::core::solver::AndersonRole;
316 auto refuse = [](
const std::string& why) {
317 throw std::runtime_error(
"steady acceleration (march_to_steady / anderson_accelerator): " +
318 why +
"; pass accelerate=False");
320 if constexpr (Grid::collocated) {
321 if (!(ghostProjection_ && faceInterp_ == 0))
323 "the collocated scheme is not the fluid-only 'ghost' projection -- for this scheme the "
324 "fixed point is not unique / the march is unstable (select "
325 "set_collocated_scheme('ghost') before the geometry)");
328 refuse(
"phase change (enable_phase_change) has no steady fixed point");
329 if (vofEnabled_ || vofMomEnabled_ || vofBlocks_)
330 refuse(
"VoF (enable_vof / enable_vof_momentum / VoF blocks) is time-accurate, not steady");
331 if (!scalars_.empty())
332 refuse(
"a transported scalar (add_scalar) is not in the march state");
334 refuse(
"the porous (volume-averaged) continuity is not supported");
335 bool propClosure =
false;
336 for (
const auto& cl : closures_)
337 propClosure = propClosure || cl.outName ==
"rho" || cl.outName ==
"mu";
338 if (varRho_ || varProps_ || propClosure ||
hasField(
"rho") ||
hasField(
"mu"))
339 refuse(
"variable density or viscosity (a property closure or a rho/mu field) is not supported");
341 refuse(
"a drag_beta field (implicit drag, CFD-DEM) is not supported");
343 refuse(
"cell force fields (force_x/force_y/force_z) are not supported");
345 refuse(
"moving scene instances have no steady fixed point");
346 if (superficialAxis_ >= 0)
347 refuse(
"set_superficial_velocity is not supported");
349 refuse(
"the pressure warm start (set_pressure_warmstart(True)) diverges on the steady march");
351 refuse(
"the balanced-force projection is not supported");
354 for (
int c = 0; c < 3; ++c) {
355 ms.fields.push_back(C[c].u);
356 ms.roles.push_back(AndersonRole::Velocity);
358 ms.fields.push_back(P_);
359 ms.roles.push_back(AndersonRole::Carried);
360 if constexpr (Grid::collocated) {
363 for (
CCField f : {uf_, vf_, wf_}) {
364 ms.fields.push_back(f);
365 ms.roles.push_back(AndersonRole::Carried);
377 static_cast<double>(advScheme_),
378 implicitFou_ ? 1.0 : 0.0};
379#ifdef PECLET_FLOW_MPI
381 ms.distributed = distributed_;
408 return mg_.allreduceSeconds();
413 return mg_.allreduceCount();
std::vector< double > getFaceVelocity(int c)
void fillVelGhosts(int comp, int fold)
long lastPressureAllreduceCount() const
double maxOpenDivergenceInternal()
The same diagnostic in INDEX units (per tRef), which is what the solver's own guards read.
void scatterInner(CCField fld, const std::vector< double > &in)
bool advectsMomentum() const
void seedFaceFieldFromCells()
double lastStepSeconds() const
std::vector< std::array< int, 3 > > pressureMgLevelRatios() const
double lastPressureAllreduceSeconds() const
double maxOpenDivergence()
OutflowBackflow outflowBackflow()
double maxPorousResidual()
double maxOpenDivergenceProjectedInternal()
The same diagnostic in INDEX units (per tRef), which is what the solver's own guards read.
CCConst openFaceView(int c) const
Component c of the face field AS THE ADVECTION AND THE DIVERGENCE DIAGNOSTIC MUST READ IT: advFaceVie...
void addWallFluxDivergence(CCField d)
double maxOpenDivergenceProjected()
std::vector< double > getOpenness(int c)
std::vector< double > getMomentumDiagonal(int c)
double lastProjectionSeconds() const
void setVelocity(int c, const std::vector< double > &v)
Write a component's inner velocity from a host vector (x-fastest, inner region) and re-impose the sol...
std::vector< double > getOpennessProj(int c)
std::vector< double > getVelocity(int c)
void fillVelGhostsTo(CCField f, int comp, int fold, bool doOutflow=true, bool faceEdges=false)
bool pressureSolveFailed() const
bool hasField(const std::string &name) const
long lastPressureIterations() const
double lastPredictorSeconds() const
bool balancedForceActive() const
double lastMomentumSeconds() const
double reduceMaxAbsInner(CCConst f)
std::vector< double > gatherInner(CCField fld)
void fillPorousEpsGhosts()
std::vector< double > getPressure()
Kokkos::DefaultExecutionSpace CCExec
void gpDivergDelta(CCField d, CCConst u, CCConst v, CCConst w, const GpOverlayReal< Real > &ov, int nOv, C3 nn, C3 extb, int gb, bool useGhost=false)
Overlay divergence correction: d(r) = rho_r * (d(r) + closure/BC/explicit face values),...
Kokkos::MDRangePolicy< Exec, Kokkos::Rank< 3, Kokkos::Iterate::Left, Kokkos::Iterate::Left > > MDRange3
3-D range, x (the first index) fastest (both the tile order and the order within a tile).
Kokkos::View< const double *, CCMem > CCConst
void divergOpen(CCConst u, CCConst v, CCConst w, CCConst ox, CCConst oy, CCConst oz, CCField d, C3 e, int g)
Kokkos::View< double *, CCMem > CCField
void divergOpenEps(CCConst u, CCConst v, CCConst w, CCConst ox, CCConst oy, CCConst oz, CCConst eps, CCField d, C3 e, int g)
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).
OUTFLOW REVERSAL CENSUS – the regime in which the zero-gradient (do-nothing) outflow is only conditio...
static constexpr double AC