flow 1.4.0
Kokkos cut-cell IBM incompressible Navier-Stokes solver + pnm pore extraction
Loading...
Searching...
No Matches
flow_bindings_phase_change.hpp
Go to the documentation of this file.
1
8#pragma once
9
11
12namespace peclet::flow::bindings {
13
15template <class Grid, class C>
16inline void bindSolverPhaseChange(C& cls) {
17 using S = BoundSolver<Grid>;
18 // --- Phase change, Part II rungs P0/P1 (WO-P01) ------------------------------------------
19 cls.def(
20 "enable_phase_change",
21 [](S& s, double rho_g, double rho_l, double h_lv) {
22 s.enablePhaseChange(rho_g, rho_l, h_lv);
23 },
24 nb::arg("rho_gas"), nb::arg("rho_liquid"), nb::arg("h_lv") = 1.0,
25 "Enable VoF phase change (VOF_PLAN section 9, rungs P0/P1; the Boyd & Ling 2023 / Malan "
26 "2021 pattern). rho_gas/rho_liquid are densities and h_lv the latent heat (energy per "
27 "mass), all in the solver's physical units. Registers 'mdot' (the interfacial mass flux, "
28 "POSITIVE = evaporation) and 'pc_source' (the deposited divergence source); both are "
29 "raw-registry fields and hold INTERNAL values -- multiply by 1/unit_scales"
30 "['mass_flux_to_internal'] and 1/unit_scales['divergence_to_internal'] (both 1 "
31 "without an extent).\n"
32 "\nWhat it does per step, at the HEAD of step(): (1) reconstruct the PLIC plane of every "
33 "interfacial cell and take its POLYGON AREA A analytically (A = |m|_2 dV/dalpha, not a "
34 "finite difference); (2) evaluate mdot (prescribed by set_mass_flux*, or computed by "
35 "set_phase_change_thermal); (3) deposit S = mdot A (1/rho_g - 1/rho_l) into the nearest "
36 "PURE GAS cell along +n, so the interfacial cell's own face velocity stays the LIQUID "
37 "velocity and Weymouth-Yue keeps a field its conservation proof is entitled to; (4) "
38 "regress the interface by a PLIC PLANE SHIFT, C -> C - mdot A dt/rho_l, with "
39 "clip-and-redistribute along -n when a cell empties. There is NEVER a volume source in "
40 "the C equation (the Hardt-Wondra smeared source leaves unresolvable residue and breaks "
41 "the WY bounds).\n"
42 "\nThe densities are given explicitly rather than read off a closure (the same contract "
43 "as enable_vof_momentum). SCOPE at this rung: staggered grid, NO immersed solid, not "
44 "composable with enable_vof_momentum; all three throw with a message. A CLOSED domain "
45 "needs the net vapour production to leave somewhere: use an outflow face, or "
46 "set_divergence_source() with a balancing sink, or rho_g = rho_l (then S == 0).");
47 cls.def("set_mass_flux_uniform", &chk::setMassFluxUniform<S>, nb::arg("mdot"),
48 "P0: prescribe a UNIFORM interfacial mass flux (mass per area per time; positive = "
49 "evaporation, liquid consumed). Turns the thermal mass flux OFF. Under an extent, call "
50 "set_rho and set_dt first: the value is converted into the 'mdot' field once.");
51 cls.def(
52 "set_mass_flux", [](S& s, nb::ndarray<double, nb::f_contig> a) { s.setMassFlux(grid_in(a)); },
53 nb::arg("array"),
54 "P0: prescribe a per-cell interfacial mass flux from a Fortran-order (nx,ny,nz) float64 "
55 "array, in the units of set_mass_flux_uniform (and with its call-order rule). Turns "
56 "the thermal mass flux OFF.");
57 cls.def(
58 "set_phase_change_thermal",
59 [](S& s, bool enabled, const std::string& name, double t_sat, double k_gas, double k_liquid,
60 double r_int) {
61 if (!enabled) {
62 s.setPhaseChangeThermalOff();
63 return;
64 }
65 if (name.empty())
66 throw std::invalid_argument(
67 "set_phase_change_thermal(True, ...): name the registered temperature scalar");
68 s.setPhaseChangeThermal(name, t_sat, k_gas, k_liquid, r_int);
69 },
70 nb::arg("enabled"), nb::arg("scalar") = "", nb::arg("t_sat") = 0.0, nb::arg("k_gas") = 0.0,
71 nb::arg("k_liquid") = 0.0, nb::arg("r_int") = 0.0,
72 "P1: compute mdot each step from a registered scalar (the temperature) instead of "
73 "prescribing it; `enabled=False` stops that (back to the prescribed mdot field):\n\n"
74 " mdot = ( k_g dT_g/dn - k_l dT_l/dn ) / h_lv , n = m/|m|_2 (LIQUID -> GAS)\n\n"
75 "Each one-sided derivative is a weighted least-squares fit THROUGH the interface value "
76 "over the PURE-PHASE cells of a 5^3 stencil on that side, with Malan's collinearity "
77 "weight w = (d.n)^2/|d|^3 and the exact normal distance from the PLIC plane. Interfacial "
78 "cells are pinned at T_G = t_sat + mdot*r_int in the energy solve through a per-cell "
79 "Dirichlet mask on the scalar (r_int = 0 is the hard Dirichlet; a nonzero r_int is the "
80 "Schrage/IHTR Robin condition of Bures & Sato 2021).\n\n"
81 "SIGN CONVENTION -- the interfacial energy balance is mdot*h_lv = (q_l - q_g).n with "
82 "q = -k grad T and n pointing OUT OF THE LIQUID, which is the form above. Check it on "
83 "the Stefan problem: superheated vapour behind the interface gives grad(T_g).n > 0 and "
84 "mdot > 0, i.e. evaporation. The opposite pairing (k_l grad T_l - k_g grad T_g) with the "
85 "SAME n would condense a superheated vapour.\n\n"
86 "The energy scalar's diffusivity is whatever add_scalar was given (a CONSTANT); per-cell "
87 "k(C) and the consistent rho c_p T geometric transport are set_phase_change_energy. That "
88 "is not a limitation for the Stefan gate, where the liquid is saturated and pinned at "
89 "T_sat.\n\n"
90 "Units: t_sat in the temperature scalar's own units (never rescaled); k_gas/k_liquid "
91 "are thermal conductivities (power per length per kelvin) and r_int an interfacial "
92 "resistance (kelvin per mass flux), all in the solver's physical units.");
93 cls.def(
94 "vof_interface_area", [](S& s) { return s.vofInterfaceArea(); },
95 "Total interfacial area of the colour field (an area in the solver's units; cells "
96 "squared without an extent), summed over "
97 "the inner region and globally reduced under MPI. Uses the geometry "
98 "diagnostics.set_phase_change_area selects, so the number a page quotes and the number the "
99 "phase "
100 "change integrates are the same one. Needs enable_vof; phase change need not be on. "
101 "A sphere of radius R reads 4 pi R^2 to about 0.2-0.8 % once its colour field is "
102 "resolved (WO-P3c).");
103 cls.def(
104 "set_phase_change_energy",
105 [](S& s, bool enabled, double rcp_gas, double rcp_liquid) {
106 if (!enabled) {
107 s.setPhaseChangeEnergyOff();
108 return;
109 }
110 if (!(rcp_gas > 0.0) || !(rcp_liquid > 0.0))
111 throw std::invalid_argument(
112 "set_phase_change_energy(True, ...): both heat capacities must be positive");
113 s.setPhaseChangeEnergy(rcp_gas, rcp_liquid);
114 },
115 nb::arg("enabled"), nb::arg("rho_cp_gas") = 0.0, nb::arg("rho_cp_liquid") = 0.0,
116 "CONSISTENT rho*c_p*T transport (VOF_PLAN section 9 item 6) for the scalar named by "
117 "set_phase_change_thermal; `enabled=False` returns to the constant-diffusivity scalar "
118 "operator and the Koren TVD advective term (the rung P0/P1 energy path). Two things "
119 "change together:\n"
120 " (1) TRANSPORT: H = (rho c_p) T is advected with the colour advection's OWN geometric "
121 "fluxes, sweep order and frozen dilation flag (vof/energy_advect.hpp), and T is recovered "
122 "as H / (rho c_p)(C^{n+1}) -- so a uniform temperature is preserved EXACTLY at any heat "
123 "capacity ratio. With two different fluxes the heat carried into a mixed cell is divided "
124 "by a capacity built from another flux: an error of order d(rho c_p), i.e. ~2000x at "
125 "water/steam, which is the artificial interfacial heating this removes.\n"
126 " (2) DIFFUSION: the implicit operator becomes A_C = rho c_p(C)/dt + sum_f k_f open_f "
127 "with k_f the arithmetic mean of the cells' k(C) (the k_gas/k_liquid of "
128 "set_phase_change_thermal) EXCEPT at a face touching a per-cell Dirichlet (interfacial) "
129 "cell, where the pure neighbour's own k is used -- a Dirichlet row is an identity row, so "
130 "that coefficient's only job is the conductance with which the pure cell reaches a "
131 "boundary condition that already sits at the interface.\n"
132 "Units: rho_cp_* are VOLUMETRIC heat capacities (energy per volume per kelvin) in the "
133 "solver's physical units, like the k of set_phase_change_thermal. Requires "
134 "set_phase_change_thermal.");
135 cls.def(
136 "set_divergence_source",
137 [](S& s, nb::ndarray<double, nb::f_contig> a) { s.setDivergenceSource(grid_in(a)); },
138 nb::arg("array"),
139 "A PRESCRIBED extra divergence source (1/time; under an extent call set_dt first) on "
140 "the inner cells, added to the Poisson RHS "
141 "beside the phase-change deposit, so the projection solves div(open u) = S. Registered "
142 "as the field 'div_source'. Its use is to make a CLOSED (periodic) domain compatible "
143 "with a net vapour production by carrying a balancing sink; with an outflow face the "
144 "outflow does that job and this is unnecessary.");
145 cls.def(
146 "clear_divergence_source", [](S& s) { s.clearDivergenceSource(); },
147 "Drop the prescribed divergence source (the field stays registered).");
148 cls.def(
149 "set_divergence_sink",
150 [](S& s, nb::ndarray<double, nb::f_contig> a) { s.setDivergenceSink(grid_in(a)); },
151 nb::arg("weights"),
152 "WO-P23: an AUTO-BALANCED sink region for the phase-change divergence source. Give a "
153 "non-negative weight per cell (Fortran-order (nx,ny,nz)); after each deposit the solver "
154 "subtracts (global sum of the phase-change source) * w / (global sum of w), so a CLOSED "
155 "domain's Poisson RHS is exactly compatible every step with no user bookkeeping. Put the "
156 "weights in the LIQUID far from the interface, where the exact solution simply has the "
157 "liquid leaving. This is what makes a closed-box phase-change run possible without the "
158 "variable-density outflow operator (whose density-ratio inconsistency is WO-R2's "
159 "subject). Registered as the field 'div_sink'.");
160 cls.def(
161 "clear_divergence_sink", [](S& s) { s.clearDivergenceSink(); },
162 "Drop the auto-balanced sink region.");
163 cls.def(
164 "apply_phase_change", [](S& s, double dt) { s.applyPhaseChange(dt); }, nb::arg("dt"),
165 "KINEMATIC phase-change step: build mdot / the PLIC areas / the normals, deposit the "
166 "divergence source (census only — nothing is projected) and apply the interface "
167 "regression over `dt`. No Navier-Stokes step, no advection. This is the P0a / P1 driver: "
168 "an interface regressing under a prescribed or thermally-computed flux, with the "
169 "momentum and pressure solves out of the picture. dt is in the caller's time units.");
170}
171
173template <class Grid, class C>
174inline void bindDiagnosticsPhaseChange(C& cls) {
175 using D = Diagnostics<Grid>;
176 // --- Phase change, Part II rungs P2/P3 (WO-P23) ------------------------------------------
177 cls.def(
178 "set_phase_change_plane_dirichlet",
179 [](D& diag, bool on) { diag.s->setPhaseChangePlaneDirichlet(on); }, nb::arg("on"),
180 "The PLANE-ANCHORED (ghost-fluid) interfacial Dirichlet condition. ON by default.\n\n"
181 "Rungs P0/P1 pinned the whole interfacial CELL at T_G, so the numerical thermal boundary "
182 "sat at the cell CENTRE while the mass-flux gradient is fitted from the PLIC PLANE — a "
183 "mismatch of up to half a cell that CHANGES SIGN as the interface sweeps through a cell, "
184 "and the first-order component of the P1 Stefan error (WO-P01 finding 6). With this on, "
185 "the condition becomes PER FACE: for a pure cell i whose neighbour j is interfacial, "
186 "that "
187 "face's row carries k*open*(T_i - T_G)/theta with theta the distance in cells from i's "
188 "centre to j's PLIC plane along the face's own axis, and the interfacial cell's own "
189 "value "
190 "is never read by any neighbour.\n\n"
191 "A per-CELL value (the literal reading of the work order) does NOT work and the "
192 "measurement is in the findings: giving the interfacial cell the value the one-sided "
193 "profile takes at its centre is right for the side the fit came from and wrong for the "
194 "other side — on the P1 Stefan ladder it heats the saturated liquid through the "
195 "interfacial cell's liquid-side face, which gives the liquid a spurious gradient that "
196 "feeds straight back into mdot: +6.20/+5.62/+5.42 % at N = 64/128/256, order 0.10, "
197 "against +1.31/+0.59/+0.20 % and order 1.37 for the cell-centre pinning it was meant to "
198 "improve on. The per-face form has no such asymmetry (the liquid-side face reads T_G at "
199 "its own theta, i.e. exactly zero flux for a saturated liquid).\n\n"
200 "False restores the rung P0/P1 behaviour bit-for-bit.");
201 cls.def(
202 "set_phase_change_quadratic_fit",
203 [](D& diag, bool on) { diag.s->setPhaseChangeQuadraticFit(on); }, nb::arg("on"),
204 "Fit the one-sided interfacial temperature gradients QUADRATICALLY through the interface "
205 "value (T - T_G = G phi + Q phi^2) instead of linearly. This is VOF_PLAN section 9 item "
206 "1's Aslam quadratic extrapolation in least-squares form — the same 5^3 pure-cell "
207 "samples, the same Malan collinearity weights, one more basis function, no PDE sweeps. "
208 "Once the plane-anchored Dirichlet has removed the cell-centre mismatch, the linear "
209 "fit's "
210 "O(T'' h) curvature bias is the leading error of the rung: its samples start about one "
211 "cell from the plane and reach two and a half, so a curved profile tilts the straight "
212 "line through the origin. ON by default (WO-P23): with the plane-anchored Dirichlet it "
213 "takes "
214 "the P1 Stefan interface position from +0.195 % to +0.003 % at N = 256, and the mdot "
215 "kernel itself from order 1.1 to order 2.0. set(False) is the ablation.");
216 cls.def(
217 "set_phase_change_area",
218 [](D& diag, const std::string& mode) {
219 diag.s->setPhaseChangeArea(enum_index(mode, kAreaModes, "set_phase_change_area", "mode"));
220 },
221 nb::arg("mode"),
222 "WO-P3c: WHICH GEOMETRY the interfacial area A_Gamma comes from. A_Gamma sets the plane "
223 "shift dV = mdot A dt / rho_l and the divergence source S = mdot A (1/rho_g - 1/rho_l), "
224 "so a bubble grows as int mdot dA and a biased area is a biased growth rate.\n"
225 " 'plic' (DEFAULT, rungs P0/P1): plicArea = |m|_2 dV/dalpha on the MYC normal.\n"
226 " 'cascade-metric': the V3 curvature cascade's own geometry -- the height function's "
227 "area element sqrt(1 + h_x^2 + h_y^2) from the SAME central differences the curvature "
228 "differentiates once more (tiers 1/2), the PV paraboloid's gradient (tier 3) -- applied "
229 "to the PLIC polygon's projected footprint, so the cells of a column still tile.\n"
230 " 'cascade-normal': the same normals, but the plane is rebuilt on them, "
231 "plicArea(n*, plicAlpha(n*, C)).\n"
232 " 'cascade-footprint': the height function's OWN footprint times its own metric, the "
233 "only per-cell variant whose pieces tile.\n"
234 " 'sheet-color-centroid' / 'sheet-color-split' / 'sheet-plic-centroid' / "
235 "'sheet-plic-split' = WO-P3d, the JOINED sheet: marching tetrahedra on the cell-centre "
236 "lattice, one watertight surface whose triangles are booked to cells -- the C = 1/2 "
237 "level "
238 "set with whole triangles to the cell holding the centroid, the same sheet clipped to "
239 "each cell's cube, and the same two deposits on the zero of the PLIC-reconstructed "
240 "signed distance (exact on a TILTED plane, where interpolating C is not, because C(d) is "
241 "the SZ piecewise cubic). The sheet modes are the only ones whose SUM converges on a "
242 "curved interface: WO-P3c proved with two analytic controls that every PER-CELL area is "
243 "first order in h/R because the pieces do not JOIN across cells.\n"
244 "All of the per-cell modes are EXACT on a plane, so every planar gate (P0a/P0b/P1/P2) is "
245 "unmoved. The default is 'plic' because the measurement says so: on a sphere whose "
246 "colour field is resolved (16^3 sub-sampling), summed plicArea is within 0.5 % of "
247 "4 pi R^2 and the cascade does not improve it. WO-P3b's 5.5-9.3 % 'PLIC area deficit' "
248 "was its probe's own 4^3 sub-sampling, which quantizes C to 1/64 and drops a QUARTER of "
249 "the interfacial cells (their volume is 1e-4 %, their area 6 %).");
250 cls.def(
251 "phase_change_area", [](D& diag) { return kAreaModes.at(diag.s->phaseChangeArea()); },
252 "The set_phase_change_area mode in force, as its name.");
253 cls.def(
254 "set_phase_change_energy_muscl",
255 [](D& diag, bool on) { diag.s->setPhaseChangeEnergyMuscl(on); }, nb::arg("on"),
256 "MinMod-limited donor reconstruction of the face temperature in the CONSISTENT energy "
257 "flux, instead of the default plain donor-cell (first-order upwind) value. OFF by "
258 "default. The consistency is what the geometric flux buys; its first-order upwind "
259 "numerical diffusion |u| h (1 - CFL)/2 thickens the thermal boundary layer and therefore "
260 "LOWERS the interfacial gradient, which is exactly what mdot is — measured on the P3 "
261 "Scriven bubble at Ja = 0.5: -2.24 % on R(t) with plain upwind against -1.46 % for the "
262 "scalar module's Koren TVD (which is NOT consistent). This buys the accuracy back; it is "
263 "a switch and not a default because it is the energy twin of set_vof_momentum_muscl.");
264 cls.def(
265 "phase_change_diagnostics",
266 [](D& diag) {
267 const auto d = diag.s->phaseChangeDiagnostics();
268 nb::dict r;
269 r["mdot_min"] = d.mdotMin;
270 r["mdot_max"] = d.mdotMax;
271 r["mdot_mean"] = d.mdotMean;
272 r["interface_cells"] = d.interfaceCells;
273 r["interface_area"] = d.area;
274 r["area_hf_cells"] = d.areaHf; // WO-P3c: the area cascade's branch census
275 r["area_pv_cells"] = d.areaPv;
276 r["area_no_cascade_cells"] = d.areaNone;
277 r["area_orphan"] = d.areaOrphan; // WO-P3d: area on cells the flux integral drops
278 r["mdot_fit"] = d.mdotFit; // WO-P3g: the least-squares estimator, diagnostic
279 r["q_operator"] = d.qOperator; // WO-P3g: the operator's own interfacial heat (W)
280 r["q_orphan"] = d.qOrphan; // ... on interfacial cells with no area
281 r["removed_volume"] = d.removedVolume;
282 r["redistributed"] = d.redistributed;
283 r["deficit_cells"] = d.deficitCells;
284 r["excess_cells"] = d.excessCells;
285 r["source_sum"] = d.sourceSum;
286 r["source_cells"] = d.sourceCells;
287 r["fallback_cells"] = d.fallbackCells;
288 r["unresolved"] = d.unresolved;
289 r["min_C"] = d.minC;
290 r["max_C"] = d.maxC;
291 r["band_div"] = d.bandDiv;
292 r["T_min"] = d.Tmin;
293 r["T_max"] = d.Tmax;
294 return r;
295 },
296 "Per-rank phase-change census of the LAST step: mdot extrema/mean and the interfacial "
297 "cell count, the total PLIC interface area, the liquid volume the regression removed, "
298 "the clip-and-redistribute ledger (|deficit| moved, and how many cells clipped at 0 / "
299 "1), the deposited divergence source (its sum and how many cells received it), how many "
300 "interfacial cells found NO pure gas cell within two cells along +n (the source then "
301 "stays put — a fallback that must be 0 on a resolved interface), the colour extrema, "
302 "'band_div' = max|div(open u)| over the INTERFACIAL cells (WO-P23: the direct read-out "
303 "of "
304 "whether the field Weymouth-Yue advects with is the liquid velocity there — the "
305 "band-extended velocity of VOF_PLAN section 9 item 3 is needed iff this is not at the "
306 "projection floor), and the energy-scalar extrema under the consistent transport.\n"
307 "Units are the solver's physical ones: mdot_* a mass flux, interface_area/area_orphan "
308 "an area, q_* a power, removed_volume/redistributed/unresolved a liquid VOLUME (colour "
309 "x cell volume), source_sum and band_div 1/time; colours and temperatures as given.");
310 cls.def(
311 "set_phase_change_fit_curvature",
312 [](D& diag, double k) { diag.s->setPhaseChangeFitCurvature(k); }, nb::arg("kappa"),
313 "WO-P3f INSTRUMENT (default 0, bitwise inert): prescribe the interface curvature "
314 "`kappa = div(n)` that the one-sided temperature fits use to measure a sample's distance "
315 "to the CURVED interface instead of to the interfacial cell's tangent plane "
316 "(`vof::pcCurvedDistance`). For a spherical GAS bubble of radius R, whose PLIC normal "
317 "points inward, kappa = -2/R.\n\n"
318 "Why it exists: the tangent-plane distance makes the fit FIRST ORDER in h/R on a curved "
319 "interface, and every off-axis sample is hotter than the plane model expects, so the "
320 "fitted dT/dn and with it mdot come out HIGH. Measured a priori on an exact sphere with "
321 "an exactly linear profile: +19.2 / +12.1 / +8.8 / +6.2 % at R = 6 / 10 / 14 / 20, "
322 "observed order 0.91-0.98 in h/R. This entry point takes a PRESCRIBED kappa so that bias "
323 "can be measured against a known geometry; it is not a curvature estimator.");
324 cls.def(
325 "set_phase_change_energy_order",
326 [](D& diag, int order) { diag.s->setPhaseChangeEnergyOrder(order); }, nb::arg("order"),
327 "WO-P3g: the ORDER of the interfacial energy operator. 1 (the shipped WO-P23...P3f "
328 "scheme) or 2.\n\n"
329 "`order = 2` turns on, TOGETHER, the four pieces WO-P3f's instruments indicated:\n"
330 " 1. `set_phase_change_mdot_operator(True)` -- mdot is the energy operator's OWN "
331 "interfacial flux q/(h_lv A) instead of a separate least-squares fit, so the heat the "
332 "energy equation loses and the mass the regression produces are one discrete quantity "
333 "(and the interfacial AREA cancels out of the mass balance entirely);\n"
334 " 2. `set_phase_change_gfm_order(2)` -- the Gibou-Fedkiw three-point ghost-fluid row "
335 "(2/((1+theta) theta), 2/(1+theta)) instead of the two-point (1/theta, 1), which is "
336 "exact on a quadratic profile at every theta;\n"
337 " 3. `set_phase_change_curvature_distance(True)` -- the row's theta and the one-sided "
338 "fits' sample distances are measured to the CURVED interface, with kappa taken per cell "
339 "from the V3 curvature cascade;\n"
340 " 4. `set_phase_change_carry_conserve(True)` -- WO-P3f's enthalpy-conserving Dirichlet "
341 "overwrite.\n\n"
342 "Why together and not one at a time: WO-P3f measured the shipped scheme's 1 % Scriven "
343 "error to be the residue of a CANCELLATION between the fit's +6 % curvature bias, the "
344 "two-point row's -5 % flux deficit and the overwrite's -0.7...-4.3 % enthalpy "
345 "destruction, so repairing any ONE alone makes the gate worse.");
346 cls.def(
347 "set_phase_change_deposit_fallback",
348 [](D& diag, bool on) { diag.s->setPhaseChangeDepositFallback(on); }, nb::arg("on") = true,
349 "WO-P3f open item 6 / WO-P3g (OFF by default): give "
350 "an interfacial cell whose two along-the-normal deposit candidates are BOTH still "
351 "interfacial a target from the 5^3 box instead of leaving the divergence source in "
352 "place. A cell that keeps its source carries div(open u) = S on its own faces, so "
353 "Weymouth-Yue advects the colour with a field that is not the liquid velocity -- read it "
354 "out with `phase_change_diagnostics()['band_div']` and the 'fallback_cells' count.");
355 cls.def(
356 "set_phase_change_mdot_operator",
357 [](D& diag, bool on) { diag.s->setPhaseChangeMdotOperator(on); }, nb::arg("on") = true,
358 "WO-P3g item 1 (default OFF): take mdot from the energy operator's own interfacial flux "
359 "-- the sum of the ghost-fluid rows' Dirichlet couplings evaluated with the converged T "
360 "-- instead of the one-sided least-squares fit, which stays as "
361 "`phase_change_diagnostics()['mdot_fit']`. Under a physical domain this needs "
362 "set_phase_change_energy: the constant-diffusivity flux carries no heat capacity, so "
363 "the step raises rather than assume one.");
364 cls.def(
365 "set_phase_change_gfm_order", [](D& diag, int o) { diag.s->setPhaseChangeGfmOrder(o); },
366 nb::arg("order"),
367 "WO-P3g item 2 (default 1): the order of the one-sided (ghost-fluid) Dirichlet row. "
368 "1 = the shipped two-point form k o (T_Gamma - T_i)/theta; 2 = Gibou-Fedkiw's "
369 "three-point form through (T_behind, T_i, T_Gamma), which reproduces a quadratic "
370 "temperature profile exactly at every theta.");
371 cls.def(
372 "set_phase_change_curvature_distance",
373 [](D& diag, bool on) { diag.s->setPhaseChangeCurvatureDistance(on); }, nb::arg("on") = true,
374 "WO-P3g item 3 (default OFF): measure the GFM row's theta and the one-sided fits' sample "
375 "distances to the CURVED interface, with the mean curvature taken PER CELL from the V3 "
376 "curvature cascade (the same kappa surface tension uses; positive for a convex blob of "
377 "liquid, i.e. -2/R for a gas bubble). Supersedes `set_phase_change_fit_curvature`, which "
378 "prescribes one curvature for the whole field; where both are set the cascade wins.");
379 cls.def(
380 "set_phase_change_carry_conserve",
381 [](D& diag, bool on) { diag.s->setPhaseChangeCarryConserve(on); }, nb::arg("on") = true,
382 "WO-P3f OPTION (default OFF): make the interfacial cells' per-cell Dirichlet OVERWRITE "
383 "enthalpy-conserving.\n\n"
384 "An interfacial cell's row is the identity `T = dval`, so whatever the geometric energy "
385 "transport left there is discarded every step. Over a cell's interfacial lifetime that "
386 "telescopes to rho c_p (T_entry - dval_exit): a liquid cell the interface sweeps enters "
387 "with its superheat and leaves as vapour at T_sat, and the difference goes nowhere. "
388 "Measured on Scriven 128^3 by `phase_change_budget()['d_overwrite']`: -0.7 % of "
389 "mdot h_lv A_Gamma at Ja = 0.5 and -4.3 % at Ja = 2, one-signed.\n\n"
390 "With this on, that enthalpy is handed to the interfacial cell's face neighbours that "
391 "are still in the solve, weighted by n_d^2 (the clip-and-redistribute allocation), as a "
392 "fixed-order gather so it is decomposition-independent. Which side receives is decided "
393 "per axis by which pure neighbour deviates from T_Gamma in the same direction as the "
394 "interfacial cell itself, i.e. the phase the enthalpy came from -- the superheated "
395 "liquid on an evaporating bubble, the superheated vapour on the Stefan problem.");
396 cls.def(
397 "phase_change_carry_ledger",
398 [](D& diag) {
399 nb::dict r;
400 r["deposited"] = diag.s->phaseChangeCarryDeposited();
401 r["lost"] = diag.s->phaseChangeCarryLost();
402 return r;
403 },
404 "WO-P3f: the last `set_phase_change_carry_conserve` pass — the enthalpy actually handed "
405 "back ('deposited') and the enthalpy of the interfacial cells that had NO neighbour left "
406 "in the solve ('lost', which stays destroyed). Both 0 when the option is off. Units as "
407 "phase_change_budget's enthalpies.");
408 cls.def(
409 "set_phase_change_budget", [](D& diag, bool on) { diag.s->setPhaseChangeBudget(on); },
410 nb::arg("on") = true,
411 "WO-P3f INSTRUMENT: turn on the energy budget of the phase-change energy solve. Costs "
412 "one extra cell field and two reductions per energy solve, and is skipped entirely when "
413 "off (the solve is then bit-identical). Read it with `phase_change_budget()`.\n\n"
414 "What it exists for: interfacial cells are Dirichlet rows, i.e. they are OUTSIDE the "
415 "energy solve, so the set over which enthalpy is conserved changes membership every step "
416 "as the interface sweeps. A liquid cell that becomes interfacial LEAVES that set "
417 "carrying "
418 "its superheat rho c_p (T - T_sat) and an interfacial cell that becomes pure RE-ENTERS "
419 "it "
420 "carrying `pcCarriedValue`; neither transfer appears in the latent-heat book-keeping.");
421 cls.def(
422 "phase_change_budget",
423 [](D& diag) {
424 const auto b = diag.s->phaseChangeBudgetValues();
425 nb::dict r;
426 r["h_open"] = b.hOpen;
427 r["h_open_new"] = b.hOpenNew;
428 r["h_liquid"] = b.hLiquid;
429 r["h_masked"] = b.hMasked;
430 r["d_overwrite"] = b.dEoverwrite;
431 r["d_overwrite_new"] = b.dEoverwriteNew;
432 r["e_enter"] = b.eEnter;
433 r["e_leave"] = b.eLeave;
434 r["q_gfm"] = b.qGfm;
435 r["q_behind"] = b.qBehind; // WO-P3g: the second-order row's one-sided band rescaling
436 r["n_enter_liquid"] = b.nEnterLiquid;
437 r["n_enter_gas"] = b.nEnterGas;
438 r["n_leave_liquid"] = b.nLeaveLiquid;
439 r["n_leave_gas"] = b.nLeaveGas;
440 r["n_masked"] = b.nMasked;
441 r["calls"] = b.calls;
442 return r;
443 },
444 "WO-P3f: the ENERGY BUDGET of the LAST energy solve, in the solver's physical units: "
445 "energies for the enthalpies and powers for `q_gfm`/`q_behind` with "
446 "set_phase_change_energy on; without it the constant-diffusivity scalar carries no heat "
447 "capacity and they are temperature x volume (and per time).\n"
448 " h_open / h_open_new sum rho c_p (T - T_sat) over the UNMASKED cells, before / after "
449 "the solve\n"
450 " h_liquid, h_masked the same over the pure-liquid and the interfacial cells\n"
451 " d_overwrite sum rho c_p (dval - T) over masked cells: what the Dirichlet "
452 "rows inject when they overwrite the transported temperature (negative = destroyed)\n"
453 " d_overwrite_new the part of it on cells that were NOT masked last step\n"
454 " e_enter / e_leave the enthalpy carried OUT of / INTO the solved set by the cells "
455 "that changed class this step\n"
456 " q_gfm the heat the plane-anchored rows deliver INTO the unmasked set "
457 "(negative while a bubble grows); the energy equation's own interfacial flux, to be "
458 "compared with the regression's `mdot h_lv A_Gamma`\n"
459 " n_enter_*/n_leave_* the class-change census\n"
460 "The discrete balance the entries close over one solve is "
461 "`sum rho c_p (T^{n+1} - T*)/dt = q_gfm + (domain boundary flux) + (solve residual)`.");
462}
463
464} // namespace peclet::flow::bindings
Shared helpers of the peclet.flow Python binding: array conversion, the string-enum tables,...
void bindDiagnosticsPhaseChange(C &cls)
SolverDiagnostics (and its collocated twin): phase-change options, ledgers and budgets.
const std::vector< std::string > kAreaModes
int enum_index(const std::string &v, const std::vector< std::string > &names, const char *who, const char *what)
void bindSolverPhaseChange(C &cls)
Solver (and its collocated twin): phase change.
std::vector< double > grid_in(nb::ndarray< double, nb::f_contig > a)
The developer tier: a view onto one Solver<Grid> (no state of its own).