Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 2 additions & 3 deletions docs/Overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,8 @@ Brief examples
import microgen

geometry = microgen.Tpms(
surface_function=microgen.surface_functions.gyroid,
offset=0.3
)
surface_function=microgen.surface_functions.gyroid,
).with_offset(0.3)
shape = geometry.sheet

shape.plot(color='white')
20 changes: 10 additions & 10 deletions docs/quick_start.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ Let's create a Gyroid TPMS structure, one of the most common triply periodic min

.. jupyter-execute::

gyroid = microgen.Tpms(
surface_function=microgen.surface_functions.gyroid,
offset=0.3,
cell_size=1.0,
repeat_cell=2,
resolution=20
gyroid = (
microgen.Tpms(surface_function=microgen.surface_functions.gyroid)
.with_offset(0.3)
.with_cell_size(1.0)
.with_repeat_cell(2)
.with_resolution(20)
)

# Get the sheet geometry as a PyVista mesh
Expand All @@ -54,10 +54,10 @@ Each TPMS can generate different part types:

.. jupyter-execute::

tpms = microgen.Tpms(
surface_function=microgen.surface_functions.gyroid,
offset=0.5,
resolution=20
tpms = (
microgen.Tpms(surface_function=microgen.surface_functions.gyroid)
.with_offset(0.5)
.with_resolution(20)
)

# Sheet (wall) geometry
Expand Down
98 changes: 51 additions & 47 deletions docs/tutorials.rst
Original file line number Diff line number Diff line change
Expand Up @@ -171,38 +171,38 @@ Schwarz P:

.. jupyter-execute::

schwarz_p = microgen.Tpms(
surface_function=microgen.surface_functions.schwarz_p,
offset=0.3,
cell_size=1.0,
repeat_cell=2,
resolution=20
schwarz_p = (
microgen.Tpms(surface_function=microgen.surface_functions.schwarz_p)
.with_offset(0.3)
.with_cell_size(1.0)
.with_repeat_cell(2)
.with_resolution(20)
)
schwarz_p.sheet.plot(color='white')

Schwarz D:

.. jupyter-execute::

schwarz_d = microgen.Tpms(
surface_function=microgen.surface_functions.schwarz_d,
offset=0.3,
cell_size=1.0,
repeat_cell=2,
resolution=20
schwarz_d = (
microgen.Tpms(surface_function=microgen.surface_functions.schwarz_d)
.with_offset(0.3)
.with_cell_size(1.0)
.with_repeat_cell(2)
.with_resolution(20)
)
schwarz_d.sheet.plot(color='white')

Neovius:

.. jupyter-execute::

neovius = microgen.Tpms(
surface_function=microgen.surface_functions.neovius,
offset=0.3,
cell_size=1.0,
repeat_cell=2,
resolution=20
neovius = (
microgen.Tpms(surface_function=microgen.surface_functions.neovius)
.with_offset(0.3)
.with_cell_size(1.0)
.with_repeat_cell(2)
.with_resolution(20)
)
neovius.sheet.plot(color='white')

Expand All @@ -214,12 +214,12 @@ You can specify a target density instead of an offset value:

.. jupyter-execute::

gyroid_50 = microgen.Tpms(
surface_function=microgen.surface_functions.gyroid,
density=0.5, # 50% density
cell_size=1.0,
repeat_cell=2,
resolution=20
gyroid_50 = (
microgen.Tpms(surface_function=microgen.surface_functions.gyroid)
.with_density(0.5) # 50% density
.with_cell_size(1.0)
.with_repeat_cell(2)
.with_resolution(20)
)
gyroid_50.sheet.plot(color='white')

Expand All @@ -231,13 +231,15 @@ Create TPMS on a spherical coordinate system:

.. jupyter-execute::

spherical_gyroid = microgen.SphericalTpms(
radius=2.0,
surface_function=microgen.surface_functions.gyroid,
offset=0.3,
cell_size=0.5,
repeat_cell=(3, 0, 0), # 0 = auto-fill to complete sphere
resolution=20
spherical_gyroid = (
microgen.SphericalTpms(
radius=2.0,
surface_function=microgen.surface_functions.gyroid,
)
.with_offset(0.3)
.with_cell_size(0.5)
.with_repeat_cell((3, 0, 0)) # 0 = auto-fill to complete sphere
.with_resolution(20)
)
spherical_gyroid.sheet.plot(color='white')

Expand All @@ -249,13 +251,15 @@ Create TPMS on a cylindrical coordinate system:

.. jupyter-execute::

cylindrical_gyroid = microgen.CylindricalTpms(
radius=1.5,
surface_function=microgen.surface_functions.gyroid,
offset=0.3,
cell_size=0.5,
repeat_cell=(2, 0, 3), # 0 = auto-fill circumference
resolution=20
cylindrical_gyroid = (
microgen.CylindricalTpms(
radius=1.5,
surface_function=microgen.surface_functions.gyroid,
)
.with_offset(0.3)
.with_cell_size(0.5)
.with_repeat_cell((2, 0, 3)) # 0 = auto-fill circumference
.with_resolution(20)
)
cylindrical_gyroid.sheet.plot(color='white')

Expand Down Expand Up @@ -348,10 +352,10 @@ Generate a tetrahedral mesh using Gmsh:
import microgen

# Create a TPMS geometry
gyroid = microgen.Tpms(
surface_function=microgen.surface_functions.gyroid,
offset=0.3,
resolution=20
gyroid = (
microgen.Tpms(surface_function=microgen.surface_functions.gyroid)
.with_offset(0.3)
.with_resolution(20)
)
shape = gyroid.generate_cad(type_part='sheet')

Expand All @@ -375,11 +379,11 @@ Generate a periodic mesh suitable for homogenization:
.. code-block:: python

# Create geometry
gyroid = microgen.Tpms(
surface_function=microgen.surface_functions.gyroid,
offset=0.3,
cell_size=1.0,
resolution=20
gyroid = (
microgen.Tpms(surface_function=microgen.surface_functions.gyroid)
.with_offset(0.3)
.with_cell_size(1.0)
.with_resolution(20)
)
shape = gyroid.generate_cad(type_part='sheet')

Expand Down
6 changes: 2 additions & 4 deletions examples/3Doperations/voronoiGyroid/voronoiGyroid.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
polyhedra = Neper.voronoi_from_tess_file(tess_file)

gyroid = Tpms(
center=(0.5, 0.5, 0.5),
surface_function=surface_functions.gyroid,
offset=0.2,
)
center=(0.5, 0.5, 0.5), surface_function=surface_functions.gyroid
).with_offset(0.2)
gyroid = gyroid.generate_cad(type_part="sheet").translate((0.5, 0.5, 0.5))

phases = []
Expand Down
11 changes: 5 additions & 6 deletions examples/Lattices/custom_lattice.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,11 @@
[l1_strut_vertex_pairs, l2_strut_vertex_pairs, half_l1_strut_vertex_pairs]
)

auxetic_lattice = CustomLattice(
strut_radius=0.1,
strut_heights=strut_heights,
base_vertices=base_vertices,
strut_vertex_pairs=strut_vertex_pairs,
strut_joints=True,
auxetic_lattice = (
CustomLattice(base_vertices, strut_vertex_pairs)
.with_strut_radius(0.1)
.with_strut_heights(strut_heights)
.with_strut_joints()
)

shape = auxetic_lattice.generate_cad()
Expand Down
6 changes: 1 addition & 5 deletions examples/Mesh/gyroid/gyroid_step_remesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@
import pyvista as pv

# 1. Generate a TPMS geometry using the gyroid surface function.
geometry = Tpms(
surface_function=gyroid,
density=0.30,
resolution=30,
)
geometry = Tpms(surface_function=gyroid).with_density(0.30).with_resolution(30)

# 2. Wrap the geometry into a microgen Phase object.
phases = []
Expand Down
42 changes: 21 additions & 21 deletions examples/Mesh/remesh/remesh.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
"""Remesh a gyroid surface keeping periodicity for FEM simulations."""
from pathlib import Path
from microgen import Tpms
from microgen.remesh import remesh_keeping_boundaries_for_fem
from microgen.shape.surface_functions import gyroid
data_dir = Path(__file__).parent / "data"
Path.mkdir(data_dir, exist_ok=True)
tpms = Tpms(surface_function=gyroid, offset=1.0, resolution=50)
initial_gyroid = tpms.grid_sheet
initial_gyroid.save(data_dir / "initial_gyroid_mesh.vtk")
max_element_edge_length = 0.02
remeshed_gyroid = remesh_keeping_boundaries_for_fem(
initial_gyroid,
hmax=max_element_edge_length,
)
remeshed_gyroid.save(data_dir / "remeshed_gyroid_mesh.vtk")
"""Remesh a gyroid surface keeping periodicity for FEM simulations."""

from pathlib import Path

from microgen import Tpms
from microgen.remesh import remesh_keeping_boundaries_for_fem
from microgen.shape.surface_functions import gyroid

data_dir = Path(__file__).parent / "data"
Path.mkdir(data_dir, exist_ok=True)

tpms = Tpms(surface_function=gyroid).with_offset(1.0).with_resolution(50)
initial_gyroid = tpms.grid_sheet
initial_gyroid.save(data_dir / "initial_gyroid_mesh.vtk")

max_element_edge_length = 0.02
remeshed_gyroid = remesh_keeping_boundaries_for_fem(
initial_gyroid,
hmax=max_element_edge_length,
)
remeshed_gyroid.save(data_dir / "remeshed_gyroid_mesh.vtk")
13 changes: 6 additions & 7 deletions examples/TPMS/coordinate_system/cylindrical.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ def swapped_gyroid(x, y, z):
return gyroid(x=z, y=y, z=x)


geometry = CylindricalTpms(
surface_function=swapped_gyroid,
offset=0.5,
cell_size=(1, 1, 1),
repeat_cell=(1, 0, 1),
radius=1,
resolution=20,
geometry = (
CylindricalTpms(surface_function=swapped_gyroid, radius=1)
.with_offset(0.5)
.with_cell_size((1, 1, 1))
.with_repeat_cell((1, 0, 1))
.with_resolution(20)
)
sheet = geometry.sheet

Expand Down
23 changes: 12 additions & 11 deletions examples/TPMS/coordinate_system/cylindrical_graded.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,18 @@ def grading(
density=1.0,
)

geometry = CylindricalTpms(
radius=5,
surface_function=swapped_gyroid,
offset=partial(
grading,
min_offset=0.0,
max_offset=full_density_offset,
),
cell_size=(1, 1, 1),
repeat_cell=(5, 0, 1),
resolution=20,
geometry = (
CylindricalTpms(radius=5, surface_function=swapped_gyroid)
.with_offset(
partial(
grading,
min_offset=0.0,
max_offset=full_density_offset,
)
)
.with_cell_size((1, 1, 1))
.with_repeat_cell((5, 0, 1))
.with_resolution(20)
)
sheet = geometry.sheet

Expand Down
15 changes: 8 additions & 7 deletions examples/TPMS/coordinate_system/rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ def rotated_gyroid(

grid_rotation = Rotation.from_euler("z", 45, degrees=True)

geometry = CylindricalTpms(
surface_function=partial(rotated_gyroid, grid_rotation=grid_rotation),
offset=0.5,
cell_size=(1, 1, 1),
repeat_cell=(1, 0, 1),
radius=1,
resolution=20,
geometry = (
CylindricalTpms(
surface_function=partial(rotated_gyroid, grid_rotation=grid_rotation), radius=1
)
.with_offset(0.5)
.with_cell_size((1, 1, 1))
.with_repeat_cell((1, 0, 1))
.with_resolution(20)
)
sheet = geometry.sheet

Expand Down
11 changes: 5 additions & 6 deletions examples/TPMS/coordinate_system/spherical.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ def swapped_gyroid(x, y, z):
return gyroid(x=z, y=y, z=x)


geometry = SphericalTpms(
surface_function=swapped_gyroid,
offset=0.5,
repeat_cell=(1, 10, 20),
radius=3,
resolution=50,
geometry = (
SphericalTpms(surface_function=swapped_gyroid, radius=3)
.with_offset(0.5)
.with_repeat_cell((1, 10, 20))
.with_resolution(50)
)
surface = geometry.surface

Expand Down
10 changes: 5 additions & 5 deletions examples/TPMS/grading/cell_size.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ def graded(
)


geometry = Tpms(
surface_function=graded,
offset=0.3,
repeat_cell=(5, 2, 2),
resolution=30,
geometry = (
Tpms(surface_function=graded)
.with_offset(0.3)
.with_repeat_cell((5, 2, 2))
.with_resolution(30)
)
sheet = geometry.sheet

Expand Down
Loading
Loading