Cell Classes#

This document summarizes the classes denoted to store and handle data about polygonal cells in 1, 2 or 3 dimensions.

Base Classes#

class polymesh.cell.PolyCell(*args, i: ndarray | None = None, **kwargs)[source]#

A subclass of polymesh.celldata.CellData as a base class for all kinds of geometrical entities.

area(*args, **kwargs) float[source]#

Returns the total area of the cells in the database. Only for 2d entities.

areas(*args, **kwargs) ndarray[source]#

Ought to return the areas of the individuall cells in the database.

centers(target: ReferenceFrame | None = None) ndarray[source]#

Returns the centers of the cells.

coords(*args, **kwargs) ndarray[source]#

Returns the coordinates of the cells in the database as a 3d numpy array.

extract_surface(detach: bool = False)[source]#

Extracts the surface of the mesh. Only for 3d meshes.

flip() PolyCell[source]#

Reverse the order of nodes of the topology.

classmethod generate_class_functions(return_symbolic: bool = True, update: bool = True) Tuple[source]#

Generates functions to evaulate shape functions, their derivatives and the shape function matrices using SymPy. For this to work, the ‘polybase’ and ‘lcoords’ class methods must be implemented.

Parameters:
  • return_symbolic (bool, Optional) – If True, the function returns symbolic expressions of shape functions and their derivatives. Default is True.

  • update (bool, Optional) – If True, class methods are updated with the generated versions. Default is True.

glob_to_loc(x: Iterable | ndarray) ndarray[source]#

Returns the local coordinates of the input points for each cell in the block. The input ‘x’ can describe a single (1d array), or several positions at once (2d array).

Notes

This function is useful when detecting if two bodies touch each other or not, and if they do, where.

Parameters:

x (Iterable or numpy.ndarray) – A single point in 3d space as an 1d array, or a collection of points as a 2d array.

Returns:

A NumPy array of shape (nE, nP, nD), where nP is the number of points in ‘x’, nE is the number of cells in the block and nD is the number of spatial dimensions.

Return type:

numpy.ndarray

jacobian(*, jac: ndarray | None = None, **kwargs) float | ndarray[source]#

Returns the jacobian determinant for one or more cells.

Parameters:
  • jac (numpy.ndarray, Optional) – One or more Jacobian matrices. Default is None.

  • **kwargs (dict) – Forwarded to jacobian_matrix() if the jacobian is not provided by the parameter ‘jac’.

Returns:

Value of the Jacobian for one or more cells.

Return type:

float or numpy.ndarray

jacobian_matrix(*, dshp: ndarray | None = None, **__) ndarray[source]#

Returns the jacobian matrices.

Parameters:

dshp (numpy.ndarray) – 3d array of shape function derivatives for the master cell, evaluated at some points. The array must have a shape of (nG, nNE, nD), where nG, nNE and nD are he number of evaluation points, nodes per cell and spatial dimensions.

Returns:

A 4d array of shape (nE, nG, nD, nD), where nE, nG and nD are the number of elements, evaluation points and spatial dimensions. The number of evaluation points in the output is governed by the parameter ‘dshp’.

Return type:

numpy.ndarray

classmethod lcenter() ndarray[source]#

Ought to return the local coordinates of the center of the master element.

Return type:

numpy.ndarray

classmethod lcoords() ndarray[source]#

Ought to return local coordinates of the master element.

Return type:

numpy.ndarray

loc_to_glob(x: Iterable | ndarray) ndarray[source]#

Returns the global coordinates of the input points for each cell in the block. The input ‘x’ can describe a single (1d array), or several local positions at once (2d array).

Notes

This function is useful when detecting if two bodies touch each other or not, and if they do, where.

Parameters:

x (Iterable or numpy.ndarray) – A single point as an 1d array, or a collection of points as a 2d array.

Returns:

A NumPy array of shape (nE, nP, nD), where nP is the number of points in ‘x’, nE is the number of cells in the block and nD is the number of spatial dimensions.

Return type:

numpy.ndarray

local_coordinates(*, target: CartesianFrame | None = None) ndarray[source]#

Returns local coordinates of the cells as a 3d float numpy array.

Parameters:

