Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/pip/pytest-cov-6.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jgsdavies authored Nov 12, 2024
2 parents ca499cf + 3dad907 commit db84aa2
Show file tree
Hide file tree
Showing 12 changed files with 28,170 additions and 216 deletions.
8 changes: 1 addition & 7 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
* @jgsdavies @ravi-ansys @JackB-Ansys @MatthewAnsys

# Geometry
/doc/source/methods/geometry_functions.rst @MatthewAnsys @jgsdavies
/src/ansys/motorcad/core/geometry.py @MatthewAnsys @jgsdavies
/tests/test_geometry.py @MatthewAnsys @jgsdavies
/src/ansys/motorcad/core/methods/rpc_methods_geometry.py @MatthewAnsys @jgsdavies
* @jgsdavies @ravi-ansys @JackB-Ansys @MatthewAnsys @james-packer
1 change: 0 additions & 1 deletion .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ jobs:
with:
cname: ${{ env.DOCUMENTATION_CNAME }}
token: ${{ secrets.GITHUB_TOKEN }}
python-version: ${{ env.MAIN_PYTHON_VERSION }}
bot-user: ${{ secrets.PYANSYS_CI_BOT_USERNAME }}
bot-email: ${{ secrets.PYANSYS_CI_BOT_EMAIL }}

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,5 @@ doc/source/examples/gallery_examples/*
/tests/test_files/base_test_file/*
/tests/test_files/SaveLoadFiles/*
/tests/test_files/SaveLoadFiles.mot
/tests/test_files/adaptive_template_testing_lam_rotor_region/*
/tests/test_files/adaptive_template_testing_solid_rotor_region/*
6 changes: 3 additions & 3 deletions examples/links/thermal_twinbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
# 3. The cooling system nodes and flow path are identified and saved to the ``CoolingSystems.csv``
# file
# 4. For each desired speed, the thermal model is solved and thermal matrices exported and saved to
# the ``dpx`` folders
# the ``dpxxxxxx`` folders
# 5. The distribution of the losses onto the individual nodes is determined and saved to the
# ``LossDistribution.csv`` file
# 6. Natural convection cooling of the Housing is characterized and saved to the
Expand Down Expand Up @@ -535,7 +535,7 @@ def generateSamples(self, parameters: dict):

for index, rpm in enumerate(rpmSamples):
print("DoE : computing sample point rpm = " + str(rpm))
exportDirectory = os.path.join(self.outputDirectory, "dp" + str(index))
exportDirectory = os.path.join(self.outputDirectory, "dp" + str(index).zfill(6))
self.computeMatrices(exportDirectory, rpm=rpm)

# write doe file
Expand All @@ -548,7 +548,7 @@ def generateSamples(self, parameters: dict):
cf.write(", " + str(parameterName))
cf.write("\n")
for i in range(0, nbDPs):
cf.write("dp" + str(i))
cf.write("dp" + str(i).zfill(6))
for j in range(0, len(parameterNames)):
cf.write(", " + str(parameterValues[j][i]))
cf.write("\n")
Expand Down
55 changes: 55 additions & 0 deletions src/ansys/motorcad/core/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ def __init__(self, motorcad_instance=None):
self._motorcad_instance = motorcad_instance
self._region_type = RegionType.adaptive
self.mesh_length = 0
self._linked_region = None
self._singular = False
self._lamination_type = ""

def __eq__(self, other):
"""Override the default equals implementation for Region."""
Expand Down Expand Up @@ -189,6 +192,12 @@ def _from_json(cls, json, motorcad_instance=None):
if "mesh_length" in json:
new_region.mesh_length = json["mesh_length"]

if "singular" in json:
new_region._singular = json["singular"]

if "lamination_type" in json:
new_region._lamination_type = json["lamination_type"]

return new_region

# method to convert python object to send to Motor-CAD
Expand All @@ -200,6 +209,11 @@ def _to_json(self):
dict
Geometry region json representation
"""
if self._region_type == RegionType.adaptive:
lamination_type = self.lamination_type
else:
lamination_type = ""

region_dict = {
"name": self.name,
"material": self.material,
Expand All @@ -212,6 +226,9 @@ def _to_json(self):
"parent_name": self.parent_name,
"region_type": self._region_type.value,
"mesh_length": self.mesh_length,
"on_boundary": False if self._linked_region is None else True,
"singular": self._singular,
"lamination_type": lamination_type,
}

return region_dict
Expand Down Expand Up @@ -253,6 +270,25 @@ def parent_name(self):
def parent_name(self, name):
self._parent_name = name

@property
def linked_region(self):
"""Get linked duplication/unite region."""
return self._linked_region

@linked_region.setter
def linked_region(self, region):
self._linked_region = region
region._linked_region = self

@property
def singular(self):
"""Get linked duplication/unite region."""
return self._singular

@singular.setter
def singular(self, singular):
self._singular = singular

@property
def child_names(self):
"""Property for child names list.
Expand Down Expand Up @@ -314,6 +350,25 @@ def parent(self):
def parent(self, region):
self._parent_name = region.name

@property
def lamination_type(self):
"""Return lamination type of region from Motor-CAD.
Returns
-------
string
"""
return self._lamination_type

@lamination_type.setter
def lamination_type(self, lamination_type):
if self.region_type == RegionType.adaptive:
self._lamination_type = lamination_type
else:
raise Exception(
"It is currently only possible to set lamination type for adaptive regions"
)

def subtract(self, region):
"""Subtract region from self, returning any additional regions.
Expand Down
112 changes: 101 additions & 11 deletions src/ansys/motorcad/core/methods/rpc_methods_graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,20 @@
# SOFTWARE.

"""RPC methods for graphs."""
from dataclasses import dataclass

from ansys.motorcad.core.rpc_client_core import MotorCADError


@dataclass
class Magnetic3dGraph:
"""Class for x, y and data from a magnetic 3d graph."""

x: list
y: list
data: list


class _RpcMethodsGraphs:
def __init__(self, mc_connection):
self.connection = mc_connection
Expand Down Expand Up @@ -143,7 +154,8 @@ def get_magnetic_3d_graph_point(self, graph_name, slice_number, point_number, ti
graph_name : str, int
Name (preferred) or ID of the graph. In Motor-CAD, you can
select **Help -> Graph Viewer** to see the graph name.
slice_number
slice_number : int
Which skew slice to get results from. Slice 1 is the first.
point_number : int
Point number to get x and y coordinate values from.
Expand All @@ -168,7 +180,8 @@ def get_fea_graph_point(self, graph_id, slice_number, point_number, time_step_nu
graph_id : str, int
Name (preferred) or ID of the graph. In Motor-CAD, you can
select **Help -> Graph Viewer** to see the graph name.
slice_number
slice_number : int
Which skew slice to get results from. Slice 1 is the first.
point_number : int
Point number to get x and y coordinate values from.
Expand Down Expand Up @@ -200,10 +213,12 @@ def get_magnetic_graph(self, graph_name):
y_values : list
Value of y coordinates from graph
"""
loop = 0
x_array = []
y_array = []
return self._get_graph(self.get_magnetic_graph_point, graph_name)
if self.connection.check_version_at_least("2025.0"):
method = "GetGenericGraph"
params = [{"variant": graph_name}, "MagneticDataSource", -1, -1]
return self.connection.send_and_receive(method, params)
else:
return self._get_graph(self.get_magnetic_graph_point, graph_name)

def get_temperature_graph(self, graph_name):
"""Get graph points from a Motor-CAD transient temperature graph.
Expand All @@ -220,10 +235,12 @@ def get_temperature_graph(self, graph_name):
y_values : list
value of y coordinates from graph
"""
loop = 0
x_array = []
y_array = []
return self._get_graph(self.get_temperature_graph_point, graph_name)
if self.connection.check_version_at_least("2025.0"):
method = "GetGenericGraph"
params = [{"variant": graph_name}, "TransientDataSource", -1, -1]
return self.connection.send_and_receive(method, params)
else:
return self._get_graph(self.get_temperature_graph_point, graph_name)

def get_power_graph(self, graph_name):
"""Get graph points from a Motor-CAD transient power loss graph.
Expand All @@ -240,4 +257,77 @@ def get_power_graph(self, graph_name):
y_values : list
value of y coordinates from graph
"""
return self._get_graph(self.get_power_graph_point, graph_name)
if self.connection.check_version_at_least("2025.0"):
method = "GetGenericGraph"
params = [{"variant": graph_name}, "PowerDataSource", -1, -1]
return self.connection.send_and_receive(method, params)
else:
return self._get_graph(self.get_power_graph_point, graph_name)

def get_heatflow_graph(self, graph_name):
"""Get graph points from a Motor-CAD heat flow graph.
Parameters
----------
graph_name : str, int
Name (preferred) or ID of the graph. In Motor-CAD, you can
select **Help -> Graph Viewer** to see the graph name.
Returns
-------
x_values : list
value of x coordinates from graph
y_values : list
value of y coordinates from graph
"""
self.connection.ensure_version_at_least("2025.0")
method = "GetGenericGraph"
params = [{"variant": graph_name}, "HeatFlowDataSource", -1, -1]
return self.connection.send_and_receive(method, params)

def get_fea_graph(self, graph_name, slice_number, point_number=0):
"""Get graph points from a Motor-CAD FEA graph.
Parameters
----------
graph_name : str, int
Name (preferred) or ID of the graph. In Motor-CAD, you can
select **Help -> Graph Viewer** to see the graph name.
slice_number : int
Which skew slice to get results from. Slice 1 is the first.
point_number : int
Point number to get x and y coordinate arrays from for
transient graphs.
Returns
-------
x_values : list
value of x coordinates from graph
y_values : list
value of y coordinates from graph
"""
self.connection.ensure_version_at_least("2025.0")
method = "GetGenericGraph"
params = [{"variant": graph_name}, "FEAPathDataSource", slice_number, point_number]
return self.connection.send_and_receive(method, params)

def get_magnetic_3d_graph(self, graph_name, slice_number):
"""Get graph points from a Motor-CAD Magnetic 3d graph.
Parameters
----------
graph_name : str, int
Name (preferred) or ID of the graph. In Motor-CAD, you can
select **Help -> Graph Viewer** to see the graph name.
slice_number : int
Which skew slice to get results from. Slice 1 is the first.
Returns
-------
Magnetic3dGraph
Class containing x, y and data as lists
"""
self.connection.ensure_version_at_least("2025.0")
method = "GetMagnetic3DGraph"
params = [{"variant": graph_name}, slice_number]
graph_3d_dict = self.connection.send_and_receive(method, params)
return Magnetic3dGraph(**graph_3d_dict)
8 changes: 2 additions & 6 deletions tests/test_calculations.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,13 @@

# import os

from RPC_Test_Common import ( # get_temp_files_dir_path
almost_equal,
get_dir_path,
reset_to_default_file,
)
from RPC_Test_Common import almost_equal, almost_equal_fixed, get_dir_path, reset_to_default_file


def test_do_magnetic_thermal_calculation(mc):
mc.do_magnetic_thermal_calculation()

assert almost_equal(mc.get_variable("ArmatureConductor_Temperature"), 134, 0)
assert almost_equal_fixed(mc.get_variable("ArmatureConductor_Temperature"), 134, 10)


# def test_calculate_saturation_map():
Expand Down
Loading

0 comments on commit db84aa2

Please sign in to comment.