#!/usr/bin/env python3 """0029: how much do the three cell laws change the per-coordinate mass scale?""" 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) u, t, Z = ASM.coordinate_weights() tot_u = sum(u) print("sum u = %.15g" % float(tot_u)) for cap in (68225, 49152, 46580): lo, hi = ASM.build_grid(cap) S = {} for law in ("trapz", "mean", "double", "exact"): arr = ASM.cell_law(law, cap, lo, hi) S[law] = float(sum(u[j] * arr[j] for j in range(ASM.N_CELLS))) print() print("cap %d (M = %d)" % (cap, cap)) for law in ("trapz", "mean", "double", "exact"): r = S[law] / S["trapz"] print(" %-7s sum u*s = %.15g ratio to trapz %.6g ratio^40-1 = %.6g" % (law, S[law], r, r ** 40 - 1)) # mass of u above the cap above = float(sum(u[j] for j in range(cap, ASM.N_CELLS))) print(" u-mass above the cap: %.6g" % above)