2"""Profile the bubble-column step from a checkpoint (the VoF step-performance harness, WO-0).
4The case is the bubble column of peclet-examples (128 x 96 x 64, 16 VoF block markers, rho/mu
5ratio 0.02, set_superficial_velocity), built by that repo's run_peclet.build() and restarted from
6ckpt_t43.npz. It runs W warm-up steps (not timed), then N timed steps with the driver's per-step
7protocol (dt = 0.25 min(cfl_dt, capillary_dt) from vof_step_limits()). See
8doc/vof_step_performance_design.md (sec. 7 WO-0, sec. 8 G-BIT / G-NUM / G-PERF).
11 PYTHONPATH=<flow build> OMP_NUM_THREADS=8 OMP_PROC_BIND=false \\
12 python tests/study/vof_perf/prof.py N [--pcg [--rtol R]] [--timing] [--dump out.npz]
13 [--warm W] [--flux device|python|none] [--levels L] [--bottom MODE] [--fixdt DT]
14 [--ckpt PATH] [--case-dir DIR] [--dummy N]
16 --ckpt checkpoint (default ~/Codes/bubble_column_perf/ckpt_t43.npz)
17 --case-dir directory holding run_peclet.py + case.py (default:
18 ~/Codes/peclet-examples/benchmarks/bubble-column/scripts)
19 --pcg MG-PCG pressure with cap 800 and relative tolerance --rtol (default 1e-10)
20 --cheb Chebyshev pressure (cap --cheb-maxit, default 120) at --rtol; prints the
21 solver's num_pressure_chebyshev_restarts when the build has it (D3, §5.13)
22 --dump save u, v, w, p, C, the timed steps' dt and pressure iterations (iters) and every
23 VoF block's colour array (col<id>) -- compare two dumps with cmp.py (G-BIT item 2)
24 --timing per-stage breakdown from diagnostics.vof_timing()
25 --levels L pressure multigrid depth; --bottom MODE = set_pressure_bottom(MODE) (E1)
26 --bottom-solver ENGINE diagnostics.set_pressure_bottom_solver(ENGINE): auto | direct |
27 algebraic (§13: the A/B of the two bottom engines on one build)
28 --div with --dump: also store each timed step's max_open_divergence_projected() (div),
29 read after the step (G-NUM item 3)
30 --stats with --dump: also store every timed step's measured block statistics (st_volume,
31 st_area, st_centroid, st_velocity, st_moments; WO-9's gate, C2 §5.10)
42def arg(name, default, cast=str):
43 return cast(A[
A.index(name) + 1])
if name
in A
else default
47 "~/Codes/peclet-examples/benchmarks/bubble-column/scripts"))
49 "~/Codes/bubble_column_perf/ckpt_t43.npz"))
51import run_peclet
as rp
54TIMING =
"--timing" in A
55FLUX =
arg(
"--flux",
"python")
56DUMP =
arg(
"--dump",
None)
57WARM =
arg(
"--warm", 5, int)
58FIXDT =
arg(
"--fixdt",
None, float)
59RTOL =
arg(
"--rtol", 1e-10, float)
68 _L =
arg(
"--levels", 4, int)
85for _name
in (
"set_superficial_velocity",
"set_bulk_velocity"):
87 getattr(s, _name)(FLUX ==
"device",
"x", 0.0)
95if "--bottom-solver" in A:
100stats = {k: []
for k
in (
"volume",
"area",
"centroid",
"velocity",
"moments")}
101print(f
"build {time.time()-t_b:.2f} s", flush=
True)
106T = {
"limits": 0.0,
"step": 0.0,
"flux": 0.0}
116 dt =
min(dtsafe * L[
"cfl_dt"], dtsafe * L[
"capillary_dt"])
126 T[
"limits"] += t1 - t0
135 stats[k].
append([b[k]
for b
in st])
147print(f
"steps {N} wall {wall:.3f} s {1000*wall/N:.2f} ms/step dt mean {np.mean(dts):.3e}")
148print(
"per-step ms: " +
" ".
join(f
"{k} {1000*v/N:.2f}" for k, v
in T.items()))
149print(f
"pressure iters mean {np.mean(iters):.2f} min {min(iters)} max {max(iters)}")
151 print(f
"chebyshev restarts {s.diagnostics.num_pressure_chebyshev_restarts}")
155 print(
"vof_timing per step ms (steps=%d):" % n)
157 if k
in (
"steps",
"k_sweeps",
"kc_calls"):
160 print(f
" {k:22s} {1000*x/n:8.3f}")
166 **({
"div":
np.array(divs)}
if DIV
else {}),
168 print(
"dumped", DUMP, f
"({len(cols)} block colours)")
arg(name, default, cast=str)