Skip to content
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

Add basic design examples and arrange the format of example page. #183

Merged
merged 31 commits into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
07b6be6
git commit -m "initial commit for examples layout"
Revathyvenugopal162 Oct 19, 2022
0fdd87d
Modify examples with proper doc strings
Revathyvenugopal162 Oct 19, 2022
e45c502
tesselation examples
Revathyvenugopal162 Oct 20, 2022
2552b87
Merge branch 'main' into docs/add-initial-examples
Revathyvenugopal162 Oct 20, 2022
2ded565
Add docstrings for teseelation example
Revathyvenugopal162 Oct 20, 2022
4362882
Merge branch 'main' into docs/add-initial-examples
Revathyvenugopal162 Oct 20, 2022
4d7b091
reformat examples
Revathyvenugopal162 Oct 20, 2022
983efa0
add new example in toc-tree
Revathyvenugopal162 Oct 20, 2022
a6fbed9
add basic example of single body
Revathyvenugopal162 Oct 20, 2022
70fd329
Add thumb nails
Revathyvenugopal162 Oct 20, 2022
6a32039
Apply suggestions from code review
Revathyvenugopal162 Oct 20, 2022
fce2f06
Add examples for planar surface and extruding face
Revathyvenugopal162 Oct 20, 2022
8582905
Add tesselate bodies to examples
Revathyvenugopal162 Oct 20, 2022
42d7302
Update doc/source/examples/design/add_design_material.mystnb
Revathyvenugopal162 Oct 20, 2022
4052e53
Code suggestions by @chadqueen
Revathyvenugopal162 Oct 20, 2022
032e8d9
Merge branch 'docs/add-initial-examples' of https://github.com/pyansy…
Revathyvenugopal162 Oct 20, 2022
c0ba9d7
Merge branch 'main' into docs/add-initial-examples
Revathyvenugopal162 Oct 20, 2022
d1cfa41
Apply suggestions from code review
Revathyvenugopal162 Oct 20, 2022
00a75de
Add minor changes
Revathyvenugopal162 Oct 20, 2022
2cd213a
Merge branch 'docs/add-initial-examples' of https://github.com/pyansy…
Revathyvenugopal162 Oct 20, 2022
a9ff5a8
Merge branch 'main' into docs/add-initial-examples
Revathyvenugopal162 Oct 20, 2022
71fe425
Add minor changes in design organisation
Revathyvenugopal162 Oct 20, 2022
a24cca5
Update doc/source/examples/design/plate_with_hole.mystnb
Revathyvenugopal162 Oct 20, 2022
7bcc239
Modify user guide
Revathyvenugopal162 Oct 20, 2022
b902d7b
Merge branch 'docs/add-initial-examples' of https://github.com/pyansy…
Revathyvenugopal162 Oct 20, 2022
503c334
Merge branch 'main' into docs/add-initial-examples
RobPasMue Oct 21, 2022
108e564
Update doc/source/examples/design/tessellation_usage.mystnb
RobPasMue Oct 21, 2022
65bcec6
Update doc/source/examples/design/tessellation_usage.mystnb
RobPasMue Oct 21, 2022
c350d9d
Merge branch 'main' into docs/add-initial-examples
Revathyvenugopal162 Oct 21, 2022
f0e05ad
Apply suggestions from code review
Revathyvenugopal162 Oct 21, 2022
12c2671
Merge branch 'main' into docs/add-initial-examples
RobPasMue Oct 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/source/_static/thumbnails/dynamic_sketch_plane.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 5 additions & 2 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,11 @@
".mystnb": ["jupytext.reads", {"fmt": "mystnb"}],
}
nbsphinx_thumbnails = {
"examples/basic_usage": "_static/thumbnails/basic_usage.png",
"examples/dynamic_sketch_plane": "_static/thumbnails/dynamic_sketch_plane.png",
"examples/basic/basic_usage": "_static/thumbnails/basic_usage.png",
"examples/design/dynamic_sketch_plane": "_static/thumbnails/dynamic_sketch_plane.png",
"examples/design/add_design_material": "_static/thumbnails/add_design_material.png",
"examples/design/plate_with_hole": "_static/thumbnails/plate_with_hole.png",
"examples/design/tessellation_usage": "_static/thumbnails/tessellation_usage.png",
}
Revathyvenugopal162 marked this conversation as resolved.
Show resolved Hide resolved
Revathyvenugopal162 marked this conversation as resolved.
Show resolved Hide resolved

typehints_defaults = "comma"
Expand Down
20 changes: 18 additions & 2 deletions doc/source/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,23 @@ Examples

All examples are collected in this page.

Math and sketch examples
------------------------
This section demonstrates the math operations on geometric objects
and sketching basic sketch objects in PyGeometry.
Revathyvenugopal162 marked this conversation as resolved.
Show resolved Hide resolved

.. nbgallery::

examples/basic/basic_usage.mystnb

