Procházet zdrojové kódy

feat(thermal): add --ambient override + verify temp-rise turns positive; fix test_executor_m3

- run_thermal.py: add --ambient N to override Ambient_Temperature in-memory (verified writable/readback)
- Measured: ambient=25 turns temp_rise_c +27.57 (was -56.88) and thermal_resistance_k_w +5.657 (was -11.07), confirming 125C anomaly was the root cause
- test_executor_m3.py: make_task now sets status=pending so claim-reject path is exercised (was a test-fixture gap, not a production bug)
- Docs: KNOWLEDGE_BASE ambient fix table, CONVERSATION_LOG
carlin před 21 hodinami
rodič
revize
ad55b2145e

+ 18 - 0
docs/CONVERSATION_LOG.md

@@ -1081,3 +1081,21 @@ test_executor_p5m2 8 项全通过。
 
 **test_executor_m3 失败定性**:该测试用 TaskExecutor 基类测"claim 拒绝→跳过"逻辑,与本次
 enable_thermal 改动(仅在 MotorCADTaskExecutor 子类)无关,为既有失败,非本次引入。
+
+## 2026-09-04 — 环境温度修正实测(温升/热阻转正)+ 修复 test_executor_m3
+
+**环境温度修正实测**(run_thermal.py --ambient 25):变量名 `Ambient_Temperature` 实测可写、
+可回读校验。MARS 默认 125°C 异常,修正为 25°C 后温升/热阻均由负转正:
+
+| 指标 | ambient=125 | ambient=25 |
+|---|---|---|
+| 温升 temp_rise_c | -56.88 | **+27.57** |
+| 热阻 thermal_resistance_k_w | -11.07 | **+5.657** |
+| 磁钢 active | 118.15°C | 67.61°C |
+| 绕组热点 | 74.59°C | 53.91°C |
+
+验证了"125°C 异常是温升/热阻为负的根因"。建议默认 25°C 或按实际工况设 40°C。
+
+**修复 test_executor_m3**:失败根因是测试辅助 make_task 未设 `status="pending"`,导致
+execute_task 的 claim 逻辑(仅 status=="pending" 才 dispatch)被跳过、`dispatch_task=False`
+未生效。修复后 4 项全通过。属测试代码缺陷,非生产代码 bug。

+ 15 - 4
docs/KNOWLEDGE_BASE.md

@@ -136,11 +136,22 @@ mc.export_results("SteadyState", r"output\raw\thermal.csv")  # 导出热结果
 - 温升 → `dT [Winding (Maximum) - Ambient]`
 - 热阻 → `Rt [Winding (Maximum) - Ambient]`
 
-**⚠ MARS 模型热边界条件异常(待用户确认修正)**:
+**⚠ MARS 模型热边界条件异常(已实测验证修正)**:
 `[Miscellaneous]` section 中 `T_Ambient=125` / `Ambient_Temperature=125`(环境温度 125°C,
-异常;辐射环境温度 `T_Ambient_Radiation=40` 合理)。导致温升/热阻为负值
-(绕组 74.6°C 比环境 125°C 还低)。热仿真前应将 `Ambient_Temperature` 设为合理值
-(如 25~40°C),否则温升/热阻指标无意义。
+异常;辐射环境温度 `T_Ambient_Radiation=40` 合理)。修正方式:`set_variable("Ambient_Temperature", 25)`
+(变量名 `Ambient_Temperature` 实测可写、可回读校验)。实测对比(TEST-060 续):
+
+| 指标 | ambient=125(异常) | ambient=25(修正后) |
+|---|---|---|
+| 绕组平均 | 67.95°C | 52.59°C |
+| 绕组热点 | 74.59°C | 53.91°C |
+| 磁钢 active | 118.15°C | 67.61°C |
+| 后轴承 | 88.47°C | 38.47°C |
+| 温升 temp_rise_c | -56.88(负) | **+27.57(转正)** |
+| 热阻 thermal_resistance_k_w | -11.07(负) | **+5.657(转正)** |
+
+环境温度修正后温升/热阻均转正、物理合理。**建议默认环境温度 25°C(常温)或按实际工况
+设 40°C**。`scripts/run_thermal.py --ambient 25` 在 Motor-CAD 内存中临时覆盖(不改原始 .mot)。
 
 **磁热耦合 vs 分离式(2026-09-04 实测对比,TEST-060 续)**:
 

+ 16 - 2
scripts/run_thermal.py

@@ -88,7 +88,7 @@ def write_and_verify(mc, variable: str, value: float) -> None:
         )
 
 
-def main(mode: str = "steady") -> int:
+def main(mode: str = "steady", ambient: float = None) -> int:
     ensure_environment()
 
     import ansys.motorcad.core as pymotorcad
@@ -120,6 +120,13 @@ def main(mode: str = "steady") -> int:
             except Exception as exc:  # noqa: BLE001
                 log("  WARNING: %s write failed: %s" % (var, exc))
 
+        if ambient is not None:
+            try:
+                write_and_verify(mc, "Ambient_Temperature", ambient)
+                log("  Ambient_Temperature = %s (override, verified)" % ambient)
+            except Exception as exc:  # noqa: BLE001
+                log("  WARNING: Ambient_Temperature write failed: %s" % exc)
+
         if mode == "coupled":
             # Magnetic-thermal coupled solve: EM + thermal in one call.
             log("Running magnetic-thermal coupled calculation ...")
@@ -196,9 +203,16 @@ if __name__ == "__main__":
         help="steady = EM then steady-state thermal (default); "
              "coupled = do_magnetic_thermal_calculation (EM+thermal in one).",
     )
+    parser.add_argument(
+        "--ambient",
+        type=float,
+        default=None,
+        help="override Ambient_Temperature (degC). Default uses the model "
+             "value (MARS model ships 125, which is abnormal; try 25 or 40).",
+    )
     args = parser.parse_args()
     try:
-        sys.exit(main(mode=args.mode))
+        sys.exit(main(mode=args.mode, ambient=args.ambient))
     except Exception:
         traceback.print_exc()
         sys.exit(1)

+ 4 - 2
scripts/test_executor_m3.py

@@ -19,8 +19,10 @@ captured = {}
 def make_task(tid, params):
     path = os.path.join(tmp, tid + "_task.json")
     with open(path, "w", encoding="utf-8") as f:
-        json.dump({"task_id": tid, "task_name": "m3", "parameters": params}, f)
-    return {"task_id": tid, "_local_file": path, "parameters": params}
+        json.dump({"task_id": tid, "task_name": "m3", "status": "pending",
+                   "parameters": params}, f)
+    return {"task_id": tid, "_local_file": path, "status": "pending",
+            "parameters": params}
 
 
 # ---------------- 1) point_id passthrough (claim succeeds) ----------------