flow 1.4.0
Kokkos cut-cell IBM incompressible Navier-Stokes solver + pnm pore extraction
Loading...
Searching...
No Matches
momentum_advect.hpp
Go to the documentation of this file.
1
142#ifndef PECLET_FLOW_VOF_MOMENTUM_ADVECT_HPP
143#define PECLET_FLOW_VOF_MOMENTUM_ADVECT_HPP
144
145#include <Kokkos_Core.hpp>
146#include <stdexcept>
147
148#include "policy.hpp"
149#include "vof/advect_wy.hpp"
150#include "vof/cutcell.hpp"
151
152namespace peclet::flow::vof {
153
157KOKKOS_INLINE_FUNCTION double vofPhaseRho(double rhoG, double rhoL, double c) {
158 return rhoG * (1.0 - c) + rhoL * c;
159}
160
161KOKKOS_INLINE_FUNCTION double vofMinmod(double a, double b) {
162 if (!(a * b > 0.0))
163 return 0.0;
164 return Kokkos::fabs(a) < Kokkos::fabs(b) ? a : b;
165}
166
170
176KOKKOS_INLINE_FUNCTION double vofPhaseSlope(double dm, double dp, bool hq, bool hm, bool hp) {
177 const double est = !hq ? 0.0 : (hm && hp ? 0.5 * (dm + dp) : (hm ? dm : (hp ? dp : 0.0)));
178 const double sgn = !(dm * dp > 0.0) ? 0.0 : (dm > 0.0 ? 1.0 : -1.0);
179 const double a2m = 2.0 * Kokkos::fabs(dm), a2p = 2.0 * Kokkos::fabs(dp);
180 const double ae = Kokkos::fabs(est);
181 double mn = a2m < a2p ? a2m : a2p;
182 mn = ae < mn ? ae : mn;
183 return sgn * mn;
184}
185
192KOKKOS_INLINE_FUNCTION double vofMomentumCap(double rg, double rl, double s, double aGeo,
193 double atP, double atO, double fAbs, double epsQ,
194 double cQ, bool kQ, double dm, double dp, double sigL,
195 double sigG) {
196 const double aaP = Kokkos::fabs(atP), aaO = Kokkos::fabs(atO);
197 const double muL = rl * fAbs, muG = rg * (aaP - fAbs), muP = muL + muG;
198 const bool outO = atO * s < 0.0;
199 const double lq = epsQ * cQ;
200 const double muO = outO ? rg * aaO + (rl - rg) * (aaO < lq ? aaO : lq) : 0.0;
201 const double R = epsQ * vofPhaseRho(rg, rl, cQ) - muP - muO + (kQ ? rl : rg) * s * (atP - atO);
202 const double adm = Kokkos::fabs(dm), adp = Kokkos::fabs(dp);
203 const double m = adm < adp ? adm : adp;
204 const double ext = 0.5 * (1.0 - Kokkos::fabs(aGeo)) * Kokkos::fabs(muG * sigG + muL * sigL);
205 const double beta = outO ? 0.5 : 1.0;
206 const double lim = beta * (R > 0.0 ? R : 0.0) * m;
207 return ext > lim ? lim / ext : 1.0;
208}
209
212 long clamped = 0;
213 long capped = 0;
214 KOKKOS_INLINE_FUNCTION VofMomCount& operator+=(const VofMomCount& o) {
215 clamped += o.clamped;
216 capped += o.capped;
217 return *this;
218 }
219};
220
221} // namespace peclet::flow::vof
222
223namespace Kokkos {
224template <>
225struct reduction_identity<peclet::flow::vof::VofMomCount> {
226 KOKKOS_FORCEINLINE_FUNCTION static peclet::flow::vof::VofMomCount sum() {
228 }
229};
230} // namespace Kokkos
231
232namespace peclet::flow::vof {
233
237KOKKOS_INLINE_FUNCTION double vofCellBox(const SField& c, const SField& mx, const SField& my,
238 const SField& mz, const SField& al, long q,
239 const double lo[3], const double hi[3], double eps = 0.0) {
240 const double cq = c(q);
241 const double vol = (hi[0] - lo[0]) * (hi[1] - lo[1]) * (hi[2] - lo[2]);
242 // WO-R2 item 4: the SAME wisp tolerance the colour reconstruction used, or this reads a plane
243 // the reconstruction pass never wrote for a wisp cell.
244 if (!wyIsMixed(cq, eps))
245 return cq * vol;
246 return plicBoxVolume(mx(q), my(q), mz(q), al(q), lo[0], hi[0], lo[1], hi[1], lo[2], hi[2]);
247}
248
253 public:
254 struct Diagnostics {
255 double minCc[3] = {0, 0, 0};
256 double maxCc[3] = {0, 0, 0};
257 double minRhoC = 0.0;
258 long floored = 0;
259 long clamped = 0;
260 long capped = 0;
261 double sumM[3] = {0, 0, 0};
262 double sumM0[3] = {0, 0, 0};
263 };
264
268 void init(const WyAdvector& w, double rhoG, double rhoL) {
269 if (!(rhoG > 0.0) || !(rhoL > 0.0))
270 throw std::invalid_argument(
271 "peclet::flow::vof::MomentumConsistentAdvector: both phase densities must be > 0");
272 n_ = w.inner();
273 e_ = w.extent();
274 g_ = w.ghost();
275 len_ = static_cast<long>(e_.x) * e_.y * e_.z;
276 rhoG_ = rhoG;
277 rhoL_ = rhoL;
278 for (int c = 0; c < 3; ++c) {
279 cc_[c] = SField("vof::Cc", len_);
280 vel_[c] = SField("vof::uAdv", len_);
281 flag_[c] = UCField("vof::ccFlag", len_);
282 }
283 fluxC_ = SField("vof::momFluxC", len_);
284 fluxU_ = SField("vof::momFluxU", len_);
285 fluxUG_ = SField("vof::momFluxUG", len_);
286 aFace_ = SField("vof::momAFace", len_);
287 }
288
289 bool initialized() const { return len_ > 0; }
290 void setPhaseDensities(double rhoG, double rhoL) {
291 rhoG_ = rhoG;
292 rhoL_ = rhoL;
293 }
294
295 SField advectedVelocity(int e) const { return vel_[e]; }
297 SField shiftedColour(int e) const { return cc_[e]; }
298
301 double rhoFloor = 0.0;
302 double rhoFloorFrac = 1e-6;
321 bool clampFluxes = true;
322
323 double phaseRhoG() const { return rhoG_; }
324 double phaseRhoL() const { return rhoL_; }
325 double lastRhoFloor() const { return floorUsed_; }
326 long clampedFluxes() const { return clamped_; }
328 long cappedFaces() const { return capped_; }
333
338 void advect(WyAdvector& w, double dt, long step) {
339 if (!initialized())
340 throw std::runtime_error(
341 "peclet::flow::vof::MomentumConsistentAdvector: init() was never called");
342 if (!(w.cflLimit < 0.5))
343 throw std::runtime_error(
344 "peclet::flow::vof::MomentumConsistentAdvector: the shifted control volume needs "
345 "|u| dt/h < 1/2 strictly (its flux slab lives inside ONE half cell), so the "
346 "Weymouth-Yue cap must be < 0.5 - the default 0.25 is the proven 3D bound");
348 throw std::invalid_argument(
349 "peclet::flow::vof::MomentumConsistentAdvector: the capped momentum schemes read the "
350 "donor's frozen flag in the first ghost layer, which the cell-flag ablation does not "
351 "define; use 'upwind' or 'muscl_mixed' with set_vof_momentum_cell_flag");
352 w.requireExchange();
353 w.checkCourant(dt); // same guard, same lastCfl_, as WyAdvector::advect
354 const double dth = dt / w.h();
355 clamped_ = 0;
356 floored_ = 0;
357 capped_ = 0;
358
359 w.freezeDilationFlag(); // the pressure-cell flag, for the colour update
360 w.reconstruct(); // planes of C^n: what C^e is clipped out of
361 if (w.hasGeometry())
363 else
366
367 const int* perm = kWySweepPerm[static_cast<int>(step % 6)];
368 for (int s = 0; s < 3; ++s) {
369 const int d = perm[s];
370 // The flux at the `-d` face of the first owned CV reads the donor one cell below, so C^e
371 // needs a valid ghost ring for the clamp of point 3. C^e is an ordinary cell field on this
372 // block (see the Indexing note), so the colour field's own exchange carries it.
373 for (int e = 0; e < 3; ++e) {
374 w.exchangeTimed(cc_[e]);
375 w.exchangeTimed(vel_[e]);
376 }
377 // The ghosts of C^e now hold C^{e,n}: the capped schemes need the donor's frozen flag also
378 // in the first ghost layer (note §4.8 item 3).
379 if (s == 0 && cappedScheme())
381 w.reconstruct(); // idempotent for s = 0; re-reconstructs after each applied sweep
382 w.computeFluxes(d, dth);
383 for (int e = 0; e < 3; ++e) {
384 if (w.hasGeometry()) { // rung V5a: openness-weighted, in fluid-volume units
385 momentumFluxesCut(w, d, e, dth);
386 momentumUpdateCut(w, d, e);
387 } else {
388 momentumFluxes(w, d, e, dth);
389 momentumUpdate(w, d, e);
390 }
391 }
392 w.applySweep(d, dth);
393 w.exchangeTimed(w.colour());
394 }
395 }
396
398 Diagnostics dg;
399 const I3 e = e_, n = n_;
400 const int g = g_;
401 const double rg = rhoG_, rl = rhoL_;
402 using MD = MDRange3<SExec>;
403 MD pol(SExec(), {g, g, g}, {g + n.x, g + n.y, g + n.z});
404 double gmin = 1e300;
405 for (int c = 0; c < 3; ++c) {
406 SField cf = cc_[c], mf = vel_[c];
407 double mn = 0.0, mx = 0.0, sm = 0.0, rmin = 0.0;
408 Kokkos::parallel_reduce(
409 "vof::mom::min", pol,
410 KOKKOS_LAMBDA(int x, int y, int z, double& acc) {
411 acc = Kokkos::fmin(acc, cf(L3(x, y, z, e)));
412 },
413 Kokkos::Min<double>(mn));
414 Kokkos::parallel_reduce(
415 "vof::mom::max", pol,
416 KOKKOS_LAMBDA(int x, int y, int z, double& acc) {
417 acc = Kokkos::fmax(acc, cf(L3(x, y, z, e)));
418 },
419 Kokkos::Max<double>(mx));
420 Kokkos::parallel_reduce(
421 "vof::mom::sum", pol,
422 KOKKOS_LAMBDA(int x, int y, int z, double& acc) {
423 const long i = L3(x, y, z, e);
424 acc += vofPhaseRho(rg, rl, cf(i)) * mf(i);
425 },
426 sm);
427 Kokkos::parallel_reduce(
428 "vof::mom::rhomin", pol,
429 KOKKOS_LAMBDA(int x, int y, int z, double& acc) {
430 acc = Kokkos::fmin(acc, vofPhaseRho(rg, rl, cf(L3(x, y, z, e))));
431 },
432 Kokkos::Min<double>(rmin));
433 Kokkos::fence();
434 dg.minCc[c] = mn;
435 dg.maxCc[c] = mx;
436 dg.sumM[c] = sm;
437 gmin = gmin < rmin ? gmin : rmin;
438 }
439 dg.minRhoC = gmin;
440 dg.floored = floored_;
441 dg.clamped = clamped_;
442 dg.capped = capped_;
443 for (int c = 0; c < 3; ++c)
444 dg.sumM0[c] = seedM_[c];
445 return dg;
446 }
447
448 public:
449 // ---- implementation detail (public for the same nvcc reason as in WyAdvector) ----------------
450
453 const I3 e = e_, n = n_;
454 const int g = g_;
455 SField c = w.colour(), mx = w.planeM(0), my = w.planeM(1), mz = w.planeM(2),
456 al = w.planeAlpha();
457 const double weps = w.wispEps; // WO-R2 item 4: the colour reconstruction's own tolerance
458 using MD = MDRange3<SExec>;
459 for (int comp = 0; comp < 3; ++comp) {
460 const long se = strideOf(comp);
461 const int ec = comp;
462 SField out = cc_[comp];
463 Kokkos::parallel_for(
464 "vof::mom::shifted_colour", MD(SExec(), {g, g, g}, {g + n.x, g + n.y, g + n.z}),
465 KOKKOS_LAMBDA(int x, int y, int z) {
466 const long i = L3(x, y, z, e);
467 double lo[3] = {0.0, 0.0, 0.0}, hi[3] = {1.0, 1.0, 1.0};
468 lo[ec] = 0.5;
469 hi[ec] = 1.0;
470 const double hiHalf = vofCellBox(c, mx, my, mz, al, i - se, lo, hi, weps);
471 lo[ec] = 0.0;
472 hi[ec] = 0.5;
473 const double loHalf = vofCellBox(c, mx, my, mz, al, i, lo, hi, weps);
474 out(i) = hiHalf + loHalf;
475 });
476 }
477 Kokkos::fence();
478 }
479
482 const I3 e = e_, n = n_;
483 const int g = g_;
484 const bool cellFlag = useCellDilationFlag;
485 UCField ccFlag = w.dilationFlag();
486 using MD = MDRange3<SExec>;
487 const double rg = rhoG_, rl = rhoL_;
488 for (int comp = 0; comp < 3; ++comp) {
489 const long se = strideOf(comp);
490 SField cf = cc_[comp], mf = vel_[comp], uf = w.faceVel(comp);
491 UCField fl = flag_[comp];
492 Kokkos::parallel_for(
493 "vof::mom::freeze", MD(SExec(), {g, g, g}, {g + n.x, g + n.y, g + n.z}),
494 KOKKOS_LAMBDA(int x, int y, int z) {
495 const long i = L3(x, y, z, e);
496 fl(i) = cellFlag ? ccFlag(i) : (cf(i) > 0.5 ? 1u : 0u);
497 mf(i) = uf(i - se); // uf_e(i-s_e) IS the velocity at control volume i
498 });
499 // The momentum census at the START of this step's advection, so the conservation claim can be
500 // made about the ADVECTION rather than about the whole coupled step (the momentum solve and
501 // the projection both change u afterwards, and they conserve `rho_f u` — the arithmetic face
502 // mean — not `rho^e u`).
503 double sm = 0.0;
504 Kokkos::parallel_reduce(
505 "vof::mom::seedsum", MD(SExec(), {g, g, g}, {g + n.x, g + n.y, g + n.z}),
506 KOKKOS_LAMBDA(int x, int y, int z, double& acc) {
507 const long i = L3(x, y, z, e);
508 acc += vofPhaseRho(rg, rl, cf(i)) * mf(i);
509 },
510 sm);
511 Kokkos::fence();
512 seedM_[comp] = sm;
513 }
514 Kokkos::fence();
515 }
516
521 void momentumFluxes(const WyAdvector& w, int d, int comp, double dth) {
522 const I3 e = e_;
523 const int g = g_;
524 const long sd = strideOf(d), se = strideOf(comp);
525 const int dd = d, ec = comp;
526 const double rg = rhoG_, rl = rhoL_;
527 if (cappedScheme()) {
528 momentumFluxesCapped(w, d, comp, dth);
529 return;
530 }
531 const bool muscl = momentumScheme == MomentumScheme::MusclMixed, clamp = clampFluxes;
532 SField c = w.colour(), mx = w.planeM(0), my = w.planeM(1), mz = w.planeM(2),
533 al = w.planeAlpha();
534 const double weps = w.wispEps;
535 SField ud = w.faceVel(d), cvU = vel_[comp], cvC = cc_[comp];
536 SField fc = fluxC_, fu = fluxU_, af = aFace_;
537 int lo3[3] = {g, g, g};
538 const int hi3[3] = {g + n_.x, g + n_.y, g + n_.z};
539 lo3[d] -= 1; // the `-d` face of the first owned CV is the `+d` face of the CV below it
540 long nclamp = 0;
541 Kokkos::parallel_reduce(
542 "vof::mom::flux",
543 MDRange3<SExec>(SExec(), {lo3[0], lo3[1], lo3[2]}, {hi3[0], hi3[1], hi3[2]}),
544 KOKKOS_LAMBDA(int x, int y, int z, long& acc) {
545 const long p = L3(x, y, z, e);
546 // The shifted CV's face velocity is the `comp`-average of the two staggered faces; summed
547 // over the three sweeps this is 1/2 (div_{p-s_e} + div_p) — zero for a projected field.
548 const double a = 0.5 * (ud(p - se) + ud(p)) * dth;
549 af(p) = a;
550 if (a == 0.0) {
551 fc(p) = 0.0;
552 fu(p) = cvU(p); // any finite value; the update multiplies it by a == F == 0
553 return;
554 }
555 const double aa = a > 0.0 ? a : -a;
556 double lo[3] = {0.0, 0.0, 0.0}, hi[3] = {1.0, 1.0, 1.0};
557 double F;
558 if (dd == ec) {
559 // The CV face sits at the CENTRE of cell p; the |a|-deep slab therefore lives inside
560 // that one cell's upwind half. |a| < 1/2 keeps it there.
561 if (a > 0.0) {
562 lo[ec] = 0.5 - aa;
563 hi[ec] = 0.5;
564 } else {
565 lo[ec] = 0.5;
566 hi[ec] = 0.5 + aa;
567 }
568 F = vofCellBox(c, mx, my, mz, al, p, lo, hi, weps);
569 } else {
570 // Transverse sweep: the CV face is the pressure cells' own `d` face, and the donor slab
571 // is the union of the `+e` half of one cell and the `-e` half of its `e` neighbour.
572 long q;
573 if (a > 0.0) {
574 q = p;
575 lo[dd] = 1.0 - aa;
576 hi[dd] = 1.0;
577 } else {
578 q = p + sd;
579 lo[dd] = 0.0;
580 hi[dd] = aa;
581 }
582 lo[ec] = 0.5;
583 hi[ec] = 1.0;
584 const double hiHalf = vofCellBox(c, mx, my, mz, al, q - se, lo, hi, weps);
585 lo[ec] = 0.0;
586 hi[ec] = 0.5;
587 const double loHalf = vofCellBox(c, mx, my, mz, al, q, lo, hi, weps);
588 F = hiHalf + loHalf;
589 }
590 // Weymouth's admissible interval on the DONOR control volume's own colour (thesis
591 // Appendix A) — the hypothesis of his boundedness proof. Collapses to the algebraic value
592 // for a full or empty donor, so full/empty CVs stay exactly stationary.
593 if (clamp) {
594 const double cd = cvC(a > 0.0 ? p : p + sd);
595 const double up = aa < cd ? aa : cd;
596 const double dn = aa - (1.0 - cd);
597 const double lob = dn > 0.0 ? dn : 0.0;
598 const double Fc = F > up ? up : (F < lob ? lob : F);
599 if (Fc != F)
600 ++acc;
601 F = Fc;
602 }
603 if (a < 0.0)
604 F = -F;
605 // Donor-CV velocity, MinMod-limited to the flux slab's centroid. A uniform field gives
606 // both MinMod arguments exactly 0, hence u^ = u bit for bit — the uniform-velocity gate.
607 const long don = a > 0.0 ? p : p + sd;
608 double slope = 0.0;
609 if (muscl)
610 slope = vofMinmod(cvU(don) - cvU(don - sd), cvU(don + sd) - cvU(don));
611 const double sgn = a > 0.0 ? 1.0 : -1.0;
612 // Only the FACE quantities are stored — the liquid flux, the Courant number and the
613 // donor velocity. The mass flux `rho_g a + (rho_l - rho_g) F` and the momentum flux are
614 // assembled in `momentumUpdate`, in a form that cancels exactly; see the note there.
615 fc(p) = F;
616 fu(p) = cvU(don) + sgn * (0.5 - 0.5 * aa) * slope;
617 },
618 nclamp);
619 Kokkos::fence();
620 clamped_ += nclamp;
621 }
622
625 void momentumUpdate(const WyAdvector& w, int d, int comp) {
627 momentumUpdatePhase(w, d, comp);
628 return;
629 }
630 const I3 e = e_, n = n_;
631 const int g = g_;
632 const long sd = strideOf(d), se = strideOf(comp);
633 const double rg = rhoG_, rl = rhoL_, dr = rhoL_ - rhoG_;
634 const double rmin = rhoG_ < rhoL_ ? rhoG_ : rhoL_;
635 const double fl0 = rhoFloor > 0.0 ? rhoFloor : rhoFloorFrac * rmin;
636 floorUsed_ = fl0;
637 SField cf = cc_[comp], vf = vel_[comp], uf = w.faceVel(comp);
638 SField fc = fluxC_, fu = fluxU_, af = aFace_;
639 UCField fl = flag_[comp];
640 long nfloor = 0;
641 Kokkos::parallel_reduce(
642 "vof::mom::update", MDRange3<SExec>(SExec(), {g, g, g}, {g + n.x, g + n.y, g + n.z}),
643 KOKKOS_LAMBDA(int x, int y, int z, long& acc) {
644 const long i = L3(x, y, z, e);
645 const double aP = af(i), aM = af(i - sd);
646 const unsigned char k = fl(i);
647 const double dil = k ? (aP - aM) : 0.0;
648 // The colour increment, formed ONCE and reused by the momentum below: that literal
649 // sharing is what makes the uniform-velocity identity exact rather than merely true in
650 // exact arithmetic.
651 const double dC = (fc(i - sd) - fc(i)) + dil;
652 const double cNew = cf(i) + dC;
653 cf(i) = cNew;
654 // The conservative update of this control volume is
655 // rho_new u_new = rho_old u_old - (Psi_+ u^_+ - Psi_- u^_-) + rho^ u_old (a_+ - a_-)
656 // with `Psi = rho_g a + drho F` the mass flux and `u^` the donor reconstruction of the
657 // CURRENT velocity. Stored and evolved as `rho^e u_e`, that is a sum of rho_l-scaled
658 // terms whose result is only rho_g-scaled in a gas control volume, and a volume a
659 // directional sweep fills and the next one empties passes through an intermediate `rho^e`
660 // a factor `ratio` larger than where it starts and ends; the rounding of that excursion
661 // is eps*ratio*|a| and does NOT cancel against the colour's own. Measured, it degraded
662 // the uniform-velocity gate LINEARLY IN THE DENSITY RATIO (6.7e-16 at 1e2 -> 3.2e-14 at
663 // 1e4) — wearing exactly the signature of the defect this rung exists to remove, for a
664 // purely floating-point reason.
665 //
666 // Subtracting `rho_new u_old` from both sides is algebraically free (substitute
667 // `rho_old = rho_new - drho dC` and watch every `u_old` term cancel) and removes it:
668 //
669 // u_new = u_old + [ rho_g (a_- dv_- - a_+ dv_+) + drho (F_- dv_- - F_+ dv_+)
670 // ]/rho_new dv_+/- = u^_+/- - u_old
671 //
672 // Every term is a DIFFERENCE OF VELOCITIES. For a uniform field each is exactly zero (the
673 // same double, subtracted), so `u_new == u_old` bit for bit at ANY density ratio and for
674 // any dC — the gate is flat in the ratio by construction, not by tolerance. This is still
675 // the conservative scheme, with `rho_new` the advected colour's own density; only the
676 // arithmetic is conditioned. (An earlier version fluxed the FROZEN u^n instead of the
677 // current velocity; the `drho dC (u^n_i - u_old)/rho_new` term that then survives has
678 // gain `ratio` on a control volume a sweep empties, and it amplified the solver's own
679 // 1e-7 float-storage noise to 1e-7 at ratio 1e4 while ratio 1e3 was clean — the gain, not
680 // a defect in the fluxes. Transporting the current state removes the term identically and
681 // is also the faithful directional split.)
682 const double uo = vf(i);
683 const double dvM = fu(i - sd) - uo, dvP = fu(i) - uo;
684 // The DILATION coefficient is `rho^ u^n`, with `u^n` the velocity FROZEN at the start of
685 // the step — the exact analogue of Weymouth-Yue freezing `H(C^n - 1/2)`, and required for
686 // the same reason. Summed over the three sweeps the dilation contributes
687 // `rho^ u (a_+ - a_-)` per sweep, and only a coefficient that is a CONSTANT OF THE STEP
688 // factors out of that sum to leave `rho^ u * div = 0`. With the running velocity there
689 // instead, the three sweeps see three different `u` and the cancellation is lost:
690 // MEASURED, per-step momentum conservation degraded to 1.4e-7 relative — first order in
691 // dt, not round-off — while the colour, whose flag IS frozen, stayed exact. Written as
692 // `rho^ (u^n - u_old)` because the `rho^ u_old` part has already been absorbed into the
693 // deviation form above; for a uniform field `u^n == u_old` and the term is exactly zero,
694 // so the consistency identity is untouched.
695 const double dilCoef = (k ? rl : rg) * (uf(i - se) - uo) * (aP - aM);
696 const double dev =
697 rg * (aM * dvM - aP * dvP) + dr * (fc(i - sd) * dvM - fc(i) * dvP) + dilCoef;
698 const double rn = vofPhaseRho(rg, rl, cNew);
699 if (rn < fl0)
700 ++acc;
701 vf(i) = uo + dev / (rn < fl0 ? fl0 : rn);
702 },
703 nfloor);
704 Kokkos::fence();
705 floored_ += nfloor;
706 }
707
708 // ---- rung V5a (WO-Q item 8): the same construction on a CUT control volume -------------------
709 // Siblings of the three kernels above, reached only through `w.hasGeometry()`. The uncut bodies
710 // are untouched, so a solid-free run is byte-identical by construction.
711
716 const I3 e = e_, n = n_;
717 const int g = g_;
718 SField c = w.colour(), mx = w.planeM(0), my = w.planeM(1), mz = w.planeM(2),
719 al = w.planeAlpha(), ep = w.epsFraction();
720 UCField kd = w.cellKind();
721 const double weps = w.wispEps;
722 using MD = MDRange3<SExec>;
723 for (int comp = 0; comp < 3; ++comp) {
724 const long se = strideOf(comp);
725 const int ec = comp;
726 SField out = cc_[comp];
727 Kokkos::parallel_for(
728 "vof::mom::shifted_colour_cut", MD(SExec(), {g, g, g}, {g + n.x, g + n.y, g + n.z}),
729 KOKKOS_LAMBDA(int x, int y, int z) {
730 const long i = L3(x, y, z, e);
731 const double ea = vofEpsEff(ep(i - se), kd(i - se) == kVofSolid);
732 const double eb = vofEpsEff(ep(i), kd(i) == kVofSolid);
733 const double ecv = 0.5 * (ea + eb);
734 if (!(ecv > 0.0)) {
735 out(i) = 0.0; // the whole control volume is inside the solid
736 return;
737 }
738 double lo[3] = {0.0, 0.0, 0.0}, hi[3] = {1.0, 1.0, 1.0};
739 lo[ec] = 0.5;
740 hi[ec] = 1.0;
741 const double hiHalf = vofCellBox(c, mx, my, mz, al, i - se, lo, hi, weps);
742 lo[ec] = 0.0;
743 hi[ec] = 0.5;
744 const double loHalf = vofCellBox(c, mx, my, mz, al, i, lo, hi, weps);
745 out(i) = (ea * hiHalf + eb * loHalf) / ecv;
746 });
747 }
748 Kokkos::fence();
749 }
750
752 KOKKOS_INLINE_FUNCTION static double cvEps(const SField& ep, const UCField& kd, long i, long se) {
753 return 0.5 *
754 (vofEpsEff(ep(i - se), kd(i - se) == kVofSolid) + vofEpsEff(ep(i), kd(i) == kVofSolid));
755 }
756
760 void momentumFluxesCut(const WyAdvector& w, int d, int comp, double dth) {
761 const I3 e = e_;
762 const int g = g_;
763 const long sd = strideOf(d), se = strideOf(comp);
764 const int dd = d, ec = comp;
765 if (cappedScheme()) {
766 momentumFluxesCutCapped(w, d, comp, dth);
767 return;
768 }
769 const bool muscl = momentumScheme == MomentumScheme::MusclMixed, clamp = clampFluxes;
770 SField c = w.colour(), mx = w.planeM(0), my = w.planeM(1), mz = w.planeM(2),
771 al = w.planeAlpha(), ep = w.epsFraction(), od = w.faceOpenness(d);
772 UCField kd = w.cellKind();
773 const double weps = w.wispEps;
774 SField ud = w.faceVel(d), cvU = vel_[comp], cvC = cc_[comp];
775 SField fc = fluxC_, fu = fluxU_, af = aFace_;
776 int lo3[3] = {g, g, g};
777 const int hi3[3] = {g + n_.x, g + n_.y, g + n_.z};
778 lo3[d] -= 1;
779 long nclamp = 0;
780 Kokkos::parallel_reduce(
781 "vof::mom::flux_cut",
782 MDRange3<SExec>(SExec(), {lo3[0], lo3[1], lo3[2]}, {hi3[0], hi3[1], hi3[2]}),
783 KOKKOS_LAMBDA(int x, int y, int z, long& acc) {
784 const long p = L3(x, y, z, e);
785 // The CV's face open area: the AXIAL face is the cell-centre plane of cell p, so its
786 // fluid area fraction is that cell's fluid VOLUME fraction; a transverse face is the two
787 // half faces of cells p - s_e and p, so it is their average.
788 const double ofac =
789 (dd == ec) ? vofEpsEff(ep(p), kd(p) == kVofSolid) : 0.5 * (od(p - se) + od(p));
790 const double a = 0.5 * (ud(p - se) + ud(p)) * dth;
791 af(p) = ofac * a;
792 if (a == 0.0 || ofac == 0.0) {
793 fc(p) = 0.0;
794 fu(p) = cvU(p);
795 return;
796 }
797 const double aa = a > 0.0 ? a : -a;
798 double lo[3] = {0.0, 0.0, 0.0}, hi[3] = {1.0, 1.0, 1.0};
799 double F;
800 if (dd == ec) {
801 if (a > 0.0) {
802 lo[ec] = 0.5 - aa;
803 hi[ec] = 0.5;
804 } else {
805 lo[ec] = 0.5;
806 hi[ec] = 0.5 + aa;
807 }
808 F = vofCellBox(c, mx, my, mz, al, p, lo, hi, weps);
809 } else {
810 long q;
811 if (a > 0.0) {
812 q = p;
813 lo[dd] = 1.0 - aa;
814 hi[dd] = 1.0;
815 } else {
816 q = p + sd;
817 lo[dd] = 0.0;
818 hi[dd] = aa;
819 }
820 lo[ec] = 0.5;
821 hi[ec] = 1.0;
822 const double ea = vofEpsEff(ep(q - se), kd(q - se) == kVofSolid);
823 const double eb = vofEpsEff(ep(q), kd(q) == kVofSolid);
824 const double ecv = 0.5 * (ea + eb);
825 const double hiHalf = vofCellBox(c, mx, my, mz, al, q - se, lo, hi, weps);
826 lo[ec] = 0.0;
827 hi[ec] = 0.5;
828 const double loHalf = vofCellBox(c, mx, my, mz, al, q, lo, hi, weps);
829 // the same fluid-volume weighting as C^e, renormalized so a uniformly liquid field
830 // gives F = |a| exactly (and hence, times `ofac`, the dilation's own `o|a|`)
831 F = ecv > 0.0 ? (ea * hiHalf + eb * loHalf) / ecv : 0.0;
832 }
833 F *= ofac;
834 if (clamp) {
835 const long don = a > 0.0 ? p : p + sd;
836 const double cd = cvC(don);
837 const double sweep = ofac * aa;
838 const double ecvDon = cvEps(ep, kd, don, se);
839 const double Fc = vofCutFluxClamp(F, sweep, ecvDon, cd);
840 if (Fc != F)
841 ++acc;
842 F = Fc;
843 }
844 if (a < 0.0)
845 F = -F;
846 const long don = a > 0.0 ? p : p + sd;
847 double slope = 0.0;
848 if (muscl)
849 slope = vofMinmod(cvU(don) - cvU(don - sd), cvU(don + sd) - cvU(don));
850 const double sgn = a > 0.0 ? 1.0 : -1.0;
851 fc(p) = F;
852 fu(p) = cvU(don) + sgn * (0.5 - 0.5 * aa) * slope;
853 },
854 nclamp);
855 Kokkos::fence();
856 clamped_ += nclamp;
857 }
858
862 void momentumUpdateCut(const WyAdvector& w, int d, int comp) {
864 momentumUpdateCutPhase(w, d, comp);
865 return;
866 }
867 const I3 e = e_, n = n_;
868 const int g = g_;
869 const long sd = strideOf(d), se = strideOf(comp);
870 const double rg = rhoG_, rl = rhoL_, dr = rhoL_ - rhoG_;
871 const double rmin = rhoG_ < rhoL_ ? rhoG_ : rhoL_;
872 const double fl0 = rhoFloor > 0.0 ? rhoFloor : rhoFloorFrac * rmin;
873 floorUsed_ = fl0;
874 SField cf = cc_[comp], vf = vel_[comp], uf = w.faceVel(comp), ep = w.epsFraction();
875 UCField kd = w.cellKind();
876 SField fc = fluxC_, fu = fluxU_, af = aFace_;
877 UCField fl = flag_[comp];
878 long nfloor = 0;
879 Kokkos::parallel_reduce(
880 "vof::mom::update_cut", MDRange3<SExec>(SExec(), {g, g, g}, {g + n.x, g + n.y, g + n.z}),
881 KOKKOS_LAMBDA(int x, int y, int z, long& acc) {
882 const long i = L3(x, y, z, e);
883 const double ecv = cvEps(ep, kd, i, se);
884 if (!(ecv > 0.0))
885 return; // the control volume is entirely inside the solid
886 const double aP = af(i), aM = af(i - sd);
887 const unsigned char k = fl(i);
888 const double dil = k ? (aP - aM) : 0.0;
889 const double dC = ((fc(i - sd) - fc(i)) + dil) / ecv;
890 const double cNew = cf(i) + dC;
891 cf(i) = cNew;
892 const double uo = vf(i);
893 const double dvM = fu(i - sd) - uo, dvP = fu(i) - uo;
894 const double dilCoef = (k ? rl : rg) * (uf(i - se) - uo) * (aP - aM);
895 const double dev =
896 rg * (aM * dvM - aP * dvP) + dr * (fc(i - sd) * dvM - fc(i) * dvP) + dilCoef;
897 const double rn = vofPhaseRho(rg, rl, cNew);
898 if (rn < fl0)
899 ++acc;
900 vf(i) = uo + dev / (ecv * (rn < fl0 ? fl0 : rn));
901 },
902 nfloor);
903 Kokkos::fence();
904 floored_ += nfloor;
905 }
906
907 // ---- the capped schemes (doc/vof_momentum_second_order.md §4): 'muscl_mixed_capped' and
908 // 'muscl_phase'. Siblings of the kernels above, reached only through `cappedScheme()`; the
909 // 'upwind' and 'muscl_mixed' bodies are untouched, so those schemes are byte-identical.
910
916 const I3 e = e_, n = n_;
917 const int g = g_;
918 for (int comp = 0; comp < 3; ++comp) {
919 SField cf = cc_[comp];
920 UCField fl = flag_[comp];
921 Kokkos::parallel_for(
922 "vof::mom::ghost_flag", MDRange3<SExec>(SExec(), {0, 0, 0}, {e.x, e.y, e.z}),
923 KOKKOS_LAMBDA(int x, int y, int z) {
924 if (x >= g && x < g + n.x && y >= g && y < g + n.y && z >= g && z < g + n.z)
925 return; // inner: frozen by freezeShiftedState
926 const long i = L3(x, y, z, e);
927 fl(i) = cf(i) > 0.5 ? 1u : 0u;
928 });
929 }
930 }
931
936 void momentumFluxesCapped(const WyAdvector& w, int d, int comp, double dth) {
937 const I3 e = e_;
938 const int g = g_;
939 const long sd = strideOf(d), se = strideOf(comp);
940 const int dd = d, ec = comp;
941 const double rg = rhoG_, rl = rhoL_;
942 const bool phase = momentumScheme == MomentumScheme::MusclPhase, clamp = clampFluxes;
943 SField c = w.colour(), mx = w.planeM(0), my = w.planeM(1), mz = w.planeM(2),
944 al = w.planeAlpha();
945 const double weps = w.wispEps;
946 SField ud = w.faceVel(d), cvU = vel_[comp], cvC = cc_[comp];
947 SField fc = fluxC_, fu = fluxU_, fug = fluxUG_, af = aFace_;
948 UCField fl = flag_[comp];
949 int lo3[3] = {g, g, g};
950 const int hi3[3] = {g + n_.x, g + n_.y, g + n_.z};
951 lo3[d] -= 1;
952 VofMomCount cnt;
953 Kokkos::parallel_reduce(
954 "vof::mom::flux_capped",
955 MDRange3<SExec>(SExec(), {lo3[0], lo3[1], lo3[2]}, {hi3[0], hi3[1], hi3[2]}),
956 KOKKOS_LAMBDA(int x, int y, int z, VofMomCount& acc) {
957 const long p = L3(x, y, z, e);
958 const double a = 0.5 * (ud(p - se) + ud(p)) * dth;
959 af(p) = a;
960 if (a == 0.0) {
961 fc(p) = 0.0;
962 fu(p) = cvU(p); // any finite value; the update multiplies it by a == F == 0
963 if (phase)
964 fug(p) = cvU(p);
965 return;
966 }
967 const double aa = a > 0.0 ? a : -a;
968 double lo[3] = {0.0, 0.0, 0.0}, hi[3] = {1.0, 1.0, 1.0};
969 double F;
970 if (dd == ec) {
971 if (a > 0.0) {
972 lo[ec] = 0.5 - aa;
973 hi[ec] = 0.5;
974 } else {
975 lo[ec] = 0.5;
976 hi[ec] = 0.5 + aa;
977 }
978 F = vofCellBox(c, mx, my, mz, al, p, lo, hi, weps);
979 } else {
980 long q;
981 if (a > 0.0) {
982 q = p;
983 lo[dd] = 1.0 - aa;
984 hi[dd] = 1.0;
985 } else {
986 q = p + sd;
987 lo[dd] = 0.0;
988 hi[dd] = aa;
989 }
990 lo[ec] = 0.5;
991 hi[ec] = 1.0;
992 const double hiHalf = vofCellBox(c, mx, my, mz, al, q - se, lo, hi, weps);
993 lo[ec] = 0.0;
994 hi[ec] = 0.5;
995 const double loHalf = vofCellBox(c, mx, my, mz, al, q, lo, hi, weps);
996 F = hiHalf + loHalf;
997 }
998 if (clamp) {
999 const double cd = cvC(a > 0.0 ? p : p + sd);
1000 const double up = aa < cd ? aa : cd;
1001 const double dn = aa - (1.0 - cd);
1002 const double lob = dn > 0.0 ? dn : 0.0;
1003 const double Fc = F > up ? up : (F < lob ? lob : F);
1004 if (Fc != F)
1005 ++acc.clamped;
1006 F = Fc;
1007 }
1008 const double fAbs = F;
1009 if (a < 0.0)
1010 F = -F;
1011 // Donor q, its other face o, and the differences along d (note §4.2, §4.3).
1012 const long q = a > 0.0 ? p : p + sd;
1013 const long o = a > 0.0 ? p - sd : p + sd;
1014 const double s = a > 0.0 ? 1.0 : -1.0;
1015 const double uq = cvU(q);
1016 const double dm = uq - cvU(q - sd), dp = cvU(q + sd) - uq;
1017 const double cq = cvC(q);
1018 double sigL, sigG;
1019 if (phase) {
1020 const double cm = cvC(q - sd), cp = cvC(q + sd);
1021 sigL = vofPhaseSlope(dm, dp, cq >= 0.5, cm >= 0.5, cp >= 0.5);
1022 sigG = vofPhaseSlope(dm, dp, cq <= 0.5, cm <= 0.5, cp <= 0.5);
1023 } else {
1024 sigL = vofMinmod(dm, dp);
1025 sigG = sigL;
1026 }
1027 const double aO = 0.5 * (ud(o - se) + ud(o)) * dth;
1028 const double th =
1029 vofMomentumCap(rg, rl, s, a, a, aO, fAbs, 1.0, cq, fl(q) != 0, dm, dp, sigL, sigG);
1030 if (th < 1.0)
1031 ++acc.capped;
1032 fc(p) = F;
1033 fu(p) = uq + s * (0.5 - 0.5 * aa) * (th * sigL);
1034 if (phase)
1035 fug(p) = uq + s * (0.5 - 0.5 * aa) * (th * sigG);
1036 },
1037 Kokkos::Sum<VofMomCount>(cnt));
1038 Kokkos::fence();
1039 clamped_ += cnt.clamped;
1040 capped_ += cnt.capped;
1041 }
1042
1047 void momentumUpdatePhase(const WyAdvector& w, int d, int comp) {
1048 const I3 e = e_, n = n_;
1049 const int g = g_;
1050 const long sd = strideOf(d), se = strideOf(comp);
1051 const double rg = rhoG_, rl = rhoL_;
1052 const double rmin = rhoG_ < rhoL_ ? rhoG_ : rhoL_;
1053 const double fl0 = rhoFloor > 0.0 ? rhoFloor : rhoFloorFrac * rmin;
1054 floorUsed_ = fl0;
1055 SField cf = cc_[comp], vf = vel_[comp], uf = w.faceVel(comp);
1056 SField fc = fluxC_, fu = fluxU_, fug = fluxUG_, af = aFace_;
1057 UCField fl = flag_[comp];
1058 long nfloor = 0;
1059 Kokkos::parallel_reduce(
1060 "vof::mom::update_phase", MDRange3<SExec>(SExec(), {g, g, g}, {g + n.x, g + n.y, g + n.z}),
1061 KOKKOS_LAMBDA(int x, int y, int z, long& acc) {
1062 const long i = L3(x, y, z, e);
1063 const double aP = af(i), aM = af(i - sd);
1064 const unsigned char k = fl(i);
1065 const double dil = k ? (aP - aM) : 0.0;
1066 const double dC = (fc(i - sd) - fc(i)) + dil;
1067 const double cNew = cf(i) + dC;
1068 cf(i) = cNew;
1069 const double uo = vf(i);
1070 const double fM = fc(i - sd), fP = fc(i);
1071 const double dvLM = fu(i - sd) - uo, dvLP = fu(i) - uo;
1072 const double dvGM = fug(i - sd) - uo, dvGP = fug(i) - uo;
1073 const double dilCoef = (k ? rl : rg) * (uf(i - se) - uo) * (aP - aM);
1074 const double dev =
1075 rg * ((aM - fM) * dvGM - (aP - fP) * dvGP) + rl * (fM * dvLM - fP * dvLP) + dilCoef;
1076 const double rn = vofPhaseRho(rg, rl, cNew);
1077 if (rn < fl0)
1078 ++acc;
1079 vf(i) = uo + dev / (rn < fl0 ? fl0 : rn);
1080 },
1081 nfloor);
1082 Kokkos::fence();
1083 floored_ += nfloor;
1084 }
1085
1088 void momentumFluxesCutCapped(const WyAdvector& w, int d, int comp, double dth) {
1089 const I3 e = e_;
1090 const int g = g_;
1091 const long sd = strideOf(d), se = strideOf(comp);
1092 const int dd = d, ec = comp;
1093 const double rg = rhoG_, rl = rhoL_;
1094 const bool phase = momentumScheme == MomentumScheme::MusclPhase, clamp = clampFluxes;
1095 SField c = w.colour(), mx = w.planeM(0), my = w.planeM(1), mz = w.planeM(2),
1096 al = w.planeAlpha(), ep = w.epsFraction(), od = w.faceOpenness(d);
1097 UCField kd = w.cellKind();
1098 const double weps = w.wispEps;
1099 SField ud = w.faceVel(d), cvU = vel_[comp], cvC = cc_[comp];
1100 SField fc = fluxC_, fu = fluxU_, fug = fluxUG_, af = aFace_;
1101 UCField fl = flag_[comp];
1102 int lo3[3] = {g, g, g};
1103 const int hi3[3] = {g + n_.x, g + n_.y, g + n_.z};
1104 lo3[d] -= 1;
1105 VofMomCount cnt;
1106 Kokkos::parallel_reduce(
1107 "vof::mom::flux_cut_capped",
1108 MDRange3<SExec>(SExec(), {lo3[0], lo3[1], lo3[2]}, {hi3[0], hi3[1], hi3[2]}),
1109 KOKKOS_LAMBDA(int x, int y, int z, VofMomCount& acc) {
1110 const long p = L3(x, y, z, e);
1111 const double ofac =
1112 (dd == ec) ? vofEpsEff(ep(p), kd(p) == kVofSolid) : 0.5 * (od(p - se) + od(p));
1113 const double a = 0.5 * (ud(p - se) + ud(p)) * dth;
1114 af(p) = ofac * a;
1115 if (a == 0.0 || ofac == 0.0) {
1116 fc(p) = 0.0;
1117 fu(p) = cvU(p);
1118 if (phase)
1119 fug(p) = cvU(p);
1120 return;
1121 }
1122 const double aa = a > 0.0 ? a : -a;
1123 double lo[3] = {0.0, 0.0, 0.0}, hi[3] = {1.0, 1.0, 1.0};
1124 double F;
1125 if (dd == ec) {
1126 if (a > 0.0) {
1127 lo[ec] = 0.5 - aa;
1128 hi[ec] = 0.5;
1129 } else {
1130 lo[ec] = 0.5;
1131 hi[ec] = 0.5 + aa;
1132 }
1133 F = vofCellBox(c, mx, my, mz, al, p, lo, hi, weps);
1134 } else {
1135 long q;
1136 if (a > 0.0) {
1137 q = p;
1138 lo[dd] = 1.0 - aa;
1139 hi[dd] = 1.0;
1140 } else {
1141 q = p + sd;
1142 lo[dd] = 0.0;
1143 hi[dd] = aa;
1144 }
1145 lo[ec] = 0.5;
1146 hi[ec] = 1.0;
1147 const double ea = vofEpsEff(ep(q - se), kd(q - se) == kVofSolid);
1148 const double eb = vofEpsEff(ep(q), kd(q) == kVofSolid);
1149 const double ecv = 0.5 * (ea + eb);
1150 const double hiHalf = vofCellBox(c, mx, my, mz, al, q - se, lo, hi, weps);
1151 lo[ec] = 0.0;
1152 hi[ec] = 0.5;
1153 const double loHalf = vofCellBox(c, mx, my, mz, al, q, lo, hi, weps);
1154 F = ecv > 0.0 ? (ea * hiHalf + eb * loHalf) / ecv : 0.0;
1155 }
1156 F *= ofac;
1157 if (clamp) {
1158 const long don = a > 0.0 ? p : p + sd;
1159 const double cd = cvC(don);
1160 const double sweep = ofac * aa;
1161 const double ecvDon = cvEps(ep, kd, don, se);
1162 const double Fc = vofCutFluxClamp(F, sweep, ecvDon, cd);
1163 if (Fc != F)
1164 ++acc.clamped;
1165 F = Fc;
1166 }
1167 const double fAbs = F;
1168 if (a < 0.0)
1169 F = -F;
1170 const long q = a > 0.0 ? p : p + sd;
1171 const long o = a > 0.0 ? p - sd : p + sd;
1172 const double s = a > 0.0 ? 1.0 : -1.0;
1173 const double uq = cvU(q);
1174 const double dm = uq - cvU(q - sd), dp = cvU(q + sd) - uq;
1175 const double cq = cvC(q), eq = cvEps(ep, kd, q, se);
1176 double sigL, sigG;
1177 if (phase) {
1178 const double cm = cvC(q - sd), cp = cvC(q + sd);
1179 const bool fm = cvEps(ep, kd, q - sd, se) > 0.0, fp = cvEps(ep, kd, q + sd, se) > 0.0;
1180 const bool fq = eq > 0.0;
1181 sigL = vofPhaseSlope(dm, dp, fq && cq >= 0.5, fm && cm >= 0.5, fp && cp >= 0.5);
1182 sigG = vofPhaseSlope(dm, dp, fq && cq <= 0.5, fm && cm <= 0.5, fp && cp <= 0.5);
1183 } else {
1184 sigL = vofMinmod(dm, dp);
1185 sigG = sigL;
1186 }
1187 // The other face's Courant numbers, by exactly the expressions that produce `af` there.
1188 const double aO = 0.5 * (ud(o - se) + ud(o)) * dth;
1189 const double ofacO =
1190 (dd == ec) ? vofEpsEff(ep(o), kd(o) == kVofSolid) : 0.5 * (od(o - se) + od(o));
1191 const double th = vofMomentumCap(rg, rl, s, a, ofac * a, ofacO * aO, fAbs, eq, cq,
1192 fl(q) != 0, dm, dp, sigL, sigG);
1193 if (th < 1.0)
1194 ++acc.capped;
1195 fc(p) = F;
1196 fu(p) = uq + s * (0.5 - 0.5 * aa) * (th * sigL);
1197 if (phase)
1198 fug(p) = uq + s * (0.5 - 0.5 * aa) * (th * sigG);
1199 },
1200 Kokkos::Sum<VofMomCount>(cnt));
1201 Kokkos::fence();
1202 clamped_ += cnt.clamped;
1203 capped_ += cnt.capped;
1204 }
1205
1208 void momentumUpdateCutPhase(const WyAdvector& w, int d, int comp) {
1209 const I3 e = e_, n = n_;
1210 const int g = g_;
1211 const long sd = strideOf(d), se = strideOf(comp);
1212 const double rg = rhoG_, rl = rhoL_;
1213 const double rmin = rhoG_ < rhoL_ ? rhoG_ : rhoL_;
1214 const double fl0 = rhoFloor > 0.0 ? rhoFloor : rhoFloorFrac * rmin;
1215 floorUsed_ = fl0;
1216 SField cf = cc_[comp], vf = vel_[comp], uf = w.faceVel(comp), ep = w.epsFraction();
1217 UCField kd = w.cellKind();
1218 SField fc = fluxC_, fu = fluxU_, fug = fluxUG_, af = aFace_;
1219 UCField fl = flag_[comp];
1220 long nfloor = 0;
1221 Kokkos::parallel_reduce(
1222 "vof::mom::update_cut_phase",
1223 MDRange3<SExec>(SExec(), {g, g, g}, {g + n.x, g + n.y, g + n.z}),
1224 KOKKOS_LAMBDA(int x, int y, int z, long& acc) {
1225 const long i = L3(x, y, z, e);
1226 const double ecv = cvEps(ep, kd, i, se);
1227 if (!(ecv > 0.0))
1228 return; // the control volume is entirely inside the solid
1229 const double aP = af(i), aM = af(i - sd);
1230 const unsigned char k = fl(i);
1231 const double dil = k ? (aP - aM) : 0.0;
1232 const double dC = ((fc(i - sd) - fc(i)) + dil) / ecv;
1233 const double cNew = cf(i) + dC;
1234 cf(i) = cNew;
1235 const double uo = vf(i);
1236 const double fM = fc(i - sd), fP = fc(i);
1237 const double dvLM = fu(i - sd) - uo, dvLP = fu(i) - uo;
1238 const double dvGM = fug(i - sd) - uo, dvGP = fug(i) - uo;
1239 const double dilCoef = (k ? rl : rg) * (uf(i - se) - uo) * (aP - aM);
1240 const double dev =
1241 rg * ((aM - fM) * dvGM - (aP - fP) * dvGP) + rl * (fM * dvLM - fP * dvLP) + dilCoef;
1242 const double rn = vofPhaseRho(rg, rl, cNew);
1243 if (rn < fl0)
1244 ++acc;
1245 vf(i) = uo + dev / (ecv * (rn < fl0 ? fl0 : rn));
1246 },
1247 nfloor);
1248 Kokkos::fence();
1249 floored_ += nfloor;
1250 }
1251
1252 long strideOf(int d) const {
1253 return d == 0 ? 1 : (d == 1 ? static_cast<long>(e_.x) : static_cast<long>(e_.x) * e_.y);
1254 }
1255
1256 private:
1257 I3 n_{0, 0, 0}, e_{0, 0, 0};
1258 int g_ = 3;
1259 long len_ = 0;
1260 double rhoG_ = 1.0, rhoL_ = 1.0, floorUsed_ = 0.0;
1261 long floored_ = 0, clamped_ = 0, capped_ = 0;
1262 double seedM_[3] = {0, 0, 0};
1263 SField cc_[3], vel_[3], fluxC_, fluxU_, fluxUG_, aFace_;
1264 UCField flag_[3];
1265};
1266
1267} // namespace peclet::flow::vof
1268
1269#endif // PECLET_FLOW_VOF_MOMENTUM_ADVECT_HPP
flow — VoF rung V1: Weymouth & Yue (2010) directionally-split, exactly volume-conserving geometric ad...
Momentum-consistent companion to WyAdvector.
bool clampFluxes
Ablation: drop the Weymouth flux clamp of point 3 (the raw geometric flux).
void momentumUpdate(const WyAdvector &w, int d, int comp)
C^e_i += (F_- - F_+) + flag (a_+ - a_-) and M_i += (G_- - G_+) + rho^ u^n_i (a_+ - a_-),...
double rhoFloor
Floor on rho^e in the recovery divide, in the same units as the phase densities.
void freezeShiftedState(const WyAdvector &w)
Freeze flag^e = H(C^{e,n} - 1/2) and seed M = rho^e u^n_e.
void momentumFluxesCut(const WyAdvector &w, int d, int comp, double dth)
Face Courant number, geometric liquid flux and momentum flux on a CUT shifted CV.
void momentumFluxesCapped(const WyAdvector &w, int d, int comp, double dth)
momentumFluxes for the capped schemes: the same a and clamped F, then the slopes of note §4....
SField advectedVelocity(int e) const
The advected velocity of component e, indexed exactly like the solver's u_e (inner cells).
void momentumUpdateCutPhase(const WyAdvector &w, int d, int comp)
momentumUpdateCut for 'muscl_phase': the per-phase dev of momentumUpdatePhase, divided by the CV's fl...
void momentumFluxes(const WyAdvector &w, int d, int comp, double dth)
Face Courant number, geometric liquid flux and momentum flux of the shifted CV of component comp,...
void freezeGhostFlags()
The frozen flag on the GHOST shell of every component, H(C^{e,n} - 1/2) from the exchanged shifted co...
MomentumScheme momentumScheme
The transported face velocity of the momentum flux; MusclPhase by default (note §12).
bool useCellDilationFlag
Ablation: use the PRESSURE-cell frozen dilation flag H(C^n - 1/2) on the shifted CV instead of the st...
void momentumUpdateCut(const WyAdvector &w, int d, int comp)
The cut update: both increments divided by the CV's fluid volume, everything else identical — in part...
void buildShiftedColour(const WyAdvector &w)
C^e(i) = slab(cell i-s_e, e, [1/2,1]) + slab(cell i, e, [0,1/2]), over the inner region.
void setPhaseDensities(double rhoG, double rhoL)
long cappedFaces() const
Faces whose slope the mass-aware cap scaled in the last step (capped schemes only).
void momentumUpdatePhase(const WyAdvector &w, int d, int comp)
momentumUpdate for 'muscl_phase' (note §4.4): each phase's mass flux carries its own face velocity; e...
static double cvEps(const SField &ep, const UCField &kd, long i, long se)
The CV's fluid volume eps^e(i) (0 when the whole CV is solid).
void advect(WyAdvector &w, double dt, long step)
One momentum-consistent Weymouth-Yue step: advances BOTH the colour field inside w and the half-shift...
void momentumFluxesCutCapped(const WyAdvector &w, int d, int comp, double dth)
momentumFluxesCut for the capped schemes: masses in cell-volume units (eps_q, at, F openness-weighted...
void init(const WyAdvector &w, double rhoG, double rhoL)
SField shiftedColour(int e) const
The half-shifted colour of component e, same indexing.
void buildShiftedColourCut(const WyAdvector &w)
C^e = [eps(i-s_e) slabHi(i-s_e) + eps(i) slabLo(i)] / eps^e(i) — each half cell's PLIC slab weighted ...
Weymouth-Yue split advection of a colour field on an extended (inner + ghost) block.
flow — thin shim: the container-free VoF cut-cell colour-transport rules (rung V5a) now live in core.
double vofMomentumCap(double rg, double rl, double s, double aGeo, double atP, double atO, double fAbs, double epsQ, double cQ, bool kQ, double dm, double dp, double sigL, double sigG)
The mass-aware cap theta in (0, 1] of note §4.3, for face p of donor q.
Kokkos::View< unsigned char *, SMem > UCField
Definition advect_wy.hpp:89
constexpr int kWySweepPerm[6][3]
The six permutations of (x, y, z), cycled by step index so no direction is systematically favoured (p...
bool wyIsMixed(double c)
The mixed-cell predicate.
Definition advect_wy.hpp:95
double vofPhaseRho(double rhoG, double rhoL, double c)
Two-phase density from a fraction, written so that C = 1 returns rho_l and C = 0 returns rho_g EXACTL...
double vofMinmod(double a, double b)
MomentumScheme
The transported face velocity of the momentum flux (doc/vof_momentum_second_order....
double vofCellBox(const SField &c, const SField &mx, const SField &my, const SField &mz, const SField &al, long q, const double lo[3], const double hi[3], double eps=0.0)
Liquid volume of the PLIC polyhedron of cell q inside a box given as per-axis intervals,...
double vofPhaseSlope(double dm, double dp, bool hq, bool hm, bool hp)
The interface-biased, MC-bounded slope of one phase (note §4.2).
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).
Definition policy.hpp:36
Kokkos::View< double *, SMem > SField
long L3(int x, int y, int z, I3 e)
Kokkos::DefaultExecutionSpace SExec
Definition sweep.py:1
flow — the multidimensional iteration policies: iteration order follows storage.
long clamped
fluxes Weymouth's admissible interval had to clamp, last step
long floored
inner CVs where the rho^e floor bit in the last recovery
long capped
faces whose slope the mass-aware cap scaled (theta < 1), last step
double sumM0[3]
the same sum at the START of the last advection (seeding)
double sumM[3]
sum of rho^e u_e over inner CVs AFTER the last advection
The two face counters of the capped flux kernels, one reduction (never a second fence).
VofMomCount & operator+=(const VofMomCount &o)
long capped
faces with theta < 1
static constexpr double F
static double perm(const std::vector< double > &gsdf, const BlockDecomposer< 3 > &dec, int rank, bool amg, int levels, MPI_Comm comm)
static constexpr double R
Kokkos::View< double *, SMem > SField