33 x = np.arange(n) + 0.5
34 X, Y, Z = np.meshgrid(x, x, x, indexing=
"ij")
35 r = np.sqrt((X - 0.5 * n - 0.13) ** 2 + (Y - 0.5 * n - 0.27) ** 2 + (Z - 0.5 * n - 0.11) ** 2)
36 return np.asfortranarray(np.clip(0.5 * n * 0.3 - r + 0.5, 0.0, 1.0))
39def build(pf, cls=None, vof=True, mu1=10.0, setup=None):
41 s.set_advection(
False)
45 s.set_pressure_geometry(np.asfortranarray(np.full((N, N, N), 10.0)))
49 s.set_property_model(
"mu",
"linear",
"C", [1.0, mu1 - 1.0])
76 except ImportError
as e:
77 print(f
"SKIP: peclet.flow not importable ({e})")
82 print((
"ok " if cond
else "FAIL ") + msg)
88 check(s.vof_viscous_interface() ==
"auto", f
"default is {s.vof_viscous_interface()!r}")
89 for m
in (
"sharp",
"averaged",
"auto"):
90 s.set_vof_viscous_interface(m)
91 check(s.vof_viscous_interface() == m, f
"{m!r} round-trips to {s.vof_viscous_interface()!r}")
93 s.set_vof_viscous_interface(
"harmonic")
94 check(
False,
"'harmonic' did not raise")
95 except ValueError
as e:
96 check(s.vof_viscous_interface() ==
"auto", f
"'harmonic' -> ValueError ({e}), selection kept")
97 check(
not hasattr(s.diagnostics,
"set_vof_viscous_interface"),
98 "the developer-tier diagnostics.set_vof_viscous_interface is gone")
101 for mode, want
in ((
"auto",
True), (
"sharp",
True), (
"averaged",
False)):
102 s =
build(pf, setup=
lambda t, m=mode: t.set_vof_viscous_interface(m))
103 band, err =
run(s, 2)
104 check((band > 0) == want
and NOTICE
not in err,
105 f
"in scope, {mode!r}: band_cells {band}, sharp {'on' if want else 'off'}, no notice")
109 x = np.arange(N) + 0.5
110 X, Y, Z = np.meshgrid(x, x, x, indexing=
"ij")
111 sdf = np.sqrt((X - 1.5) ** 2 + (Y - 1.5) ** 2 + (Z - 1.5) ** 2) - 1.0
112 t.set_solid(np.asfortranarray(sdf), cutcell_pressure=
True)
115 (
"laplacian stress",
lambda t: t.set_viscous_stress(
"laplacian")),
116 (
"immersed solid", solid),
117 (
"porous momentum",
lambda t: t.set_porous_continuity(
True)),
118 (
"phase change",
lambda t: t.enable_phase_change(1.0, 10.0, 1.0)),
119 (
"harmonic face mu",
lambda t: t.diagnostics.set_property_mode(
"variable",
True)),
121 for label, setup
in out:
123 band, err =
run(
build(pf, setup=setup), 2)
124 check(band == 0
and err.count(NOTICE) == 1,
125 f
"{label}, 'auto': band_cells {band}, notices {err.count(NOTICE)} (want 0, 1)")
126 except Exception
as e:
127 check(
False, f
"{label}, 'auto' raised {type(e).__name__}: {e}")
129 def both(t, setup=setup):
131 t.set_vof_viscous_interface(
"sharp")
135 check(
False, f
"{label}, 'sharp': did not raise")
136 except RuntimeError
as e:
137 check(
"set_vof_viscous_interface('sharp')" in str(e), f
"{label}, 'sharp' raises: {e}")
143 x = (np.arange(N) + 0.5) / N
144 X, Y, Z = np.meshgrid(x, x, x, indexing=
"ij")
147 t.set_vof(np.asfortranarray(np.full((N, N, N), 0.5)))
148 for c, A
in enumerate((Y, Z, X)):
149 t.set_velocity(c, np.asfortranarray(0.01 * np.sin(2.0 * np.pi * A)))
150 t.set_vof_viscous_interface(m)
153 for m
in (
"auto",
"averaged"):
154 t =
build(pf, setup=
lambda u, m=m: mixture(u, m))
156 got[m] = (band, b
"".join(np.ascontiguousarray(a).tobytes()
157 for a
in (t.get_u(), t.get_v(), t.get_w(), t.get_p())))
158 check(got[
"auto"][0] == 0
and got[
"auto"][1] == got[
"averaged"][1],
159 f
"uniform mixture C, 'auto': band_cells {got['auto'][0]}, bitwise 'averaged'")
161 band, err =
run(
build(pf, mu1=1.0), 2)
162 check(band == 0
and NOTICE
not in err, f
"uniform mu, 'auto': band_cells {band}, no notice")
164 band, err =
run(
build(pf, vof=
False), 1)
165 check(band == 0
and NOTICE
not in err, f
"no VoF, 'auto': band_cells {band}, no notice")
167 run(
build(pf, vof=
False, setup=
lambda t: t.set_vof_viscous_interface(
"sharp")))
168 check(
False,
"no VoF, 'sharp': did not raise")
169 except RuntimeError
as e:
170 check(
"enable_vof" in str(e), f
"no VoF, 'sharp' raises: {e}")
173 s =
build(pf, cls=pf.SolverColocated)
174 check(s.vof_viscous_interface() ==
"auto",
"SolverColocated default is 'auto'")
175 band, err =
run(s, 2)
176 check(band == 0
and err.count(NOTICE) == 1,
177 f
"SolverColocated, 'auto': band_cells {band}, notices {err.count(NOTICE)} (want 0, 1)")
179 s.set_vof_viscous_interface(
"sharp")
180 check(
False,
"SolverColocated 'sharp' did not raise")
181 except RuntimeError
as e:
182 check(s.vof_viscous_interface() ==
"auto", f
"SolverColocated 'sharp' raises: {e}")
184 print(
"PASS" if not fails
else f
"FAIL ({len(fails)})")
185 return 1
if fails
else 0