porepy.grids.refinement module

This module contains various methods to refine a grid.

It furthermore contains classes to define sequences of refined grids, and a factory class to generate sets of refined grids.

class GridSequenceFactory(network, params)[source]

Bases: ABC

Factory class to generate a set of refined grids.

To define new refinement types, inherit from this class and override the _generate() method.

The class can be used in (for now) two ways:

Either by nested or unstructured refinement. This is set by setting the parameter mode to 'nested' or 'unstructured' respectively.

The number of refinement is set by the parameter 'num_refinements'.

Mesh sizes are set by the standard FractureNetwork.mesh() arguments mesh_size_fracs and mesh_size_bound. These are set by the parameter mesh_param.

If the mode is 'nested', mesh_param should be a single dictionary; subsequent mesh refinements are then set by nested refinement.

If the mode is 'unstructured', mesh_params should be a list, where each list element is a dictionary with mesh size parameters to be passed to the FractureNetwork.

Further argument, such as fractures that are really constraints, can be given by params['grid_params']. These are passed on the FractureNetwork.mesh(), essentially as **kwargs.

Acknowledgements

The design idea and the majority of the code was contributed to by Haakon Ervik.

Parameters
  • network (Union[pp.FractureNetwork2d, pp.FractureNetwork3d]) – Define the domain that is to be discretized.

  • params (dict) –

    Parameter dictionary. See above for more details on admissible keywords.

    Note that entries for every keyword are required and will raise an error if not available.

close()[source]

Method for finalizing gmsh.

gmsh will be informed that it should be finalized. Final method to be called when the iteration is going to be stopped.

Return type

None

dim: int

Dimension of the fracture network.

class GridSequenceIterator(factory)[source]

Bases: object

Iterator for generating successively refined grids by the use of a grid factory.

Parameters

factory (GridSequenceFactory) – Factory class for generating set of refined grids.

distort_grid_1d(g, ratio=0.1, fixed_nodes=None)[source]

Randomly distort internal nodes in a 1d grid.

The boundary nodes are left untouched, and the perturbations will not perturb the topology of the mesh.

Parameters
  • g (Grid) – The grid that will be perturbed. Modifications will happen in place.

  • ratio (float) –

    default=0.1

    Perturbation ratio. A node can be moved at most half the distance in towards any of its neighboring nodes. The ratio will multiply the chosen distortion. Should be less than 1 to preserve grid topology.

  • fixed_nodes (Optional[ndarray]) –

    default=None

    Index of nodes to keep fixed under distortion. Boundary nodes will always be fixed, even if not explicitly included as fixed_node.

Returns

The grid, but with distorted nodes.

Return type

Grid

refine_grid_1d(g, ratio=2)[source]

Refine the cells in a 1D grid.

Parameters
  • g (Grid) – The 1D grid that is to be refined.

  • ratio (int) –

    default=2

    Refinement level.

Returns

A new, more refined, grid.

Return type

Grid

refine_triangle_grid(g)[source]

Uniform refinement of triangular grids.

All cells are split into four subcells by combining existing nodes and face centers.

Note

It should be fairly straightforward to extend the function to 3D simplex grids as well. The loop over face combinations extends straightforwardly, but obtaining the node in the corner defined by faces may be a bit tricky.

Parameters

g (TriangleGrid) – The triangle grid that is to be refined.

Returns

A 2-tuple containing

TriangleGrid:

New grid, with nd+2 times as many cells as g.

ndarray: shape=(g.num_cells*(nd+2),)

Mapping from new to old cells.

Return type

tuple[porepy.grids.simplex.TriangleGrid, numpy.ndarray]

remesh_1d(g_old, num_nodes, tol=1e-6)[source]

Create a new 1d mesh covering the same domain as an old one.

The new grid is equi-spaced, and there is no guarantee that the nodes in the old and new grids are coinciding. Use with care, in particular for grids with internal boundaries.

Parameters
  • g_old (Grid) – 1d grid to be replaced/remeshed.

  • num_nodes (int) – Number of nodes in the new grid.

  • tol (optional) – Tolerance used to compare node coordinates (for mapping of boundary conditions). Defaults to 1e-6.

Returns

The new grid that covers the same domain as g_old.

Return type

Grid