porepy.models.geometry module

Geometry definition for simulation setup.

class ModelGeometry[source]

Bases: object

This class provides geometry related methods and information for a simulation model.

basis(grids, dim)[source]

Return a cell-wise basis for all subdomains.

The basis is represented as a list of matrices, each of which represents a basis function. The individual matrices have shape Nc * dim, Nc where Nc is the total number of cells in the subdomains.

Examples

To extend a cell-wise scalar to a vector field, use sum([e_i for e_i in basis(subdomains)]). To restrict to a vector in the tangential direction only, use sum([e_i for e_i in basis(subdomains, dim=nd-1)])

See also

e_i() for the construction of a single basis function. normal_component() for the construction of a restriction to the

normal component of a vector only.

tangential_component() for the construction of a restriction to the

tangential component of a vector only.

Parameters
Returns

List of pp.ad.Matrix, each of which represents a basis function.

Return type

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

domain_boundary_sides(g)[source]

Obtain indices of grid faces on the different parts of the domain boundary.

It is assumed the domain is box shaped.

TODO: Update this from develop before merging. :param g: Grid for which to obtain the boundary faces.

Parameters

g (Grid) –

Return type

tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray]

e_i(grids, *, i, dim)[source]

Return a cell-wise basis function in a specified dimension.

It is assumed that the grids are embedded in a space of dimension dim and aligned with the coordinate axes, that is, the reference space of the grid. Moreover, the grid is assumed to be planar.

Example

For a grid with two cells, and with i=1 and dim=3, the returned basis will be (aftert conversion to a numpy array) .. code-block:: python

array([[0., 0.],

[1., 0.], [0., 0.], [0., 0.], [0., 1.], [0., 0.]])

See also

basis() for the construction of a full basis.

Parameters
  • grids (Sequence[Union[Grid, MortarGrid]]) – List of grids on which the basis vector is defined.

  • 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

Raises
  • ValueError – If dim is smaller than the dimension of the mixed-dimensional.

  • ValueError – If i is larger than dim.

interfaces_to_subdomains(interfaces)[source]

Subdomain neighbours of interfaces.

Parameters

interfaces (list[porepy.grids.mortar_grid.MortarGrid]) – List of interfaces for which to find subdomains.

Returns

Unique list of all subdomains neighbouring any of the interfaces. The subdomains are sorted according to their index as defined by the mixed-dimensional grid.

Return type

list[porepy.grids.grid.Grid]

internal_boundary_normal_to_outwards(subdomains, *, dim)[source]

Obtain a vector for flipping normal vectors on internal boundaries.

For a list of subdomains, check if the normal vector on internal boundaries point into the internal interface (e.g., into the fracture), and if so, flip the normal vector. The flipping takes the form of an operator that multiplies the normal vectors of all faces on fractures, leaves internal faces (internal to the subdomain proper, that is) unchanged, but flips the relevant normal vectors on subdomain faces that are part of an internal boundary.

Currently, this is a helper method for the computation of outward normals in outwards_internal_boundary_normals(). Other usage is allowed, but one is adviced to carefully consider subdomain lists when combining this with other operators.

Parameters
Returns

Operator with flipped signs if normal vector points inwards.

Return type

Operator

local_coordinates(subdomains)[source]

Ad wrapper around tangential_normal_projections for fractures.

Parameters

subdomains (list[porepy.grids.grid.Grid]) – List of subdomains for which to compute the local coordinates.

Returns

Local coordinates as a pp.ad.Matrix.

Return type

Matrix

mesh_arguments()[source]

Mesh arguments for md-grid creation.

Returns

Dictionary of meshing arguments compatible with

FractureNetwork.mesh() method.

Return type

mesh_args

normal_component(subdomains)[source]

Compute the normal component of a vector field.

The normal space is defined according to the local coordinates of the subdomains, with the normal space defined by final component, e.g., number self.nd-1 (zero offset). of the cell-wise vector. It is assumed that the components of a vector are stored with a dimension-major ordering (the dimension varies fastest).

See also

e_i() for the definition of the basis functions. tangential_component() for the definition of the tangential space.

Parameters

