Skip to content

Commit 8a30b49

Browse files
gmalinvePipKat
andauthored
FEAT: MaxwellMatrix class (#4855)
Co-authored-by: Kathy Pippert <[email protected]>
1 parent c4cde69 commit 8a30b49

File tree

2 files changed

+146
-3
lines changed

2 files changed

+146
-3
lines changed

_unittest/test_28_Maxwell3D.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,14 @@ def test_32a_matrix(self, add_app):
525525
m3d.assign_current(rectangle4.faces[0], amplitude=1, name="Cur4")
526526

527527
L = m3d.assign_matrix(assignment=["Cur1", "Cur2", "Cur3"], matrix_name="Matrix1")
528+
assert not L.reduced_matrices
529+
m3d.solution_type = SOLUTIONS.Maxwell3d.Magnetostatic
530+
out = L.join_series(sources=["Cur1", "Cur2"], matrix_name="ReducedMatrix3")
531+
assert not out[0]
532+
assert not out[1]
533+
m3d.solution_type = SOLUTIONS.Maxwell3d.EddyCurrent
528534
out = L.join_series(sources=["Cur1", "Cur2"], matrix_name="ReducedMatrix1")
535+
assert L.reduced_matrices
529536
assert isinstance(out[0], str)
530537
assert isinstance(out[1], str)
531538
out = L.join_parallel(["Cur1", "Cur3"], matrix_name="ReducedMatrix2")
@@ -534,7 +541,27 @@ def test_32a_matrix(self, add_app):
534541
out = L.join_parallel(["Cur5"])
535542
assert not out[0]
536543

537-
def test_32b_export_rl_matrix(self):
544+
def test_32b_reduced_matrix(self):
545+
self.aedtapp.set_active_design("Matrix2")
546+
parent_matrix = [m for m in self.aedtapp.boundaries if m.type == "Matrix"][0]
547+
assert parent_matrix.reduced_matrices
548+
reduced_matrix_1 = parent_matrix.reduced_matrices[0]
549+
assert reduced_matrix_1.name == "ReducedMatrix1"
550+
assert reduced_matrix_1.parent_matrix == parent_matrix.name
551+
source_name = list(reduced_matrix_1.sources.keys())[0]
552+
assert reduced_matrix_1.update(old_source=source_name, source_type="series", new_source="new_series")
553+
assert list(reduced_matrix_1.sources.keys())[0] == "new_series"
554+
assert reduced_matrix_1.sources["new_series"] == "Cur1, Cur2"
555+
assert reduced_matrix_1.update(old_source="new_series", source_type="series", new_excitations="Cur2, Cur3")
556+
assert list(reduced_matrix_1.sources.keys())[0] == "new_series"
557+
assert reduced_matrix_1.sources["new_series"] == "Cur2, Cur3"
558+
assert not reduced_matrix_1.update(old_source="invalid", source_type="series", new_excitations="Cur2, Cur3")
559+
assert not reduced_matrix_1.update(old_source="new_series", source_type="invalid", new_excitations="Cur2, Cur3")
560+
assert not reduced_matrix_1.delete(source="invalid")
561+
assert reduced_matrix_1.delete(source="new_series")
562+
assert len(parent_matrix.reduced_matrices) == 1
563+
564+
def test_32c_export_rl_matrix(self):
538565
self.aedtapp.set_active_design("Matrix2")
539566
L = self.aedtapp.assign_matrix(assignment=["Cur1", "Cur2", "Cur3"], matrix_name="matrix_export_test")
540567
L.join_series(["Cur1", "Cur2"], matrix_name="reduced_matrix_export_test")
@@ -553,7 +580,7 @@ def test_32b_export_rl_matrix(self):
553580
assert self.aedtapp.export_rl_matrix("matrix_export_test", export_path_2, False, 10, 3, True)
554581
assert os.path.exists(export_path_2)
555582

556-
def test_32c_post_processing(self):
583+
def test_32d_post_processing(self):
557584
expressions = self.aedtapp.post.available_report_quantities(
558585
report_category="EddyCurrent", display_type="Data Table", context={"Matrix1": "ReducedMatrix1"}
559586
)

pyaedt/modules/Boundary.py

Lines changed: 117 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1414,6 +1414,33 @@ def __init__(self, app, name, props=None, boundarytype=None):
14141414
self.type = boundarytype
14151415
self._boundary_name = self.name
14161416
self.auto_update = True
1417+
self.__reduced_matrices = None
1418+
self.matrix_assignment = None
1419+
1420+
@property
1421+
def reduced_matrices(self):
1422+
"""List of reduced matrix groups for the parent matrix.
1423+
1424+
Returns
1425+
-------
1426+
dict
1427+
Dictionary of reduced matrices where the key is the name of the parent matrix
1428+
and the values are in a list of reduced matrix groups.
1429+
"""
1430+
if self._app.solution_type == "EddyCurrent":
1431+
self.__reduced_matrices = {}
1432+
cc = self._app.odesign.GetChildObject("Parameters")
1433+
parents = cc.GetChildNames()
1434+
if self.name in parents:
1435+
parent_object = self._app.odesign.GetChildObject("Parameters").GetChildObject(self.name)
1436+
parent_type = parent_object.GetPropValue("Type")
1437+
if parent_type == "Matrix":
1438+
self.matrix_assignment = parent_object.GetPropValue("Selection").split(",")
1439+
child_names = parent_object.GetChildNames()
1440+
self.__reduced_matrices = []
1441+
for r in child_names:
1442+
self.__reduced_matrices.append(MaxwellMatrix(self._app, self.name, r))
1443+
return self.__reduced_matrices
14171444

14181445
@property
14191446
def object_properties(self):
@@ -1530,6 +1557,9 @@ def update(self):
15301557

15311558
@pyaedt_function_handler()
15321559
def _create_matrix_reduction(self, red_type, sources, matrix_name=None, join_name=None):
1560+
if not self._app.solution_type == "EddyCurrent":
1561+
self._app.logger.error("Matrix reduction is possible only in Eddy current solvers.")
1562+
return False, False
15331563
if not matrix_name:
15341564
matrix_name = generate_unique_name("ReducedMatrix", n=3)
15351565
if not join_name:
@@ -1592,8 +1622,94 @@ def join_parallel(self, sources, matrix_name=None, join_name=None):
15921622
)
15931623