target (CartesianFrame, Optional) – A target frame. If provided, coordinates are returned in this frame, otherwise they are returned in the local frames of the cells. Default is None.

locate(x: Iterable | ndarray, lazy: bool = True, tol: float = 1e-12, k: int = 4) Tuple[ndarray][source]#

Locates a set of points inside the cells of the block.

Parameters:
  • x (Iterable or numpy.ndarray) – The coordinates of the points that we want to investigate.

  • tol (float, Optional) – Floating point tolerance for detecting boundaries. Default is 1e-12.

  • lazy (bool, Optional) – If False, the ckeck is performed for all cells in the block. If True, it is used in combination with parameter ‘k’ and the check is only performed for the k nearest neighbours of the input points. Default is True.

  • k (int, Optional) – The number of neighbours for the case when ‘lazy’ is true. Default is 4.

Returns:

  • numpy.ndarray – The indices of ‘x’ that are inside a cell of the block.

  • numpy.ndarray – The block-local indices of the cells that include the points with the returned indices.

  • numpy.ndarray – The parametric coordinates of the located points inside the including cells.

measure(*args, **kwargs) float[source]#

Ought to return the net measure for the cells in the database as a group.

measures(*args, **kwargs) ndarray[source]#

Ought to return measures for each cell in the database.

pip(x: Iterable | ndarray, tol: float = 1e-12, lazy: bool = True, k: int = 4) bool | ndarray[source]#

Returns an 1d boolean integer array that tells if the points specified by ‘x’ are included in any of the cells in the block.

Parameters:
  • x (Iterable or numpy.ndarray) – The coordinates of the points that we want to investigate.

  • tol (float, Optional) – Floating point tolerance for detecting boundaries. Default is 1e-12.

  • lazy (bool, Optional) – If False, the ckeck is performed for all cells in the block. If True, it is used in combination with parameter ‘k’ and the check is only performed for the k nearest neighbours of the input points. Default is True.

  • k (int, Optional) – The number of neighbours for the case when ‘lazy’ is true. Default is 4.

Returns:

A single or NumPy array of booleans for every input point.

Return type:

bool or numpy.ndarray

points_involved() PointCloud[source]#

Returns the points involved in the cells of the block.

points_of_cells(*, points: float | Iterable | None = None, cells: int | Iterable | None = None, target: str | CartesianFrame = 'global') ndarray[source]#

Returns the points of the cells as a NumPy array.

classmethod polybase() Tuple[List][source]#

Ought to retrun the polynomial base of the master element.

Returns:

  • list – A list of SymPy symbols.

  • list – A list of monomials.

rewire(imap: ndarray | MutableMapping | None = None, invert: bool = False) PolyCell[source]#

Rewires the topology of the block according to the mapping described by the argument imap. The mapping of the j-th node of the i-th cell happens the following way:

topology_new[i, j] = imap[topology_old[i, j]]

The object is returned for continuation.

Parameters:
  • imap (MapLike) – Mapping from old to new node indices (global to local).

  • invert (bool, Optional) – If True the argument imap describes a local to global mapping and an inversion takes place. In this case, imap must be a numpy array. Default is False.

classmethod shape_function_derivatives(pcoords: ndarray) ndarray[source]#

Evaluates shape function derivatives wrt. the master element.

Parameters:

pcoords (numpy.ndarray) – Locations of the evaluation points.

Returns:

An array of shape (nP, nNE, nD), where nP, nNE and nD are the number of evaluation points, nodes and spatial dimensions.

Return type:

numpy.ndarray

classmethod shape_function_matrix(pcoords: ndarray, N: int | None = None) ndarray[source]#

Evaluates the shape function matrix at the specified locations.

Parameters:
  • pcoords (numpy.ndarray) – Locations of the evaluation points.

  • N (int, Optional) – Number of unknowns per node.

Returns:

An array of shape (nP, nDOF, nDOF * nNE) where nP, nDOF and nNE are the number of evaluation points, degrees of freedom per node and nodes per cell.

Return type:

numpy.ndarray

classmethod shape_function_values(pcoords: ndarray) ndarray[source]#

Evaluates the shape functions at the specified locations.

Parameters:

