77 lines
3.1 KiB
Python
77 lines
3.1 KiB
Python
from __future__ import annotations
|
|
|
|
import argparse
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--library", required=True)
|
|
parser.add_argument("--input", required=True)
|
|
args = parser.parse_args()
|
|
|
|
root = Path(__file__).resolve().parents[2]
|
|
sys.path.insert(0, str(root / "python"))
|
|
|
|
from sphlite_debug import ( # noqa: PLC0415
|
|
COUPLING_EXPORT_BOTH,
|
|
COUPLING_IMPORT_FORCE,
|
|
PHASE_SHELL,
|
|
SPHLite,
|
|
)
|
|
|
|
wrapper_source = (root / "python" / "sphlite_debug.py").read_text(encoding="utf-8")
|
|
if "sphlite_coupling_get_region_count" not in wrapper_source:
|
|
raise AssertionError("Python wrapper is missing coupling region query")
|
|
if "sphlite_coupling_apply_particle_forces" not in wrapper_source:
|
|
raise AssertionError("Python wrapper is missing coupling force import")
|
|
if "sphft_" in wrapper_source:
|
|
raise AssertionError("Python wrapper directly references Fortran symbols")
|
|
|
|
solver = SPHLite(args.library)
|
|
solver.initialize()
|
|
try:
|
|
summary = solver.inspect(args.input)
|
|
if summary["coupling_regions"] != 2:
|
|
raise AssertionError("coupling inspect region count mismatch")
|
|
region_info = summary["coupling_region_info"]
|
|
if region_info[1]["name"] != "SHELL_BOTH":
|
|
raise AssertionError("coupling inspect region name mismatch")
|
|
if region_info[1]["export_mode"] != COUPLING_EXPORT_BOTH:
|
|
raise AssertionError("coupling inspect export mode mismatch")
|
|
if region_info[1]["import_mode"] != COUPLING_IMPORT_FORCE:
|
|
raise AssertionError("coupling inspect import mode mismatch")
|
|
if summary["coupling_nonfinite_imports"] != 0:
|
|
raise AssertionError("coupling inspect nonfinite count mismatch")
|
|
|
|
export = solver.coupling_particle_export(2)
|
|
if len(export["ext_ids"]) != 3 or export["ext_ids"][0] != 1:
|
|
raise AssertionError("coupling Python particle export mismatch")
|
|
if export["phases"][0] != PHASE_SHELL:
|
|
raise AssertionError("coupling Python particle phase mismatch")
|
|
if len(export["scalar_values"]) != 3 * 7:
|
|
raise AssertionError("coupling Python scalar export shape mismatch")
|
|
if len(export["vector_values"]) != 3 * 3 * 3:
|
|
raise AssertionError("coupling Python vector export shape mismatch")
|
|
|
|
solver.coupling_apply_particle_forces(2, [1], [2.0, 0.0, 0.0])
|
|
diagnostics = solver.coupling_diagnostics()
|
|
if diagnostics["coupling_imported_forces"] != 1:
|
|
raise AssertionError("coupling Python diagnostics import count mismatch")
|
|
if len(diagnostics["coupling_force"]) != 3:
|
|
raise AssertionError("coupling Python diagnostics force shape mismatch")
|
|
try:
|
|
solver.coupling_apply_particle_forces(2, [1], [1.0, 0.0])
|
|
except ValueError:
|
|
pass
|
|
else:
|
|
raise AssertionError("coupling Python force shape error did not raise")
|
|
finally:
|
|
solver.finalize()
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|