pygeon.discretizations.fem.l2 module

Module for the discretizations of the L2 space.

class pygeon.discretizations.fem.l2.PwPolynomials(keyword='unitary_data')[source]

Bases: Discretization

PwPolynomials is a subclass of pg.Discretization that represents an abstract element wise polynomial discretization.

poly_order

Polynomial degree of the basis functions

tensor_order = 0

Scalar-valued discretization

ndof(sd)[source]

Returns the number of degrees of freedom associated to the method. In this case, it returns the number of cells in the grid.

Parameters:

sd (pg.Grid) – The grid object.

Returns:

The number of degrees of freedom.

Return type:

int

local_dofs_of_cell(sd, c)[source]

Compute the local degrees of freedom (DOFs) indices for a cell.

Parameters:
  • sd (pp.Grid) – Grid object or a subclass.

  • c (int) – Index of the cell.

Returns:

Array of local DOF indices associated with the cell.

Return type:

np.ndarray

abstractmethod ndof_per_cell(sd)[source]

Returns the number of degrees of freedom per cell.

Parameters:

sd (pg.Grid) – The grid object.

Returns:

The number of degrees of freedom per cell.

Return type:

int

assemble_mass_matrix(sd, data=None)[source]

Computes the mass matrix for piecewise polynomials.

Parameters:
  • sd (pg.Grid) – The grid on which to assemble the matrix.

  • data (dict | None) – Dictionary with possible scaling.

Returns:

Sparse csc matrix of shape (sd.num_cells, sd.num_cells).

Return type:

sps.csc_array

assemble_lumped_matrix(sd, data=None)[source]

Assembles the lumped matrix for the given grid.

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

  • data (dict | None) – Optional data dictionary.

Returns:

The assembled lumped matrix.

Return type:

sps.csc_array

assemble_diff_matrix(sd)[source]

Assembles the matrix corresponding to the differential operator.

This method takes a grid object and returns the differential matrix corresponding to the given grid.

Parameters:

sd (pg.Grid) – The grid object or its subclass.

Returns:

The differential matrix.

Return type:

sps.csc_array

assemble_broken_grad_matrix(sd)[source]

Assembles the broken (element-wise) gradient matrix for the given grid. This method should be implemented in the child class.

Parameters:

sd (pg.Grid) – The grid or a subclass.

Returns:

The assembled broken gradient matrix.

Return type:

sps.csc_array

assemble_stiff_matrix(sd, _data=None)[source]

Assembles the stiffness matrix for the given grid.

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

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

Returns:

The assembled stiffness matrix.

Return type:

sps.csc_array

assemble_nat_bc(sd, _func, _b_faces)[source]

Assembles the natural boundary condition vector, equal to zero.

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

  • func (Callable[[np.ndarray], np.ndarray]) – The function defining the natural boundary condition.

  • b_faces (np.ndarray) – The array of boundary faces.

Returns:

The assembled natural boundary condition vector.

Return type:

np.ndarray

get_range_discr_class(dim)[source]

Returns the discretization class for the range of the differential.

Parameters:

dim (int) – The dimension of the range space.

Raises:

NotImplementedError – There is no zero discretization available in PyGeoN.

abstractmethod assemble_local_mass(dim)[source]

Computes the local mass matrix for piecewise polynomials.

Parameters:

dim (int) – The dimension of the grid.

Returns:

Local mass matrix for piecewise polynomials.

Return type:

np.ndarray

abstractmethod assemble_local_lumped_mass(dim)[source]

Computes the local lumped mass matrix for piecewise polynomials

Parameters:

dim (int) – The dimension of the grid.

Returns:

Local lumped mass matrix for piecewise polynomials.

Return type:

np.ndarray

proj_to_PwPolynomials(sd)[source]

Construct the matrix for projecting a piecewise function to a piecewise polynomial function.

Parameters:

sd (pg.Grid) – The grid on which to construct the matrix.

Returns:

The matrix representing the projection.

Return type:

sps.csc_array

proj_to_lower_PwPolynomials(sd)[source]

Projects the discretization to -1 order discretization.

Parameters:

sd (pg.Grid) – The grid object.

Returns:

The projection matrix.

Return type:

sps.csc_array

Raises:

NotImplementedError – If the method is not implemented in a subclass.

abstractmethod proj_to_higher_PwPolynomials(sd)[source]

Projects the discretization to +1 order discretization.

Parameters:

sd (pg.Grid) – The grid object.

Returns:

The projection matrix.

Return type:

sps.csc_array

class pygeon.discretizations.fem.l2.PwConstants(keyword='unitary_data')[source]

Bases: PwPolynomials

Discretization class for the piecewise constants. NOTE: Each degree of freedom is the integral over the cell.

poly_order = 0

Polynomial degree of the basis functions

ndof_per_cell(_sd)[source]

Returns the number of degrees of freedom per cell.

Parameters:

sd (pg.Grid) – The grid object.

Returns:

The number of degrees of freedom per cell.

Return type:

int

assemble_local_mass(_dim)[source]

Computes the local mass matrix for piecewise constants

Parameters:

dim (int) – The dimension of the grid.

Returns:

Local mass matrix for piecewise constants.

Return type:

np.ndarray

assemble_local_lumped_mass(dim)[source]

Computes the local lumped mass matrix for piecewise constants

Parameters:

dim (int) – The dimension of the grid.

Returns:

Local lumped mass matrix for piecewise constants.

Return type:

np.ndarray

assemble_mass_matrix(sd, data=None)[source]

Computes the mass matrix for piecewise constants

Parameters:
  • sd (pg.Grid) – The grid on which to assemble the matrix.

  • data (dict | None) – Dictionary with possible scaling.

Returns:

