Skip to content

Commit

Permalink
Merge branch 'main' into doc/typo
Browse files Browse the repository at this point in the history
  • Loading branch information
Devin-Crawford authored Jan 2, 2024
2 parents 5b55a50 + ba21b66 commit dc6eae1
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 120 deletions.
34 changes: 32 additions & 2 deletions _unittest/test_02_2D_modeler.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,19 @@ def test_03_objects(self):
assert self.aedtapp.modeler._omaterial_manager

def test_04_create_rectangle(self):
test_color = (220, 90, 0)
rect1 = self.aedtapp.modeler.create_rectangle([0, -2, -2], [3, 8])
rect2 = self.aedtapp.modeler.create_rectangle(
position=[10, -2, -2], dimension_list=[3, 10], name="MyRectangle", matname="Copper"
position=[10, -2, -2],
dimension_list=[3, 10],
name="MyRectangle",
material_name="Copper",
color=test_color,
)
assert rect1.solve_inside
assert rect1.model
assert rect1.material_name == "vacuum"
assert rect2.color == test_color
assert isclose(rect1.faces[0].area, 3.0 * 8.0)

list_of_pos = [ver.position for ver in rect1.vertices]
Expand Down Expand Up @@ -73,8 +79,15 @@ def test_05_create_rectangle_rz(self):

def test_06_create_circle(self):
circle1 = self.aedtapp.modeler.create_circle([0, -2, 0], 3)

# TODO: deprecate "matname" as named argument, replace it with the Object3D property "material_name"
circle2 = self.aedtapp.modeler.create_circle(
position=[0, -2, -2], radius=3, num_sides=6, name="MyCircle", matname="Copper"
position=[0, -2, -2],
radius=3,
num_sides=6,
name="MyCircle",
matname="Copper",
display_wireframe=True,
)
assert circle1.solve_inside
assert circle1.model
Expand All @@ -85,6 +98,22 @@ def test_06_create_circle(self):
assert circle2.model
assert circle2.material_name == "copper"
assert isclose(circle1.faces[0].area, math.pi * 3.0 * 3.0)
circle3 = self.aedtapp.modeler.create_circle(
position=[0, 4, -2],
radius=2,
num_sides=8,
name="Circle3",
material_name="Copper",
)
assert circle3.material_name == "copper"
circle4 = self.aedtapp.modeler.create_circle(
position=[0, -4, -2],
radius=2.2,
num_sides=6,
name="NonModelCirc",
model=False,
)
assert not circle4.model

def test_06a_calculate_radius_2D(self):
circle1 = self.aedtapp.modeler.create_circle([0, -2, 0], 3)
Expand Down Expand Up @@ -132,6 +161,7 @@ def test_08_create_regular_polygon(self):

