A Python package that automatically transforms SWASH (Simulating WAves till SHore) input files from cartesian coordinates to unstructured meshes using gmsh. The mesh generation is adaptive, with refinement proportional to water depth --- finest resolution near the shoreline and coarsest at maximum depth. Breakwaters (identified by porosity ≠ 1) automatically receive the finest resolution.
- Adaptive mesh refinement: Automatically creates finer mesh near shorelines and breakwaters
- Depth-based sizing: Mesh resolution varies from fine (shallow water) to coarse (deep water)
- Gauge support: Optional refinement around specified gauge positions
- SWASH compatibility: Exports meshes in Triangle format (.node, .ele, .edge files)
- Boundary tagging: Automatic boundary numbering (West=1, North=2, East=3, South=4)
- Interpolation options: Linear, quadratic, or cubic interpolation for mesh size variation
uv add git+https://github.com/Lab-MAREE/swash-mesh-creationpip install https://github.com/Lab-MAREE/swash-mesh-creationThe package provides a command-line interface with two main commands:
Generate an unstructured mesh from SWASH input files:
# Basic usage
swash-mesh create /path/to/swash/directory
# With custom mesh parameters
swash-mesh create /path/to/swash/directory \
--lc-fine 5.0 \
--lc-coarse 100.0 \
--interpolation 2
# Short alias
sm c /path/to/swash/directory -f 5.0 -c 100.0 -i 2Parameters:
swash_dir: Directory containing SWASH input files--lc-fine/-f: Mesh size at coastline (default: 5.0)--lc-coarse/-c: Mesh size at deepest part (default: 100.0)--interpolation/-i: Interpolation order (1=linear, 2=quadratic, 3=cubic, default: 1)
Apply the generated mesh to SWASH input files:
# Apply mesh to SWASH configuration
swash-mesh apply /path/to/swash/directory
# Short alias
sm a /path/to/swash/directoryThe generated mesh can be visualized with:
gmsh mesh.mshThe SWASH directory must contain:
For mesh creation:
INPUT: SWASH input file with simulation parametersbathymetry.txt: 2D array of bathymetry valuesporosity.txt(optional): Porosity values for breakwater detection
For mesh application:
- All files from mesh creation, plus:
mesh.msh: Node coordinates and connectivity generated bygmshmesh.node: Node coordinates and boundary markers in the triangle formatmesh.ele: Element connectivity in the triangle format
The mesh creation process generates:
mesh.msh: Node coordinates and connectivity generated bygmshmesh.node: Node coordinates and boundary markers in the triangle formatmesh.ele: Element connectivity in the triangle format- Various visualization files (if enabled)
- Bathymetry Analysis: Reads bathymetry data and identifies shoreline boundaries
- Breakwater Detection: Identifies areas with porosity ≠ 1 as breakwaters
- Distance Field Creation: Computes distance fields from shorelines and gauges
- Adaptive Refinement: Applies depth-based mesh sizing with specified interpolation
- Mesh Generation: Uses gmsh to create the unstructured triangular mesh
- Format Conversion: Exports to Triangle format for SWASH compatibility
- Interpolation: Maps bathymetry values to mesh nodes using RBF interpolation
# Install with development dependencies
uv sync --group dev
# Run code quality tools
uv run black . # Format code
uv run isort . # Sort imports
uv run ty check # Type checking
uv run ruff check # LintingCore dependencies:
- gmsh (≥4.14.0): Mesh generation engine
- numpy (≥2.3.1): Numerical operations
- scipy (≥1.16.0): Interpolation algorithms and .mat reading
- typer (≥0.16.0): CLI framework
- plotly (≥6.2.0): Visualization
- tqdm (≥4.67.1): Progress bars
- Adapt this package to use parameters given as function or cli arguments instead of reading the SWASH input file so it's usable with any program
- Refine the detections of breakwaters so it's more robust than simply the proxy of porosity
- Use the shorelines as boundaries in the mesh generation to completely remove land surfaces rather than making the mesh larger at those locations