porepy.numerics.ad.grid_operators module

Ad representation of grid-related quantities needed to write equations. The classes defined here are mainly wrappers that constructs Ad matrices based on grid information.

class BoundaryCondition(keyword, subdomains, name=None)[source]

Bases: Operator

Wrapper class for Ad representations of boundary conditions for a given keyword.

Parameters
parse(mdg)[source]

Convert the Ad expression into numerical values for the boundary conditions, in the form of an np.ndarray concatenated for all subdomains.

Parameters

mdg (pp.MixedDimensionalGrid) – Mixed-dimensional grid. The boundary condition will be taken from the data dictionaries with the relevant keyword.

Returns

Value of boundary conditions.

Return type

np.ndarray

interfaces: list[pp.MortarGrid]

List of interfaces on which the operator is defined, passed at instantiation.

Will be empty for operators not associated with specific interfaces.

subdomains: list[pp.Grid]

List of subdomains on which the operator is defined, passed at instantiation.

Will be empty for operators not associated with specific subdomains.

class Divergence(subdomains, dim=1, name=None)[source]

Bases: Operator

Wrapper class for Ad representations of divergence operators.

Parameters
parse(mdg)[source]

Convert the Ad expression into a divergence operators on all relevant subdomains, represented as a sparse block matrix.

Parameters

mdg (pp.MixedDimensionalGrid) – Not used, but needed for compatibility with the general parsing method for Operators.

Returns

Block matrix representation of a divergence operator on

multiple subdomains.

Return type

sps.spmatrix

interfaces: list[pp.MortarGrid]

List of interfaces on which the operator is defined, passed at instantiation.

Will be empty for operators not associated with specific interfaces.

subdomains: list[pp.Grid]

List of subdomains on which the operator is defined, passed at instantiation.

Will be empty for operators not associated with specific subdomains.

class Geometry(subdomains, nd, name=None, matrix_names=None)[source]

Bases: Operator

Wrapper class for Ad representations of grids.

Parameters
cell_volumes

Diagonal ad matrix of cell volumes.

Type

pp.ad.Matrix

face_areas

Diagonal ad matrix of face areas.

Type

pp.ad.Matrix

nd

Ambient/highest dimension of the mixed-dimensional grid.

Type

int

FIXME: Implement parse??

basis(dim=None)[source]

Return a cell-wise basis for all subdomains.

Parameters

dim (int, optional) – Dimension of the base. Defaults to the dimension of the Geometry.

Returns

Array of dim pp.ad.Matrix, each of which is represents a basis function.

Return type

list[porepy.numerics.ad.operators.Matrix]

e_i(i, dim=None)[source]

Return a cell-wise basis function for all subdomains.

Parameters
  • dim (int) – Dimension of the functions.

  • i (int) – Index of the basis function. Note: Counts from 0.

Returns

Ad representation of a matrix with the basis functions as

columns.

Return type

pp.ad.Matrix

interfaces: list[pp.MortarGrid]

List of interfaces on which the operator is defined, passed at instantiation.

Will be empty for operators not associated with specific interfaces.

subdomains: list[pp.Grid]

List of subdomains on which the operator is defined, passed at instantiation.

Will be empty for operators not associated with specific subdomains.

class MortarProjections(mdg, subdomains, interfaces, dim=1)[source]

Bases: Operator

Wrapper class to generate projections to and from MortarGrids.

Parameters
mortar_to_primary_int

Matrix of projections from the mortar grid to the primary grid. Intended for extensive quantities (so fluxes). Represented as an Ad Matrix operator.

Type

pp.ad.Matrix

mortar_to_primary_avg

Matrix of projections from the mortar grid to the primary grid. Intended for intensive quantities (so pressures). Represented as an Ad Matrix operator.

Type

pp.ad.Matrix

primary_to_mortar_int

Matrix of projections from the primary grid to the mortar grid. Intended for extensive quantities (so fluxes). Represented as an Ad Matrix operator.

Type

pp.ad.Matrix

primary_to_mortar_avg

Matrix of projections from the primary grid to the mortar grid. Intended for intensive quantities (so pressures). Represented as an Ad Matrix operator.

Type

pp.ad.Matrix

mortar_to_secondary_int

Matrix of projections from the mortar grid to the secondary grid. Intended for extensive quantities (so fluxes). Represented as an Ad Matrix operator.

Type

pp.ad.Matrix

mortar_to_secondary_avg

Matrix of projections from the mortar grid to the secondary grid. Intended for intensive quantities (so pressures). Represented as an Ad Matrix operator.

Type

pp.ad.Matrix

secondary_to_mortar_int

Matrix of projections from the secondary grid to the mortar grid. Intended for extensive quantities (so fluxes). Represented as an Ad Matrix operator.

Type

pp.ad.Matrix

secondary_to_mortar_avg

Matrix of projections from the secondary grid to the mortar grid. Intended for intensive quantities (so pressures). Represented as an Ad Matrix operator.

Type

pp.ad.Matrix

sign_of_mortar_sides

Matrix representation that assigns signs to two mortar sides. Needed to implement a jump operator in contact mechanics.

Type

pp.Ad.Matrix

interfaces: list[pp.MortarGrid]

List of interfaces on which the operator is defined, passed at instantiation.

Will be empty for operators not associated with specific interfaces.

subdomains: list[pp.Grid]

List of subdomains on which the operator is defined, passed at instantiation.

