3D operations

Repeating unit geometry

from pathlib import Path

from microgen import Rve, repeat_shape
from microgen.cad import import_step

rve = Rve(dim=1)

step_file = str(Path(__file__).parent / "octettruss.step")
unit_geom = import_step(step_file)

shape = repeat_shape(unit_geom, rve, grid=(5, 5, 5))

stl_file = str(Path(__file__).parent / "repeated_shape.stl")
shape.export_stl(stl_file)
../_images/repeated_geometry.png

Raster Ellipsoid

from pathlib import Path

from microgen import Ellipsoid, Phase, Rve, mesh, raster_phase
from microgen.cad import make_compound_from_solids

rve = Rve(dim=1)

elem = Ellipsoid(radii=(0.15, 0.31, 0.4))
elli = elem.generate_cad()

raster = raster_phase(phase=Phase(shape=elli), rve=rve, grid=[5, 5, 5])

compound = make_compound_from_solids(
    [solid for phase in raster for solid in phase.solids]
)
step_file = str(Path(__file__).parent / "compound.step")
compound.export_step(step_file)

vtk_file = str(Path(__file__).parent / "rasterEllipsoid.vtk")
mesh(
    mesh_file=step_file,
    list_phases=raster,
    size=0.03,
    order=1,
    output_file=vtk_file,
)
../_images/rasterEllipsoid.png

Voronoi

from pathlib import Path

from microgen import Neper, Phase, mesh
from microgen.cad import make_compound

# We import the Polyhedra from Neper tessellation file

# Revel = Rve(dim=1)
# phases = []

# for polyhedron in listPolyhedra:
#     elem = Polyhedron(
#         center=(
#             polyhedron["original"][0],
#             polyhedron["original"][1],
#             polyhedron["original"][2],
#         ),
#         dic=polyhedron,
#     )
#     phases.append(Phase(shape=elem.generate_cad()))

# compound = cq.Compound.makeCompound([phase.shape for phase in phases])
# cq.exporters.export(compound, "compound.step")

# mesh(
#     mesh_file="compound.step",
#     list_phases=phases,
#     size=0.05,
#     order=1,
#     output_file="Voronoi.vtk",
# )

tess_file = str(Path(__file__).parent / "test1.tess")
polyhedra = Neper.voronoi_from_tess_file(tess_file)

shapes = [poly.generate_cad() for poly in polyhedra]

compound = make_compound(shapes)
step_file = str(Path(__file__).parent / "compound.step")
compound.export_step(step_file)

phases = [Phase(shape=shape) for shape in shapes]

vtk_file = str(Path(__file__).parent / "Voronoi.vtk")
mesh(
    mesh_file=step_file,
    list_phases=phases,
    size=0.05,
    order=1,
    output_file=vtk_file,
)
../_images/Voronoi.png

Voronoi gyroid

from pathlib import Path

from microgen import Neper, Phase, Tpms, mesh
from microgen.cad import make_compound
from microgen.shape import surface_functions

# We import the Polyhedra from Neper tessellation file
tess_file = str(Path(__file__).parent / "test1.tess")
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,
)
gyroid = gyroid.generate_cad(type_part="sheet").translate((0.5, 0.5, 0.5))

phases = []
for polyhedron in polyhedra:
    shape = polyhedron.generate_cad()
    phases.append(Phase(shape=shape.intersect(gyroid)))

compound = make_compound([phase.shape for phase in phases])
step_file = str(Path(__file__).parent / "compound.step")
compound.export_step(step_file)

vtk_file = str(Path(__file__).parent / "Gyroid-voro.vtk")
mesh(
    mesh_file=step_file,
    list_phases=phases,
    size=0.05,
    order=1,
    output_file=vtk_file,
)
../_images/Gyroid-voro.png