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)
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.from_cad(elli), rve=rve, grid=[5, 5, 5])
compound = make_compound_from_solids(
[solid.wrapped for phase in raster for solid in phase.cad.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,
)
Voronoi
from pathlib import Path
from microgen import Neper, Phase, mesh
from microgen.cad import make_compound
# Import the Polyhedra from a Neper tessellation file, build a CAD compound,
# export STEP, and tetrahedralise via gmsh.
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.from_cad(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,
)
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.from_cad(shape.intersect(gyroid)))
compound = make_compound([phase.cad 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,
)