#!/usr/bin/env python3 """0029: check our independent grid and trapz cell law against the reference engine's own `outward_dickman_grid` / `CapEngine.survival` values recorded in `0029_probe_survival.py`.""" import importlib.util import sys from pathlib import Path HERE = Path(__file__).resolve().parent sys.path.insert(0, str(HERE)) spec = importlib.util.spec_from_file_location("asm0029", HERE / "0029_assembly.py") ASM = importlib.util.module_from_spec(spec) spec.loader.exec_module(ASM) # values printed by 0029_probe_survival.py (reference engine, arb) REF_GRID = {68225: 1.0, 68226: 0.999985342724, 68227: 0.999970685662, 68325: 0.99853533478, 98262: 0.635173685889} REF_SURV = {68225: 0.999992671344, 68226: 0.999978014175, 68227: 0.999963357221, 68325: 0.99852801685, 98262: 0.63516859746} lo, hi = ASM.build_grid(68225) law = ASM.cell_law("trapz", 68225, lo, hi) print("%8s %18s %18s %10s | %18s %18s %10s" % ( "j", "grid.lower (ours)", "grid.lower (ref)", "rel.dev", "trapz (ours)", "survival (ref)", "rel.dev")) worst = 0.0 for j in sorted(REF_GRID): a = float(lo[j]) b = REF_GRID[j] c = float(law[j]) d = REF_SURV[j] ra = abs(a - b) / abs(b) rc = abs(c - d) / abs(d) worst = max(worst, ra, rc) print("%8d %18.12g %18.12g %10.2g | %18.12g %18.12g %10.2g" % (j, a, b, ra, c, d, rc)) print() print("worst relative deviation from the reference engine: %.3g" % worst)