flow 1.4.0
Kokkos cut-cell IBM incompressible Navier-Stokes solver + pnm pore extraction
Loading...
Searching...
No Matches
flow_bindings_vof.hpp
Go to the documentation of this file.
1
9#pragma once
10
12
13namespace peclet::flow::bindings {
14
16template <class Grid, class C>
17inline void bindSolverVof(C& cls) {
18 using S = BoundSolver<Grid>;
19 // --- Geometric VoF colour field (rung V2a) -----------------------------------------------
20 cls.def(
21 "enable_vof", [](S& s) { s.enableVof(); },
22 "Enable the geometric (PLIC + Weymouth-Yue) VoF colour field 'C'. Registers 'C' as an "
23 "ordinary cell field (get_field/set_field/diagnostics.field_view/closure input) and "
24 "allocates the "
25 "colour field's OWN g=3 working block + halo; the solver's G=2 is untouched. C is "
26 "advected at the end of every step() with the just-projected face velocities.\n\n"
27 "RUNG V2a SCOPE — read before using: there is NO surface tension (rung V4) and NO "
28 "momentum-consistent transport (rung V2b). Mass and momentum are advected by different "
29 "fluxes, so a mixed cell carries a spurious interfacial momentum source of order "
30 "delta-rho; the literature (Rudman 1998, Arrufat 2021) is unambiguous that this breaks "
31 "down around density ratio 1000 unless the resolution is absurd. **V2a is valid only at "
32 "MODEST density ratios** for cases with motion. A high-ratio case AT REST (the "
33 "hydrostatic acid test) is exact, because there is no momentum to mis-advect. "
34 "COLLOCATED (SolverColocated) is supported since rung V8 (2026-09-02), ALL-FLUID only: "
35 "the colour is advected by the PROJECTED face field uf_/vf_/wf_ (the field the ABC "
36 "approximate projection makes exactly divergence-free, which is what Weymouth-Yue's "
37 "conservation proof needs), and the CSF enters the implicit momentum predictor as the "
38 "mass-adjoint face integral (doc/collocated_varrho_forces.md). An immersed solid on that "
39 "grid THROWS "
40 "(the cut-cell colour transport of rung V5a is staggered-only), and so does "
41 "enable_vof_momentum. On the collocated grid the SPURIOUS-CURRENT number to read is the "
42 "FACE field (get_uf/get_vf/get_wf): the CELL field additionally carries the approximate "
43 "projection's invisible odd-even mode, which centerToFace annihilates and the projection "
44 "therefore cannot remove. An IMMERSED SOLID is supported since "
45 "rung V5a: the geometric fluxes are openness-weighted and the update is done in "
46 "fluid-volume units, so sum eps_eff*C is conserved exactly against the projection's own "
47 "openness-weighted divergence; it needs set_solid(..., cutcell_pressure=True) (the "
48 "staircase operator has no face openness to weight with) and it approximates the "
49 "solid-clipped flux polygon by (whole-cell PLIC slab) x (open area) — see "
50 "diagnostics.vof_diagnostics()['clipped_volume'].");
51 cls.def(
52 "set_vof", [](S& s, nb::ndarray<double, nb::f_contig> a) { s.setVof(grid_in(a)); },
53 nb::arg("array"),
54 "Set the colour field from a Fortran-order (nx,ny,nz) float64 array: C = the LIQUID "
55 "volume fraction of the cell, in [0,1]. Enables VoF if it is not on yet. Initialise it "
56 "SHARP (0/1 with the exact fraction in the interface cells) — geometric VoF keeps a "
57 "sharp interface and a diffuse initial profile is simply a different problem.");
58 cls.def(
59 "get_vof", [](S& s) { return field_out(s, s.getVof()); },
60 "The colour field's inner region as a Fortran-order (nx,ny,nz) float64 array "
61 "(== get_field('C')).");
62 cls.def(
63 "vof_max_courant", [](S& s) { return s.vofMaxCourant(); },
64 "INTERFACE-LOCAL Courant number max|uf|*dt/h over the faces of mixed cells and their "
65 "face neighbours, with the current velocity and dt (all-reduce max under MPI). This — "
66 "not the global max — is the number Weymouth's boundedness bound applies to: a global "
67 "max over-throttles badly (measured on Zalesak: 0.314 at a quiescent domain corner while "
68 "the interface never exceeded 0.157). Pick dt as dt*cfl_target/vof_max_courant().");
69 cls.def("set_vof_cfl_limit", &chk::setVofCflLimit<S>, nb::arg("value"),
70 "Weymouth-Yue boundedness cap on the interface-local Courant number. Default 0.25 — the "
71 "PROVEN 3D bound 1/(2(N-1)) from Weymouth's thesis eq. A.33; the widely-quoted 0.5 is "
72 "the 2D value. step() throws when it is exceeded. Conservation is INDEPENDENT of "
73 "boundedness (the telescoping is algebraic), so an over-CFL run loses 0<=C<=1, not "
74 "volume.");
75 cls.def(
76 "vof_cfl_limit", [](S& s) { return s.vofCflLimit(); },
77 "The Weymouth-Yue boundedness cap currently in force.");
78 // --- rung V5a (WO-Q): transport through an immersed solid --------------------------------
79 cls.def(
80 "advect_vof", [](S& s, double dt) { s.advectVofKinematic(dt); }, nb::arg("dt"),
81 "KINEMATIC colour advection: advance C ONCE with the solver's CURRENT face velocity over "
82 "`dt` (seconds), with NO Navier-Stokes step. This is the advection-benchmark entry point "
83 "(Zalesak, LeVeque, and the cut-cell conservation gates): a frozen projected velocity "
84 "advecting a colour field is a pure statement about the transport scheme, with the "
85 "momentum and pressure solves out of the picture.\\n\\n"
86 "It THROWS if the current velocity is not discretely divergence-free to 1e-10, measured "
87 "with max_open_divergence_projected() (the NON-mutating diagnostic). That is not a "
88 "nicety: Weymouth-Yue's exact conservation is CONDITIONAL on sum_f o_f u_f = 0 per cell, "
89 "because the dilation term adds H(C-1/2) times that residual to every full cell's volume "
90 "budget. Run step() to a steady state (or project()) and advect with the solver's own "
91 "output; never with an analytic sample, which is solenoidal only to O(h^2).\n\n"
92 "It ALSO throws when no cut-cell pressure operator exists (WO-R2): without one the "
93 "divergence guard measures nothing at all — max_open_divergence() returns 0.0 — and a "
94 "cell-centre-sampled LeVeque field (true max|div| 0.612) was silently accepted and lost "
95 "4.93 % of the liquid in 50 steps. Call set_pressure_geometry(sdf) on an all-fluid box, "
96 "or set_solid(sdf, cutcell_pressure=True).");
97 cls.def(
98 "set_contact_angle", [](S& s, double deg) { s.setContactAngle(deg); }, nb::arg("theta"),
99 "Rung V5b (WO-S). Prescribe a STATIC contact angle, in DEGREES, measured THROUGH THE "
100 "LIQUID, on every immersed SDF wall. Needs set_solid(..., cutcell_pressure=True) + "
101 "enable_vof; with no call the wall stays at the neutral 90-degree fill of rung V5a and "
102 "every V5a number is byte-identical.\n\n"
103 "What it changes is PASS 1 of the solid-band fill and nothing else: the band cells "
104 "receive the volume fractions of the plane that continues the fluid-side interface into "
105 "the solid at angle theta (m . n_w = cos theta, with n_w = grad(sdf)/|grad(sdf)| the "
106 "solid->fluid wall normal and m the PLIC normal pointing into the gas). The unmodified V3 "
107 "height-function/MYC cascade then returns the curvature of an interface meeting the wall "
108 "at theta and the V4 balanced force does the rest — NO force is added at the wall. "
109 "theta = 0 fills the band with liquid (complete wetting), theta = 180 empties it.\n\n"
110 "Construction (src/vof/wetting.hpp): the anchor fluid cell is found by walking along n_w; "
111 "its fluid-only Youngs normal supplies the AZIMUTH of the contact line (its in-wall "
112 "component, which a fluid-restricted stencil measures to ~1e-14 on a plane) while the "
113 "angle to the wall is replaced by the prescribed one — the wall-normal component of a "
114 "fluid-only estimator is unusable (measured 23 deg of error at theta = 30 against 2.3 "
115 "for the full stencil, gate G0e). The plane is then anchored by matching the anchor "
116 "cell's own liquid volume, which makes the fill EXACTLY idempotent: an interface that "
117 "already meets the wall at theta is reproduced to 1e-15 (gate G0a), so theta is a fixed "
118 "point of the scheme.");
119 cls.def(
120 "set_contact_angle_field",
121 [](S& s, nb::ndarray<double, nb::f_contig> a) { s.setContactAngleField(grid_in(a)); },
122 nb::arg("theta"),
123 "Per-cell static contact angle in DEGREES, as a Fortran-order (nx,ny,nz) array. Only the "
124 "value AT the solid band cell being filled is read, so cells away from a wall are "
125 "irrelevant. theta is a field so the dynamic-angle rung (V6) changes only what fills it.");
126 cls.def(
127 "contact_angle", [](S& s) { return s.contactAngle(); },
128 "The prescribed static contact angle in degrees (90 if none was set).");
129 cls.def(
130 "set_contact_angle_dynamic",
131 [](S& s, bool enabled, double th, double slip, double mu, double sigma) {
132 if (!enabled) {
133 s.setContactAngleDynamicOff();
134 return;
135 }
136 chk::finite("set_contact_angle_dynamic", "sigma", sigma, "force/length");
137 if (!(slip > 0.0 && slip < 1.0) || !(mu > 0.0))
138 throw std::invalid_argument(
139 "set_contact_angle_dynamic(True, ...): slip_length_cells must lie in (0, 1) and "
140 "mu_liquid must be positive");
141 s.setContactAngleDynamic(th, slip, mu, sigma);
142 },
143 nb::arg("enabled"), nb::arg("theta_e") = 90.0, nb::arg("slip_length_cells") = 0.0,
144 nb::arg("mu_liquid") = 0.0, nb::arg("sigma") = 0.0,
145 "Rung V6 (WO-V6). The DYNAMIC contact angle -- `enabled=False` turns it (and the "
146 "hysteresis) off so the static angle stands again; `enabled=True` imposes at the grid "
147 "scale the Cox-Voinov apparent angle of a contact line moving at speed U_cl, with the "
148 "outer cut-off at the CELL SIZE and an EXPLICIT slip length lambda (Afkhami, Zaleski & "
149 "Bussmann, JCP 228:5370, 2009):\n\n"
150 " theta_Delta^3 = theta_e^3 + 9 Ca_cl ln(Delta/lambda), Ca_cl = mu_l U_cl / sigma\n\n"
151 "angles in radians internally, arguments in DEGREES; Ca_cl > 0 advancing, < 0 receding; "
152 "theta_Delta is clamped into [1, 179] degrees (diagnostics.set_contact_angle_clamp).\n\n"
153 "`slip_length_cells` is lambda/Delta and must lie in (0, 1). It is not a tuning knob "
154 "you may omit from a report: a VoF contact line's NUMERICAL slip is proportional to the "
155 "cell size, so without an explicit lambda the imposed angle is silently grid-dependent "
156 "(VOF_PLAN section 6). ALWAYS state lambda alongside a dynamic-wetting result.\n\n"
157 "`mu_liquid` is the liquid dynamic viscosity entering Ca_cl (solver units); `sigma` "
158 "defaults to whatever set_surface_tension holds. theta_e also becomes the static base "
159 "angle, so this call replaces set_contact_angle. U_cl is measured as -u.t_hat at the "
160 "anchor fluid cell of each band cell, with t_hat the IN-WALL direction of the fluid-side "
161 "PLIC normal (m points into the gas, so the liquid advances along -t_hat), then smoothed "
162 "with a 3-point mean along t_hat. Needs set_solid(..., cutcell_pressure=True) + "
163 "enable_vof; with no call every V5b number is byte-identical.");
164 cls.def(
165 "set_contact_angle_hysteresis",
166 [](S& s, double a, double r) { s.setContactAngleHysteresis(a, r); }, nb::arg("theta_a"),
167 nb::arg("theta_r"),
168 "Rung V6 (WO-V6). Advancing / receding contact-angle hysteresis, in DEGREES. While the "
169 "measured apparent angle lies in [theta_r, theta_a] the contact line is PINNED and the "
170 "fill imposes the APPARENT angle itself — which reproduces the current interface exactly, "
171 "because the V5b fill is idempotent (WO-S finding 1), so no Young force appears and the "
172 "line does not move. Above theta_a the advancing angle is imposed and below theta_r the "
173 "receding one, each with the Cox-Voinov correction of set_contact_angle_dynamic when "
174 "that is also configured. Sets the static base to (theta_a+theta_r)/2 if no angle was "
175 "set yet.");
176 cls.def(
177 "set_wall_slip_length", [](S& s, double lam) { s.setWallSlipLength(lam); },
178 nb::arg("lambda_cells"),
179 "Rung V6b (WO-V6b) - the VELOCITY half of the dynamic contact line. In the Robust-Scaled "
180 "cut-cell IBM closure the TANGENTIAL wall datum stops being no-slip and becomes the "
181 "NAVIER condition\n\n"
182 " u_t(wall) - u_body = lambda * d(u_t)/dn\n\n"
183 "with `lambda_cells` the slip length in the caller's own units (CELLS without a physical "
184 "domain, where the cell size is 1); the model needs lambda < one cell. "
185 "The wall-NORMAL component is untouched: the wall stays impermeable, with the moving-body "
186 "velocity as its datum. 0 (the default) restores the validated no-slip closure "
187 "BIT-IDENTICALLY - the closure polynomials are the lambda = 0 members of the same "
188 "family, and the lambda > 0 branch is never entered.\n\n"
189 "It is ONE lambda with set_contact_angle_dynamic: either call overwrites the shared "
190 "value (last call wins), so the Cox-Voinov inner cut-off and the momentum wall closure "
191 "cannot disagree. Only this call switches the MOMENTUM half on, so every WO-V6 result "
192 "taken with the angle half alone is unchanged.\n\n"
193 "Why it exists, measured: with no-slip the contact line advances only at the scheme's "
194 "own numerical slip, ~1/180 of Lucas-Washburn (WO-V6 finding 6), and WO-V7's pore-scale "
195 "campaign found every IMBIBITION verdict inverted below the capillary number at which "
196 "the imposed velocity crosses that numerical slip velocity. Typical values are 0.01-0.5 "
197 "cells; state lambda with every dynamic-wetting result. Staggered grids only; needs "
198 "set_solid(..., cutcell_pressure=True). Changing it rebuilds the three cut-cell overlays "
199 "and the momentum operator in place (the velocity field is NOT reset).\n\n"
200 "APPROXIMATIONS, both stated because they are invisible from the call: the tangential "
201 "projector is taken DIAGONAL (the cross terms -n_c n_j u_j are dropped; they vanish "
202 "exactly for an axis-aligned wall and are O(n_c n_j) otherwise), and an axis whose BOTH "
203 "neighbours are solid (a one-cell fluid gap) keeps the no-slip closure - counted by "
204 "diagnostics.wall_slip_sandwich_cells().");
205 cls.def(
206 "wall_slip_length", [](S& s) { return s.wallSlipLength(); },
207 "The Navier slip length in force, in the caller's units (0 = no-slip).");
208 cls.def(
209 "vof_has_geometry", [](S& s) { return s.vofHasGeometry(); },
210 "True when the colour advection is running the CUT-CELL (openness-weighted) kernels, "
211 "i.e. an immersed solid is present and set_solid ran with cutcell_pressure=True. False "
212 "means "
213 "the uncut rung-V1 kernels are running, byte-identically to a solid-free build.");
214}
215
218template <class Grid, class C>
219inline void bindDiagnosticsVof(C& cls) {
220 using D = Diagnostics<Grid>;
221 cls.def(
222 "vof_last_courant", [](D& diag) { return diag.s->vofLastCourant(); },
223 "The interface-local Courant number of the step just taken (0 before the first step).");
224 cls.def(
225 "set_vof_step_parity", [](D& diag, long n) { diag.s->setVofStepParity(n); }, nb::arg("n"),
226 "Set the sweep-permutation counter of the NEXT colour advection: the Weymouth-Yue sweep "
227 "order is kWySweepPerm[n % 6], cycled so no axis is systematically favoured. Exposed so "
228 "a benchmark can hold the permutation fixed (n constant) or resume a run across a "
229 "restart. Default: it increments once per advection from 0.");
230 cls.def(
231 "vof_step_parity", [](D& diag) { return diag.s->vofStepParity(); },
232 "The sweep-permutation counter of the next colour advection.");
233 cls.def(
234 "set_vof_wisp_eps", [](D& diag, double eps) { diag.s->setVofWispEps(eps); }, nb::arg("eps"),
235 "Wisp tolerance on the Weymouth-Yue mixed-cell predicate: a cell counts as carrying an "
236 "interface only while eps < C < 1 - eps, and one outside that band is fluxed "
237 "ALGEBRAICALLY as C_donor * a — its ACTUAL colour, so the exact telescoping conservation "
238 "is untouched. The same threshold gates the interface-local Courant band "
239 "(|C_i - C_j| > eps instead of an exact !=).\n\n"
240 "DEFAULT 1e-8 (the same value the V3 curvature predicate uses under surface tension); "
241 "0 restores the V1 predicate bit for bit. Two measured reasons it is not 0 (WO-R2 item "
242 "4): (i) a domain that DRAINS through an open boundary leaves nothing but round-off "
243 "residue, ~1e-18, which `0 < C < 1` still calls mixed — the MYC normal of that stencil "
244 "is degenerate and plicAlpha divides by it (sum C -> -inf -> NaN within three steps on "
245 "one backend); (ii) the round-off wake behind a passing interface (min C ~ -3.8e-17) "
246 "kept the whole wake inside the Courant band, so vof_last_courant() on Zalesak read "
247 "0.3110 by step 1000 on a case whose interface never exceeds 0.255.");
248 cls.def(
249 "vof_wisp_eps", [](D& diag) { return diag.s->vofWispEps(); },
250 "The wisp tolerance currently in force (see set_vof_wisp_eps).");
251 cls.def(
252 "set_pressure_exact_residual", [](D& diag, bool on) { diag.s->setPressureExactResidual(on); },
253 nb::arg("on") = true,
254 "Apply the level-0 pressure operator EXACTLY (matrix-free, double, flux form) in the "
255 "residual and the Krylov matvec instead of reading the float band storage. P1 of the "
256 "suite defect-correction campaign (suite/docs/archive/DEFECT_CORRECTION_PLAN.md). Per "
257 "solver, OFF at construction.\n\n"
258 "enable_vof() turns it ON, because a two-phase coefficient contrast is exactly what "
259 "amplifies the float operator's broken row-sum identity A*1 = 0. Measured on Hysing "
260 "case 2 (64x128x4, adaptive dt, nvidia-cuda): max|div(open u)| 1.85e-03 -> 5.15e-11, "
261 "with 116/600 pressure iterations, 1123 steps, the dt-limit census and both published "
262 "functionals (v_rise max 0.2574 at t = 0.671, y_c(3) 1.1082) identical to every printed "
263 "digit. Everything below level 0 stays float on purpose: it is a preconditioner and its "
264 "errors change the convergence RATE, never the fixed point. A flag read at every solve, "
265 "so it may be changed at any time; the ablation is False AFTER enable_vof.");
266 cls.def(
267 "pressure_exact_residual", [](D& diag) { return diag.s->pressureExactResidual(); },
268 "Whether the exact level-0 operator apply is in force (see set_pressure_exact_residual).");
269 cls.def(
270 "set_vof_cutcell_flux_clamp", [](D& diag, bool on) { diag.s->setVofCutFluxClamp(on); },
271 nb::arg("on"),
272 "Ablation: Weymouth's admissible-interval clamp on the openness-weighted cut-cell flux "
273 "(ON by default). The clamp bounds |F| by what the DONOR actually holds — at most "
274 "eps*C liquid and at most eps*(1-C) gas of the fluid volume o*|a| swept through the face "
275 "— applied to the one value both neighbours share, so conservation still telescopes "
276 "bit-exactly. It is what makes the whole-cell-PLIC-times-open-area flux approximation "
277 "BOUNDED. Measured with it off on a 24^3 packing at CFL 0.2: the [0,1] clip fires at "
278 "3.2e-5 liquid volume per step and the conserved functional drifts 1.3e-8 in 30 steps; "
279 "with it on the clip stops firing.");
280 cls.def(
281 "vof_filled_color", [](D& diag) { return field_out(*diag.s, diag.s->getVofFilledColour()); },
282 "The colour field INCLUDING the neutral solid-band fill — what the MYC and "
283 "height-function stencils actually read — as a Fortran-order (nx,ny,nz) array. "
284 "get_vof()/'C' is the canonical field and carries EXACTLY 0 in solid cells; the fill is "
285 "a stencil device regenerated at every ghost exchange (three passes with a shrinking "
286 "depth "
287 "budget, src/vof/cutcell.hpp), and it is what makes the wall look 90-degree neutral "
288 "instead of perfectly non-wetting.");
289 cls.def(
290 "vof_geometry",
291 [](D& diag, int which) { return field_out(*diag.s, diag.s->getVofGeometry(which)); },
292 nb::arg("which"),
293 "The cut-cell geometry the colour block runs on, as a Fortran-order (nx,ny,nz) array: "
294 "0 = the cell fluid fraction eps (4^3-subsampled, a multiple of 1/64), 1/2/3 = the "
295 "openness of the +x/+y/+z face of each cell (the ADVECTOR's high-face convention, one "
296 "cell shifted from the solver's ox/oy/oz), 4 = the classification (1 = SOLID, i.e. "
297 "eps == 0 AND all six faces closed).\n\n"
298 "On an ALL-FLUID solver (set_pressure_geometry, or no cut-cell pressure operator) there "
299 "is no geometry block and this returns the TRIVIAL geometry the V1 transport kernels "
300 "actually execute: eps = 1, openness = 1, classification = 0. It used to raise, which "
301 "meant one diagnostic could not serve a packed scene and its all-fluid control.");
302 cls.def(
303 "set_contact_angle_pivot",
304 [](D& diag, const std::string& mode) {
305 diag.s->setContactAnglePivot(enum_index(mode, kPivots, "set_contact_angle_pivot", "mode"));
306 },
307 nb::arg("mode"),
308 "ABLATION -- how the theta-plane is anchored in the fluid cell. 'volume' (DEFAULT) match "
309 "the anchor cell's liquid volume with plicAlpha; 'centroid' pass through the PLIC "
310 "centroid p_f (the Afkhami-Bussmann / Basilisk contact.h rule); 'projected-centroid' the "
311 "work order's c = p_f - sdf(p_f) n_w; 'contact-line' the contact line on the wall. "
312 "'volume', 'centroid' and 'contact-line' are exactly idempotent (1e-15 on gate G0a); "
313 "'projected-centroid' is NOT -- projecting the centroid along n_w shifts the plane by "
314 "-sdf(p_f) cos(theta), measured 0.26 in cell fraction at theta = 60, with the wrong sign "
315 "(it removes liquid from the band for a wetting angle).");
316 cls.def(
317 "contact_angle_diagnostics",
318 [](D& diag) {
319 const auto d = diag.s->contactAngleDiagnostics();
320 nb::dict r;
321 r["contact_cells"] = d.contactCells;
322 r["neighbour_cells"] = d.neighbourCells;
323 r["pure_cells"] = d.pureCells;
324 r["parallel_cells"] = d.parallelCells;
325 r["neutral_cells"] = d.neutralCells;
326 r["unfilled_cells"] = d.unfilledCells;
327 r["mean_apparent_angle"] = d.meanApparentAngle;
328 r["set_angle"] = d.setAngle;
329 r["dynamic_cells"] = d.dynamicCells;
330 r["pinned_cells"] = d.pinnedCells;
331 r["advancing_cells"] = d.advancingCells;
332 r["receding_cells"] = d.recedingCells;
333 r["mean_imposed_theta"] = d.meanImposedTheta;
334 r["mean_apparent_theta"] = d.meanApparentTheta;
335 r["max_Ca_cl"] = d.maxCaCl;
336 r["max_contact_speed"] = d.maxContactSpeed;
337 return r;
338 },
339 "The solid-band census of the CURRENT colour field on this rank: how many band cells "
340 "each "
341 "branch of pass 1 wrote ('contact_cells' the theta plane of the cell's own anchor, "
342 "'neighbour_cells' the mean of the anchor's MIXED neighbours' planes where the anchor "
343 "itself is pure phase, 'pure_cells' the pure-phase "
344 "continuation C_s = C_f, 'parallel_cells' an interface parallel to the wall where no "
345 "rotation is defined, 'neutral_cells' the WO-Q neutral-mean fallback, 'unfilled_cells' "
346 "left untouched), plus 'mean_apparent_angle' — the mean angle the fluid-only normal "
347 "reported at the contact cells BEFORE the rotation, in degrees. That last number is the "
348 "direct read-out of how far the fluid-side interface still is from the prescribed angle, "
349 "measured on the fill's own data rather than on a post-processed shape.\n\n"
350 "Rung V6 (WO-V6) adds, all zero unless set_contact_angle_dynamic / "
351 "set_contact_angle_hysteresis is configured: 'dynamic_cells' (band cells the V6 pass "
352 "produced an angle for), 'pinned_cells' / 'advancing_cells' / 'receding_cells' (the "
353 "hysteresis branch census), 'mean_imposed_theta' and 'mean_apparent_theta' in degrees, "
354 "'max_Ca_cl' = max |mu_l U_cl / sigma| and 'max_contact_speed' = max |U_cl| in solver "
355 "velocity units.");
356 cls.def(
357 "wall_slip_sandwich_cells",
358 [](D& diag) {
359 auto a = diag.s->wallSlipSandwichCells();
360 return nb::make_tuple(a[0], a[1], a[2]);
361 },
362 "Per velocity component, the number of cut-cell AXES at which a one-cell fluid gap made "
363 "the Navier closure inapplicable and the no-slip one was kept. Nonzero means part of the "
364 "wall is silently no-slip; report it.");
365 cls.def(
366 "set_contact_angle_smoothing", [](D& diag, bool on) { diag.s->setContactAngleSmoothing(on); },
367 nb::arg("on"),
368 "ABLATION - the 3-point in-wall mean of U_cl (default ON). A MAC velocity next to a wall "
369 "is noisy cell to cell and the cube root of the Cox-Voinov relation puts that noise "
370 "straight into the imposed angle; off measures what the smoothing is worth.");
371 cls.def(
372 "set_contact_angle_clamp",
373 [](D& diag, double lo, double hi) { diag.s->setContactAngleClamp(lo, hi); }, nb::arg("lo"),
374 nb::arg("hi"),
375 "The clamp on the Cox-Voinov cube, in degrees (default 1 / 179). The cubic has no "
376 "solution beyond the maximum receding capillary number (film entrainment) and the fill's "
377 "plane construction degenerates at 0/180.");
378 cls.def(
379 "vof_dynamic_field",
380 [](D& diag, int w) { return field_out(*diag.s, diag.s->getVofDynamicField(w)); },
381 nb::arg("which"),
382 "The V6 per-cell dynamic-wetting state on the inner region, as (nx,ny,nz): 0 the IMPOSED "
383 "angle in degrees, 1 the measured APPARENT angle in degrees, 2 the smoothed U_cl "
384 "(positive = the liquid ADVANCES), 3 Ca_cl, 4 the state (0 not a contact cell, 1 "
385 "Cox-Voinov on the static base, 2 PINNED, 3 advancing, 4 receding). Regenerates the "
386 "fill, "
387 "so it is also the direct gate on the pass's decomposition independence.");
388 cls.def(
389 "set_vof_timing", [](D& diag, bool on) { diag.s->setVofTiming(on); }, nb::arg("on"),
390 "WO-V9: arm (or disarm) the VoF pipeline's per-stage timers, and reset them. OFF by "
391 "default. When armed, every stage boundary calls Kokkos::fence() before reading the "
392 "clock -- the same rule the step's three coarse phase timers already follow, because on "
393 "a device backend queued work would otherwise be billed to whichever stage next reads "
394 "the clock. A fence changes WHEN work happens, never WHAT it computes: a run with the "
395 "timers armed is bit-identical to the same run without them (gated in "
396 "tests/kokkos/test_vof_timing.cpp). When disarmed the cost is one branch per stage and "
397 "no fence at all.");
398 cls.def(
399 "reset_vof_timing", [](D& diag) { diag.s->resetVofTiming(); },
400 "Zero the VoF stage timers and the step counter without disarming them.");
401 cls.def(
402 "vof_timing",
403 [](D& diag) {
404 const auto& v = diag.s->vofTimingReport();
405 const auto& k = diag.s->vofKernelTiming();
406 nb::dict r;
407 r["steps"] = v.steps;
408 // the step's three coarse phases, summed over the same window (seconds)
409 r["step"] = diag.s->vofTimingStepSeconds();
410 r["predictor"] = diag.s->vofTimingPredictorSeconds();
411 r["momentum_solve"] = diag.s->vofTimingMomentumSeconds();
412 r["projection"] = diag.s->vofTimingProjectionSeconds();
413 // the VoF stages
414 r["vof_advect"] = v.advect;
415 r["vof_bridge"] = v.bridge;
416 r["vof_momentum_advect"] = v.momAdvect;
417 r["vof_momentum_bridge"] = v.momBridge;
418 r["curvature"] = v.curvature;
419 r["csf"] = v.csf;
420 r["phase_change"] = v.phaseChange;
421 // the advector's own kernels (shared by the colour, momentum and energy drivers)
422 r["k_freeze"] = k.freeze;
423 r["k_reconstruct"] = k.reconstruct;
424 r["k_fluxes"] = k.fluxes;
425 r["k_sweep"] = k.sweep;
426 r["k_clip"] = k.clip;
427 r["k_exchange"] = k.exchange;
428 r["k_sweeps"] = k.sweeps;
429 // the V3 curvature cascade's own passes
430 const auto& q = diag.s->vofCurvatureTiming();
431 r["kc_calls"] = q.calls;
432 r["kc_compact"] = q.compact;
433 r["kc_planes"] = q.planes;
434 r["kc_height"] = q.height;
435 r["kc_fallback"] = q.fallback;
436 r["kc_clip"] = q.clip;
437 r["block_advect"] = v.blockAdvect;
438 r["block_debris"] = v.blockDebris;
439 r["kc_census"] = q.census;
440 return r;
441 },
442 "WO-V9: cumulative VoF stage times in SECONDS since the last set_vof_timing/"
443 "reset_vof_timing, on this rank. `steps` is the number of step() calls in the window, so "
444 "every entry divides down to a per-step cost. `step`/`predictor`/`momentum_solve`/"
445 "`projection` are the step's three coarse phases summed over the SAME window (the "
446 "remainder of `step` is BC re-imposition, Picard bookkeeping and the scalars). "
447 "`vof_advect` is the whole colour stage and `vof_bridge` the part of it spent in the "
448 "G=2 <-> g=3 bridges and the C ghost policy; `vof_momentum_advect` is its V2b twin. "
449 "`k_*` are the advector's own kernels, shared by the colour, momentum-consistent and "
450 "consistent-energy drivers, so they are the per-KERNEL breakdown of whichever of the two "
451 "stages is running: `k_reconstruct` the MYC + plicAlpha pass, `k_fluxes` the geometric "
452 "face fluxes, `k_sweep` the update, `k_clip` the V5a cut-cell clip, `k_exchange` the "
453 "g = 3 ghost exchange, `k_sweeps` the number of sweeps (3 per advect call). Returns "
454 "zeros unless the timers are armed.");
455 cls.def(
456 "set_vof_worklist", [](D& diag, bool on) { diag.s->setVofWorklist(on); }, nb::arg("on"),
457 "WyAdvector::useWorklist -- compact the PLIC reconstruction pass onto the mixed cells "
458 "(a parallel_scan over the reconstruction region, then a dense parallel_for over the "
459 "compacted list) instead of a guarded parallel_for over the whole region. Default ON. "
460 "Pure optimization: the flux never reads a non-mixed cell's plane, so the two paths "
461 "produce the same field BIT FOR BIT (gated in tests/kokkos/test_vof_advect.cpp and "
462 "measured in WO-V9).");
463 cls.def(
464 "vof_worklist", [](D& diag) { return diag.s->vofWorklist(); },
465 "Whether the reconstruction-pass compaction is on.");
466 cls.def(
467 "set_vof_curvature_worklist", [](D& diag, bool on) { diag.s->setVofCurvatureWorklist(on); },
468 nb::arg("on"),
469 "WO-V9: run the V3 curvature cascade (the PLIC plane pass, the height functions and the "
470 "PV fallback) over a COMPACTED list of the interfacial cells instead of over the whole "
471 "inner region. Default ON. The cascade is the most divergent kernel in the pipeline -- "
472 "on a resolved droplet the interfacial cells are well under 1 % of the block, so a dense "
473 "parallel_for puts one or two active lanes in a warp and the other thirty run the guard "
474 "and then idle for the whole height function. Compaction is a pure re-ordering (each "
475 "cell reads the same neighbours and writes the same value), so the two paths are "
476 "BIT-IDENTICAL; tests/kokkos/test_vof_timing.cpp gates that and WO-V9 records the gain.");
477 cls.def(
478 "vof_curvature_worklist", [](D& diag) { return diag.s->vofCurvatureWorklist(); },
479 "Whether the curvature-cascade compaction is on.");
480}
481
482} // namespace peclet::flow::bindings
Shared helpers of the peclet.flow Python binding: array conversion, the string-enum tables,...
int enum_index(const std::string &v, const std::vector< std::string > &names, const char *who, const char *what)
std::vector< double > grid_in(nb::ndarray< double, nb::f_contig > a)
void bindSolverVof(C &cls)
Solver (and its collocated twin): VoF colour field, advection, contact angle and wall slip.
nb::ndarray< nb::numpy, double > field_out(S &s, std::vector< double > &&v)
void bindDiagnosticsVof(C &cls)
SolverDiagnostics (and its collocated twin): VoF step controls, geometry, contact angle,...
const std::vector< std::string > kPivots
The developer tier: a view onto one Solver<Grid> (no state of its own).