Skip to content

Commit f794b6b

Browse files
Feat/add pymotorcad methods for transient (#327)
* added thermal option for save and load results * added version check and input check for save and load results * case sensitivity and message string changes * case sensitivity and message string changes * tests for thermal save and load * Apply suggestions from code review * improve test coverage --------- Co-authored-by: Jack Davies <[email protected]> Co-authored-by: Jack Davies <[email protected]>
1 parent 3dad907 commit f794b6b

File tree

2 files changed

+59
-20
lines changed

2 files changed

+59
-20
lines changed

src/ansys/motorcad/core/methods/rpc_methods_general.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
# SOFTWARE.
2222

2323
"""RPC methods (general)."""
24+
from ansys.motorcad.core.rpc_client_core import MotorCADError
2425

2526

2627
class _RpcMethodsGeneral:
@@ -378,31 +379,49 @@ def save_to_file(self, mot_file):
378379
return self.connection.send_and_receive(method, params)
379380

380381
def save_results(self, solution_type):
381-
"""Save the output results from an ``"EMagnetic"`` solution.
382+
"""Save the output results from an ``"EMagnetic"`` or ``"Thermal"`` solution.
382383
383-
This method supports only ``"EMagnetic"`` solutions.
384+
This method supports only ``"EMagnetic"`` or ``"Thermal"`` solutions.
384385
385386
Parameters
386387
----------
387388
solution_type : str
388-
Soultion type, which must be ``"EMagnetic"``.
389+
Solution type, which must be ``"EMagnetic"`` or ``"Thermal"``.
389390
"""
390391
method = "SaveResults"
391392
params = [solution_type]
393+
394+
if solution_type.lower() == "thermal":
395+
self.connection.ensure_version_at_least("2025.0")
396+
elif solution_type.lower() != "emagnetic":
397+
raise MotorCADError(
398+
"Save results are not available for this solution type: "
399+
+ solution_type
400+
+ "\nAvailable solution types are: Thermal, EMagnetic"
401+
)
392402
return self.connection.send_and_receive(method, params)
393403

394404
def load_results(self, solution_type):
395-
"""Load the output results from an ``"EMagnetic"`` solution.
405+
"""Load the output results from an ``"EMagnetic"`` or ``"Thermal"`` solution.
396406
397-
This method supports only ``"EMagnetic"`` solution.
407+
This method supports only ``"EMagnetic"`` or ``"Thermal"`` solution.
398408
399409
Parameters
400410
----------
401411
solution_type : str
402-
Soultion type, which must be ``"EMagnetic"``.
412+
Solution type, which must be ``"EMagnetic"`` or ``"Thermal"``.
403413
"""
404414
method = "LoadResults"
405415
params = [solution_type]
416+
417+
if solution_type.lower() == "thermal":
418+
self.connection.ensure_version_at_least("2025.0")
419+
elif solution_type.lower() != "emagnetic":
420+
raise MotorCADError(
421+
"Load results are not available for this solution type: "
422+
+ solution_type
423+
+ "\nAvailable solution types are: Thermal, EMagnetic"
424+
)
406425
return self.connection.send_and_receive(method, params)
407426

408427
def load_magnetisation_curves(self, file_path):

tests/test_general.py

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
import os
2424

25+
import pytest
26+
2527
from RPC_Test_Common import (
2628
almost_equal,
2729
get_base_test_file_path,
@@ -31,7 +33,7 @@
3133
reset_to_default_file,
3234
)
3335
import ansys.motorcad.core
34-
from ansys.motorcad.core import MotorCAD
36+
from ansys.motorcad.core import MotorCAD, MotorCADError
3537

3638
# Allows us to add a new api method to testing before the next Motor-CAD release is available
3739
# Dev release will have a lower version number than actual release so don't want to check this
@@ -188,21 +190,39 @@ def test_save_load_magnetisation_curves(mc):
188190
reset_to_default_file(mc)
189191

190192

191-
def test_save_load_results():
193+
def test_save_load_results(mc):
192194
# Currently not working as part of full tests
193195
# Works individually - need to look into this
194-
pass
195-
# mc.do_magnetic_calculation()
196-
# mc.save_results("EMagnetic")
197-
# assert os.path.exists(get_temp_files_dir_path() + r"\temp_test_file\EMag\outputResults.mot")
198-
# assert os.path.exists(get_temp_files_dir_path() + r"\temp_test_file\EMag\GraphResults.ini")
199-
#
200-
# mc.load_from_file(get_temp_files_dir_path() + r"\temp_test_file.mot")
201-
#
202-
# mc.load_results("EMagnetic")
203-
# assert mc.get_variable("MaxTorque") != 0
204-
#
205-
# reset_to_default_file(mc)
196+
197+
# EMag test
198+
mc.do_magnetic_calculation()
199+
mc.save_results("EMagnetic")
200+
assert os.path.exists(get_temp_files_dir_path() + r"\temp_test_file\EMag\outputResults.mot")
201+
assert os.path.exists(get_temp_files_dir_path() + r"\temp_test_file\EMag\GraphResults.ini")
202+
203+
mc.load_from_file(get_temp_files_dir_path() + r"\temp_test_file.mot")
204+
205+
mc.load_results("EMagnetic")
206+
assert mc.get_variable("MaxTorque") != 0
207+
208+
reset_to_default_file(mc)
209+
210+
# Thermal test - transient graphs only
211+
mc.do_transient_analysis()
212+
mc.save_results("Thermal")
213+
assert os.path.exists(get_temp_files_dir_path() + r"\temp_test_file\Thermal\GraphResults.ini")
214+
215+
mc.load_from_file(get_temp_files_dir_path() + r"\temp_test_file.mot")
216+
217+
mc.load_results("TheRmal")
218+
assert mc.get_power_graph_point("Armature Copper(Total)", 5) != 0
219+
220+
with pytest.raises(MotorCADError):
221+
mc.load_results("wrong_type")
222+
223+
with pytest.raises(MotorCADError):
224+
mc.save_results("wrong_type")
225+
reset_to_default_file(mc)
206226

207227

208228
def test_get_message(mc):

0 commit comments

Comments
 (0)