pcoords (numpy.ndarray) – Locations of the evaluation points.

Returns:

An array of shape (nP, nNE) where nP and nNE are the number of evaluation points and shape functions. If there is only one evaluation point, the returned array is one dimensional.

Return type:

numpy.ndarray

source_coords() ndarray[source]#

Returns the coordinates of the hosting pointcloud.

source_frame() ReferenceFrame[source]#

Returns the frame of the hosting pointcloud.

source_points() PointCloud[source]#

Returns the hosting pointcloud.

to_simplices() Tuple[ndarray][source]#

Returns the cells of the block, refactorized into simplices.

topology() TopologyArray[source]#

Returns the numerical representation of the topology of the cells.

unique_indices() ndarray[source]#

Returns the indices of the points involved in the cells of the block.

volume(*args, **kwargs) float[source]#

Returns the volume of the cells in the database.

volumes(*args, **kwargs) ndarray[source]#

Ought to return the volumes of the individual cells in the database.

class polymesh.cell.PolyCell1d(*args, i: ndarray | None = None, **kwargs)[source]#

Base class for 1d cells

area() float[source]#

Returns the total area of the cells in the database. Only for 2d entities.

areas() ndarray[source]#

Returns the areas as a NumPy array.

lengths() ndarray[source]#

Returns the lengths as a NumPy array.

lenth() float[source]#

Returns the total length of the cells in the database.

measures() ndarray[source]#

Ought to return measures for each cell in the database.

points_of_cells(*, points: float | Iterable | None = None, cells: int | Iterable | None = None, flatten: bool = False, target: str | CartesianFrame = 'global', rng: Iterable | None = None, **kwargs) ndarray[source]#

Returns the points of the cells as a NumPy array.

volumes() ndarray[source]#

Returns the volumes as a NumPy array.

class polymesh.cell.PolyCell2d(*args, i: ndarray | None = None, **kwargs)[source]#

Base class for 2d cells

area() float[source]#

Returns the total area of the cells in the block.

areas() ndarray[source]#

Returns the areas of the cells.

classmethod lcenter() ndarray[source]#

Ought to return the local coordinates of the center of the master element.

Return type:

numpy.ndarray

local_coordinates(*_, target: CartesianFrame | None = None) ndarray[source]#

Returns the local coordinates of the cells of the block.

measures() ndarray[source]#

Returns the areas of the cells.

pip(x: Iterable | ndarray, tol: float = 1e-12) bool | ndarray[source]#

Returns an 1d boolean integer array that tells if the points specified by ‘x’ are included in any of the cells in the block.

Parameters:

x (Iterable or numpy.ndarray) – The coordinates of the points that we want to investigate.

Returns:

A single or NumPy array of booleans for every input point.

Return type:

bool or numpy.ndarray

thickness() ndarray[source]#

Returns the thicknesses of the cells. If not set, a thickness of 1.0 is returned for each cell.

to_triangles() ndarray[source]#

Returns the topology as a collection of T3 triangles.

classmethod trimap() Iterable[source]#

Returns a mapper to transform topology and other data to a collection of T3 triangles.

volumes() ndarray[source]#

Returns the volumes of the cells.

class polymesh.cell.PolyCell3d(*args, **kwargs)[source]#

Base class for 3d cells

boundary(detach: bool = False) Tuple[ndarray][source]#

Returns the boundary of the block as 2 NumPy arrays.

extract_surface(detach: bool = False) Tuple[ndarray][source]#

Extracts the surface of the object.

locate(x: Iterable | ndarray, lazy: bool = True, tol: float = 1e-12, k: int = 4) Tuple[ndarray][source]#

Locates a set of points inside the cells of the block.

Parameters:
  • x (Iterable or numpy.ndarray) – The coordinates of the points that we want to investigate.

  • tol (float, Optional) – Floating point tolerance for detecting boundaries. Default is 1e-12.

  • lazy (bool, Optional) – If False, the ckeck is performed for all cells in the block. If True, it is used in combination with parameter ‘k’ and the check is only performed for the k nearest neighbours of the input points. Default is True.

  • k (int, Optional) – The number of neighbours for the case when ‘lazy’ is true. Default is 4.

