Microgen modules
Phase module
Phase class to manage list of solids belonging to the same phase
- class microgen.phase.Phase(shape: Shape | None = None, solids: List[Solid] | None = None, center: Tuple[float, float, float] | None = None, orientation: Tuple[float, float, float] | None = None)
Bases:
object
Phase class to manage list of solids belonging to the same phase properties: centerOfMass, inertiaMatrix, shape, solids
- Parameters:
shape – Shape object
solids – list of cq.Solid or list of list
center – center
orientation – orientation
- property centerOfMass: ndarray
Returns the center of ‘mass’ of an object. :param compute: if False and centerOfMass already exists, does not compute it (use carefully)
- classmethod generatePhasePerRaster(solidList: List[Solid], rve: Rve, grid: List[int]) List[Phase]
Rasters solids from phase according to the rve divided by the given grid
- Parameters:
solidList – list of solids
grid – number of divisions in each direction [x, y, z]
rve – RVE divided by the given grid
- Returns:
list of Phases
- classmethod generate_phase_per_raster(solids: list[Solid], rve: Rve, grid: list[int]) list[Phase]
Rasters solids from phase according to the rve divided by the given grid
- Parameters:
solidList – list of solids
grid – number of divisions in each direction [x, y, z]
rve – RVE divided by the given grid
- Returns:
list of Phases
- getCenterOfMass(compute: bool = True) ndarray
Returns the center of ‘mass’ of an object. :param compute: if False and centerOfMass already exists, does not compute it (use carefully)
- getInertiaMatrix(compute: bool = True) ndarray
Calculates the inertia Matrix of an object. :param compute: if False and inertiaMatrix already exists, does not compute it (use carefully)
- property inertiaMatrix: ndarray
Calculates the inertia Matrix of an object. :param compute: if False and inertiaMatrix already exists, does not compute it (use carefully)
- numInstances = 0
- rasterize(rve: Rve, grid: List[int], phasePerRaster: bool = True) List[Phase] | None
Rasters solids from phase according to the rve divided by the given grid
- Parameters:
rve – RVE divided by the given grid
grid – number of divisions in each direction [x, y, z]
phasePerRaster – if True, returns list of phases
- Returns:
list of Phases if required
- repeat(rve: Rve, grid: Tuple[int, int, int]) None
Repeats phase in each direction according to the given grid
- Parameters:
rve – RVE of the phase to repeat
grid – list of number of phase repetitions in each direction
- static repeatShape(unit_geom: Shape, rve: Rve, grid: Tuple[int, int, int]) Shape
Repeats unit geometry in each direction according to the given grid
- Parameters:
unit_geom – Shape to repeat
rve – RVE of the geometry to repeat
grid – list of number of geometry repetitions in each direction
- Returns:
cq shape of the repeated geometry
- static repeat_shape(unit_geom: Shape, rve: Rve, grid: tuple[int, int, int]) Shape
Repeats unit geometry in each direction according to the given grid
- Parameters:
unit_geom – Shape to repeat
rve – RVE of the geometry to repeat
grid – list of number of geometry repetitions in each direction
- Returns:
cq shape of the repeated geometry
- rescale(scale: float | Tuple[float, float, float]) None
Rescale phase according to scale parameters [dim_x, dim_y, dim_z]
- Parameters:
scale – float or list of scale factor in each direction
- static rescaleShape(shape: Shape, scale: float | Tuple[float, float, float]) Shape
Rescale given object according to scale parameters [dim_x, dim_y, dim_z]
- Parameters:
shape – Shape
scale – float or list of scale factor in each direction
- Return shape:
rescaled Shape
- property shape: Shape | None
- property solids: List[Solid]
- split_solids(rve: Rve, grid: List[int]) List[Solid]
Split solids from phase according to the rve divided by the given grid
- Parameters:
rve – RVE divided by the given grid
grid – number of divisions in each direction [x, y, z]
- Returns:
list of solids
- translate(vec: Sequence[float]) None
Operations
Boolean operations
- microgen.operations.cutPhaseByShapeList(phaseToCut: Phase, cqShapeList: List[Shape]) Phase
Cuts a phase by a list of shapes
- Parameters:
phaseToCut – phase to cut
cqShapeList – list of cutting shapes
- Return resultCut:
cut phase
- microgen.operations.cutPhases(phaseList: List[Phase], reverseOrder: bool = True) List[Phase]
Cuts list of shapes in the given order (or reverse) and fuse them.
- Parameters:
phaseList – list of phases to cut
reverseOrder – bool, order for cutting shapes, when True: the last shape of the list is not cut
:return list of phases
- microgen.operations.cutPhasesByShape(phaseList: List[Phase], cut_obj: Shape) List[Phase]
Cuts list of phases by a given shape
- Parameters:
phaseList – list of phases to cut
cut_obj – cutting object
- Return phase_cut:
final result
- microgen.operations.cutShapes(cqShapeList: List[Shape], reverseOrder: bool = True) List[Shape]
Cuts list of shapes in the given order (or reverse) and fuse them.
- Parameters:
cqShapeList – list of CQ Shape to cut
reverseOrder – bool, order for cutting shapes, when True: the last shape of the list is not cut
- Return cutted_shapes:
list of CQ Shape
- microgen.operations.fuseShapes(cqShapeList: List[Shape], retain_edges: bool) Shape
Fuse all shapes in cqShapeList
- Parameters:
cqShapeList – list of shapes to fuse
retain_edges – retain intersecting edges
:return fused object
- microgen.operations.rasterPhase(phase: Phase, rve: Rve, grid: List[int], phasePerRaster: bool = True) Phase | List[Phase]
Rasters solids from phase according to the rve divided by the given grid
- Parameters:
phase – phase to raster
rve – RVE divided by the given grid
grid – number of divisions in each direction [x, y, z]
phasePerRaster – if True, returns list of phases
- Returns:
Phase or list of Phases
- microgen.operations.repeatPolyData(mesh: PolyData, rve: Rve, grid: Tuple[int, int, int]) PolyData
Repeats mesh in each direction according to the given grid
- Parameters:
mesh – pv.PolyData to repeat
rve – RVE of the geometry to repeat
grid – list of number of geometry repetitions in each direction
- Returns:
pv.PolyData of the repeated geometry
- microgen.operations.repeatShape(unit_geom: Shape, rve: Rve, grid: Tuple[int, int, int]) Shape
Repeats unit geometry in each direction according to the given grid
- Parameters:
unit_geom – Shape to repeat
rve – RVE of the geometry to repeat
grid – list of number of geometry repetitions in each direction
- Returns:
cq shape of the repeated geometry
- microgen.operations.repeat_shape(unit_geom: Shape, rve: Rve, grid: Tuple[int, int, int]) Shape
Repeats unit geometry in each direction according to the given grid
- Parameters:
unit_geom – Shape to repeat
rve – RVE of the geometry to repeat
grid – list of number of geometry repetitions in each direction
- Returns:
cq shape of the repeated geometry
- microgen.operations.rescale(shape: Shape, scale: float | Tuple[float, float, float]) Shape
Rescale given object according to scale parameters [dim_x, dim_y, dim_z]
- Parameters:
shape – Shape
scale – float or list of scale factor in each direction
- Return shape:
rescaled Shape
- microgen.operations.rotateEuler(obj: Shape | Workplane, center: ndarray | Tuple[float, float, float], psi: float, theta: float, phi: float) Shape | Workplane
Rotates object according to XZX Euler angle convention
- Parameters:
obj – Object to rotate
center – numpy array (x, y, z)
psi – first Euler angle, in degrees
theta – first Euler angle, in degrees
phi – first Euler angle, in degrees
- Returns:
Rotated object
- microgen.operations.rotatePvEuler(obj: PolyData, center: Sequence[float], psi: float, theta: float, phi: float) PolyData
Rotates object according to XZX Euler angle convention
- Parameters:
obj – Object to rotate
center – numpy array (x, y, z)
psi – first Euler angle, in degrees
theta – second Euler angle, in degrees
phi – third Euler angle, in degrees
- Returns:
Rotated object
Rve
Representative Volume Element (RVE).
- class microgen.rve.Rve(dim_x: float | None = None, dim_y: float | None = None, dim_z: float | None = None, center: Vector3DType = (0, 0, 0), dim: float | Vector3DType = 1)
Bases:
object
Representative Volume Element (RVE).
- Parameters:
dim_x – X dimension of the RVE
dim_y – Y dimension of the RVE
dim_z – Z dimension of the RVE
center – center of the RVE
dim – dimensions of the RVE
- classmethod from_min_max(x_min: float = -0.5, x_max: float = 0.5, y_min: float = -0.5, y_max: float = 0.5, z_min: float = -0.5, z_max: float = 0.5) Rve
Generate a Rve from the min - max values.
- Parameters:
x_min – min X dimension of the RVE
x_max – max X dimension of the RVE
x_min – min Y dimension of the RVE
x_max – max Y dimension of the RVE
x_min – min Z dimension of the RVE
x_max – max Z dimension of the RVE
Periodic
Periodic function to cut a shape periodically according to a RVE
Mesh
Mesh using gmsh
- exception microgen.mesh.OutputMeshNotPeriodicError
Bases:
Exception
Raised when output mesh from meshPeriodic is not periodic
- microgen.mesh.is_periodic(nodes_coords: ndarray[Any, dtype[float64]], tol: float = 1e-08, dim: int = 3) bool
Checks whether a mesh is periodic, given its nodes’ coordinates
- Parameters:
nodes_coords – list of nodes coordinates of the analyzed mesh
tol – tolerance
dim – mesh dimension
- microgen.mesh.mesh(mesh_file: str, listPhases: List[Phase], size: float, order: int, output_file: str = 'Mesh.msh', mshFileVersion: int = 4) None
Meshes step file with gmsh with list of phases management
- Parameters:
mesh_file – step file to mesh
listPhases – list of phases to mesh
size – mesh size constraint (see: gmsh.model.mesh.setSize(dimTags, size))
order – see gmsh.model.mesh.setOrder(order)
output_file – output file (.msh, .vtk)
mshFileVersion – gmsh file version
- microgen.mesh.meshPeriodic(mesh_file: str, rve: Rve, listPhases: List[Phase], size: float, order: int, output_file: str = 'MeshPeriodic.msh', mshFileVersion: int = 4, tol: float = 1e-08) None
Meshes periodic geometries with gmsh
- Parameters:
mesh_file – step file to mesh
rve – RVE for periodicity
listPhases – list of phases to mesh
size – mesh size constraint (see: gmsh.model.mesh.setSize(dimTags, size))
order – see gmsh.model.mesh.setOrder(order)
output_file – output file (.msh, .vtk)
mshFileVersion – gmsh file version
tol – tolerance for periodicity check
Remesh
- exception microgen.remesh.InputMeshNotPeriodicError
Bases:
Exception
Raised when input mesh of remesh_keeping_periodicity_for_fem is not periodic
- exception microgen.remesh.OutputMeshNotPeriodicError
Bases:
Exception
Raised when output mesh of remesh_keeping_periodicity_for_fem is not periodic
- microgen.remesh.remesh_keeping_periodicity_for_fem(input_mesh: BoxMesh, mesh_version: int = 2, dimension: int = 3, tol: float = 1e-08, hausd: float | None = None, hgrad: float | None = None, hmax: float | None = None, hmin: float | None = None, hsiz: float | None = None) BoxMesh
- microgen.remesh.remesh_keeping_periodicity_for_fem(input_mesh: UnstructuredGrid, mesh_version: int = 2, dimension: int = 3, tol: float = 1e-08, hausd: float | None = None, hgrad: float | None = None, hmax: float | None = None, hmin: float | None = None, hsiz: float | None = None) UnstructuredGrid
Remeshes a mesh using mmg while keeping periodicity
- Parameters:
input_mesh – BoxMesh or pv.UnstructuredGrid mesh to be remeshed
mesh_version – mesh file version (default: 2)
dimension – mesh dimension (default: 3)
tol – tolerance for periodicity check
The following parameters are used to control mmg remeshing, see here for more info : https://www.mmgtools.org/mmg-remesher-try-mmg/mmg-remesher-options
- Parameters:
hausd – Maximal Hausdorff distance for the boundaries approximation
hgrad – Gradation value, ie ratio between lengths of adjacent mesh edges
hmax – Maximal edge size
hmin – Minimal edge size
hsiz – Build a constant size map of size hsiz
External
- Functions related to external software
- class microgen.external.Mmg
Bases:
object
- static mmg2d(d=None, h=None, m=None, v=None, val=None, default=None, input=None, output=None, solution=None, metric=None, A=None, ar=None, hausd=None, hgrad=None, hmax=None, hmin=None, hsiz=None, lag=None, ls=None, _3dMedit=None, noinsert=None, nomove=None, nosurf=None, noswap=None, nr=None, nreg=None, nsd=None, optim=None, opnbdy=None, rmc=None)
Runs mmg2d_O3 from the command line with given arguments
- static mmg3d(d=None, h=None, m=None, v=None, val=None, default=None, input=None, output=None, solution=None, metric=None, A=None, ar=None, octree=None, hausd=None, hgrad=None, hmax=None, hmin=None, hsiz=None, lag=None, ls=None, nofem=None, noinsert=None, nomove=None, nosurf=None, noswap=None, nr=None, nreg=None, nsd=None, optim=None, optimLES=None, opnbdy=None, rmc=None, rn=None)
Runs mmg3d_O3 from the command line with given arguments
- static mmgs(d=None, h=None, m=None, v=None, val=None, default=None, input=None, output=None, solution=None, metric=None, A=None, ar=None, hausd=None, hgrad=None, hmax=None, hmin=None, hsiz=None, ls=None, noinsert=None, nomove=None, nosurf=None, noswap=None, nr=None, nreg=None, nsd=None, optim=None, rn=None)
Runs mmgs_O3 from the command line with given arguments
- exception microgen.external.MmgError
Bases:
Exception
Raised when Mmg command fails
- class microgen.external.Neper
Bases:
object
- static generateVoronoiFromTessFile(filename: str) List[Polyhedron]
Generates list of Voronoi polyhedron shapes from a tessellation file generated with neper
- static run(filename: str, nbCell: int, dimCube: Tuple[float, float, float]) None
Runs neper command from the command line
command = neper -T -n nbCell -id 1 -dim 3 -domain ‘cube(dimCube[0], dimCube[1], dimCube[2])’ -morpho gg -o filename
- Parameters:
filename – output file
nbCell – Specify the number of cells of the tessellation
dimCube – neper’s documentation
- microgen.external.parseNeper(filename: str) tuple
Parses .tess tessellation file obtained with neper :param filename: .tess file name