porepy.grids.simplex module

Module containing classes for simplex grids.

Acknowledgement

The implementation of structured grids is in practice a translation of the corresponding functions found in the Matlab Reservoir Simulation Toolbox (MRST) developed by SINTEF ICT.

class StructuredTetrahedralGrid(*args, **kwargs)[source]

Bases: TetrahedralGrid

Class for a structured tetrahedral grids, composed of Cartesian cells divided into two.

Example

Grid on the unit cube.

>>> nx = np.array([2, 3])
>>> physdims = np.ones(2)
>>> g = simplex.StructuredTriangleGrid(nx, physdims)
Parameters
  • nx

    shape=(2,)

    Number of cells in each direction of the underlying Cartesian grid.

  • physdims

    shape=(2,), default=None

    Domain size. If None, nx is used, thus Cartesian cells are unit cubes.

  • name

    default=None

    Name of the grid. If None, 'StructuredTetrahedralGrid' will be assigned.

Return type

Grid

cell_centers: ndarray

An array containing column-wise the centers of all cells with shape=(ambient_dimension, num_cells).

Available after calling compute_geometry().

cell_faces: csc_matrix

An array with shape=(num_faces, num_cells) representing the map from cells to faces bordering respective cell.

Matrix elements have value +-1, where + corresponds to the face normal vector being outwards.

cell_volumes: ndarray

An array containing column-wise the volumes per cell with shape=(num_cells,).

Available after calling compute_geometry().

dim: int

Grid dimension. Should be in {0, 1, 2, 3}.

face_areas: ndarray

Areas of all faces (shape=(num_cells,)). Available after calling compute_geometry().

face_centers: ndarray

Centers of all faces. (shape=(ambient_dimension, num_faces)). Available after calling compute_geometry().

face_nodes: csc_matrix

An array with shape=(num_nodes, num_faces) representing the map from faces to nodes spanning respective face.

Assumes the nodes of each face are ordered according to the right-hand rule.

Note

To use compute_geometry() later, the field face_nodes.indices should store the nodes of each face sorted. face_nodes.indices[face_nodes.indptr[i]:face_nodes.indptr[i+1]] are the nodes of face i, which should be ordered counter-clockwise.

By counter-clockwise we mean as seen from cell cell_faces[i,:] == -1.

Equivalently the nodes will be clockwise as seen from cell cell_faces[i,:] == 1.

Note that operations on the face_nodes matrix (such as converting it to a csr-matrix) may change the ordering of the nodes (face_nodes.indices), which will break compute_geometry().

face_normals: ndarray

An array containing column-wise normal vectors of all faces with shape=(ambient_dimenaion, num_faces).

See also cell_faces.

Available after calling compute_geometry().

frac_num: int

Index of the fracture the grid corresponds to. Take value (0, 1, ...) if the grid corresponds to a fracture, -1 if not.

frac_pairs: ndarray

Indices of faces that are geometrically coinciding, but lay on different side of a lower-dimensional grid.

global_point_ind: ndarray

An array with shape=(num_nodes,) containing indices of each point, assigned during processing of mixed-dimensional grids created by gmsh.

Used to identify points that are geometrically equal, though on different grids.

Could potentially be used to identify such geometrically equal points at a later stage, but there is no guarantee that this will work.

history: list[str]

Information on the formation of the grid, such as the constructor, computations of geometry etc.

name: str

Name assigned to this grid.

nodes: ndarray

An array with shape=(ambient_dimension, num_nodes) containing node coordinates column-wise.

num_cells: int

Number of cells in the grid.

num_faces: int

Number of faces in the grid.

num_nodes: int

Number of nodes in the grid.

parent_cell_ind: ndarray

Index of parent the cell in the parent grid for grids that have refined sub-grids or are sub-grids of larger grids.

Defaults to a mapping to its own index with shape=(num_cells,).

periodic_face_map: ndarray

Index of periodic boundary faces, (shape=(2, num_periodic_faces), dtype=int).

Face index periodic_face_map[0, i] is periodic with face index periodic_face_map[1, i]. This attribute is set with set_periodic_map().

tags: dict[str, numpy.ndarray]

Tags allow to mark subdomains of interest.

