45 """The ISSUES reproducer: a half-filled box, uniform u = 1, body force in z."""
50 s.set_advection(
False)
51 s.set_pressure_geometry(np.full((n, n, n), 1e30, order=
"F"))
52 s.set_body_force((0.0, 0.0, 1e-3))
54 C = np.zeros((n, n, n), order=
"F")
55 C[:, :, : n // 2] = 1.0
57 u = np.zeros((n, n, n), order=
"F")
66 print(
"ISSUES item 1 -- step() atomic across the Weymouth-Yue boundedness throw")
73 except RuntimeError
as e:
74 threw = str(e).split(
"\n")[0]
75 print(f
" WY throw: {threw[:110]}")
77 check(
"WY: step() threw", bool(threw), threw[:60])
82 check(
"WY: retry at a smaller dt runs",
True)
89 s.set_advection(
False)
90 s.set_pressure_geometry(np.full((n, n, n), 1e30, order=
"F"))
91 s.set_body_force((0.0, 0.0, 1e-3))
93 x, y, z = np.meshgrid(*[np.arange(n) + 0.5] * 3, indexing=
"ij")
94 r = np.sqrt((x - n / 2) ** 2 + (y - n / 2) ** 2 + (z - n / 2) ** 2)
95 s.set_vof(np.asfortranarray(np.clip(4.0 - r, 0.0, 1.0)))
96 s.set_surface_tension(1.0)
97 s.set_dt(0.2 * s.capillary_dt())
101 s.set_dt(10.0 * s.capillary_dt())
105 except RuntimeError
as e:
106 threw = str(e).split(
"\n")[0]
107 print(f
" capillary throw: {threw[:110]}")
109 check(
"sigma: step() threw", bool(threw), threw[:60])
110 check(
"sigma: state bitwise unchanged",
same(s0,
state(s)), str(d))
118 s.set_advection(
False)
119 s.set_domain_bc(
"-z",
"wall"); s.set_domain_bc(
"+z",
"wall")
120 s.set_pressure_geometry(np.full((nx, 4, nz), 1e30, order=
"F"))
122 x, y, z = np.meshgrid(np.arange(nx) + 0.5, np.arange(4) + 0.5,
123 np.arange(nz) + 0.5, indexing=
"ij")
124 r = np.sqrt((x - nx / 2) ** 2 + (z - nz / 4) ** 2)
125 C = np.asfortranarray(np.clip(0.5 + (r - 0.25 * nx / 2), 0.0, 1.0) * 0 + (r > 0.25 * nx).astype(float))
127 s.set_property_model(
"rho",
"linear",
"C", [1.0, 9.0])
128 s.set_property_model(
"mu",
"linear",
"C", [0.005, 0.045])
129 s.set_pressure_fcg(
True, 600, 1e-10)
131 s.set_surface_tension(sigma)
132 s.set_body_force((0.0, 0.0, -5e-2))
136 ww = np.zeros((nx, 4, nz), order=
"F")
137 ww += (0.3 * np.sin(2 * np.pi * (np.arange(nx) + 0.5) / nx))[:,
None,
None]
139 s.set_dt(min(1.0, 0.4 * s.capillary_dt()))
144 print(
"ISSUES item 2 -- step_adaptive reproduces the gallery driver bitwise")
148 for cfl, cap, sig, dmax
in ((0.4, 0.4, 0.02, math.inf), (0.2, 0.4, 0.0, 1.0)):
149 print(f
" -- cfl_target = {cfl}, capillary_cfl = {cap}, sigma = {sig}, dt_max = {dmax}"
150 f
" ({'capillary' if sig else 'CFL/dt_max'}-bound)")
156 dts_a, ncap, ncfl = [], 0, 0
157 for _
in range(nsteps):
158 L = a.vof_step_limits()
159 dt = min(cflT * L[
"cfl_dt"], capT * L[
"capillary_dt"], dmax)
163 ncap += int(capT * L[
"capillary_dt"] <= min(cflT * L[
"cfl_dt"], dmax))
164 ncfl += int(cflT * L[
"cfl_dt"] < min(capT * L[
"capillary_dt"], dmax))
166 dts_b = [b.step_adaptive(cflT, capT, dmax)
for _
in range(nsteps)]
168 check(
" dt sequence identical", dts_a == dts_b,
169 f
"max|d dt| = {max(abs(x - y) for x, y in zip(dts_a, dts_b)):.3e}")
171 print(f
" {nsteps} steps, dt {dts_a[0]:.6g} -> {dts_a[-1]:.6g}, "
172 f
"pressure {a.diagnostics.last_pressure_iterations()}/600, failed={a.diagnostics.pressure_solve_failed()}; "
173 f
"capillary bound {ncap} steps, CFL bound {ncfl}; "
174 f
"dt range [{min(dts_a):.6g}, {max(dts_a):.6g}]")
179 print(
"ISSUES item 4 -- vof_geometry() on an all-fluid VoF solver")
182 s.set_rho(1.0); s.set_mu(0.1)
183 s.set_pressure_geometry(np.full((n, n, n), 10.0, order=
"F"))
185 eps = np.asarray(s.diagnostics.vof_geometry(0))
186 kind = np.asarray(s.diagnostics.vof_geometry(4))
187 check(
"vof_has_geometry() is False", s.vof_has_geometry()
is False)
188 check(
"eps == 1 everywhere", eps.shape == (n, n, n)
and np.all(eps == 1.0),
189 f
"min {eps.min()} max {eps.max()}")
190 check(
"openness == 1 everywhere",
191 all(np.all(np.asarray(s.diagnostics.vof_geometry(k)) == 1.0)
for k
in (1, 2, 3)))
192 check(
"classification == 0 everywhere", np.all(kind == 0.0))
194 gas = np.asarray(s.diagnostics.vof_geometry(0)) * (1.0 - s.get_vof())
195 check(
"E7 dual-use expression runs", gas.shape == (n, n, n))
200 """Cell-centre-sampled LeVeque deformation field (u, v, w) on an n^3 unit box."""
201 c = (np.arange(n) + 0.5) / n
202 X, Y, Z = np.meshgrid(c, c, c, indexing=
"ij")
203 f = math.cos(math.pi * t / T)
204 u = 2.0 * np.sin(np.pi * X) ** 2 * np.sin(2 * np.pi * Y) * np.sin(2 * np.pi * Z) * f
205 v = -np.sin(2 * np.pi * X) * np.sin(np.pi * Y) ** 2 * np.sin(2 * np.pi * Z) * f
206 w = -np.sin(2 * np.pi * X) * np.sin(2 * np.pi * Y) * np.sin(np.pi * Z) ** 2 * f
207 return (np.asfortranarray(u * n), np.asfortranarray(v * n), np.asfortranarray(w * n))
211 c = (np.arange(n) + 0.5) / n
212 X, Y, Z = np.meshgrid(c, c, c, indexing=
"ij")
213 d = np.sqrt((X - cx) ** 2 + (Y - cx) ** 2 + (Z - cx) ** 2)
214 return np.asfortranarray(np.clip(0.5 + (r - d) * n, 0.0, 1.0))
218 print(
"ISSUES item 5 -- SolverColocated: set_state + advect_vof")
220 s = pf.SolverColocated(n, n, n)
221 s.set_rho(1.0); s.set_mu(0.0)
222 s.set_pressure_geometry(np.full((n, n, n), 10.0, order=
"F"))
228 print(f
" max|u| = {np.abs(u).max():.4g}, max|uf| after set_state = "
229 f
"{np.abs(np.asarray(s.get_uf())).max():.4g}")
230 check(
"set_state seeds the face field", np.abs(np.asarray(s.get_uf())).max() > 1.0)
231 div = s.max_open_divergence_projected()
232 print(f
" max|div(open uf)| of the seeded field = {div:.4g}")
233 dt = 0.2 / np.abs(np.asarray(s.get_uf())).max()
236 moved = float(np.abs(s.get_vof() - C0).max())
237 vol = float(s.get_vof().sum())
238 check(
"advect_vof no longer a silent no-op", moved > 0.0, f
"max|C-C0| = {moved:.3e}")
241 r.set_rho(1.0); r.set_mu(0.0)
242 r.set_pressure_geometry(np.full((n, n, n), 10.0, order=
"F"))
243 r.enable_vof(); r.set_vof(C0)
244 for nm, fa
in zip(
"uvw", (s.get_uf(), s.get_vf(), s.get_wf())):
245 r.set_field(nm, np.asfortranarray(np.asarray(fa)))
248 dC = float(np.abs(r.get_vof() - s.get_vof()).max())
249 print(f
" dt = {dt:.6g}, 10 steps: max|C-C0| = {moved:.4g}, sum C = {vol:.12g} (C0: {float(C0.sum()):.12g})")
250 check(
"collocated colour == the staggered run on the SAME face field", dC == 0.0,
251 f
"max|dC| = {dC:.3e}")
253 s2 = pf.SolverColocated(n, n, n)
254 s2.set_rho(1.0); s2.set_mu(0.0)
255 s2.set_pressure_geometry(np.full((n, n, n), 10.0, order=
"F"))
256 s2.enable_vof(); s2.set_vof(C0)
260 except RuntimeError
as e:
261 m2 = str(e).split(
"\n")[0]
262 check(
"a never-built face field is refused",
"never been built" in m2, m2[:70])
268 s.set_rho(1.0); s.set_mu(mu); s.set_dt(dt); s.set_advection(
False)
269 s.set_domain_bc(
"-z",
"wall")
270 s.set_domain_bc(
"+z", top_type)
271 s.set_pressure_geometry(np.full((4, 4, nz), 1e30, order=
"F"))
272 s.set_body_force((F, 0.0, 0.0))
273 for _
in range(steps):
279 print(
"ISSUES item 7 -- domain BC type 4 = free slip")
287 u = s.get_u()[0, 0, :]
288 zc = np.arange(nz) + 0.5
290 cont = F / (2 * mu) * (H ** 2 - (H - zc) ** 2)
291 disc = cont + F / (2 * mu) * 0.25
292 e_cont = float(np.abs(u - cont).max() / cont.max())
293 e_disc = float(np.abs(u - disc).max() / disc.max())
294 print(f
" u_max {u.max():.8f}; continuum parabola {cont.max():.8f} (rel {e_cont:.3e}), "
295 f
"discrete parabola {disc.max():.8f} (rel {e_disc:.3e}); "
296 f
"pressure {s.diagnostics.last_pressure_iterations()}, failed={s.diagnostics.pressure_solve_failed()}")
297 check(
"half-channel == the scheme's own discrete parabola (solver tol)", e_disc < 1e-8, f
"{e_disc:.3e}")
298 check(
"half-channel within h^2 of the continuum parabola", e_cont < 1e-3, f
"{e_cont:.3e}")
302 u2 = f2.get_u()[0, 0, :nz]
303 d = float(np.abs(u - u2).max() / u.max())
304 print(f
" vs the lower half of a {2*nz}-cell no-slip channel: max rel difference {d:.3e}")
305 check(
"free slip == the symmetry plane of a full channel", d < 1e-9, f
"{d:.3e}")
308 check(
"type 4 unused -> nothing moves (sanity)", np.isfinite(a.get_u()).all())
315MAIN = dict(atomic=gate_atomic, adaptive=gate_adaptive, geometry=gate_geometry,