Service based examples
----------------------

This section demonstrates service based operations on PyGeometry.

.. nbgallery::

examples/dynamic_sketch_plane.mystnb
examples/basic_usage.mystnb
examples/design/add_design_material.mystnb
examples/design/plate_with_hole.mystnb
examples/design/dynamic_sketch_plane.mystnb
RobPasMue marked this conversation as resolved.
Show resolved Hide resolved
examples/design/tessellation_usage.mystnb
74 changes: 74 additions & 0 deletions doc/source/examples/design/add_design_material.mystnb
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
---
jupytext:
text_representation:
extension: .mystnb
format_name: myst
format_version: 0.13
jupytext_version: 1.14.1
kernelspec:
display_name: Python 3 (ipykernel)
language: python
name: python3
---
# Single body with material assignment

In PyGeometry ``body`` represents solids and surfaces organized within the design assembly.
Revathyvenugopal162 marked this conversation as resolved.
Show resolved Hide resolved
The current state of ``sketch``, which is a client side execution cab be used for the operations of
the geometric design assembly. Geometric Service also provides data structure to create individual materials
and its properties.

This example demonstrate how to create a single body from the extruded sketch and how to assign material to it.
Revathyvenugopal162 marked this conversation as resolved.
Show resolved Hide resolved

```{code-cell} ipython3
from pint import Quantity

from ansys.geometry.core import Modeler
from ansys.geometry.core.materials import Material, MaterialProperty, MaterialPropertyType
from ansys.geometry.core.math import UNITVECTOR3D_Z, Frame, Plane, Point2D, Point3D, UnitVector3D
from ansys.geometry.core.misc import UNITS
from ansys.geometry.core.sketch import Sketch
```
## Defining the ``Sketch``.

Create a basic ``circle`` sketch instance with radius 10mm in default plane.
Revathyvenugopal162 marked this conversation as resolved.
Show resolved Hide resolved

```{code-cell} ipython3
sketch = Sketch()
sketch.circle(Point2D([10, 10], UNITS.mm), Quantity(10, UNITS.mm))
```

## Initiate the design in server.
Revathyvenugopal162 marked this conversation as resolved.
Show resolved Hide resolved
A server connection is established and a design has been initiated.
```{code-cell} ipython3
modeler = Modeler()
design_name = "ExtrudeProfile"
design = modeler.create_design(design_name)
```

## Add materials to the design.
Adding materials and its property to the design.
Revathyvenugopal162 marked this conversation as resolved.
Show resolved Hide resolved
Revathyvenugopal162 marked this conversation as resolved.
Show resolved Hide resolved
```{code-cell} ipython3
density = Quantity(125, 10 * UNITS.kg / (UNITS.m * UNITS.m * UNITS.m))
poisson_ratio = Quantity(0.33, UNITS.dimensionless)
tensile_strength = Quantity(45)
material = Material(
"steel",
density,
[MaterialProperty(MaterialPropertyType.POISSON_RATIO, "PoissonRatio", poisson_ratio)],
)
material.add_property(MaterialPropertyType.TENSILE_STRENGTH, "TensileProp", Quantity(45))
design.add_material(material)
```
Revathyvenugopal162 marked this conversation as resolved.
Show resolved Hide resolved
## extrude the body from single sketch.
Revathyvenugopal162 marked this conversation as resolved.
Show resolved Hide resolved

Extrude the sketch to create body and add material to the body.
Revathyvenugopal162 marked this conversation as resolved.
Show resolved Hide resolved

```{code-cell} ipython3
# Extrude the sketch to create a Body
body = design.extrude_sketch("SingleBody", sketch, Quantity(10, UNITS.mm))

# Assign a material to a Body
body.assign_material(material)

body.plot()
```
73 changes: 73 additions & 0 deletions doc/source/examples/design/plate_with_hole.mystnb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
---
jupytext:
text_representation:
extension: .mystnb
format_name: myst
format_version: 0.13
jupytext_version: 1.14.1
kernelspec:
display_name: Python 3 (ipykernel)
language: python
name: python3
---

# Extruded rectangular plate with multiple bodies
Revathyvenugopal162 marked this conversation as resolved.
Show resolved Hide resolved

Multiple bodies can be created from a single sketch by extruding the same sketch by layers.
Revathyvenugopal162 marked this conversation as resolved.
Show resolved Hide resolved
The box is located in the center of the plate, with the default origin of a sketch plane (origin at (0,0,0)).
Revathyvenugopal162 marked this conversation as resolved.
Show resolved Hide resolved
The outer plate is extruded with equal radius holes at four corners of the plate.
Revathyvenugopal162 marked this conversation as resolved.
Show resolved Hide resolved
The projection is at the center of the face. The default projection depth is through the entire part.

+++
import the fundamental objects:
Revathyvenugopal162 marked this conversation as resolved.
Show resolved Hide resolved

