test: shear-wave row validation, controlled-pass semantics, bounds
- shear_wave: validate_rows before screens (exact scheduled steps/t*, no duplicates, all numeric/list fields finite, nonnegative error fields, rho_min>0; signed amplitude/phase/interval errors keep their sign); INVALID_RUN for invalid refined rows; own_screens_pass vs controlled_pass so a CONTROL_SCREEN_FAIL set never reports a controlled pass; empty or duplicate refined schemes rejected; pressure-budget redundancy stated. - run_case: SHEAR_WAVE_SHA256 repinned to the updated module. - tests: divergence/advection bounds use a(t) and the derived h^2 term; invalid-row mutations; signed errors allowed; controlled_pass checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3554cb2fde
commit
f337652683
4 files changed
+132
-32
No files matched your search
@@ -85,11 +85,13 @@ class ConventionTests(unittest.TestCase):
|
||||
# Central differences do not cancel exactly: each derivative carries
|
||||
# -(k_j h)^2/6 relative truncation, so div_h = -A cos(theta) h^2/6 sum_j E_j k_j^3
|
||||
# + O(h^4) (nonzero for an oblique k). Bound it with that leading term plus roundoff.
|
||||
trunc = U * h * h / 6 * float(np.abs(sw.E * k**3).sum()) * 1.01
|
||||
a = U * math.exp(-sw.decay_rate(N, NU) * t)
|
||||
trunc = a * h * h / 6 * float(np.abs(sw.E * k**3).sum()) * 1.01
|
||||
# Argument rounding: eps*max|x|/h*U*|k| ~ 2.2e-16*21.6/1e-3*0.03*0.44 ~ 6e-14.
|
||||
roundoff = 1e-13
|
||||
self.assertLess(np.max(np.abs(dx[0] + dy[1])), trunc + roundoff)
|
||||
self.assertLess(np.max(np.abs(z[0] * dx + z[1] * dy)), U * trunc + roundoff)
|
||||
# Discrete advection: same truncation scaled by |u| <= a.
|
||||
self.assertLess(np.max(np.abs(z[0] * dx + z[1] * dy)), a * trunc + roundoff)
|
||||
# Halving h reduces the divergence truncation about fourfold.
|
||||
hh = h / 2
|
||||
div2 = ((f(x + hh, y, t) - f(x - hh, y, t))[0] + (f(x, y + hh, t) - f(x, y - hh, t))[1]) / (2 * hh)
|
||||
@@ -206,6 +208,8 @@ class MetricTests(unittest.TestCase):
|
||||
|
||||
|
||||
def record(n, depth, rows, explosion="constant", completed=True, source="s"):
|
||||
for row in rows:
|
||||
row["spurious_pressure_scaled_by_level"] = [row["spurious_pressure_scaled"]] * depth
|
||||
return dict(n=n, depth=depth, viscosity=U * n / sw.RE, rows=rows, completed=completed,
|
||||
explosion=explosion, source=source)
|
||||
|
||||
@@ -215,7 +219,11 @@ def rows_for(n, rate_error=0.0, residual=1e-4, pressure=1e-3, phase=0.0):
|
||||
out = []
|
||||
for tstar in TIMES:
|
||||
step = round(tstar * n / U)
|
||||
out.append(dict(tstar=tstar, step=step, a_hat=U * math.exp(-rate * step), b_hat=0.0,
|
||||
amp = U * math.exp(-rate * step)
|
||||
out.append(dict(tstar=step * U / n, step=step, a_hat=amp, b_hat=0.0,
|
||||
amplitude_ratio=1.0, modal_amplitude=amp, amplitude_exact=amp,
|
||||
phase_drift=phase, mass=float(n * n), rho_min=0.999, rho_max=1.001,
|
||||
max_speed=amp, longitudinal_l2=0.0, spurious_pressure_max_scaled=pressure,
|
||||
amplitude_error=0.0, residual_l2=residual, phase_drift_abs=phase,
|
||||
spurious_pressure_scaled=pressure,
|
||||
spurious_pressure_rms=pressure * U * U / 4,
|
||||
@@ -245,7 +253,9 @@ class AssessTests(unittest.TestCase):
|
||||
failing = record(128, 1, rows_for(128, residual=0.5)) # complete, > eps(128)
|
||||
report = sw.assess(failing, fine, [refined])
|
||||
self.assertEqual(report["status"], "CONTROL_SCREEN_FAIL")
|
||||
self.assertIn("constant", report["refined"]) # refined results preserved
|
||||
own = report["refined"]["constant"]
|
||||
self.assertTrue(own["own_screens_pass"]) # refined own screens kept
|
||||
self.assertFalse(own["controlled_pass"]) # but no controlled comparison passes
|
||||
good = record(128, 1, rows_for(128))
|
||||
self.assertEqual(sw.assess(None, fine, [refined])["status"], "INVALID_CONTROL")
|
||||
incomplete = record(128, 1, rows_for(128), completed=False)
|
||||
@@ -253,6 +263,29 @@ class AssessTests(unittest.TestCase):
|
||||
mixed = record(256, 1, rows_for(256), source="other")
|
||||
self.assertEqual(sw.assess(good, mixed, [refined])["status"], "INVALID_CONTROL")
|
||||
|
||||
def test_invalid_rows_are_rejected_before_screens(self):
|
||||
base = record(128, 1, rows_for(128))
|
||||
fine = record(256, 1, rows_for(256))
|
||||
for mutate in (
|
||||
lambda rows: rows[2].update(rho_min=float("nan")),
|
||||
lambda rows: rows[2].update(spurious_pressure_scaled_by_level=[0.0, float("nan")]),
|
||||
lambda rows: rows[2].update(step=rows[1]["step"], tstar=rows[1]["tstar"]),
|
||||
lambda rows: rows[2].update(residual_l2=-1e-6),
|
||||
lambda rows: rows[2].pop("longitudinal_l2"),
|
||||
):
|
||||
refined = record(128, 2, rows_for(128))
|
||||
mutate(refined["rows"])
|
||||
self.assertEqual(sw.assess(base, fine, [refined])["status"], "INVALID_RUN")
|
||||
# Legitimate signs stay allowed: negative amplitude and phase errors.
|
||||
refined = record(128, 2, rows_for(128))
|
||||
for row in refined["rows"]:
|
||||
row.update(amplitude_error=-1e-3, phase_drift=-1e-4, phase_drift_abs=1e-4)
|
||||
report = sw.assess(base, fine, [refined])
|
||||
self.assertEqual(report["status"], "PASS")
|
||||
self.assertEqual(sw.assess(base, fine, [])["status"], "INVALID_CONTROL")
|
||||
with self.assertRaises(ValueError):
|
||||
sw.assess(base, fine, [record(128, 2, rows_for(128)), record(128, 2, rows_for(128))])
|
||||
|
||||
def test_wrong_shapes(self):
|
||||
base = record(128, 1, rows_for(128))
|
||||
fine = record(256, 1, rows_for(256))
|
||||
@@ -307,7 +340,8 @@ def receipt(n, depth, explosion="constant"):
|
||||
steps = run_case.sample_steps(n)[0]
|
||||
rows = rows_for(n)
|
||||
for row, step in zip(rows, steps):
|
||||
row.update(step=step, tstar=step * U / n)
|
||||
row.update(step=step, tstar=step * U / n,
|
||||
spurious_pressure_scaled_by_level=[row["spurious_pressure_scaled"]] * depth)
|
||||
cells = [n * n] if depth == 1 else [8704, 30720]
|
||||
hops = [16 * n * 2**level for level in range(depth)]
|
||||
builds = []
|
||||
|
||||
Reference in new issue
Block a user