32. mesh — mesh.py

mesh.py

Definition of the Mesh class for describing discrete geometrical models. And some useful meshing functions to create such models.

class mesh.Mesh(coords=None, elems=None, prop=None, eltype=None)

A mesh is a discrete geometrical model consisting of nodes and elements.

In the Mesh geometrical data model, coordinates of all points are gathered in a single twodimensional array ‘coords’ with shape (ncoords,3) and the individual geometrical elements are described by indices into the ‘coords’ array. This model has some advantages over the Formex data model, where all points of all element are stored by their coordinates:

  • compacter storage, because coordinates of coinciding points do not need to be repeated,
  • faster connectivity related algorithms.

The downside is that geometry generating algorithms are far more complex and possibly slower.

In pyFormex we therefore mostly use the Formex data model when creating geometry, but when we come to the point of exporting the geometry to file (and to other programs), a Mesh data model may be more adequate.

The Mesh data model has at least the following attributes:

  • coords: (ncoords,3) shaped Coords array,
  • elems: (nelems,nplex) shaped array of int32 indices into coords. All values should be in the range 0 <= value < ncoords.
  • prop: array of element property numbers, default None.
  • eltype: string designing the element type, default None.

Create a new Mesh from the specified data.

data is either a tuple of (coords,elems) arrays, or an object having a ‘toMesh()’ method, which should return such a tuple.

Mesh objects have the following methods:

copy()
Return a copy using the same data arrays
toFormex()

Convert a Mesh to a Formex.

The Formex inherits the element property numbers and eltype from the Mesh. Node property numbers however can not be translated to the Formex data model.

data()
Return the mesh data as a tuple (coords,elems)
nelems()
nplex()
ncoords()
shape()
bbox()
nedges()

Return the number of edges.

Currently, the edges are not fused!

centroids()

Return the centroids of all elements of the Formex.

The centroid of an element is the point whose coordinates are the mean values of all points of the element. The return value is a Coords object with nelems points.

report()
compact()
Renumber the mesh and remove unconnected nodes.
extrude(n, step=1., dir=0, autofix=True)

Extrude a Mesh in one of the axes directions.

Returns a new Mesh obtained by extruding the given Mesh over n steps of length step in direction of axis dir. The returned Mesh has double plexitude of the original.

This function is usually used to extrude points into lines, lines into surfaces and surfaces into volumes. By default it will try to fix the connectivity ordering where appropriate. If autofix is switched off, the connectivities are merely stacked, and the user may have to fix it himself.

Currently, this function correctly transforms: point1 to line2, line2 to quad4, tri3 to wedge6, quad4 to hex8.

sweep(path, autofix=True)

Sweep a mesh along a path, creating an extrusion

Returns a new Mesh obtained by sweeping the given Mesh over a path. The returned Mesh has double plexitude of the original. The operation is similar to the extrude() method, but the path can be any 3D curve.

This function is usually used to extrude points into lines, lines into surfaces and surfaces into volumes. By default it will try to fix the connectivity ordering where appropriate. If autofix is switched off, the connectivities are merely stacked, and the user may have to fix it himself.

Currently, this function correctly transforms: point1 to line2, line2 to quad4, tri3 to wedge6, quad4 to hex8.

convert(fromtype, totype)

Convert a mesh from element type fromtype to type totype.

Currently defined conversions: ‘quad4’ -> ‘tri3’

classmethod concatenate(clas, ML)
Concatenate a list of meshes of the same plexitude and eltype

Functions defined in the module mesh

mesh.vectorPairAreaNormals(vec1, vec2)

Compute area of and normals on parallellograms formed by vec1 and vec2.

vec1 and vec2 are (n,3) shaped arrays holding collections of vectors. The result is a tuple of two arrays: - area (n) : the area of the parallellogram formed by vec1 and vec2. - normal (n,3) : (normalized) vectors normal to each couple (vec1,2). These are calculated from the cross product of vec1 and vec2, which indeed gives area * normal.

Note that where two vectors are parallel, an area zero will results and an axis with components NaN.

mesh.vectorPairCosAngles(vec1, vec2, normalized=False)

Return the cosine of the angles between two vectors.

vec1: an (nvector,3) shaped array of floats vec2: an (nvector,3) shaped array of floats normalized: can be set True if the vectors are already normalized.

Return value: an (nvector,) shaped array of floats

mesh.vectorPairAngles(vec1, vec2, normalized=False, angle_spec=Deg)
mesh.vectorRotation(vec1, vec2, upvec=[, 0., 0., 1.])

Return axis and angle to rotate vectors in a parallel to b

vectors in a and b should be unit vectors. The returned axis is the cross product of a and b. If the vectors are already parallel, a random vector normal to a is returned.

mesh.sweepCoords(path, origin=[, 0., 0., 0.], normal=0, upvector=None, avgdir=False, enddir=None)

Sweep a Coords object along a path, returning a series of copies.

origin and normal define the local path position and direction on the mesh.

At each point of the curve, a copy of the Coords object is created, with its origin in the curve’s point, and its normal along the curve’s direction. In case of a PolyLine, directions are pointing to the next point by default. If avgdir==True, average directions are taken at the intermediate points. Missing end directions can explicitely be set by enddir, and are by default taken along the last segment. If the curve is closed, endpoints are treated as any intermediate point, and the user should normally not specify enddir.

The return value is a sequence of the transformed Coords objects.

mesh.defaultEltype(nplex)
Default element type for a mesh with given plexitude.
mesh.connectMesh(mesh1, mesh2, n=1, n1=None, n2=None, eltype=None)

Connect two meshes to form a hypermesh.

mesh1 and mesh2 are two meshes with same topology (shape). The two meshes are connected by a higher order mesh with n elements in the direction between the two meshes. n1 and n2 are node selection indices permitting a permutation of the nodes of the base sets in their appearance in the hypermesh. This can e.g. be used to achieve circular numbering of the hypermesh.

mesh.connectMeshSequence(ML, loop=False)
mesh.createWedgeElements(S1, S2, div=1)
mesh.sweepGrid(nodes, elems, path, scale=1., angle=0., a1=None, a2=None)

Documentation

Previous topic

31. datareader — Numerical data reader

Next topic

33. fe — Finite Element Models in pyFormex.

This Page