generated from ansys/template
-
Notifications
You must be signed in to change notification settings - Fork 13
feat: Integrate geometry imports #952
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AlejandroFernandezLuces
wants to merge
27
commits into
main
Choose a base branch
from
feat/pygeometry-connection
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
cc987dc
feat: Integrate geometry imports
AlejandroFernandezLuces 43f2550
chore: adding changelog file 952.added.md [dependabot-skip]
pyansys-ci-bot 0431528
fix: RST format
AlejandroFernandezLuces a3e54eb
Merge branch 'feat/pygeometry-connection' of https://github.com/ansys…
AlejandroFernandezLuces 6643e11
Merge branch 'main' into feat/pygeometry-connection
AlejandroFernandezLuces c5c0790
fix: Add dependency to toml file
AlejandroFernandezLuces 6f5175b
Merge branch 'feat/pygeometry-connection' of https://github.com/ansys…
AlejandroFernandezLuces a457f29
fix: Toml file
AlejandroFernandezLuces d73bf47
Merge branch 'main' into feat/pygeometry-connection
AlejandroFernandezLuces 051302d
fix: Proper code blocks
AlejandroFernandezLuces e4a9577
Merge branch 'feat/pygeometry-connection' of https://github.com/ansys…
AlejandroFernandezLuces 4098b91
Merge branch 'main' into feat/pygeometry-connection
AlejandroFernandezLuces b8ede97
Merge branch 'main' into feat/pygeometry-connection
AlejandroFernandezLuces 50b8595
fix: Missing line
AlejandroFernandezLuces 04c2cdb
Merge branch 'feat/pygeometry-connection' of https://github.com/ansys…
AlejandroFernandezLuces e8170db
Merge branch 'main' into feat/pygeometry-connection
AlejandroFernandezLuces 04c8763
fix: Code style
AlejandroFernandezLuces fa94846
Merge branch 'main' into feat/pygeometry-connection
AlejandroFernandezLuces 29cf95b
Update examples/gallery/12_import_from_pygeometry.py
AlejandroFernandezLuces 64d7e49
fix: Bug in reader and example
AlejandroFernandezLuces 6209c12
Merge branch 'main' into feat/pygeometry-connection
AlejandroFernandezLuces 8adfb04
Merge branch 'feat/pygeometry-connection' of https://github.com/ansys…
AlejandroFernandezLuces 3424ad0
Merge branch 'feat/pygeometry-connection' of https://github.com/ansys…
AlejandroFernandezLuces 44401ab
Apply suggestions from code review
AlejandroFernandezLuces ea4ec6c
Merge branch 'main' into feat/pygeometry-connection
AlejandroFernandezLuces bfdc665
Merge branch 'main' into feat/pygeometry-connection
AlejandroFernandezLuces be9592b
Merge branch 'main' into feat/pygeometry-connection
AlejandroFernandezLuces File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
feat: Integrate geometry imports |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
# Copyright (C) 2024 - 2025 ANSYS, Inc. and/or its affiliates. | ||
# SPDX-License-Identifier: MIT | ||
# | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
|
||
""" | ||
.. _ref_pygeometry_import: | ||
|
||
================================= | ||
Import a geometry from PyGeometry | ||
================================= | ||
|
||
**Summary**: This example demonstrates how to create a simple geometry using | ||
PyGeometry and import it into PyPrimeMesh. | ||
|
||
|
||
|
||
Procedure | ||
~~~~~~~~~ | ||
#. Launch the Geometry service and create a simple geometry. | ||
#. Launch Ansys Prime Server. | ||
#. Create a CAD geometry with PyGeometry. | ||
#. Import the geometry into PyPrimeMesh. | ||
#. Mesh and display the imported geometry. | ||
#. Exit the PyPrimeMesh and PyGeometry sessions. | ||
|
||
|
||
|
||
Create the geometry | ||
~~~~~~~~~~~~~~~~~~~ | ||
First we create a simple geometry using PyGeometry. The geometry is a plate | ||
with a hole in the center: | ||
|
||
.. code-block:: python | ||
|
||
from pint import Quantity | ||
|
||
from ansys.geometry.core import launch_modeler | ||
from ansys.geometry.core.math import Point2D | ||
from ansys.geometry.core.misc import UNITS | ||
from ansys.geometry.core.sketch import Sketch | ||
from ansys.geometry.core.math import Point2D | ||
|
||
modeler = launch_modeler(hidden=True) | ||
|
||
sketch = Sketch() | ||
( | ||
sketch.segment(Point2D([-4, 5], unit=UNITS.mm), Point2D([4, 5], unit=UNITS.mm)) | ||
.segment_to_point(Point2D([4, -5], unit=UNITS.mm)) | ||
.segment_to_point(Point2D([-4, -5], unit=UNITS.mm)) | ||
.segment_to_point(Point2D([-4, 5], unit=UNITS.mm)) | ||
.box(Point2D([0, 0], unit=UNITS.mm), Quantity(3, UNITS.mm), Quantity(3, UNITS.mm)) | ||
) | ||
design = modeler.create_design("ExtrudedPlateNoHoles") | ||
body = design.extrude_sketch(f"PlateLayer", sketch, Quantity(2, UNITS.mm)) | ||
sketch_hole = Sketch() | ||
sketch_hole.circle(Point2D([0, 0], unit=UNITS.mm), Quantity(0.5, UNITS.mm)) | ||
|
||
hole_centers = [ | ||
Plane(Point3D([3, 4, 0], unit=UNITS.mm)), | ||
Plane(Point3D([-3, 4, 0], unit=UNITS.mm)), | ||
Plane(Point3D([-3, -4, 0], unit=UNITS.mm)), | ||
Plane(Point3D([3, -4, 0], unit=UNITS.mm)), | ||
] | ||
for center in hole_centers: | ||
sketch_hole.plane = center | ||
design.extrude_sketch( | ||
name=f"H_{center.origin.x}_{center.origin.y}", | ||
sketch=sketch_hole, | ||
distance=Quantity(2, UNITS.mm), | ||
cut=True, | ||
) | ||
|
||
|
||
Import the geometry into PyPrimeMesh | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
Once the geometry is created, we can pass the Design object to PyPrimeMesh to | ||
create a mesh: | ||
|
||
.. code-block:: python | ||
|
||
import ansys.meshing.prime as prime | ||
from ansys.meshing.prime.graphics.plotter import PrimePlotter | ||
|
||
prime_client = prime.launch_prime() | ||
model = prime_client.model | ||
mesh_util = prime.lucid.Mesh(model=model) | ||
mesh_util.from_geometry(design) | ||
|
||
|
||
Mesh the geometry and display it | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
With the geometry imported, we can now mesh it and display the mesh: | ||
|
||
.. code-block:: python | ||
|
||
model.set_global_sizing_params( | ||
prime.GlobalSizingParams(model, min=0.2, max=10.0, growth_rate=1.2) | ||
) | ||
mesh_util.surface_mesh(min_size=0.2) | ||
mesh_util.volume_mesh() | ||
|
||
# Print the results | ||
model.parts[0].print_mesh = True | ||
print(model) | ||
display = PrimePlotter() | ||
display.plot(model) | ||
display.show() | ||
modeler.close() | ||
AlejandroFernandezLuces marked this conversation as resolved.
Show resolved
Hide resolved
|
||
prime_client.exit() | ||
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.