sfepy.mesh.meshutils module

Finite element mesh utilites.

exception sfepy.mesh.meshutils.MeshUtilsCheckError[source]

Function check failed.

exception sfepy.mesh.meshutils.MeshUtilsError[source]

Base class for exceptions in meshutils.

exception sfepy.mesh.meshutils.MeshUtilsParseError[source]

Parse error in input file.

exception sfepy.mesh.meshutils.MeshUtilsWarning[source]

Not necessarily error, but some strange thing happened.

class sfepy.mesh.meshutils.bound[source]

Handles all physical entities <= mshmodelnum.

This class is optionaly filled in mesh.readmsh() by calling the method bound.handle2(). It extracts only the node numbers of the entity. All entities are stored in self.f dictionary (key is the entity number).

Has methods to get the node numbers in PMD notation: (1 2 4 1 2 3 4 8 9 10 -> 1:4 8:10) ie. it removes any repeating numbers and shortens the list using ”:”

Has method to find elements from a given list, which lie on the boundary formed by nodes (also returns appropriate side of elements).

So - all boundary conditions should be done using this class.

associateelements(elements)[source]
associateelements_key(key, elements)[source]

Finds the elements under the key key in elements.

This is a regular (very slow, but bullet proof) version.

associateelements_key_fast(key, elements)[source]

Finds the elements under the key key in elements.

This is a fast version, which assumes an undocumented feature, that all the elements which gmsh exports are in exactly the same order both in the entity key and mshmodelnum.

finde(p, elements)[source]
findelements(key, elements)[source]

Returns element numbers (in a list), which lies at the boundary determined by self.nodes.

Also returns the side of element. Currently only support triangles and quadrangles.

fromstr(str)[source]
getf(key)[source]
getstr(key)[source]
handle(n, list)[source]

Appends number in ‘list’ to internal dictionary (key=n)

handle2(p)[source]
handleelement(p)[source]

Handles element - not for boundary conditions

readpmd(filename)[source]

Loads internal dictionary from ‘filename’.

Format must be the same as from write()

simplify(l)[source]

Removes repeating numbers and sorts the internal list l.

Note: it’s very slow for large meshes. This is the thing which slows down everything.

str(l)[source]

Converts l (must be a sorted list) to string (using ‘:’).

writeSV(f, els, key)[source]
writepmd(filename)[source]
sfepy.mesh.meshutils.check(s, what)[source]
sfepy.mesh.meshutils.error(s, type=0)[source]
sfepy.mesh.meshutils.flat(a)[source]
sfepy.mesh.meshutils.formatpos(n, T)[source]
sfepy.mesh.meshutils.formatpos2(n, T)[source]
class sfepy.mesh.meshutils.mesh[source]
average(list)[source]
average_vectors(list)[source]
clean()[source]

Deletes the whole mesh.

computegrad(scalars)[source]

Returns the gradient of scalars (both are given in nodes).

computenorm(vectors)[source]

Returns sqrt(x^2+y^2+z^2) for all vectors (x,y,z) in vectors.

convert_el_to_nodes(els)[source]
convert_stress_to_nodes()[source]
det(x, y)[source]
dist(a, b)[source]
dist2(p, q)[source]
getnumhexahedra()[source]
getnumprisms()[source]
getnumquadrangles()[source]
getnumtetrahedra()[source]
getnumtriangles()[source]
getscalar(n)[source]

Returns a scalar of a node whose number is n.

getscalar2(n, scalars)[source]

Returns a scalar of a node whose number is n.

getvector(n)[source]

Returns a vector associated to a node whose number is n.

getxyz(n)[source]

Returns a tuple (x,y,z) of a node whose number is n.

printinfo()[source]
readELE(filename, symmetric=False)[source]

Read elements from filename (*.ELE).

readELE2(filename)[source]

Read elements from filename (*.ELE).

readGMV(filename, what=2)[source]

Reads GMV file.

what ... 0 read only mesh
... 1 read only data ... 2 read both
readNOD(filename, scale=1.0)[source]

Read nodes from filename (*.NOD).

readmsh(filename, b=None, symmetric=False, associateelements=True)[source]

Reads mesh from filename (*.msh).

it will read the physical entity “mshmodelnum” (default 100), which must contain every node (which will be used) and every element.

Optional parameter b of type bound will be filled with all other physical (!=mshmodelnum) nodes.

example:

gmsh exports these physical entities: 100,1,2,101,200

then readmsh will read 100 into self.elements and self.nodes, and optionally fills “b” with entities 1,2,101 and 200. The assumption is, that entity 100 will contain every node and element used in entities 1,2,101 and 200. Also the nodes and elements in 100 must be consecutively sorted (use mshsort for this purpose)

it will convert msh types to PMD types, so that self.elements only contains PMD types

