"""Verify the executor enable_thermal plumbing end-to-end on real Motor-CAD. Runs RobustMotorCADSolver with enable_thermal=True for a single point and checks that: 1. The EM and thermal solves both complete. 2. Thermal metrics are merged into the point result. 3. Thermal metric columns are written to scan_results.csv. Ambient temperature is overridden to 25 C in-memory (the MARS model ships an abnormal 125 C) so the temperature-rise / thermal-resistance metrics come out physically positive. Run with the venv python that has ansys-motorcad-core installed, e.g.: /Scripts/python.exe scripts/verify_enable_thermal.py All source is ASCII only. """ from __future__ import annotations import os import sys import time from pathlib import Path _ROOT = Path(__file__).resolve().parent.parent sys.path.insert(0, str(_ROOT / "src")) sys.path.insert(0, str(_ROOT / "scripts")) from robust_motorcad import RobustMotorCADSolver # noqa: E402 MODEL = str(_ROOT / "models" / "MARS-12S10P_SSSR_D76-C150_V5.0-0819.mot") THERMAL_KEYS = [ "winding_temp_c", "winding_hotspot_temp_c", "magnet_temp_c", "stator_temp_c", "bearing_temp_c", "temp_rise_c", "thermal_resistance_k_w", ] def main(thermal_mode: str = "coupled") -> int: output_dir = str(_ROOT / "output" / ( "verify_thermal_" + time.strftime("%Y%m%d_%H%M%S") )) solver = RobustMotorCADSolver( model_path=MODEL, output_dir=output_dir, ambient_temperature=25.0, thermal_mode=thermal_mode, ) solver.connect() try: result = solver.run_single_point( {"RMSCurrent": 21.0, "Shaft_Speed": 5000.0}, point_index=0, point_label="verify", ) print("status: %s" % result["status"], flush=True) print("=== thermal metrics in point result ===", flush=True) for key in THERMAL_KEYS: print(" %s = %s" % (key, result.get("metrics", {}).get(key)), flush=True) csv_path = os.path.join(output_dir, "scan_results.csv") csv_ok = os.path.exists(csv_path) print("scan_results.csv exists: %s" % csv_ok, flush=True) thermal_in_csv = False if csv_ok: header = open(csv_path, encoding="utf-8").readline().rstrip() thermal_in_csv = all(k in header for k in THERMAL_KEYS) print("thermal columns present in CSV header: %s" % thermal_in_csv, flush=True) merged = all( key in result.get("metrics", {}) for key in THERMAL_KEYS ) ok = ( result["status"] == "OK" and merged and csv_ok and thermal_in_csv ) print("") print("ENABLE_THERMAL END-TO-END: %s" % ("PASS" if ok else "FAIL"), flush=True) return 0 if ok else 1 finally: solver.disconnect() if __name__ == "__main__": import argparse parser = argparse.ArgumentParser() parser.add_argument("--thermal-mode", choices=["off", "steady", "coupled"], default="coupled") args = parser.parse_args() sys.exit(main(thermal_mode=args.thermal_mode))