Returns:

  • numpy.ndarray – The indices of ‘x’ that are inside one of the cells of the block.

  • numpy.ndarray – The block-local indices of the cells that include the points with the returned indices.

  • numpy.ndarray – The master coordinates of the located points inside the including cells.

measures(*args, **kwargs) ndarray[source]#

Returns the measures of the block.

pip(x: Iterable | ndarray, tol: float = 1e-12, lazy: bool = True, k: int = 4) bool | ndarray[source]#

Returns an 1d boolean integer array that tells if the points specified by ‘x’ are included in any of the cells in the block.

Parameters:
  • x (Iterable or numpy.ndarray) – The coordinates of the points that we want to investigate.

  • tol (float, Optional) – Floating point tolerance for detecting boundaries. Default is 1e-12.

  • lazy (bool, Optional) – If False, the ckeck is performed for all cells in the block. If True, it is used in combination with parameter ‘k’ and the check is only performed for the k nearest neighbours of the input points. Default is True.

  • k (int, Optional) – The number of neighbours for the case when ‘lazy’ is true. Default is 4.

Returns:

A single or NumPy array of booleans for every input point.

Return type:

bool or numpy.ndarray

classmethod tetmap() Iterable[source]#

Returns a mapper to transform topology and other data to a collection of T3 triangles.

to_pv(detach: bool = False) UnstructuredGrid | PolyData[source]#

Returns the block as a pyVista object.

to_tetrahedra(flatten: bool = True) ndarray[source]#

Returns the topology as a collection of TET4 tetrahedra.

Parameters:

flatten (bool, Optional) – If True, the topology is returned as a 2d array. If False, the length of the first axis equals the number of cells in the block, the length of the second axis equals the number of tetrahedra per cell.

to_vtk(detach: bool = False)[source]#

Returns the block as a VTK object.

volumes() ndarray[source]#

Returns the volumes of the block as an 1d float array.

class polymesh.line.Line(*args, **kwargs)[source]#

Base class for all lines.

jacobian(*args, jac: ndarray | None = None, **kwargs)[source]#

Calculates jacobian determinants.

Parameters:

jac (numpy.ndarray) – Array of jacobian matrices derivatives.

jacobian_matrix(*args, dshp: ndarray | None = None, **kwargs)[source]#

Calculates jacobian matrices.

Parameters:

dshp (numpy.ndarray) – Array of shape function derivatives.

class polymesh.line.NonlinearLine(*args, **kwargs)[source]#

Base class for general nonlinear lines.

See also

Line

NNODE: int = None#
vtkCellType: int = None#
class polymesh.line.QuadraticLine(*args, **kwargs)[source]#

Base class for quadratic 3-noded lines.

See also

Line

vtkCellType: int = None#
class polymesh.polygon.BiQuadraticQuadrilateral(*args, i: ndarray | None = None, **kwargs)[source]#

9-noded biquadratic quadrilateral.

to_triangles()[source]#

Returns the topology as a collection of T3 triangles.

classmethod trimap()[source]#

Returns a mapper to transform topology and other data to a collection of T3 triangles.

class polymesh.polygon.PolyGon(*args, i: ndarray | None = None, **kwargs)[source]#

Base class for polygons.

class polymesh.polygon.QuadraticTriangle(*args, **kwargs)[source]#

Quadratic 6-noded triangle.

to_triangles()[source]#

Returns the topology as a collection of T3 triangles.

classmethod trimap(subdivide: bool = True)[source]#

Returns a mapper to transform topology and other data to a collection of T3 triangles.

class polymesh.polygon.Quadrilateral(*args, i: ndarray | None = None, **kwargs)[source]#

Basic 4-noded bilinear quadrilateral.

to_triangles()[source]#

Returns the topology as a collection of T3 triangles.

classmethod trimap()[source]#

Returns a mapper to transform topology and other data to a collection of T3 triangles.

class polymesh.polygon.Triangle(*args, **kwargs)[source]#

Base class for triangles.

areas(*args, **kwargs)[source]#

Returns the areas of the cells.

to_triangles()[source]#

Returns the topology as a collection of T3 triangles.

classmethod trimap() ndarray[source]#

