From dc6713e9513d2908c44449a57013de7173debf7d Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 30 Oct 2026 11:10:39 +0000 Subject: [PATCH] =?UTF-8?q?research:=20D=C3=BCtsch=20config=20from=20the?= =?UTF-8?q?=20shipped=20config=5Flbm.json=20schema;=20real-loader=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The generated config failed the real loader (KeyError: cuda). It now copies src/CelerisLab/configs/config_lbm.json and overrides only grid, physics, collision/streaming/storage, y walls, LES off and uniform inlet profile; inlet scheme and outlet mode stay the template's and are recorded in case.json. New CPU test loads the generated file with load_lbm_config. Co-Authored-By: Claude Opus 5.5 --- research/duetsch_re100_kc5/run.py | 22 ++++++++++++++++++---- tests/unit/test_duetsch_protocol.py | 19 +++++++++++++++++++ 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/research/duetsch_re100_kc5/run.py b/research/duetsch_re100_kc5/run.py index 72017d3..9e9bc15 100644 --- a/research/duetsch_re100_kc5/run.py +++ b/research/duetsch_re100_kc5/run.py @@ -20,13 +20,26 @@ import numpy as np import protocol as p +TEMPLATE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..", "src", + "CelerisLab", "configs", "config_lbm.json") + + def config(D, box, T): + """Shipped config_lbm.json (full parser schema) with only the case fields + overridden: grid, still fluid (velocity 0), nu from Re, MRT, uniform inlet + profile, bounce-back y walls. Inlet scheme and outlet mode stay the + template's (zou_he_local, neq_extrap) and are recorded in case.json.""" u = p.KC * D / T n = int(round(box * D)) - return {"grid": {"lattice_model": "D2Q9", "nx": n, "ny": n, "nz": 1}, - "physics": {"data_type": "FP32", "viscosity": u * D / p.RE, "velocity": 0.0, "rho": 1.0}, - "method": {"collision": "MRT", "streaming": "double_buffer", "store_precision": "FP32", - "ddf_shifting": False, "y_wall_bc": "bounce_back"}}, u, n + with open(TEMPLATE) as fh: + cfg = json.load(fh) + cfg["grid"].update(lattice_model="D2Q9", nx=n, ny=n, nz=1) + cfg["physics"].update(data_type="FP32", viscosity=u * D / p.RE, velocity=0.0, rho=1.0) + cfg["method"].update(collision="MRT", streaming="double_buffer", store_precision="FP32", + ddf_shifting=False, y_wall_bc="bounce_back") + cfg["method"]["les"]["enabled"] = False + cfg["method"]["inlet"]["profile"] = "uniform" + return cfg, u, n def main(): @@ -85,6 +98,7 @@ def main(): json.dump(dict(D=D, T=T, box=args.box, n=n, u_max=u_max, nu=cfg["physics"]["viscosity"], tau=3 * cfg["physics"]["viscosity"] + 0.5, A=A, steps=steps, cycles=args.cycles, F_ref=0.5 * u_max ** 2 * D, + inlet=cfg["method"]["inlet"], outlet=cfg["method"]["outlet"], weights=[r[8] for r in samples]), fh) finally: sim.close() diff --git a/tests/unit/test_duetsch_protocol.py b/tests/unit/test_duetsch_protocol.py index c600d52..375411c 100644 --- a/tests/unit/test_duetsch_protocol.py +++ b/tests/unit/test_duetsch_protocol.py @@ -85,3 +85,22 @@ def test_exact_point_inside_body_is_missing_even_with_fluid_corners(): assert value is None and used == () and total == 0.0 value, used, total = p.sample(field, fluid, 3.35, 3.0, centre, radius) # just outside assert value is not None and total > 0.0 + + +def test_generated_config_passes_the_real_loader(tmp_path): + import json + import sys + sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "research/duetsch_re100_kc5")) + try: + import run + finally: + sys.path.pop(0) + from CelerisLab.config import load_lbm_config + cfg_dict, u_max, n = run.config(20, 10.0, 2520) + path = tmp_path / "config_lbm.json" + path.write_text(json.dumps(cfg_dict)) + cfg = load_lbm_config(str(path)) + assert (cfg.nx, cfg.ny) == (n, n) == (200, 200) + assert cfg.collision == "MRT" and cfg.streaming == "double_buffer" and not cfg.ddf_shifting + assert cfg.velocity == 0.0 and cfg.viscosity == pytest.approx(u_max * 20 / 100) + assert cfg.y_wall_bc == "bounce_back"