mesh¶
The mesh module provides mesh generators: methods that return a topology and an
accompanying geometry function. Meshes can either be generated on the fly, e.g.
rectilinear()
, or read from external an externally prepared file,
gmsh()
, and converted to nutils format. Note that no mesh writers are
provided at this point; output is handled by the nutils.plot
module.

nutils.mesh.
rectilinear
(richshape, periodic=(), name='rect')¶ rectilinear mesh

nutils.mesh.
multipatch
(patches, nelems, patchverts=None, name='multipatch')¶ multipatch rectilinear mesh generator
Generator for a
MultipatchTopology
and geometry. TheMultipatchTopology
consists of a set patches, where each patch is aStructuredTopology
and all patches have the same number of dimensions.The
patches
argument, anumpy.ndarray
like with shape(npatches, 2*ndims)
or(npatches,)+(2,)*ndims
, defines the connectivity by labelling the patch vertices. For example, three onedimensional patches can be connected at one edge by:# connectivity: 3 # │ # 1──0──2 patches=[[0,1], [0,2], [0,3]]
Or two twodimensional patches along an edge by:
# connectivity: 3──4──5 # │ │ │ # 0──1──2 patches=[[[0,3],[1,4]], [[1,4],[2,5]]]
The geometry is specified by the
patchverts
argument: anumpy.ndarray
like with shape(nverts,ngeomdims)
specifying for each vertex a coordinate. Note that the dimension of the geometry may be higher than the dimension of the patches. The created geometry is a patchwise linear interpolation of the vertex coordinates. If thepatchverts
argument is omitted the geometry describes a unit hypercube per patch.The
nelems
argument is either anint
defining the number of elements per patch per dimension, or adict
with edges (a pair of vertex numbers) as keys and the number of elements (int
) as values, with keyNone
specifying the default number of elements. Example:# connectivity: 3─────4─────5 # │ 4x3 │ 8x3 │ # 0─────1─────2 patches=[[[0,3],[1,4]], [[1,4],[2,5]]] nelems={None: 4, (1,2): 8, (4,5): 8, (0,3): 3, (1,4): 3, (2,5): 3}
Since the patches are structured topologies, the number of elements per patch per dimension should be unambiguous. In above example specifying
nelems={None: 4, (1,2): 8}
will raise an exception because the patch on the right has 8 elements along edge(1,2)
and 4 along(4,5)
.Example
An Lshaped domain can be generated by:
# connectivity: 2──5 # │  # 1──4─────7 y # │ │ │ │ # 0──3─────6 └──x domain, geom = mesh.multipatch( patches=[[0,1,3,4], [1,2,4,5], [3,4,6,7]], patchverts=[[0,0], [0,1], [0,2], [1,0], [1,1], [1,2], [3,0], [3,1]], nelems={None: 4, (3,6): 8, (4,7): 8})
The number of elements is chosen such that all elements in the domain have the same size.
A topology and geometry describing the surface of a sphere can be generated by creating a multipatch cube surface and inflating the cube to a sphere:
# connectivity: 3────7 # ╱│ ╱│ # 2────6 │ y # │ │ │ │ │ # │ 1──│─5 │ z # │╱ │╱ │╱ # 0────4 *────x topo, cube = multipatch( patches=[ # The order of the vertices is chosen such that normals point outward. [2,3,0,1], [4,5,6,7], [4,6,0,2], [1,3,5,7], [1,5,0,4], [2,6,3,7], ], patchverts=tuple(itertools.product(*([[1,1]]*3))), nelems=10, ) sphere = cube / function.sqrt((cube**2).sum(0))
Parameters:  patches – A
numpy.ndarray
with shape sequence of patches with each patch being a list of vertex indices.  patchverts – A sequence of coordinates of the vertices.
 nelems – Either an
int
specifying the number of elements per patch per dimension, or adict
with edges (a pair of vertex numbers) as keys and the number of elements (int
) as values, with keyNone
specifying the default number of elements.
Returns: nutils.topology.MultipatchTopology
– The multipatch topology.nutils.function.Array
– The geometry defined by thepatchverts
or a unit hypercube per patch ifpatchverts
is not specified.
 patches – A

nutils.mesh.
gmsh
(fname, name='gmsh')¶ Gmsh parser
Parser for Gmsh files in .msh format. Only files with physical groups are supported. See the Gmsh manual for details.
Parameters: Returns:  topo (
nutils.topology.SimplexTopology
) – Topology of parsed Gmsh file.  geom (
nutils.function.Array
) – Isoparametric map.
 topo (

nutils.mesh.
fromfunc
(func, nelems, ndims, degree=1)¶ piecewise

nutils.mesh.
demo
(xmin=0, xmax=1, ymin=0, ymax=1)¶ demo triangulation of a rectangle

nutils.mesh.
unitsquare
(nelems, etype)¶ Unit square mesh.
Parameters: Returns: nutils.topology.Topology
– The structured/unstructured topology.nutils.function.Array
– The geometry function.