19. elements
— Definition of elements for the Mesh
model¶
This modules provides local numbering schemes of element
connectivities for Mesh
models. It allows a consistent
numbering throughout pyFormex.
When interfacing with other programs, one should be aware
that conversions may be necessary. Conversions to/from external programs
are done by the interface modules.
The module defines the ElementType
class and a whole slew of its
instances, which are the element types used in pyFormex.
Here is also the definition of the Elems
class, which is a
specialisation of the Connectivity
using an
ElementType instance as the eltype. The Elems class is one of the basic
data holders in the Mesh
model.
19.1. Classes defined in module elements¶
- class elements.ElementType(*args, **kargs)[source]¶
Element types for
Mesh
models.An ElementType instance stores all the data that define a particular geometrical entity type. It defines the geometrical meaning of a set of points in the Mesh geometrical model.
Several subclasses are defined to easily created families of related element types.
All successfully created element types are stored in the class
register
, from where they can be looked up by their name.- Parameters:
name (str) – The name of the element type. Case is ignored. It is stored in the ElementType instance in capitalized form. The key in the register is the name in lower case. Often the name has a numeric last part equal to the plexitude of the element, but this is not a requirement.
doc (str) – A short description of the element.
ndim (int) –
The dimensionality (level) of the element (0..3):
0: point
1: line
2: surface
3: volume
degree (tuple of int) – For elements that have a parametric formulation, the degree of the interpolation functions in the
ndim
parametric directions.nplex (int) – The plexitude of the element: this is the number of nodes that define the geometry of an individual element.
rst (float array_like) – The position of the nodes in parametric space. This array should have a shape (ndim, nplex).
h (tuple of lambda) – A tuple of lambda functions computing the interpolation of the element. The tuple should contain exactly nplex functions. Each function should take
ndim
arguments and return an array of nplex values at the nodes. The functions should fulfil the finite element requirement:h[i](rst[:,j]) = 1 if i==j and 0 if i!=j
. This requirement is checked when creating the element type.order (int array_like, optional) – The order in which the nodes are stored, if different from the order in
rst
andh
.vertices (float array_like, optionally) – The natural coordinates of the nodes (nplex,3). This should be be provided if, and only if, the element does not have a parametric formulation (specified by degree, rst, h). The nodes of the elements are usually defined in a unit space [0,1] in each axis direction.
edges (
Elems
) – A connectivity table listing the edges of the element with local node numbers. The eltype of the Elems should be an ElementType instance of level 1. This parameter should be provided if and only if the element is of level 2 or 3. The edges should be the conceptually correct edges of the element. If the element contains edges of different plexitudes, they should be specified with the highest plexitude and degenerate elements should be used for the lower plexitude edges.faces (
Elems
) – A connectivity table listing the faces of the element with local node numbers. The eltype of the Elems should be an ElementType instance of level 2. This parameter should be provided if and only iff the element is of level 3. The faces should be the conceptually correct faces of the element. If the element contains faces of different plexitudes, they should be specified with the highest plexitude and degenerate elements should be used for the lower plexitude faces.**kargs (keyword arguments) – Other keyword arguments are stored in the ElementType as is. These can also be set after initialization by direct assignment to the instance’s attribute. Below are some predefined values used by pyFormex.
reverse (int array_like) – The order of the nodes for the reversed element. Reversing a line element reverses its parametric direction. Reversing a surface element reverses the direction of the positive normal. Reversing a volume element turns the element inside out (which could possibly be used to represent holes in space).
gl2faces (
Elems
) – A connectivity defining the entities to be used in rendering the element. This should only be provided if it the rendered geometry should be different from the element itself or from the elementfaces
. This is used to draw approximate renderings of elements for which there is no correct functionality available: linear approximations for higher order elements, triangular subdivisions for quadrilaterals. Note that although the name suggests faces, this connectivity can be of any level.gl2edges (
Elems
) – A connectivity defining the entities to be used in wire rendering of the element. This is likegl2faces
but defines the edges to be rendered in the wireframe and smoothwire and flatwire rendering modes.conversions (dict) – A dict holding the possible strategies for conversion of the element to other element types. The key is the target element name, possibly extended with an extra string to discriminate between multiple strategies leading to the same element. The value is a list of actions to undertake to get from the initial element type to the target element type. See more details in the section Element type conversion below.
extruded (dict) – A dict with data for how to extrude an element to a higher level element. Extrusion increases the level of the element with one, by creating 1 or 2 new planes of nodes in a new direction. The key in the dict is the degree of the extrusion: 1 or 2. The value is a tuple (eltype, nodes), where eltype is the target element type (an existing ElementType instance) and nodes is a list of nodes numbers as they will appear in the new node planes. If nodes is left out of the tuple, they will be ordered exactly like in the original element.
degenerate (dict) – A dict with data for how to replace a degenerate element with a reduced element. A degenerate element has one or more coinciding nodes. The reduced elements replaces coinciding nodes with a single node yielding an element with lower plexitude. The keys in the dict are reduced element types. The values are lists of coinciding node conditions and matching reduction schemes: see the section Degenerate element reduction below for more details.
subdivide_proxy (ElementType, optional) – An intermediate element type to help in subdividing an element. If this is defined, subdivision of the element will be done by first converting to the subdivide_proxy type, subdivide that element, and convert back to the original.
Notes
The ordering of the
rst
andh
defines a fixed local numbering scheme of the nodes in the element. It can however be changed by specifying the ‘order’ argument. The ordering of the items inedges
andfaces
specify the local numbering of the edges and faces. For solid elements, it is guaranteed that the vertices of all faces are numbered in a consecutive order spinning positively around the outward normal on the face.Some of the parameters of an ElementType are instances of
Elems
, but Elems instances contain themselves anElementType
instance. Therefore care should be taken not to define circular dependencies. If the ElementType instances are created in order of increasing level, there is no problem with theedges
andfaces
parameters, as these are of a lower level than the element itself, and will have been defined before. For other attributes however this might not always be the case. These attributes can then be defined by direct assignment, after the needed ElementTypes have been initialized.List of elements
The list of available element types can be found from:
>>> ElementType.list() ['point', 'line2', 'line3', 'line4', 'tri3', 'tri6', 'quad4', 'quad6', 'quad9', 'quad16', 'quad8', 'quad12', 'tet4', 'tet10', 'tet14', 'tet15', 'wedge6', 'hex8', 'hex27', 'hex20', 'hex16', 'octa', 'icosa'] >>> ElementType.printall() Available Element Types: 0-dimensional elements: ['point'] 1-dimensional elements: ['line2', 'line3', 'line4'] 2-dimensional elements: ['tri3', 'tri6', 'quad4', 'quad6', 'quad9', 'quad16', 'quad8', 'quad12'] 3-dimensional elements: ['tet4', 'tet10', 'tet14', 'tet15', 'wedge6', 'hex8', 'hex27', 'hex20', 'hex16', 'octa', 'icosa']
Element type conversion
Element type conversion in pyFormex is a powerful feature to transform Mesh type objects. While mostly used to change the element type, there are also conversion types that refine the Mesh.
Available conversion methods are defined in an attribute conversion of the input element type. This attribute should be a dictionary, where the keys are the name of the conversion method and the values describe what steps need be taken to achieve this conversion. The method name should be the name of the target element, optionally followed by a suffix to discriminate between different methods yielding the same target element type. The suffix should always start with a ‘-’. The part starting at the ‘-’ will be stripped of to set the final target element name.
E.g., a ‘line3’ element type is a quadratic line element through three points. There are two available methods to convert it to ‘line2’ (straight line segments betwee two points), named named ‘line2’, resp. ‘line2-2’. The first will transform a ‘line3’ element in a single ‘line2’ between the two endpoints (i.e. the chord of the quadratic element); the second will replace each ‘line3’ with two straight segments: from first to central node, and from central node to end node.
The values in the dictionary are a list of execution steps to be performed in the conversion. Each step is a tuple of a single character defining the type of the step, and the data needed by this type of step. The steps are executed one by one to go from the source element type to the target.
Currently, the following step types are defined:
Type
Data
‘s’ (select)
connectivity list of selected nodes
‘a’ (average)
list of tuples of nodes to be averaged
‘v’ (via)
string with name of intermediate element type
‘x’ (execute)
the name of a proper conversion function
‘r’ (random)
list of conversion method names
The operation of these methods is as follows:
‘s’ (select): This is the most common conversion type. It selects a set of nodes of the input element, and creates one or more new elements with these nodes. The data field is a list of tuples defining for each created element which node numbers from the source element should be included. This method is typically used to reduce the plexitude of the element.
‘a’ (average): Creates new nodes, the position of which is computed as an average of existing nodes. The data field is a list of tuples with the numbers of the nodes that should be averaged for each new node. The resulting new nodes are added in order at the end of the existing nodes. If this order is not the proper local node numbering, an ‘s’ step should follow to put the (old and new) nodes in the proper order. This method will usually increase the plexitude of the elements.
‘v’ (via): The conversion is made via an intermediate element type. The initial element type is first converted to this intermediate type and the result is then transformed to the target type.
‘x’ (execute): Calls a function to do the conversion. The function takes the input Mesh as argument and returns the converted Mesh. Currently this function should be a global function in the mesh module. Its name is specified as data in the conversion rule.
‘r’ (random): Chooses a random method between a list of alternatives. The data field is a list of conversion method names defined for the same element (and thus inside the same dictionary). While this could be considered an amusement (e.g. used in the Carpetry example), there are serious applications for this, e.g. when transforming a Mesh of squares or rectangles into a Mesh of triangles, by adding one diagonal in each element. Results with such a Mesh may however be different dependent on the choice of diagonal. The converted Mesh has directional preferences, not present in the original. The Quad4 to Tri3 conversion therefore has the choice to use either ‘up’ or ‘down’ diagonals. But a better choice is often the ‘random’ method, which will put the diagonals in a random direction, thus reducing the effect.
Degenerate element reduction
Each element can have an attribute
degenerate
, defining some rules of how the element can be reduced to a lower plexitude element in case it becomes degenerate. An element is said to be degenerate if the same node number is used more than once in the connectivity of a single element. Reduction of degenerate elements is usually only done if the element can be reduced to another element of the same level. For example, if two node of a quadrilateral element are coinciding, it could be replaced with a triangle. Both are level 2 elements. When the triangle has two coinciding nodes however, the element is normally not reduced to a line (level 1), but rather completely removed from the (level 2) model. However, nothing prohibits cross-level reductions.The
degenerate
attribute of an element is a dict where the key is a target element and the corresponding value is a list of reduction rules. Each rule is a tuple of two items: a set of conditions and a node selector to reduce the element. The conditions items is itself a tuple of any number of conditions, where each condition is a tuple of two node indices. If these nodes are equal, the condition is met. If all conditions in a rule are met, the reduction rule is applied. The second item in a rule, the node selector, is an index specifying the indices of the nodes that should be retained in the new (reduced) elements.As an example, take the Line3 element, which has 3 nodes defining a curved line element. Node 1 is the middle node, and nodes 0 and 2 are the end nodes. The element has four ways of being degenerate: nodes 0 and 1 are the same, nodes 1 and 2 are the same, nodes 0 and 2 are the same, and all three nodes are the same. For the first two of them, a reduction scheme is defined, reducing the element to a straight line segment (Line2) between the two end points:
Line3.degenerate = { Line2: [(((0, 1), ), (0, 2)), (((1, 2), ), (0, 2)), ], }
In this case each of the reduction rules contains only a single condition, but there exist cases where multiple conditions have to be net at the same time, which is why the condition (0, 1) is itself enclosed in a tuple. But what about the other degenerate cases. If both end points coincide, it is not clear what to do: reduce to a line segment between the coincident end points, or between an end point and the middle. Here pyFormex made the choice to not reduce such case and leave the degenerate Line3 element. But the user could add a rule to e.g. reduce the case to a line segment between end point and middle point:
Line3.degenerate[Line2].append((((0, 2), ), (0, 1)))
Also the case of three coinciding points is left unhandled. But the user could reduce such cases to a Point:
Line3.degenerate[Point] = [(((0, 1), (1, 2)), (0, ))]
Here we need two conditions to check that nodes 0, 1 and 2 are equal. However, in this case the user probably also wants the third degenerate case (nodes 0 and 2 are equal) to be reduced to a Point. So he could just use:
Line3.degenerate[Point] = [(((0, 2), ), (0, ))]
- register¶
A dict collecting all the created ElementType instances with their lower case name as key.
- Type:
Examples
>>> print(ElementType.default) {1: Point, 2: Line2, 3: Tri3, 4: Quad4, 6: Wedge6, 8: Hex8}
- getEntities(level)[source]¶
Return the type and connectivity table of some element entities.
- Parameters:
level (int) – The level of the entities to return. If negative, it is a value relative to the level of the caller. If non-negative, it specifies the absolute level. Thus, for an ElementType of level 3, getEntities(-1) returns the faces, while for a level 2 ElementType, it returns the edges. In both cases however, getEntities(1) returns the edges.
- Returns:
Elems
|Connectivity
– The connectivity table and element type of the entities of the specified level. The type is normally Elems. If the requested entity level is outside the range 0..ndim, an empty Connectivity is returned.
Examples
>>> Tri3.getEntities(0) Elems([[0], [1], [2]], eltype=Point) >>> Tri3.getEntities(1) Elems([[0, 1], [1, 2], [2, 0]], eltype=Line2) >>> Tri3.getEntities(2) Elems([[0, 1, 2]], eltype=Tri3) >>> Tri3.getEntities(3) Connectivity([], shape=(0, 1))
- getDrawFaces(quadratic=False)[source]¶
Return the local connectivity for drawing the element’s faces
- getDrawEdges(quadratic=False)[source]¶
Return the local connectivity for drawing the element’s edges
- toMesh(level=None)[source]¶
Convert the element type to a Mesh.
Returns a Mesh with a single element of natural size.
- toFormex()[source]¶
Convert the element type to a Formex.
Returns a Formex with a single element of natural size.
- family()[source]¶
Return the element family name.
The element family name is the first part of the lname that consists only of lower case letters.
- classmethod list(ndim=None, types=False)[source]¶
Return a list of available ElementTypes.
- Parameters:
- Returns:
list – A list of ElementType names (default) or instances.
Examples
>>> ElementType.list() ['point', 'line2', 'line3', 'line4', 'tri3', 'tri6', 'quad4', 'quad6', 'quad9', 'quad16', 'quad8', 'quad12', 'tet4', 'tet10', 'tet14', 'tet15', 'wedge6', 'hex8', 'hex27', 'hex20', 'hex16', 'octa', 'icosa'] >>> ElementType.list(ndim=1) ['line2', 'line3', 'line4'] >>> ElementType.list(ndim=1, types=True) [Line2, Line3, Line4]
- classmethod printall(lower=False)[source]¶
Print all available element types.
Prints a list of the names of all available element types, grouped by their dimensionality.
- classmethod has(elname)[source]¶
Check that an ElementType with the given name exists.
- Parameters:
elname (str) – The element name (case insensitive).
- Returns:
bool – True if the specified ElementType has been registered.
- classmethod drop(elname)[source]¶
Remove an ElementType from the registry.
- Parameters:
elname (str) – The element name (case insensitive).
- classmethod get(eltype=None, nplex=None, register=True)[source]¶
Find the ElementType matching an element name and/or plexitude.
- Parameters:
eltype (
ElementType
| str | None) – The element type or name. If not provided andnplex
is provided, the default element type for that plexitude will be used, if it exists. If a name, it should be the name of one of the existing ElementType instances (case insensitive).nplex (int) – The plexitude of the element. If provided and an eltype was provided, it should match the eltype plexitude. If no eltype was provided, the default element type for this plexitude is returned.
- Returns:
ElementType
– The ElementType matching the provided eltype and/or nplex- Raises:
ValueError – If neither
name
nornplex
can resolve into an element type.
Examples
>>> ElementType.get('tri3') Tri3 >>> ElementType.get(nplex=2).lname 'line2' >>> ElementType.get('QUAD4') Quad4 >>> ElementType.get('poly5', register=False) Poly5 >>> ElementType.get('plex17') Plex17
- classmethod polygon(nplex, register=True)[source]¶
Return the Polygon element of the specified plexitude.
- Parameters:
nplex (int) – The plexitude of the element, i.e. the number of vertices of the polygons. Clearly, nplex should be >= 3.
- Returns:
ElementType – An ElementType representing a polygon of the specified plexitude. If nplex < 3, an exception is raised. For nplex=3 and nplex=4, the returned element type is
Tri3
andQuad4
, respectively. For higher plexitude, an element of thePolygon
family is returned, with name Poly## where ## is the plexitude.
Notes
Elements of the
Polygon
family are created on the fly when needed, and stored in the element database for later reuse if a polygon element of the same plexitude would be required.Examples
>>> [ElementType.polygon(i, register=False) ... for i in (3, 4, 5, 6, 8, 137)] [Tri3, Quad4, Poly5, Poly6, Poly8, Poly137] >>> ElementType.polygon(2) Traceback (most recent call last): ... ValueError: nplex=2 is invalid for Polygon elements
- class elements.Elems(data, eltype=None)[source]¶
A Connectivity where the eltype is an ElementType subclass.
This is a
Connectivity
with knowledge about the geometrical meaning of the element type. It is used to store the connectivity table of aMesh
instance. It is also used to store some subitems in theElementType
.- Parameters:
data (int array_like) – The connectivity data to initialize the Elems. The data should be 2-dim with shape
(nelems,nplex)
, wherenelems
is the number of elements andnplex
is the plexitude of the elements. It can be a list, an ndarray or a Connectivity. In the latter case it usually shares the storage with that object.eltype (class | str) – The element type of the Elems. It is either a subclass of
elements.ElementType
or thename()
of such a subclass. That subclass should have the same plexitude as the connectivity data. If not provided and the default element type for that plexitude will be used if such exists inElementtype.default
.
Examples
>>> L = [[0,1,2],[0,1,3]] >>> Elems(L) Elems([[0, 1, 2], [0, 1, 3]], eltype=Tri3) >>> Elems(L, 'tri3') Elems([[0, 1, 2], [0, 1, 3]], eltype=Tri3) >>> Elems(L, Tri3) Elems([[0, 1, 2], [0, 1, 3]], eltype=Tri3) >>> C = Connectivity(L, eltype='tri3') >>> Elems(C) Elems([[0, 1, 2], [0, 1, 3]], eltype=Tri3) >>> Elems(C, 'tri3') Elems([[0, 1, 2], [0, 1, 3]], eltype=Tri3) >>> Elems(C, Tri3) Elems([[0, 1, 2], [0, 1, 3]], eltype=Tri3)
- levelSelector(level)[source]¶
Return a selector for lower level entities.
- Parameters:
level (int) – An specifying one of the hierarchical levels of element entities. See
Element.getEntities()
.- Returns:
Elems
– A new Elems object with shape(self.nelems*selector.nelems,selector.nplex)
.
Examples
>>> E = Elems([[0,1,2],[0,1,3],[0,5,3]],'tri3') >>> E.levelSelector(1) Elems([[0, 1], [1, 2], [2, 0]], eltype=Line2)
- selectNodes(selector)[source]¶
Return a Connectivity with subsets of the nodes.
- Parameters:
selector (int | int array_like) –
A single int specifies a relative or absolute hierarchical level of element entities (See the Element class). A 2-dim int array selector is then constructed automatically from
self.eltype.getEntities(selector)
.Else, it is a 2-dim int array like (often a
Connectivity
or anotherElems
. Each row of selector holds a list of the local node numbers that should be retained in the new Connectivity table.As an example, if the Elems is plex-3 representing triangles, a selector [[0,1],[1,2],[2,0]] would extract the edges of the triangle. The same would be obtained with
selector=-1
orselector=1
.- Returns:
Elems
|Connectivity
– An Elems or Connectivity object with eltype equal to that of the selector. This means that if the selector has an eltype that is one of the elements defined inelements
, the return type will be Elems, else Connectivity. The shape is(self.nelems*selector.nelems,selector.nplex)
. Duplicate elements created by the selector are retained.
Examples
>>> E = Elems([[0,1,2],[0,1,3],[0,5,3]]) >>> sel = E.levelSelector(1) >>> E.selectNodes(sel) Elems([[0, 1], [1, 2], [2, 0], [0, 1], [1, 3], [3, 0], [0, 5], [5, 3], [3, 0]], eltype=Line2) >>> E.selectNodes(Elems([[0,1],[0,2]],eltype=Line2)) Elems([[0, 1], [0, 2], [0, 1], [0, 3], [0, 5], [0, 3]], eltype=Line2) >>> E.selectNodes([[0,1],[0,2]]) Connectivity([[0, 1], [0, 2], [0, 1], [0, 3], [0, 5], [0, 3]])
- insertLevel(selector, permutations='all')[source]¶
Insert an extra hierarchical level in a Connectivity table.
A Connectivity table identifies higher hierarchical entities in function of lower ones. This method inserts an extra level in the hierarchy. For example, if you have volumes defined in function of points, you can insert an intermediate level of edges, or faces. Each element may generate multiple instances of the intermediate level.
- Parameters:
selector (int | int array_like) –
A single int specifies a relative or absolute hierarchical level of element entities (See the Element class). A 2-dim int array selector is then constructed automatically from
self.eltype.getEntities(selector)
.Else, it is a 2-dim int array like (often a
Connectivity
or anotherElems
. Each row of selector holds a list of the local node numbers that should be retained in the new Connectivity table.permutations (str) –
Defines which permutations of the row data are allowed while still considering the rows equal. Equal rows in the intermediate level are collapsed into single items. Possible values are:
’none’: no permutations are allowed: rows must match the same date at the same positions.
’roll’: rolling is allowed. Rows that can be transformed into each other by rolling are considered equal;
’all’: any permutation of the same data will be considered an equal row. This is the default.
- Returns:
hi (
Connectivity
) – A Connecivity defining the original elements in function of the intermediate level ones.lo (
Elems
|Connectivity
) – An Elems or Connectivity object with eltype equal to that of the selector. This means that if the selector has an eltype that is one of the elements defined inelements
, the return type will be Elems, else Connectivity.The resulting node numbering of the created intermediate entities
(the lo return value) respects the numbering order of the original
elements and the applied the selector, but in case of collapsing
duplicate rows, it is undefined which of the collapsed sequences is
returned.
Because the precise order of the data in the collapsed rows is lost,
it is in general not possible to restore the exact original table
from the two result tables.
See however
mesh.Mesh.getBorder()
for an application where aninverse operation is possible, because the border only contains
unique rows.
See also
mesh.Mesh.combine()
, which is an almost inverse operationfor the general case, if the selector is complete.
The resulting rows may however be permutations of the original.
Examples
>>> E = Elems([[0,1,2],[0,1,3],[0,5,3]], 'tri3') >>> hi, lo = E.insertLevel(1) >>> hi Connectivity([[0, 4, 1], [0, 5, 2], [3, 6, 2]]) >>> lo Elems([[0, 1], [2, 0], [3, 0], [0, 5], [1, 2], [1, 3], [5, 3]], eltype=Line2) >>> hi, lo = E.insertLevel([[0,1],[1,2],[2,0]]) >>> hi Connectivity([[0, 4, 1], [0, 5, 2], [3, 6, 2]]) >>> lo Connectivity([[0, 1], [2, 0], [3, 0], [0, 5], [1, 2], [1, 3], [5, 3]]) >>> E = Elems([[0,1,2,3]],'quad4') >>> hi, lo = E.insertLevel([[0,1,2],[1,2,3],[0,1,1],[0,0,1],[1,0,0]]) >>> hi Connectivity([[1, 2, 0, 0, 0]]) >>> lo Connectivity([[0, 1, 1], [0, 1, 2], [1, 2, 3]])
- reduceDegenerate(target=None, return_indices=False)[source]¶
Reduce degenerate elements to lower plexitude elements.
This will try to reduce the degenerate elements of the Elems to lower plexitude elements. This is only possible if the ElementType has an attribute
degenerate
containing the proper reduction rules.- Parameters:
target (str, optional) – Target element name. If provided, only reductions to that element type are performed. Else, all the target element types for which a reduction scheme is available, will be tried.
return_indices (bool, optional) – If True, also returns the indices of the elements in the input Elems that are contained in each of the parts returned.
- Returns:
conn (list of Elems instances) – A list of Elems of which the first one contains the originally non-degenerate elements, the next one(s) contain the reduced elements (per reduced element type) and the last one contains elements that could not be reduced (this may be absent). In the following cases a list with only the original is returned:
there are no degenerate elements in the Elems;
the ElementType does not have any reduction scheme defined;
the ElementType does not have a reduction scheme fot the target.
ind (list of indices, optional) – Only returned if
return_indices
is True: the indices of the elements ofself
contained in each item inconn
.
Note
If the Elems is part of a
Mesh
, you should use themesh.Mesh.splitDegenerate()
method instead, as that will preserve the property numbers in the resulting Meshes.The returned reduced Elems may still be degenerate for their own element type.
See also
mesh.Mesh.splitDegenerate
split mesh in non-degenerate and reduced
Examples
>>> Elems([[0,1,2],[0,1,3]],eltype=Line3).reduceDegenerate() [Elems([[0, 1, 2], [0, 1, 3]], eltype=Line3)] >>> C = Elems([[0,1,2],[0,1,1],[0,3,2]],eltype='line3') >>> C.reduceDegenerate() [Elems([[0, 1, 2], [0, 3, 2]], eltype=Line3), Elems([[0, 1]], eltype=Line2)] >>> C = Elems([[0,1,2],[0,1,1],[0,3,2],[1,1,1],[0,0,2]],eltype=Line3) >>> C.reduceDegenerate() [Elems([[0, 1, 2], [0, 3, 2]], eltype=Line3), Elems([[1, 1], [0, 2], [0, 1]], eltype=Line2)] >>> conn, ind = C.reduceDegenerate(return_indices=True) >>> conn [Elems([[0, 1, 2], [0, 3, 2]], eltype=Line3), Elems([[1, 1], [0, 2], [0, 1]], eltype=Line2)] >>> ind [array([0, 2]), array([3, 4, 1])]
- extrude(nnod, degree)[source]¶
Extrude an Elems to a higher level Elems.
- Parameters:
nnod (increment) – Node increment for each new node plane. It should be higher than the highest node number in self.
degree (int) – Number of node planes to add. This is also the degree of the extrusion. Currently it is limited to 1 or 2.
nodes (The extrusion adds degree planes of) –
node (each with a) –
nnod –
selects (to the original Elems and then) –
the (the target nodes from it as defined by) –
value. (self.eltype.extruded[degree]) –
- Returns:
Elems – An Elems for the extruded element.
Examples
>>> a = Elems([[0,1],[1,2]],eltype=Line2).extrude(3,1) >>> print(a) [[0 1 4 3] [1 2 5 4]] >>> print(a.eltype.lname) quad4 >>> a = Elems([[0,1,2],[0,2,3]],eltype=Line3).extrude(4,2) >>> print(a) [[ 0 2 10 8 1 6 9 4 5] [ 0 3 11 8 2 7 10 4 6]] >>> print(a.eltype.lname) quad9
- getFreeEntities(level=-1, return_indices=False)[source]¶
Return the free entities of the specified level.
- Parameters:
level (int) – The level of the entities to return. If negative, it is a value relative to the level of the caller. If non-negative, it specifies the absolute level.
return_indices (bool) – If True, also returns an index array (nentities,2) for inverse lookup of the higher entity (column 0) and its local lower entity number (column 1).
- Returns:
Elems
– A connectivity table with the free entities of the specified level. Free entities are entities that are only connected to a single element.
See also
Mesh.getFreeEntities()
return the free entities of a Mesh
Mesh.getBorder()
return the border entities of a Mesh
Examples
>>> elems = Elems([[0, 1, 3], [3, 2, 0]], eltype='tri3') >>> elems.getFreeEntities(1) Elems([[0, 1], [2, 0], [1, 3], [3, 2]], eltype=Line2) >>> elems.getFreeEntities(1,True)[1] array([[0, 0], [1, 1], [0, 1], [1, 0]])
- class elements.Polygon(*args, **kargs)[source]¶
A Polygon element type.
This element type is useful to define a Mesh of polygons that all have the same plexitude. The polygon elements are created on demand.
Examples
>>> P = Polygon(5, register=False) >>> print(P) Poly5 >>> print(P.getFaces()) [[0 1 2 3 4]] >>> print(P.getDrawFaces()) [[0 1 2 3 4]] >>> print(P.getEdges()) [[0 1] [1 2] [2 3] [3 4] [4 0]] >>> print(P.getDrawEdges()) [[0 1] [1 2] [2 3] [3 4] [4 0]]