Utilities and examples for generating 2D Gmsh meshes, including adaptive coastal meshes suitable for FVCOM-style workflows.
basic_mesh_example.py: builds a simple rectangular mesh and writesrectangle_mesh.msh.adaptive_mesh_example.py: builds a rectangle with spatially varying target element size and writesadaptive_mesh.msh.coastal_bathy_adaptive_mesh.py: builds a coastal ocean mesh with refinement near shoreline and shallow bathymetry.load_mesh.py: loads a.mshfile, reconstructs coordinates, and plots the mesh over a basemap.
- Python 3.10+
- Internet access for first-time coastal data downloads
- Gmsh desktop application (https://gmsh.info/) if you want to open meshes in the Gmsh GUI interface
Install Python dependencies:
python -m pip install -r requirements.txtRun the simple examples:
python basic_mesh_example.py
python adaptive_mesh_example.pyThese produce:
rectangle_mesh.mshadaptive_mesh.msh
Run interactively and enter coordinates at prompts (press Enter after each value):
python coastal_bathy_adaptive_mesh.pyPrompt sequence:
Enter lat-min:Enter lat-max:Enter lon-min:Enter lon-max:
You can also pass coordinates directly with flags:
python coastal_bathy_adaptive_mesh.py --lat-min 44.8 --lat-max 52.0 --lon-min -129.0 --lon-max -121.0Optional arguments:
--output-mesh: output mesh filename (default:coastal_adaptive_mesh.msh)--cache-dir: cache directory for downloaded data (default:mesh_cache)--show-gui: open the Gmsh GUI after mesh generation
Outputs:
coastal_adaptive_mesh.mshcoastal_adaptive_mesh.json(projection sidecar used for back-projection in plotting)- Download/cache files under
mesh_cache/
By default, load_mesh.py reads coastal_adaptive_mesh.msh and saves a map image:
python load_mesh.pyOutput:
mesh_map.png
- The first coastal run downloads global bathymetry and Natural Earth land polygons; later runs reuse cached files.
- If plotting a projected coastal mesh, keep the
.jsonsidecar next to the.mshfile so coordinates can be converted back to lon/lat.
- Parts of the bathymetry/coastal mesh workflow in this project were adapted from: https://github.com/emmashie/model-agent/blob/main/agents/llm_grid_agent.py
- Please refer to the upstream repository for original context, updates, and licensing details.