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:
objectPhase 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
See get_center_of_mass.
Deprecated in favor of get_center_of_mass.
- property center_of_mass: ndarray[tuple[Any, ...], dtype[float64]]
Return the center of ‘mass’ of an object.
- Parameters:
compute – if False and centerOfMass already exists, does not compute it (use carefully)
- classmethod generatePhasePerRaster(solidList: list[cq.Solid], rve: Rve, grid: list[int]) list[Phase]
See generate_phase_per_raster.
Deprecated in favor of generate_phase_per_raster.
- classmethod generate_phase_per_raster(solids: list[cq.Solid], rve: Rve, grid: list[int]) list[Phase]
Raster 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
See get_center_of_mass.
Deprecated in favor of get_center_of_mass.
- getInertiaMatrix(compute: bool = True) ndarray
See get_inertia_matrix.
Deprecated in favor of get_inertia_matrix.
- get_center_of_mass(*, compute: bool = True) ndarray[tuple[Any, ...], dtype[float64]]
Return the center of ‘mass’ of an object.
- Parameters:
compute – if False and centerOfMass already exists, does not compute it (use carefully)
- get_inertia_matrix(*, compute: bool = True) ndarray[tuple[Any, ...], dtype[float64]]
Calculate the inertia Matrix of an object.
- Parameters:
compute – if False and inertiaMatrix already exists, does not compute it (use carefully)
- property inertiaMatrix: ndarray
See get_inertia_matrix.
Deprecated in favor of get_inertia_matrix.
- property inertia_matrix: ndarray[tuple[Any, ...], dtype[float64]]
Calculate the inertia Matrix of an object.
- Parameters:
compute – if False and inertiaMatrix already exists, does not compute it (use carefully)
- num_instances = 0
- rasterize(rve: Rve, grid: list[int], phasePerRaster: bool | None = None, *, phase_per_raster: bool = True) list[Phase] | None
Raster 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]
phase_per_raster – if True, returns list of phases
- Returns:
list of Phases if required
- repeat(rve: Rve, grid: tuple[int, int, int]) None
Repeat 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: cq.Shape, rve: Rve, grid: tuple[int, int, int]) cq.Shape
See repeat_shape.
Deprecated in favor of repeat_shape.
- static repeat_shape(unit_geom: cq.Shape, rve: Rve, grid: tuple[int, int, int]) cq.Shape
Repeat 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
See rescale_shape.
Deprecated in favor of rescale_shape.
- static rescale_shape(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
Return the shape of the phase.
- property solids: list[Solid]
Return the list of solids of the phase.
- split_solids(rve: Rve, grid: list[int]) list[cq.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
Translate phase by a given vector.
Operations
Boolean operations.
- microgen.operations.cutPhaseByShapeList(phaseToCut: Phase, cqShapeList: list[Shape]) Phase
See cut_phase_by_shape_list.
Deprecated in favor of cut_phase_by_shape_list.
- microgen.operations.cutPhases(phaseList: list[Phase], reverseOrder: bool = True) list[Phase]
See cut_phases.
Deprecated in favor of cut_phases.
- microgen.operations.cutPhasesByShape(phaseList: list[Phase], cut_obj: Shape) list[Phase]
See cut_phases_by_shape.
Deprecated in favor of cut_phases_by_shape.
- microgen.operations.cutShapes(cqShapeList: list[Shape], reverseOrder: bool = True) list[Shape]
See cut_shapes.
Deprecated in favor of cut_shapes.
- microgen.operations.cut_phase_by_shape_list(phase_to_cut: Phase, shapes: list[Shape]) Phase
Cut a phase by a list of shapes.
- Parameters:
phase_to_cut – phase to cut
shapes – list of cutting shapes
- Return resultCut:
cut phase
- microgen.operations.cut_phases(phases: list[Phase], *, reverse_order: bool = True) list[Phase]
Cut list of shapes in the given order (or reverse) and fuse them.
- Parameters:
phases – list of phases to cut
reverse_order – bool, order for cutting shapes, when True: the last shape of the list is not cut
:return list of phases
- microgen.operations.cut_phases_by_shape(phases: list[Phase], cut_obj: Shape) list[Phase]
Cut list of phases by a given shape.
- Parameters:
phases – list of phases to cut
cut_obj – cutting object
- Return phase_cut:
final result
- microgen.operations.cut_shapes(shapes: list[Shape], *, reverse_order: bool = True) list[Shape]
Cut list of shapes in the given order (or reverse) and fuse them.
- Parameters:
shapes – list of CQ Shape to cut
reverse_order – 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
See fuse_shapes.
Deprecated in favor of fuse_shapes.
- microgen.operations.fuse_shapes(shapes: list[Shape], *, retain_edges: bool) Shape
Fuse all shapes in cqShapeList.
- Parameters:
shapes – 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]
See raster_phase.
Deprecated in favor of raster_phase.
- microgen.operations.raster_phase(phase: Phase, rve: Rve, grid: list[int], *, phase_per_raster: bool = True) Phase | list[Phase]
Raster 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]
phase_per_raster – if True, returns list of phases
- Returns:
Phase or list of Phases
- microgen.operations.repeatPolyData(mesh: pv.PolyData, rve: Rve, grid: tuple[int, int, int]) pv.PolyData
See repeat_polydata.
Deprecated in favor of repeat_polydata.
- microgen.operations.repeatShape(unit_geom: cq.Shape, rve: Rve, grid: tuple[int, int, int]) cq.Shape
See repeat_shape.
Deprecated in favor of repeat_shape.
- microgen.operations.repeat_polydata(mesh: pv.PolyData, rve: Rve, grid: tuple[int, int, int]) pv.PolyData
Repeat 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.repeat_shape(unit_geom: cq.Shape, rve: Rve, grid: tuple[int, int, int]) cq.Shape
Repeat 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.rotate(obj: T, center: ndarray[tuple[Any, ...], dtype[float64]] | Sequence[float], rotation: Rotation) T
Rotate object according to given rotation.
- Parameters:
obj – Object to rotate
center – numpy array (x, y, z)
rotation – scipy Rotation object
- Returns:
Rotated object
- Raises:
ValueError – if object type is not supported
- microgen.operations.rotateEuler(obj: Shape | Workplane, center: ndarray | tuple[float, float, float], psi: float, theta: float, phi: float) Shape | Workplane
See rotate_euler.
Deprecated in favor of rotate_euler.
- microgen.operations.rotatePvEuler(obj: PolyData, center: Sequence[float], psi: float, theta: float, phi: float) PolyData
See rotatePvEuler.
Deprecated in favor of rotatePvEuler.
- microgen.operations.rotate_euler(obj: Shape | Workplane, center: ndarray[tuple[Any, ...], dtype[float64]] | Sequence[float], angles_or_rotation: Sequence[float] | Rotation) Shape | Workplane
Rotate object according to ZXZ Euler angle convention.
- Parameters:
obj – Object to rotate
center – numpy array (x, y, z)
angles_or_rotation – list of Euler angles (psi, theta, phi) in degrees or scipy Rotation object
- Returns:
Rotated object
- microgen.operations.rotate_pv_euler(obj: PolyData, center: Sequence[float], angles_or_rotation: Sequence[float] | Rotation) PolyData
Rotate object according to ZXZ Euler angle convention.
- Parameters:
obj – Object to rotate
center – numpy array (x, y, z)
angles_or_rotation – list of Euler angles (psi, theta, phi) in degrees or scipy Rotation object
- 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:
objectRepresentative 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:
ExceptionRaised when output mesh from meshPeriodic is not periodic.
- microgen.mesh.is_periodic(nodes_coords: ndarray[tuple[Any, ...], dtype[float64]], tol: float = 1e-08, dim: int | None = None) bool
Check 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 (deprecated: unnecessary parameter)
- microgen.mesh.mesh(mesh_file: str, list_phases: list[Phase] | None = None, size: float | None = None, order: int | None = None, output_file: str = 'Mesh.msh', msh_file_version: int = 4, listPhases: list[Phase] | None = None, mshFileVersion: int | None = None) None
Mesh 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
Mesh 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
- microgen.mesh.mesh_periodic(mesh_file: str, rve: Rve, list_phases: list[Phase], size: float, order: int, output_file: str = 'MeshPeriodic.msh', msh_file_version: int = 4, tol: float = 1e-08) None
Mesh periodic geometries with gmsh.
- Parameters:
mesh_file – step file to mesh
rve – RVE for periodicity
list_phases – 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)
msh_file_version – gmsh file version
tol – tolerance for periodicity check
Remesh
Remesh a mesh using mmg while keeping boundaries untouched.
- exception microgen.remesh.InputMeshNotPeriodicError
Bases:
ExceptionRaised when input mesh of remesh_keeping_boundaries_for_fem with periodic=True option is not periodic.
- exception microgen.remesh.OutputMeshNotPeriodicError
Bases:
ExceptionRaised when output mesh of remesh_keeping_boundaries_for_fem with periodic=True option is not periodic.
- microgen.remesh.remesh_keeping_boundaries_for_fem(input_mesh: BoxMesh, periodic: bool = True, 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_boundaries_for_fem(input_mesh: UnstructuredGrid, periodic: bool = True, 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
Remesh a mesh using mmg while keeping boundary elements untouched.
- Parameters:
input_mesh – BoxMesh or pv.UnstructuredGrid mesh to be remeshed
periodic – whether the mesh is periodic and must stay periodic (default: True)
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
- microgen.remesh.remesh_keeping_periodicity_for_fem(input_mesh: BoxMesh | 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) BoxMesh | UnstructuredGrid
See remesh_keeping_boundaries_for_fem.
Deprecated in favor of remesh_keeping_boundaries_for_fem.
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:
ExceptionRaised 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