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()
argumentsmesh_size_fracs
andmesh_size_bound
. These are set by the parametermesh_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 theFractureNetwork
.Further argument, such as fractures that are really constraints, can be given by
params['grid_params']
. These are passed on theFractureNetwork.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.
- class GridSequenceIterator(factory)[source]
Bases:
object
Iterator for generating successively refined grids by the use of a grid factory.
See also
- 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
- 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 asg
.
ndarray
:shape=(g.num_cells*(nd+2),)
Mapping from new to old cells.
- Return type
- 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
- Returns
The new grid that covers the same domain as g_old.
- Return type