The default tags are used to mark fractures, tips and domain boundaries. Tags are used for nodes, as well as faces. User tags can be provided in the constructor.

well_num: int

Index of the well associated to the grid. Takes a value in (0, 1, ..) if the grid corresponds to a well, -1 if not.

class StructuredTriangleGrid(*args, **kwargs)[source]

Bases: TriangleGrid

Class for a structured triangular grids, composed of squares divided into two.

Example

Grid on the unit cube.

>>> nx = np.array([2, 3])
>>> physdims = np.ones(2)
>>> g = simplex.StructuredTriangleGrid(nx, physdims)
Parameters
  • nx

    shape=(2,)

    Number of cells in each direction of the underlying Cartesian grid.

  • physdims

    shape=(2,), default=None

    Domain size. If None, nx is used, thus Cartesian cells are unit squares.

  • name

    default=None

    Name of the grid. If None, 'StructuredTriangleGrid' will be assigned.

Return type

Grid

cell_centers: ndarray

An array containing column-wise the centers of all cells with shape=(ambient_dimension, num_cells).

Available after calling compute_geometry().

cell_faces: csc_matrix

An array with shape=(num_faces, num_cells) representing the map from cells to faces bordering respective cell.

Matrix elements have value +-1, where + corresponds to the face normal vector being outwards.

cell_volumes: ndarray

An array containing column-wise the volumes per cell with shape=(num_cells,).

Available after calling compute_geometry().

dim: int

Grid dimension. Should be in {0, 1, 2, 3}.

face_areas: ndarray

Areas of all faces (shape=(num_cells,)). Available after calling compute_geometry().

face_centers: ndarray

Centers of all faces. (shape=(ambient_dimension, num_faces)). Available after calling compute_geometry().

face_nodes: csc_matrix

An array with shape=(num_nodes, num_faces) representing the map from faces to nodes spanning respective face.

Assumes the nodes of each face are ordered according to the right-hand rule.

Note

To use compute_geometry() later, the field face_nodes.indices should store the nodes of each face sorted. face_nodes.indices[face_nodes.indptr[i]:face_nodes.indptr[i+1]] are the nodes of face i, which should be ordered counter-clockwise.

By counter-clockwise we mean as seen from cell cell_faces[i,:] == -1.

Equivalently the nodes will be clockwise as seen from cell cell_faces[i,:] == 1.

Note that operations on the face_nodes matrix (such as converting it to a csr-matrix) may change the ordering of the nodes (face_nodes.indices), which will break compute_geometry().

face_normals: ndarray

An array containing column-wise normal vectors of all faces with shape=(ambient_dimenaion, num_faces).

See also cell_faces.

Available after calling compute_geometry().

frac_num: int

Index of the fracture the grid corresponds to. Take value (0, 1, ...) if the grid corresponds to a fracture, -1 if not.

frac_pairs: ndarray

Indices of faces that are geometrically coinciding, but lay on different side of a lower-dimensional grid.

global_point_ind: ndarray

An array with shape=(num_nodes,) containing indices of each point, assigned during processing of mixed-dimensional grids created by gmsh.

Used to identify points that are geometrically equal, though on different grids.

Could potentially be used to identify such geometrically equal points at a later stage, but there is no guarantee that this will work.

history: list[str]

Information on the formation of the grid, such as the constructor, computations of geometry etc.

name: str

Name assigned to this grid.

nodes: ndarray

An array with shape=(ambient_dimension, num_nodes) containing node coordinates column-wise.

num_cells: int

Number of cells in the grid.

num_faces: int

Number of faces in the grid.

num_nodes: int

Number of nodes in the grid.

parent_cell_ind: ndarray

Index of parent the cell in the parent grid for grids that have refined sub-grids or are sub-grids of larger grids.

Defaults to a mapping to its own index with shape=(num_cells,).

periodic_face_map: ndarray

Index of periodic boundary faces, (shape=(2, num_periodic_faces), dtype=int).

Face index periodic_face_map[0, i] is periodic with face index periodic_face_map[1, i]. This attribute is set with set_periodic_map().

tags: dict[str, numpy.ndarray]

Tags allow to mark subdomains of interest.

The default tags are used to mark fractures, tips and domain boundaries. Tags are used for nodes, as well as faces. User tags can be provided in the constructor.