Sparse csc matrix of shape (sd.num_cells, sd.num_cells).

Return type:

sps.csc_array

assemble_lumped_matrix(sd, data=None)[source]

Computes the lumped mass matrix, which coincides with the mass matrix for P0.

Parameters:
  • sd (pg.Grid) – The grid on which to assemble the matrix.

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

Returns:

The assembled lumped mass matrix.

Return type:

sps.csc_array

assemble_broken_grad_matrix(sd)[source]

Assembles the broken (element-wise) gradient matrix for the given grid, which is zero for the piecewise constants

Parameters:

sd (pg.Grid) – The grid or a subclass.

Returns:

The assembled broken gradient matrix.

Return type:

sps.csc_array

interpolate(sd, func)[source]

Interpolates a function onto the finite element space

Parameters:
  • sd (pg.Grid) – Grid or a subclass.

  • func (Callable[[np.ndarray], np.ndarray]) – A function that returns the function values at coordinates.

Returns:

The values of the degrees of freedom.

Return type:

np.ndarray

proj_to_higher_PwPolynomials(sd)[source]

Projects the P0 discretization to the P1 discretization.

Parameters:

sd (pg.Grid) – The grid object.

Returns:

The projection matrix.

Return type:

sps.csc_array

eval_at_cell_centers(sd)[source]

Assembles the matrix that evaluates a function at the cell centers of a grid.

Parameters:

sd (pg.Grid) – The grid or a subclass.

Returns:

The evaluation matrix.

Return type:

sps.csc_array

class pygeon.discretizations.fem.l2.PwLinears(keyword='unitary_data')[source]

Bases: PwPolynomials

Discretization class for piecewise linear finite element method.

poly_order = 1

Polynomial degree of the basis functions

ndof_per_cell(sd)[source]

Returns the number of degrees of freedom per cell.

Parameters:

sd (pg.Grid) – The grid object.

Returns:

The number of degrees of freedom per cell.

Return type:

int

assemble_local_mass(dim)[source]

Computes the local mass matrix for piecewise linears

Parameters:

dim (int) – The dimension of the grid.

Returns:

Local mass matrix for piecewise linears.

Return type:

np.ndarray

assemble_local_lumped_mass(dim)[source]

Computes the local lumped mass matrix for piecewise linears

Parameters:

dim (int) – The dimension of the grid.

Returns:

Local lumped mass matrix for piecewise linears.

Return type:

np.ndarray

eval_at_cell_centers(sd)[source]

Assembles the matrix for evaluating the discretization at the cell centers.

Parameters:

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

Returns:

The evaluation matrix.

Return type:

sps.csc_array

interpolate(sd, func)[source]

Interpolates a function onto the finite element space by evaluating the function at the (sd.dim + 1) Gauss points.

Parameters:
  • sd (pg.Grid) – Grid, or a subclass.

  • func (Callable) – A function that returns the function values at coordinates.

Returns:

The values of the degrees of freedom.

Return type:

np.ndarray

proj_to_lower_PwPolynomials(sd)[source]

Construct the matrix for projecting a piece-wise function to a piecewise constant function.

Parameters:

sd (pg.Grid) – The grid on which to construct the matrix.

Returns:

The matrix representing the projection.

Return type:

sps.csc_array

proj_to_higher_PwPolynomials(sd)[source]

Projects the P1 discretization to the P2 discretization.

Parameters:

sd (pg.Grid) – The grid object.

Returns:

The projection matrix.

Return type:

sps.csc_array

get_dof_lookup_array(sd)[source]

Assembles a lookup matrix L with the property L[cell, node] = dof_index.

Parameters:

sd (pg.Grid) – The grid or a subclass.

Returns:

The lookup matrix.

Return type:

sps.csc_array

assemble_broken_grad_matrix(sd)[source]

Assembles the broken (element-wise) gradient matrix for the given grid. This operator maps to the vector-valued piecewise constants.

Parameters:

sd (pg.Grid) – The grid or a subclass.

Returns:

The assembled broken gradient matrix.

Return type:

sps.csc_array

class pygeon.discretizations.fem.l2.PwQuadratics(keyword='unitary_data')[source]

Bases: PwPolynomials

PwQuadratics is a class that represents piecewise quadratic finite element discretizations.

poly_order = 2

Polynomial degree of the basis functions

ndof_per_cell(sd)[source]

Returns the number of degrees of freedom per cell.

Parameters:

sd (pg.Grid) – The grid object.

Returns:

The number of degrees of freedom per cell.

Return type:

int

assemble_local_mass(dim)[source]

Computes the local mass matrix for piecewise quadratics.

Parameters:

dim (int) – The dimension of the grid.

Returns:

Local mass matrix for piecewise quadratics.

Return type:

np.ndarray

assemble_local_lumped_mass(dim)[source]

Computes the local lumped mass matrix for piecewise quadratics

Parameters:

dim (int) – The dimension of the grid.

Returns:

Local lumped mass matrix for piecewise quadratics.

Return type:

np.ndarray

eval_at_cell_centers(sd)[source]

Assembles the matrix for evaluating the discretization at the cell centers.

Parameters:

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

Returns:

The evaluation matrix.

Return type:

sps.csc_array

interpolate(sd, func)[source]

Interpolates a function onto the finite element space

Parameters:
  • sd (pg.Grid) – Grid, or a subclass.

  • func (Callable) – A function that returns the function values at degrees of freedom.

Returns:

The values of the degrees of freedom.

Return type:

np.ndarray

proj_to_higher_PwPolynomials(sd)[source]

Projects the discretization to +1 order discretization.

Parameters:

sd (pg.Grid) – The grid object.

Returns:

The projection matrix.

Return type:

sps.csc_array