refine makes an existing mesh finer in new refinement areas. It needs only the mesh, which may come from another program. Cells outside the affected area keep their nodes and coordinates exactly.
Before and after; the new or changed cells are highlighted:
transition_rows works as for generate: one value per level step, or one value for all. A level finer than the mesh has adds levels to its lattice.
Carry cell data over: the replacement map
result.replacement_map relates the new cells to the old ones:
source[i]: the old cell that new cell i lies in (for an unchanged cell, itself);
unchanged[i]: whether new cell i is an old cell with the same nodes;
removed: the old cells that are not in the new mesh.
Per-cell values of the old mesh, such as an initial water level, carry over in one line:
old_values = np.linspace(10.0, 12.0, len(quad_mesh.faces)) # one value per old cellrm = result.replacement_mapnew_values = old_values[rm.source]print(f"{rm.unchanged.sum()} cells unchanged, {(~rm.unchanged).sum()} new, "f"{len(rm.removed)} old cells replaced")
239 cells unchanged, 365 new, 44 old cells replaced
The options and exit codes are those of generate. A mesh that cannot be recognised exits with 2 and writes model_v2_net_recognition.gpkg with the problem locations.
Domain and water areas
You may pass a domain and water areas to refine, or put them in the TOML file. They only remove new cells, and the domain’s holes are clipped like water. New cells only replace existing ones, inside the footprint of the mesh, so the mesh never grows. See Why refine starts from the mesh.