85 print(
"\n" +
"=" * 96)
86 print(
"G1 COLOUR BUDGET, COUPLED (WO-R gate G1 driven by step(), not by a prescribed field)")
88 print(
" A liquid slug is injected through a uniform -z inlet and flushed out of the +z")
89 print(
" outlet, with the full momentum + projection step in between. The gate is")
90 print(
" sum(C)(t) - integral(inflow liquid) + integral(outflow liquid) = const,")
91 print(
" the fluxes being the ADVECTOR's own boundary face fluxes (vof_bc_volumes). Unlike the")
92 print(
" kinematic ctest twin, the advecting field here is the projection's output, so the")
93 print(
" floor is the projection's discrete divergence residual (WO-J finding 3).\n")
94 nx = ny = 32
if not QUICK
else 16
95 nz = 64
if not QUICK
else 32
96 nslug, nafter = (60, 740)
if not QUICK
else (20, 120)
102 s.set_advection(
False)
103 for f
in (
"-x",
"+x",
"-y",
"+y"):
104 s.set_domain_bc(f,
"wall", (0, 0, 0))
105 s.set_domain_bc(
"-z",
"inflow", (0.0, 0.0, W))
106 s.set_domain_bc(
"+z",
"outflow", (0, 0, 0))
111 s.diagnostics.set_velocity_solver_params(60)
112 s.set_pressure_multigrid(
True, levels=8)
113 s.set_pressure_solver_params(80)
114 s.set_pressure_geometry(np.full((nx, ny, nz), 1e30, order=
"F"))
115 s.set_pressure_chebyshev(
True, 400, 1e-12)
117 s.set_vof(np.zeros((nx, ny, nz), order=
"F"))
118 s.set_vof_inflow(
"-z", 1.0)
119 s.set_vof_backflow(
"+z", 0.0)
121 ledger, budget0, drift = 0.0,
None, 0.0
122 cmin, cmax = 1.0, 0.0
124 for i
in range(nslug + nafter):
126 s.set_vof_inflow(
"-z", 0.0)
129 d = s.diagnostics.vof_diagnostics()
130 ledger += sum(s.vof_bc_volumes())
131 b = d[
"sum"] - ledger
134 drift = max(drift, abs(b - budget0))
135 cmin, cmax = min(cmin, d[
"min"]), max(cmax, d[
"max"])
136 tot = s.vof_bc_volumes_total()
137 injected, left = tot[4], -tot[5]
138 d = s.diagnostics.vof_diagnostics()
139 print(f
" injected {injected:.10g}, left {left:.10g}, remaining sum(C) {d['sum']:.3e}")
140 print(f
" |budget drift| {drift:.3e} (relative to the injected volume {drift/injected:.3e})")
141 print(f
" C in [{cmin:.3e}, {cmax:.17g}]")
142 print(f
" {h} ({time.time()-t0:.0f} s)")
143 ok = (drift / injected < 1e-10)
and h.valid
and cmin > -1e-12
and cmax < 1 + 1e-12
144 print(f
" GATE: {'PASS' if ok else 'FAIL'} (budget <= 1e-10 relative, C bounded, no cap)")
154 100: dict(rho_l=100.0, rho_g=1.0, mu_l=50.0, mu_g=1.0, dt=0.5, mom=
True, cap=400),
155 1000: dict(rho_l=100.0, rho_g=0.1, mu_l=50.0, mu_g=1.0, dt=0.25, mom=
True, cap=2000),
161 nx, ny, nz = 32, 4, 64
163 drho = p[
"rho_l"] - p[
"rho_g"]
164 p = dict(p, g=4.93e-3 * 99.0 / drho)
165 umax = drho * p[
"g"] * delta ** 2 / (2 * p[
"mu_l"])
166 Q = drho * p[
"g"] * delta ** 3 / (3 * p[
"mu_l"])
167 Re = p[
"rho_l"] * umax * delta / p[
"mu_l"]
168 steps = steps
or (900
if QUICK
else 2400)
169 print(
"\n" +
"=" * 96)
170 print(f
"G2 NUSSELT FALLING FILM, density ratio {ratio}, mu ratio {p['mu_l']/p['mu_g']:.0f}"
171 f
"{'' if outflow_rho else ' [ABLATION: --no-outflow-rho]'}")
173 print(
" A liquid film of thickness delta = 8 cells runs down the -x wall of a quasi-2D duct,")
174 print(
" fed at the +z inlet with the exact Nusselt profile and leaving through the -z outlet.")
175 print(
" The body force is the REDUCED gravity -(rho_l - rho_g) g C: the gas is then exactly")
176 print(
" force-free and hydrostatic, which is what the Nusselt similarity solution assumes")
177 print(
" (with gravity on the gas too, the Dirichlet p=0 outlet would accelerate the gas")
178 print(
" column instead of supporting it — a different problem).")
179 print(f
" u_max {umax:.5g} cells/s, Q {Q:.5g} cells^2/s, film Reynolds {Re:.2f}\n")
181 s.set_rho(p[
"rho_l"])
184 s.set_advection(
False)
185 s.set_domain_bc(
"-x",
"wall", (0, 0, 0))
186 s.set_domain_bc(
"+x",
"wall", (0, 0, 0))
187 s.set_domain_bc(
"-z",
"outflow", (0, 0, 0))
189 xc = np.arange(nx) + 0.5
190 wprof = np.where(xc < delta, -(drho * p[
"g"] / p[
"mu_l"]) * (delta * xc - 0.5 * xc ** 2), 0.0)
191 prof = np.zeros((nx, ny, 3))
192 prof[:, :, 2] = wprof[:,
None]
193 s.set_domain_bc_profile(
"+z", np.ascontiguousarray(prof))
198 s.diagnostics.set_velocity_solver_params(60)
199 s.set_pressure_multigrid(
True, levels=8)
200 s.set_pressure_solver_params(80)
201 s.set_pressure_geometry(np.full((nx, ny, nz), 1e30, order=
"F"))
204 C = np.zeros((nx, ny, nz), order=
"F")
205 frac = np.clip(delta - np.arange(nx), 0.0, 1.0)
206 C[:, :, :] = frac[:,
None,
None]
207 s.set_vof(np.asfortranarray(C))
208 s.set_property_model(
"rho",
"linear",
"C", [p[
"rho_g"], p[
"rho_l"] - p[
"rho_g"]])
209 s.set_property_model(
"mu",
"linear",
"C", [p[
"mu_g"], p[
"mu_l"] - p[
"mu_g"]])
210 s.set_property_model(
"force_z",
"linear",
"C", [0.0, -drho * p[
"g"]])
212 s.enable_vof_momentum(p[
"rho_g"], p[
"rho_l"])
218 s.set_pressure_fcg(
True, p[
"cap"], 1e-11)
220 s.set_vof_inflow_profile(
"+z", np.ascontiguousarray(np.repeat(frac[:,
None], ny, axis=1)))
221 s.set_vof_backflow(
"-z", 0.0)
223 w0 = np.zeros((nx, ny, nz), order=
"F")
224 w0[:, :, :] = wprof[:,
None,
None]
225 s.set_field(
"w", np.asfortranarray(w0))
236 for i
in range(steps):
238 L = s.vof_step_limits()
239 dt = min(p[
"dt"], 0.4 * L[
"cfl_dt"])
if L[
"cfl_dt"] > 0
else p[
"dt"]
241 ncap += int(dt < p[
"dt"])
244 hist.append(s.diagnostics.vof_diagnostics()[
"sum"])
248 dmeas = float(C[:, :, zmid].sum() / ny)
249 qmeas = float(-(C[:, :, zmid] * w[:, :, zmid]).sum() / ny)
250 tail = np.array(hist[-200:])
251 steady = float(np.abs(tail - tail.mean()).max() / max(tail.mean(), 1e-300))
252 print(f
" at z = nz/2: film thickness {dmeas:.4f} cells (target {delta}) "
253 f
"[error {dmeas-delta:+.4f}]")
254 print(f
" flow rate {qmeas:.6g} (Nusselt {Q:.6g}) "
255 f
"[{100*(qmeas/Q-1):+.2f} %]")
256 print(f
" sum(C) steadiness over the last 200 steps: {steady:.3e} relative")
257 print(f
" dt: nominal {p['dt']}, throttled by the WY cap on {ncap} of the "
258 f
"{(steps + 19)//20} re-picks; final {dt:.4g}")
259 print(f
" {h} ({time.time()-t0:.0f} s)")
260 ok = (abs(qmeas / Q - 1) < 0.03
and abs(dmeas - delta) < 0.5
and steady < 1e-4
and h.valid)
261 print(f
" GATE: {'PASS' if ok else 'FAIL'} (Q within 3 %, delta within 0.5 cell, "
262 f
"sum(C) steady to 1e-4, no cap)")
263 return ok, qmeas / Q - 1, dmeas - delta, steady, h.iters
268 print(
"\n" +
"=" * 96)
269 print(
"G3 GAS OVER A RESTING POOL, density ratio 1000, momentum-consistent transport")
271 print(
" Gas enters at -x above a liquid pool that fills the lower half, and leaves at +x. The")
272 print(
" pool must not move and must not lose volume, and the inflow ghost DENSITY must be the")
273 print(
" INLET fluid's — gas above the pool, liquid at the pool's own inlet plane.")
275 print(
" NOTE ON THE GATE AS WRITTEN. WO-R asks for the ghost density 'through get_field(rho)")
276 print(
" on the first inner plane'. That measures the wrong quantity: get_field returns the")
277 print(
" INNER cells, whose rho is rho(C_inner) whatever the ghost policy does. The ghost is")
278 print(
" what the inlet FACE density is built from, and it is reachable only through")
279 print(
" field_view('rho'), which returns the padded buffer. That is what is gated below.\n")
280 nx = 64
if not QUICK
else 32
282 nz = 32
if not QUICK
else 16
283 steps = 500
if not QUICK
else 150
284 rho_l, rho_g = 1000.0, 1.0
285 mu_l, mu_g = 10.0, 0.1
291 s.set_advection(
False)
292 s.set_domain_bc(
"-z",
"wall", (0, 0, 0))
293 s.set_domain_bc(
"+z",
"wall", (0, 0, 0))
294 s.set_domain_bc(
"+x",
"outflow", (0, 0, 0))
296 zc = np.arange(nz) + 0.5
298 prof = np.zeros((ny, nz, 3))
299 prof[:, :, 0] = np.where(gas, U, 0.0)[
None, :]
300 s.set_domain_bc_profile(
"-x", np.ascontiguousarray(prof))
305 s.diagnostics.set_velocity_solver_params(60)
306 s.set_pressure_multigrid(
True, levels=8)
307 s.set_pressure_solver_params(80)
308 s.set_pressure_geometry(np.full((nx, ny, nz), 1e30, order=
"F"))
310 C = np.zeros((nx, ny, nz), order=
"F")
311 C[:, :, : nz // 2] = 1.0
312 s.set_vof(np.asfortranarray(C))
313 s.set_property_model(
"rho",
"linear",
"C", [rho_g, rho_l - rho_g])
314 s.set_property_model(
"mu",
"linear",
"C", [mu_g, mu_l - mu_g])
315 s.enable_vof_momentum(rho_g, rho_l)
316 s.set_pressure_fcg(
True, 800, 1e-11)
318 cprof = np.where(gas, 0.0, 1.0)
319 s.set_vof_inflow_profile(
"-x", np.ascontiguousarray(np.repeat(cprof[
None, :], ny, axis=0)))
320 s.set_vof_backflow(
"+x", 0.0)
323 v0 = s.diagnostics.vof_diagnostics()[
"sum"]
325 for _
in range(steps):
328 v1 = s.diagnostics.vof_diagnostics()[
"sum"]
330 u, v, w = s.get_u(), s.get_v(), s.get_w()
332 umax_liq = float(np.max([np.abs(f[liq]).max()
for f
in (u, v, w)]))
333 rho =
to_host(s.diagnostics.field_view(
"rho"))
334 G = (rho.shape[0] - nx) // 2
335 ghost = rho[G - 1, G + ny // 2, :]
336 gh_gas = float(np.mean(ghost[G + nz // 2: G + nz]))
337 gh_liq = float(np.mean(ghost[G: G + nz // 2]))
338 print(f
" pool volume {v0:.10g} -> {v1:.10g} (relative change {abs(v1-v0)/v0:.3e})")
339 print(f
" max|u| in the liquid {umax_liq:.4e} ({umax_liq/U:.3e} of the gas inlet speed)")
340 print(f
" inflow ghost rho: {gh_gas:.6g} above the pool (want {rho_g}), "
341 f
"{gh_liq:.6g} at the pool (want {rho_l})")
342 print(f
" {h} ({time.time()-t0:.0f} s)")
343 ok = (abs(v1 - v0) / v0 < 1e-10
and umax_liq / U < 1e-3
and h.valid
344 and abs(gh_gas - rho_g) < 1e-9 * rho_l
and abs(gh_liq - rho_l) < 1e-9 * rho_l)
345 print(f
" GATE: {'PASS' if ok else 'FAIL'}")
360 rows.append((r, dq, dd, st, it))