porepy.numerics.discretization module
Module contains two classes: 1) The abstract superclass for all discretizations 2) A do-nothing discretization
- class Discretization(keyword)[source]
Bases:
ABC
Interface for all discretizations. Specifies methods that must be implemented for a discretization class to be compatible with the assembler.
- Parameters
keyword (str) –
- assemble_matrix(g, data)[source]
Assemble discretization matrix.
The default implementation will assemble both the discretization matrix and the right hand side vector, and return only the former. This behavior is overridden by some discretization methods.
- Parameters
g (
pp.Grid
) – Grid to be discretized.data (
dictionary
) – With discretization parameters.
- Returns
Discretization matrix.
- Return type
sps.csc_matrix
- abstract assemble_matrix_rhs(g, data)[source]
Assemble discretization matrix and rhs vector.
- Parameters
g (
pp.Grid
) – Grid to be discretized.data (
dictionary
) – With discretization parameters.
- Returns
Discretization matrix. np.ndarray: Right hand side term.
- Return type
sps.csc_matrix
- assemble_rhs(g, data)[source]
Assemble right hand side term.
The default implementation will assemble both the discretization matrix and the right hand side vector, and return only the latter. This behavior is overridden by some discretization methods.
- Parameters
g (
pp.Grid
) – Grid to be discretized.data (
dictionary
) – With discretization parameters.
- Returns
Right hand side term.
- Return type
np.ndarray
- abstract discretize(g, data)[source]
Construct discretization matrices.
- The discretization matrices should be added to
data[pp.DISCRETIZATION_MATRICES][self.keyword]
- Parameters
g (
pp.Grid
) – Grid to be discretized.data (
dictionary
) – With discretization parameters.
- Return type
None
- abstract ndof(g)[source]
Return the number of degrees of freedom associated to the method.
- Parameters
g (Grid) – grid, or a subclass.
- Returns
the number of degrees of freedom.
- Return type
dof
- update_discretization(g, data)[source]
Partial update of discretization.
Intended use is when the discretization should be updated, e.g. because of changes in parameters, grid geometry or grid topology, and it is not desirable to recompute the discretization on the entire grid. A typical case will be when the discretization operation is costly, and only a minor update is necessary.
- The updates can generally come as a combination of two forms:
The discretization on part of the grid should be recomputed.
The old discretization can be used (in parts of the grid), but the numbering of unknowns has changed, and the discretization should be reorder accordingly.
By default, this method will simply forward the call to the standard discretize method. Discretization methods that wants a tailored approach should override the standard implementation.
Information on the basis for the update should be stored in a field
data[‘update_discretization’]
this should be a dictionary with up to six keys. The following optional keys:
modified_cells, modified_faces, modified_nodes
define cells, faces and nodes that have been modified (either parameters, geometry or topology), and should be rediscretized. It is up to the discretization method to implement the change necessary by this modification. Note that depending on the computational stencil of the discretization method, a grid quantity may be rediscretized even if it is not marked as modified. The dictionary could further have keys:
cell_index_map, face_index_map, node_index_map
these should specify sparse matrices that maps old to new indices. If not provided, unit mappings should be assumed, that is, no changes to the grid topology are accounted for.
It is up to the caller to specify which parts of the grid to recompute, and how to update the numbering of degrees of freedom. If the discretization method does not provide a tailored implementation for update, it is not necessary to provide this information.
- Parameters
g (
pp.Grid
) – Grid to be rediscretized.data (
dictionary
) – With discretization parameters.
- Return type
None
- class VoidDiscretization(keyword, ndof_cell=0, ndof_face=0, ndof_node=0)[source]
Bases:
Discretization
Do-nothing discretization object. Used if a discretizaiton object is needed for technical reasons, but not really necessary.
- assemble_matrix_rhs(g, data)[source]
Assemble discretization matrix and rhs vector, both empty.
- Parameters
g (
pp.Grid
) – Grid to be discretized.data (
dictionary
) – With discretization parameters.
- Returns
Of specified dimensions relative to the grid. Empty. np.array: Of specified dimensions relative to the grid. All zeros.
- Return type
sps.csc_matrix