Mesh Generation

1D interval domain meshes

class FEMpy.Mesh.Interval1D(left, right, h, basis_type)[source]

Defines a one-dimensional mesh and associated information matrices.

Create a mesh object defined from left to right with step size h. This object provides the information matrices describing the mesh (P and T) as well as the information matrices describing the finite element of type basis_type (Pb and Tb).

Parameters:
  • left (float) – The left end point of the domain.
  • right (float) – The right end point of the domain.
  • h (float) – Mesh grid spacing.
  • basis_type ({101, ‘linear’, 102, ‘quadratic’}) – Finite element basis type. Can either be called as a integer code or a string identifier to indicate the type of basis function we are using.
    • 101, ‘linear’ : 1-dimensional, linear basis.
    • 102, ‘quadratic’ : 1-dimensional, quadratic basis.
P

Information matrix containing the coordinates of all mesh nodes.

Type:ndarray
T

Information matrix containing the global node indices of the mesh nodes of all the mesh elements.

Type:ndarray
Pb

Information matrix containing the coordinates of all finite element nodes.

Type:ndarray
Tb

Information matrix containing the global node indices of the finite element nodes.

Type:ndarray

Examples

Automatically generate the boundary nodes.

>>> from FEMpy import Interval1D
>>> mesh = Interval1D(0, 1, 1/2, 'linear')
>>> mesh.boundary_nodes
array([0., 1.])

Get the vertices of the nth element.

>>> from FEMpy import Interval1D
>>> mesh = Interval1D(0, 1, 1/4, 'quadratic')
>>> mesh.get_vertices(3)
array([0.75, 1.  ])

Show the number of elements in the interval.

>>> from FEMpy import Interval1D
>>> mesh = Interval1D(-1, 3, 1/8, 'quadratic')
>>> mesh.num_elements_x
32
boundary_nodes

Returns the boundary node coordinates generated from the mesh.

get_vertices(n)[source]

Extracts the vertices of the mesh element n.

Parameters:n (int) – Mesh element index.
Returns:The vertices of the mesh element En.
Return type:ndarray
num_elements_x

Returns the number of elements along the domain x-axis.

2D rectangular meshes with triangular elements

class FEMpy.Mesh.TriangularMesh2D(left, right, bottom, top, h1, h2, basis_type)[source]

Defines a two-dimensional mesh with triangular elements and associated information matrices.

Create a mesh object defined on the domain [left, right] x [`bottom, top] with step size h1 in the x-direction and h2 in the y-direction. This object provides the information matrices describing the mesh (P and T) as well as the information matrices describing the finite element of type basis_type (Pb and Tb).

Parameters:
  • left (float) – The left edge point of the domain.
  • right (float) – The right edge point of the domain.
  • bottom (float) – The bottom edge point of the domain.
  • top (float) – The top edge point of the domain.
  • h1 (float) – Mesh grid spacing along x-direction.
  • h2 (float) – Mesh grid spacing along y-direction.
  • basis_type ({201, ‘linear’, ‘linear2D_tri’, 202, ‘quadratic’, ‘quadratic2D_tri’}) – Finite element basis type. Can either be called as a integer code or a string identifier to indicate the type of basis function we are using.
    • 201, ‘linear’, ‘linear2D_tri : 1-dimensional, linear basis on triangular elements.
    • 202, ‘quadratic’, ‘quadratic2D_tri : 1-dimensional, quadratic basis on triangular elements.
P

Information matrix containing the coordinates of all mesh nodes.

Type:ndarray
T

Information matrix containing the global node indices of the mesh nodes of all the mesh elements.

Type:ndarray
Pb

Information matrix containing the coordinates of all finite element nodes.

Type:ndarray
Tb

Information matrix containing the global node indices of the finite element nodes.

Type:ndarray

Examples

Automatically generate the boundary nodes and edges.

>>> from FEMpy import TriangularMesh2D
>>> mesh = TriangularMesh2D(0, 1, 0, 1, 1/2, 1/2, 'quadratic')
>>> mesh.boundary_nodes
array([[0.  , 0.25, 0.5 , 0.75, 1., 1.  , 1. , 1.  , 1., 0.75, 0.5, 0.25, 0.  , 0.  , 0.  , 0.  ],
       [0.  , 0.  , 0.  , 0.  , 0., 0.25, 0.5, 0.75, 1., 1.  , 1. , 1.  , 1.  , 0.75, 0.5 , 0.25]])
>>> mesh.boundary_edges
array([[0. , 0.5, 1. , 1. , 1. , 0.5, 0. , 0. ],
       [0. , 0. , 0. , 0.5, 1. , 1. , 1. , 0.5]])

Get the number of elements in the x-axis and y-axis.

>>> from FEMpy import TriangularMesh2D
>>> mesh = TriangularMesh2D(0, 2, 0, 1, 1/2, 1/2, 'linear')
>>> mesh.num_elements_x
4
>>> mesh.num_elements_y
2
boundary_edges

Returns the boundary edge coordinates generated from the mesh.

num_elements_y

Returns the number of elements along the domain y-axis.