Returns a mapper to transform topology and other data to a collection of T3 triangles.

class polymesh.polyhedron.BiquadraticWedge(*args, **kwargs)[source]#

Class for 6-noded biquadratic wedges.

classmethod tetmap() ndarray[source]#

Returns a mapper to transform topology and other data to a collection of T3 triangles.

class polymesh.polyhedron.HexaHedron(*args, **kwargs)[source]#

Class for 8-noded hexahedra.

classmethod tetmap() ndarray[source]#

Returns a mapper to transform topology and other data to a collection of T3 triangles.

class polymesh.polyhedron.PolyHedron(*args, **kwargs)[source]#

Base class to handle polyhedra.

class polymesh.polyhedron.QuadraticTetraHedron(*args, **kwargs)[source]#

Class for 10-noded quadratic tetrahedra.

classmethod tetmap(subdivide: bool = True) ndarray[source]#

Returns a mapper to transform topology and other data to a collection of T3 triangles.

class polymesh.polyhedron.TetraHedron(*args, **kwargs)[source]#

Class for 4-noded tetrahedra.

classmethod tetmap() ndarray[source]#

Returns a mapper to transform topology and other data to a collection of T3 triangles.

to_tetrahedra(flatten: bool = True) ndarray[source]#

Returns the topology as a collection of TET4 tetrahedra.

Parameters:

flatten (bool, Optional) – If True, the topology is returned as a 2d array. If False, the length of the first axis equals the number of cells in the block, the length of the second axis equals the number of tetrahedra per cell.

class polymesh.polyhedron.TriquadraticHexaHedron(*args, **kwargs)[source]#

Class for 27-noded triquadratic hexahedra.

class polymesh.polyhedron.Wedge(*args, **kwargs)[source]#

Class for 6-noded trilinear wedges.

classmethod tetmap() ndarray[source]#

Returns a mapper to transform topology and other data to a collection of T3 triangles.

Lagrange Cells#

class polymesh.cells.l2.L2(*args, **kwargs)[source]#

2-Node line element.

See also

Line

classmethod lcenter() ndarray[source]#

Returns the local coordinates of the center of the cell.

Return type:

numpy.ndarray

classmethod lcoords() ndarray[source]#

Returns local coordinates of the cell.

Return type:

numpy.ndarray

classmethod polybase() Tuple[List][source]#

Retruns the polynomial base of the master element.

Returns:

  • list – A list of SymPy symbols.

  • list – A list of monomials.

class polymesh.cells.l3.L3(*args, **kwargs)[source]#

3-Node line element.

See also

QuadraticLine

classmethod lcenter() ndarray[source]#

Returns the local coordinates of the center of the cell.

Return type:

numpy.ndarray

classmethod lcoords() ndarray[source]#

Returns local coordinates of the cell.

Return type:

numpy.ndarray

classmethod polybase() Tuple[List][source]#

Retruns the polynomial base of the master element.

Returns:

  • list – A list of SymPy symbols.

  • list – A list of monomials.

class polymesh.cells.t3.T3(*args, **kwargs)[source]#

A class to handle 3-noded triangles.

See also

Triangle

classmethod lcenter() ndarray[source]#

Returns the local coordinates of the center of the cell.

Return type:

numpy.ndarray

classmethod lcoords() ndarray[source]#

Returns local coordinates of the cell.

Return type:

numpy.ndarray

classmethod polybase() Tuple[List][source]#

Retruns the polynomial base of the master element.

Returns:

  • list – A list of SymPy symbols.

  • list – A list of monomials.

class polymesh.cells.t6.T6(*args, **kwargs)[source]#

A class to handle 6-noded triangles.

See also

Triangle

areas() ndarray[source]#

Returns the areas of the triangles of the block.

Return type:

numpy.ndarray

classmethod lcenter() ndarray[source]#

Returns the local coordinates of the center of the cell.

Return type:

numpy.ndarray

classmethod lcoords() ndarray[source]#

Returns local coordinates of the cell.

Return type:

numpy.ndarray

classmethod polybase() Tuple[List][source]#

Retruns the polynomial base of the master element.

Returns:

  • list – A list of SymPy symbols.

  • list – A list of monomials.

