morphogen.mesh.conforming

Conforming tetrahedral meshes of implicit morphologies.

The level-set function of a microstructure (negative inside phase 1) is sampled at the nodes of a background mesh of the box: a Kuhn triangulation of a regular grid (six tetrahedra per cube, so that the faces of the box are exactly represented). MMG (mmg3d -ls, LGPL; installed by the pymmg package or found on the PATH) discretizes the zero level set into a conforming interface between the two phases and remeshes the result: elements are adapted to the curvature of the interface within a Hausdorff distance, graded, and of good quality, while the faces of the box stay plane.

For periodic microstructures, opposite faces get matching nodes, so that periodic boundary conditions are exact: the level set takes the same values on opposite faces of the background mesh, MMG first discretizes it without remeshing (the cut faces match), then remeshes the volume and the interface while keeping the faces of the box unchanged (along all the axes, or some of them). Elsewhere, the faces are remeshed freely.

Mirrored meshes (mirrored_mesh()): a microstructure symmetric about the mid-planes of its box is meshed in the irreducible part of the box and reflected across them, so that the mesh has the symmetries exactly (an unstructured mesh of the whole box has none), which the analyses by group theory need (morphogen.homogenization. bifurcation); a periodic microstructure symmetric about its mid-planes is symmetric about the faces of its box too, so that the reflected faces match: periodic conditions apply. With the diagonal planes of a square or cubic box among its mirrors (the groups of the square, 4/mmm, and of the cube, m-3m), the irreducible part is the chamber of the group (a triangular prism, a tetrahedron), a union of tetrahedra of the background mesh, meshed and mapped by every operation of the group. ImplicitBody makes a microstructure of a level-set function.

Sharp edges. The function of a union of spheres or segments has a fold where two of them meet, and its surface a sharp edge there (a groove), which a function sampled on a grid rounds. The structures made of such primitives give the smooth pieces of their phases (morphogen.models.pieces: primitives that do not overlap); the box is then cut by the surface of each piece in turn, the function of the piece taken at the vertices themselves, and the lines where two cuts meet — the sharp edges — are edges of the mesh, given to MMG as ridges and kept through the remeshing (sharp_edges; sharp).

Element sizes: size bounds the edge length (-hmax); the interface is refined to follow its curvature within the Hausdorff distance hausdorff. Thin features must be resolved by the background grid (background, default size / 2) and by a few elements: a sheet of thickness t needs size of the order of t with 10-node elements, smaller with 4-node elements.

morphogen.mesh.conforming.REF_INSIDE = 3

MMG references of the subdomains created by the level-set discretization

morphogen.mesh.conforming.REF_OUTSIDE = 2

MMG references of the subdomains created by the level-set discretization

morphogen.mesh.conforming.REF_INTERFACE = 10

MMG references of the subdomains created by the level-set discretization

morphogen.mesh.conforming.REF_PHASE = 20

this plus their phase

Type:

The references of the tetrahedra of a mesh of several phases

morphogen.mesh.conforming.SNAP = 0.2

Level-set values closer to zero than this fraction of an edge of the background mesh (times the gradient) are moved away from zero: the interface then never cuts an edge close to a node, which avoids slivers and halves the remeshing time; the interface moves by at most this fraction of the background spacing.

morphogen.mesh.conforming.REF_PIECE = 1000

The references of the tetrahedra of the pieces of a mesh cut piece by piece (the meshes that follow sharp edges): this plus the number of their piece

morphogen.mesh.conforming.REF_SHARP = 1000

The references of the edges of MMG’s mesh along the sharp edges of an interface: this plus a number of the two pieces that meet there

morphogen.mesh.conforming.SNAP_SHARP = 0.05

the lines where two cuts meet are the sharp edges, which a smaller share keeps within the Hausdorff distance of the remeshing

Type:

SNAP for the cuts of the pieces

morphogen.mesh.conforming.mmg_executable(path: str | None = None, program: str = 'mmg3d') → str[source]

Path of an MMG executable (mmg3d or mmg2d): explicit, $MORPHOGEN_MMG3D ($MORPHOGEN_MMG2D), the pymmg package, or mmg3d_O3 / mmg3d on the PATH.