well_num: int

Index of the well associated to the grid. Takes a value in (0, 1, ..) if the grid corresponds to a well, -1 if not.

class TetrahedralGrid(*args, **kwargs)[source]

Bases: Grid

Class for Tetrahedral grids.

If the cells are not provided, a Delaunay tesselation will be constructed.

Parameters
  • p

    shape=(3, num_points)

    Coordinates of vertices.

  • tet

    shape=(4, num_tet), default=None

    Cell vertices. If None, a Delaunay triangulation will be performed.

  • name

    default=None

    Name of grid type. If None, 'TetrahedralGrid' will be assigned.

Return type

Grid

cell_centers: ndarray

An array containing column-wise the centers of all cells with shape=(ambient_dimension, num_cells).

Available after calling compute_geometry().

cell_faces: csc_matrix

An array with shape=(num_faces, num_cells) representing the map from cells to faces bordering respective cell.

Matrix elements have value +-1, where + corresponds to the face normal vector being outwards.

cell_volumes: ndarray

An array containing column-wise the volumes per cell with shape=(num_cells,).

Available after calling compute_geometry().

dim: int

Grid dimension. Should be in {0, 1, 2, 3}.

face_areas: ndarray

Areas of all faces (shape=(num_cells,)). Available after calling compute_geometry().

face_centers: ndarray

Centers of all faces. (shape=(ambient_dimension, num_faces)). Available after calling compute_geometry().

face_nodes: csc_matrix

An array with shape=(num_nodes, num_faces) representing the map from faces to nodes spanning respective face.

Assumes the nodes of each face are ordered according to the right-hand rule.

Note

To use compute_geometry() later, the field face_nodes.indices should store the nodes of each face sorted. face_nodes.indices[face_nodes.indptr[i]:face_nodes.indptr[i+1]] are the nodes of face i, which should be ordered counter-clockwise.

By counter-clockwise we mean as seen from cell cell_faces[i,:] == -1.

Equivalently the nodes will be clockwise as seen from cell cell_faces[i,:] == 1.

Note that operations on the face_nodes matrix (such as converting it to a csr-matrix) may change the ordering of the nodes (face_nodes.indices), which will break compute_geometry().

face_normals: ndarray

An array containing column-wise normal vectors of all faces with shape=(ambient_dimenaion, num_faces).

See also cell_faces.

Available after calling compute_geometry().

frac_num: int

Index of the fracture the grid corresponds to. Take value (0, 1, ...) if the grid corresponds to a fracture, -1 if not.

frac_pairs: ndarray

Indices of faces that are geometrically coinciding, but lay on different side of a lower-dimensional grid.

global_point_ind: ndarray

An array with shape=(num_nodes,) containing indices of each point, assigned during processing of mixed-dimensional grids created by gmsh.

Used to identify points that are geometrically equal, though on different grids.

Could potentially be used to identify such geometrically equal points at a later stage, but there is no guarantee that this will work.

history: list[str]

Information on the formation of the grid, such as the constructor, computations of geometry etc.

name: str

Name assigned to this grid.

nodes: ndarray

An array with shape=(ambient_dimension, num_nodes) containing node coordinates column-wise.

num_cells: int

Number of cells in the grid.

num_faces: int

Number of faces in the grid.

num_nodes: int

Number of nodes in the grid.

parent_cell_ind: ndarray

Index of parent the cell in the parent grid for grids that have refined sub-grids or are sub-grids of larger grids.

Defaults to a mapping to its own index with shape=(num_cells,).

periodic_face_map: ndarray

Index of periodic boundary faces, (shape=(2, num_periodic_faces), dtype=int).

Face index periodic_face_map[0, i] is periodic with face index periodic_face_map[1, i]. This attribute is set with set_periodic_map().

tags: dict[str, numpy.ndarray]

Tags allow to mark subdomains of interest.

The default tags are used to mark fractures, tips and domain boundaries. Tags are used for nodes, as well as faces. User tags can be provided in the constructor.

well_num: int

Index of the well associated to the grid. Takes a value in (0, 1, ..) if the grid corresponds to a well, -1 if not.

class TriangleGrid(*args, **kwargs)[source]

Bases: Grid

Class representation of a general triangular grid.

