Files
FemLite/examples/two_arches/check_two_arches_results.py
T
shenw 75d4e735b1
FemLite CI / build-test (push) Has been cancelled
Release FemLite 0.5.2 V5 closeout
2026-07-01 14:51:40 +08:00

102 lines
3.9 KiB
Python

from __future__ import annotations
import csv
import math
import sys
from pathlib import Path
def read_csv(path: Path) -> list[dict[str, str]]:
if not path.exists():
raise RuntimeError(f"missing output file: {path}")
with path.open(newline="", encoding="utf-8") as handle:
return list(csv.DictReader(handle))
def require_close(actual: float, expected: float, tol: float, label: str) -> None:
if not math.isfinite(actual):
raise RuntimeError(f"{label} is not finite: {actual}")
if abs(actual - expected) > tol:
raise RuntimeError(f"{label} expected {expected:.12e}, got {actual:.12e}")
def require_node(nodes: list[dict[str, str]], node_id: int) -> dict[str, str]:
for row in nodes:
if int(row["node_id"]) == node_id:
return row
raise RuntimeError(f"node {node_id} was not written")
def check_reference_geometry(case_dir: Path) -> None:
nodes = read_csv(case_dir / "nodes_00000000.csv")
elements = read_csv(case_dir / "elements_00000000.csv")
if len(nodes) != 214:
raise RuntimeError(f"expected 214 nodes, got {len(nodes)}")
if len(elements) != 105:
raise RuntimeError(f"expected 105 shell elements, got {len(elements)}")
# Coordinates come directly from models.sme.two_arches.pdf:
# lower R=100 mm, upper R=80 mm, lower sector 100 deg, upper sector 80 deg.
node1 = require_node(nodes, 1)
require_close(float(node1["x"]), -7.660444431e-2, 5.0e-10, "lower left x")
require_close(float(node1["y"]), -1.5e-3, 5.0e-12, "lower left y")
require_close(float(node1["z"]), -3.572123904e-2, 5.0e-10, "lower left z")
lower_mid = require_node(nodes, 75)
require_close(float(lower_mid["x"]), 0.0, 5.0e-10, "lower midpoint x")
require_close(float(lower_mid["z"]), 0.0, 5.0e-10, "lower midpoint z")
upper_left = require_node(nodes, 153)
require_close(float(upper_left["x"]), -5.142300877e-2, 5.0e-10, "upper left x")
require_close(float(upper_left["z"]), 1.871644456e-2, 5.0e-10, "upper left z")
upper_mid = require_node(nodes, 183)
require_close(float(upper_mid["x"]), 0.0, 5.0e-10, "upper midpoint x")
require_close(float(upper_mid["z"]), 0.0, 5.0e-10, "upper midpoint z")
def check_solution(case_dir: Path) -> None:
history = read_csv(case_dir / "history.csv")
if len(history) < 3:
raise RuntimeError(f"expected at least three history rows, got {len(history)}")
final = history[-1]
max_displacement = float(final["max_displacement"])
if max_displacement > 2.0e-3:
raise RuntimeError(
"two-arches benchmark developed nonphysical dynamic overshoot: "
f"max displacement {max_displacement:.12e}"
)
nodes = read_csv(case_dir / "nodes_00000002.csv")
upper_mid = require_node(nodes, 183)
require_close(float(upper_mid["uz"]), -1.2e-3, 1.0e-10, "upper midpoint uz")
contact_rows = read_csv(case_dir / "contact_00000002.csv")
summary = next((row for row in contact_rows if row.get("kind") == "SUMMARY"), None)
if summary is None:
raise RuntimeError("contact output has no SUMMARY row")
active = int(summary["active_count"])
penetration = float(summary["max_penetration"])
force_norm = float(summary["force_norm"])
if active <= 0:
raise RuntimeError("two-arches benchmark did not activate shell contact")
if penetration <= 0.0:
raise RuntimeError(f"expected positive contact penetration, got {penetration}")
if force_norm <= 0.0:
raise RuntimeError(f"expected positive contact force norm, got {force_norm}")
def main(argv: list[str]) -> int:
if len(argv) != 2:
print("usage: check_two_arches_results.py CASE_OUTPUT_DIR")
return 2
case_dir = Path(argv[1])
check_reference_geometry(case_dir)
check_solution(case_dir)
print("two_arches geometry/contact smoke checks passed")
return 0
if __name__ == "__main__":
raise SystemExit(main(sys.argv))