Expose Solid summary interfaces
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def run_command(args: list[str]) -> subprocess.CompletedProcess[str]:
|
||||
result = subprocess.run(args, text=True, capture_output=True)
|
||||
if result.returncode != 0:
|
||||
raise AssertionError(result.stderr or result.stdout)
|
||||
return result
|
||||
|
||||
|
||||
def read_fields(output: str) -> dict[str, str]:
|
||||
fields: dict[str, str] = {}
|
||||
for line in output.splitlines():
|
||||
if ":" in line:
|
||||
name, value = line.split(":", 1)
|
||||
fields[name.strip()] = value.strip()
|
||||
return fields
|
||||
|
||||
|
||||
def read_summary(path: Path) -> dict[str, str]:
|
||||
result: dict[str, str] = {}
|
||||
for line in path.read_text(encoding="utf-8").splitlines()[1:]:
|
||||
if "," in line:
|
||||
name, value = line.split(",", 1)
|
||||
result[name.strip()] = value.strip()
|
||||
return result
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--exe", required=True)
|
||||
parser.add_argument("--library", required=True)
|
||||
parser.add_argument("--input", required=True)
|
||||
parser.add_argument("--output-dir", required=True)
|
||||
args = parser.parse_args()
|
||||
|
||||
root = Path(__file__).resolve().parents[2]
|
||||
sys.path.insert(0, str(root / "Python"))
|
||||
from sphlite_debug import SPHLite
|
||||
|
||||
exe = str(Path(args.exe))
|
||||
model = str(Path(args.input))
|
||||
output_dir = Path(args.output_dir)
|
||||
|
||||
inspect = read_fields(run_command([exe, model]).stdout)
|
||||
if inspect["mode"] != "inspect" or inspect["status"] != "ok":
|
||||
raise AssertionError("Solid CLI inspect mode mismatch")
|
||||
if int(inspect["solid_particles"]) != 4:
|
||||
raise AssertionError("Solid CLI inspect particle count mismatch")
|
||||
if float(inspect["solid_mass"]) <= 0.0:
|
||||
raise AssertionError("Solid CLI inspect mass mismatch")
|
||||
if float(inspect["solid_dtcrit"]) <= 0.0:
|
||||
raise AssertionError("Solid CLI inspect dt mismatch")
|
||||
|
||||
run = read_fields(run_command([exe, model, "--run", "--output", str(output_dir)]).stdout)
|
||||
if run["mode"] != "run" or int(run["step"]) <= 0:
|
||||
raise AssertionError("Solid CLI run mode mismatch")
|
||||
if int(run["solid_particles"]) != 4 or float(run["solid_mass"]) <= 0.0:
|
||||
raise AssertionError("Solid CLI run summary mismatch")
|
||||
summary_path = output_dir / f"sphlite_{int(run['step']):08d}_summary.csv"
|
||||
summary = read_summary(summary_path)
|
||||
if int(summary["solid_particles"]) != 4:
|
||||
raise AssertionError("Solid CLI output summary mismatch")
|
||||
|
||||
solver = SPHLite(args.library)
|
||||
solver.initialize()
|
||||
try:
|
||||
solver.read_inp(model)
|
||||
solver.build_model()
|
||||
restart = output_dir / "solid_cli_restart.tmp"
|
||||
solver.write_restart(restart)
|
||||
solver.read_restart(restart)
|
||||
solid = solver.solid_summary()
|
||||
if solid["solid_particles"] != 4 or solid["solid_mass"] <= 0.0:
|
||||
raise AssertionError("Solid CLI restart checker mismatch")
|
||||
finally:
|
||||
solver.finalize()
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user