If no triangulation is provided, Delaunay will be applied.

Note

Triangular grids are by definition 2D.

Example

>>> p = np.random.rand(2, 10)
>>> tri = scipy.spatial.Delaunay(p.transpose()).simplices
>>> g = TriangleGrid(p, tri.transpose())
Parameters
  • p

    shape=(2, num_nodes)

    Cloud of point coordinates.

  • tri

    shape=(3, num_cells), default=None

    Cell-node connections. If None, a Delaunay triangulation will be applied.

  • name

    default=None

    Name of the grid. If None, 'TriangleGrid' will be assigned.

Return type

Grid

cell_node_matrix()[source]
Returns

An array with shape=(num_cells, 3), representing the cell-to-node map.

Return type

ndarray

cell_centers: ndarray

An array containing column-wise the centers of all cells with shape=(ambient_dimension, num_cells).

Available after calling compute_geometry().

cell_faces: csc_matrix

An array with shape=(num_faces, num_cells) representing the map from cells to faces bordering respective cell.

Matrix elements have value +-1, where + corresponds to the face normal vector being outwards.

cell_volumes: ndarray

An array containing column-wise the volumes per cell with shape=(num_cells,).

Available after calling compute_geometry().

dim: int

Grid dimension. Should be in {0, 1, 2, 3}.

face_areas: ndarray

Areas of all faces (shape=(num_cells,)). Available after calling compute_geometry().

face_centers: ndarray

Centers of all faces. (shape=(ambient_dimension, num_faces)). Available after calling compute_geometry().

face_nodes: csc_matrix

An array with shape=(num_nodes, num_faces) representing the map from faces to nodes spanning respective face.

Assumes the nodes of each face are ordered according to the right-hand rule.

Note

To use compute_geometry() later, the field face_nodes.indices should store the nodes of each face sorted. face_nodes.indices[face_nodes.indptr[i]:face_nodes.indptr[i+1]] are the nodes of face i, which should be ordered counter-clockwise.

By counter-clockwise we mean as seen from cell cell_faces[i,:] == -1.

Equivalently the nodes will be clockwise as seen from cell cell_faces[i,:] == 1.

Note that operations on the face_nodes matrix (such as converting it to a csr-matrix) may change the ordering of the nodes (face_nodes.indices), which will break compute_geometry().

face_normals: ndarray

An array containing column-wise normal vectors of all faces with shape=(ambient_dimenaion, num_faces).

See also cell_faces.

Available after calling compute_geometry().

frac_num: int

Index of the fracture the grid corresponds to. Take value (0, 1, ...) if the grid corresponds to a fracture, -1 if not.

frac_pairs: ndarray

Indices of faces that are geometrically coinciding, but lay on different side of a lower-dimensional grid.

global_point_ind: ndarray

An array with shape=(num_nodes,) containing indices of each point, assigned during processing of mixed-dimensional grids created by gmsh.

Used to identify points that are geometrically equal, though on different grids.

Could potentially be used to identify such geometrically equal points at a later stage, but there is no guarantee that this will work.

history: list[str]

Information on the formation of the grid, such as the constructor, computations of geometry etc.

name: str

Name assigned to this grid.

nodes: ndarray

An array with shape=(ambient_dimension, num_nodes) containing node coordinates column-wise.

num_cells: int

Number of cells in the grid.

num_faces: int

Number of faces in the grid.

num_nodes: int

Number of nodes in the grid.

parent_cell_ind: ndarray

Index of parent the cell in the parent grid for grids that have refined sub-grids or are sub-grids of larger grids.

Defaults to a mapping to its own index with shape=(num_cells,).

periodic_face_map: ndarray

Index of periodic boundary faces, (shape=(2, num_periodic_faces), dtype=int).

Face index periodic_face_map[0, i] is periodic with face index periodic_face_map[1, i]. This attribute is set with set_periodic_map().

tags: dict[str, numpy.ndarray]

Tags allow to mark subdomains of interest.

The default tags are used to mark fractures, tips and domain boundaries. Tags are used for nodes, as well as faces. User tags can be provided in the constructor.

well_num: int

Index of the well associated to the grid. Takes a value in (0, 1, ..) if the grid corresponds to a well, -1 if not.