```{code-cell} ipython3
import numpy as np
from pint import Quantity

from ansys.geometry.core import Modeler
from ansys.geometry.core.math import Plane, Point3D, Point2D
from ansys.geometry.core.misc import UNITS
from ansys.geometry.core.sketch import Sketch
```

## Defining a ``Sketch`` profile for the proposed design
Revathyvenugopal162 marked this conversation as resolved.
Show resolved Hide resolved

The profile required four ``Segment`` which constitute the outer body of the design, a `Box`` on the center and
Revathyvenugopal162 marked this conversation as resolved.
Show resolved Hide resolved
a ``Circle`` at four corners.

A single sketch instance can be used for multiple design operations.
Revathyvenugopal162 marked this conversation as resolved.
Show resolved Hide resolved

```{code-cell} ipython3
sketch = Sketch()
(sketch.segment(Point2D([-4, 5], unit=UNITS.m), Point2D([4, 5], unit=UNITS.m))
.segment_to_point(Point2D([4, -5], unit=UNITS.m))
.segment_to_point(Point2D([-4, -5], unit=UNITS.m))
.segment_to_point(Point2D([-4, 5], unit=UNITS.m))
.box(Point2D([0,0], unit=UNITS.m), Quantity(3, UNITS.m), Quantity(3, UNITS.m))
.circle(Point2D([3, 4], unit=UNITS.m), Quantity(0.5, UNITS.m))
.circle(Point2D([-3, -4], unit=UNITS.m), Quantity(0.5, UNITS.m))
.circle(Point2D([-3, 4], unit=UNITS.m), Quantity(0.5, UNITS.m))
.circle(Point2D([3, -4], unit=UNITS.m), Quantity(0.5, UNITS.m))
)
```

## Creating the design and plot

A server connection is established and the single sketch profile is used to extrude
the board profile at multiple Z-offsets. A named selection is then created from the
resulting list of layer bodies.
The design is going to extrude the four segments with desired thickness, resulting in four server calls.
Revathyvenugopal162 marked this conversation as resolved.
Show resolved Hide resolved

```{code-cell} ipython3
modeler = Modeler()
design = modeler.create_design("ExtrudedPlate")

layers= []
layer_thickness = Quantity(2, UNITS.m)
for layer_index in range(4):
layers.append(design.extrude_sketch(f"PlateLayer_{layer_index}", sketch, layer_thickness))
Revathyvenugopal162 marked this conversation as resolved.
Show resolved Hide resolved

board_named_selection = design.create_named_selection("Plate", bodies=layers)
design.plot()
```
65 changes: 65 additions & 0 deletions doc/source/examples/design/tessellation_usage.mystnb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
jupytext:
text_representation:
extension: .mystnb
format_name: myst
format_version: 0.13
jupytext_version: 1.14.1
kernelspec:
display_name: Python 3 (ipykernel)
language: python
name: python3
---

# Tessellation of two bodies

Create two stacked bodies and return the tessellation as two merged bodies.

+++
import the fundamental objects:

```{code-cell} ipython3
from pint import Quantity

from ansys.geometry.core.sketch import Sketch
from ansys.geometry.core import Modeler
from ansys.geometry.core.math import Point2D, Point3D, Plane
from ansys.geometry.core.misc import UNITS
from ansys.geometry.core.plotting.plotter import Plotter
Revathyvenugopal162 marked this conversation as resolved.
Show resolved Hide resolved
```

## Creating the design

Revathyvenugopal162 marked this conversation as resolved.
Show resolved Hide resolved
```{code-cell} ipython3
modeler = Modeler()

sketch_1 = Sketch()
box = sketch_1.box(
Point2D([10, 10], unit=UNITS.m), width=Quantity(10, UNITS.m), height=Quantity(5, UNITS.m)
)
circle = sketch_1.circle(
Point2D([0, 0], unit=UNITS.m), radius=Quantity(25, UNITS.m)
)

design = modeler.create_design("TessellationDesign")
comp = design.add_component("TessellationComponent")
body = comp.extrude_sketch("FirstBody", sketch=sketch_1, distance=10 * UNITS.m)

# Create the second body in a plane with different origin.
sketch_2 = Sketch(Plane([0, 0, 10]))
box = sketch_2.box(Point2D(
[10, 10], unit=UNITS.m), width=Quantity(10, UNITS.m), height=Quantity(5, UNITS.m)
)
circle = sketch_2.circle(
Point2D([0, 10], unit=UNITS.m), radius=Quantity(25, UNITS.m)
)

body = comp.extrude_sketch("SecondBody", sketch=sketch_2, distance=10 * UNITS.m)
dataset = comp.tessellate(merge_bodies=True)
dataset
```

## Plot the tessellation as two merged bodies.
Revathyvenugopal162 marked this conversation as resolved.
Show resolved Hide resolved
```{code-cell} ipython3
comp.plot(merge_bodies=True)
```