50def solver(n, seeds, blocks=True, csf=True):
55 s.set_advection(
False)
56 s.set_pressure_geometry(np.full((nx, ny, nz), 10.0, order=
"F"))
57 s.set_pressure_chebyshev(
True, 800, 1e-12)
59 s.set_vof(np.zeros((nx, ny, nz), order=
"F"))
60 s.set_property_model(
"rho",
"linear",
"C", [RHO_L, RHO_G - RHO_L])
61 s.set_property_model(
"mu",
"linear",
"C", [MU, MU_G - MU])
62 s.set_surface_tension(SIGMA)
63 s.enable_vof_blocks(seeds)
65 s.enable_vof_block_csf()
67 s.diagnostics.set_vof_block_overlap_density(
True)
93def run(s, steps, dt=None, every=50, tag="", safety=None):
94 L = s.vof_step_limits()
96 dt = 0.25 * min(L[
"cfl_dt"], L[
"capillary_dt"])
99 RUNSTAT.update(bound_steps=0, dt_min=dt, clipped=0, debris=0, ov_cells=0)
100 for i
in range(steps):
101 if REPICK
and safety
is not None:
102 L = s.vof_step_limits()
103 dt = safety * L[
"capillary_dt"]
105 RUNSTAT[
"dt_min"] = min(RUNSTAT[
"dt_min"], dt)
108 if hasattr(s.diagnostics,
"vof_block_stats"):
110 RUNSTAT[
"bound_steps"] += int(k[
"bound"])
111 RUNSTAT[
"clipped"] += k[
"clipped"]
112 RUNSTAT[
"debris"] = max(RUNSTAT[
"debris"], k[
"debris_cells"])
113 RUNSTAT[
"ov_cells"] = max(RUNSTAT[
"ov_cells"], k[
"overlap_cells"])
114 except Exception
as exc:
115 print(f
" {tag} step {i}: THREW {exc}")
116 hist.append(float(
"nan"))
120 if not math.isfinite(u):
122 return dt, np.array(hist)
127 print(
"STATIC — two spheres at rest, no gravity: parasitic current vs centre distance d")
129 n = (int(8 * R), int(5 * R), int(5 * R))
130 cy, cz = n[1] / 2, n[2] / 2
132 cap = math.sqrt((RHO_L + RHO_G) / (4 * math.pi * SIGMA))
133 print(f
" R = {R} cells, box {n}, rho_g/rho_l = {RHO_G}, mu = {MU}, sigma = {SIGMA}; "
134 f
"Brackbill dt = {cap:.4e}; Laplace dp = {2*SIGMA/R:.2f}")
136 ds = [float(x)
for x
in arg(
"--d",
"14,10.5,10,9,8,6,4", str).split(
",")]
137 cases = ([(
"single",
None)]
if "--no-single" not in sys.argv
else []) + \
138 [(f
"d={d:g}", d)
for d
in ds]
139 for name, d
in cases:
141 seeds = [(cx, cy, cz, R)]
143 seeds = [(cx - d / 2, cy, cz, R), (cx + d / 2, cy, cz, R)]
145 v0 = [b[
"volume"]
for b
in s.diagnostics.vof_block_stats()]
147 dt, h =
run(s, STEPS, dt=
arg(
"--cap-safety", 0.25) * cap, tag=name,
148 safety=
arg(
"--cap-safety", 0.25))
149 v1 = [b[
"volume"]
for b
in s.diagnostics.vof_block_stats()]
151 dv = max(abs(a / b - 1)
for a, b
in zip(v1, v0))
152 rows.append((name, h))
153 print(f
" {name:8s} max|u| @50 {h[min(49,len(h)-1)]:.3e} @end {h[-1]:.3e} peak {np.nanmax(h):.3e} "
154 f
"maxC {float(C.max()):.6f} dV {dv:.1e} ({time.time()-t0:.0f} s) "
155 f
"bound-steps {RUNSTAT['bound_steps']} dt_min/Brackbill {RUNSTAT['dt_min']/cap:.3f} "
156 f
"clipped {RUNSTAT['clipped']} debris<= {RUNSTAT['debris']} "
157 f
"ov_cells<= {RUNSTAT['ov_cells']}", flush=
True)
158 if "--dump" in sys.argv:
159 np.savez(f
"{arg('--dump', 'static', str)}_{name}.npz", h=h, u=s.get_u(), v=s.get_v(),
165 """Two bubbles in a Couette flow, offset in y by b < D so they collide glancingly -- the
166 deterministic stand-in for the channel's turbulent collisions. Per step: max|u|, union max C,
167 marker overlap (sum V_k - sum C_union), and the step at which anything goes non-finite."""
169 print(
"SHEAR — two bubbles colliding in Couette flow (walls at +-y moving at +-U)")
173 gap0 =
arg(
"--gap", 20.0)
174 blocks =
"--single-field" not in sys.argv
175 n = (int(round(13 * R)), int(round(8 * R)), int(round(6 * R)))
180 s.set_domain_bc(
"-y",
"wall", (-U, 0, 0))
181 s.set_advection(
False)
182 s.set_domain_bc(
"+y",
"wall", (U, 0, 0))
183 s.set_pressure_geometry(np.full(n, 10.0, order=
"F"))
184 s.set_pressure_chebyshev(
True, 800, 1e-12)
185 y = (np.arange(ny) + 0.5) / ny
186 u0 = np.broadcast_to((-U + 2 * U * y)[
None, :,
None], n)
187 s.set_velocity(0, np.asfortranarray(u0))
189 s.set_vof(np.zeros(n, order=
"F"))
190 s.set_property_model(
"rho",
"linear",
"C", [RHO_L, RHO_G - RHO_L])
191 s.set_property_model(
"mu",
"linear",
"C", [MU, MU_G - MU])
192 s.set_surface_tension(SIGMA)
193 seeds = [(nx / 2 - gap0 / 2, ny / 2 + b / 2, nz / 2, R), (nx / 2 + gap0 / 2, ny / 2 - b / 2, nz / 2, R)]
195 s.enable_vof_blocks(seeds)
196 s.enable_vof_block_csf()
198 s.diagnostics.set_vof_block_overlap_density(
True)
200 from vof_surface_tension
import sphere_fractions
203 C = np.maximum(C, sphere_fractions(n, q[3], q[:3]))
204 s.set_vof(np.asfortranarray(C))
206 print(f
" box {n}, R = {R}, b = {b}, U = {U} -> approach speed {rel:.2f} cells/time; "
207 f
"We = {RHO_L*rel**2*2*R/SIGMA:.2f}; {'BLOCKS' if blocks else 'single field'}")
208 T =
arg(
"--T", 3.0 * gap0 / max(rel, 1e-9))
211 V0 = [q[
"volume"]
for q
in s.diagnostics.vof_block_stats()]
if blocks
else None
212 agg = dict(umax=0.0, bound=0, contact=0, ovmax=0.0, clipped=0, debris=0, dvol=0.0,
213 first_contact=
None, last_contact=
None, debris_steps=0, debris_vol_max=0.0)
215 L = s.vof_step_limits()
216 dt = 0.25 * min(L[
"cfl_dt"], L[
"capillary_dt"])
217 if not (dt > 0
and math.isfinite(dt)):
218 print(f
" step {i}: limits non-finite {L}")
223 except Exception
as exc:
224 print(f
" step {i} t={t:.3f}: THREW {exc}")
228 if blocks
and hasattr(s.diagnostics,
"vof_block_curvature_stats"):
230 agg[
"umax"] = max(agg[
"umax"],
umax(s))
231 agg[
"bound"] += int(k[
"bound"])
232 if k[
"overlap_cells"] > 0:
234 agg[
"first_contact"] = agg[
"first_contact"]
or i
235 agg[
"last_contact"] = i
236 agg[
"ovmax"] = max(agg[
"ovmax"], k[
"overlap_excess"])
237 agg[
"clipped"] += k[
"clipped"]
238 agg[
"debris"] = max(agg[
"debris"], k[
"debris_cells"])
239 agg[
"debris_steps"] += int(k[
"debris_cells"] > 0)
240 agg[
"debris_vol_max"] = max(agg[
"debris_vol_max"], k[
"debris_volume"])
245 st = s.diagnostics.vof_block_stats()
246 vols = [q[
"volume"]
for q
in st]
247 ov = sum(vols) - float(C.sum())
248 cen = [q[
"centroid"]
for q
in st]
249 dx = cen[1][0] - cen[0][0]
250 extra = f
"V {vols[0]:.4f}/{vols[1]:.4f} overlap {ov:8.4f} dx {dx:6.2f}"
252 extra = f
"sumC {float(C.sum()):.4f}"
253 print(f
" step {i:5d} t={t:7.3f} dt={dt:.2e} max|u| {um:8.3f} maxC {float(C.max()):.6f} "
254 f
"{extra} ({time.time()-t0:.0f} s)", flush=
True)
255 if not math.isfinite(um)
or um > 20 * U:
259 V1 = [q[
"volume"]
for q
in s.diagnostics.vof_block_stats()]
260 agg[
"dvol"] = max(abs(a / b - 1)
for a, b
in zip(V1, V0))
261 print(f
" SUMMARY steps {i} t {t:.3f}/{T:.3f} max|u| {agg['umax']:.3f} "
262 f
"max rel dV {agg['dvol']:.2e} contact steps {agg['contact']} "
263 f
"({agg['first_contact']}..{agg['last_contact']}) max overlap excess "
264 f
"{agg['ovmax']:.4f} phantom-bound steps {agg['bound']} clipped cells (sum) "
265 f
"{agg['clipped']} debris: max cells {agg['debris']}, steps with debris "
266 f
"{agg['debris_steps']}, max volume {agg['debris_vol_max']:.3e}; ledger returned per "
267 f
"marker {[f'{r:.3e}' for r in k['returned']]}, lost {k['lost']:.3e}, unresolved "
268 f
"{k['unresolved']}", flush=
True)