53PAIRS = ((1e-2, 1e-3), (1e2, 1e3), (1e-3, 1e-4), (1e3, 1e4))
54DS = (0.1, 1.0, 10.0, 100.0, 1e4)
58 off = (np.arange(sub) + 0.5) / sub
59 g = (np.arange(n)[:,
None] + off[
None, :]).ravel()
60 out = np.zeros((n, n, n))
62 X, Y, Z = np.meshgrid(g, g, k + off, indexing=
"ij")
63 ins = (nrm[0] * (X - x0[0]) + nrm[1] * (Y - x0[1]) + nrm[2] * (Z - x0[2]) < 0).astype(np.float64)
64 out[:, :, k] = ins.reshape(n, sub, n, sub, sub).
mean(axis=(1, 3, 4))
65 return np.asfortranarray(out)
70 from gsv1
import layered_fractions
71 m = np.array((2.0, 1.0, 1.0))
72 nrm = m / np.linalg.norm(m)
73 P = 1.0 / float(np.linalg.norm(m))
74 s0 = float(nrm @ np.full(3, 0.5)) + 0.3 / N
75 return np.asfortranarray(layered_fractions(nrm, s0, P, frac * P, 0.0, N))
77 b = g = math.radians(22.5)
78 nrm = (math.cos(b) * math.cos(g), math.cos(b) * math.sin(g), math.sin(b))
80 C = np.zeros((N, N, N))
if lowA
else np.ones((N, N, N))
81 C[N // 2, :, :] = 1.0
if lowA
else 0.0
82 return np.asfortranarray(C)
86 """u = curl(psi) on the MAC grid, psi on edges, zero on every wall edge (index units)."""
87 r = np.random.default_rng(seed)
88 px = r.standard_normal((N, N + 1, N + 1))
89 py = r.standard_normal((N + 1, N, N + 1))
90 pz = r.standard_normal((N + 1, N + 1, N))
91 px[:, [0, N], :] = 0.0; px[:, :, [0, N]] = 0.0
92 py[[0, N], :, :] = 0.0; py[:, :, [0, N]] = 0.0
93 pz[[0, N], :, :] = 0.0; pz[:, [0, N], :] = 0.0
94 u = (pz[:, 1:, :] - pz[:, :-1, :]) - (py[:, :, 1:] - py[:, :, :-1])
95 v = (px[:, :, 1:] - px[:, :, :-1]) - (pz[1:, :, :] - pz[:-1, :, :])
96 w = (py[1:, :, :] - py[:-1, :, :]) - (px[:, 1:, :] - px[:, :-1, :])
97 div = (u[1:] - u[:-1]) + (v[:, 1:] - v[:, :-1]) + (w[:, :, 1:] - w[:, :, :-1])
98 assert np.max(np.abs(div)) < 1e-12
and not u[0].any()
and not u[N].any()
99 return u[:N], v[:, :N], w[:, :, :N]
103 """u = curl(psi) on the periodic MAC grid (index units): psi_x at (i+1/2, j, k), psi_y at
104 (i, j+1/2, k), psi_z at (i, j, k+1/2); face c index i is the -c face of cell i."""
105 r = np.random.default_rng(seed)
106 px, py, pz = (r.standard_normal((N, N, N))
for _
in range(3))
107 d =
lambda a, ax: np.roll(a, -1, axis=ax) - a
108 u = d(pz, 1) - d(py, 2)
109 v = d(px, 2) - d(pz, 0)
110 w = d(py, 0) - d(px, 1)
111 div = d(u, 0) + d(v, 1) + d(w, 2)
112 assert np.max(np.abs(div)) < 1e-12
146 geom, muR, rhoR, Dn, mode, frac = args
149 muA, muB = (muR, 1.0)
if lowA
else (1.0, 1.0 / muR)
150 rA, rB = (rhoR, 1.0)
if lowA
else (1.0, 1.0 / rhoR)
153 s =
pf.Solver((N, N, N), extent=(1.0, 1.0, 1.0))
155 for f
in (
"-x",
"+x",
"-y",
"+y",
"-z",
"+z"):
156 s.set_domain_bc(f,
"periodic" if geom ==
"pplane" else "wall")
159 s.set_pressure_geometry(np.full((N, N, N), 1.0, order=
"F"))
161 C0 =
colour(geom, lowA, frac)
163 s.set_property_model(
"mu",
"linear",
"C", [muB, muA - muB])
164 s.set_property_model(
"rho",
"linear",
"C", [rB, rA - rB])
165 s.set_advection(
False)
167 s.set_pressure_chebyshev(
True, PCAP, PRTOL)
168 s.set_vof_viscous_interface(mode)
169 rho = rB + (rA - rB) * C0
172 u, v, w = (a - float(np.sum(rf * a)) / float(np.sum(rf))
for a, rf
in zip((u, v, w),
rho_face_periodic(rho)))
173 en = energy_periodic_deflated
177 amp = 1e-3 * h / (dt * max(np.max(np.abs(a))
for a
in (u, v, w)))
178 for c, a
in enumerate((u, v, w)):
179 s.set_velocity(c, np.asfortranarray(amp * a))
180 E = [en([s.get_u(), s.get_v(), s.get_w()], rho)]
181 Efull = [
energy_periodic([s.get_u(), s.get_v(), s.get_w()], rho)]
if geom ==
"pplane" else None
182 cen = {
"band_cells": 0,
"virtual_cells": 0,
"film_cells": 0,
"fit_fallbacks": 0}
188 for n
in range(STEPS):
191 except RuntimeError
as ex:
192 blow = f
"step {n + 1}: {str(ex)[:60]}"
195 pit = s.diagnostics.last_pressure_iterations()
196 pmax = max(pmax, pit)
199 first_cap = n + 1
if first_cap
is None else first_cap
201 c = s.diagnostics.vof_viscous_interface_census()
205 vel = [s.get_u(), s.get_v(), s.get_w()]
206 E.append(en(vel, rho))
207 if Efull
is not None:
211 if Efull
is not None:
213 lo_ = min(200, max(len(Ef) - 101, 0))
214 wf = Ef[lo_ + 100:] / Ef[lo_:-100]
if len(Ef) > 101
else np.array([np.nan])
215 rep = (f
"[judged E'=E-translations; reported E: E_end/E0={Ef[-1] / Ef[0]:.6f} "
216 f
"max E(n+100)/E(n)={float(np.max(wf)):.6f}] frac={frac:g} ")
217 up = np.nonzero(E[1:] > E[:-1])[0]
218 first_grow = int(up[0]) + 1
if up.size
else None
219 tag =
"GSV9" + {
"plane":
"b",
"film":
"d",
"pplane":
"b'"}[geom] + (
"" if mode ==
"sharp" else "-AVG")
220 timing = (f
"{rep}pdriver=chebyshev(rtol={PRTOL:g},cap={PCAP}) max_p_it={pmax} capped_steps={capped} "
221 f
"first_cap_step={first_cap} first_energy_growth_step={first_grow} {tie_str(tie)}")
223 return (f
"{tag} NOT_JUDGED geom={geom} muA/muB={muR:g} rhoA/rhoB={rhoR:g} D_hi={Dn:g} "
224 f
"(a capped pressure step) steps_run={len(E) - 1} {timing}",
None,
None)
226 grow = E[1:] / E[:-1]
227 return (f
"{tag} MISS/MISS geom={geom} muA/muB={muR:g} rhoA/rhoB={rhoR:g} "
228 f
"D_hi={Dn:g} BLOWUP at {blow} E_last/E0={E[-1] / E[0]:.3e} min_n E_n/E0={float(np.min(E) / E[0]):.3e} "
229 f
"last-100-step mean growth/step={float(np.exp(np.mean(np.log(grow[-100:])))):.6f} "
230 f
"{timing}",
False,
False)
231 above = int(np.sum(E[1:] > E[0]))
232 lo = min(200, max(len(E) - 101, 0))
233 En, Ew = E[lo:-100], E[lo + 100:]
234 win = Ew / np.where(En > 0, En, np.nan)
235 gmax = float(np.max(win))
if np.all(En > 0)
else float(
"nan")
236 keep = En >= FLOOR * E[0]
237 gfl = float(np.max(win[keep]))
if np.any(keep)
else float(
"nan")
238 gbel = float(np.nanmax(win[~keep]))
if np.any(~keep)
else float(
"nan")
239 ok = above == 0
and gmax <= 1.0 + 1e-10
240 okf = above == 0
and not (gfl > 1.0 + 1e-10)
241 vd =
lambda b:
"PASS" if b
else "MISS"
242 return (f
"{tag} {vd(ok)}/{vd(okf)} geom={geom} "
243 f
"muA/muB={muR:g} rhoA/rhoB={rhoR:g} D_hi={Dn:g} E_end/E0={E[-1] / E[0]:.3e} "
244 f
"max_n E_n/E0={float(np.max(E[1:]) / E[0]):.6f} steps_above_E0={above} "
245 f
"max E(n+100)/E(n),n>=200={gmax:.6f} [E_n>=1e-20E0: {gfl:.6f}, below: {gbel:.6f}] "
246 f
"band/step={cen['band_cells'] / STEPS:.0f} "
247 f
"virt/step={cen['virtual_cells'] / STEPS:.0f} film/step={cen['film_cells'] / STEPS:.0f} "
248 f
"fallbacks={cen['fit_fallbacks']} {timing}", ok, okf)
252 p = argparse.ArgumentParser()
253 p.add_argument(
"--geom", choices=(
"plane",
"film",
"pplane",
"both"), default=
"both")
254 p.add_argument(
"--procs", type=int, default=6)
255 p.add_argument(
"--mode", choices=(
"sharp",
"averaged"), default=
"sharp")
256 p.add_argument(
"--frac", type=float, default=0.5)
257 p.add_argument(
"--D", type=
lambda t: tuple(float(x)
for x
in t.split(
",")), default=DS)
258 p.add_argument(
"--pairs", type=
lambda t: tuple(int(x)
for x
in t.split(
",")), default=
None)
260 geoms = (
"plane",
"film")
if a.geom ==
"both" else (a.geom,)
261 pairs = PAIRS
if a.pairs
is None else tuple(PAIRS[i]
for i
in a.pairs)
262 jobs = [(g, m, r, d, a.mode, a.frac)
for g
in geoms
for (m, r)
in pairs
for d
in a.D]
264 with Pool(a.procs)
as pool:
265 for line, ok, okf
in pool.imap_unordered(run, jobs):
266 print(line, flush=
True)
267 res.append((ok, okf))
268 tag = f
"GSV9{'' if a.mode == 'sharp' else '-AVG'}"
269 nj = sum(1
for ok, _
in res
if ok
is None)
271 for k, nm
in ((0,
"as-written"), (1,
"floor-excluded")):
272 npass = sum(1
for r
in res
if r[k]
is True)
273 verdict =
"PASS" if npass == len(res)
else (
"MISS" if npass + nj < len(res)
else "NOT_JUDGED")
274 rc |= verdict !=
"PASS"
275 print(f
"{tag} {nm} {verdict} {npass}/{len(res)} runs pass, {nj} not judged (geom={a.geom})")
static std::vector< double > slice(const std::vector< double > &g, int ox, int oy, int oz, int lnx, int lny, int lnz)