Closed PatilSuneel closed 1 month ago
Hi @PatilSuneel! Thanks for opening this issue. Let me try it out locally and get back to you.
Okay so... I came up with a minimal failing example. The problem is not with the looping itself but actually with case 50 for your above script. Try running this script on your side, you will see that it also fails:
from pint import Quantity
from ansys.geometry.core import launch_modeler
from ansys.geometry.core.designer import Design
from ansys.geometry.core.math import Point2D
from ansys.geometry.core.misc import UNITS, Distance
from ansys.geometry.core.sketch import Sketch
modeler = launch_modeler(mode="spaceclaim")
outer_hole_radius = Distance(0.5, UNITS.m)
design = modeler.create_design("ExtrudedPlate")
def extrude_body(outer_hole_radius: Distance, design: Design, i: int):
originX = i * 8
oroginY = i * 10
point1X = originX - 4
point1Y = oroginY + 5
point2X = originX + 4
point3Y = oroginY - 5
center1X = originX + 3
center1Y = oroginY + 4
center2X = originX - 3
center2Y = oroginY - 4
sketch = Sketch()
(
sketch.segment(
start=Point2D([point1X, point1Y], unit=UNITS.m),
end=Point2D([point2X, point1Y], unit=UNITS.m),
)
.segment_to_point(end=Point2D([point2X, point3Y], unit=UNITS.m))
.segment_to_point(end=Point2D([point1X, point3Y], unit=UNITS.m))
.segment_to_point(end=Point2D([point1X, point1Y], unit=UNITS.m))
.box(
center=Point2D([originX, oroginY], unit=UNITS.m),
width=Distance(3, UNITS.m),
height=Distance(3, UNITS.m),
)
.circle(center=Point2D([center1X, center1Y], unit=UNITS.m), radius=outer_hole_radius)
.circle(center=Point2D([center2X, center2Y], unit=UNITS.m), radius=outer_hole_radius)
.circle(center=Point2D([center2X, center1Y], unit=UNITS.m), radius=outer_hole_radius)
.circle(center=Point2D([center1X, center2Y], unit=UNITS.m), radius=outer_hole_radius)
)
body = design.extrude_sketch(f"PlateLayer{i}", sketch, Quantity(2, UNITS.m))
design.create_named_selection(f"Plate{i}", bodies=[body])
# Body 51 or i == 50
i = 50
extrude_body(outer_hole_radius, design, i)
modeler.close()
Continuing to investigate!
Hi @PatilSuneel - so together with @b-matteo we identified the issue. The SpaceClaim design area is not infinite and with your current loop and dimensions you were going out of bounds. Bear in mind that the default units of SpaceClaim are mm
and your bodies are being displaced in the range of m
per iteration, leading to very big designs in extent.
I propose you do your test with the following script in which I changed the units to be cm
for your bodies. You can see that instead of having to put UNITS.xx
everywhere, I just changed the Python library's default unit of length to cm
(saving some coding time).
Try running it yourself, this should work like a charm.
I also refactored the code so that the sketch creation, extrusion and named selection creation all happens in one atomic function:
import time
from ansys.geometry.core import launch_modeler
from ansys.geometry.core.designer import Design
from ansys.geometry.core.math import Point2D
from ansys.geometry.core.misc import UNITS, Distance, DEFAULT_UNITS
from ansys.geometry.core.sketch import Sketch
# Change default length units to cm
DEFAULT_UNITS.LENGTH = UNITS.cm
# Launch modeler
modeler = launch_modeler(mode="spaceclaim")
# Create a new design
design = modeler.create_design("ExtrudedPlate")
# Define the outer hole radius
outer_hole_radius = Distance(0.5)
def extrude_and_named_selection(outer_hole_radius: Distance, design: Design, i: int):
originX = i * 8
originY = i * 10
point1X = originX - 4
point1Y = originY + 5
point2X = originX + 4
point3Y = originY - 5
center1X = originX + 3
center1Y = originY + 4
center2X = originX - 3
center2Y = originY - 4
sketch = Sketch()
(
sketch.segment(
start=Point2D([point1X, point1Y]),
end=Point2D([point2X, point1Y]),
)
.segment_to_point(end=Point2D([point2X, point3Y]))
.segment_to_point(end=Point2D([point1X, point3Y]))
.segment_to_point(end=Point2D([point1X, point1Y]))
.box(
center=Point2D([originX, originY]),
width=Distance(3),
height=Distance(3),
)
.circle(center=Point2D([center1X, center1Y]), radius=outer_hole_radius)
.circle(center=Point2D([center2X, center2Y]), radius=outer_hole_radius)
.circle(center=Point2D([center2X, center1Y]), radius=outer_hole_radius)
.circle(center=Point2D([center1X, center2Y]), radius=outer_hole_radius)
)
body = design.extrude_sketch(f"PlateLayer{i}", sketch, Distance(2))
design.create_named_selection(f"Plate{i}", bodies=[body])
# Time the execution - START
time_start = time.time()
for i in range(100):
extrude_and_named_selection(outer_hole_radius, design, i)
time_end = time.time()
# Time the execution - END
print(f"Time taken: {time_end - time_start:.2f} seconds")
# Close the modeler
modeler.close()
Thanks for identifying the issue, I will try it out.
If it works, feel free to close the issue. Otherwise post your findings here and we will look into it! =) Thanks @PatilSuneel
Yes it is working like a charm... Thanks a lot
Nice! Thanks for the feedback. Closing the issue.
🔍 Before submitting the issue
🐞 Description of the bug
Hi All, I am doing an excersise to understand how much time required to create an geometry and I am comparing between standalone Sc and PyGeometry. For this excersise I have taken a simple plate with a hole geometry. The code works somthing like below where 50 indicates number of loops.
The code is working fine for up-to range = 50 if I increase the range values greater than 50 the code is failing, following is the error
📝 Steps to reproduce
💻 Which operating system are you using?
Windows
📀 Which ANSYS version are you using?
2024 R1
🐍 Which Python version are you using?
3.11
📦 Installed packages