pygeon.discretizations.discretization module
Module for the discretization class.
- class pygeon.discretizations.discretization.Discretization(keyword='unitary_data')[source]
Bases:
ABCAbstract class for PyGeoN discretization methods.
- poly_order
Polynomial degree of the basis functions
- tensor_order
Tensor order of the basis functions
- __init__(keyword='unitary_data')[source]
Initialize the Discretization object.
- Parameters:
keyword (str) – The keyword used to identify the discretization method. Default is pg.UNITARY_DATA.
- Returns:
None
- __repr__()[source]
Return a string representation of the Discretization object.
The string includes the type of the discretization and, if available, the keyword associated with it.
- Returns:
A string representation of the Discretization object.
- Return type:
- abstractmethod ndof(sd)[source]
Returns the number of degrees of freedom associated to the method.
- Parameters:
sd – Grid, or a subclass.
- Returns:
the number of degrees of freedom.
- Return type:
ndof
- assemble_mass_matrix(sd, data=None)[source]
Assembles the mass matrix by projecting to the corresponding piecewise polynomial space.
- Parameters:
sd (pg.Grid) – Grid object or a subclass.
data (dict | None) – Dictionary with physical parameters for scaling.
- Returns:
The mass matrix.
- Return type:
sps.csc_array
- assemble_lumped_matrix(sd, data=None)[source]
Assembles the lumped mass matrix using the corresponding piecewise polynomial space.
- Parameters:
sd (pg.Grid) – Grid object or a subclass.
data (dict | None) – Dictionary with physical parameters for scaling.
- Returns:
The lumped mass matrix.
- Return type:
sps.csc_array
- abstractmethod 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 stiffness matrix.
This method takes a grid object sd and an optional data dictionary data as input. It first calls the assemble_diff_matrix method to obtain the differential matrix B. Then, it creates an instance of the range discretization class using the dim attribute of sd. Next, it calls the assemble_mass_matrix method of the range discretization class to obtain the mass matrix A. Finally, it returns the product of the transpose of B, A, and B.
- Parameters:
sd (pg.Grid) – Grid object or a subclass.
data (dict | None) – Optional data dictionary. Defaults to None.
- Returns:
The stiffness matrix.
- Return type:
sps.csc_array
- abstractmethod 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 coordinates.
- Returns:
The values of the degrees of freedom
- 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
- source_term(sd, func)[source]
Assembles the source term by interpolating the given function and multiplying by the mass matrix
- Parameters:
sd (pg.Grid) – Grid object or a subclass.
func (Callable) – A function that returns the function values at coordinates.
- Returns:
The evaluation matrix.
- Return type:
np.ndarray
- abstractmethod assemble_nat_bc(sd, func, b_faces)[source]
Assembles the natural boundary condition term (Tr q, p)_Gamma
- Parameters:
sd (pg.Grid) – The grid object.
func (Callable) – The function representing the natural boundary condition.
b_faces (np.ndarray) – The array of boundary faces.
- Returns:
The assembled natural boundary condition term.
- Return type:
np.ndarray
- abstractmethod 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 containing the range of the differential
- Return type:
pg.Discretization
- abstractmethod proj_to_PwPolynomials(sd)[source]
Returns the inclusion matrix that projects the finite element space onto the lowest order piecewise polynomial space without loss of information.
- Parameters:
sd (pg.Grid) – The grid.
- Returns:
The inclusion matrix.
- Return type:
sps.csc_array
- assemble_broken_grad_matrix(sd)[source]
Assembles the broken (element-wise) gradient matrix for the given grid.
- Parameters:
sd (pg.Grid) – The grid or a subclass.
- Returns:
The assembled broken gradient matrix.
- Return type:
sps.csc_array
- error_l2(sd, num_sol, ana_sol, relative=True, poly_order=-1, data=None)[source]
Returns the l2 error computed against an analytical solution given as a function. The default behavior interpolates the function as a piecewise polynomial of order at least 1.
This behavior can be overruled by setting poly_order = None. Then the error is computed using interpolation, which may result in unexpected superconvergence.
- Parameters:
sd (pg.Grid) – Grid, or a subclass.
num_sol (np.ndarray) – Vector of the numerical solution.
ana_sol (Callable) – Function that represents the analytical solution.
relative (bool, optional) – Compute the relative error or not. Defaults to True.
poly_order (int, optional) – If poly_order is specified as an integer, the error is evaluated in a piecewise polynomial space of that order. If it is None, we use interpolation.
- Returns:
The computed error.
- Return type: