Skip to main content

refine

refine(
    mesh,
    refinement_areas,
    *,
    transition_rows=1,
    domain=None,
    water_areas=(),
    water_removal='centre',
    crs=None,
    progress=None,
)

Refine an existing mesh locally with new refinement areas.

The lattice and the lattice squares are recognised from the cells of the mesh (transition cells as parts of their square), the new areas are applied, the 2:1 balance is restored where needed and the transitions around the changed squares are rebuilt. Squares that do not change keep their cells exactly, nodes included.

Parameters

Name Type Description Default
mesh Mesh The existing mesh, for example from :func:read_ugrid. required
refinement_areas iterable of (shapely geometry, int), or Areas The new refinement areas with their level (1 or higher, relative to the base cell of the mesh). required
transition_rows int or sequence of int Transition rows per level step from coarse to fine, as for :func:generate: one value per step up to the highest level of the result (that of the mesh or of the new areas, whichever is higher), or one value for every step; each at least 0. Only the steps the new areas need are used. 1
domain shapely geometry or Areas New cells outside it are removed; its holes act as water areas. It never adds cells: refining stays within the footprint of the mesh. None
water_areas iterable of shapely geometry, or Areas New cells are removed by the water removal rule; existing cells stay. ()
water_removal ('centre', 'inside', 'touches') Water removal rule. "centre"
crs pyproj.CRS or str or int CRS of input without CRS (shapely geometries) when the mesh has a CRS; input with its own CRS is transformed to the CRS of the mesh. None
progress callable As for :func:generate. None

Returns

Name Type Description
RefineResult The new mesh (lattice levels raised if the new areas are finer) and the replacement map.

Raises

Name Type Description
MeshRecognitionError If the mesh is not a refined quad mesh: nodes off its lattice, cells that fill no lattice square, or a broken 2:1 balance; it carries the locations. Duplicate nodes are accepted: cells that do not change keep theirs.
InputError For invalid areas, transition rows, CRS or water removal rule (as :func:generate).
OrthogonalityRepairError If the orthogonality repair cannot close; it carries the raw mesh.
Cancelled If the progress callback returned True.