From 300d4385b79d114c4d21d2d7907a2183f5fd4338 Mon Sep 17 00:00:00 2001 From: haitao-ZCU Date: Wed, 30 Sep 2026 15:32:22 +0200 Subject: [PATCH 01/13] use units_data to let ansys give related vars and units --- motors/synrm_3f_60s.py | 1 + motors/synrm_5f_60s.py | 1 + 2 files changed, 2 insertions(+) diff --git a/motors/synrm_3f_60s.py b/motors/synrm_3f_60s.py index 65c0189..76cf7c6 100644 --- a/motors/synrm_3f_60s.py +++ b/motors/synrm_3f_60s.py @@ -58,4 +58,5 @@ def assign_stator_coils(self, m2d: Maxwell2d) -> None: m2d.add_winding_coils(assignment=f"Phase{phase_name}", coils=[f"CS_{coil_name}" for coil_name, _ in group]) def extract_results(self, solutions): + print(solutions.units_data) return {"Moving1.Torque": np.array(solutions.data_real("Moving1.Torque"))} diff --git a/motors/synrm_5f_60s.py b/motors/synrm_5f_60s.py index 8e6fe46..9875527 100644 --- a/motors/synrm_5f_60s.py +++ b/motors/synrm_5f_60s.py @@ -64,4 +64,5 @@ def assign_stator_coils(self, m2d: Maxwell2d) -> None: m2d.add_winding_coils(assignment=f"Phase{phase_name}", coils=[f"CS_{coil_name}" for coil_name, _ in group]) def extract_results(self, solutions): + print(solutions.units_data) return {"Moving1.Torque": np.array(solutions.data_real("Moving1.Torque"))} From b27cd1f87f4f1f2080aca716ad38d7d43f66cd60 Mon Sep 17 00:00:00 2001 From: haitao-ZCU Date: Wed, 30 Sep 2026 15:50:39 +0200 Subject: [PATCH 02/13] check ansys units --- motors/synrm_3f_36s.py | 1 + motors/synrm_3f_60s.py | 1 - motors/synrm_5f_40s.py | 1 + motors/synrm_5f_60s.py | 1 - 4 files changed, 2 insertions(+), 2 deletions(-) diff --git a/motors/synrm_3f_36s.py b/motors/synrm_3f_36s.py index 812a051..00cbbeb 100644 --- a/motors/synrm_3f_36s.py +++ b/motors/synrm_3f_36s.py @@ -254,6 +254,7 @@ def set_variables(self, m2d: Maxwell2d, Id, Iq): m2d.variable_manager["Iq"] = f"{Iq}A" def extract_results(self, solutions): + print(solutions.units_data) position = np.array(solutions.data_real("Moving1.Position")) torque = np.array(solutions.data_real("Moving1.Torque")) diff --git a/motors/synrm_3f_60s.py b/motors/synrm_3f_60s.py index 76cf7c6..65c0189 100644 --- a/motors/synrm_3f_60s.py +++ b/motors/synrm_3f_60s.py @@ -58,5 +58,4 @@ def assign_stator_coils(self, m2d: Maxwell2d) -> None: m2d.add_winding_coils(assignment=f"Phase{phase_name}", coils=[f"CS_{coil_name}" for coil_name, _ in group]) def extract_results(self, solutions): - print(solutions.units_data) return {"Moving1.Torque": np.array(solutions.data_real("Moving1.Torque"))} diff --git a/motors/synrm_5f_40s.py b/motors/synrm_5f_40s.py index d22601a..248ec0c 100644 --- a/motors/synrm_5f_40s.py +++ b/motors/synrm_5f_40s.py @@ -223,6 +223,7 @@ def set_variables(self, m2d: Maxwell2d, Id1, Iq1, Id3, Iq3): m2d.variable_manager["Iq3"] = f"{Iq3}A" def extract_results(self, solutions): + print(solutions.units_data) position = np.array(solutions.data_real("Moving1.Position")) torque = np.array(solutions.data_real("Moving1.Torque")) diff --git a/motors/synrm_5f_60s.py b/motors/synrm_5f_60s.py index 9875527..8e6fe46 100644 --- a/motors/synrm_5f_60s.py +++ b/motors/synrm_5f_60s.py @@ -64,5 +64,4 @@ def assign_stator_coils(self, m2d: Maxwell2d) -> None: m2d.add_winding_coils(assignment=f"Phase{phase_name}", coils=[f"CS_{coil_name}" for coil_name, _ in group]) def extract_results(self, solutions): - print(solutions.units_data) return {"Moving1.Torque": np.array(solutions.data_real("Moving1.Torque"))} From 4f01d0284bc8b27a2d8bfc94fe7d29af9c1b730f Mon Sep 17 00:00:00 2001 From: haitao-ZCU Date: Wed, 30 Sep 2026 15:58:17 +0200 Subject: [PATCH 03/13] SI units for 3f_36s --- motors/synrm_3f_36s.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/motors/synrm_3f_36s.py b/motors/synrm_3f_36s.py index 00cbbeb..070a336 100644 --- a/motors/synrm_3f_36s.py +++ b/motors/synrm_3f_36s.py @@ -254,21 +254,20 @@ def set_variables(self, m2d: Maxwell2d, Id, Iq): m2d.variable_manager["Iq"] = f"{Iq}A" def extract_results(self, solutions): - print(solutions.units_data) - position = np.array(solutions.data_real("Moving1.Position")) - torque = np.array(solutions.data_real("Moving1.Torque")) + # SI units + position = np.array(solutions.data_real("Moving1.Position", convert_to_SI=True)) + torque = np.array(solutions.data_real("Moving1.Torque", convert_to_SI=True)) - theta_el = np.deg2rad(position - self.InitPos) * self.geometry.PolePairs - flux_phases = np.stack([np.array(solutions.data_real(f"FluxLinkage(Phase{p})")) for p in "ABC"], axis=-1) - vind_phases = np.stack([np.array(solutions.data_real(f"InducedVoltage(Phase{p})")) for p in "ABC"], axis=-1) - current_phases = np.stack([np.array(solutions.data_real(f"InputCurrent(Phase{p})")) for p in "ABC"], axis=-1) + theta_el = (position - np.deg2rad(self.InitPos)) * self.geometry.PolePairs + flux_phases = np.stack([np.array(solutions.data_real(f"FluxLinkage(Phase{p})", convert_to_SI=True)) for p in "ABC"], axis=-1) + vind_phases = np.stack([np.array(solutions.data_real(f"InducedVoltage(Phase{p})", convert_to_SI=True)) for p in "ABC"], axis=-1) + current_phases = np.stack([np.array(solutions.data_real(f"InputCurrent(Phase{p})", convert_to_SI=True)) for p in "ABC"], axis=-1) Flux_d, Flux_q = to_dq(flux_phases, theta_el, harmonic=1) Ui_d, Ui_q = to_dq(vind_phases, theta_el, harmonic=1) - I_d, I_q = (v / 1e3 for v in to_dq(current_phases, theta_el, harmonic=1)) - # mA to A + I_d, I_q = to_dq(current_phases, theta_el, harmonic=1) - L_raw = [np.stack([np.array(solutions.data_real(f"L(Phase{x},Phase{y})")) for y in "ABC"], axis=-1) / 1e9 for x in "ABC"] + L_raw = [np.stack([np.array(solutions.data_real(f"L(Phase{x},Phase{y})", convert_to_SI=True)) for y in "ABC"], axis=-1) / 1e9 for x in "ABC"] # nH to H L_d_row = np.zeros((len(position), 3)) From 143ea43d99a35c27e260751f49fe1552a73836b2 Mon Sep 17 00:00:00 2001 From: haitao-ZCU Date: Wed, 30 Sep 2026 16:24:45 +0200 Subject: [PATCH 04/13] SI units for 5f --- motors/synrm_5f_40s.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/motors/synrm_5f_40s.py b/motors/synrm_5f_40s.py index 248ec0c..0dcf572 100644 --- a/motors/synrm_5f_40s.py +++ b/motors/synrm_5f_40s.py @@ -223,22 +223,21 @@ def set_variables(self, m2d: Maxwell2d, Id1, Iq1, Id3, Iq3): m2d.variable_manager["Iq3"] = f"{Iq3}A" def extract_results(self, solutions): - print(solutions.units_data) - position = np.array(solutions.data_real("Moving1.Position")) - torque = np.array(solutions.data_real("Moving1.Torque")) + # SI units + position = np.array(solutions.data_real("Moving1.Position", convert_to_SI=True)) + torque = np.array(solutions.data_real("Moving1.Torque", convert_to_SI=True)) - theta_el = electrical_angle(position, self.InitPos, self.geometry.PolePairs, self.RotSign, degrees=True) - flux_phases = np.stack([np.array(solutions.data_real(f"FluxLinkage(Phase{p})")) for p in "ABCDE"], axis=-1) - vind_phases = np.stack([np.array(solutions.data_real(f"InducedVoltage(Phase{p})")) for p in "ABCDE"], axis=-1) - current_phases = np.stack([np.array(solutions.data_real(f"InputCurrent(Phase{p})")) for p in "ABCDE"], axis=-1) + theta_el = electrical_angle(position, np.deg2rad(self.InitPos), self.geometry.PolePairs, self.RotSign, degrees=False) + flux_phases = np.stack([np.array(solutions.data_real(f"FluxLinkage(Phase{p})", convert_to_SI=True)) for p in "ABCDE"], axis=-1) + vind_phases = np.stack([np.array(solutions.data_real(f"InducedVoltage(Phase{p})", convert_to_SI=True)) for p in "ABCDE"], axis=-1) + current_phases = np.stack([np.array(solutions.data_real(f"InputCurrent(Phase{p})", convert_to_SI=True)) for p in "ABCDE"], axis=-1) Flux_d1, Flux_q1 = to_dq(flux_phases, theta_el, harmonic=1) Flux_d3, Flux_q3 = to_dq(flux_phases, theta_el, harmonic=3) Vind_d1, Vind_q1 = to_dq(vind_phases, theta_el, harmonic=1) Vind_d3, Vind_q3 = to_dq(vind_phases, theta_el, harmonic=3) - I_d1, I_q1 = (v / 1e3 for v in to_dq(current_phases, theta_el, harmonic=1)) - I_d3, I_q3 = (v / 1e3 for v in to_dq(current_phases, theta_el, harmonic=3)) - # mA to A + I_d1, I_q1 = to_dq(current_phases, theta_el, harmonic=1) + I_d3, I_q3 = to_dq(current_phases, theta_el, harmonic=3) Im1 = np.sqrt(self.Id1**2 + self.Iq1**2) Im3 = np.sqrt(self.Id3**2 + self.Iq3**2) @@ -256,8 +255,7 @@ def extract_results(self, solutions): V_d1, V_q1 = to_dq(V_phases, theta_el, harmonic=1) V_d3, V_q3 = to_dq(V_phases, theta_el, harmonic=3) - L_raw = [np.stack([np.array(solutions.data_real(f"L(Phase{x},Phase{y})")) for y in "ABCDE"], axis=-1) / 1e9 for x in "ABCDE"] - # nH to H + L_raw = [np.stack([np.array(solutions.data_real(f"L(Phase{x},Phase{y})", convert_to_SI=True)) for y in "ABCDE"], axis=-1) for x in "ABCDE"] L_d1_row = np.zeros((len(time), 5)) L_q1_row = np.zeros((len(time), 5)) From 321e61b298c53367d56f5428cea8067b684cb9e5 Mon Sep 17 00:00:00 2001 From: haitao-ZCU Date: Wed, 30 Sep 2026 17:02:17 +0200 Subject: [PATCH 05/13] simplify 3f_36s test file to compare in SI units --- motors/synrm_3f_36s.py | 3 +-- tests/test_ansys_regression.py | 7 +------ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/motors/synrm_3f_36s.py b/motors/synrm_3f_36s.py index 070a336..82507dc 100644 --- a/motors/synrm_3f_36s.py +++ b/motors/synrm_3f_36s.py @@ -267,8 +267,7 @@ def extract_results(self, solutions): Ui_d, Ui_q = to_dq(vind_phases, theta_el, harmonic=1) I_d, I_q = to_dq(current_phases, theta_el, harmonic=1) - L_raw = [np.stack([np.array(solutions.data_real(f"L(Phase{x},Phase{y})", convert_to_SI=True)) for y in "ABC"], axis=-1) / 1e9 for x in "ABC"] - # nH to H + L_raw = [np.stack([np.array(solutions.data_real(f"L(Phase{x},Phase{y})", convert_to_SI=True)) for y in "ABC"], axis=-1) for x in "ABC"] L_d_row = np.zeros((len(position), 3)) L_q_row = np.zeros((len(position), 3)) diff --git a/tests/test_ansys_regression.py b/tests/test_ansys_regression.py index 5bf8111..e50ded7 100644 --- a/tests/test_ansys_regression.py +++ b/tests/test_ansys_regression.py @@ -107,12 +107,7 @@ def test_legacy_and_live_design_match_across_rotor_rebuilds(tmp_path): def _legacy_extract_results(solutions): out = {} for expr in legacy_design.solution_expressions: - val = np.array(solutions.data_real(expr)) - if expr in ("I_d", "I_q"): - val = val / 1e3 # mA to A - elif expr in ("L_d", "L_q"): - val = val / 1e9 # nH to H - out[expr] = val + out[expr]=np.array(solutions.data_real(expr, convert_to_SI=True)) # use SI units to compare return out legacy_design.extract_results = _legacy_extract_results From 45f44b457447f54e15e2894e1fe86135516728b4 Mon Sep 17 00:00:00 2001 From: haitao-ZCU Date: Wed, 30 Sep 2026 17:10:56 +0200 Subject: [PATCH 06/13] use SI units for 3f/5f_60s torque --- motors/synrm_3f_60s.py | 2 +- motors/synrm_5f_60s.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/motors/synrm_3f_60s.py b/motors/synrm_3f_60s.py index 65c0189..72f1262 100644 --- a/motors/synrm_3f_60s.py +++ b/motors/synrm_3f_60s.py @@ -58,4 +58,4 @@ def assign_stator_coils(self, m2d: Maxwell2d) -> None: m2d.add_winding_coils(assignment=f"Phase{phase_name}", coils=[f"CS_{coil_name}" for coil_name, _ in group]) def extract_results(self, solutions): - return {"Moving1.Torque": np.array(solutions.data_real("Moving1.Torque"))} + return {"Moving1.Torque": np.array(solutions.data_real("Moving1.Torque", convert_to_SI=True))} diff --git a/motors/synrm_5f_60s.py b/motors/synrm_5f_60s.py index 8e6fe46..b2315b8 100644 --- a/motors/synrm_5f_60s.py +++ b/motors/synrm_5f_60s.py @@ -64,4 +64,4 @@ def assign_stator_coils(self, m2d: Maxwell2d) -> None: m2d.add_winding_coils(assignment=f"Phase{phase_name}", coils=[f"CS_{coil_name}" for coil_name, _ in group]) def extract_results(self, solutions): - return {"Moving1.Torque": np.array(solutions.data_real("Moving1.Torque"))} + return {"Moving1.Torque": np.array(solutions.data_real("Moving1.Torque", convert_to_SI=True))} From 4c570198671a7fdbea51745773abe418762efcc7 Mon Sep 17 00:00:00 2001 From: haitao-ZCU Date: Wed, 30 Sep 2026 17:23:08 +0200 Subject: [PATCH 07/13] simplify --- tests/test_synrm_3f_36s.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/test_synrm_3f_36s.py b/tests/test_synrm_3f_36s.py index 69d9ad5..95ffa38 100644 --- a/tests/test_synrm_3f_36s.py +++ b/tests/test_synrm_3f_36s.py @@ -149,17 +149,18 @@ def test_mm_to_str_raises_without_mm_suffix(geometry): def test_extract_results_converts_units(computation): computation.set_variables(SimpleNamespace(variable_manager={}), Id=1.0, Iq=2.0) - def data_real(expr): + def data_real(expr, convert_to_SI=False): + assert convert_to_SI, f"expected convert_to_SI=True for {expr}" letters = ["ABC".index(part[0]) + 1 for part in expr.split("Phase")[1:]] value = float(np.prod(letters) if letters else 7.0) - return np.full(2, value * 1e9 if expr.startswith("L(") else value) + return np.full(2, value) solutions = SimpleNamespace(data_real=data_real, primary_sweep_values=[0.0, 1.0]) out = computation.extract_results(solutions) - theta_el = np.deg2rad(np.full(2, 7.0) - computation.InitPos) * computation.geometry.PolePairs + theta_el = (np.full(2, 7.0) - np.deg2rad(computation.InitPos)) * computation.geometry.PolePairs current_phases = np.stack([np.full(2, i + 1.0) for i in range(3)], axis=-1) expected_I_d, _ = to_dq(current_phases, theta_el, harmonic=1) - assert out["I_d"] == pytest.approx(expected_I_d / 1e3) + assert out["I_d"] == pytest.approx(expected_I_d) assert out["Moving1.Torque"] == pytest.approx(np.full(2, 7.0)) From 889f155b0314222ecb540b54e40e90c8c7282b5a Mon Sep 17 00:00:00 2001 From: haitao-ZCU Date: Wed, 30 Sep 2026 17:25:10 +0200 Subject: [PATCH 08/13] simplify --- tests/test_synrm_5f_40s.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/test_synrm_5f_40s.py b/tests/test_synrm_5f_40s.py index ed7953e..3a01642 100644 --- a/tests/test_synrm_5f_40s.py +++ b/tests/test_synrm_5f_40s.py @@ -91,10 +91,11 @@ def test_Rstat_Lew_values(computation2): def test_extract_results_converts_units(computation2): computation2.set_variables(SimpleNamespace(variable_manager={}), Id1=1.0, Iq1=2.0, Id3=3.0, Iq3=4.0) - def data_real(expr): + def data_real(expr, convert_to_SI=False): + assert convert_to_SI, f"expected convert_to_SI=True for {expr}" letters = ["ABCDE".index(part[0]) + 1 for part in expr.split("Phase")[1:]] value = float(np.prod(letters) if letters else 7.0) - return np.full(2, value * 1e9 if expr.startswith("L(") else value) + return np.full(2, value) solutions = SimpleNamespace(data_real=data_real, primary_sweep_values=[0.0, 1.0]) out = computation2.extract_results(solutions) @@ -103,5 +104,5 @@ def data_real(expr): current_phases = np.stack([np.full(2, i + 1.0) for i in range(5)], axis=-1) expected_I_d1, _ = to_dq(current_phases, theta_el, harmonic=1) - assert out["I_d1"] == pytest.approx(expected_I_d1 / 1e3) + assert out["I_d1"] == pytest.approx(expected_I_d1) assert out["Moving1.Torque"] == pytest.approx(np.full(2, 7.0)) From 169ff79da4d1d0702076208ae5fb3a0698b39cc3 Mon Sep 17 00:00:00 2001 From: haitao-ZCU Date: Wed, 30 Sep 2026 17:26:52 +0200 Subject: [PATCH 09/13] update theta_el --- tests/test_synrm_5f_40s.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_synrm_5f_40s.py b/tests/test_synrm_5f_40s.py index 3a01642..dbfe673 100644 --- a/tests/test_synrm_5f_40s.py +++ b/tests/test_synrm_5f_40s.py @@ -100,7 +100,7 @@ def data_real(expr, convert_to_SI=False): solutions = SimpleNamespace(data_real=data_real, primary_sweep_values=[0.0, 1.0]) out = computation2.extract_results(solutions) - theta_el = electrical_angle(np.full(2, 7.0), computation2.InitPos, computation2.geometry.PolePairs, computation2.RotSign, degrees=True) + theta_el = electrical_angle(np.full(2, 7.0), np.deg2rad(computation2.InitPos), computation2.geometry.PolePairs, computation2.RotSign, degrees=False) current_phases = np.stack([np.full(2, i + 1.0) for i in range(5)], axis=-1) expected_I_d1, _ = to_dq(current_phases, theta_el, harmonic=1) From 8538bfa76b314e4b536eef4690d84890f0be899d Mon Sep 17 00:00:00 2001 From: haitao-ZCU Date: Wed, 30 Sep 2026 17:34:23 +0200 Subject: [PATCH 10/13] ruff format --- tests/test_ansys_regression.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_ansys_regression.py b/tests/test_ansys_regression.py index e50ded7..6e4c2b4 100644 --- a/tests/test_ansys_regression.py +++ b/tests/test_ansys_regression.py @@ -107,7 +107,7 @@ def test_legacy_and_live_design_match_across_rotor_rebuilds(tmp_path): def _legacy_extract_results(solutions): out = {} for expr in legacy_design.solution_expressions: - out[expr]=np.array(solutions.data_real(expr, convert_to_SI=True)) # use SI units to compare + out[expr] = np.array(solutions.data_real(expr, convert_to_SI=True)) # use SI units to compare return out legacy_design.extract_results = _legacy_extract_results From d2af5b96347e50150c1dbbe2279995cf65179cd2 Mon Sep 17 00:00:00 2001 From: haitao-ZCU Date: Thu, 1 Oct 2026 10:52:09 +0200 Subject: [PATCH 11/13] add staticmethod --- machine_design/designs/computation.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/machine_design/designs/computation.py b/machine_design/designs/computation.py index 4e57fbe..9f31a7b 100644 --- a/machine_design/designs/computation.py +++ b/machine_design/designs/computation.py @@ -1,3 +1,5 @@ +import numpy as np + from abc import ABC, abstractmethod from ansys.aedt.core import Maxwell2d @@ -43,6 +45,10 @@ def set_variables(self, m2d: Maxwell2d, *args): ... @abstractmethod def extract_results(self, solutions): ... + @staticmethod + def extract_expression(solutions, expr: str) -> np.ndarray: + return np.asarray(solutions.data_real(expr, convert_to_SI=True)) + def set_initpos(self) -> None: Q = int(self.geometry.geom_params["SlotNumber"]) p = self.geometry.PolePairs From 117067eb4d3df80bafdb31ee719c0cb93c0b2cda Mon Sep 17 00:00:00 2001 From: haitao-ZCU Date: Thu, 1 Oct 2026 11:14:10 +0200 Subject: [PATCH 12/13] replace data_real() with extract_expression() --- motors/synrm_3f_36s.py | 12 ++++++------ motors/synrm_3f_60s.py | 2 +- motors/synrm_5f_40s.py | 12 ++++++------ motors/synrm_5f_60s.py | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/motors/synrm_3f_36s.py b/motors/synrm_3f_36s.py index 82507dc..ff51bbf 100644 --- a/motors/synrm_3f_36s.py +++ b/motors/synrm_3f_36s.py @@ -255,19 +255,19 @@ def set_variables(self, m2d: Maxwell2d, Id, Iq): def extract_results(self, solutions): # SI units - position = np.array(solutions.data_real("Moving1.Position", convert_to_SI=True)) - torque = np.array(solutions.data_real("Moving1.Torque", convert_to_SI=True)) + position = self.extract_expression(solutions, "Moving1.Position") + torque = self.extract_expression(solutions, "Moving1.Torque") theta_el = (position - np.deg2rad(self.InitPos)) * self.geometry.PolePairs - flux_phases = np.stack([np.array(solutions.data_real(f"FluxLinkage(Phase{p})", convert_to_SI=True)) for p in "ABC"], axis=-1) - vind_phases = np.stack([np.array(solutions.data_real(f"InducedVoltage(Phase{p})", convert_to_SI=True)) for p in "ABC"], axis=-1) - current_phases = np.stack([np.array(solutions.data_real(f"InputCurrent(Phase{p})", convert_to_SI=True)) for p in "ABC"], axis=-1) + flux_phases = np.stack([self.extract_expression(solutions, f"FluxLinkage(Phase{p})") for p in "ABC"], axis=-1) + vind_phases = np.stack([self.extract_expression(solutions, f"InducedVoltage(Phase{p})") for p in "ABC"], axis=-1) + current_phases = np.stack([self.extract_expression(solutions, f"InputCurrent(Phase{p})") for p in "ABC"], axis=-1) Flux_d, Flux_q = to_dq(flux_phases, theta_el, harmonic=1) Ui_d, Ui_q = to_dq(vind_phases, theta_el, harmonic=1) I_d, I_q = to_dq(current_phases, theta_el, harmonic=1) - L_raw = [np.stack([np.array(solutions.data_real(f"L(Phase{x},Phase{y})", convert_to_SI=True)) for y in "ABC"], axis=-1) for x in "ABC"] + L_raw = [np.stack([self.extract_expression(solutions, f"L(Phase{x},Phase{y})") for y in "ABC"], axis=-1) for x in "ABC"] L_d_row = np.zeros((len(position), 3)) L_q_row = np.zeros((len(position), 3)) diff --git a/motors/synrm_3f_60s.py b/motors/synrm_3f_60s.py index 72f1262..9690afd 100644 --- a/motors/synrm_3f_60s.py +++ b/motors/synrm_3f_60s.py @@ -58,4 +58,4 @@ def assign_stator_coils(self, m2d: Maxwell2d) -> None: m2d.add_winding_coils(assignment=f"Phase{phase_name}", coils=[f"CS_{coil_name}" for coil_name, _ in group]) def extract_results(self, solutions): - return {"Moving1.Torque": np.array(solutions.data_real("Moving1.Torque", convert_to_SI=True))} + return {"Moving1.Torque": self.extract_expression(solutions, "Moving1.Torque")} diff --git a/motors/synrm_5f_40s.py b/motors/synrm_5f_40s.py index 0dcf572..2242c64 100644 --- a/motors/synrm_5f_40s.py +++ b/motors/synrm_5f_40s.py @@ -224,13 +224,13 @@ def set_variables(self, m2d: Maxwell2d, Id1, Iq1, Id3, Iq3): def extract_results(self, solutions): # SI units - position = np.array(solutions.data_real("Moving1.Position", convert_to_SI=True)) - torque = np.array(solutions.data_real("Moving1.Torque", convert_to_SI=True)) + position = self.extract_expression(solutions, "Moving1.Position") + torque = self.extract_expression(solutions, "Moving1.Torque") theta_el = electrical_angle(position, np.deg2rad(self.InitPos), self.geometry.PolePairs, self.RotSign, degrees=False) - flux_phases = np.stack([np.array(solutions.data_real(f"FluxLinkage(Phase{p})", convert_to_SI=True)) for p in "ABCDE"], axis=-1) - vind_phases = np.stack([np.array(solutions.data_real(f"InducedVoltage(Phase{p})", convert_to_SI=True)) for p in "ABCDE"], axis=-1) - current_phases = np.stack([np.array(solutions.data_real(f"InputCurrent(Phase{p})", convert_to_SI=True)) for p in "ABCDE"], axis=-1) + flux_phases = np.stack([self.extract_expression(solutions, f"FluxLinkage(Phase{p})") for p in "ABCDE"], axis=-1) + vind_phases = np.stack([self.extract_expression(solutions, f"InducedVoltage(Phase{p})") for p in "ABCDE"], axis=-1) + current_phases = np.stack([self.extract_expression(solutions, f"InputCurrent(Phase{p})") for p in "ABCDE"], axis=-1) Flux_d1, Flux_q1 = to_dq(flux_phases, theta_el, harmonic=1) Flux_d3, Flux_q3 = to_dq(flux_phases, theta_el, harmonic=3) @@ -255,7 +255,7 @@ def extract_results(self, solutions): V_d1, V_q1 = to_dq(V_phases, theta_el, harmonic=1) V_d3, V_q3 = to_dq(V_phases, theta_el, harmonic=3) - L_raw = [np.stack([np.array(solutions.data_real(f"L(Phase{x},Phase{y})", convert_to_SI=True)) for y in "ABCDE"], axis=-1) for x in "ABCDE"] + L_raw = [np.stack([self.extract_expression(solutions, f"L(Phase{x},Phase{y})") for y in "ABCDE"], axis=-1) for x in "ABCDE"] L_d1_row = np.zeros((len(time), 5)) L_q1_row = np.zeros((len(time), 5)) diff --git a/motors/synrm_5f_60s.py b/motors/synrm_5f_60s.py index b2315b8..f04d2cf 100644 --- a/motors/synrm_5f_60s.py +++ b/motors/synrm_5f_60s.py @@ -64,4 +64,4 @@ def assign_stator_coils(self, m2d: Maxwell2d) -> None: m2d.add_winding_coils(assignment=f"Phase{phase_name}", coils=[f"CS_{coil_name}" for coil_name, _ in group]) def extract_results(self, solutions): - return {"Moving1.Torque": np.array(solutions.data_real("Moving1.Torque", convert_to_SI=True))} + return {"Moving1.Torque": self.extract_expression(solutions, "Moving1.Torque")} From 305507ff2857e77d8eab8cf315371458b25c7537 Mon Sep 17 00:00:00 2001 From: haitao-ZCU Date: Thu, 1 Oct 2026 11:31:51 +0200 Subject: [PATCH 13/13] ruff --- machine_design/designs/computation.py | 3 +-- motors/synrm_3f_60s.py | 1 - motors/synrm_5f_60s.py | 1 - 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/machine_design/designs/computation.py b/machine_design/designs/computation.py index 9f31a7b..f756403 100644 --- a/machine_design/designs/computation.py +++ b/machine_design/designs/computation.py @@ -1,7 +1,6 @@ -import numpy as np - from abc import ABC, abstractmethod +import numpy as np from ansys.aedt.core import Maxwell2d from machine_design.generic.compute_initpos import compute_initpos diff --git a/motors/synrm_3f_60s.py b/motors/synrm_3f_60s.py index 9690afd..ef7b2af 100644 --- a/motors/synrm_3f_60s.py +++ b/motors/synrm_3f_60s.py @@ -1,6 +1,5 @@ """Anchor `synrm_3f_60s`: 3-phase synchronous reluctance machine, 60 stator slots.""" -import numpy as np from ansys.aedt.core import Maxwell2d from machine_design.generic.winding import phase_groups diff --git a/motors/synrm_5f_60s.py b/motors/synrm_5f_60s.py index f04d2cf..9a47438 100644 --- a/motors/synrm_5f_60s.py +++ b/motors/synrm_5f_60s.py @@ -4,7 +4,6 @@ phases. Excitation is dq1 + dq3. """ -import numpy as np from ansys.aedt.core import Maxwell2d from machine_design.generic.winding import phase_groups