mesh

The mesh module provides tools for manipulating ADCIRC meshes.

Functions

Submodules

mesh_merger

Module for merging ADCIRC meshes with optional VEW boundary generation.

class vewutils.mesh.mesh_merger.MergeStrategy[source]

Bases: ABC

Abstract base class for mesh merging strategies.

abstractmethod merge(channel_mesh, land_mesh, config)[source]

Merge two meshes according to the strategy.

Return type:

AdcircMesh

class vewutils.mesh.mesh_merger.VEWBoundaryStrategy[source]

Bases: MergeStrategy

Strategy that keeps duplicate nodes and adds VEW boundaries.

static _find_edges(elements_df)[source]

Find all edges in the mesh and count how many elements each edge belongs to.

Parameters:

elements_df (DataFrame) – DataFrame containing element definitions

Return type:

Dict

Returns:

Dictionary mapping edges (as frozenset of node IDs) to the number of elements they belong to

static _split_node_string(nodes, node_neighbors, elements_df)[source]

Split a string of nodes into segments based on domain boundaries.

Return type:

List[List[int]]

_find_paired_nodes(nodes_df, tolerance)[source]

Find pairs of nodes that are at identical locations.

Return type:

List[Tuple[int, int]]

_create_vew_boundaries(paired_nodes, land_mesh, node_mapping, combined_elements, config)[source]

Create VEW boundary definitions.

Return type:

List[Dict]

_filter_boundary_nodes(node_ids, original_length, matching_nodes)[source]

Filter out nodes that are members of matching nodes from a boundary.

Parameters:
  • node_ids (List[str]) – List of node IDs in the boundary

  • original_length (int) – Original length of the boundary

  • matching_nodes (Set[str]) – Set of node IDs that match between the two meshes

Return type:

Tuple[List[int], bool]

Returns:

Tuple of (list of indices to keep, whether to keep the boundary)

merge(channel_mesh, land_mesh, config)[source]

Merge meshes using VEW boundaries.

Return type:

AdcircMesh

class vewutils.mesh.mesh_merger.MergedNodesStrategy[source]

Bases: MergeStrategy

Strategy that merges duplicate nodes at boundaries.

merge(channel_mesh, land_mesh, config)[source]

Merge meshes by merging duplicate nodes.

Return type:

AdcircMesh

class vewutils.mesh.mesh_merger.MeshMerger(channel_mesh, land_mesh)[source]

Bases: object

Class for merging ADCIRC meshes with configurable strategies.

__init__(channel_mesh, land_mesh)[source]

Initialize the mesh merger with channel and land meshes.

static _create_default_config()[source]

Create default configuration for mesh merging.

Return type:

Dict

with_tolerance(tolerance)[source]

Set the tolerance for node matching.

Return type:

MeshMerger

with_height_offset(offset)[source]

Set the height offset for VEW boundaries.

Return type:

MeshMerger

with_flow_coefficients(subcritical, supercritical)[source]

Set the flow coefficients for VEW boundaries.

Return type:

MeshMerger

with_channel_values(enabled=True)[source]

Choose whether to use channel mesh values at matching nodes.

Return type:

MeshMerger

merge(boundary_mode='merge')[source]

Merge the meshes using the selected strategy.

Return type:

AdcircMesh

vewutils.mesh.mesh_merger.get_parser()[source]
vewutils.mesh.mesh_merger.main(args=None)[source]

mesh_subtractor

vewutils.mesh.mesh_subtractor.get_parser()[source]
class vewutils.mesh.mesh_subtractor.MeshSubtractor[source]

Bases: object

__init__()[source]
_find_edges(mesh)[source]

Find edges and count how many elements each edge belongs to.

_split_node_string(mesh, unshared_edges, unshared_elems)[source]

Split node string into segments based on domain boundaries.

_generate_boundary_polygons(mesh, segments)[source]

Generate a polygon from the mesh boundary segments.

Parameters:
  • mesh – AdcircMesh object containing node coordinates

  • segments – List of node segments defining boundary rings

Returns:

A shapely geometry representing the union of all boundary polygons

Return type:

MultiPolygon or Polygon

Raises:

ValueError – If no valid polygons could be created from the segments

subtract(mesh_a, mesh_b)[source]

Remove elements from mesh_a that are inside mesh_b’s domain boundary.

vewutils.mesh.mesh_subtractor.main(args=None)[source]

add_land_boundaries

Module for adding land boundaries (ibtype = 20) along unassigned boundary segments.

