47 """Tight global index box of C > 0.5, grown by `pad`, clamped to the grid."""
48 idx = np.argwhere(C > 0.5)
49 lo = idx.min(axis=0) - pad
50 hi = idx.max(axis=0) + 1 + pad
51 lo = np.maximum(lo, 0)
52 hi = np.minimum(hi, C.shape)
53 return [int(lo[0]), int(lo[1]), int(lo[2]), int(hi[0]), int(hi[1]), int(hi[2])]
56HYSING1 = dict(rho1=1000.0, rho2=100.0, mu1=10.0, mu2=1.0, g=0.98, sigma=24.5,
61 """Hysing case 1, quasi-2D. `blocks` selects the container; the physics is identical."""
66 R = sc.len_to_cells(0.25)
69 s.set_mu(sc.mu(p[
"mu1"]))
70 s.set_advection(
False)
71 s.set_domain_bc(
"-z",
"wall", (0, 0, 0))
72 s.set_domain_bc(
"+z",
"wall", (0, 0, 0))
73 s.set_pressure_geometry(np.full((nx, ny, nz), 10.0, order=
"F"))
74 s.set_pressure_chebyshev(
True, 600, RTOL
or 1e-12)
76 B = cylinder_fractions((nx, ny, nz), R, nx / 2.0, sc.len_to_cells(0.5))
78 s.set_vof(np.asfortranarray(B))
79 s.set_property_model(
"rho",
"linear",
"C", [p[
"rho1"], p[
"rho2"] - p[
"rho1"]])
80 s.set_property_model(
"mu",
"linear",
"C",
81 [sc.mu(p[
"mu1"]), sc.mu(p[
"mu2"] - p[
"mu1"])])
82 s.set_surface_tension(sc.sigma(p[
"sigma"]))
83 s.set_property_model(
"force_z",
"linear",
"C",
84 [-sc.bodyforce(p[
"rho1"] * p[
"g"]),
85 -sc.bodyforce((p[
"rho2"] - p[
"rho1"]) * p[
"g"])])
86 s.enable_vof_blocks_from_field([
marker_box(B)])
87 s.enable_vof_block_csf()
89 s.set_vof(np.asfortranarray(1.0 - B))
90 s.set_property_model(
"rho",
"linear",
"C", [p[
"rho2"], p[
"rho1"] - p[
"rho2"]])
91 s.set_property_model(
"mu",
"linear",
"C",
92 [sc.mu(p[
"mu2"]), sc.mu(p[
"mu1"] - p[
"mu2"])])
93 s.set_surface_tension(sc.sigma(p[
"sigma"]))
94 s.set_property_model(
"force_z",
"linear",
"C",
95 [-sc.bodyforce(p[
"rho2"] * p[
"g"]),
96 -sc.bodyforce((p[
"rho1"] - p[
"rho2"]) * p[
"g"])])
102 zs = (np.arange(nz) + 0.5) / sc.s
104 dt = 0.4 * min(s.vof_step_limits()[
"cfl_dt"], s.capillary_dt())
106 t, i, vmax, tvmax, yc = 0.0, 0, 0.0, 0.0, 0.0
111 L = s.vof_step_limits()
112 dt = 0.4 * min(L[
"cfl_dt"], L[
"capillary_dt"])
119 B = C
if blocks
else 1.0 - C
123 yc = float((B.sum(axis=(0, 1)) * zs).sum() / vb)
124 vrise = float((B * s.get_w()).sum() / vb) / sc.s
126 vmax, tvmax = vrise, t
127 if verbose
and i % 200 == 0:
128 print(f
" t = {t:5.3f} dt = {dt:.3e} y_c = {yc:.4f} v = {vrise:.4f} "
129 f
"V/V0 = {vb/v0:.6f}")
130 return dict(vmax=vmax, tvmax=tvmax, yc=yc, steps=i, solve=h, vdrift=vb / v0 - 1.0,
131 wall=time.time() - t0, s=s)
166 """Grace (1973), as tabulated by Clift, Grace & Weber (1978) ch. 7, eqs (7-10)/(7-11):
168 H = (4/3) Eo Mo^-0.149 (mu_l/mu_w)^-0.14 mu_w = 0.9 cP
169 J = 0.94 H^0.757 (2 < H <= 59.3), 3.42 H^0.441 (H > 59.3)
170 U_T = (mu_l/(rho_l d)) Mo^-0.149 (J - 0.857)
172 THE TRAP, and it is the reason this gate was nearly reported wrong. The correlation contains a
173 DIMENSIONAL factor, `(mu_l/mu_water)^-0.14`, which a purely dimensionless (Eo, Mo, ratio)
174 specification does NOT determine: at Eo = 10, Mo = 1e-3 the "Grace-diagram terminal velocity"
175 is 0.959 cells/s if one silently sets that factor to 1 and 0.579 if the liquid is the one that
176 actually HAS Mo = 1e-3. It has to be the latter: Mo = 1e-3 at water-like rho and sigma forces
177 mu_l ~ 0.073 Pa s ~ 81 x water (water itself is Mo ~ 2.5e-11), so a factor of 1 describes no
178 liquid at all. `mu_ratio_to_water = None` therefore DERIVES the factor from the physical
179 system that the dimensionless pair implies at rho_l = 1000 kg/m^3, sigma = 0.065 N/m,
180 g = 9.81 m/s^2 -- a glycerol/water mixture, the standard Mo = 1e-3 fluid.
182 if mu_ratio_to_water
is None:
183 RHO_P, SIG_P, G_P, MU_W = 1000.0, 0.065, 9.81, 9.0e-4
184 mu_phys = (Mo * RHO_P * SIG_P ** 3 / G_P) ** 0.25
185 mu_ratio_to_water = mu_phys / MU_W
186 H = (4.0 / 3.0) * Eo * Mo ** -0.149 * mu_ratio_to_water ** -0.14
188 J = 0.94 * H ** 0.757
190 J = 3.42 * H ** 0.441
191 return (mu_l / (rho_l * d)) * Mo ** -0.149 * (J - 0.857)
195 print(
"\n" +
"=" * 96)
196 print(
"GATE 2 — a single 3-D bubble at Eo = 10, Mo = 1e-3 vs the Grace-diagram terminal velocity")
200 Eo, Mo, ratio = 10.0, 1e-3, 100.0
201 D = 12.0
if QUICK
else 16.0
203 rho_l, sigma = 1.0, 1.0
204 g = Eo * sigma / (rho_l * D * D)
205 mu_l = (Mo * rho_l ** 2 * sigma ** 3 / g) ** 0.25
206 rho_g, mu_g = rho_l / ratio, mu_l / ratio
207 nx = int(round(4 * D))
208 nz = int(round(9 * D))
210 print(f
" D = {D:g} cells, box {nx}x{ny}x{nz}, rho_l {rho_l}, rho_g {rho_g}, mu_l {mu_l:.4e}, "
211 f
"sigma {sigma}, g {g:.4e}")
213 Ut1 =
grace_terminal(Eo, Mo, D, rho_l, mu_l, sigma, g, mu_ratio_to_water=1.0)
214 Ub = math.sqrt(g * D)
215 mu_phys = (Mo * 1000.0 * 0.065 ** 3 / 9.81) ** 0.25
216 print(f
" the physical system this (Eo, Mo) implies at rho = 1000, sigma = 0.065, g = 9.81: "
217 f
"d = {math.sqrt(Eo*0.065/(1000*9.81))*1e3:.2f} mm, mu_l = {mu_phys*1e3:.1f} cP "
218 f
"({mu_phys/9e-4:.0f} x water)")
219 print(f
" Grace/Clift U_T = {Ut:.4f} cells/s (Re = {rho_l*Ut*D/mu_l:.1f}, "
220 f
"Fr = U/sqrt(gD) = {Ut/Ub:.3f})")
221 print(f
" [the same formula with the viscosity factor set to 1 -- i.e. pretending the liquid "
222 f
"is water, which cannot have Mo = 1e-3 -- reads {Ut1:.4f}; see grace_terminal()]")
226 s.set_advection(
False)
227 s.set_domain_bc(
"-z",
"wall", (0, 0, 0))
228 s.set_domain_bc(
"+z",
"wall", (0, 0, 0))
229 s.set_pressure_geometry(np.full((nx, ny, nz), 10.0, order=
"F"))
230 s.set_pressure_chebyshev(
True, 800, 1e-12)
232 B = sphere_fractions((nx, ny, nz), R, (nx / 2.0, ny / 2.0, 1.6 * D))
233 s.set_vof(np.asfortranarray(B))
234 s.set_property_model(
"rho",
"linear",
"C", [rho_l, rho_g - rho_l])
235 s.set_property_model(
"mu",
"linear",
"C", [mu_l, mu_g - mu_l])
236 s.set_surface_tension(sigma)
237 s.set_property_model(
"force_z",
"linear",
"C",
238 [-rho_l * g, -(rho_g - rho_l) * g])
239 s.enable_vof_blocks_from_field([
marker_box(B)])
240 s.enable_vof_block_csf()
241 T = (3.0
if QUICK
else 6.0) * D / Ut
249 L = s.vof_step_limits()
250 dt = 0.4 * min(L[
"cfl_dt"], L[
"capillary_dt"])
256 st = s.diagnostics.vof_block_stats()[0]
258 hist.append((t, st[
"centroid"][2], st[
"volume"], st[
"area"],
259 st[
"moments"][2], st[
"moments"][0]))
263 ur = float((C * w).sum() / C.sum())
264 print(f
" t = {t:8.2f} z_c = {hist[-1][1]:8.3f} U = {ur:.4f} "
265 f
"V/V0 = {hist[-1][2]/hist[0][2]:.6f} A = {hist[-1][3]:.1f}")
266 hist = np.array(hist)
269 U = np.polyfit(hist[-k:, 0], hist[-k:, 1], 1)[0]
271 E = math.sqrt(hist[-1, 5] / hist[-1, 4])
272 print(f
"\n measured terminal velocity {U:.4f} cells/s ({100*(U/Ut-1):+.1f} % of Grace)")
273 print(f
" Re = {rho_l*U*D/mu_l:.1f}; aspect ratio (sqrt(m_xx/m_zz)) {E:.3f} "
274 f
"(ellipsoidal regime: E > 1)")
275 print(f
" volume drift {hist[-1,2]/hist[0,2]-1:+.2e}; interface area "
276 f
"{hist[-1,3]:.1f} vs the sphere's {4*math.pi*R*R:.1f} cells^2")
277 print(f
" {i} steps, {h} ({time.time()-t0:.0f} s)")
278 print(f
" GATE: |U/U_Grace - 1| <= 10 % -> "
279 f
"{'PASS' if abs(U/Ut - 1) <= 0.10 else 'FAIL'}")
284 print(
"\n" +
"=" * 96)
285 print(
"GATE 3 — two bubbles in line, the larger catching the smaller: no numerical coalescence")
287 print(
" A LARGE bubble rising in line behind a SMALL one closes the gap deterministically (at")
288 print(
" fixed Mo the terminal velocity grows with D), so the collision happens on a schedule")
289 print(
" instead of waiting on the wake. In a single global colour field the two merge the")
290 print(
" moment their PLIC bands touch -- the film is sub-grid and the field has no way to")
291 print(
" represent two interfaces in one cell. With one marker each they cannot merge, and the")
292 print(
" union carries CELLS THAT BELONG TO BOTH. The control is the same case, same numbers,")
293 print(
" on the structured field.")
294 Eo, Mo, ratio = 10.0, 1e-3, 100.0
295 D = 10.0
if QUICK
else 12.0
296 Rs, Rl = 0.40 * D, 0.60 * D
297 rho_l, sigma = 1.0, 1.0
298 g = Eo * sigma / (rho_l * D * D)
299 mu_l = (Mo * rho_l ** 2 * sigma ** 3 / g) ** 0.25
300 rho_g, mu_g = rho_l / ratio, mu_l / ratio
301 nx = ny = int(round(5 * D))
302 nz = int(round(11 * D))
308 zc_s = zc_l + Rs + Rl + 2.0
309 print(f
" D_small = {2*Rs:.1f}, D_large = {2*Rl:.1f} cells; box {nx}x{ny}x{nz}; "
310 f
"centres z = {zc_l:.1f} / {zc_s:.1f} (gap {zc_s-zc_l-Rs-Rl:.1f} cells)")
316 s.set_advection(
False)
317 s.set_domain_bc(
"-z",
"wall", (0, 0, 0))
318 s.set_domain_bc(
"+z",
"wall", (0, 0, 0))
319 s.set_pressure_geometry(np.full((nx, ny, nz), 10.0, order=
"F"))
320 s.set_pressure_chebyshev(
True, 800, 1e-12)
322 B0 = sphere_fractions((nx, ny, nz), Rl, (nx / 2.0, ny / 2.0, zc_l))
323 B1 = sphere_fractions((nx, ny, nz), Rs, (nx / 2.0, ny / 2.0, zc_s))
324 s.set_vof(np.asfortranarray(np.maximum(B0, B1)))
325 s.set_property_model(
"rho",
"linear",
"C", [rho_l, rho_g - rho_l])
326 s.set_property_model(
"mu",
"linear",
"C", [mu_l, mu_g - mu_l])
327 s.set_surface_tension(sigma)
328 s.set_property_model(
"force_z",
"linear",
"C", [-rho_l * g, -(rho_g - rho_l) * g])
331 mid = (b0[5] + b1[2]) // 2
332 b0[5] = min(b0[5], mid)
333 b1[2] = max(b1[2], mid)
334 s.enable_vof_blocks_from_field([b0, b1])
335 s.enable_vof_block_csf()
336 return s, 4 / 3 * math.pi * Rl ** 3, 4 / 3 * math.pi * Rs ** 3
339 """Empty cells on the axis BETWEEN the two blobs; 0 = they have merged there."""
340 col = C[nx // 2, ny // 2, :]
341 occ = np.argwhere(col > 0.5).ravel()
344 inside = col[occ.min():occ.max() + 1]
345 return int((inside < 0.5).sum())
348 T = (3.0
if QUICK
else 6.0) * D / Ut
350 for name, blk
in ((
"blocks",
True), (
"single field (control)",
False)):
351 s, v0l, v0s =
build(blk)
353 t, i, dt = 0.0, 0, 0.0
354 mingap, overlap_max = 10 ** 9, 0.0
359 L = s.vof_step_limits()
360 dt = 0.4 * min(L[
"cfl_dt"], L[
"capillary_dt"])
369 mingap = min(mingap, gap)
370 if gap == 0
and merged_at
is None:
373 vols = [b[
"volume"]
for b
in s.diagnostics.vof_block_stats()]
374 overlap_max = max(overlap_max, sum(vols) - float(C.sum()))
376 print(f
" t = {t:7.2f} gap {axis_gap(s.get_vof()):3d} cells "
377 f
"({time.time()-t0:.0f} s)")
379 info = dict(steps=i, solve=h, gap=axis_gap(C), mingap=mingap, merged=merged_at,
380 wall=time.time() - t0)
381 print(f
"\n -- {name}: {i} steps, {info['solve']} ({info['wall']:.0f} s)")
383 st = s.diagnostics.vof_block_stats()
384 info[
"vols"] = [b[
"volume"]
for b
in st]
385 info[
"zc"] = [b[
"centroid"][2]
for b
in st]
386 info[
"overlap"] = overlap_max
387 print(f
" marker volumes {info['vols'][0]:.4f} / {info['vols'][1]:.4f} "
388 f
"(seed {v0l:.4f} / {v0s:.4f}; drift "
389 f
"{info['vols'][0]/v0l-1:+.2e} / {info['vols'][1]/v0s-1:+.2e})")
390 print(f
" centroids z {info['zc'][0]:.2f} / {info['zc'][1]:.2f}; final film gap on "
391 f
"the axis {info['gap']} cells, MINIMUM over the run {mingap}")
392 print(f
" peak shared liquid (sum V_marker - sum C_union) {overlap_max:.3f} cells")
394 print(f
" final film gap on the axis {info['gap']} cells, MINIMUM {mingap}; "
395 f
"merged at t = {merged_at}")
397 b, c = res[
"blocks"], res[
"single field (control)"]
398 ok = (b[
"mingap"] >= 1)
and (c[
"mingap"] == 0)
399 print(f
"\n GATE: the control MERGES (gap -> 0) while the blocks keep two markers with their")
400 print(f
" own volumes and a film at least one cell thick.")
401 print(f
" blocks min gap {b['mingap']} cells (peak shared liquid "
402 f
"{b['overlap']:.3f}); control min gap {c['mingap']} cells "
403 f
"(merged at t = {c['merged']}) -> {'PASS' if ok else 'INCONCLUSIVE'}")
408 """The discriminating half of gate 3, when the film gate does not reach contact on its own.
410 Seed the two markers ALREADY TOUCHING -- the centre distance is one cell less than the sum of
411 the radii, so their PLIC bands share cells from step 0 -- and run a real two-phase step. A
412 single global colour field has one blob there and can never have two again; two markers have
413 two, each conserving its own volume, and the union carries the shared liquid explicitly.
415 print(
"\n" +
"=" * 96)
416 print(
"GATE 3b — two markers seeded IN CONTACT under a real NS step: the union carries cells")
417 print(
" that belong to both, and the control is one blob for ever")
419 Eo, Mo, ratio = 10.0, 1e-3, 100.0
421 Rs, Rl = 0.40 * D, 0.60 * D
422 rho_l, sigma = 1.0, 1.0
423 g = Eo * sigma / (rho_l * D * D)
424 mu_l = (Mo * rho_l ** 2 * sigma ** 3 / g) ** 0.25
425 rho_g, mu_g = rho_l / ratio, mu_l / ratio
426 nx = ny = int(round(4 * D))
427 nz = int(round(7 * D))
429 zc_s = zc_l + Rs + Rl - 1.0
430 steps = 100
if QUICK
else 400
431 print(f
" D_small = {2*Rs:.1f}, D_large = {2*Rl:.1f}; box {nx}x{ny}x{nz}; centre distance "
432 f
"{zc_s-zc_l:.1f} = R_s + R_l - 1")
438 s.set_advection(
False)
439 s.set_domain_bc(
"-z",
"wall", (0, 0, 0))
440 s.set_domain_bc(
"+z",
"wall", (0, 0, 0))
441 s.set_pressure_geometry(np.full((nx, ny, nz), 10.0, order=
"F"))
442 s.set_pressure_chebyshev(
True, 800, 1e-12)
444 B0 = sphere_fractions((nx, ny, nz), Rl, (nx / 2.0, ny / 2.0, zc_l))
445 B1 = sphere_fractions((nx, ny, nz), Rs, (nx / 2.0, ny / 2.0, zc_s))
446 s.set_vof(np.asfortranarray(np.maximum(B0, B1)))
447 s.set_property_model(
"rho",
"linear",
"C", [rho_l, rho_g - rho_l])
448 s.set_property_model(
"mu",
"linear",
"C", [mu_l, mu_g - mu_l])
449 s.set_surface_tension(sigma)
450 s.set_property_model(
"force_z",
"linear",
"C", [-rho_l * g, -(rho_g - rho_l) * g])
458 s.enable_vof_blocks([(nx / 2.0, ny / 2.0, zc_l, Rl), (nx / 2.0, ny / 2.0, zc_s, Rs)])
459 s.enable_vof_block_csf()
460 return s, 4 / 3 * math.pi * Rl ** 3, 4 / 3 * math.pi * Rs ** 3
463 for name, blk
in ((
"blocks",
True), (
"single field (control)",
False)):
464 s, v0l, v0s =
build(blk)
468 for i
in range(steps):
470 L = s.vof_step_limits()
471 dt = 0.2 * min(L[
"cfl_dt"], L[
"capillary_dt"])
476 col = C[nx // 2, ny // 2, :]
477 occ = np.argwhere(col > 0.5).ravel()
480 for v
in (col > 0.5):
484 info = dict(blobs=blobs, union=float(C.sum()), solve=h, wall=time.time() - t0)
486 st = s.diagnostics.vof_block_stats()
487 info[
"vols"] = [b[
"volume"]
for b
in st]
488 info[
"shared"] = sum(info[
"vols"]) - info[
"union"]
489 info[
"cells_both"] =
None
491 print(f
"\n -- {name}: {steps} steps, {h} ({info['wall']:.0f} s)")
493 print(f
" TWO markers, volumes {info['vols'][0]:.3f} / {info['vols'][1]:.3f} "
494 f
"(seed {v0l:.3f} / {v0s:.3f}, drift {info['vols'][0]/v0l-1:+.2e} / "
495 f
"{info['vols'][1]/v0s-1:+.2e})")
496 print(f
" union {info['union']:.3f} cells; SHARED liquid "
497 f
"sum(V_marker) - sum(C_union) = {info['shared']:.3f} cells")
498 print(f
" blobs along the axis in the union field: {blobs}")
500 print(f
" ONE colour field: {blobs} blob(s) along the axis, "
501 f
"union {info['union']:.3f} cells")
502 b, c = out[
"blocks"], out[
"single field (control)"]
503 ok = b[
"shared"] > 0.0
504 print(f
"\n GATE: the blocks carry {b['shared']:.3f} cells of liquid that belong to BOTH "
505 f
"markers -- a state a single colour field cannot represent (the control's union is "
506 f
"{c['union']:.3f} cells in {c['blobs']} blob). -> {'PASS' if ok else 'FAIL'}")
511 print(
"\n" +
"=" * 96)
512 print(
"RUNG W1 — 64-bubble swarm: master assignment, per-bubble outputs, packing")
518 s.set_advection(
False)
519 s.set_pressure_geometry(np.full((n, n, n), 10.0, order=
"F"))
521 s.set_vof(np.zeros((n, n, n), order=
"F"))
527 r = 2.0 + 7.0 * ((k % 8) / 7.0)
528 seeds.append(((i + 0.5) * n / 4, (j + 0.5) * n / 4, (m + 0.5) * n / 4, r))
530 s.enable_vof_blocks(seeds)
531 print(f
" {len(s.diagnostics.vof_block_stats())} markers seeded")
532 print(f
" {'mode':<16}{'imbalance (np = 1 here; the census is the replicated table)':<40}")
533 for mode, name
in ((0,
"round robin"), (1,
"LPT"), (2,
"weighted ORB")):
534 print(f
" {name:<16}{s.diagnostics.vof_block_imbalance_of(mode):.4f}")
535 st = s.diagnostics.vof_block_stats()
536 tot_v = sum(b[
"volume"]
for b
in st)
537 tot_a = sum(b[
"area"]
for b
in st)
538 print(f
" per-bubble outputs: total volume {tot_v:.2f} cells, total interface area "
539 f
"{tot_a:.2f} cells^2")
540 b = max(st, key=
lambda q: q[
"volume"])
541 R = (3 * b[
"volume"] / (4 * math.pi)) ** (1 / 3)
542 print(f
" largest marker id {b['id']}: V {b['volume']:.3f} -> R {R:.3f} cells, area "
543 f
"{b['area']:.2f} vs 4 pi R^2 {4*math.pi*R*R:.2f} ({100*(b['area']/(4*math.pi*R*R)-1):+.2f} %)")
544 print(f
" centroid {tuple(round(q,3) for q in b['centroid'])} moments "
545 f
"{tuple(round(q,3) for q in b['moments'])}")