mesh.py
Definition of the Mesh class for describing discrete geometrical models. And some useful meshing functions to create such models.
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:
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:
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:
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.
Return the number of edges.
Currently, the edges are not fused!
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.
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 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 a mesh from element type fromtype to type totype.
Currently defined conversions: ‘quad4’ -> ‘tri3’
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)¶