pygeon.discretizations.fem.vec_h1 module

Module for the discretizations of the vector H1 space.

class pygeon.discretizations.fem.vec_h1.VecLagrange1(keyword='unitary_data')[source]

Bases: VecDiscretization

Vector Lagrange finite element discretization for H1 space.

This class represents a finite element discretization for the H1 space using vector Lagrange elements. It provides methods for assembling various matrices and operators, such as the mass matrix, divergence matrix, symmetric gradient matrix, and more.

Convention for the ordering is first all the x, then all the y, and (if dim = 3) all the z.

The stress tensor and strain tensor are represented as vectors unrolled row-wise. In 2D, the stress tensor has a length of 4, and in 3D, it has a length of 9.

We are considering the following structure of the stress tensor in 2D:

\[\begin{split}\sigma = \begin{bmatrix} \sigma_{xx} & \sigma_{xy} \\ \sigma_{yx} & \sigma_{yy} \end{bmatrix}\end{split}\]

which is represented in the code unrolled row-wise as a vector of length 4:

\[\sigma = [\sigma_{xx}, \sigma_{xy}, \sigma_{yx}, \sigma_{yy}]\]

While in 3D the stress tensor can be written as:

\[\begin{split}\sigma = \begin{bmatrix} \sigma_{xx} & \sigma_{xy} & \sigma_{xz} \\ \sigma_{yx} & \sigma_{yy} & \sigma_{yz} \\ \sigma_{zx} & \sigma_{zy} & \sigma_{zz} \end{bmatrix}\end{split}\]

where its vectorized structure of length 9 is given by:

\[\sigma = [\sigma_{xx}, \sigma_{xy}, \sigma_{xz}, \sigma_{yx}, \sigma_{yy}, \sigma_{yz}, \sigma_{zx}, \sigma_{zy}, \sigma_{zz}]\]

The strain tensor follows the same approach.

poly_order = 1

Polynomial degree of the basis functions

tensor_order = 1

Vector-valued discretization

__init__(keyword='unitary_data')[source]

Initialize the vector discretization class. The base discretization class is pg.Lagrange1.

Parameters:

keyword (str) – The keyword for the vector discretization class. Default is pg.UNITARY_DATA.

Returns:

None

base_discr

The scalar discretization method.

assemble_div_matrix(sd)[source]

Returns the div matrix operator for the lowest order vector Lagrange element

Parameters:

sd (pg.Grid) – The grid object.

Returns:

The div matrix obtained from the discretization.

Return type:

sps.csc_array

local_div(c_volume, coord, dim)[source]

Compute the local div matrix for vector P1.

Parameters:
  • c_volume (float) – Cell volume.

  • coord (ndarray) – Coordinates of the cell.

  • dim (int) – Dimension of the cell.

Returns:

Local mass Hdiv matrix. Shape: (num_faces_of_cell, num_faces_of_cell)

Return type:

ndarray

assemble_div_div_matrix(sd, data=None)[source]

Returns the div-div matrix operator for the lowest order vector Lagrange element. The matrix is multiplied by the Lame’ parameter lambda.

Parameters:
  • sd (pg.Grid) – The grid object.

  • data (dict | None) – Additional data, the Lame’ parameter lambda. Defaults to None.

Returns:

Sparse (sd.num_nodes, sd.num_nodes) Div-div matrix obtained from the discretization.

Return type:

csc_array

assemble_symgrad_matrix(sd)[source]

Returns the symmetric gradient matrix operator for the lowest order vector Lagrange element

Parameters:

sd (pg.Grid) – The grid object representing the domain.

Returns:

The sparse symmetric gradient matrix operator.

Return type:

sps.csc_array

Notes

  • If a 0-dimensional grid is given, a zero matrix is returned.

  • The method maps the domain to a reference geometry.

  • The method allocates data to store matrix entries efficiently.

  • The symmetrization matrix is constructed differently for 2D and 3D cases.

  • The method computes the symgrad local matrix for each cell and saves the values in the global structure.

  • Finally, the method constructs the global matrices using the saved values.

local_symgrad(c_volume, coord, dim, sym)[source]

Compute the local symmetric gradient matrix for P1.

Parameters:
  • c_volume (float) – Cell volume.

  • coord (np.ndarray) – Coordinates of the cell.

  • dim (int) – Dimension of the cell.

  • sym (np.ndarray) – Symmetric matrix.

Returns:

Local symmetric gradient matrix of shape (num_faces_of_cell, num_faces_of_cell).

Return type:

np.ndarray

assemble_symgrad_symgrad_matrix(sd, data=None)[source]

Returns the symgrad-symgrad matrix operator for the lowest order vector Lagrange element. The matrix is multiplied by twice the Lame’ parameter mu.

Parameters:
  • sd (pg.Grid) – The grid.

  • data (dict | None) – Additional data, the Lame’ parameter mu. Defaults to None.

Returns:

Sparse symgrad-symgrad matrix of shape (sd.num_nodes, sd.num_nodes). The matrix obtained from the discretization.

Return type:

sps.csc_array

assemble_diff_matrix(sd)[source]

Assembles the matrix corresponding to the differential operator.

Parameters:

sd (pg.Grid) – Grid object or a subclass.

Returns:

The differential matrix.

Return type:

sps.csc_array

assemble_stiff_matrix(sd, data=None)[source]

Assembles the global stiffness matrix for the finite element method.

Parameters:
  • sd (pg.Grid) – The grid on which the finite element method is defined.

  • data (dict | None) – Additional data required for the assembly process.

Returns:

The assembled global stiffness matrix.

Return type:

sps.csc_array

get_range_discr_class(dim)[source]

Returns the discretization class that contains the range of the differential.

Parameters:

dim (int) – The dimension of the range.

Returns:

The discretization class that contains the range of the differential.

Return type:

Discretization

Raises:
  • NotImplementedError – If there is no range discretization for the vector

  • Lagrangian 1 in PyGeoN.

compute_stress(sd, u, data)[source]

Compute the stress tensor for a given displacement field.

Parameters:
  • sd (pg.Grid) – The spatial discretization object.

  • u (ndarray) – The displacement field.

  • data (dict) – Data for the computation including the Lame parameters accessed with the keys pg.LAME_LAMBDA and pg.LAME_MU. Both float and np.ndarray are accepted.

Returns:

The stress tensor.

Return type:

ndarray

class pygeon.discretizations.fem.vec_h1.VecLagrange2(keyword='unitary_data')[source]

Bases: VecDiscretization

VecLagrange2 is a vector discretization class that extends the functionality of the pg.VecDiscretization base class. It utilizes the pg.Lagrange2 scalar discretization class for its operations.

poly_order = 2

Polynomial degree of the basis functions

tensor_order = 1

Vector-valued discretization

__init__(keyword='unitary_data')[source]

Initialize the vector discretization class. The base discretization class is pg.Lagrange2.

Parameters:

keyword (str) – The keyword for the vector discretization class. Default is pg.UNITARY_DATA.

Returns:

None

get_range_discr_class(dim)[source]

Returns the discretization class that contains the range of the differential.

Parameters:

dim (int) – The dimension of the range.

Returns:

The discretization class that contains the range of the differential.

Return type:

Discretization

Raises:
  • NotImplementedError – If there is no range discretization for the vector

  • Lagrangian 2 in PyGeoN.