morphogen.mesh.conforming.has_mmg() → bool[source]

Whether the MMG mesher is available.

morphogen.mesh.conforming.background_mesh(shape, lower, upper)[source]

Triangulation of the box in six tetrahedra per cube: nodes, positive tetrahedra, boundary triangles and their references (1-6 for the faces x0, x1, y0, y1, z0, z1).

Each cube is split along a main diagonal (Kuhn triangulation), reflected along the axes where the cube index is odd: the triangulation stays conforming, its opposite faces match, and it is symmetric with respect to the planes of the grid (a single diagonal direction would bias the discretized interfaces and make the apparent stiffness of cubic structures slightly anisotropic).

morphogen.mesh.conforming.node_level_set(micro, spacing: float, phase: int | None = None) → tuple[ndarray, tuple[int, int, int]][source]

Level-set values at the nodes of a regular grid covering the box exactly: those of the phase 1, or of the implicit function of phase (phase_level_set()).

morphogen.mesh.conforming.background_interpolation(values: ndarray, lower, upper, points) → ndarray[source]

The values at points of the function that is linear in each tetrahedron of the background mesh (background_mesh()) and takes values at its nodes (an array over the nodes of the grid): in the cube of a point, mirrored along the axes where its index is odd, the tetrahedron is that of the order of its coordinates.

morphogen.mesh.conforming.conforming_mesh(micro, *, size: float, min_size: float | None = None, hausdorff: float | None = None, gradation: float = 2.0, background: float | None = None, phases: str = 'all', order: int = 1, curved: bool | None = None, periodic: bool | None = None, remove_islands: float | None = 1e-05, sharp_edges: bool | None = None, grains: bool | None = None, min_feature: float | None = None, cells: str = 'whole', method: str = 'auto', executable: str | None = None, workdir=None, timeout: float | None = None) → TetMesh[source]

Tetrahedral mesh of a microstructure, conforming to the interface of its phases.

By default from its exact geometry, without a background grid, when the microstructure knows it (method; morphogen.mesh.exact). Voronoi and Laguerre tessellations are meshed grain by grain from their cells (morphogen.mesh.polycrystal.polycrystal_mesh()): every grain boundary is conforming, and each element knows its grain (mesh.cell) and its crystal orientation (mesh.orientations).