15941624

1625+
class MaxwellMatrix(object):
1626+
def __init__(self, app, parent_name, reduced_name):
1627+
self._app = app
1628+
self.parent_matrix = parent_name
1629+
self.name = reduced_name
1630+
self.__sources = None
1631+
1632+
@property
1633+
def sources(self):
1634+
"""List of matrix sources."""
1635+
if self._app.solution_type == "EddyCurrent":
1636+
sources = (
1637+
self._app.odesign.GetChildObject("Parameters")
1638+
.GetChildObject(self.parent_matrix)
1639+
.GetChildObject(self.name)
1640+
.GetChildNames()
1641+
)
1642+
self.__sources = {}
1643+
for s in sources:
1644+
excitations = (
1645+
self._app.odesign.GetChildObject("Parameters")
1646+
.GetChildObject(self.parent_matrix)
1647+
.GetChildObject(self.name)
1648+
.GetChildObject(s)
1649+
.GetPropValue("Source")
1650+
)
1651+
self.__sources[s] = excitations
1652+
return self.__sources
1653+
1654+
@pyaedt_function_handler()
1655+
def update(self, old_source, source_type, new_source=None, new_excitations=None):
1656+
"""Update the reduced matrix.
1657+
1658+
Parameters
1659+
----------
1660+
old_source : str
1661+
Original name of the source to update.
1662+
source_type : str
1663+
Source type, which can be ``Series`` or ``Parallel``.
1664+
new_source : str, optional
1665+
New name of the source to update.
1666+
The default value is the old source name.
1667+
new_excitations : str, optional
1668+
List of excitations to include in the matrix reduction.
1669+
The default values are excitations included in the source to update.
1670+
1671+
Returns
1672+
-------
1673+
bool
1674+
``True`` when successful, ``False`` when failed.
1675+
"""
1676+
if old_source not in self.sources.keys():
1677+
self._app.logger.error("Source does not exist.")
1678+
return False
1679+
else:
1680+
new_excitations = self.sources[old_source] if not new_excitations else new_excitations
1681+
if source_type.lower() not in ["series", "parallel"]:
1682+
self._app.logger.error("Join type not valid.")
1683+
return False
1684+
if not new_source:
1685+
new_source = old_source
1686+
args = ["NAME:" + new_source, "Type:=", "Join in " + source_type, "Sources:=", new_excitations]
1687+
self._app.o_maxwell_parameters.EditReduceOp(self.parent_matrix, self.name, old_source, args)
1688+
return True
1689+
1690+
@pyaedt_function_handler()
1691+
def delete(self, source):
1692+
"""Delete a specified source in a reduced matrix.
1693+
1694+
Parameters
1695+
----------
1696+
source : string
1697+
Name of the source to delete.
1698+
1699+
Returns
1700+
-------
1701+
bool
1702+
``True`` when successful, ``False`` when failed.
1703+
"""
1704+
if source not in self.sources.keys():
1705+
self._app.logger.error("Invalid source name.")
1706+
return False
1707+
self._app.o_maxwell_parameters.DeleteReduceOp(self.parent_matrix, self.name, source)
1708+
return True
1709+
1710+
15951711
class FieldSetup(BoundaryCommon, object):
1596-
"""Manages Far Field and Near Field Component data and execution.
1712+
"""Manages far field and near field component data and execution.
15971713
15981714
Examples
15991715
--------

0 commit comments

Comments
 (0)