Will be empty for operators not associated with specific subdomains.

class ParameterArray(param_keyword, array_keyword, subdomains=None, interfaces=None, name=None)[source]

Bases: Operator

Extract an array from the parameter dictionaries for a given set of subdomains.

Can be used to implement sources, and general arrays to be picked from the parameter array (and thereby could be changed during the simulation, without having to redefine the abstract Ad representation of the equations).

Parameters
  • param_keyword (str) –

  • array_keyword (str) –

  • subdomains (Optional[list[pp.Grid]]) –

  • interfaces (Optional[list[pp.MortarGrid]]) –

  • name (Optional[str]) –

parse(mdg)[source]

Convert the Ad expression into numerical values for the scalar sources, in the form of an np.ndarray concatenated for all subdomains.

Parameters

mdg (pp.MixedDimensionalGrid) – Mixed-dimensional grid. The boundary condition will be taken from the data dictionaries with the relevant keyword.

Returns

Value of boundary conditions.

Return type

np.ndarray

interfaces: list[pp.MortarGrid]

List of interfaces on which the operator is defined, passed at instantiation.

Will be empty for operators not associated with specific interfaces.

subdomains: list[pp.Grid]

List of subdomains on which the operator is defined, passed at instantiation.

Will be empty for operators not associated with specific subdomains.

class ParameterMatrix(param_keyword, array_keyword, subdomains=None, interfaces=None, name=None)[source]

Bases: ParameterArray

Extract a matrix from the parameter dictionaries for a given set of subdomains.

Typical use: Parameters which are left multiplied with an ad expression. Note that

array parameters are represented by one diagonal matrix for each grid.

Parameters
  • param_keyword (str) –

  • array_keyword (str) –

  • subdomains (Optional[list[pp.Grid]]) –

  • interfaces (Optional[list[pp.MortarGrid]]) –

  • name (Optional[str]) –

parse(mdg)[source]

Convert the Ad expression into numerical values for the scalar sources, in the form of an np.ndarray concatenated for all subdomains.

Parameters

mdg (pp.MixedDimensionalGrid) – Mixed-dimensional grid. The boundary condition will be taken from the data dictionaries with the relevant keyword.

Returns

Value of boundary conditions.

Return type

sps.spmatrix

interfaces: list[pp.MortarGrid]

List of interfaces on which the operator is defined, passed at instantiation.

Will be empty for operators not associated with specific interfaces.

subdomains: list[pp.Grid]

List of subdomains on which the operator is defined, passed at instantiation.

Will be empty for operators not associated with specific subdomains.

class SubdomainProjections(subdomains, dim=1)[source]

Bases: Operator

Wrapper class for generating projection to and from subdomains.

One use case in when variables are defined on only some subdomains.

The class should be used through the methods {cell, face}_{projection, restriction}.

See also MortarProjections for projections to and from mortar subdomains.

Parameters
  • subdomains (list[pp.Grid]) –

  • dim (int) –

cell_prolongation(subdomains)[source]

Construct prolongation from subdomain to global cell quantities.

Parameters

subdomains (List of pp.Grid) – One or several subdomains to which the prolongation should apply.

Returns

Matrix operator (in the Ad sense) that represent the

prolongation.

Return type

pp.ad.Matrix

cell_restriction(subdomains)[source]

Construct restrictions from global to subdomain cell quantities.

Parameters

subdomains (List of pp.Grid) – One or several subdomains to which the projection should apply.

Returns

Matrix operator (in the Ad sense) that represents the

projection.

Return type

pp.ad.Matrix

face_prolongation(subdomains)[source]

Construct prolongation from subdomain to global face quantities.

Parameters

subdomains (List of pp.Grid) – One or several subdomains to which the prolongation should apply.

Returns

Matrix operator (in the Ad sense) that represent the

prolongation.

Return type

pp.ad.Matrix

face_restriction(subdomains)[source]

Construct restrictions from global to subdomain face quantities.

Parameters

subdomains (List of pp.Grid) – One or several subdomains to which the projection should apply.

Returns

Matrix operator (in the Ad sense) that represent the

projection.

Return type

pp.ad.Matrix

interfaces: list[pp.MortarGrid]

List of interfaces on which the operator is defined, passed at instantiation.

Will be empty for operators not associated with specific interfaces.

subdomains: list[pp.Grid]

List of subdomains on which the operator is defined, passed at instantiation.

Will be empty for operators not associated with specific subdomains.

class Trace(subdomains, dim=1, name=None)[source]

Bases: Operator

Wrapper class for Ad representations of trace operators and their inverse, that is, mappings between grid cells and faces.

NOTE: The mapping will hit both boundary and interior faces, so the values to be mapped should be carefully filtered (e.g. by combining it with a mortar mapping).

The mapping does not alter signs of variables, that is, the direction of face normal vectors is not accounted for.

Parameters
  • subdomains (list[pp.Grid]) –

  • dim (int) –

  • name (Optional[str]) –

trace

Matrix of trace projections from cells to faces.

Type

pp.ad.Matrix

inv_trace

Matrix of trace projections from faces to cells.

Type

pp.ad.Matrix

dim: int
interfaces: list[pp.MortarGrid]

List of interfaces on which the operator is defined, passed at instantiation.

Will be empty for operators not associated with specific interfaces.

subdomains: list[pp.Grid]

List of subdomains on which the operator is defined, passed at instantiation.

Will be empty for operators not associated with specific subdomains.