1"""G-SV9(f), the onset (doc/vof_sharp_viscous_stress.md §6.5, WO-6f; reported, not gated).
3The (b') periodic twin (m = (2,1,1), two plane families per period, N = 16) at
4D_hi in {0.1, 0.3, 1, 3, 10, 30, 100}, both modes, the four G-SV9 ratio pairs, layer fraction 0.5 and
50.75, measured two ways:
6 march : gsv9.py --geom pplane (the production default solve, 2000 steps), judged on E' (the
7 energy with the three translations removed, WO-6a') over windows with E_n >= 1e-20 E_0
8 (USER Q15); a run is unstable iff that verdict is MISS (blow-up included).
9 arnoldi : gsv9_split.py prod --geom pplane with the WO-6a' translation deflation, the E1/E5 setting
10 of §6.5 (production u-only map, non-incremental, RB-GS update stop 1e-12 with the
11 residual stop off, Chebyshev 1e-13, k 6, ncv 40, maxiter 1000); unstable iff
12 rho > 1 + 1e-9 (the G-SV9(e) threshold). Linearity and ARPACK convergence are printed;
13 lin > 1e-10 or conv = 0 is flagged.
14Table: the smallest unstable D_hi per mode x pair x frac, for each measure. STOP rule (§6.5):
15'sharp' unstable at D_hi <= 3 on any case where 'averaged' is stable -> architect.
17 nice -n 10 python gsv9f.py arnoldi --out DIR [--procs 3] (resumable: one file per case)
18 python gsv9f.py table --march DIR --arnoldi DIR (march files: DIR/march_<mode>_f<frac>.out)
26from concurrent.futures
import ThreadPoolExecutor
28HERE = os.path.dirname(os.path.abspath(__file__))
29DS = (0.1, 0.3, 1.0, 3.0, 10.0, 30.0, 100.0)
30PAIRS = ((1e-2, 1e-3), (1e2, 1e3), (1e-3, 1e-4), (1e3, 1e4))
32MODES = (
"sharp",
"averaged")
33ARN = [
"prod",
"--geom",
"pplane",
"--N",
"16",
"--pdriver",
"cheb",
"--mom-tol",
"1e-12",
"--k",
"6",
34 "--ncv",
"40",
"--maxiter",
"1000"]
43 return f
"arn_{mode}_mu{pair[0]:g}_rho{pair[1]:g}_D{D:g}_f{frac:g}.out"
47 out, mode, pair, D, frac = job
48 path = os.path.join(out,
cname(mode, pair, D, frac))
49 if os.path.exists(path)
and any(ln.startswith(
"PROD")
for ln
in lines(path)):
51 cmd = [sys.executable, os.path.join(HERE,
"gsv9_split.py")] + ARN + [
52 "--mode", mode,
"--pair", f
"{pair[0]:g},{pair[1]:g}",
"--D", f
"{D:g}",
"--frac", f
"{frac:g}"]
53 with open(path,
"w")
as f:
54 rc = subprocess.call(cmd, stdout=f, stderr=subprocess.STDOUT, cwd=HERE)
55 return path, f
"rc={rc}"
59 os.makedirs(a.out, exist_ok=
True)
61 jobs = [(a.out, m, p, d, f)
for d
in DS
for f
in FRACS
for m
in MODES
for p
in PAIRS]
62 with ThreadPoolExecutor(a.procs)
as ex:
63 for path, st
in ex.map(one, jobs):
64 ln = [x
for x
in lines(path)
if x.startswith(
"PROD")]
65 print(f
"GSV9F-ARN {os.path.basename(path)} {st} " + (ln[0].split(
"|")[1].strip()
if ln
else "NO PROD LINE"),
67 print(
"EXIT", flush=
True)
72 for path
in glob.glob(os.path.join(d,
"march_*_f*.out")):
73 mode, frac = re.match(
r"march_(\w+?)_f([0-9.]+)\.out", os.path.basename(path)).groups()
74 for ln
in lines(path):
75 m = re.match(
r"GSV9b'(-AVG)? (\S+) geom=pplane muA/muB=(\S+) rhoA/rhoB=(\S+) D_hi=(\S+)", ln)
79 fl = v.split(
"/")[1]
if "/" in v
else v
80 res[(mode, (float(m.group(3)), float(m.group(4))), float(m.group(5)), float(frac))] = fl
85 """gsv9.py prints mu_A/mu_B of its own normalisation; map to the PAIRS entry."""
87 if abs(p[0] - muR) <= 1e-9 * p[0]
and abs(p[1] - rhoR) <= 1e-9 * p[1]:
98 path = os.path.join(d,
cname(mode, p, D, f))
99 if not os.path.exists(path):
101 for ln
in lines(path):
102 if ln.startswith(
"PROD"):
103 rho = float(re.search(
r"\| rho=(\S+)", ln).group(1))
104 lin = float(re.search(
r"lin=(\S+)", ln).group(1))
105 conv = int(re.search(
r"conv=(\d)", ln).group(1))
106 res[(mode, p, D, f)] = (rho, lin, conv)
113 for k, v
in sorted(ar.items(), key=
lambda kv: (kv[0][0], kv[0][1], kv[0][3], kv[0][2])):
114 print(f
"GSV9F-CASE arnoldi {k[0]} mu={k[1][0]:g} rho={k[1][1]:g} frac={k[3]:g} D_hi={k[2]:g} "
115 f
"rho={v[0]:.6f} lin={v[1]:.1e} conv={v[2]} march={mr.get(k, '-')}")
117 def onset(get, mode, p, f):
118 miss = [D
for D
in DS
if get(mode, p, D, f)
is None]
119 uns = [D
for D
in DS
if get(mode, p, D, f)
is True]
120 return (min(uns)
if uns
else None), miss
122 gm =
lambda mo, p, D, f: (
None if (mo, p, D, f)
not in mr
else mr[(mo, p, D, f)] !=
"PASS")
123 ga =
lambda mo, p, D, f: (
None if (mo, p, D, f)
not in ar
else ar[(mo, p, D, f)][0] > 1.0 + 1e-9)
125 print(
"GSV9F-TABLE smallest unstable D_hi (march: E' floor-excluded MISS; arnoldi: rho > 1+1e-9); "
126 "'none' = stable at every D_hi run; [missing D]")
131 for nm, g
in ((
"march", gm), (
"arnoldi", ga)):
132 o, miss = onset(g, mo, p, f)
133 cells.append(f
"{mo}/{nm}={'none' if o is None else f'{o:g}'}" + (f
"[{','.join(f'{x:g}' for x in miss)}]" if miss
else ""))
134 print(f
"GSV9F-ONSET frac={f:g} mu={p[0]:g} rho={p[1]:g} " +
" ".join(cells))
135 for nm, g
in ((
"march", gm), (
"arnoldi", ga)):
137 if D <= 3.0
and g(
"sharp", p, D, f)
is True and g(
"averaged", p, D, f)
is False:
138 stop.append(f
"{nm} frac={f:g} mu={p[0]:g} rho={p[1]:g} D_hi={D:g}")
139 full = len(DS) * len(PAIRS) * len(FRACS) * len(MODES)
140 print(f
"GSV9F-STOPRULE {'STOP (architect): ' + '; '.join(stop) if stop else 'clear'} "
141 f
"(march {len(mr)}/{full}, arnoldi {len(ar)}/{full} cases)")
145 p = argparse.ArgumentParser()
146 sp = p.add_subparsers(dest=
"cmd", required=
True)
147 r = sp.add_parser(
"arnoldi")
148 r.add_argument(
"--out", required=
True)
149 r.add_argument(
"--procs", type=int, default=3)
150 t = sp.add_parser(
"table")
151 t.add_argument(
"--march", required=
True)
152 t.add_argument(
"--arnoldi", required=
True)
157if __name__ ==
"__main__":
cname(mode, pair, D, frac)