Lattices

Octet-truss

from pathlib import Path

import cadquery as cq
import numpy as np

from microgen import Cylinder, Phase, Rve, cutPhases, meshPeriodic, periodic

# ----------LOADTXT------------------------------------------------------------------------------------------#

# dir = os.path.dirname(os.path.realpath("__file__"))
# # path
# path_data = dir + "/"
# Ngeomphase_file = "test_octet.dat"

# # fichier
# NPhases_file = path_data + Ngeomphase_file
NPhases_file = str(Path(__file__).parent / "test_octet.dat")

dt = np.dtype(
    [
        ("number", int),
        ("shape", np.str_, 10),
        ("xc", np.float64),
        ("yc", np.float64),
        ("zc", np.float64),
        ("psi", np.float64),
        ("theta", np.float64),
        ("phi", np.float64),
        ("a1", np.float64),
        ("a2", np.float64),
    ]
)
# précision du type des données
DATA = np.loadtxt(
    NPhases_file,
    dtype=dt,
    usecols=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9),
    skiprows=1,
    unpack=True,
    ndmin=1,
)

xc = DATA[2]
yc = DATA[3]
zc = DATA[4]
psi = DATA[5]
theta = DATA[6]
phi = DATA[7]
height = DATA[8]
radius = DATA[9]

# sections = read_sections(path_data,section_file)

rve = Rve(dim=1)
listPhases = []
listPeriodicPhases = []

n = len(xc)

for i in range(0, n):
    elem = Cylinder(
        center=(xc[i] - 0.5, yc[i] - 0.5, zc[i] - 0.5),
        orientation=(psi[i], theta[i], phi[i]),
        height=height[i],
        radius=radius[i],
    )
    listPhases.append(Phase(shape=elem.generate()))

for phase_elem in listPhases:
    periodicPhase = periodic(phase=phase_elem, rve=rve)
    listPeriodicPhases.append(periodicPhase)

phases_cut = cutPhases(phaseList=listPeriodicPhases, reverseOrder=False)
compound = cq.Compound.makeCompound([phase.shape for phase in phases_cut])

step_file = str(Path(__file__).parent / "octettruss.step")
stl_file = str(Path(__file__).parent / "octettruss.stl")
cq.exporters.export(compound, step_file)
cq.exporters.export(compound, stl_file)

vtk_file = str(Path(__file__).parent / "octettruss.vtk")
meshPeriodic(
    mesh_file=step_file,
    rve=rve,
    listPhases=phases_cut,
    order=1,
    size=0.03,
    output_file=vtk_file,
)
../_images/octettruss.png

Honeycomb

from pathlib import Path

import cadquery as cq
import numpy as np

from microgen import Box, ExtrudedPolygon, Phase, cutPhaseByShapeList, mesh

side_length = 2.5  # side in mm of the hexagon
poly_height = 2.5  # height in mm of the hexagon
theta = 30 * np.pi / 180  # half angle of the hexagone

h0 = 0.5 * poly_height
h1 = np.cos(theta) * side_length
h2 = abs(np.sin(theta) * side_length)

thickness = 30  # mm

data_file = str(Path(__file__).parent / "seedList.data")
with open(data_file) as f:
    seedList = [[1, 1, 1]]
    seedList = np.genfromtxt(f, delimiter="\t")

box = Box(dim=(thickness, 60, 60))

shapeList = []
for seed in seedList:
    poly = ExtrudedPolygon(
        center=(seed[0] - thickness, seed[1], seed[2]),
        listCorners=[
            (0, h2 + h0),
            (h1, h0),
            (h1, -h0),
            (0, -h2 - h0),
            (-h1, -h0),
            (-h1, h0),
            (0, h2 + h0),
        ],
        height=thickness,
    )
    shapeList.append(poly.generate())

boxPhase = Phase(shape=box.generate())

honeycomb = cutPhaseByShapeList(phaseToCut=boxPhase, cqShapeList=shapeList)

step_file = str(Path(__file__).parent / "honeycomb.step")
stl_file = str(Path(__file__).parent / "honeycomb.stl")
cq.exporters.export(honeycomb.shape, step_file)
cq.exporters.export(honeycomb.shape, stl_file)
vtk_file = str(Path(__file__).parent / "honeycomb.vtk")
mesh(
    mesh_file=step_file,
    listPhases=[honeycomb],
    size=1,
    order=1,
    output_file=vtk_file,
)
../_images/honeycomb.png