flow 1.4.0
Kokkos cut-cell IBM incompressible Navier-Stokes solver + pnm pore extraction
Loading...
Searching...
No Matches
gsv9e.py
Go to the documentation of this file.
1"""G-SV9 (e) (doc/vof_sharp_viscous_stress.md §11, third-pass amendment; WO-6e): the spectral gate.
2
3The Arnoldi spectral radius of the PRODUCTION incremental step map on (u, v, w, p), colour frozen,
4mean of p removed, Chebyshev pressure to rtol 1e-13, RB-GS to an update stop of 1e-13 with the
5residual stop off (coordinator F1, 2026-11-01: 1e-15 sits below the RB-GS round-off floor at
6D_hi 1e4 and hits the sweep cap; the linearity check certifies the stop):
7`gsv9_split.py prod --incremental --pdriver cheb --mom-tol 1e-13`, one process per run.
8Cases: the (b) plane (n(22.5, 22.5), offset 0.3, walls, exact fractions) at N = 16 and the (d)
9film at N = 12, each with the four ratio pairs x D_hi in {0.1, 1, 10, 100, 1e4}, both modes.
10PASS: rho <= 1 + 1e-9 for every 'sharp' run; 'averaged' is reported. A run whose linearity check
11exceeds 1e-10, or whose solves cap (pressure 20000, momentum 200000 sweeps), is NOT JUDGED.
12
13FIFTH PASS (§6.8 A, WO-A5; USER Q24 pending, default adopted) supersedes the momentum half above:
14the momentum runs a FIXED N_A = 2000 RB-GS sweeps per component (`--mom-fixed 2000`, update and
15residual stops off), and the momentum cap test is replaced by the doubling certificate printed on the
16PROD line (dbl_u, dbl_p <= 1e-12 on x1 and x_s); a failure reruns the case at 2 N_A once, a second
17failure is NOT JUDGED. The pressure half stays (max_p_it >= 20000 -> NOT JUDGED). Order: plane, then film.
18ARPACK: ncv 40, maxiter 1000; an unconverged run is re-run at ncv 80; a 'sharp' run still
19unconverged is decided by its (b)/(d) march verdict and listed (UNCONVERGED).
20
21 nice -n 10 python gsv9e.py [--procs 10] [--build BUILD_DIR] [--pilot] (one line per run + a verdict)
22--pilot runs only the stiffest case (plane, D_hi 1e4, mu 1e-3 / rho 1e-4, sharp); linearity
23> 1e-10 there stops the table (coordinator, 2026-11-01).
24The momentum cap test is conservative: 'momentum_sweeps' is summed over the three components.
25"""
26import argparse
27import os
28import re
29import subprocess
30import sys
31from multiprocessing.pool import ThreadPool
32
33HERE = os.path.dirname(os.path.abspath(__file__))
34PAIRS = ((1e-2, 1e-3), (1e2, 1e3), (1e-3, 1e-4), (1e3, 1e4))
35DS = (0.1, 1.0, 10.0, 100.0, 1e4)
36GEOMS = (("plane", 16), ("film", 12))
37PCAP = 20000 # the pressure half of the cap test (the momentum half: the doubling certificate)
38N_A, DBL = 2000, 1e-12 # WO-A5: fixed RB-GS sweeps per component; the doubling certificate's bound
39RX = re.compile(r"\| rho=(\S+) \|.*max_pcg_it=(\d+) lin=(\S+) .*conv=(\d) ncv=(\d+) max_momentum_sweeps=(\d+)"
40 r" dbl_u=(\S+) dbl_p=(\S+) mom_fixed=(\d+) cpu_per_mv=(\S+)")
41
42
43def prod(geom, N, mode, mu, rho, D, ncv, env, nfix=N_A):
44 cmd = [sys.executable, os.path.join(HERE, "gsv9_split.py"), "prod", "--geom", geom, "--N", str(N),
45 "--mode", mode, "--pair", f"{mu:g},{rho:g}", "--D", f"{D:g}", "--incremental", "--pdriver", "cheb",
46 "--ncv", str(ncv), "--maxiter", "1000", "--mom-fixed", str(nfix)]
47 out = subprocess.run(cmd, capture_output=True, text=True, env=env)
48 line = next((x for x in out.stdout.splitlines() if x.startswith("PROD")), None)
49 if line is None:
50 return None, (out.stderr.strip().splitlines() or ["no output"])[-1][:160]
51 m = RX.search(line)
52 return dict(rho=float(m.group(1)), pit=int(m.group(2)), lin=float(m.group(3)), conv=int(m.group(4)),
53 ncv=int(m.group(5)), msw=int(m.group(6)), du=float(m.group(7)), dp=float(m.group(8)),
54 nfix=int(m.group(9)), cpu=float(m.group(10))), line
55
56
57def run(job):
58 geom, N, mode, mu, rho, D, env = job
59 nfix = N_A
60 r, line = prod(geom, N, mode, mu, rho, D, 40, env, nfix)
61 if r is not None and max(r["du"], r["dp"]) > DBL: # doubling failed: rerun once at 2 N_A
62 nfix = 2 * N_A
63 r, line = prod(geom, N, mode, mu, rho, D, 40, env, nfix)
64 dbl_ok = r is not None and max(r["du"], r["dp"]) <= DBL
65 if r is not None and dbl_ok and not r["conv"]:
66 r, line = prod(geom, N, mode, mu, rho, D, 80, env, nfix)
67 tag = f"GSV9e {mode:8s} geom={geom} N={N} mu={mu:g} rho={rho:g} D_hi={D:g}"
68 if r is None:
69 return tag, "ERROR", line
70 capped = r["pit"] >= PCAP # the momentum half is the doubling certificate (WO-A5)
71 if r["lin"] > 1e-10 or capped or not dbl_ok:
72 v = "NOT_JUDGED"
73 elif not r["conv"]:
74 v = "UNCONVERGED"
75 else:
76 v = "PASS" if r["rho"] <= 1.0 + 1e-9 else "MISS"
77 return tag, v, (f"rho={r['rho']:.6f} lin={r['lin']:.1e} ncv={r['ncv']} conv={r['conv']} "
78 f"max_p_it={r['pit']} max_momentum_sweeps={r['msw']} dbl_u={r['du']:.1e} dbl_p={r['dp']:.1e} "
79 f"N_A={r['nfix']} cpu_per_mv={r['cpu']:.3f}")
80
81
82def main():
83 p = argparse.ArgumentParser()
84 p.add_argument("--procs", type=int, default=10)
85 p.add_argument("--build", default=os.environ.get("PYTHONPATH", ""))
86 p.add_argument("--pilot", action="store_true")
87 a = p.parse_args()
88 env = dict(os.environ, PYTHONPATH=a.build, OMP_NUM_THREADS="1", OMP_PROC_BIND="false")
89 jobs = [(g, N, m, mu, r, D, env) for (g, N) in GEOMS for m in ("sharp", "averaged")
90 for (mu, r) in PAIRS for D in DS]
91 if a.pilot:
92 jobs = [j for j in jobs if j[:6] == ("plane", 16, "sharp", 1e-3, 1e-4, 1e4)]
93 res = []
94 with ThreadPool(a.procs) as pool:
95 for tag, v, info in pool.imap_unordered(run, jobs):
96 print(f"{tag} {v} {info}", flush=True)
97 res.append((tag, v))
98 sh = [v for t, v in res if "sharp" in t]
99 av = [v for t, v in res if "averaged" in t]
100 cnt = lambda L, k: sum(1 for v in L if v == k)
101 if cnt(sh, "MISS"):
102 verdict = "MISS"
103 elif cnt(sh, "PASS") == len(sh):
104 verdict = "PASS"
105 else:
106 verdict = "NOT_JUDGED/UNCONVERGED-listed"
107 print(f"GSV9e {verdict} sharp: {cnt(sh, 'PASS')} PASS, {cnt(sh, 'MISS')} MISS, {cnt(sh, 'NOT_JUDGED')} NOT_JUDGED, "
108 f"{cnt(sh, 'UNCONVERGED')} UNCONVERGED, {cnt(sh, 'ERROR')} ERROR of {len(sh)}; averaged (reported): "
109 f"{cnt(av, 'PASS')} <=1+1e-9, {cnt(av, 'MISS')} above, {len(av) - cnt(av, 'PASS') - cnt(av, 'MISS')} other")
110 return 0 if verdict == "PASS" else 1
111
112
113if __name__ == "__main__":
114 sys.exit(main())
prod(geom, N, mode, mu, rho, D, ncv, env, nfix=N_A)
Definition gsv9e.py:43
main()
Definition gsv9e.py:82
run(job)
Definition gsv9e.py:57