flow 1.3.0
Kokkos cut-cell IBM incompressible Navier-Stokes solver + pnm pore extraction
Loading...
Searching...
No Matches
cmp.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2"""Compare two prof.py --dump files array by array (the VoF step-performance harness, WO-0).
3
4Usage: python tests/study/vof_perf/cmp.py a.npz b.npz
5
6One line per array (u, v, w, p, C, dts, iters, and every block colour col<id>): bitwise
7equality, max|a-b| and max|a-b|/max|a|. An array present in only one file prints bitwise=False.
8The last line is max over u, v, w, p, C of the relative difference -- N50_rtol when a is the
9rtol 1e-10 dump and b the 1e-9 one (doc/vof_step_performance_design.md sec. 8, G-NUM item 1).
10Exit status 0 only if every array is bitwise equal (G-BIT item 2), 1 otherwise.
11"""
12import sys
13
14import numpy as np
15
16a, b = np.load(sys.argv[1]), np.load(sys.argv[2])
17all_same = True
18worst = 0.0
19for k in list(a.files) + [k for k in b.files if k not in a.files]:
20 if k not in a.files or k not in b.files:
21 print(f"{k:4s} bitwise=False only in {'b' if k in b.files else 'a'}")
22 all_same = False
23 continue
24 x, y = a[k], b[k]
25 same = x.shape == y.shape and x.dtype == y.dtype and x.tobytes() == y.tobytes() # bytes: -0/NaN
26 d = float(np.max(np.abs(x.astype(np.float64) - y))) if x.shape == y.shape else float('nan')
27 sc = float(np.max(np.abs(x))) or 1.0
28 print(f"{k:4s} bitwise={same} max|diff|={d:.3e} rel={d/sc:.3e}")
29 all_same = all_same and same
30 if k in ("u", "v", "w", "p", "C"):
31 worst = max(worst, d / sc)
32print(f"max rel over u v w p C = {worst:.3e} all bitwise={all_same}")
33sys.exit(0 if all_same else 1)