class polymesh.cells.q4.Q4(*args, i: ndarray | None = None, **kwargs)[source]#

Polygon class for 4-noded bilinear quadrilaterals.

See also

Quadrilateral

classmethod lcenter() ndarray[source]#

Returns the local coordinates of the center of the cell.

Return type:

numpy.ndarray

classmethod lcoords() ndarray[source]#

Returns local coordinates of the cell.

Return type:

numpy.ndarray

classmethod polybase() Tuple[List][source]#

Retruns the polynomial base of the master element.

Returns:

  • list – A list of SymPy symbols.

  • list – A list of monomials.

class polymesh.cells.q9.Q9(*args, i: ndarray | None = None, **kwargs)[source]#

Polygon class for 9-noded biquadratic quadrilaterals.

dshpfnc()#

Returns the first orderderivatives of the shape functions, evaluated at multiple points, according to ‘pcoords’.

— (nP, nNE, 2)

classmethod lcenter() ndarray[source]#

Returns the local coordinates of the center of the cell.

Return type:

numpy.ndarray

classmethod lcoords()[source]#

Returns local coordinates of the cell.

Return type:

numpy.ndarray

classmethod polybase() Tuple[List][source]#

Retruns the polynomial base of the master element.

Returns:

  • list – A list of SymPy symbols.

  • list – A list of monomials.

class polymesh.cells.tet4.TET4(*args, **kwargs)[source]#

4-node isoparametric hexahedron.

See also

TetraHedron

classmethod lcenter() ndarray[source]#

Ought to return the local coordinates of the center of the master element.

Return type:

numpy.ndarray

classmethod lcoords() ndarray[source]#

Ought to return local coordinates of the master element.

Return type:

numpy.ndarray

classmethod polybase() Tuple[List][source]#

Retruns the polynomial base of the master element.

Returns:

  • list – A list of SymPy symbols.

  • list – A list of monomials.

class polymesh.cells.tet10.TET10(*args, **kwargs)[source]#

10-node isoparametric hexahedron.

classmethod lcenter()[source]#

Ought to return the local coordinates of the center of the master element.

Return type:

numpy.ndarray

classmethod lcoords()[source]#

Ought to return local coordinates of the master element.

Return type:

numpy.ndarray

classmethod polybase() Tuple[List][source]#

Retruns the polynomial base of the master element.

Returns:

  • list – A list of SymPy symbols.

  • list – A list of monomials.

volumes(coords: ndarray | None = None, topo: ndarray | None = None) ndarray[source]#

Returns the volumes of the block as an 1d float array.

class polymesh.cells.h8.H8(*args, **kwargs)[source]#

8-node isoparametric hexahedron.

top
7--6
|  |
4--5

bottom
3--2
|  |
0--1

See also

HexaHedron

classmethod lcenter() ndarray[source]#

Returns the local coordinates of the center of the cell.

Return type:

numpy.ndarray

classmethod lcoords() ndarray[source]#

Returns local coordinates of the cell.

Return type:

numpy.ndarray

classmethod polybase() Tuple[List][source]#

Retruns the polynomial base of the master element.

Returns:

  • list – A list of SymPy symbols.

  • list – A list of monomials.

volumes() ndarray[source]#

Returns the volumes of the cells.

Return type:

numpy.ndarray

class polymesh.cells.h27.H27(*args, **kwargs)[source]#

27-node isoparametric triquadratic hexahedron.

top
7---14---6
|    |   |
15--25--13
|    |   |
4---12---5

middle
19--23--18
|    |   |
20--26--21
|    |   |
16--22--17

bottom
3---10---2
|    |   |
11--24---9
|    |   |
0----8---1
classmethod lcenter() ndarray[source]#

Returns the local coordinates of the center of the cell.

Return type:

numpy.ndarray

classmethod lcoords() ndarray[source]#

Returns local coordinates of the cell.

Return type:

numpy.ndarray

classmethod polybase() Tuple[List][source]#

Retruns the polynomial base of the master element.

Returns:

  • list – A list of SymPy symbols.

  • list – A list of monomials.

volumes() ndarray[source]#

Returns the volumes of the cells.

Return type:

numpy.ndarray