Skip to content

Commit 020c54e

Browse files
Revathyvenugopal162RobPasMueMaxJPRey
authored
Add basic design examples and arrange the format of example page. (#183)
Co-authored-by: Roberto Pastor Muela <roberto.pastormuela@ansys.com> Co-authored-by: Maxime Rey <87315832+MaxJPRey@users.noreply.github.com>
1 parent 062777b commit 020c54e

13 files changed

+331
-15
lines changed
Loading
Loading
Loading
Loading

doc/source/conf.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,12 @@
120120
".mystnb": ["jupytext.reads", {"fmt": "mystnb"}],
121121
}
122122
nbsphinx_thumbnails = {
123-
"examples/basic_usage": "_static/thumbnails/basic_usage.png",
124-
"examples/dynamic_sketch_plane": "_static/thumbnails/dynamic_sketch_plane.png",
125-
"examples/design_organization": "_static/thumbnails/design_organization.png",
123+
"examples/basic/basic_usage": "_static/thumbnails/basic_usage.png",
124+
"examples/design/dynamic_sketch_plane": "_static/thumbnails/dynamic_sketch_plane.png",
125+
"examples/design/add_design_material": "_static/thumbnails/add_design_material.png",
126+
"examples/design/plate_with_hole": "_static/thumbnails/plate_with_hole.png",
127+
"examples/design/tessellation_usage": "_static/thumbnails/tessellation_usage.png",
128+
"examples/design/design_organization": "_static/thumbnails/design_organization.png",
126129
}
127130

128131
typehints_defaults = "comma"

doc/source/examples.rst

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,24 @@ Examples
33

44
All examples are collected in this page.
55

6+
Math and sketch examples
7+
------------------------
8+
This section demonstrates the math operations on geometric objects
9+
and basic sketching capabilities in PyGeometry.
10+
11+
.. nbgallery::
12+
13+
examples/basic/basic_usage.mystnb
14+
15+
Service based examples
16+
----------------------
17+
18+
This section demonstrates service based operations on PyGeometry.
19+
620
.. nbgallery::
721

8-
examples/design_organization.mystnb
9-
examples/dynamic_sketch_plane.mystnb
10-
examples/basic_usage.mystnb
22+
examples/design/add_design_material.mystnb
23+
examples/design/plate_with_hole.mystnb
24+
examples/design/dynamic_sketch_plane.mystnb
25+
examples/design/tessellation_usage.mystnb
26+
examples/design/design_organization.mystnb
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
jupytext:
3+
text_representation:
4+
extension: .mystnb
5+
format_name: myst
6+
format_version: 0.13
7+
jupytext_version: 1.14.1
8+
kernelspec:
9+
display_name: Python 3 (ipykernel)
10+
language: python
11+
name: python3
12+
---
13+
# Single body with material assignment
14+
15+
In PyGeometry, a ``Body`` represents solids or surfaces organized within the ``Design`` assembly.
16+
The current state of ``Sketch``, which is a client-side execution, can be used for the operations of
17+
the geometric design assembly. The Geometry Service also provides data structures to create individual materials
18+
and its properties, which are also exposed through PyGeometry.
19+
20+
This example demonstrates how to create a single body from a sketch, by requesting its extrusion,
21+
and how to assign a material to it.
22+
23+
```{code-cell} ipython3
24+
from pint import Quantity
25+
26+
from ansys.geometry.core import Modeler
27+
from ansys.geometry.core.materials import Material, MaterialProperty, MaterialPropertyType
28+
from ansys.geometry.core.math import UNITVECTOR3D_Z, Frame, Plane, Point2D, Point3D, UnitVector3D
29+
from ansys.geometry.core.misc import UNITS
30+
from ansys.geometry.core.sketch import Sketch
31+
```
32+
## Defining the ``Sketch``
33+
34+
Create a basic ``circle`` sketch instance with radius 10mm in the default plane.
35+
36+
```{code-cell} ipython3
37+
sketch = Sketch()
38+
sketch.circle(Point2D([10, 10], UNITS.mm), Quantity(10, UNITS.mm))
39+
```
40+
41+
## Initiate the design in the server
42+
43+
A server connection is established and a design has been initiated.
44+
```{code-cell} ipython3
45+
modeler = Modeler()
46+
design_name = "ExtrudeProfile"
47+
design = modeler.create_design(design_name)
48+
```
49+
50+
## Add materials to the design
51+
52+
Adding materials and its properties to the design. Additional properties of
53+
the material can be added at construction of the ``Material`` object or afterwards,
54+
as it is shown in the code snippet.
55+
```{code-cell} ipython3
56+
density = Quantity(125, 10 * UNITS.kg / (UNITS.m * UNITS.m * UNITS.m))
57+
poisson_ratio = Quantity(0.33, UNITS.dimensionless)
58+
tensile_strength = Quantity(45)
59+
material = Material(
60+
"steel",
61+
density,
62+
[MaterialProperty(MaterialPropertyType.POISSON_RATIO, "PoissonRatio", poisson_ratio)],
63+
)
64+
material.add_property(MaterialPropertyType.TENSILE_STRENGTH, "TensileProp", Quantity(45))
65+
design.add_material(material)
66+
```
67+
## Extrude the body from the sketch
68+
69+
Extrude the sketch to create the body and assign a material to it.
70+
71+
```{code-cell} ipython3
72+
# Extrude the sketch to create a Body
73+
body = design.extrude_sketch("SingleBody", sketch, Quantity(10, UNITS.mm))
74+
75+
# Assign a material to a Body
76+
body.assign_material(material)
77+
78+
body.plot()
79+
```

doc/source/examples/design_organization.mystnb renamed to doc/source/examples/design/design_organization.mystnb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ used sketch.
7575
double_nested_component = nested_component.add_component("DoubleNestedComponent")
7676

7777
circle_surface_body = double_nested_component.create_surface("CircularSurfaceBody", circle_sketch)
78-
circle_surface_body.translate(UNITVECTOR3D_X, Distance(-10, UNITS.mm))
78+
circle_surface_body.translate(UNITVECTOR3D_X, Distance(-35, UNITS.mm))
7979

8080
design.plot()
8181
```

0 commit comments

Comments
 (0)