Skip to content

Commit

Permalink
Assign voltage to edges in Maxwell 2D (#5708)
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuelopez-ansys authored Jan 31, 2025
1 parent 8b5ad23 commit 10b9f89
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 20 deletions.
57 changes: 37 additions & 20 deletions src/ansys/aedt/core/maxwell.py
Original file line number Diff line number Diff line change
Expand Up @@ -949,12 +949,12 @@ def assign_rotate_motion(

@pyaedt_function_handler(face_list="assignment")
def assign_voltage(self, assignment, amplitude=1, name=None):
"""Assign a voltage source to a list of faces in Maxwell 3D or a list of objects in Maxwell 2D.
"""Assign a voltage source to a list of faces in Maxwell 3D or a list of objects or edges in Maxwell 2D.
Parameters
----------
assignment : list
List of faces or objects to assign a voltage source to.
List of faces, objects or edges to assign a voltage source to.
amplitude : float, optional
Voltage amplitude in mV. The default is ``1``.
name : str, optional
Expand All @@ -969,30 +969,47 @@ def assign_voltage(self, assignment, amplitude=1, name=None):
References
----------
>>> oModule.AssignVoltage
Examples
--------
Create a region in Maxwell 2D and assign voltage to its edges.
>>> from ansys.aedt.core import Maxwell2d
>>> m2d = Maxwell2d(version="2024.2", solution_type="ElectrostaticZ")
>>> region_id = m2d.modeler.create_region(pad_value=[500,50,50])
>>> voltage = m2d.assign_voltage(assignment=region_id.edges, amplitude=0, name = "GRD")
>>> m2d.release_desktop()
Create a region in Maxwell 3D and assign voltage to its edges.
>>> from ansys.aedt.core import Maxwell3d
>>> m3d = Maxwell3d(version="2024.2", solution_type="Electrostatic")
>>> region_id = m3d.modeler.create_box([0, 0, 0], [10, 10, 10])
>>> voltage = m3d.assign_voltage(assignment=region_id.faces, amplitude=0, name = "GRD")
>>> m3d.release_desktop()
"""
if isinstance(amplitude, (int, float)):
amplitude = str(amplitude) + "mV"
amplitude = f"{amplitude}mV"

if not name:
name = generate_unique_name("Voltage")
name = name or generate_unique_name("Voltage")
assignment = self.modeler.convert_to_selections(assignment, True)
is_maxwell_2d = self.design_type == "Maxwell 2D"
object_names_set = set(self.modeler.object_names)

props = {
"Voltage" if not is_maxwell_2d else "Value": amplitude,
"Objects": [],
"Faces": [] if not is_maxwell_2d else None,
"Edges": [] if is_maxwell_2d else None,
}

if self.design_type == "Maxwell 2D":
props = dict({"Objects": assignment, "Value": amplitude})
else:
if len(assignment) == 1:
if isinstance(assignment[0], str) and assignment[0] in self.modeler.object_names:
props = dict({"Objects": assignment, "Voltage": amplitude})
else:
props = dict({"Faces": assignment, "Value": amplitude})
for element in assignment:
if isinstance(element, str) and element in object_names_set:
props["Objects"].append(element)
else:
object_names_set = set(self.modeler.object_names)
props = dict({"Faces": [], "Objects": [], "Voltage": amplitude})
for element in assignment:
if isinstance(element, str) and element in object_names_set:
props["Objects"].append(element)
else:
props["Faces"].append(element)
key = "Edges" if is_maxwell_2d else "Faces"
props[key].append(element)

return self._create_boundary_object(name, props, "Voltage")

@pyaedt_function_handler(face_list="assignment")
Expand Down
13 changes: 13 additions & 0 deletions tests/system/general/test_27_Maxwell2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,3 +622,16 @@ def test_create_external_circuit(self, local_scratch, m2d_app):
match="No windings in the Maxwell design.",
):
m2d_app.create_external_circuit()

def test_assign_voltage(self, local_scratch, m2d_app):
m2d_app.solution_type = SOLUTIONS.Maxwell2d.ElectroStaticZ

region_id = m2d_app.modeler.create_region(pad_value=[500, 50, 50])
v1 = m2d_app.assign_voltage(assignment=region_id, amplitude=0, name="GRD1")
assert v1.properties["Value"] == "0mV"
assert len(m2d_app.boundaries) == 1
assert m2d_app.assign_voltage(assignment=region_id.edges[0], amplitude=1, name="GRD2")
assert m2d_app.assign_voltage(assignment=region_id.edges, amplitude=2, name="GRD3")
rect = m2d_app.modeler.create_rectangle([32, 1.5, 0], [8, 3], is_covered=True)
assert m2d_app.assign_voltage(assignment=[region_id.name, rect.name], amplitude=3, name="GRD4")
assert len(m2d_app.boundaries) == 4

0 comments on commit 10b9f89

Please sign in to comment.