research: Dütsch config from the shipped config_lbm.json schema; real-loader test
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 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
fbe7b2fb7c
commit
dc6713e951
@@ -20,13 +20,26 @@ import numpy as np
|
|||||||
import protocol as p
|
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):
|
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
|
u = p.KC * D / T
|
||||||
n = int(round(box * D))
|
n = int(round(box * D))
|
||||||
return {"grid": {"lattice_model": "D2Q9", "nx": n, "ny": n, "nz": 1},
|
with open(TEMPLATE) as fh:
|
||||||
"physics": {"data_type": "FP32", "viscosity": u * D / p.RE, "velocity": 0.0, "rho": 1.0},
|
cfg = json.load(fh)
|
||||||
"method": {"collision": "MRT", "streaming": "double_buffer", "store_precision": "FP32",
|
cfg["grid"].update(lattice_model="D2Q9", nx=n, ny=n, nz=1)
|
||||||
"ddf_shifting": False, "y_wall_bc": "bounce_back"}}, u, n
|
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():
|
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"],
|
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,
|
tau=3 * cfg["physics"]["viscosity"] + 0.5, A=A, steps=steps,
|
||||||
cycles=args.cycles, F_ref=0.5 * u_max ** 2 * D,
|
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)
|
weights=[r[8] for r in samples]), fh)
|
||||||
finally:
|
finally:
|
||||||
sim.close()
|
sim.close()
|
||||||
|
|||||||
@@ -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
|
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
|
value, used, total = p.sample(field, fluid, 3.35, 3.0, centre, radius) # just outside
|
||||||
assert value is not None and total > 0.0
|
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"
|
||||||
|
|||||||
Reference in New Issue
Block a user