Skip to content

Commit 585b2e1

Browse files
mlkaplan36pre-commit-ci[bot]pyansys-ci-botRobPasMueRyanJWard
authored
feat: workflow enhancements for better tool results (#1723)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> Co-authored-by: Roberto Pastor Muela <37798125+RobPasMue@users.noreply.github.com> Co-authored-by: rward <ryan.ward@ansys.com> Co-authored-by: Ryan Ward <129954471+RyanJWard@users.noreply.github.com>
1 parent 1439fe4 commit 585b2e1

File tree

8 files changed

+322
-13
lines changed

8 files changed

+322
-13
lines changed

doc/changelog.d/1723.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
workflow enhancements for better tool results

src/ansys/geometry/core/designer/geometry_commands.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
ExtrudeFacesUpToRequest,
3636
FilletRequest,
3737
FullFilletRequest,
38+
ModifyCircularPatternRequest,
3839
ModifyLinearPatternRequest,
3940
PatternRequest,
4041
RenameObjectRequest,
@@ -744,6 +745,58 @@ def create_circular_pattern(
744745

745746
return result.result.success
746747

748+
@protect_grpc
749+
@min_backend_version(25, 2, 0)
750+
def modify_circular_pattern(
751+
self,
752+
selection: Union["Face", list["Face"]],
753+
circular_count: int = 0,
754+
linear_count: int = 0,
755+
step_angle: Real = 0.0,
756+
step_linear: Real = 0.0,
757+
) -> bool:
758+
"""Modify a circular pattern. Leave an argument at 0 for it to remain unchanged.
759+
760+
Parameters
761+
----------
762+
selection : Face | list[Face]
763+
Faces that belong to the pattern.
764+
circular_count : int, default: 0
765+
How many members are in the circular pattern.
766+
linear_count : int, default: 0
767+
How many times the circular pattern repeats along the radial lines for a
768+
two-dimensional pattern.
769+
step_angle : Real, default: 0.0
770+
Defines the circular angle.
771+
step_linear : Real, default: 0.0
772+
Defines the step, along the radial lines, for a pattern dimension greater than 1.
773+
774+
Returns
775+
-------
776+
bool
777+
``True`` when successful, ``False`` when failed.
778+
"""
779+
from ansys.geometry.core.designer.face import Face
780+
781+
selection: list[Face] = selection if isinstance(selection, list) else [selection]
782+
783+
check_type_all_elements_in_iterable(selection, Face)
784+
785+
for object in selection:
786+
object.body._reset_tessellation_cache()
787+
788+
result = self._commands_stub.ModifyCircularPattern(
789+
ModifyCircularPatternRequest(
790+
selection=[object._grpc_id for object in selection],
791+
circular_count=circular_count,
792+
linear_count=linear_count,
793+
step_angle=step_angle,
794+
step_linear=step_linear,
795+
)
796+
)
797+
798+
return result.result.success
799+
747800
@protect_grpc
748801
@min_backend_version(25, 2, 0)
749802
def create_fill_pattern(

src/ansys/geometry/core/tools/prepare_tools.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
get_design_from_face,
4242
)
4343
from ansys.geometry.core.misc.checks import check_type_all_elements_in_iterable, min_backend_version
44+
from ansys.geometry.core.tools.repair_tool_message import RepairToolMessage
4445
from ansys.geometry.core.typing import Real
4546

4647
if TYPE_CHECKING: # pragma: no cover
@@ -204,3 +205,49 @@ def share_topology(
204205
)
205206
)
206207
return share_topo_response.result
208+
209+
@protect_grpc
210+
@min_backend_version(25, 2, 0)
211+
def enhanced_share_topology(
212+
self, bodies: list["Body"], tol: Real = 0.0, preserve_instances: bool = False
213+
) -> RepairToolMessage:
214+
"""Share topology between the chosen bodies.
215+
216+
Parameters
217+
----------
218+
bodies : list[Body]
219+
List of bodies to share topology between.
220+
tol : Real
221+
Maximum distance between bodies.
222+
preserve_instances : bool
223+
Whether instances are preserved.
224+
225+
Returns
226+
-------
227+
RepairToolMessage
228+
Message containing number of problem areas found/fixed, created and/or modified bodies.
229+
"""
230+
from ansys.geometry.core.designer.body import Body
231+
232+
if not bodies:
233+
return RepairToolMessage(False, [], [], 0, 0)
234+
235+
# Verify inputs
236+
check_type_all_elements_in_iterable(bodies, Body)
237+
238+
share_topo_response = self._prepare_stub.EnhancedShareTopology(
239+
ShareTopologyRequest(
240+
selection=[GRPCBody(id=body.id) for body in bodies],
241+
tolerance=DoubleValue(value=tol),
242+
preserve_instances=BoolValue(value=preserve_instances),
243+
)
244+
)
245+
246+
message = RepairToolMessage(
247+
share_topo_response.success,
248+
share_topo_response.created_bodies_monikers,
249+
share_topo_response.modified_bodies_monikers,
250+
share_topo_response.found,
251+
share_topo_response.repaired,
252+
)
253+
return message

src/ansys/geometry/core/tools/repair_tool_message.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,14 @@
2525
class RepairToolMessage:
2626
"""Provides return message for the repair tool methods."""
2727

28-
def __init__(self, success: bool, created_bodies: list[str], modified_bodies: list[str]):
28+
def __init__(
29+
self,
30+
success: bool,
31+
created_bodies: list[str],
32+
modified_bodies: list[str],
33+
found: int = -1,
34+
repaired: int = -1,
35+
):
2936
"""Initialize a new instance of the extra edge problem area class.
3037
3138
Parameters
@@ -36,10 +43,20 @@ def __init__(self, success: bool, created_bodies: list[str], modified_bodies: li
3643
List of bodies created after the repair operation.
3744
modified_bodies: list[str]
3845
List of bodies modified after the repair operation.
46+
found: int, default: -1
47+
Number of problem areas found for the repair operation.
48+
If default, the operation does not provide the number of found problem areas.
49+
repaired: int, default: -1
50+
Number of problem areas repaired during the repair operation.
51+
If default, the operation does not provide the number of fixed problem areas.
52+
53+
3954
"""
4055
self._success = success
4156
self._created_bodies = created_bodies
4257
self._modified_bodies = modified_bodies
58+
self._found = found
59+
self._repaired = repaired
4360

4461
@property
4562
def success(self) -> bool:
@@ -55,3 +72,13 @@ def created_bodies(self) -> list[str]:
5572
def modified_bodies(self) -> list[str]:
5673
"""The list of the modified bodies after the repair operation."""
5774
return self._modified_bodies
75+
76+
@property
77+
def found(self) -> int:
78+
"""Number of problem areas found for the repair operation."""
79+
return self._found
80+
81+
@property
82+
def repaired(self) -> int:
83+
"""Number of problem areas repaired during the repair operation."""
84+
return self._repaired

src/ansys/geometry/core/tools/repair_tools.py

Lines changed: 88 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ def find_interferences(
470470
@protect_grpc
471471
@min_backend_version(25, 2, 0)
472472
def find_and_fix_short_edges(
473-
self, bodies: list["Body"], length: Real = 0.0
473+
self, bodies: list["Body"], length: Real = 0.0, comprehensive_result: bool = False
474474
) -> RepairToolMessage:
475475
"""Find and fix the short edge problem areas.
476476
@@ -484,24 +484,29 @@ def find_and_fix_short_edges(
484484
List of bodies that short edges are investigated on.
485485
length : Real, optional
486486
The maximum length of the edges. By default, 0.0.
487+
comprehensive_result : bool, optional
488+
Whether to fix all problem areas individually.
489+
By default, False.
487490
488491
Returns
489492
-------
490493
RepairToolMessage
491-
Message containing created and/or modified bodies.
494+
Message containing number of problem areas found/fixed, created and/or modified bodies.
492495
"""
493496
from ansys.geometry.core.designer.body import Body
494497

495498
check_type_all_elements_in_iterable(bodies, Body)
496499
check_type(length, Real)
500+
check_type(comprehensive_result, bool)
497501

498502
if not bodies:
499-
return RepairToolMessage(False, [], [])
503+
return RepairToolMessage(False, [], [], 0, 0)
500504

501505
response = self._repair_stub.FindAndFixShortEdges(
502506
FindShortEdgesRequest(
503507
selection=[body.id for body in bodies],
504508
max_edge_length=DoubleValue(value=length),
509+
comprehensive=comprehensive_result,
505510
)
506511
)
507512

@@ -511,12 +516,16 @@ def find_and_fix_short_edges(
511516
response.success,
512517
response.created_bodies_monikers,
513518
response.modified_bodies_monikers,
519+
response.found,
520+
response.repaired,
514521
)
515522
return message
516523

517524
@protect_grpc
518525
@min_backend_version(25, 2, 0)
519-
def find_and_fix_extra_edges(self, bodies: list["Body"]) -> RepairToolMessage:
526+
def find_and_fix_extra_edges(
527+
self, bodies: list["Body"], comprehensive_result: bool = False
528+
) -> RepairToolMessage:
520529
"""Find and fix the extra edge problem areas.
521530
522531
Notes
@@ -529,22 +538,26 @@ def find_and_fix_extra_edges(self, bodies: list["Body"]) -> RepairToolMessage:
529538
List of bodies that short edges are investigated on.
530539
length : Real
531540
The maximum length of the edges.
541+
comprehensive_result : bool, optional
542+
Whether to fix all problem areas individually.
543+
By default, False.
532544
533545
Returns
534546
-------
535547
RepairToolMessage
536-
Message containing created and/or modified bodies.
548+
Message containing number of problem areas found/fixed, created and/or modified bodies.
537549
"""
538550
from ansys.geometry.core.designer.body import Body
539551

540552
check_type_all_elements_in_iterable(bodies, Body)
553+
check_type(comprehensive_result, bool)
541554

542555
if not bodies:
543-
return RepairToolMessage(False, [], [])
556+
return RepairToolMessage(False, [], [], 0, 0)
544557

545558
response = self._repair_stub.FindAndFixExtraEdges(
546559
FindExtraEdgesRequest(
547-
selection=[body.id for body in bodies],
560+
selection=[body.id for body in bodies], comprehensive=comprehensive_result
548561
)
549562
)
550563

@@ -554,13 +567,19 @@ def find_and_fix_extra_edges(self, bodies: list["Body"]) -> RepairToolMessage:
554567
response.success,
555568
response.created_bodies_monikers,
556569
response.modified_bodies_monikers,
570+
response.found,
571+
response.repaired,
557572
)
558573
return message
559574

560575
@protect_grpc
561576
@min_backend_version(25, 2, 0)
562577
def find_and_fix_split_edges(
563-
self, bodies: list["Body"], angle: Real = 0.0, length: Real = 0.0
578+
self,
579+
bodies: list["Body"],
580+
angle: Real = 0.0,
581+
length: Real = 0.0,
582+
comprehensive_result: bool = False,
564583
) -> RepairToolMessage:
565584
"""Find and fix the split edge problem areas.
566585
@@ -576,28 +595,35 @@ def find_and_fix_split_edges(
576595
The maximum angle between edges. By default, 0.0.
577596
length : Real, optional
578597
The maximum length of the edges. By default, 0.0.
598+
comprehensive_result : bool, optional
599+
Whether to fix all problem areas individually.
600+
By default, False.
579601
580602
Returns
581603
-------
582604
RepairToolMessage
583-
Message containing created and/or modified bodies.
605+
Message containing number of problem areas found/fixed, created and/or modified bodies.
584606
"""
585607
from ansys.geometry.core.designer.body import Body
586608

587609
check_type_all_elements_in_iterable(bodies, Body)
588610
check_type(angle, Real)
589611
check_type(length, Real)
612+
check_type(comprehensive_result, bool)
590613

591614
if not bodies:
592-
return RepairToolMessage(False, [], [])
615+
return RepairToolMessage(False, [], [], 0, 0)
593616

594617
angle_value = DoubleValue(value=float(angle))
595618
length_value = DoubleValue(value=float(length))
596619
body_ids = [body.id for body in bodies]
597620

598621
response = self._repair_stub.FindAndFixSplitEdges(
599622
FindSplitEdgesRequest(
600-
bodies_or_faces=body_ids, angle=angle_value, distance=length_value
623+
bodies_or_faces=body_ids,
624+
angle=angle_value,
625+
distance=length_value,
626+
comprehensive=comprehensive_result,
601627
)
602628
)
603629

@@ -607,6 +633,57 @@ def find_and_fix_split_edges(
607633
response.success,
608634
response.created_bodies_monikers,
609635
response.modified_bodies_monikers,
636+
response.found,
637+
response.repaired,
638+
)
639+
return message
640+
641+
@protect_grpc
642+
@min_backend_version(25, 2, 0)
643+
def find_and_fix_simplify(
644+
self, bodies: list["Body"], comprehensive_result: bool = False
645+
) -> RepairToolMessage:
646+
"""Find and simplify the provided geometry.
647+
648+
Notes
649+
-----
650+
This method simplifies the provided geometry.
651+
652+
Parameters
653+
----------
654+
bodies : list[Body]
655+
List of bodies to be simplified.
656+
comprehensive_result : bool, optional
657+
Whether to fix all problem areas individually.
658+
By default, False.
659+
660+
Returns
661+
-------
662+
RepairToolMessage
663+
Message containing number of problem areas found/fixed, created and/or modified bodies.
664+
"""
665+
from ansys.geometry.core.designer.body import Body
666+
667+
check_type_all_elements_in_iterable(bodies, Body)
668+
check_type(comprehensive_result, bool)
669+
670+
if not bodies:
671+
return RepairToolMessage(False, [], [], 0, 0)
672+
673+
body_ids = [body.id for body in bodies]
674+
675+
response = self._repair_stub.FindAndSimplify(
676+
FindAdjustSimplifyRequest(selection=body_ids, comprehensive=comprehensive_result)
677+
)
678+
679+
parent_design = get_design_from_body(bodies[0])
680+
parent_design._update_design_inplace()
681+
message = RepairToolMessage(
682+
response.success,
683+
response.created_bodies_monikers,
684+
response.modified_bodies_monikers,
685+
response.found,
686+
response.repaired,
610687
)
611688
return message
612689

0 commit comments

Comments
 (0)