Skip to content

Commit

Permalink
Apply mesh sheets obj segmentation (#3932)
Browse files Browse the repository at this point in the history
* apply mesh sheets

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update pyaedt/modeler/modeler3d.py

Co-authored-by: Kathy Pippert <[email protected]>

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Kathy Pippert <[email protected]>
  • Loading branch information
3 people authored Dec 1, 2023
1 parent 0521483 commit 4f64da5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
5 changes: 4 additions & 1 deletion _unittest/test_28_Maxwell3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -819,14 +819,17 @@ def test_50_objects_segmentation(self, cyl_gap):
assert isinstance(sheets[0][object_name], list)
assert len(sheets[0][object_name]) == segments_number - 1
segments_number = 4
mesh_sheets_number = 3
object_name = "PM_I1_1"
magnet_id = [obj.id for obj in cyl_gap.modeler.object_list if obj.name == object_name][0]
sheets = cyl_gap.modeler.objects_segmentation(
magnet_id, segments_number=segments_number, apply_mesh_sheets=True
magnet_id, segments_number=segments_number, apply_mesh_sheets=True, mesh_sheets_number=mesh_sheets_number
)
assert isinstance(sheets, tuple)
assert isinstance(sheets[0][object_name], list)
assert len(sheets[0][object_name]) == segments_number - 1
assert isinstance(sheets[1][object_name], list)
assert len(sheets[1][object_name]) == mesh_sheets_number
segmentation_thickness = 1
object_name = "PM_O1"
magnet = [obj for obj in cyl_gap.modeler.object_list if obj.name == object_name][0]
Expand Down
27 changes: 21 additions & 6 deletions pyaedt/modeler/modeler3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -1269,7 +1269,12 @@ def import_from_openstreet_map(

@pyaedt_function_handler
def objects_segmentation(
self, objects_list, segmentation_thickness=None, segments_number=None, apply_mesh_sheets=False
self,
objects_list,
segmentation_thickness=None,
segments_number=None,
apply_mesh_sheets=False,
mesh_sheets_number=2,
):
"""Get segmentation of an object given the segmentation thickness or number of segments.
Expand All @@ -1288,6 +1293,9 @@ def objects_segmentation(
Whether to apply mesh sheets to selected objects.
Mesh sheets are needed in case the user would like to have additional layers
inside the objects for a finer mesh and more accurate results. The default is ``False``.
mesh_sheets_number : int, optional
Number of mesh sheets within one magnet segment.
If nothing is provided and ``apply_mesh_sheets=True``, the default value is ``2``.
Returns
-------
Expand Down Expand Up @@ -1333,11 +1341,18 @@ def objects_segmentation(
mesh_sheets = {}
mesh_objects = {}
# mesh sheets
self.move(face_object, [0, 0, segmentation_thickness / 4])
mesh_sheets[obj.name] = face_object.duplicate_along_line(
[0, 0, (segmentation_thickness * 2.0) / 4.0], segments_number * 2
)
mesh_objects[obj.name] = []
mesh_sheet_position = segmentation_thickness / (mesh_sheets_number + 1)
for i in range(len(segment_objects[obj.name]) + 1):
if i == 0:
face = obj.bottom_face_z
else:
face = segment_objects[obj.name][i - 1].faces[0]
mesh_face_object = self.create_object_from_face(face)
self.move(mesh_face_object, [0, 0, mesh_sheet_position])
mesh_sheets[obj.name] = mesh_face_object.duplicate_along_line(
[0, 0, mesh_sheet_position], mesh_sheets_number
)
mesh_objects[obj.name] = [mesh_face_object]
for value in mesh_sheets[obj.name]:
mesh_objects[obj.name].append([x for x in self.sheet_objects if x.name == value][0])
face_object.delete()
Expand Down

0 comments on commit 4f64da5

Please sign in to comment.