class vewutils.mesh.add_land_boundaries.LandBoundaryAdder(mesh)[source]

Bases: object

Class for adding land boundaries along unassigned boundary segments.

__init__(mesh)[source]

Initialize with an ADCIRC mesh.

static _find_edges(elements_df)[source]

Find all edges in the mesh and count how many elements each edge belongs to.

Parameters:

elements_df – DataFrame containing element definitions

Return type:

Dict

Returns:

Dictionary mapping edges (as frozenset of node IDs) to the number of elements they belong to

_get_boundary_nodes()[source]

Get all nodes that are part of boundary edges.

Return type:

Set[int]

_get_assigned_boundary_nodes()[source]

Get all nodes that are already part of boundary conditions and their endpoints.

Return type:

Tuple[Set[int], Set[int]]

Returns:

Tuple of (set of all assigned nodes, set of endpoint nodes that are part of unassigned boundary edges)

_split_node_string(nodes, node_neighbors)[source]

Split a string of nodes into segments based on domain boundaries.

Return type:

List[List[int]]

add_land_boundaries()[source]

Add land boundaries (ibtype = 20) along unassigned boundary segments.

Return type:

AdcircMesh

vewutils.mesh.add_land_boundaries.get_parser()[source]
vewutils.mesh.add_land_boundaries.main(args=None)[source]

adjust_vew_barrier_heights

Script to ensure VEW boundary barrier heights are above bank elevations.

vewutils.mesh.adjust_vew_barrier_heights.get_parser()[source]
vewutils.mesh.adjust_vew_barrier_heights.main(args=None)[source]

adjust_vew_channel_elevations

Script to adjust VEW boundary elevations by lowering channel node elevations relative to bank nodes.

vewutils.mesh.adjust_vew_channel_elevations.get_parser()[source]
vewutils.mesh.adjust_vew_channel_elevations.main(args=None)[source]

vew_boundary_manipulator

Module for manipulating VEW boundaries in ADCIRC meshes.

class vewutils.mesh.vew_boundary_manipulator.VEWBoundaryManipulator[source]

Bases: object

Class for manipulating VEW boundaries in ADCIRC meshes.

static find_matching_nodes(nodes_df1, nodes_df2, tolerance)[source]

Find matching nodes between two meshes within tolerance.

Parameters:
  • nodes_df1 (DataFrame) – First mesh nodes DataFrame

  • nodes_df2 (DataFrame) – Second mesh nodes DataFrame

  • tolerance (float) – Distance tolerance for matching nodes

Return type:

Dict[int, int]

Returns:

Dictionary mapping first mesh node IDs to second mesh node IDs

static get_vew_node_pairs(mesh)[source]

Extract bank and channel node pairs from VEW boundaries.

Parameters:

mesh (AdcircMesh) – AdcircMesh object

Returns:

(bank_to_channel, channel_to_bank) dictionaries mapping node IDs

Return type:

tuple

static lower_channel_elevations_above_banks(mesh, tolerance)[source]

Lower channel node elevations only when they are above their corresponding bank nodes.

Parameters:
  • mesh (AdcircMesh) – AdcircMesh object

  • tolerance (float) – Amount to lower channel node elevations below bank node elevations (in meters)

Return type:

AdcircMesh

Returns:

Modified AdcircMesh object

static get_vew_boundaries(mesh)[source]

Get all VEW boundaries from the mesh.

Parameters:

mesh (AdcircMesh) – AdcircMesh object

Return type:

list

Returns:

List of VEW boundary dictionaries

static add_vew_boundary(mesh, node_pairs, barrier_heights, subcritical_coefficients=None, supercritical_coefficients=None)[source]

Add a new VEW boundary to the mesh.

Parameters:
  • mesh (AdcircMesh) – AdcircMesh object

  • node_pairs (list) – List of (bank_node, channel_node) tuples

  • barrier_heights (list) – List of barrier heights for each node pair

  • subcritical_coefficients (list) – List of subcritical flow coefficients (default: 1.0)

  • supercritical_coefficients (list) – List of supercritical flow coefficients (default: 1.0)

Return type:

AdcircMesh

Returns:

Modified AdcircMesh object

static ensure_barrier_heights_above_banks(mesh, tolerance=0.001)[source]

Set barrier heights in VEW boundaries to bank elevations plus tolerance.

Parameters:
  • mesh (AdcircMesh) – AdcircMesh object

  • tolerance (float) – Amount to add to bank elevations for barrier heights (in meters, default: 0.001)

Return type:

AdcircMesh

Returns:

Modified AdcircMesh object