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.

nutils.mesh.
rectilinear
(richshape, periodic=(), name=None, space='X', root=None)¶ rectilinear mesh

nutils.mesh.
multipatch
(patches, nelems, patchverts=None, name=None)¶ 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 = 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
>>> import itertools >>> from nutils import function >>> topo, cube = multipatch( ... patches=[ ... [0,1,2,3], # x=1 ... [4,5,6,7], # x= 1 ... [0,1,4,5], # y=1 ... [2,3,6,7], # y= 1 ... [0,2,4,6], # z=1 ... [1,3,5,7], # z= 1 ... ], ... patchverts=tuple(itertools.product(*([[1,1]]*3))), ... nelems=1) >>> sphere = function.normalized(cube)
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.
parsegmsh
(mshdata)¶ Gmsh parser
Parser for Gmsh data in
msh2
ormsh4
format. See the Gmsh manual for details.Parameters: mshdata ( io.BufferedIOBase
) – Msh file contents.Returns: Keyword arguments for simplex()
Return type: dict

nutils.mesh.
gmsh
(fname, name='gmsh', *, space='X')¶ Gmsh parser
Parser for Gmsh files in .msh format. Only files with physical groups are supported. See the Gmsh manual for details.
Parameters:  fname (
str
orio.BufferedIOBase
) – Path to mesh file or mesh file object.  name (
str
orNone
) – Name of parsed topology, defaults to ‘gmsh’.
Returns:  topo (
nutils.topology.SimplexTopology
) – Topology of parsed Gmsh file.  geom (
nutils.function.Array
) – Isoparametric map.
 fname (

nutils.mesh.
simplex
(nodes, cnodes, coords, tags, btags, ptags, name='simplex', *, space='X')¶ Simplex topology.
Parameters:  nodes (
numpy.ndarray
) – Vertex indices as (nelems x ndims+1) integer array, sorted along the second dimension. This table fully determines the connectivity of the simplices.  cnodes (
numpy.ndarray
) – Coordinate indices as (nelems x ncnodes) integer array following Nutils’ conventions for Bernstein polynomials. The polynomial degree is inferred from the array shape.  coords (
numpy.ndarray
) – Coordinates as (nverts x ndims) float array to be indexed bycnodes
.  tags (
dict
) – Dictionary of name>element numbers. Element order is preserved in the resulting volumetric groups.  btags (
dict
) – Dictionary of name>edges, where edges is a (nedges x 2) integer array containing pairs of element number and edge number. The segments are assigned to boundary or interfaces groups automatically while otherwise preserving order.  ptags (
dict
) – Dictionary of name>node numbers referencing thenodes
table.  name (
str
) – Name of simplex topology.
Returns:  topo (
nutils.topology.SimplexTopology
) – Topology with volumetric, boundary and interface groups.  geom (
nutils.function.Array
) – Geometry function.
 nodes (

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

nutils.mesh.
unitsquare
(nelems, etype)¶ Unit square mesh.
Parameters:  nelems (
int
) – Number of elements along boundary  etype (
str
) –Type of element used for meshing. Supported are:
"square"
or"rectilinear"
: structured mesh of squares."triangle"
: unstructured mesh of triangles."mixed"
: unstructured mesh of triangles and squares."multipatch"
: multipatch mesh consisting of five patches with the following structure:
*─────* │╲ ╱│ │ *─* │ │ │ │ │ │ *─* │ │╱ ╲│ *─────*
Returns: nutils.topology.TransformChainsTopology
– The structured/unstructured topology.nutils.function.Array
– The geometry function.
 nelems (

nutils.mesh.
unitcircle
(nelems, variant)¶ Unit circle mesh.
The circle is centered at coordinate
(0, 0)
and has unit radius.Parameters:  nelems (
int
) – Number of elements along boundary  variant (
str
) –Mesh variant. Supported are:
"rectilinear"
: structured mesh of squares, blownup to a circle."multipatch"
: multipatch mesh consisting of five patches with the same topological structure asunitsquare()
withetype='multipatch'
.
Returns: nutils.topology.TransformChainsTopology
– The structured/unstructured topology.nutils.function.Array
– The geometry function.
 nelems (