@pytest.mark.skipif(is_linux or sys.version_info < (3, 8), reason="Not running in ironpython")
def test_09_plot(self):
self.aedtapp.solution_type = "MagnetostaticZ"
self.aedtapp.modeler.create_regular_polygon([0, 0, 0], [0, 0, 2])
self.aedtapp.modeler.create_regular_polygon(
position=[0, 0, 0], start_point=[0, 0, 2], num_sides=3, name="MyPolygon", matname="Copper"
Expand Down
32 changes: 25 additions & 7 deletions _unittest/test_02_3D_modeler.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,24 @@ def test_04_convert_to_selection(self):

def test_05_split(self):
self.aedtapp.insert_design("split_test")
box1 = self.aedtapp.modeler.create_box([-10, -10, -10], [20, 20, 20], "box_to_split")
box2 = self.aedtapp.modeler.create_box([-10, -10, -10], [20, 20, 20], "box_to_split2")
box1 = self.aedtapp.modeler.create_box([-10, -10, -10], [20, 20, 20], "box_to_split", color=(255, 0, 0))
assert box1.color == (255, 0, 0)
box2 = self.aedtapp.modeler.create_box([-10, -10, -10], [20, 20, 20], "box_to_split2", transparency=1)
assert box2.transparency == 1
split = self.aedtapp.modeler.split(box1.name, 2)
assert isinstance(split, list)
assert isinstance(split[0], str)
split2 = box2.split(1)
assert isinstance(split2, list)
assert box2.name in split2[0]
box3 = self.aedtapp.modeler.create_box([10, 10, 10], [20, 20, 20], "box_to_split3")
rect1 = self.aedtapp.modeler.create_rectangle(self.aedtapp.PLANE.XY, [10, 8, 20], [20, 30], name="rect1")
box3 = self.aedtapp.modeler.create_box([10, 10, 10], [20, 20, 20], "box_to_split3", display_wireframe=True)
assert box3.display_wireframe
rect1 = self.aedtapp.modeler.create_rectangle(
self.aedtapp.PLANE.XY, [10, 8, 20], [20, 30], name="rect1", transparency=0.5, display_wireframe=True
)
assert rect1.transparency == 0.5
assert rect1.display_wireframe
assert rect1.name == "rect1"
split = self.aedtapp.modeler.split(objects=box3, sides="Both", tool=rect1.id)
assert isinstance(split, list)
assert isinstance(split[0], str)
Expand Down Expand Up @@ -209,8 +217,10 @@ def test_17_unite(self):
assert self.aedtapp.modeler.unite([o1, o2], purge=True) == o1.name

def test_18_chamfer(self):
# TODO
assert True
o1 = self.aedtapp.modeler["box_to_split"]
assert abs(o1.volume - 4000.0) < tol
assert o1.top_edge_x.chamfer(1)
assert abs(o1.volume - 3990.0) < tol # Volume decreased

def test_19_clone(self):
self.restore_model()
Expand Down Expand Up @@ -1069,13 +1079,21 @@ def test_62_copy_solid_bodies_udm_3dcomponent(self, add_app):
obj_udm = self.aedtapp.modeler.create_udm(
udmfullname="Maxwell3D/OnDieSpiralInductor.py", udm_params_list=my_udmPairs, udm_library="syslib"
)

assert len(obj_udm.parts) == 5
names = [p.name for p in obj_udm.parts.values()]
assert "Inductor" in names
assert "Substrate" in names
compfile = self.aedtapp.components3d["Bowtie_DM"]
obj_3dcomp = self.aedtapp.modeler.insert_3d_component(compfile)
assert len(obj_3dcomp.parts) == 4
dest = add_app(design_name="IcepakDesign1", just_open=True)
dest.copy_solid_bodies_from(self.aedtapp, [obj_udm.name, obj_3dcomp.name])
assert len(dest.modeler.object_list) == 9
assert "Arm" in dest.modeler.object_names
dest.delete_design("IcepakDesign1")
dest = add_app(design_name="IcepakDesign2", just_open=True)
dest.copy_solid_bodies_from(self.aedtapp)
dest2 = add_app(design_name="uUSB")
dest2.copy_solid_bodies_from(self.aedtapp, [obj_udm.name, obj_3dcomp.name])
assert len(dest2.modeler.objects) == 9
assert "port1" in dest2.modeler.object_names
19 changes: 18 additions & 1 deletion pyaedt/modeler/cad/Primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -7895,7 +7895,7 @@ def _refresh_object_types(self):
self._all_object_names = self._solids + self._sheets + self._lines + self._points + self._unclassified

@pyaedt_function_handler()
def _create_object(self, name, pid=0, use_cached=False):
def _create_object(self, name, pid=0, use_cached=False, **kwargs):
if use_cached:
line_names = self._lines
else:
Expand Down Expand Up @@ -7926,6 +7926,23 @@ def _create_object(self, name, pid=0, use_cached=False):
new_id = o.id
self.objects[new_id] = o
self._object_names_to_ids[o.name] = new_id

# Set properties from kwargs.
if len(kwargs) > 0:
props = [
attr
for attr in dir(o)
if isinstance(getattr(type(o), attr, None), property) # Get a list of settable properties.
and getattr(type(o), attr).fset is not None
]
for k, val in kwargs.items():
if k in props: # Only try to set valid properties.
try:
setattr(o, k, val)
except:
self.logger.warning("Unable to assign " + str(k) + " to object " + o.name + ".")
else:
self.logger.error("'" + str(k) + "' is not a valid property of the primitive ")
return o

@pyaedt_function_handler()
Expand Down
40 changes: 30 additions & 10 deletions pyaedt/modeler/cad/Primitives2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Primitives2D(GeometryModeler, object):
def plane2d(self):
"""Create a 2D plane."""
plane = "Z"
if self._app.design_type == "Maxwell 2D":
if self._app.design_type == "Maxwell 2D": # Cylindrical symmetry about the z-axis.
if self._app._odesign.GetGeometryMode() == "about Z":
plane = "Y"
return plane
Expand All @@ -31,7 +31,9 @@ def __init__(self, application):
GeometryModeler.__init__(self, application, is3d=False)

@pyaedt_function_handler()
def create_circle(self, position, radius, num_sides=0, is_covered=True, name=None, matname=None, non_model=False):
def create_circle(
self, position, radius, num_sides=0, is_covered=True, name=None, matname=None, non_model=False, **kwargs
):
"""Create a circle.
Parameters
Expand All @@ -52,6 +54,9 @@ def create_circle(self, position, radius, num_sides=0, is_covered=True, name=Non
the default material is assigned.
non_model : bool, optional
Either to create the new object as model or non-model. The default is ``False``.
**kwargs : optional
Additional keyword arguments may be passed when creating the primitive to set properties. See
``pyaedt.modeler.cad.object3d.Object3d`` for more details.
Returns
Expand All @@ -72,6 +77,7 @@ def create_circle(self, position, radius, num_sides=0, is_covered=True, name=Non
"""
# TODO: kwargs such as 'matname' and 'nonmodel' should be deprecated.
szAxis = self.plane2d
XCenter, YCenter, ZCenter = self._pos_with_arg(position)
Radius = self._arg_with_dim(radius)
Expand All @@ -87,10 +93,12 @@ def create_circle(self, position, radius, num_sides=0, is_covered=True, name=Non

vArg2 = self._default_object_attributes(name=name, matname=matname, flags="NonModel#" if non_model else "")
new_object_name = self.oeditor.CreateCircle(vArg1, vArg2)
return self._create_object(new_object_name)
return self._create_object(new_object_name, **kwargs)

@pyaedt_function_handler()
def create_ellipse(self, position, major_radius, ratio, is_covered=True, name=None, matname=None, non_model=False):
def create_ellipse(
self, position, major_radius, ratio, is_covered=True, name=None, matname=None, non_model=False, **kwargs
):
"""Create an ellipse.
Parameters
Expand All @@ -111,6 +119,10 @@ def create_ellipse(self, position, major_radius, ratio, is_covered=True, name=No
the default material is assigned.
non_model : bool, optional
Either if create the new object as model or non-model. The default is ``False``.
**kwargs : optional
Additional keyword arguments may be passed when creating the primitive to set properties. See
``pyaedt.modeler.cad.object3d.Object3d`` for more details.
Returns
-------
Expand Down Expand Up @@ -142,10 +154,12 @@ def create_ellipse(self, position, major_radius, ratio, is_covered=True, name=No

vArg2 = self._default_object_attributes(name=name, matname=matname, flags="NonModel#" if non_model else "")
new_object_name = self.oeditor.CreateEllipse(vArg1, vArg2)
return self._create_object(new_object_name)
return self._create_object(new_object_name, **kwargs)

@pyaedt_function_handler()
def create_rectangle(self, position, dimension_list, is_covered=True, name=None, matname=None, non_model=False):
def create_rectangle(
self, position, dimension_list, is_covered=True, name=None, matname=None, non_model=False, **kwargs
):
"""Create a rectangle.
Parameters
Expand Down Expand Up @@ -182,6 +196,7 @@ def create_rectangle(self, position, dimension_list, is_covered=True, name=None,
... name="MyCircle", matname="Copper")
"""
# TODO: Primitives in Maxwell 2D must have Z=0, otherwise the transparency cannot be changed. (issue 4071)
axis = self.plane2d
x_start, y_start, z_start = self._pos_with_arg(position)
width = self._arg_with_dim(dimension_list[0])
Expand All @@ -198,10 +213,12 @@ def create_rectangle(self, position, dimension_list, is_covered=True, name=None,

vArg2 = self._default_object_attributes(name=name, matname=matname, flags="NonModel#" if non_model else "")
new_object_name = self.oeditor.CreateRectangle(vArg1, vArg2)
return self._create_object(new_object_name)
return self._create_object(new_object_name, **kwargs)

@pyaedt_function_handler()
def create_regular_polygon(self, position, start_point, num_sides=6, name=None, matname=None, non_model=False):
def create_regular_polygon(
self, position, start_point, num_sides=6, name=None, matname=None, non_model=False, **kwargs
):
"""Create a rectangle.
Parameters
Expand All @@ -220,6 +237,9 @@ def create_regular_polygon(self, position, start_point, num_sides=6, name=None,
the default material is assigned.
non_model : bool, optional
Either if create the new object as model or non-model. The default is ``False``.
**kwargs : optional
Additional keyword arguments may be passed when creating the primitive to set properties. See
``pyaedt.modeler.cad.object3d.Object3d`` for more details.
Returns
Expand All @@ -243,7 +263,7 @@ def create_regular_polygon(self, position, start_point, num_sides=6, name=None,
x_start, y_start, z_start = self._pos_with_arg(start_point)

n_sides = int(num_sides)
assert n_sides > 2
assert n_sides > 2 # TODO: Replace assert with an exception.

vArg1 = ["NAME:RegularPolygonParameters"]
vArg1.append("XCenter:="), vArg1.append(x_center)
Expand All @@ -258,7 +278,7 @@ def create_regular_polygon(self, position, start_point, num_sides=6, name=None,

vArg2 = self._default_object_attributes(name=name, matname=matname, flags="NonModel#" if non_model else "")
new_object_name = self.oeditor.CreateRegularPolygon(vArg1, vArg2)
return self._create_object(new_object_name)
return self._create_object(new_object_name, **kwargs)

@pyaedt_function_handler()
def create_region(self, pad_percent=300, is_percentage=True):
Expand Down
Loading

0 comments on commit dc6eae1

Please sign in to comment.