flow 1.4.0
Kokkos cut-cell IBM incompressible Navier-Stokes solver + pnm pore extraction
Loading...
Searching...
No Matches
flow_ibm_vof.hpp
Go to the documentation of this file.
1
9#ifndef PECLET_FLOW_FLOW_IBM_VOF_HPP
10#define PECLET_FLOW_FLOW_IBM_VOF_HPP
11
12namespace peclet::flow {
13
19inline constexpr const char* kVofMomBlocksMsg =
20 "enable_vof_momentum and enable_vof_blocks* are not composable: momentum-consistent transport "
21 "advects rho*u with the geometric fluxes of the ONE structured colour field (at the head of "
22 "step()) and skips the colour stage that advects the block markers, so the markers would never "
23 "move and the momentum fluxes would not be theirs. Use the structured colour field with "
24 "enable_vof_momentum, or the block container without it.";
25
26template <class Grid>
28 vofTiming_ = on;
29 vofAdv_.timingOn = on;
30 vofCurv_.timingOn = on;
31 if (vofBlocks_)
32 vofBlocks_->timingOn = on;
34}
35
36template <class Grid>
38 return vofTiming_;
39}
40
41template <class Grid>
43 vt_ = VofTiming();
44 vofAdv_.resetTiming();
45 vofCurv_.resetTiming();
46 if (vofBlocks_) {
47 vofBlocks_->debrisSeconds = 0.0;
48 vofBlocks_->debrisCalls = 0;
49 }
50 tStepSum_ = tPredSum_ = tMomSum_ = tProjSum_ = 0.0;
51}
52
53template <class Grid>
55 return vt_;
56}
57
58template <class Grid>
60 return vofAdv_.timing();
61}
62
63template <class Grid>
65 return vofCurv_.timing();
66}
67
68template <class Grid>
70 vofCurv_.useWorklist = on;
71}
72
73template <class Grid>
75 return vofCurv_.useWorklist;
76}
77
78template <class Grid>
80 return tStepSum_;
81}
82
83template <class Grid>
85 return tPredSum_;
86}
87
88template <class Grid>
90 return tMomSum_;
91}
92
93template <class Grid>
95 return tProjSum_;
96}
97
98template <class Grid>
100 vofAdv_.useWorklist = on;
101}
102
103template <class Grid>
105 return vofAdv_.useWorklist;
106}
107
108template <class Grid>
110 vofAdv_.init(nx_, ny_, nz_, 1.0, kVofG); // h = 1: flow works in cell units
111 vofAdv_.cflLimit = vofCflLimit_;
112 vofAdv_.interfaceLocalCfl = true; // WO-J item 4 — see maxCourantInterface()
113 const I3 e3 = vofAdv_.extent();
114 e3_ = C3{e3.x, e3.y, e3.z};
115 vofAdv_.exchange = [this](CCField f) { this->vofFillGhosts(f); };
116 vofAdv_.globalMax = nullptr;
117#ifdef PECLET_FLOW_MPI
118 if (distributed_ && dec_) {
119 int rank = 0;
120 MPI_Comm_rank(comm_, &rank);
121 // Periodic on all three axes, exactly like the velocity halo: the halo owns every interior
122 // ghost and wraps the global boundary, and vofFillGhosts then overwrites the out-of-domain
123 // ghosts of any non-periodic axis with the globally-clamped value.
124 std::array<bool, 3> per{true, true, true};
125 vofHalo_ = std::make_shared<GridHaloTopology<3>>();
126 vofHalo_->buildTopology(*dec_, rank, kVofG, per, comm_);
127 vofDev_ = std::make_shared<GridHalo<double>>();
128 vofDev_->setLabel("vof g3");
129 vofDev_->init(*vofHalo_);
130 MPI_Comm cm = comm_;
131 vofAdv_.globalMax = [cm](double v) {
132 double r = v;
133 MPI_Allreduce(&v, &r, 1, MPI_DOUBLE, MPI_MAX, cm);
134 return r;
135 };
136 }
137#endif
138 buildVofGeometry(); // rung V5a (WO-Q): openness + fluid fraction on the colour block
139 // WO-R: the out-of-domain mask and the resampled boundary-colour profiles are properties of
140 // THIS block, so they are (re)built with it — and the mask is only INSTALLED on the advector
141 // when a VoF boundary colour has actually been set, which is what keeps the V1 flux path
142 // bit-identical otherwise (gate G5).
144 // The half-shifted momentum CVs live on this same block, so they are rebuilt with it.
145 vofCurv_.init(nx_, ny_, nz_, kVofG);
146 if (vofMomEnabled_) {
147 vofMom_.init(vofAdv_, vofRhoG_, vofRhoL_);
148 for (int c = 0; c < 3; ++c)
149 if (uAdv_[c].extent(0) != n_)
150 uAdv_[c] = CCField("uAdv", n_);
151 }
152 // The other drivers that live on THIS block and are initialised lazily: their own `ready()` /
153 // `initialized()` predicates ask "has init run", not "is it the right size", so a
154 // re-decomposition has to re-init them here or they keep the previous block's allocations
155 // while every kernel indexes them with the new `e3_`.
156 const std::size_t blockLen = (std::size_t)e3_.x * e3_.y * e3_.z;
157 if (pcAreaC_.ready() && pcAreaC_.area().extent(0) != blockLen)
158 pcAreaC_.init(nx_, ny_, nz_, kVofG);
159 if (pcAreaMc_.ready() && pcAreaMc_.area().extent(0) != blockLen)
160 pcAreaMc_.init(nx_, ny_, nz_, kVofG);
161 if (vofEnergy_.initialized() && vofEnergy_.temperature().extent(0) != blockLen)
162 vofEnergy_.init(vofAdv_, pcRcpG_, pcRcpL_);
163 bindVofBlockPatch(); // rung W0: the block exchange's Views were just reallocated
164}
165
166template <class Grid>
168 if (!vofEnabled_ || !contactAngleSet_)
169 return 0;
170 int m = 0;
171 for (int f = 0; f < 6; ++f)
172 if (bc_[f] == 1 || bc_[f] == 4)
173 m |= (1 << f);
174 return m;
175}
176
177template <class Grid>
178KOKKOS_INLINE_FUNCTION double Solver<Grid>::vofWallPlaneSdf(int gx, int gy, int gz, I3 gs,
179 int mask) {
180 const int gi[3] = {gx, gy, gz};
181 const int q[3] = {gs.x, gs.y, gs.z};
182 double d = 1e30;
183 for (int a = 0; a < 3; ++a) {
184 const double c = (double)gi[a] + 0.5;
185 if (mask & (1 << (2 * a)))
186 d = Kokkos::fmin(d, c);
187 if (mask & (1 << (2 * a + 1)))
188 d = Kokkos::fmin(d, (double)q[a] - c);
189 }
190 return d;
191}
192
193template <class Grid>
195 if (!vofEnabled_)
196 return;
197 const int wet = vofWetWallMask();
198 if ((!hasSolid_ || !cutcellPressure_) && !wet) {
199 vofAdv_.disableGeometry(); // all-fluid: the V1 kernels run byte-identically
200 vofAdv_.disableWetting();
201 vofSolidG2_ = CCField();
202 return;
203 }
204 if (wet && !cutcellPressure_)
205 throw std::runtime_error(
206 "set_contact_angle: a wetting DOMAIN wall (bc type 1/4) needs a cut-cell pressure "
207 "operator, because the colour transport weights its geometric fluxes with the face "
208 "openness. Build one with set_pressure_geometry(all_fluid_sdf) (all-fluid) or "
209 "set_solid(sdf, cutcell_pressure=True).");
210 vofAdv_.enableGeometry();
211 if (hasSolid_ && cutcellPressure_) {
212 if (vofCs_.extent(0) != n_)
213 vofCs_ = CCField("vofCs", n_);
214 buildCellFraction(vofCs_, CCConst(sdf_), e_,
215 G); // inner region; ghosts come from the exchange
216 copyInner(vofAdv_.epsFraction(), e3_, kVofG, CCConst(vofCs_), e_, G);
217 vofExchangeRaw(vofAdv_.epsFraction());
218 CCField oa[3] = {ox_, oy_, oz_};
219 for (int d = 0; d < 3; ++d) {
220 vof::copyFaceVelocity(vofAdv_.faceOpenness(d), I3{e3_.x, e3_.y, e3_.z}, kVofG, oa[d],
221 I3{e_.x, e_.y, e_.z}, G, d);
222 vofExchangeRaw(vofAdv_.faceOpenness(d));
223 }
224 } else {
225 // Domain walls only: the trivial geometry (every cell whole, every face open) is exactly
226 // what the uncut kernels compute, and `applyDomainWallGeometry` then closes the band.
227 Kokkos::deep_copy(vofAdv_.epsFraction(), 1.0);
228 for (int d = 0; d < 3; ++d)
229 Kokkos::deep_copy(vofAdv_.faceOpenness(d), 1.0);
230 }
231 if (wet)
233 vofAdv_.classifyGeometry();
234 vofExchangeRaw(vofAdv_.kindDouble()); // the owner's classification into every ghost layer
235 // ISSUES sweep item 3: that exchange ends in `clampFill`, whose zero-gradient copy would set
236 // the out-of-domain band back to the first INNER cell's classification (fluid) -- the band
237 // is the one region with no owner, so it has to be re-imposed here. Without this the whole
238 // domain-wall fill is silently inert (measured: contact census 0, equilibrium ~141 deg at
239 // every prescribed angle, i.e. the perfectly non-wetting empty band).
240 if (wet)
242 vofAdv_.finalizeGeometry();
243 // The G=2 mirror of the classification: the canonical "C" field reports EXACTLY 0 in solid
244 // cells (gate G2), while the g=3 working block carries the neutral band fill that the MYC and
245 // height-function stencils need. The fill is regenerated deterministically by every
246 // `vofFillGhosts`, so nothing is lost by not persisting it.
247 if (vofSolidG2_.extent(0) != n_)
248 vofSolidG2_ = CCField("vofSolidG2", n_);
249 copyInner(vofSolidG2_, e_, G, CCConst(vofAdv_.kindDouble()), e3_, kVofG);
250 applyContactAngle(); // rung V5b (WO-S): re-wire the theta field / wall SDF onto the new block
252}
253
254template <class Grid>
256 const I3 gs = vofGlobalSize(), org = vofOrigin();
257 const C3 e = e3_;
258 const int g = kVofG, mk = mask;
259 CCField ep = vofAdv_.epsFraction();
260 CCField of[3] = {vofAdv_.faceOpenness(0), vofAdv_.faceOpenness(1), vofAdv_.faceOpenness(2)};
261 CCField ofx = of[0], ofy = of[1], ofz = of[2];
262 Kokkos::parallel_for(
263 "peclet::flow::vof_domain_wall_geom", MDRange3<CCExec>(CCExec(), {0, 0, 0}, {e.x, e.y, e.z}),
264 KOKKOS_LAMBDA(int x, int y, int z) {
265 const long i = (long)x + (long)y * e.x + (long)z * (long)e.x * e.y;
266 const int gx = x - g + org.x, gy = y - g + org.y, gz = z - g + org.z;
267 auto inside = [&](int ax, int ay, int az) {
268 const int gi[3] = {ax, ay, az};
269 const int q[3] = {gs.x, gs.y, gs.z};
270 for (int a = 0; a < 3; ++a) {
271 if ((mk & (1 << (2 * a))) && gi[a] < 0)
272 return false;
273 if ((mk & (1 << (2 * a + 1))) && gi[a] >= q[a])
274 return false;
275 }
276 return true;
277 };
278 const bool in0 = inside(gx, gy, gz);
279 if (!in0)
280 ep(i) = 0.0;
281 // the advector's HIGH-face convention: of[d](i) is the +d face of cell i
282 if (!in0 || !inside(gx + 1, gy, gz))
283 ofx(i) = 0.0;
284 if (!in0 || !inside(gx, gy + 1, gz))
285 ofy(i) = 0.0;
286 if (!in0 || !inside(gx, gy, gz + 1))
287 ofz(i) = 0.0;
288 });
289 CCExec().fence();
290}
291
292template <class Grid>
294 const I3 gs = vofGlobalSize(), org = vofOrigin();
295 const C3 e = e3_;
296 const int g = kVofG, mk = mask;
297 CCField kd = vofAdv_.kindDouble();
298 Kokkos::parallel_for(
299 "peclet::flow::vof_domain_wall_kind", MDRange3<CCExec>(CCExec(), {0, 0, 0}, {e.x, e.y, e.z}),
300 KOKKOS_LAMBDA(int x, int y, int z) {
301 const long i = (long)x + (long)y * e.x + (long)z * (long)e.x * e.y;
302 const int gi[3] = {x - g + org.x, y - g + org.y, z - g + org.z};
303 const int q[3] = {gs.x, gs.y, gs.z};
304 for (int a = 0; a < 3; ++a) {
305 if (((mk & (1 << (2 * a))) && gi[a] < 0) ||
306 ((mk & (1 << (2 * a + 1))) && gi[a] >= q[a])) {
307 kd(i) = 1.0;
308 return;
309 }
310 }
311 });
312 CCExec().fence();
313}
314
315template <class Grid>
317 const I3 gs = vofGlobalSize(), org = vofOrigin();
318 const C3 e = e3_;
319 const int g = kVofG;
320 for (int a = 0; a < 3; ++a)
321 for (int sd = 0; sd < 2; ++sd) {
322 if (!(mask & (1 << (2 * a + sd))))
323 continue;
324 const int q = (a == 0) ? gs.x : (a == 1) ? gs.y : gs.z;
325 const int o = (a == 0) ? org.x : (a == 1) ? org.y : org.z;
326 // block-local index of the depth-3 and depth-2 layers on this face
327 const int i3 = (sd == 0) ? (-3 - o + g) : (q - o + g + 2);
328 const int i2 = (sd == 0) ? (-2 - o + g) : (q - o + g + 1);
329 const int dims[3] = {e.x, e.y, e.z};
330 if (i3 < 0 || i3 >= dims[a] || i2 < 0 || i2 >= dims[a])
331 continue; // this rank's block does not own that face
332 const long st[3] = {1, (long)e.x, (long)e.x * (long)e.y};
333 const int b = (a + 1) % 3, c = (a + 2) % 3;
334 const long sa = st[a], sb = st[b], sc = st[c];
335 CCField ff = f;
336 Kokkos::parallel_for(
337 "peclet::flow::vof_extend_wall_band",
338 MDRange2<CCExec>(CCExec(), {0, 0}, {dims[b], dims[c]}), KOKKOS_LAMBDA(int p0, int p1) {
339 const long base = (long)p0 * sb + (long)p1 * sc;
340 ff(base + (long)i3 * sa) = ff(base + (long)i2 * sa);
341 });
342 }
343 CCExec().fence();
344}
345
346template <class Grid>
348 if (!vofEnabled_ || !vofAdv_.hasGeometry() || !vofSolidG2_.extent(0) || !vofSolidZero_)
349 return;
350 // `vofSolidG2_` lives on the EXTENDED G=2 block (copyInner wrote it at (x+G, y+G, z+G)), so it
351 // is indexed exactly like cField_ — indexing it as an inner-sized array reads the wrong cells
352 // and silently zeroes live fluid colour (measured: 0.5 % of the liquid volume lost per step).
353 CCField c = cField_;
354 CCConst sl = CCConst(vofSolidG2_);
355 const int ex = e_.x, ey = e_.y, g = G;
356 Kokkos::parallel_for(
357 "peclet::flow::vof_zero_solid", MDRange3<CCExec>(CCExec(), {0, 0, 0}, {nx_, ny_, nz_}),
358 KOKKOS_LAMBDA(int x, int y, int z) {
359 const long i = (long)(x + g) + (long)(y + g) * ex + (long)(z + g) * (long)ex * ey;
360 if (sl(i) > 0.5)
361 c(i) = 0.0;
362 });
363 CCExec().fence();
364}
365
366template <class Grid>
368 return bc_[2 * a] == 0 && bc_[2 * a + 1] == 0;
369}
370
371template <class Grid>
374 // Rung V5a (WO-Q): the neutral (90 deg) solid-band fill, for the COLOUR field only. It is a
375 // stencil device, not transported data — the MYC 3^3 stencil and the V3 height-function
376 // columns of a near-wall cell reach into the solid, and leaving those cells at 0 makes every
377 // wall perfectly non-wetting. Three passes with a shrinking depth budget (`vof/cutcell.hpp`),
378 // then a SECOND exchange so the outermost ghost layer holds its owner's filled value (the
379 // passes only reach ghost depth 2, and the curvature cascade reads depth 3).
380 if (vofAdv_.hasGeometry() && f.data() == vofAdv_.colour().data()) {
381 // Rung V5b (WO-S): the theta-consistent pass 1 reads the FLUID-ONLY Youngs normal of the
382 // anchor fluid cell, which the pass may reach at ghost depth 3 — one deeper than a 3^3
383 // stencil can be evaluated on this block. Build it on the INNER region and run it through
384 // the block's own ghost policy, exactly as the geometry classification is: every read the
385 // theta pass then makes is the OWNER's value, which is what keeps the inner fill
386 // decomposition-independent.
387 if (vofAdv_.hasWetting()) {
388 vofAdv_.buildWettingNormals();
389 for (int d = 0; d < 3; ++d)
390 vofExchangeRaw(vofAdv_.wettingNormal(d));
391 // Rung V6 (WO-V6): produce the theta FIELD the pass is about to read. Pass A measures the
392 // apparent angle and the raw contact-line speed at ghost depth <= 2 from already-exchanged
393 // data; both are then exchanged so the 3-point in-wall smoothing of pass B, which reaches
394 // depth 3, reads the OWNER's values — the same argument that makes the V5b fill bitwise
395 // across np. Five extra exchanges per fill (three velocity components + two measurements),
396 // skipped entirely when no dynamic angle is configured.
397 if (vofDyn_.active() && vofDyn_.allocated()) {
399 vofDyn_.sigma = effectiveContactSigma();
400 if (!(vofDyn_.sigma > 0.0) && vofDyn_.dynamic && !contactSigmaWarned_) {
401 contactSigmaWarned_ = true;
402 std::fprintf(stderr,
403 "peclet.flow: set_contact_angle_dynamic is active but sigma is 0 "
404 "(no set_surface_tension and no explicit sigma) - Ca_cl is 0 and the "
405 "Cox-Voinov correction is inert.\n");
406 }
407 vofDyn_.measure(vofAdv_);
408 vofExchangeRaw(vofDyn_.uclRaw());
409 vofExchangeRaw(vofDyn_.valid());
410 vofDyn_.impose(vofAdv_);
411 }
412 }
413 vofAdv_.solidBandFill();
414 if (const int wet = vofWetWallMask())
415 vofExtendWallBand(f, wet); // ISSUES sweep item 3: the depth-3 layer no pass can write
417 }
418}
419
420template <class Grid>
422 const bool px = vofAxisPeriodic(0), py = vofAxisPeriodic(1), pz = vofAxisPeriodic(2);
423#ifdef PECLET_FLOW_MPI
424 if (distributed_ && vofDev_)
425 vofDev_->exchange(f);
426 else
427#endif
428 vof::periodicFill(f, I3{e3_.x, e3_.y, e3_.z}, kVofG, px, py, pz);
429 if (px && py && pz)
430 return;
431 const I3 gs = vofGlobalSize(), org = vofOrigin();
432 // ISSUES sweep item 3: the theta band of a wetting DOMAIN wall lives in exactly the ghost
433 // cells `clampFill` would overwrite with the zero-gradient copy, so the colour field skips
434 // the clamp there and `vofFillGhosts` owns that band instead. 0 for every other field and
435 // for every configuration without a domain-wall contact angle -> byte-identical.
436 const int skip = (f.data() == vofAdv_.colour().data()) ? vofWetWallMask() : 0;
437 vof::clampFill(f, I3{e3_.x, e3_.y, e3_.z}, kVofG, org, gs, px, py, pz, skip);
438 vofApplyColourBc(f); // WO-R: inflow / inletOutlet backflow; a no-op unless one is set
439}
440
441template <class Grid>
443#ifdef PECLET_FLOW_MPI
444 if (distributed_)
445 return I3{gnx_, gny_, gnz_};
446#endif
447 return I3{nx_, ny_, nz_};
448}
449
450template <class Grid>
452 return I3{og_.x, og_.y, og_.z};
453}
454
455template <class Grid>
457 // Rung V8 (WO-T): on the collocated grid the divergence-free field is the PROJECTED MAC face
458 // field uf_/vf_/wf_, not the cell field — and it is in flow's own low-face convention
459 // (`uf(i) = 1/2(U(i)+U(i-1))` sits at i-1/2, the -x face of cell i), the SAME convention
460 // `getFaceVelocity` reports and `copyFaceVelocity` shifts. So the bridge is the identical call
461 // on a different source view; the cell field never enters the colour transport.
462 if constexpr (Grid::collocated) {
463 CCField fa[3] = {uf_, vf_, wf_};
464 for (int c = 0; c < 3; ++c) {
465 // the face field's own ghost policy (project() does exactly this), keeping the high-side
466 // boundary face: the fill is IN PLACE on uf_, and a plain wrap would undo the projection's
467 // outlet face for every later reader -- the scalars, the census (doc/uf_outlet_fix.md)
469 vof::copyFaceVelocity(vofAdv_.faceVel(c), I3{e3_.x, e3_.y, e3_.z}, kVofG, fa[c],
470 I3{e_.x, e_.y, e_.z}, G, c);
471 }
472 return;
473 }
474 for (int c = 0; c < 3; ++c) {
475 // KEEP the projection's outflow-face correction when there IS one (see
476 // fillVelGhostsKeepOutflow): the full fill would overwrite it with the zero-gradient copy
477 // and hand the advector a field that is not divergence-free at the outlet. When no
478 // projection has run since the last full fill — the KINEMATIC path, where the caller
479 // prescribes the velocity on the inner cells and the boundary face has never been set —
480 // the zero-gradient fill is exactly what supplies that face, so run the full one.
481 // With no outflow face at all the two are identical.
482 if (outflowCorrValid_)
483 fillVelGhostsTo(C[c].u, c, 0, false);
484 else
485 fillVelGhosts(c, 0);
486 // The uniform face-velocity seam (getFaceVelocity): staggered C[c].u already lives on the
487 // faces. copyFaceVelocity carries the low-face -> high-face index shift; see
488 // colour_field.hpp.
489 vof::copyFaceVelocity(vofAdv_.faceVel(c), I3{e3_.x, e3_.y, e3_.z}, kVofG, C[c].u,
490 I3{e_.x, e_.y, e_.z}, G, c);
491 }
492}
493
494template <class Grid>
495std::vector<vof::VofBox> Solver<Grid>::vofBlockRankBoxes(int size) const {
496 std::vector<vof::VofBox> rb(static_cast<std::size_t>(size));
497 const I3 gs = vofGlobalSize();
498#ifdef PECLET_FLOW_MPI
499 if (distributed_ && dec_) {
500 for (int r = 0; r < size; ++r) {
501 const auto b = dec_->block(static_cast<std::size_t>(r));
502 for (int d = 0; d < 3; ++d) {
503 rb[r].lo[d] = static_cast<int>(b.origin[d]);
504 rb[r].hi[d] = static_cast<int>(b.origin[d] + b.size[d]);
505 }
506 }
507 return rb;
508 }
509#endif
510 rb[0].hi[0] = gs.x;
511 rb[0].hi[1] = gs.y;
512 rb[0].hi[2] = gs.z;
513 return rb;
514}
515
516template <class Grid>
518 if (!vofBlockExch_)
519 return;
520 // The rank table first, for the same reason: `buildVofBlock` runs on every re-decomposition
521 // (redistribute -> initMpi), and the pieces are meaningless against the old boxes.
522 int size = 1;
523#ifdef PECLET_FLOW_MPI
524 if (distributed_)
525 MPI_Comm_size(comm_, &size);
526#endif
527 vofBlockExch_->setRankBoxes(vofBlockRankBoxes(size));
529 pp.e = I3{e3_.x, e3_.y, e3_.z};
530 pp.n = I3{nx_, ny_, nz_};
531 pp.o = vofOrigin();
532 pp.g = kVofG;
533 vofBlockExch_->setPatch(pp, vofAdv_.faceVel(0), vofAdv_.faceVel(1), vofAdv_.faceVel(2));
534}
535
536template <class Grid>
538 if (vofOverlapDensity_ && vofBlkS_.extent(0)) {
539 // vof_overlap_design §5.6, opt-in: the overlap volume as film liquid (the "tent").
540 const long len3 = static_cast<long>(e3_.x) * e3_.y * e3_.z;
541 if (static_cast<long>(vofBlkCeff_.extent(0)) != len3)
542 vofBlkCeff_ = SField("vof::blockcsf::ceff", len3);
543 const I3 e = I3{e3_.x, e3_.y, e3_.z};
544 const int g = kVofG;
545 SField un = vofAdv_.colour(), sm = vofBlkS_, ce = vofBlkCeff_;
546 Kokkos::parallel_for(
547 "vof::block::tent", MDRange3<SExec>(SExec(), {g, g, g}, {g + nx_, g + ny_, g + nz_}),
548 KOKKOS_LAMBDA(int x, int y, int z) {
549 const long i = L3(x, y, z, e);
550 const double sv = sm(i);
551 ce(i) = (sv <= 1.0 + 1e-8) ? un(i) : Kokkos::fmax(0.0, 2.0 - sv);
552 });
553 Kokkos::fence();
554 copyInner(cField_, e_, G, CCConst(vofBlkCeff_), e3_, kVofG);
555 } else {
556 copyInner(cField_, e_, G, CCConst(vofAdv_.colour()), e3_, kVofG);
557 }
558 fillPropGhosts(cField_);
559}
560
561template <class Grid>
563 vofOverlap_ = VofOverlapCensus{};
564 if (!vofBlocks_ || !(vofBlocks_->csfEnabled || vofOverlapDensity_))
565 return;
566 const long len3 = static_cast<long>(e3_.x) * e3_.y * e3_.z;
567 if (static_cast<long>(vofBlkS_.extent(0)) != len3)
568 vofBlkS_ = SField("vof::blockcsf::sum", len3);
569 vofBlocks_->scatterSum(vofBlkS_);
570 const I3 e = I3{e3_.x, e3_.y, e3_.z};
571 const int g = kVofG;
572 SField sm = vofBlkS_;
573 double mx = 0.0, ex = 0.0;
574 long nc = 0;
575 Kokkos::parallel_reduce(
576 "vof::block::overlap_census",
577 MDRange3<SExec>(SExec(), {g, g, g}, {g + nx_, g + ny_, g + nz_}),
578 KOKKOS_LAMBDA(int x, int y, int z, double& m, double& a, long& c) {
579 const double sv = sm(L3(x, y, z, e));
580 m = Kokkos::fmax(m, sv);
581 if (sv > 1.0 + 1e-8) {
582 a += sv - 1.0;
583 ++c;
584 }
585 },
586 Kokkos::Max<double>(mx), ex, nc);
587 CCExec().fence("peclet::flow::vof_overlap_census"); // S4: instance, not global
588#ifdef PECLET_FLOW_MPI
589 if (distributed_) {
590 double gm = 0.0, ge = 0.0;
591 long gc = 0;
592 MPI_Allreduce(&mx, &gm, 1, MPI_DOUBLE, MPI_MAX, comm_);
593 MPI_Allreduce(&ex, &ge, 1, MPI_DOUBLE, MPI_SUM, comm_);
594 MPI_Allreduce(&nc, &gc, 1, MPI_LONG, MPI_SUM, comm_);
595 mx = gm;
596 ex = ge;
597 nc = gc;
598 }
599#endif
600 vofOverlap_.maxSum = mx;
601 vofOverlap_.excess = ex;
602 vofOverlap_.cells = nc;
603 // Under the opt-in overlap density the phantom is an ordinary liquid-gas interface (C_eff runs
604 // 0.5 -> 0 across it), so the base bound is the right one there (vof_overlap_design §5.6, G7a).
605 // The TRIGGER is S > 1 + 1e-2, not the census's 1 + 1e-8 (vof_overlap_design §11): Weymouth-Yue
606 // residue of one marker inside another keeps S a hair above 1 on nearly every step after a
607 // contact (measured: bound on 5028 of 5907 shear steps, every channel_18 step), whereas a
608 // phantom interface worth a capillary mode means a marker's band inside another's body.
609 constexpr double kPhantomTrigger = 1e-2;
610 vofOverlap_.active = vofPhantomBound_ && vofBlocks_->csfEnabled && !vofOverlapDensity_ &&
611 mx > 1.0 + kPhantomTrigger;
612}
613
614template <class Grid>
616 vofPhantomBound_ = enabled;
617 vofOverlap_.active = vofOverlap_.active && enabled; // takes effect for the very next step
618}
619
620template <class Grid>
622 vofBlockDebris_ = enabled ? 1 : 0;
623 if (vofBlocks_ && vofBlocks_->csfEnabled)
624 vofBlocks_->debrisRemove = enabled;
625}
626
627template <class Grid>
629 if (!vofBlocks_)
630 throw std::runtime_error("set_vof_block_overlap_density: call enable_vof_blocks first");
631 vofOverlapDensity_ = enabled;
634}
635
636template <class Grid>
638 copyInner(vofAdv_.colour(), e3_, kVofG, CCConst(cField_), e_, G);
639 vofFillGhosts(vofAdv_.colour());
640}
641
642template <class Grid>
643void Solver<Grid>::addCsfRhs(int c, CCField dst, bool rowScaled, bool faceRange) {
644 CCExec space;
645 C3 e = e_;
646 CCField bb = dst;
647 const int hi = faceRange ? 1 : 0;
648 CCConst rs = CCConst(C[c].rscale), cv = CCConst(cField_), kp = CCConst(kappaField_),
649 kb = CCConst(kappaBranch_);
650 const long strd = strideOf(c);
651 // Phase 3 (V3.1): the CSF carries the PRESSURE-GRADIENT WEIGHT of this component's axis,
652 // `w_a = 1/h_a'^2` — the same symbol Phase 2 puts on `-(P(i) - P(i - s_a))`. Exactly 1.0 on
653 // every isotropic run, so `x / 1.0 == x` keeps this kernel bit-identical.
654 const double sig = sigmaCsf_, h = 1.0 / u_.w[c];
655 using MD = MDRange3<CCExec>;
656 Kokkos::parallel_for(
657 "csf_rhs", MD(space, {G, G, G}, {e.x - G + hi, e.y - G + hi, e.z - G + hi}),
658 KOKKOS_LAMBDA(int x, int y, int z) {
659 const long i = (long)x + (long)y * e.x + (long)z * (long)e.x * e.y;
660 const double dC = cv(i) - cv(i - strd);
661 if (dC == 0.0)
662 return; // no interface across this face -> no force, and no orphan either
663 double kf = 0.0;
664 vof::csfFaceCurvature(kp(i - strd), kb(i - strd), kp(i), kb(i), kf);
665 if (rowScaled)
666 bb(i) += rs(i) * vof::csfFaceForce(sig, kf, dC, h);
667 else
668 bb(i) += vof::csfFaceForce(sig, kf, dC, h);
669 });
670}
671
672template <class Grid>
673void Solver<Grid>::addCsfRhsCellInterp(int c, CCField dst, bool rowScaled, bool faceRange) {
674 CCExec space;
675 C3 e = e_;
676 CCField bb = dst;
677 const int hi = faceRange ? 1 : 0;
678 CCConst rs = CCConst(C[c].rscale), cv = CCConst(cField_), kp = CCConst(kappaField_),
679 kb = CCConst(kappaBranch_);
680 const long strd = strideOf(c);
681 const double sig = sigmaCsf_, h = 1.0 / u_.w[c]; // the ablation takes the same weight (V3.1)
682 using MD = MDRange3<CCExec>;
683 Kokkos::parallel_for(
684 "csf_rhs_cellinterp", MD(space, {G, G, G}, {e.x - G + hi, e.y - G + hi, e.z - G + hi}),
685 KOKKOS_LAMBDA(int x, int y, int z) {
686 const long i = (long)x + (long)y * e.x + (long)z * (long)e.x * e.y;
687 double f[2] = {0.0, 0.0};
688 for (int q = 0; q < 2; ++q) { // q = 0 -> cell i-s_c, q = 1 -> cell i
689 const long j = i - (1 - q) * strd;
690 if (!vof::csfKappaDefined(kb(j)))
691 continue;
692 f[q] = sig * kp(j) * 0.5 * (cv(j + strd) - cv(j - strd)) / h;
693 }
694 if (rowScaled)
695 bb(i) += rs(i) * 0.5 * (f[0] + f[1]);
696 else
697 bb(i) += 0.5 * (f[0] + f[1]);
698 });
699}
700
701template <class Grid>
703 CCExec space;
704 C3 e = e_;
705 CCField bb = C[c].b;
706 CCConst rs = CCConst(C[c].rscale), fb = CCConst(csfBlkF_[c]);
707 using MD = MDRange3<CCExec>;
708 Kokkos::parallel_for(
709 "csf_rhs_blocks", MD(space, {G, G, G}, {e.x - G, e.y - G, e.z - G}),
710 KOKKOS_LAMBDA(int x, int y, int z) {
711 const long i = (long)x + (long)y * e.x + (long)z * (long)e.x * e.y;
712 bb(i) += rs(i) * fb(i);
713 });
714}
715
716template <class Grid>
718 if (!vofEnabled_ || !kappaField_.extent(0))
719 throw std::runtime_error(
720 "csf_diagnostics: needs VoF + a curvature field (call set_surface_tension and step, or "
721 "compute_vof_curvature)");
723 C3 e = e_;
724 CCConst cv = CCConst(cField_), kp = CCConst(kappaField_), kb = CCConst(kappaBranch_);
725 const double sig = sigmaCsf_, eps = csfInterfaceEps_;
726 using MD = MDRange3<CCExec>;
727 for (int c = 0; c < 3; ++c) {
728 const double h = 1.0 / u_.w[c]; // the V3.1 per-axis gradient weight of this component
729 const long strd = strideOf(c);
730 double mx = 0.0;
731 long orph = 0, forced = 0;
732 Kokkos::parallel_reduce(
733 "csf_diag", MD(CCExec(), {G, G, G}, {e.x - G, e.y - G, e.z - G}),
734 KOKKOS_LAMBDA(int x, int y, int z, double& m, long& o, long& f) {
735 const long i = (long)x + (long)y * e.x + (long)z * (long)e.x * e.y;
736 const double dC = cv(i) - cv(i - strd);
737 if (dC == 0.0)
738 return;
739 double kf = 0.0;
740 const bool ok = vof::csfFaceCurvature(kp(i - strd), kb(i - strd), kp(i), kb(i), kf);
741 if (ok)
742 ++f;
743 else if (Kokkos::fabs(dC) > eps)
744 ++o;
745 m = Kokkos::fmax(m, Kokkos::fabs(vof::csfFaceForce(sig, kf, dC, h)));
746 },
747 Kokkos::Max<double>(mx), orph, forced);
748 d.maxForce[c] = mx;
749 d.orphanFaces[c] = orph;
750 d.forcedFaces[c] = forced;
751 }
752 return d;
753}
754
755template <class Grid>
757 // PHASE 3 LIFTED Phase 2's `requireIsotropic` refusal here (flow/doc/anisotropic_vof.md).
758 // The colour transport itself needed nothing — a stretched cell IS the unit cube of the index
759 // coordinates, so every volume fraction, PLIC plane<->volume relation, slab flux and
760 // Weymouth-Yue sweep is metric-free (§3, decision V1). What took the metric is everything
761 // that reads a DIRECTION, a LENGTH or an AREA: the height-function curvature over physical
762 // column and transverse spacings, the two paraboloid fits in the physical frame (§4), the CSF
763 // face force carrying THIS axis's pressure-gradient weight `w_a` so the balanced-force
764 // identity survives (§5), the theta rotation of the wetting fill (§6), and the phase-change
765 // layer's normals, areas, sample distances and `V_cell` (§7).
766
767 if constexpr (Grid::collocated) {
768 // Rung V8: allowed. The colour is advected by the PROJECTED face field uf_/vf_/wf_ — which is
769 // what the ABC approximate projection makes exactly divergence-free, i.e. precisely the field
770 // Weymouth-Yue's conservation proof needs — and the CSF enters the implicit predictor as the
771 // mass-adjoint face integral (collocated_varrho.hpp). ALL-FLUID only at this rung.
772 if (hasSolid_)
773 throw std::runtime_error(
774 "enable_vof: geometric VoF on SolverColocated (rung V8) is ALL-FLUID only — immersed "
775 "solids on this path are the next package (doc/collocated_multiphase_solids_plan.md). "
776 "Use the staggered Solver (rung V5a supports cut cells).");
777 collocatedV8AutoFallback("geometric VoF on the collocated grid");
778 }
779 if (vofEnabled_)
780 return;
781 cField_ = addField("C"); // the G=2 registry mirror (closure input / IO / redistribute)
782 vofEnabled_ = true;
783 // WO-R2 item 3 — the EXACT (matrix-free, double, flux-form) level-0 residual/matvec becomes
784 // the default the moment there is an interface. Measured on Hysing case 2 (WO-R item 6,
785 // 64x128x4, adaptive dt): it removes 7.5 orders of the projected flux divergence
786 // (1.85e-03 -> 5.15e-11) and moves NOTHING else — 116/600 pressure iterations, 1123 steps, the
787 // dt-limit census and both published functionals identical to every printed digit. The defect
788 // it removes is the float operator's broken row-sum identity A*1 = 0, and a two-phase
789 // coefficient contrast is precisely what amplifies it. `set_pressure_exact_residual(False)`
790 // after `enable_vof` is the ablation.
792 // WO-R2 item 4 — the wisp tolerance. 0 is V1 verbatim (and stays the standalone advector's
793 // default); an open-boundary domain that DRAINS reaches C ~ 1e-18 everywhere, where the MYC
794 // normal is degenerate and plicAlpha divides by it (measured: sum C -> -inf -> NaN in three
795 // steps). Same 1e-8 the curvature predicate uses under surface tension.
796 vofAdv_.wispEps = vofWispEps_;
798}
799
800template <class Grid>
802 if (!(eps >= 0.0) || eps >= 0.5)
803 throw std::runtime_error("set_vof_wisp_eps: the threshold must be in [0, 0.5)");
804 vofWispEps_ = eps;
805 vofAdv_.wispEps = eps;
806 if (vofBlocks_)
807 vofBlocks_->setWispEps(eps); // §12.1: one wisp guard for the global and the block advectors
808}
809
810template <class Grid>
812 return vofWispEps_;
813}
814
815template <class Grid>
817 return 1e-8;
818}
819
820template <class Grid>
822 return vofEnabled_;
823}
824
825template <class Grid>
826void Solver<Grid>::setVof(const std::vector<double>& c) {
827 enableVof();
828 scatterInner(cField_, c);
829 zeroSolidColour(); // rung V5a: solid cells carry no colour (the band fill is regenerated)
830 fillPropGhosts(cField_);
831 pcMaskFresh_ = false; // WO-P3g: the Dirichlet/plane geometry no longer describes this colour
832}
833
834template <class Grid>
835std::vector<double> Solver<Grid>::getVof() {
836 return gatherInner(cField_);
837}
838
839template <class Grid>
841 if (!vofEnabled_)
842 throw std::runtime_error("vof_diagnostics: VoF is not enabled (call enable_vof/set_vof)");
844 auto d = vofAdv_.diagnostics();
845 // `solidSumC` is the census of the CANONICAL field: the working block's solid cells carry the
846 // neutral band fill (reported as `solidFillSum`), while "C" itself is 0 there — that is the
847 // quantity gate G2 of WO-Q asks for.
848 d.solidSumC = vofSolidColourSum();
849 return d;
850}
851
852template <class Grid>
854 if (!vofEnabled_ || !vofAdv_.hasGeometry() || !vofSolidG2_.extent(0))
855 return 0.0;
856 CCConst c = CCConst(cField_), sl = CCConst(vofSolidG2_);
857 const int ex = e_.x, ey = e_.y, g = G;
858 double acc = 0.0;
859 Kokkos::parallel_reduce(
860 "peclet::flow::vof_solid_sum", MDRange3<CCExec>(CCExec(), {0, 0, 0}, {nx_, ny_, nz_}),
861 KOKKOS_LAMBDA(int x, int y, int z, double& a) {
862 const long i = (long)(x + g) + (long)(y + g) * ex + (long)(z + g) * (long)ex * ey;
863 if (sl(i) > 0.5)
864 a += c(i);
865 },
866 acc);
867 Kokkos::fence();
868 return acc;
869}
870
871template <class Grid>
873 if (!vofEnabled_)
874 return 0.0;
877 const double loc = vofAdv_.maxCourantInterfaceAuto(dt_ / vofAdv_.h());
878 return vofAdv_.globalMax ? vofAdv_.globalMax(loc) : loc;
879}
880
881template <class Grid>
883 return vofEnabled_ ? vofAdv_.lastCfl() : 0.0;
884}
885
886template <class Grid>
888 vofCflLimit_ = v;
889 if (vofEnabled_)
890 vofAdv_.cflLimit = v;
891}
892
893template <class Grid>
895 return vofCflLimit_;
896}
897
898template <class Grid>
899void Solver<Grid>::requireVofGeometry(const char* who) {
900 if constexpr (Grid::collocated) {
901 // Rung V8 scope, re-checked here because `set_solid` can follow `enable_vof`.
902 if (hasSolid_)
903 throw std::runtime_error(
904 std::string(who) +
905 ": geometric VoF on SolverColocated (rung V8) is ALL-FLUID only. The cut-cell colour "
906 "transport (rung V5a) is validated on the STAGGERED solver.");
907 }
908 if (!hasSolid_ || vofAdv_.hasGeometry())
909 return;
910 std::string m(who);
911 m += ": an immersed solid is present but the colour block has no cut-cell geometry. Rung V5a "
912 "needs the cut-cell openness, i.e. set_solid(sdf, cutcell_pressure=True) (the staircase "
913 "pressure operator has no face openness to weight the geometric fluxes with).";
914 throw std::runtime_error(m);
915}
916
917template <class Grid>
919 return vofAdv_.hasGeometry();
920}
921
922template <class Grid>
924 vofAdv_.cutFluxClamp = on;
925}
926
927template <class Grid>
929 return vofAdv_.cutFluxClamp;
930}
931
932template <class Grid>
934 vofSolidZero_ = on;
935}
936
937template <class Grid>
939 return vofSolidZero_;
940}
941
942template <class Grid>
943std::vector<double> Solver<Grid>::getVofFilledColour() {
944 if (!vofEnabled_)
945 throw std::runtime_error("vof_filled_color: VoF is not enabled");
947 CCField t("vofFilled", n_);
948 copyInner(t, e_, G, CCConst(vofAdv_.colour()), e3_, kVofG);
949 return gatherInner(t);
950}
951
952template <class Grid>
953std::vector<double> Solver<Grid>::getVofGeometry(int which) {
954 if (!vofEnabled_)
955 throw std::runtime_error("vof_geometry: VoF is not enabled (needs enable_vof)");
956 if (which < 0 || which > 4)
957 throw std::runtime_error("vof_geometry: `which` must be 0..4");
958 // ISSUES sweep item 4. An ALL-FLUID VoF solver has no cut-cell geometry block, but the
959 // geometry it would carry is not undefined -- it is the trivial one, and it is exactly what
960 // the V1 transport kernels execute: every cell fully fluid (eps = 1), every face fully open
961 // (o = 1), no solid (kind = 0). Returning it lets ONE diagnostic --
962 // `vof_geometry(0) * (1 - get_vof())` for the gas volume, say -- serve a packed scene and its
963 // all-fluid control, instead of forcing the caller to branch on `vof_has_geometry()` and
964 // synthesise the ones itself (which is what examples/bubble-through-packing had to do).
965 if (!vofAdv_.hasGeometry())
966 return std::vector<double>((std::size_t)nx_ * ny_ * nz_, which == 4 ? 0.0 : 1.0);
967 CCField t("vofGeom", n_);
968 CCConst src;
969 if (which == 0)
970 src = CCConst(vofAdv_.epsFraction());
971 else if (which < 4)
972 src = CCConst(vofAdv_.faceOpenness(which - 1));
973 else
974 src = CCConst(vofAdv_.kindDouble());
975 copyInner(t, e_, G, src, e3_, kVofG);
976 return gatherInner(t);
977}
978
979template <class Grid>
980void Solver<Grid>::setContactAngle(double thetaDeg) {
981 if (!(thetaDeg >= 0.0 && thetaDeg <= 180.0))
982 throw std::runtime_error("set_contact_angle: theta must be in [0, 180] degrees");
983 contactAngleDeg_ = thetaDeg;
984 contactAngleField_.clear();
985 contactAngleSet_ = true;
987 buildVofGeometry(); // item 3: a wetting DOMAIN wall changes the colour block's geometry
989}
990
991template <class Grid>
993 if (!vofEnabled_ || hasSolid_ || vofWetWallMask() != 0)
994 return;
995 throw std::runtime_error(
996 "set_contact_angle: this solver has no wetting wall - no immersed SDF solid (set_solid) "
997 "and no impermeable domain face (set_domain_bc(face, 1) no-slip or 4 free-slip). The "
998 "angle would be imposed nowhere. (Inflow/outflow faces carry no contact line.)");
999}
1000
1001template <class Grid>
1002void Solver<Grid>::setContactAngleField(const std::vector<double>& thetaDeg) {
1003 if (thetaDeg.size() != (std::size_t)nx_ * ny_ * nz_)
1004 throw std::runtime_error("set_contact_angle_field: expected nx*ny*nz values");
1005 contactAngleField_ = thetaDeg;
1006 contactAngleSet_ = true;
1008 buildVofGeometry(); // item 3
1010}
1011
1012template <class Grid>
1014 return contactAngleSet_;
1015}
1016
1017template <class Grid>
1019 return contactAngleDeg_;
1020}
1021
1022template <class Grid>
1024 if (mode < 0 || mode > 3)
1025 throw std::runtime_error("set_contact_angle_pivot: mode must be 0..3");
1026 contactPivot_ = mode;
1027 vofAdv_.wettingPivot = mode;
1028}
1029
1030template <class Grid>
1032 return contactPivot_;
1033}
1034
1035template <class Grid>
1036void Solver<Grid>::setContactAngleDynamic(double thetaEDeg, double slipCells, double muLiquid,
1037 double sigma) {
1038 // `slipCells` is a LENGTH in the caller's units (cells when no physical domain is armed);
1039 // the model needs lambda/Delta, which is what the internal value is.
1040 const double slipInt = slipCells * u_.lenToInt();
1041 if (!(slipInt > 0.0 && slipInt < 1.0))
1042 throw std::runtime_error(
1043 "set_contact_angle_dynamic: the slip length must lie in (0, 1) cell (lambda < Delta)");
1044 if (!(muLiquid > 0.0))
1045 throw std::runtime_error("set_contact_angle_dynamic: mu_liquid must be positive");
1046 vofDyn_.dynamic = true;
1047 vofDyn_.slip = slipInt;
1048 vofDyn_.muLiquid = muLiquid * u_.muToInt();
1049 contactSigmaOverride_ = sigma;
1050 // ONE lambda across the two halves of Afkhami-Zaleski-Bussmann (WO-V6b): this call and
1051 // set_wall_slip_length write the SAME stored value, so the angle model's inner cut-off and
1052 // the momentum wall closure can never disagree (last call wins). Whether the MOMENTUM half is
1053 // active is a separate switch, set only by set_wall_slip_length -- so every result WO-V6
1054 // validated with the angle half alone stays exactly what it was.
1055 slipPhys_ = slipCells;
1056 slipLambda_ = slipInt;
1057 if (wallSlip_ && hasSolid_ && !Grid::collocated) {
1058 buildVelocityOverlays(/*resetU=*/false);
1060 }
1061 setContactAngle(thetaEDeg); // sets the static base and (re)wires the theta field
1062}
1063
1064template <class Grid>
1065void Solver<Grid>::setWallSlipLength(double lambdaCells) {
1066 if (!(lambdaCells >= 0.0))
1067 throw std::runtime_error("set_wall_slip_length: lambda must be >= 0");
1068 const double lambdaInt = lambdaCells * u_.lenToInt();
1069 if (lambdaCells > 0.0 && Grid::collocated)
1070 throw std::runtime_error(
1071 "set_wall_slip_length: the Navier wall closure is a staggered-grid feature (the "
1072 "collocated scheme carries its own wall treatment)");
1073 slipPhys_ = lambdaCells;
1074 slipLambda_ = lambdaInt;
1075 wallSlip_ = lambdaCells > 0.0;
1076 if (vofDyn_.dynamic && lambdaCells > 0.0)
1077 vofDyn_.slip = lambdaInt;
1078 if (hasSolid_) {
1079 buildVelocityOverlays(/*resetU=*/false);
1081 }
1082}
1083
1084template <class Grid>
1086 return wallSlip_ ? slipPhys_ : 0.0;
1087}
1088
1089template <class Grid>
1090std::array<int, 3> Solver<Grid>::wallSlipSandwichCells() const {
1091 return slipSandwich_;
1092}
1093
1094template <class Grid>
1095void Solver<Grid>::setContactAngleHysteresis(double thetaADeg, double thetaRDeg) {
1096 if (!(thetaADeg >= thetaRDeg))
1097 throw std::runtime_error("set_contact_angle_hysteresis: theta_a must be >= theta_r");
1098 if (!(thetaRDeg >= 0.0 && thetaADeg <= 180.0))
1099 throw std::runtime_error("set_contact_angle_hysteresis: angles must lie in [0, 180]");
1100 const double toRad = 3.14159265358979323846 / 180.0;
1101 vofDyn_.hysteresis = true;
1102 vofDyn_.thetaA = thetaADeg * toRad;
1103 vofDyn_.thetaR = thetaRDeg * toRad;
1104 if (!contactAngleSet_)
1105 setContactAngle(0.5 * (thetaADeg + thetaRDeg)); // a base is required; the mid angle
1106 else
1108}
1109
1110template <class Grid>
1112 vofDyn_.dynamic = false;
1113 vofDyn_.hysteresis = false;
1115}
1116
1117template <class Grid>
1119 return vofDyn_.dynamic;
1120}
1121
1122template <class Grid>
1124 return vofDyn_.hysteresis;
1125}
1126
1127template <class Grid>
1129 return vofDyn_.slip;
1130}
1131
1132template <class Grid>
1134 vofDyn_.smooth = on;
1135}
1136
1137template <class Grid>
1138void Solver<Grid>::setContactAngleClamp(double loDeg, double hiDeg) {
1139 if (!(loDeg > 0.0 && hiDeg < 180.0 && loDeg < hiDeg))
1140 throw std::runtime_error("set_contact_angle_clamp: need 0 < lo < hi < 180");
1141 const double toRad = 3.14159265358979323846 / 180.0;
1142 vofDyn_.thetaMin = loDeg * toRad;
1143 vofDyn_.thetaMax = hiDeg * toRad;
1144}
1145
1146template <class Grid>
1148 return contactSigmaOverride_ > 0.0 ? contactSigmaOverride_ : sigmaCsf_;
1149}
1150
1151template <class Grid>
1152std::vector<double> Solver<Grid>::getVofDynamicField(int which) {
1153 if (!vofEnabled_ || !vofDyn_.active() || !vofDyn_.allocated())
1154 throw std::runtime_error(
1155 "vof_dynamic_field: no dynamic contact angle (call set_contact_angle_dynamic / "
1156 "set_contact_angle_hysteresis first)");
1157 bridgeColourToVof(); // regenerates the fill, hence the dynamic pass
1158 CCField t("vofDyn", n_);
1159 const double toDeg = 180.0 / 3.14159265358979323846;
1160 CCConst src;
1161 if (which == 0)
1162 src = CCConst(vofDyn_.imposed());
1163 else if (which == 1)
1164 src = CCConst(vofDyn_.apparent());
1165 else if (which == 2)
1166 src = CCConst(vofDyn_.speed());
1167 else if (which == 3)
1168 src = CCConst(vofDyn_.capillary());
1169 else
1170 src = CCConst(vofDyn_.stateField());
1171 copyInner(t, e_, G, src, e3_, kVofG);
1172 auto v = gatherInner(t);
1173 if (which <= 1)
1174 for (auto& q : v)
1175 q *= toDeg;
1176 return v;
1177}
1178
1179template <class Grid>
1181 if (!vofEnabled_)
1182 throw std::runtime_error("contact_angle_diagnostics: VoF is not enabled");
1184 d.setAngle = contactAngleDeg_;
1185 if (!vofAdv_.hasWetting())
1186 return d;
1187 bridgeColourToVof(); // regenerates the fill, hence the census
1188 long counts[vof::kVofWetCount];
1189 long nApp = 0;
1190 // ISSUES sweep item 3: a wetting DOMAIN wall's band lives in the GHOST layers, so the
1191 // census has to reach them or `contact_cells` reads 0 -- the very symptom the item was
1192 // reported for. 0 (the inner region) when no domain wall is wetting.
1193 vofAdv_.wettingCensusGhost(counts, d.meanApparentAngle, nApp, vofWetWallMask() ? kVofG : 0);
1194 d.unfilledCells = counts[vof::kVofWetNone];
1195 d.contactCells = counts[vof::kVofWetTheta];
1196 d.neighbourCells = counts[vof::kVofWetNeighbour];
1197 d.pureCells = counts[vof::kVofWetPure];
1198 d.parallelCells = counts[vof::kVofWetParallel];
1199 d.neutralCells = counts[vof::kVofWetNeutral];
1200 if (vofDyn_.active() && vofDyn_.allocated()) {
1201 const auto cs = vofDyn_.census(vofAdv_);
1202 d.dynamicCells = cs.contactCells;
1203 d.pinnedCells = cs.cells[vof::kVofDynPinned];
1204 d.advancingCells = cs.cells[vof::kVofDynAdvancing];
1205 d.recedingCells = cs.cells[vof::kVofDynReceding];
1206 d.meanImposedTheta = cs.meanImposedDeg;
1207 d.meanApparentTheta = cs.meanApparentDeg;
1208 d.maxCaCl = cs.maxCa;
1209 d.maxContactSpeed = cs.maxSpeed;
1210 }
1211 return d;
1212}
1213
1214template <class Grid>
1216 if (!contactAngleSet_ || !vofEnabled_ || !vofAdv_.hasGeometry())
1217 return; // remembered; buildVofGeometry calls back once the geometry exists
1218 vofAdv_.enableWetting();
1219 vofAdv_.wettingPivot = contactPivot_;
1220 // (a) the SDF on the colour block: inner region from the solver's own sdf_, then the colour
1221 // field's ghost policy, so the central-difference wall normal at ghost depth <= 2 is the
1222 // OWNER's (the WO-Q finding-5 argument, applied to the wall normal).
1223 if (hasSolid_)
1224 copyInner(vofAdv_.wallSdf(), e3_, kVofG, CCConst(sdf_), e_, G);
1225 else
1226 Kokkos::deep_copy(vofAdv_.wallSdf(), 1e30);
1227 vofExchangeRaw(vofAdv_.wallSdf());
1228 // ISSUES sweep item 3: fold the wetting DOMAIN wall planes into the same field, on the WHOLE
1229 // block (the plane distance is a closed form of the global index, so no exchange is needed and
1230 // the out-of-domain band gets the value the clamp cannot produce). `min` is the SDF of the
1231 // union of the solids, so an SDF body and a domain wall compose; and the central difference
1232 // the theta pass takes of this field is exactly the inward face normal in the band.
1233 if (const int wet = vofWetWallMask()) {
1234 const I3 gs = vofGlobalSize(), org = vofOrigin();
1235 const C3 e = e3_;
1236 const int g = kVofG;
1237 CCField sd = vofAdv_.wallSdf();
1238 Kokkos::parallel_for(
1239 "peclet::flow::vof_wall_sdf_domain", MDRange3<CCExec>(CCExec(), {0, 0, 0}, {e.x, e.y, e.z}),
1240 KOKKOS_LAMBDA(int x, int y, int z) {
1241 const long i = (long)x + (long)y * e.x + (long)z * (long)e.x * e.y;
1242 const double d = vofWallPlaneSdf(x - g + org.x, y - g + org.y, z - g + org.z, gs, wet);
1243 sd(i) = Kokkos::fmin(sd(i), d);
1244 });
1245 CCExec().fence();
1246 }
1247 // (b) theta, in radians.
1248 const double toRad = 3.14159265358979323846 / 180.0;
1249 if (contactAngleField_.empty()) {
1250 Kokkos::deep_copy(vofAdv_.contactAngle(), contactAngleDeg_ * toRad);
1251 } else {
1252 CCField t("thetaG2", n_);
1253 std::vector<double> rad(contactAngleField_.size());
1254 for (std::size_t i = 0; i < rad.size(); ++i)
1255 rad[i] = contactAngleField_[i] * toRad;
1256 scatterInner(t, rad);
1257 copyInner(vofAdv_.contactAngle(), e3_, kVofG, CCConst(t), e_, G);
1258 vofExchangeRaw(vofAdv_.contactAngle());
1259 }
1260 // (c) rung V6: the STATIC base the dynamic selector starts from. The V6 pass OVERWRITES
1261 // `contactAngle()` every fill, so it must never read back its own previous output.
1262 if (vofDyn_.active()) {
1263 vofDyn_.allocate(vofAdv_.size());
1264 Kokkos::deep_copy(vofDyn_.base(), vofAdv_.contactAngle());
1265 }
1266}
1267
1268template <class Grid>
1270 if (!vofDyn_.allocated())
1271 return;
1272 if constexpr (Grid::collocated)
1273 throw std::runtime_error("set_contact_angle_dynamic: SolverColocated has no immersed solid");
1274 const long st[3] = {1, (long)e_.x, (long)e_.x * (long)e_.y};
1275 for (int c = 0; c < 3; ++c) {
1276 // The cell-centre mean reads the face ONE cell out on the component's own axis, so the
1277 // velocity ghost ring has to be valid. Same rule as `bridgeVelocityToVof`: keep the
1278 // projection's outflow-face correction when there is one, otherwise the full fill (the
1279 // kinematic path, where the zero-gradient rule is what supplies the boundary face at all).
1280 if (outflowCorrValid_)
1281 fillVelGhostsTo(C[c].u, c, 0, false);
1282 else
1283 fillVelGhosts(c, 0);
1284 if (vofDynVel_[c].extent(0) != n_)
1285 vofDynVel_[c] = CCField("vofDynVel", n_);
1286 CCField t = vofDynVel_[c];
1287 CCConst u = CCConst(C[c].u);
1288 const long sc = st[c];
1289 const int ex = e_.x, ey = e_.y, g = G;
1290 Kokkos::parallel_for(
1291 "peclet::flow::vof_dyn_cellvel", MDRange3<CCExec>(CCExec(), {0, 0, 0}, {nx_, ny_, nz_}),
1292 KOKKOS_LAMBDA(int x, int y, int z) {
1293 const long i = (long)(x + g) + (long)(y + g) * ex + (long)(z + g) * (long)ex * ey;
1294 t(i) = 0.5 * (u(i) + u(i + sc));
1295 });
1296 CCExec().fence();
1297 copyInner(vofDyn_.cellVel(c), e3_, kVofG, CCConst(t), e_, G);
1298 vofExchangeRaw(vofDyn_.cellVel(c));
1299 }
1300}
1301
1302template <class Grid>
1304 return vofAdv_;
1305}
1306
1307template <class Grid>
1309 vofStep_ = n;
1310 if (vofBlocks_)
1311 vofBlocks_->setStep(n);
1312}
1313
1314template <class Grid>
1316 return vofStep_;
1317}
1318
1319template <class Grid>
1320void Solver<Grid>::advectVofKinematic(double dtPhysArg) {
1321 const double dt = dtPhysArg * u_.timeToInt();
1322 if (!vofEnabled_)
1323 throw std::runtime_error("advect_vof: VoF is not enabled (call enable_vof / set_vof first)");
1324 requireVofGeometry("advect_vof");
1325 // ISSUES sweep item 5: on the collocated grid the advecting field is the MAC FACE field, and
1326 // a face field that was never built is all zeros — which the divergence guard below happily
1327 // certifies as solenoidal, so the whole advection became a silent no-op. `set_state` /
1328 // `set_velocity` now seed it (seedFaceFieldFromCells) and a projection builds it; refuse the
1329 // one remaining way to reach the trap.
1330 if constexpr (Grid::collocated) {
1331 if (!faceFieldValid_)
1332 throw std::runtime_error(
1333 "advect_vof: SolverColocated advects the colour with the MAC FACE field uf_/vf_/wf_ "
1334 "(the only discretely divergence-free field on this grid), and it has never been "
1335 "built — it is all zeros, which the divergence guard would certify as solenoidal and "
1336 "the advection would be a silent no-op. Call set_state()/set_velocity() (which now "
1337 "seed the face field through the same centerToFace map project() uses) or step() "
1338 "first.");
1339 }
1340 // WO-R2 item 4a (found by the E1 gallery page): the divergence guard below was INERT on a bare
1341 // box. `maxOpenDivergence()` returns 0.0 when there is no cut-cell pressure operator, so a
1342 // cell-centre-sampled analytic field — LeVeque, whose true max|div(open u)| is 0.612 — sailed
1343 // through the check and lost 4.93 % of the liquid in 50 steps with no diagnostic at all.
1344 // Refuse the configuration instead of measuring nothing.
1345 if (!cutcellPressure_)
1346 throw std::runtime_error(
1347 "advect_vof: no cut-cell pressure operator, so the divergence guard cannot measure "
1348 "anything (max_open_divergence() would return 0 whatever the field is). Build one with "
1349 "set_pressure_geometry(sdf) on an all-fluid box, or set_solid(sdf, "
1350 "cutcell_pressure=True) — Weymouth-Yue conservation is conditional on "
1351 "sum_f o_f u_f = 0 per cell and a cell-centre-sampled analytic field does NOT satisfy "
1352 "it (measured on LeVeque: max|div| 0.612, 4.93 % of the liquid lost in 50 steps).");
1353 // and measure the field the caller actually has: max_open_divergence() re-imposes the
1354 // zero-gradient outflow face before measuring, i.e. it MUTATES u and reports a field the
1355 // advector will not be handed (WO-R). The projected sibling does neither.
1356 const double div = maxOpenDivergenceProjectedInternal(); // the 1e-10 gate is index-unit
1357 if (!(div <= 1e-10)) {
1358 char msg[320];
1359 std::snprintf(msg, sizeof(msg),
1360 "advect_vof: the current face velocity is not discretely divergence-free "
1361 "(max|div(open*u)| = %.6g > 1e-10). Weymouth-Yue conservation is conditional "
1362 "on it; project the field first (step() / project()).",
1363 div);
1364 throw std::runtime_error(msg);
1365 }
1368 if (pcEnergy_) { // WO-P23: the temperature rides the same sweeps here too
1369 ScalarField& sc = scalarField(pcTName_);
1370 copyInner(vofEnergy_.temperature(), e3_, kVofG, CCConst(sc.c), e_, G);
1371 vofEnergy_.advect(vofAdv_, dt, vofStep_++);
1372 copyInner(sc.c, e_, G, CCConst(vofEnergy_.temperature()), e3_, kVofG);
1373 scalarFillGhosts(sc);
1374 } else {
1375 vofAdv_.advect(dt, vofStep_++);
1376 }
1377 copyInner(cField_, e_, G, CCConst(vofAdv_.colour()), e3_, kVofG);
1379 fillPropGhosts(cField_);
1381}
1382
1383template <class Grid>
1384void Solver<Grid>::enableVofBlocks(const std::vector<std::array<double, 4>>& seeds) {
1386 for (const auto& sd : seeds)
1387 vofBlocks_->seedSphere(sd[0], sd[1], sd[2], sd[3]);
1388 vofBlocks_->scatter(vofAdv_.colour());
1390}
1391
1392template <class Grid>
1394 if (!vofEnabled_)
1395 throw std::runtime_error("enable_vof_blocks: VoF is not enabled (call enable_vof first)");
1396 if (vofMomEnabled_)
1397 throw std::runtime_error(kVofMomBlocksMsg);
1398 if (hasSolid_)
1399 throw std::runtime_error(
1400 "enable_vof_blocks: the block container is ALL-FLUID at rung W0 (the cut-cell block is "
1401 "rung W12). Drop set_solid, or use the structured colour field (advect_vof).");
1402 int rank = 0, size = 1;
1403#ifdef PECLET_FLOW_MPI
1404 if (distributed_) {
1405 MPI_Comm_rank(comm_, &rank);
1406 MPI_Comm_size(comm_, &size);
1407 }
1408#endif
1409 vofBlocks_ = std::make_shared<vof::VofBlockSet>();
1410 const std::array<bool, 3> per{vofAxisPeriodic(0), vofAxisPeriodic(1), vofAxisPeriodic(2)};
1411 vofBlocks_->init(vofGlobalSize(), per, rank, size, 1.0); // flow works in cell units
1412 // The anisotropic metric: `pushVofMetric` runs from `refreshUnitDerived`, which in the documented
1413 // order (Solver(extent) -> set_rho -> ... -> enable_vof_blocks) fires BEFORE the block set
1414 // exists, so the set is created here with the metric already in force (review2 finding 1: the
1415 // block CSF silently ran on the unit metric on every anisotropic box).
1416 vofBlocks_->setMetric(u_.vofMetric());
1417 vofBlocks_->cflLimit = vofCflLimit_;
1418 // vof_overlap_design §12.1: the block advectors run the SAME wisp guard as the global one (the
1419 // enable_vof value); at 0 they reconstruct 1e-33 residue into NaN (channel_18, step 10908).
1420 vofBlocks_->setWispEps(vofAdv_.wispEps);
1421 vofBlockExch_ = std::make_shared<vof::VofBlockExchange>();
1422 vofBlockExch_->init(vofGlobalSize(), per, vofBlockRankBoxes(size), rank);
1423#ifdef PECLET_FLOW_MPI
1424 if (distributed_)
1425 vofBlockExch_->setComm(comm_);
1426#endif
1428 vofBlocks_->setExchange(vofBlockExch_);
1429}
1430
1431template <class Grid>
1433 vofBlocks_->assignMasters();
1434 vofBlocks_->scatter(vofAdv_.colour());
1436}
1437
1438template <class Grid>
1440 return static_cast<bool>(vofBlocks_);
1441}
1442
1443template <class Grid>
1445 vofBlocks_.reset();
1446 vofBlockExch_.reset();
1447}
1448
1449template <class Grid>
1450void Solver<Grid>::advectVofBlocks(double dtPhysArg, bool requireSolenoidal) {
1451 advectVofBlocksInternal(dtPhysArg * u_.timeToInt(), requireSolenoidal);
1452}
1453
1454template <class Grid>
1455void Solver<Grid>::advectVofBlocksInternal(double dt, bool requireSolenoidal) {
1456 if (!vofBlocks_)
1457 throw std::runtime_error("advect_vof_blocks: call enable_vof_blocks first");
1458 const double div = requireSolenoidal ? maxOpenDivergenceInternal() : 0.0; // index-unit gate
1459 if (!(div <= 1e-10)) {
1460 char msg[320];
1461 std::snprintf(msg, sizeof(msg),
1462 "advect_vof_blocks: the current face velocity is not discretely "
1463 "divergence-free (max|div(open*u)| = %.6g > 1e-10). Weymouth-Yue conservation "
1464 "is conditional on it; project the field first (step() / project()).",
1465 div);
1466 throw std::runtime_error(msg);
1467 }
1468 const double _tv0 = vofTick();
1469 vofBlocks_->timingOn = vofTiming_;
1470 const double _td0 = vofBlocks_->debrisSeconds;
1471 bridgeVelocityToVof(); // the block exchange reads THESE views (advector high-face convention)
1472 vofBlocks_->advect(dt, vofAdv_.colour());
1473 updateVofBlockOverlap(); // vof_overlap_design §5.6: S, the census, the phantom-bound gate
1475 if (vofTiming_) {
1476 vofAdd(vt_.blockAdvect, _tv0);
1477 vt_.blockDebris += vofBlocks_->debrisSeconds - _td0;
1478 }
1479}
1480
1481template <class Grid>
1482std::vector<vof::VofBlockStats> Solver<Grid>::vofBlockStats() const {
1483 if (!vofBlocks_)
1484 throw std::runtime_error("vof_block_stats: call enable_vof_blocks first");
1485 return vofBlocks_->statsAll();
1486}
1487
1488template <class Grid>
1490 if (!vofBlocks_)
1491 throw std::runtime_error("vof_block_imbalance: call enable_vof_blocks first");
1492 return vofBlocks_->cellImbalance();
1493}
1494
1495template <class Grid>
1496void Solver<Grid>::vofBlockCensus(std::vector<long>& masters, std::vector<long>& cells) const {
1497 if (!vofBlocks_)
1498 throw std::runtime_error("vof_block_census: call enable_vof_blocks first");
1499 vofBlocks_->masterCensus(masters, cells);
1500}
1501
1502template <class Grid>
1503void Solver<Grid>::setVofBlockAssign(int mode, long every) {
1504 if (!vofBlocks_)
1505 throw std::runtime_error("set_vof_block_assign: call enable_vof_blocks first");
1506 vofBlocks_->assignMode = static_cast<vof::VofMasterAssign>(mode);
1507 vofBlocks_->reassignEvery = every;
1508 vofBlocks_->assignMasters();
1509}
1510
1511template <class Grid>
1513 if (!vofBlocks_)
1514 throw std::runtime_error("vof_block_assign: call enable_vof_blocks first");
1515 return static_cast<int>(vofBlocks_->assignMode);
1516}
1517
1518template <class Grid>
1520 if (!vofBlocks_)
1521 throw std::runtime_error("vof_block_imbalance_of: call enable_vof_blocks first");
1522 const auto save = vofBlocks_->assignMode;
1523 vofBlocks_->assignMode = static_cast<vof::VofMasterAssign>(mode);
1524 const std::vector<int> m = vofBlocks_->plannedMasters();
1525 vofBlocks_->assignMode = save;
1526 const int np = vofBlocks_->size();
1527 std::vector<long> load(static_cast<std::size_t>(np), 0);
1528 long tot = 0, mx = 0;
1529 for (std::size_t i = 0; i < m.size(); ++i) {
1530 const long w = vofBlocks_->blocks()[i].box.cells();
1531 load[static_cast<std::size_t>(m[i])] += w;
1532 tot += w;
1533 }
1534 for (long v : load)
1535 mx = std::max(mx, v);
1536 return tot == 0 ? 1.0 : static_cast<double>(mx) * np / static_cast<double>(tot);
1537}
1538
1539template <class Grid>
1541 if (!vofBlockExch_)
1542 throw std::runtime_error("set_vof_block_device_staging: call enable_vof_blocks first");
1543 vofBlockExch_->deviceStaging = on;
1544}
1545
1546template <class Grid>
1548 if (!vofBlocks_)
1549 throw std::runtime_error("set_vof_block_pool: call enable_vof_blocks first");
1550 vofBlocks_->usePool = on;
1551 if (!on)
1552 vofBlocks_->clearPool();
1553}
1554
1555template <class Grid>
1556std::array<long, 2> Solver<Grid>::vofBlockPoolStats() const {
1557 if (!vofBlocks_)
1558 throw std::runtime_error("vof_block_pool_stats: call enable_vof_blocks first");
1559 return {vofBlocks_->poolHits(), vofBlocks_->poolMisses()};
1560}
1561
1562template <class Grid>
1563void Solver<Grid>::enableVofBlocksFromField(const std::vector<std::array<int, 6>>& boxes) {
1565 for (const auto& q : boxes) {
1566 vof::VofBox bb;
1567 for (int d = 0; d < 3; ++d) {
1568 bb.lo[d] = q[d];
1569 bb.hi[d] = q[3 + d];
1570 }
1571 vofBlocks_->seedBox(bb);
1572 }
1573 bridgeColourToVof(); // the caller's `set_vof` field -> the g=3 patch the gather reads
1574 vofBlocks_->finishSeeding(vofAdv_.colour());
1576}
1577
1578template <class Grid>
1579std::vector<double> Solver<Grid>::vofBlockColour(long id) {
1580 if (!vofBlocks_)
1581 throw std::runtime_error("vof_block_color: call enable_vof_blocks first");
1582 if (id < 0 || static_cast<std::size_t>(id) >= vofBlocks_->count())
1583 throw std::runtime_error("vof_block_color: no such block id");
1584 return vofBlocks_->blockColourHost(static_cast<std::size_t>(id));
1585}
1586
1587template <class Grid>
1588std::vector<double> Solver<Grid>::vofBlockKappa(long id) {
1589 if (!vofBlocks_)
1590 throw std::runtime_error("vof_block_kappa: call enable_vof_blocks first");
1591 if (id < 0 || static_cast<std::size_t>(id) >= vofBlocks_->count())
1592 throw std::runtime_error("vof_block_kappa: no such block id");
1593 return vofBlocks_->blockKappaHost(static_cast<std::size_t>(id));
1594}
1595
1596template <class Grid>
1597void Solver<Grid>::enableVofBlocksFromColours(const std::vector<std::array<int, 6>>& boxes,
1598 const std::vector<std::vector<double>>& colours) {
1599 if (boxes.size() != colours.size())
1600 throw std::runtime_error("enable_vof_blocks_from_colors: one color array per box is required");
1602 for (std::size_t i = 0; i < boxes.size(); ++i) {
1603 vof::VofBox bb;
1604 for (int d = 0; d < 3; ++d) {
1605 bb.lo[d] = boxes[i][d];
1606 bb.hi[d] = boxes[i][3 + d];
1607 }
1608 vofBlocks_->seedBoxWithColour(bb, colours[i]);
1609 }
1611}
1612
1613template <class Grid>
1615 if (!vofBlocks_)
1616 throw std::runtime_error("enable_vof_block_csf: call enable_vof_blocks first");
1617 if (!(sigmaCsf_ > 0.0))
1618 throw std::runtime_error("enable_vof_block_csf: set_surface_tension(sigma) first (sigma > 0)");
1619 if constexpr (Grid::collocated)
1620 throw std::runtime_error(
1621 "enable_vof_block_csf: the block CSF is STAGGERED-only at rung W2 (the collocated face "
1622 "-acceleration form is V8's, and composing the two is not this rung).");
1623 // The block cascade must be the SAME estimator as the structured one -- above all the wisp
1624 // guard: without `interfaceEps` a Weymouth-Yue round-off wisp is an "interfacial" cell whose
1625 // zero-area PLIC polygon returns |kappa| ~ 1e8, and the face between it and a real interface
1626 // carries a force eight orders too large. Measured consequence when it was missing: the
1627 // distributed run's CSF force differed from the single-rank one by 6.7e-3 after two steps,
1628 // amplified from a 3e-16 colour difference by a flipped cascade branch.
1629 // Every tunable from the structured cascade in ONE copy (review2 finding 2: a hand-written list
1630 // here once dropped the debug switches), then the three the block path sets itself.
1631 vofBlocks_->curvProto.copyTunablesFrom(vofCurv_);
1632 vofBlocks_->curvProto.interfaceEps = csfInterfaceEps_;
1633 // Same contract as the structured cascade: the purity test follows the advector
1634 // (VofCurvature::pureEps).
1635 vofBlocks_->curvProto.pureEps = vofAdv_.wispEps;
1636 vofBlocks_->setWispEps(vofAdv_.wispEps); // §12.1: the advectors follow the same value
1637 vofBlocks_->curvProto.kappaMax = vofBlockKappaMax_; // the clip: BLOCK path only (§5.1, §11)
1638 vofBlocks_->debrisRemove = (vofBlockDebris_ != 0); // debris removal: default ON (§5.3)
1639 vofBlocks_->enableCsf(sigmaCsf_);
1640 const long len3 = static_cast<long>(e3_.x) * e3_.y * e3_.z;
1641 for (int c = 0; c < 3; ++c) {
1642 vofBlkF_[c] = SField("vof::blockcsf::patch", len3);
1643 csfBlkF_[c] = CCField("vof::blockcsf", n_);
1644 }
1645 updateVofBlockOverlap(); // an overlap present at seeding gates the very first step
1647}
1648
1649template <class Grid>
1651 if (!vofBlocks_ || !vofBlocks_->csfEnabled)
1652 return;
1653 vofBlocks_->computeCsf(vofBlkF_[0], vofBlkF_[1], vofBlkF_[2]);
1654 for (int c = 0; c < 3; ++c)
1655 copyInner(csfBlkF_[c], e_, G, CCConst(vofBlkF_[c]), e3_, kVofG);
1656}
1657
1658template <class Grid>
1659std::vector<double> Solver<Grid>::getVofBlockForce(int c) {
1660 if (!csfBlkF_[c].extent(0))
1661 throw std::runtime_error("vof_block_force: call enable_vof_block_csf() first");
1662 return gatherInner(csfBlkF_[c]);
1663}
1664
1665template <class Grid>
1667 if (!vofBlocks_)
1668 throw std::runtime_error("vof_block_curvature_stats: call enable_vof_blocks first");
1669 return vofBlocks_->csfCurvatureStats();
1670}
1671
1672template <class Grid>
1674 checkVofBcFace(f, 2, "set_vof_inflow");
1675 vofInflowSet_[f] = true;
1676 vofInflowC_[f] = value;
1677 vofInflowProfRaw_[f].clear();
1678 vofBcArm();
1679}
1680
1681template <class Grid>
1682void Solver<Grid>::setVofInflowProfile(int f, const std::vector<double>& prof, int nb, int nc) {
1683 checkVofBcFace(f, 2, "set_vof_inflow_profile");
1684 if ((int)prof.size() != nb * nc)
1685 throw std::runtime_error("set_vof_inflow_profile: profile size != nb*nc");
1686 vofInflowSet_[f] = true;
1687 vofInflowProfRaw_[f] = prof;
1688 vofInflowProfNb_[f] = nb;
1689 vofInflowProfNc_[f] = nc;
1690 vofBcArm();
1691}
1692
1693template <class Grid>
1695 checkVofBcFace(f, 3, "set_vof_backflow");
1696 vofBackflowSet_[f] = true;
1697 vofBackflowC_[f] = value;
1698 vofBcArm();
1699}
1700
1701template <class Grid>
1703 return vofBcActive_;
1704}
1705
1706template <class Grid>
1707std::vector<double> Solver<Grid>::vofBcVolumes() const {
1708 return std::vector<double>(vofBcVol_, vofBcVol_ + 6);
1709}
1710
1711template <class Grid>
1712std::vector<double> Solver<Grid>::vofBcVolumesTotal() const {
1713 return std::vector<double>(vofBcVolTotal_, vofBcVolTotal_ + 6);
1714}
1715
1716template <class Grid>
1718 for (int f = 0; f < 6; ++f)
1719 vofBcVol_[f] = vofBcVolTotal_[f] = 0.0;
1720}
1721
1722template <class Grid>
1724 if (!vofBcActive_ || !vofEnabled_)
1725 return;
1726 if (f.data() != vofAdv_.colour().data())
1727 return;
1728 const I3 e3{e3_.x, e3_.y, e3_.z};
1729 for (int face = 0; face < 6; ++face) {
1730 if (!touchesGlobalFace(face))
1731 continue; // rank-owned global faces only (the WO-F rule)
1732 const int a = face / 2, sd = face % 2;
1733 if (bc_[face] == 2 && vofInflowSet_[face]) {
1734 if (vofInflowProf3_[face].extent(0))
1735 vof::bcColourProfile(f, e3, kVofG, a, sd, vofInflowProf3_[face], vofProf3Nc_[face]);
1736 else
1737 vof::bcColourConst(f, e3, kVofG, a, sd, vofInflowC_[face]);
1738 } else if (bc_[face] == 3 && vofBackflowSet_[face]) {
1739 // reads the face velocity the advector is about to flux with, so it must run after
1740 // bridgeVelocityToVof() — which it does: advectVof bridges the velocity first.
1741 vof::bcColourBackflow(f, e3, kVofG, a, sd, vofAdv_.faceVel(a), vofBackflowC_[face]);
1742 }
1743 }
1744}
1745
1746template <class Grid>
1748 if (!vofBcActive_ || !vofEnabled_)
1749 return;
1750 const bool isColour = cField_.extent(0) && f.data() == cField_.data();
1751 const I3 e2{e_.x, e_.y, e_.z};
1752 for (int face = 0; face < 6; ++face) {
1753 if (bc_[face] != 2 || !vofInflowSet_[face] || !touchesGlobalFace(face))
1754 continue;
1755 const int a = face / 2, sd = face % 2;
1756 if (isColour) {
1757 if (vofInflowProfG2_[face].extent(0))
1758 vof::bcColourProfile(f, e2, G, a, sd, vofInflowProfG2_[face], vofProfG2Nc_[face]);
1759 else
1760 vof::bcColourConst(f, e2, G, a, sd, vofInflowC_[face]);
1761 } else {
1762 for (const auto& cl : closures_)
1763 if (cl.out.data() == f.data())
1764 applyClosureFaceGhost(cl, e_, G, a, sd);
1765 }
1766 }
1767}
1768
1769template <class Grid>
1771 if (!vofEnabled_)
1772 return;
1773 const I3 e3{e3_.x, e3_.y, e3_.z};
1774 const bool px = vofAxisPeriodic(0), py = vofAxisPeriodic(1), pz = vofAxisPeriodic(2);
1775 if (vofBcActive_) {
1776 vofOutside_ = vof::UCField("vof::outside", vofAdv_.size());
1777 vof::buildOutsideMask(vofOutside_, e3, kVofG, vofOrigin(), vofGlobalSize(), px, py, pz);
1778 vofAdv_.setOutsideMask(vofOutside_);
1779 } else {
1780 vofAdv_.setOutsideMask(vof::UCField());
1781 }
1782 // the boundary-flux ledger counts only the GLOBAL domain faces this rank owns
1783 for (int face = 0; face < 6; ++face)
1784 vofAdv_.setBcFaceOwned(face, vofBcActive_ && bc_[face] != 0 && touchesGlobalFace(face));
1785 for (int face = 0; face < 6; ++face) {
1786 vofInflowProf3_[face] = CCField();
1787 vofInflowProfG2_[face] = CCField();
1788 if (vofInflowProfRaw_[face].empty())
1789 continue;
1790 vofInflowProf3_[face] =
1791 resampleFaceScalar(vofInflowProfRaw_[face], vofInflowProfNb_[face], vofInflowProfNc_[face],
1792 face, e3_, kVofG, vofProf3Nc_[face]);
1793 vofInflowProfG2_[face] =
1794 resampleFaceScalar(vofInflowProfRaw_[face], vofInflowProfNb_[face], vofInflowProfNc_[face],
1795 face, e_, G, vofProfG2Nc_[face]);
1796 }
1797}
1798
1799template <class Grid>
1800CCField Solver<Grid>::resampleFaceScalar(const std::vector<double>& prof, int nb, int nc, int face,
1801 C3 ext, int g, int& outNc) {
1802 const int a = face / 2;
1803 const int dims[3] = {ext.x, ext.y, ext.z};
1804 const int bax = (a + 1) % 3, cax = (a + 2) % 3;
1805 const int Lb = dims[bax], Lc = dims[cax];
1806 CCField pf("vof::bcprof", (std::size_t)Lb * Lc);
1807 auto h = Kokkos::create_mirror_view(pf);
1808 auto cl = [](int v, int n) { return v < 0 ? 0 : (v >= n ? n - 1 : v); };
1809 for (int p0 = 0; p0 < Lb; ++p0)
1810 for (int p1 = 0; p1 < Lc; ++p1)
1811 h((long)p0 * Lc + p1) = prof[(std::size_t)cl(p0 - g, nb) * nc + cl(p1 - g, nc)];
1812 Kokkos::deep_copy(pf, h);
1813 outNc = Lc;
1814 return pf;
1815}
1816
1817template <class Grid>
1818void Solver<Grid>::checkVofBcFace(int f, int wantType, const char* who) {
1819 if (f < 0 || f > 5)
1820 throw std::runtime_error(std::string(who) + ": face must be 0..5 (-x,+x,-y,+y,-z,+z)");
1821 enableVof();
1822 if (bc_[f] != wantType)
1823 throw std::runtime_error(std::string(who) + ": face " + std::to_string(f) +
1824 " has domain BC type " + std::to_string(bc_[f]) + ", not " +
1825 std::to_string(wantType) + " — call set_domain_bc(face, " +
1826 std::to_string(wantType) +
1827 ", ...) first (2 = inflow, "
1828 "3 = outflow).");
1829}
1830
1831template <class Grid>
1833 vofBcActive_ = true;
1835 // Refresh C's G=2 ghost band NOW. The property ghosts derive from it (vofBcPropGhosts) and the
1836 // first step's `project()` fills rho's ghosts BEFORE the colour advection refills C's, so
1837 // without this the first step would evaluate rho(C) at the inflow ghost on the pre-BC (Neumann
1838 // copy) colour — i.e. on the interior's phase.
1839 if (vofEnabled_ && cField_.extent(0))
1840 fillPropGhosts(cField_);
1841}
1842
1843template <class Grid>
1845 if (!vofBcActive_)
1846 return;
1847 for (int f = 0; f < 6; ++f) {
1848 vofBcVol_[f] = vofAdv_.bcFaceVolume(f);
1849 vofBcVolTotal_[f] += vofBcVol_[f];
1850 }
1851}
1852
1853template <class Grid>
1855 if (!vofEnabled_)
1856 throw std::runtime_error(
1857 "compute_vof_curvature: VoF is not enabled (call enable_vof / set_vof first)");
1858 if (!kappaField_.extent(0)) {
1859 kappaField_ = addField("kappa");
1860 kappaBranch_ = addField("kappa_branch");
1861 }
1863 // The cascade's purity test must agree with the one the colour field was ADVECTED under. Set
1864 // here, at the point of use, rather than at enable_vof: `set_vof_wisp_eps` and
1865 // `enable_phase_change` both move `wispEps` afterwards, and a stale copy degrades the height
1866 // function silently (see `vof::VofCurvature::pureEps` for the mechanism and the measurement).
1867 vofCurv_.pureEps = vofAdv_.wispEps;
1868 vofCurvStats_ = vofCurv_.compute(vofAdv_.colour());
1869 copyInner(kappaField_, e_, G, CCConst(vofCurv_.kappa()), e3_, kVofG);
1870 copyInner(kappaBranch_, e_, G, CCConst(vofCurv_.branch()), e3_, kVofG);
1871 // kappa is face-interpolated by the V4 surface-tension force exactly as the properties are, so
1872 // it gets the same rank-aware ghost policy they do (WO-G / WO-I).
1873 fillPropGhosts(kappaField_);
1874 fillPropGhosts(kappaBranch_);
1875}
1876
1877template <class Grid>
1879 return vofCurvStats_;
1880}
1881
1882template <class Grid>
1883std::vector<double> Solver<Grid>::getVofCurvature() {
1884 if (!kappaField_.extent(0))
1885 throw std::runtime_error("vof_curvature: call compute_vof_curvature() first");
1886 std::vector<double> out = gatherInner(kappaField_);
1887 const double k = u_.curvToPhys();
1888 if (k != 1.0)
1889 for (double& x : out)
1890 x *= k;
1891 return out;
1892}
1893
1894template <class Grid>
1896 if (!kappaBranch_.extent(0))
1897 throw std::runtime_error("vof_curvature_branch: call compute_vof_curvature() first");
1898 return gatherInner(kappaBranch_);
1899}
1900
1901template <class Grid>
1903 vofCurv_.weightWidth = d;
1904}
1905
1906template <class Grid>
1908 return vofCurv_.weightWidth;
1909}
1910
1911template <class Grid>
1913 vofCurv_.useMixedHeightFit = on;
1914}
1915
1916template <class Grid>
1918 return vofCurv_.useMixedHeightFit;
1919}
1920
1921template <class Grid>
1923 if (!(sigma >= 0.0))
1924 throw std::runtime_error("set_surface_tension: sigma must be >= 0");
1925 if (sigma > 0.0) {
1926 enableVof();
1927 if (!kappaField_.extent(0)) {
1928 kappaField_ = addField("kappa");
1929 kappaBranch_ = addField("kappa_branch");
1930 }
1931 // Wisp guard on the curvature's interfacial predicate. NOT optional once the curvature feeds
1932 // a force: Weymouth-Yue leaves round-off colour residue (measured down to -3e-35) in every
1933 // cell its sweeps touch, those cells satisfy `0 < C < 1`, and the cascade returns |kappa| up
1934 // to 1e8 for them off a zero-area PLIC polygon. A face between one of them and a real
1935 // interfacial cell then carries a force eight orders too large. See
1936 // `vof::VofCurvature::interfaceEps` for the measurement; the V3 default (0) is unchanged for
1937 // anyone calling `compute_vof_curvature()` without surface tension.
1938 vofCurv_.interfaceEps = csfInterfaceEps_;
1939 }
1940 // sigma is PHYSICAL (force per unit length); internally sigma*tRef^2/(rhoRef*hRef^3), which is
1941 // what makes p' = sigma'*kappa' hold with kappa' = kappa*hRef.
1942 sigmaPhys_ = sigma;
1943 sigmaCsf_ = sigma * u_.sigmaToInt();
1944 registerBalancedForceState(); // V8 (collocated CSF) turns the balanced-force projection on
1945}
1946
1947template <class Grid>
1949 return sigmaPhys_;
1950}
1951
1952template <class Grid>
1954 csfInterfaceEps_ = eps;
1955 if (sigmaCsf_ > 0.0)
1956 vofCurv_.interfaceEps = eps;
1957}
1958
1959template <class Grid>
1961 return csfInterfaceEps_;
1962}
1963
1964template <class Grid>
1965void Solver<Grid>::setVofBlockKappaClip(bool enabled, double kappaMaxPhys) {
1966 double km = 0.0; // off
1967 if (enabled) {
1968 if (kappaMaxPhys < 0.0)
1969 km = -1.0; // the default 1/Delta_min, evaluated against the cascade's own metric
1970 else if (kappaMaxPhys > 0.0)
1971 km = kappaMaxPhys * u_.lenToPhys(); // kappa' = kappa * hRef (index units)
1972 else
1973 throw std::runtime_error(
1974 "set_vof_block_kappa_clip: kappa_max must be > 0 (or None for 1/Delta_min)");
1975 }
1976 vofBlockKappaMax_ = km; // the single-field cascade (vofCurv_) never clips (§11)
1977 if (vofBlocks_)
1978 vofBlocks_->setKappaMax(km);
1979}
1980
1981template <class Grid>
1983 csfMode_ = m;
1984}
1985
1986template <class Grid>
1988 return csfMode_;
1989}
1990
1991template <class Grid>
1993 return static_cast<bool>(vofBlocks_) && vofBlocks_->csfEnabled;
1994}
1995
1996template <class Grid>
1998 return vofEnabled_ && sigmaCsf_ > 0.0 && (kappaField_.extent(0) != 0 || vofBlockCsf());
1999}
2000
2001template <class Grid>
2003 kappaFrozen_ = on;
2004}
2005
2006template <class Grid>
2008 return kappaFrozen_;
2009}
2010
2011template <class Grid>
2013 enableVof();
2014 if (!kappaField_.extent(0)) {
2015 kappaField_ = addField("kappa");
2016 kappaBranch_ = addField("kappa_branch");
2017 }
2018 Kokkos::deep_copy(kappaField_, kappa / u_.curvToPhys());
2019 Kokkos::deep_copy(kappaBranch_, (double)vof::kCurvHf);
2020 kappaFrozen_ = true;
2021}
2022
2023template <class Grid>
2025 return capillaryDtInternal() * u_.timeToPhys();
2026}
2027
2028template <class Grid>
2030 if (!(sigmaCsf_ > 0.0))
2031 return std::numeric_limits<double>::infinity();
2032 // Phase 3 (V3.2): the SMALLEST spacing sets the shortest resolvable capillary wave. `hpMin`
2033 // is exactly 1.0 on every isotropic run, so the number is unchanged.
2034 double hpMin = u_.hp[0];
2035 for (int a = 1; a < 3; ++a)
2036 hpMin = hpMin < u_.hp[a] ? hpMin : u_.hp[a];
2037 // vof_overlap_design §5.6: while two block markers overlap, the part of A's surface inside B
2038 // is an interface with rho_min on BOTH sides, so its Brackbill bound uses 2 rho_min.
2039 if (vofOverlap_.active && vofBlockCsf()) {
2040 double lo = 0.0, hi = 0.0;
2041 phaseDensityRange(lo, hi);
2042 return vof::capillaryDt(2.0 * lo, vofEnabled_ ? hpMin : 1.0, sigmaCsf_);
2043 }
2044 return vof::capillaryDt(phaseDensitySum(), vofEnabled_ ? hpMin : 1.0, sigmaCsf_);
2045}
2046
2047template <class Grid>
2049 capillaryCfl_ = f;
2050}
2051
2052template <class Grid>
2054 return capillaryCfl_;
2055}
2056
2057template <class Grid>
2059 VofStepLimits L;
2060 L.courant = vofMaxCourant();
2061 L.cflDt = (L.courant > 0.0) ? dtPhys_ * vofCflLimit_ / L.courant
2062 : std::numeric_limits<double>::infinity();
2063 L.capillaryDt = capillaryDt();
2064 const double cap = capillaryCfl_ * L.capillaryDt;
2065 L.capillaryBinds = cap < L.cflDt;
2066 L.binding = L.capillaryBinds ? cap : L.cflDt;
2067 return L;
2068}
2069
2070template <class Grid>
2072 double lo = 0.0, hi = 0.0;
2073 phaseDensityRange(lo, hi);
2074 return lo + hi;
2075}
2076
2077template <class Grid>
2078void Solver<Grid>::phaseDensityRange(double& rlo, double& rhi) {
2079 if (vofMomEnabled_) {
2080 rlo = std::fmin(vofRhoG_, vofRhoL_);
2081 rhi = std::fmax(vofRhoG_, vofRhoL_);
2082 return;
2083 }
2084 if (!effVarRho()) {
2085 rlo = rho_;
2086 rhi = rho_;
2087 return;
2088 }
2089 CCExec space;
2090 C3 e = e_;
2091 double lo = 1e300, hi = -1e300;
2092 using MD = MDRange3<CCExec>;
2093 // A closure-driven rho field is produced by updateProperties() at the head of the step, so
2094 // before the FIRST step it is still all zeros and a naive min+max would report 0 — and this is
2095 // a diagnostic users call while choosing dt, i.e. exactly then. Refresh and retry once in that
2096 // case; the step's own call site runs after updateProperties() and never takes the branch.
2097 for (int pass = 0; pass < 2; ++pass) {
2099 lo = 1e300;
2100 hi = -1e300;
2101 Kokkos::parallel_reduce(
2102 "rho_minmax", MD(space, {G, G, G}, {e.x - G, e.y - G, e.z - G}),
2103 KOKKOS_LAMBDA(int x, int y, int z, double& mn, double& mx) {
2104 const long i = (long)x + (long)y * e.x + (long)z * (long)e.x * e.y;
2105 mn = Kokkos::fmin(mn, f(i));
2106 mx = Kokkos::fmax(mx, f(i));
2107 },
2108 Kokkos::Min<double>(lo), Kokkos::Max<double>(hi));
2109 if (hi > 0.0 || pass == 1)
2110 break;
2112 }
2113#ifdef PECLET_FLOW_MPI
2114 if (distributed_) {
2115 double g[2] = {lo, -hi}, r[2];
2116 MPI_Allreduce(g, r, 2, MPI_DOUBLE, MPI_MIN, comm_);
2117 lo = r[0];
2118 hi = -r[1];
2119 }
2120#endif
2121 rlo = lo;
2122 rhi = hi;
2123}
2124
2125template <class Grid>
2126double Solver<Grid>::stepAdaptive(double cflTarget, double capillaryCflTarget, double dtMax) {
2127 if (!vofEnabled_)
2128 throw std::runtime_error(
2129 "step_adaptive: needs enable_vof() (it picks dt from the two "
2130 "explicit two-phase limits vof_step_limits() reports)");
2131 if (!(cflTarget > 0.0) || !(capillaryCflTarget > 0.0) || !(dtMax > 0.0))
2132 throw std::runtime_error("step_adaptive: cfl_target, capillary_cfl and dt_max must be > 0");
2133 const VofStepLimits L = vofStepLimits();
2134 double dt = cflTarget * L.cflDt;
2135 const double dc = capillaryCflTarget * L.capillaryDt;
2136 if (dc < dt)
2137 dt = dc;
2138 if (dtMax < dt)
2139 dt = dtMax;
2140 if (!(dt > 0.0) || !std::isfinite(dt))
2141 throw std::runtime_error("step_adaptive: no finite dt (cfl_dt = " + std::to_string(L.cflDt) +
2142 ", capillary_dt = " + std::to_string(L.capillaryDt) +
2143 ") - pass a finite dt_max when neither limit is active");
2144 setDt(dt);
2145 // The limits were just evaluated on this exact state, so `step()`'s own head-of-step
2146 // pre-check (item 1) would repeat the interface-local reduction and the g=3 fill for nothing.
2147 vofPrecheckDone_ = true;
2148 step();
2149 return dt;
2150}
2151
2152template <class Grid>
2154 const bool skip = vofPrecheckDone_;
2155 vofPrecheckDone_ = false;
2156 if (!vofEnabled_ || skip)
2157 return;
2158 if (csfActive()) {
2159 const double cap = capillaryCfl_ * capillaryDtInternal();
2160 if (!(dt_ <= cap))
2161 throw std::runtime_error(capillaryThrowMessage(cap));
2162 }
2163 // The block container carries one advector per marker with its own colour support; the union
2164 // field on `vofAdv_` is a derived quantity there, so the cap is left to the blocks themselves.
2165 if (vofBlocks_)
2166 return;
2167 const double cfl = vofMaxCourant();
2168 if (!(cfl <= vofCflLimit_))
2169 throw std::runtime_error(
2170 "peclet::flow::vof::WyAdvector: CFL = max|uf| dt/h = " + std::to_string(cfl) +
2171 " exceeds the Weymouth-Yue boundedness cap " + std::to_string(vofCflLimit_) +
2172 " (dt = " + std::to_string(dt_) + ", h = " + std::to_string(vofAdv_.h()) +
2173 ") - reduce dt. Rejected at the HEAD of step(): no field has been advanced, so a retry "
2174 "at a smaller dt is exact (see set_vof_cfl_limit / step_adaptive).");
2175}
2176
2177template <class Grid>
2178std::string Solver<Grid>::capillaryThrowMessage(double cap) const {
2179 const std::string rho = (vofOverlap_.active && vofBlockCsf())
2180 ? "2 rho_min [block markers overlap: the phantom gas-gas interface, "
2181 "vof_overlap_design 5.6]"
2182 : "rho_1+rho_2";
2183 return "surface tension: dt = " + std::to_string(dt_) + " exceeds the capillary limit " +
2184 std::to_string(cap) + " (Brackbill sqrt((" + rho + ") h^3/(4 pi sigma)) = " +
2185 std::to_string(cap / (capillaryCfl_ > 0.0 ? capillaryCfl_ : 1.0)) + " x safety factor " +
2186 std::to_string(capillaryCfl_) +
2187 "). Surface tension is EXPLICIT: this is a hard stability boundary (Denner & van "
2188 "Wachem 2015), not a margin. Reduce dt, or raise set_capillary_cfl deliberately.";
2189}
2190
2191template <class Grid>
2193 if (!csfActive())
2194 return;
2195 if (vofBlockCsf())
2196 computeVofBlockCsf(); // rung W2: per-block cascade + the CSF face force, scattered SUM
2197 else if (!kappaFrozen_)
2199 const double cap = capillaryCfl_ * capillaryDtInternal();
2200 if (!(dt_ <= cap))
2201 throw std::runtime_error(capillaryThrowMessage(cap));
2202}
2203
2204template <class Grid>
2206 if (!vofEnabled_)
2207 return;
2208 // Rung W2: with the block container on, the colour is the BLOCKS' state and the registered
2209 // "C" is the union derived from it — so the step's colour stage is the block advection, in
2210 // exactly this slot and for exactly the same reason (the face field has just been projected).
2211 // `vofBlocks_` is null unless `enable_vof_blocks` ran, so every other path is unchanged.
2212 if (vofBlocks_) {
2213 advectVofBlocksInternal(dt_, /*requireSolenoidal=*/false); // dt_ is internal
2214 return;
2215 }
2216 requireVofGeometry("enable_vof");
2217 const double _tv0 = vofTick(); // WO-V9: the whole colour stage
2218 double _tb = 0.0; // ... of which the G=2 <-> g=3 bridges
2219 const double _tb0 = vofTick();
2222 vofAdd(_tb, _tb0);
2223 vofAdv_.resetBcFaceVolume(); // WO-R: the per-step boundary liquid ledger
2224 if (pcEnergy_) {
2225 // WO-P23: the CONSISTENT rho c_p T transport. The temperature rides the SAME sweeps, planes
2226 // and fluxes as the colour (`vof/energy_advect.hpp`), so it has to be bridged onto the g=3
2227 // block first and taken off it after; the scalar module then does diffusion ONLY (its
2228 // `energy` flag switches off the Koren advective term and the constant-D operator).
2229 ScalarField& sc = scalarField(pcTName_);
2230 copyInner(vofEnergy_.temperature(), e3_, kVofG, CCConst(sc.c), e_, G);
2231 vofEnergy_.advect(vofAdv_, dt_, vofStep_++);
2232 copyInner(sc.c, e_, G, CCConst(vofEnergy_.temperature()), e3_, kVofG);
2233 scalarFillGhosts(sc);
2234 } else {
2235 vofAdv_.advect(dt_, vofStep_++);
2236 }
2238 // Back to the G=2 registry mirror, then ITS ghost policy: the closures write inner cells only,
2239 // but the property face means (rho_f in the momentum diagonal, the projection coefficient, the
2240 // face body force) read the ghost ring, so C's ghosts must be filled with the SAME policy rho
2241 // uses or the derived rho ghost is inconsistent with the interior at a boundary.
2242 const double _tb1 = vofTick();
2243 copyInner(cField_, e_, G, CCConst(vofAdv_.colour()), e3_, kVofG);
2244 zeroSolidColour(); // rung V5a: the canonical field carries 0 in solid cells, not the fill
2245 fillPropGhosts(cField_);
2246 vofAdd(_tb, _tb1);
2247 vofAdd(vt_.advect, _tv0);
2248 vt_.bridge += _tb;
2249}
2250
2251template <class Grid>
2252void Solver<Grid>::enableVofMomentum(double rhoGasPhys, double rhoLiquidPhys) {
2253 const double rhoGas = rhoGasPhys * u_.rhoToInt(), rhoLiquid = rhoLiquidPhys * u_.rhoToInt();
2254 if constexpr (Grid::collocated)
2255 throw std::runtime_error(
2256 "enable_vof_momentum: momentum-consistent VoF transport is STAGGERED-ONLY (rung V2b); the "
2257 "collocated construction is Favre-averaged face states, rung V8.");
2258 enableVof();
2259 if (porous_)
2260 throw std::runtime_error(
2261 "enable_vof_momentum: the volume-averaged porous momentum and the momentum-consistent VoF "
2262 "transport both own the momentum time term; they are not composable at this rung.");
2263 if (!(rhoGas > 0.0) || !(rhoLiquid > 0.0))
2264 throw std::runtime_error("enable_vof_momentum: both phase densities must be > 0");
2265 if (vofBlocks_)
2266 throw std::runtime_error(kVofMomBlocksMsg);
2267 // The pair is (rho at C = 0, rho at C = 1) and must be what the density closure produces there:
2268 // the momentum flux is rho(C=0)*(a-F) + rho(C=1)*F. A swapped pair is not caught by anything
2269 // downstream — it transports the momentum at the other phase's density, silently (Q6).
2270 double rho0Phys = 0.0, rho1Phys = 0.0;
2271 if (vofRhoClosureEnds(rho0Phys, rho1Phys)) {
2272 auto differs = [](double a, double b) {
2273 return std::fabs(a - b) > 1e-9 * std::fmax(std::fabs(a), std::fabs(b));
2274 };
2275 if (differs(rhoGasPhys, rho0Phys) || differs(rhoLiquidPhys, rho1Phys)) {
2276 char msg[640];
2277 std::snprintf(
2278 msg, sizeof(msg),
2279 "enable_vof_momentum(rho_c0=%.10g, rho_c1=%.10g): the pair must be the density at "
2280 "C = 0, then the density at C = 1, whichever phase each is. The 'rho' closure gives "
2281 "rho(C=0) = %.10g, "
2282 "rho(C=1) = %.10g%s",
2283 rhoGasPhys, rhoLiquidPhys, rho0Phys, rho1Phys,
2284 (!differs(rhoGasPhys, rho1Phys) && !differs(rhoLiquidPhys, rho0Phys))
2285 ? " -- the pair is SWAPPED."
2286 : ".");
2287 throw std::runtime_error(msg);
2288 }
2289 }
2290 vofRhoG_ = rhoGas;
2291 vofRhoL_ = rhoLiquid;
2292 vofMomEnabled_ = true;
2293 for (int c = 0; c < 3; ++c)
2294 if (uAdv_[c].extent(0) != n_)
2295 uAdv_[c] = CCField("uAdv", n_);
2296 vofMom_.init(vofAdv_, vofRhoG_, vofRhoL_);
2297}
2298
2299template <class Grid>
2300bool Solver<Grid>::vofRhoClosureEnds(double& rho0Phys, double& rho1Phys) const {
2301 // The LAST closure writing "rho" is the one in force (closures apply in registration order).
2302 const Closure* cl = nullptr;
2303 for (const auto& c : closures_)
2304 if (c.outName == "rho")
2305 cl = &c;
2306 if (!cl || cl->in0Name != "C" || !cl->in1Name.empty())
2307 return false;
2308 if (cl->kind == ClosureKind::LinearMix) {
2309 rho0Phys = cl->pPhys[0];
2310 rho1Phys = cl->pPhys[0] + cl->pPhys[1];
2311 return true;
2312 }
2313 if (cl->kind != ClosureKind::Table1D || cl->nTab <= 0)
2314 return false;
2315 // Clamped piecewise-linear, as applyClosure evaluates it, on the caller's (physical) ys.
2316 auto hx = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), cl->tabX);
2317 const auto& ys = cl->tabYPhys;
2318 auto at = [&](double s) {
2319 const int n = cl->nTab;
2320 if (s <= hx(0))
2321 return ys[0];
2322 if (s >= hx(n - 1))
2323 return ys[n - 1];
2324 int lo = 0;
2325 while (lo + 1 < n - 1 && hx(lo + 1) <= s)
2326 ++lo;
2327 return ys[lo] + (s - hx(lo)) / (hx(lo + 1) - hx(lo)) * (ys[lo + 1] - ys[lo]);
2328 };
2329 rho0Phys = at(0.0);
2330 rho1Phys = at(1.0);
2331 return true;
2332}
2333
2334template <class Grid>
2336 return vofMomEnabled_;
2337}
2338
2339template <class Grid>
2341 vofMom_.rhoFloorFrac = f;
2342}
2343
2344template <class Grid>
2346 return vofMom_.rhoFloorFrac;
2347}
2348
2349template <class Grid>
2351 return vofMom_.lastRhoFloor();
2352}
2353
2354template <class Grid>
2355void Solver<Grid>::setVofMomentumScheme(const std::string& name) {
2356 using MS = vof::MomentumScheme;
2357 if (name == "upwind")
2358 vofMom_.momentumScheme = MS::Upwind;
2359 else if (name == "muscl_mixed")
2360 vofMom_.momentumScheme = MS::MusclMixed;
2361 else if (name == "muscl_mixed_capped")
2362 vofMom_.momentumScheme = MS::MusclMixedCapped;
2363 else if (name == "muscl_phase")
2364 vofMom_.momentumScheme = MS::MusclPhase;
2365 else
2366 throw std::invalid_argument("set_vof_momentum_scheme: unknown scheme '" + name +
2367 "' (expected 'upwind', 'muscl_mixed', 'muscl_mixed_capped' or "
2368 "'muscl_phase')");
2369}
2370
2371template <class Grid>
2373 switch (vofMom_.momentumScheme) {
2375 return "upwind";
2377 return "muscl_mixed";
2379 return "muscl_mixed_capped";
2381 return "muscl_phase";
2382 }
2383 return "upwind";
2384}
2385
2386template <class Grid>
2390
2391template <class Grid>
2393 vofMom_.useCellDilationFlag = on;
2394}
2395
2396template <class Grid>
2398 vofMom_.clampFluxes = on;
2399}
2400
2401template <class Grid>
2403 if (!vofMomEnabled_)
2404 throw std::runtime_error("vof_momentum_diagnostics: enable_vof_momentum was never called");
2405 return vofMom_.diagnostics();
2406}
2407
2408template <class Grid>
2409std::vector<double> Solver<Grid>::getVofAdvectedVelocity(int c) {
2410 if (!vofMomEnabled_)
2411 throw std::runtime_error("vof_advected_velocity: enable_vof_momentum was never called");
2412 return gatherInner(uAdv_[c]);
2413}
2414
2415template <class Grid>
2417 if (!vofMomEnabled_)
2418 return;
2419 requireVofGeometry("enable_vof_momentum");
2420 // No implicit-advection guard: advectsMomentum() is false under VoF momentum, so implicitAdv()
2421 // is too -- the VoF fluxes carry the momentum advection, the solver's own operator never runs.
2422 if (!effVarRho())
2423 throw std::runtime_error(
2424 "enable_vof_momentum requires the variable-density momentum/projection path: register a "
2425 "density closure on C (set_property_model('rho','linear','C',[rho_g, rho_l-rho_g])) or "
2426 "call set_density_mode('variable').");
2427 if (vofMom_.phaseRhoG() != vofRhoG_ || vofMom_.phaseRhoL() != vofRhoL_)
2428 vofMom_.setPhaseDensities(vofRhoG_, vofRhoL_);
2429 const double _tv0 = vofTick(); // WO-V9: the whole colour + momentum stage
2430 double _tb = 0.0;
2431 const double _tb0 = vofTick();
2434 vofAdd(_tb, _tb0);
2435 vofAdv_.resetBcFaceVolume(); // WO-R: the per-step boundary liquid ledger
2436 vofMom_.advect(vofAdv_, dt_, vofStep_++);
2438 // Colour back to the G=2 registry mirror (same contract as advectVof), and the advected
2439 // velocity back onto the solver's velocity index convention.
2440 const double _tb1 = vofTick();
2441 copyInner(cField_, e_, G, CCConst(vofAdv_.colour()), e3_, kVofG);
2443 fillPropGhosts(cField_);
2444 // A plain inner-to-inner copy: the momentum control volumes are indexed in the solver's own
2445 // low-face convention (vof/momentum_advect.hpp "Indexing"), so CV_c(i) IS the solver's u_c(i)
2446 // and there is no shift here to get wrong.
2447 for (int c = 0; c < 3; ++c)
2448 copyInner(uAdv_[c], e_, G, CCConst(vofMom_.advectedVelocity(c)), e3_, kVofG);
2449 vofAdd(_tb, _tb1);
2450 vofAdd(vt_.momAdvect, _tv0);
2451 vt_.momBridge += _tb;
2452}
2453
2454template <class Grid>
2456 const bool px = vofAxisPeriodic(0), py = vofAxisPeriodic(1), pz = vofAxisPeriodic(2);
2457#ifdef PECLET_FLOW_MPI
2458 if (distributed_ && vofDev_)
2459 vofDev_->exchange(f);
2460 else
2461#endif
2462 vof::periodicFill(f, I3{e3_.x, e3_.y, e3_.z}, kVofG, px, py, pz);
2463 if (px && py && pz)
2464 return;
2465 const I3 gs = vofGlobalSize(), org = vofOrigin();
2466 vof::clampFill(f, I3{e3_.x, e3_.y, e3_.z}, kVofG, org, gs, px, py, pz);
2467}
2468
2469template <class Grid>
2470double Solver<Grid>::vofTick() const {
2471 if (!vofTiming_)
2472 return 0.0;
2473 // As phaseTick(): the step's device work is on the default instance, so its fence times it; a
2474 // global fence would also wait on the side factor (X) and bill it to the stage (curvature).
2475 CCExec().fence("peclet::flow::vof_tick");
2477}
2478
2479template <class Grid>
2480void Solver<Grid>::vofAdd(double& acc, double t0) {
2481 if (!vofTiming_)
2482 return;
2483 CCExec().fence("peclet::flow::vof_add"); // as vofTick()
2484 acc += vof::WyAdvector::wallSeconds() - t0;
2485}
2486
2487} // namespace peclet::flow
2488
2489#endif // PECLET_FLOW_FLOW_IBM_VOF_HPP
void imposeDomainWallKind(int mask)
void vofExchangeScalar(CCField f)
The colour block's ghost policy WITHOUT the colour-specific rules (no solid-band fill,...
void setVofMomentumMuscl(bool on)
void setVofCurvatureMixedHeightFit(bool on)
void setContactAngleClamp(double loDeg, double hiDeg)
const VofTiming & vofTimingReport() const
bool vofBlocksEnabled() const
void setVofRhoFloorFrac(double f)
void enableVofBlocksFromField(const std::vector< std::array< int, 6 > > &boxes)
static constexpr int kVofG
void setContactAngleSmoothing(bool on)
void vofApplyColourBc(CCField f)
The colour field's boundary rules, applied at the END of vofFillGhosts — i.e.
void fillVelGhosts(int comp, int fold)
double maxOpenDivergenceInternal()
The same diagnostic in INDEX units (per tRef), which is what the solver's own guards read.
void addCsfRhs(int c, CCField dst, bool rowScaled, bool faceRange=false)
double capillaryCfl() const
void scatterInner(CCField fld, const std::vector< double > &in)
void setContactAnglePivot(int mode)
void setVofBlockPool(bool on)
bool contactAngleSet() const
ScalarField & scalarField(const std::string &name)
void setVofKappaConstant(double kappa)
kappa is a PHYSICAL curvature, 1/length (the internal field is 1/h; see vof_curvature()).
std::vector< double > getVofCurvature()
The interface curvature kappa = 2H in the caller's units, i.e.
void fillPropGhosts(CCField f, bool edges=false)
void checkVofBcFace(int f, int wantType, const char *who)
A VoF boundary colour is only meaningful on a face that already carries the matching domain BC,...
void setVofTiming(bool on)
std::vector< double > vofBlockKappa(long id)
void addCsfRhsBlocks(int c)
std::string vofMomentumScheme() const
void setVofMomentumCellFlag(bool on)
CCField addField(const std::string &name)
void vofBcArm()
Arm the rung: install the mask, rebuild the profiles, and zero the boundary volume ledger.
bool vofHasGeometry() const
bool vofRhoClosureEnds(double &rho0Phys, double &rho1Phys) const
void advectVofBlocksInternal(double dtInt, bool requireSolenoidal)
The same with dt already in INTERNAL time (step() passes its dt_).
std::vector< double > getVofFilledColour()
void enableVofBlocks(const std::vector< std::array< double, 4 > > &seeds)
void pcUpdateEnergyProps()
Refresh k(C) and (rho c_p)(C) on the G=2 block from the current colour.
std::vector< double > getVofAdvectedVelocity(int c)
void setContactAngleDynamic(double thetaEDeg, double slipCells, double muLiquid, double sigma=0.0)
void setPressureExactResidual(bool on)
WO-R2 item 3 — the exact (matrix-free, double, flux-form) level-0 operator apply in the residual and ...
std::vector< double > getVofGeometry(int which)
void vofRebuildBcBlock()
(Re)build everything that lives on the g=3 block for this rung: the out-of-domain mask and the resamp...
void fillFaceGhostsKeepBoundary(CCField f, int a)
std::vector< double > vofBcVolumes() const
Signed liquid volume that crossed each of the six domain faces during the LAST colour advection,...
double maxOpenDivergenceProjectedInternal()
The same diagnostic in INDEX units (per tRef), which is what the solver's own guards read.
std::vector< double > getVof()
double surfaceTension() const
The surface tension in the caller's units (what set_surface_tension was given).
void copyInner(CCField dst, C3 de, int dg, CCConst src, C3 se, int sg)
double capillaryDtInternal()
The same limit in the solver's index time (per tRef) — what the step's own guards compare to.
double vofTimingProjectionSeconds() const
CsfDiagnostics csfDiagnostics()
void setSurfaceTension(double sigma)
void vofHarvestBcVolumes()
Move the advector's per-face boundary volume ledger into the solver's, once per advection.
void enableVofMomentum(double rhoGasPhys, double rhoLiquidPhys)
rhoGas / rhoLiquid are PHYSICAL densities, the same numbers the rho closure is given.
std::vector< double > getVofCurvatureBranch()
void setVofInflowProfile(int f, const std::vector< double > &prof, int nb, int nc)
Per-position inflow colour on face f: prof is (nb, nc) on the INNER grid of the face's two perpendicu...
double vofBlockImbalanceOf(int mode) const
void requireVofGeometry(const char *who)
double capillaryDt()
The Brackbill capillary limit in the CALLER's time unit.
void setVof(const std::vector< double > &c)
void setContactAngleHysteresis(double thetaADeg, double thetaRDeg)
static constexpr double defaultVofWispEps()
The value enableVof starts from.
void buildVelocityOverlays(bool resetU)
Build the three per-component Robust-Scaled cut-cell overlays + solid masks from the CURRENT sdf_ (ex...
vof::VofCurvature::Stats vofBlockCurvatureStats() const
void applyDomainWallGeometry(int mask)
std::vector< double > getVofBlockForce(int c)
bool vofKappaFrozen() const
std::array< long, 2 > vofBlockPoolStats() const
void setVofCutFluxClamp(bool on)
ContactAngleDiagnostics contactAngleDiagnostics()
void setVofCurvatureWeightWidth(double d)
bool vofCutFluxClamp() const
double vofRhoFloorFrac() const
double vofTimingPredictorSeconds() const
void vofExchangeRaw(CCField f)
double wallSlipLength() const
The Navier slip length in the caller's units (0 = no-slip).
double vofInterfaceEps() const
void setVofBlockAssign(int mode, long every)
double contactAngle() const
void setWallSlipLength(double lambdaCells)
WO-V6b – the VELOCITY half of the dynamic contact line.
void requireWettingWall() const
void vofBlockCensus(std::vector< long > &masters, std::vector< long > &cells) const
void setVofBackflow(int f, double value)
inletOutlet backflow colour on outflow face f (default 0 = gas): where the boundary face velocity poi...
vof::MomentumConsistentAdvector::Diagnostics vofMomentumDiagnostics()
std::vector< double > vofBlockColour(long id)
std::vector< double > getVofDynamicField(int which)
void setVofCurvatureWorklist(bool on)
VofCurvature::useWorklist — run the height-function cascade and the PV fallback over a COMPACTED list...
static constexpr int G
Definition flow_ibm.hpp:82
void setContactAngleField(const std::vector< double > &thetaDeg)
void setCapillaryCfl(double f)
const vof::VofCurvature::Timing & vofCurvatureTiming() const
CCField resampleFaceScalar(const std::vector< double > &prof, int nb, int nc, int face, C3 ext, int g, int &outNc)
Clamp-resample a per-position face scalar from the user's (nb, nc) INNER grid onto the ghost-inclusiv...
bool vofMomentumEnabled() const
vof::VofCurvature::Stats vofCurvatureStats() const
void setVofPhantomCapillaryBound(bool enabled)
int contactAnglePivot() const
void setVofMomentumScheme(const std::string &name)
std::vector< double > vofBcVolumesTotal() const
The same, accumulated since enable_vof() (or the last resetVofBcVolumes()).
void setVofWorklist(bool on)
WyAdvector::useWorklist — the compaction of the PLIC reconstruction pass onto the mixed cells.
void vofExtendWallBand(CCField f, int mask)
void setVofInflow(int f, double value)
Colour of the fluid entering through inflow face f (0..5 = -x,+x,-y,+y,-z,+z), in [0,...
bool contactAngleHysteresis() const
void setVofStepParity(long n)
long strideOf(int c) const
const vof::WyAdvector::Timing & vofKernelTiming() const
void fillVelGhostsTo(CCField f, int comp, int fold, bool doOutflow=true, bool faceEdges=false)
void collocatedV8AutoFallback(const char *why)
std::array< int, 3 > wallSlipSandwichCells() const
Cut-cell axes at which a one-cell fluid gap kept the no-slip closure (per component).
void setVofBlockDeviceStaging(bool on)
void setVofKappaFrozen(bool on)
double vofRhoFloor() const
double stepAdaptive(double cflTarget, double capillaryCflTarget, double dtMax)
void setVofBlockOverlapDensity(bool enabled)
static double vofWallPlaneSdf(int gx, int gy, int gz, I3 gs, int mask)
void enableVofBlocksFromColours(const std::vector< std::array< int, 6 > > &boxes, const std::vector< std::vector< double > > &colours)
void setVofBlockDebris(bool enabled)
void advectVofKinematic(double dtPhysArg)
dt is in the caller's time unit.
void setVofInterfaceEps(double eps)
void setVofWispEps(double eps)
WO-R2 item 4 — the wisp threshold on the advector's mixed-cell predicate and on the interface Courant...
double effectiveContactSigma() const
void setVofBlockKappaClip(bool enabled, double kappaMaxPhys=-1.0)
double vofLastCourant() const
std::string capillaryThrowMessage(double cap) const
bool contactAngleDynamic() const
double vofTimingMomentumSeconds() const
double vofTimingStepSeconds() const
void setVofSolidColourZero(bool on)
std::vector< vof::VofBox > vofBlockRankBoxes(int size) const
double vofCurvatureWeightWidth() const
void phaseDensityRange(double &lo, double &hi)
void vofBcPropGhosts(CCField f)
WO-R item 5 — the Neumann property policy at an inflow face.
void vofFillGhosts(CCField f)
void addCsfRhsCellInterp(int c, CCField dst, bool rowScaled, bool faceRange=false)
const vof::WyAdvector & vofAdvector() const
vof::WyAdvector::Diagnostics vofDiagnostics()
bool vofAxisPeriodic(int a) const
void setVofCflLimit(double v)
VofStepLimits vofStepLimits()
Both limits at the current state, in the CALLER's time unit (courant is dimensionless).
std::vector< double > gatherInner(CCField fld)
double vofWispEps() const
bool vofSolidColourZero() const
bool vofCurvatureWorklist() const
double vofBlockImbalance() const
std::vector< vof::VofBlockStats > vofBlockStats() const
void advectVofBlocks(double dtPhysArg, bool requireSolenoidal=true)
dt is in the caller's time unit.
void setContactAngle(double thetaDeg)
void setVofFluxClamp(bool on)
bool vofCurvatureMixedHeightFit() const
double contactAngleSlip() const
double vofCflLimit() const
Weymouth-Yue split advection of a colour field on an extended (inner + ghost) block.
double capillaryDt(double rhoSum, double h, double sigma)
Brackbill capillary time-step limit sqrt((ρ₁+ρ₂) h³ / (4πσ)).
bool csfKappaDefined(double branch)
Is the curvature of a cell carrying branch code branch usable?
Kokkos::View< unsigned char *, SMem > UCField
Definition advect_wy.hpp:89
void bcColourBackflow(SField f, I3 e, int g, int a, int s, SField un, double backflow)
inletOutlet on an outflow face: where the boundary face velocity points INTO the domain,...
void bcColourConst(SField f, I3 e, int g, int a, int s, double value)
Overwrite ALL g ghost layers of domain face (axis a, side s) with a constant colour.
void bcColourProfile(SField f, I3 e, int g, int a, int s, SField prof, int nc)
Same, with a per-position colour on the face's (b, c) plane.
void buildOutsideMask(UCField m, I3 e, int g, I3 o, I3 gs, bool px, bool py, bool pz)
1 for every ghost cell of the block that lies OUTSIDE the global domain on a non-periodic axis,...
Definition colour_bc.hpp:84
@ kVofDynReceding
theta_app < theta_r: theta_r (+ Cox-Voinov)
@ kVofDynPinned
theta_r <= theta_app <= theta_a: the apparent angle is imposed
@ kVofDynAdvancing
theta_app > theta_a: theta_a (+ Cox-Voinov)
VofMasterAssign
How a block's MASTER rank is chosen.
void clampFill(SField f, I3 e, int g, I3 o, I3 gs, bool px, bool py, bool pz, int skip=0)
Zero-gradient (Neumann) fill of the ghost cells that lie OUTSIDE the global domain on a non-periodic ...
void copyFaceVelocity(SField dst, I3 de, int dg, SField src, I3 se, int sg, int dir)
Embed the ENTIRE source extended block (inner + its sg ghost layers) into a LARGER destination extend...
void periodicFill(SField f, I3 e, int g, bool px, bool py, bool pz)
Periodic wrap of a single-block extended field at ghost width g (the single-rank ghost path; under MP...
double csfFaceForce(double sigma, double kf, double dC, double hGrad)
The balanced-force CSF contribution to the momentum RHS at one staggered velocity unknown,...
MomentumScheme
The transported face velocity of the momentum flux (doc/vof_momentum_second_order....
bool csfFaceCurvature(double k0, double b0, double k1, double b1, double &kf)
Face curvature for the balanced-force CSF, from the two cells sharing the face.
Kokkos::DefaultExecutionSpace CCExec
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::View< const double *, CCMem > CCConst
void buildCellFraction(CCField cs, CCConst sdf, C3 e, int g)
void applyClosureFaceGhost(const Closure &cl, C3 e, int g, int a, int side)
constexpr const char * kVofMomBlocksMsg
enable_vof_momentum x enable_vof_blocks*: refused in EITHER call order.
Kokkos::DefaultExecutionSpace SExec
Kokkos::View< double *, CCMem > CCField
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).
Definition policy.hpp:31
Definition prof.py:1
std::vector< double > tabYPhys
std::array< double, 4 > pPhys
This rank's own patch: the extended block the face velocity and the union colour live on.
I3 o
global index of inner cell (0,0,0)
Half-open global cell box [lo, hi).
Per-call census of the cascade over this block's inner region (LOCAL; a distributed caller sums them ...
static double value(int gx, int gy, int gz)