subdomains (list[porepy.grids.grid.Grid]) – List of grids on which the vector field is defined.

Returns

Matrix extracting normal component of the vector field and expressing it in normal basis. The size of the matrix is (Nc, Nc * self.nd), where Nc is the total number of cells in the subdomains.

Return type

Matrix

outwards_internal_boundary_normals(interfaces, *, unitary)[source]

Compute outward normal vectors on internal boundaries.

Parameters
Returns

Operator computing outward normal vectors on internal boundaries. Evaluated shape (num_intf_cells * dim, num_intf_cells * dim).

Return type

Operator

set_fracture_network()[source]

Assign fracture network class.

Return type

None

set_geometry()[source]

Define geometry and create a mixed-dimensional grid.

Return type

None

set_md_grid()[source]

Create the mixed-dimensional grid.

A unit square grid with no fractures is assigned by default if self.fracture_network contains no fractures. Otherwise, the network’s mesh method is used.

The method assigns the following attributes to self:

mdg (pp.MixedDimensionalGrid): The produced grid bucket. box (dict): The bounding box of the domain, defined through minimum and

maximum values in each dimension.

Return type

None

subdomain_projections(dim)[source]

Return the projection operators for all subdomains in md-grid.

The projection operators restrict or prolong a dim-dimensional quantity from the full set of subdomains to any subset. Projection operators are constructed once and then stored. If you need to use projection operators based on a different set of subdomains, please construct them yourself. Alternatively, compose a projection from subset A to subset B as

P_A_to_B = P_full_to_B * P_A_to_full.

Parameters

dim (int) – Dimension of the quantities to be projected.

Returns

Projection operator.

Return type

proj

subdomains_to_interfaces(subdomains, codims)[source]

Interfaces neighbouring any of the subdomains.

Parameters
  • subdomains (list[porepy.grids.grid.Grid]) – Subdomains for which to find interfaces.

  • codims (list[int]) – Codimension of interfaces to return. The common option is [1], i.e. only interfaces between subdomains one dimension apart.

Returns

Unique list of all interfaces neighboring any of the subdomains. Interfaces are sorted according to their index, as defined by the mixed-dimensional grid.

Return type

list[porepy.grids.mortar_grid.MortarGrid]

tangential_component(subdomains)[source]

Compute the tangential component of a vector field.

The tangential space is defined according to the local coordinates of the subdomains, with the tangential space defined by the first self.nd components of the cell-wise vector. It is assumed that the components of the vector are stored with a dimension-major ordering (the dimension varies fastest).

Parameters

subdomains (list[porepy.grids.grid.Grid]) – List of grids on which the vector field is defined.

Returns

Operator extracting tangential component of the vector field and expressing it in tangential basis.

Return type

Operator

wrap_grid_attribute(grids, attr, *, dim, inverse=False)[source]

Wrap a grid attribute as an ad matrix.

Parameters
  • grids (Sequence[Union[Grid, MortarGrid]]) – List of grids on which the property is defined.

  • attr (str) – Grid attribute to wrap. The attribute should be a ndarray and will be flattened if it is not already one dimensional.

  • dim (int) – Dimensions to include for vector attributes. Intended use is to limit the number of dimensions for a vector attribute, e.g. to exclude the z-component of a vector attribute in 2d, to acieve compatibility with code which is explicitly 2d (e.g. fv discretizations).

  • inverse (bool) – If True, the inverse of the attribute will be wrapped. This is a hack around the fact that the Ad framework does not support division. FIXME: Remove when ad supports division.

Returns

The property wrapped as an ad matrix, with the wrapped attribute on the diagonal.

Raises
  • ValueError – If one of the grids does not have the attribute.

  • ValueError – If the attribute is not a ndarray.

Return type

Matrix

domain_bounds: dict[str, float]

Box-shaped domain. Set by the method set_md_grid().

fracture_network: Union[FractureNetwork2d, FractureNetwork3d]

Representation of fracture network including intersections.

mdg: MixedDimensionalGrid

Mixed-dimensional grid. Set by the method set_md_grid().

nd: int

Ambient dimension of the problem. Set by the method set_geometry()

units: Units

Unit system.

well_network: WellNetwork3d

Well network.