diff --git a/research/viv_re150/run.py b/research/viv_re150/run.py index 81fd790..629de5f 100644 --- a/research/viv_re150/run.py +++ b/research/viv_re150/run.py @@ -96,12 +96,13 @@ def main(): d = sim.moving_diagnostics()[0] f_obs = sim.read_force(body)[1] f_rhs = float(d[1] + d[3]) # CME + Wen (y) - if not math.isfinite(f_rhs): - status = "fail_nonfinite_force" + row = (n, y1, v1, f_rhs, float(d[1]), float(d[3]), float(f_obs), + float(d[7] - d[10]), float(d[13])) + if not viv.finite(row): # every recorded output, not only the RHS + status = "fail_nonfinite_output" break s.y, s.v, f_last = y1, v1, f_rhs # commit only after a successful step - rows.append((n, s.y, s.v, f_rhs, float(d[1]), float(d[3]), float(f_obs), - float(d[7] - d[10]), float(d[13]))) + rows.append(row) if args.smoke: continue # no settle / score in the plumbing smoke if cyc.update(s.y) == "scored": diff --git a/research/viv_re150/viv.py b/research/viv_re150/viv.py index a06ca9f..c8b8d01 100644 --- a/research/viv_re150/viv.py +++ b/research/viv_re150/viv.py @@ -16,6 +16,11 @@ WINDOW_TOL, LAST5_TOL = 0.02, 0.01 CYCLE_CAP, STEP_CAP_TN, SEED_TN, Y_LIMIT = 150, 200, 40, 1.0 +def finite(values): + """True iff every recorded value is finite (fail-closed output check).""" + return all(math.isfinite(float(v)) for v in values) + + class Structure: """Undamped spring-mass, exact harmonic update over dt = 1 with constant force.""" diff --git a/tests/unit/test_viv_logic.py b/tests/unit/test_viv_logic.py index c7513cd..0b4feb5 100644 --- a/tests/unit/test_viv_logic.py +++ b/tests/unit/test_viv_logic.py @@ -86,3 +86,11 @@ def test_viv_config_passes_the_real_loader(tmp_path): assert (cfg.nx, cfg.ny) == (nx, ny) == (3000, 2400) assert cfg.collision == "MRT" and cfg.y_wall_bc == "free_slip" and cfg.velocity == .04 assert math.isclose(cfg.viscosity, .04 * 40 / 150) + + +def test_finite_rejects_any_nonfinite_recorded_output(): + row = (3, .1, .2, .3, .4, .5, .6, .7, 0.0) + assert viv.finite(row) + for i in range(len(row)): + for bad in (float("nan"), float("inf"), -float("inf")): + assert not viv.finite(row[:i] + (bad,) + row[i + 1:])