symmetric.... is the problem rot symmetric? if yes, readmsh() will automatically convert triangles to rottriangles and quadrangles to rotquadrangles.

readmsh2(filename, b=None, symmetric=False, associateelements=True)[source]

Reads mesh from filename (*.msh). Version 2.0

it will read the physical entity “mshmodelnum” (default 100), which must contain every node (which will be used) and every element.

Optional parameter b of type bound will be filled with all other physical (!=mshmodelnum) nodes.

example:

gmsh exports these physical entities: 100,1,2,101,200

then readmsh will read 100 into self.elements and self.nodes, and optionally fills “b” with entities 1,2,101 and 200. The assumption is, that entity 100 will contain every node and element used in entities 1,2,101 and 200. Also the nodes and elements in 100 must be consecutively sorted (use mshsort for this purpose)

it will convert msh types to PMD types, so that self.elements only contains PMD types

symmetric.... is the problem rot symmetric? if yes, readmsh() will automatically convert triangles to rottriangles and quadrangles to rotquadrangles.

readpmd(filename)[source]

Read the mesh from filename (*.I1).

Can read I1, which was produced by writepmd().

Should be able to read some hand written I1s from PMD Example Manual. Sometimes you will have to tweak the parser to read your syntax.

I suggest to only use the writepmd() I1 syntax. This is easily readable/writable.

readstr2STR(filename)[source]

Reads temperature data from filename (*.STR) to scalars.

readstr3STR(filename)[source]

Reads temperature data from filename (*.STR) to scalars.

readxt2sSTR(filename)[source]

Reads temperature data from filename (*.STR) to scalars.

removecentralnodes(nods)[source]
renumber_elements()[source]
scalars_elements2nodes(scalarsel)[source]
sortnodes()[source]
vectors_elements2nodes(scalarsel)[source]
writeBC(filename, verbose=True)[source]

self.faces contain triplets (p1,p2,p3) which are triangles of tetrahedrons on the boundary. We need to find the number of each corresponding tetrahedron and it’s side.

writeELE(filename)[source]

Write nodes to filename (*.ELE).

writeNOD(filename)[source]

Write nodes to filename (*.NOD).

writemsh(filename, verbose=True)[source]

Writes mesh to filename (*.msh).

writemsh2(filename)[source]

Writes mesh to filename (*.msh). Version 2.0

writepmd(filename)[source]

Writes the mesh to filename (*.I1).

writeregions(filename)[source]
writescalars(filename, scalars, C=0.0)[source]
writescalarspos(filename, infotext='PMD_scalars')[source]

Writes self.scalars to *.pos.

Optional parameter infotext specifies the name of the view in the pos file.

  1. Associates a scalar with every node, so gmsh shows points.
  2. Associates a scalar with every node of all elements, so gmsh fills the whole element (triangle, quadrangle, tetrahedra, ... etc.) with an extrapolated color.

You can set visibility in gmsh (only points, only triangles...).

writescalarspos2(filename, scaltime, infotext='PMD_scalars', dt=1.0)[source]

Writes self.scalars to *.pos.

Optional parameter infotext specifies the name of the view in the pos file.

  1. Associates a scalar with every node, so gmsh shows points.
  2. Associates a scalar with every node of all elements, so gmsh fills the whole element (triangle, quadrangle, tetrahedra, ... etc.) with an extrapolated color.

You can set visibility in gmsh (only points, only triangles...).

writescalarspos3(filename, scalars, infotext='PMD_scalars')[source]
writestresspos(filename, infotext='PMD_stress')[source]

Writes scalars together with nodes and elements to filename.

Optional parameter infotext specifies the name of the view in the pos file.

1) Associates a scalar with every node, so gmsh shows points. 2) Associates a scalar with every node of all elements, so gmsh fills the whole element (triangle, quadrangle etc.) with an extrapolated color.

You can set visibility in gmsh (only points, only triangles...).

writevectorspos(filename, infotext='PMD_vectors')[source]

Writes scalars together with nodes and elements to filename.

Optional parameter infotext specifies the name of the view in the pos file.

1) Associates a scalar with every node, so gmsh shows points. 2) Associates a scalar with every node of all elements, so gmsh fills the whole element (triangle, quadrangle etc.) with an extrapolated color.

You can set visibility in gmsh (only points, only triangles...).

writevectorspos3(filename, vectorfield, infotext='PMD_vectors')[source]
writexda(filename, verbose=True, b=None)[source]

Writes mesh to filename (*.xda).

We try to be byte to byte compatible with the xda output from libmesh (so I use the same tabs and spaces as libmesh does).

sfepy.mesh.meshutils.myfloat(s)[source]

Converts s to float, including PMD float format (without E).

sfepy.mesh.meshutils.numlist2str(x)[source]