Parameters:
  • size – Largest element size (-hmax).

  • min_size – Smallest element size (default size / 10) and Hausdorff distance between the meshed and the discrete interfaces (default size / 20).

  • hausdorff – Smallest element size (default size / 10) and Hausdorff distance between the meshed and the discrete interfaces (default size / 20).

  • gradation – Maximal ratio of the sizes of neighbouring elements (-hgrad).

  • background – Spacing of the grid sampling the level set (default size / 2): it bounds the geometric accuracy of the interface. Give at least three samples across the thinnest feature (sheet, strut, fibre): an under-resolved level set biases the volume fraction and the apparent properties (by a few percent for two samples).

  • phases – "all" meshes both phases (composites); "solid" meshes phase 1 only (porous media: the pores carry no stress), "matrix" phase 0 only (the pores are phase 1, e.g. spherical pores in a matrix). Structures of more than two phases, or of other phases than 0 and 1 (coated inclusions, inclusions in a polycrystal, cells of several phases, osteons…), are meshed conforming to the interfaces of all their phases, each cut by its implicit function (phase_level_sets_at() on the exact route, phase_level_set() on the grid) in the part of the box that the previous ones left: "all", or the phases to keep (a list, of any structure).

  • order – 1 (4-node tetrahedra) or 2 (10-node tetrahedra).

  • curved – 10-node elements: put the nodes of the interfaces, corners and mid-edge nodes, on the implicit surfaces of the phases, so that the elements along the interfaces have curved edges (isoparametric elements, morphogen.mesh.curved.curved_mesh()) and the phases their volumes: by default; false keeps the flat faces that MMG makes, with the mid-edge nodes at the middles of their edges. The grain boundaries of tessellations are plane.

  • periodic – Opposite faces with matching nodes, for periodic boundary conditions (default: when the microstructure is periodic), or three booleans: along those axes only. The level set is cut on the background mesh, whose faces match, then MMG remeshes the inside and the interface while the faces of the box along those axes stay unchanged.

  • remove_islands – Relative volume below which MMG removes isolated components (-rmc; non-periodic meshes only).

  • sharp_edges – Follow the sharp edges of the phases with edges of the mesh: the grooves where the spheres or the segments of a union overlap, those of their coatings and of their bores. The structure gives the smooth pieces of its phases (implicit_pieces()), the box is cut by the surface of each in turn, and the lines where two cuts meet are kept as ridges through the remeshing (mesh.sharp: these edges; the curved elements then put their nodes on both surfaces). By default, when the structure gives pieces that meet; false cuts the box by the function of each phase, which rounds its sharp edges over an element. The overlaps shallower than the hausdorff distance (exact route) or half the background spacing (grid) are not followed. The cells and convex pieces of the exact route keep the edges of their facets.

  • grains – Mesh the grains of a tessellation (default: for Voronoi and Laguerre tessellations without a grain-boundary phase); False meshes only the interface between its phases (the grains and their boundary phase).

  • min_feature – Grains: features of the tessellation smaller than this length are removed before meshing (default size / 4).

  • cells – Grains of a periodic tessellation: "whole" (default) meshes the whole grains, periodized at the design (their union fills the volume of the box, their boundary is made of translated pairs of faces); "box" cuts them by the faces of the box.

  • method – "exact": the exact geometry, without a grid (morphogen.mesh.exact.exact_mesh(): the cells of tessellations, exact convex pieces, or the adaptive mesh of the exact level set, refined to hausdorff and min_size; background unused); "grid": the level set sampled on a background grid of spacing background; "auto" (default): "exact" when the microstructure has an exact route (morphogen.mesh.exact.exact_route(): every structure that gives the functions of its phases at any point, of two phases or more, the phases kept by a list and the sharp edges of smooth pieces included; not transparent dead leaves, the coatings of structures that are not unions of spheres and segments, nor cells carrying crystal orientations but tessellations), "grid" otherwise, and should the exact mesh fail (MMG) or its periodic faces not match. The 10-node elements of a level set are those of its 4-node mesh on either route, curved by morphogen.mesh.curved.curved_mesh().

class morphogen.mesh.conforming.ImplicitBody(domain: Domain, function)[source]

Bases: object

A microstructure given by its level-set function in domain: function(points) of points (rows) negative inside phase 1, positive outside (for instance the distance to the nearest hole less its radius, for the solid of a porous plate).

level_set(shape=None, *, voxel_size=None, grid: Grid | None = None)[source]
morphogen.mesh.conforming.point_group(mirrors, diagonals=()) → list[ndarray][source]

The operations (3 x 3 matrices about the centre of the box) of the group generated by the reflections across the mid-planes of the axes mirrors and across the diagonal planes x_i - c_i = x_j - c_j of the pairs diagonals (axes among the mirrors): signed permutations, 16 for the square of 4/mmm (mirrors x, y, z and the diagonal of x and y), 48 for the cube of m-3m (two diagonals).

morphogen.mesh.conforming.mirrored_mesh(micro, *, size: float, mirrors=(0, 1, 2), diagonals=(), cells=(1, 1, 1), order: int = 1, phases: str = 'all', check: bool = True, **options) → TetMesh[source]

A conforming tetrahedral mesh of a microstructure symmetric about the mid-planes of its box along the axes mirrors (see the module): the irreducible part of the box, halved along each of them, meshed by MMG (conforming_mesh(): size, phases and the other options; matching faces along the other axes), then reflected across the mid-planes, the nodes of each plane shared by its two halves. The mesh has these mirrors exactly, and its opposite faces match along every axis (the reflected ones, a periodic microstructure being symmetric about the faces of its box as well). diagonals: pairs of mirrored axes of equal edges whose diagonal planes through the centre, x_i - c_i = x_j - c_j, are mirrors too (((0, 1),) for the square of 4/mmm, ((0, 1), (1, 2)) for the cube of m-3m): the chamber of the group (point_group()) is meshed and mapped by each of its operations. cells: copies of the box side by side (a cell of several primitive cells, whose translations are exact symmetries of the mesh). check: the level set is sampled to verify its symmetry. Elements of order 1 or 2.