Utilities for pre-processing (building computational/input grids, writing bathymetry) and post-processing (quick figures & movies) around (SWASH) runs. The focus is small, composable MATLAB functions you can drop into your own workflow.
Status: early-stage, but already usable for 2D regular grids (rectilinear or rotated). Expect breaking changes while the API stabilizes.
bathy_extend.m– extend a bathymetric domain by mirroring edge profiles (adds ~25% per side) and plot original vs extended fields.bathy_preprocessing.m– download bathy bathy data, generate SWASH input bathy txt file.make_swash_cgrid.m– writeCGRID REGULAR ...line for the SWASH computational grid fromOut.x/y/z.make_swash_inpgrid.m– writeINPGRID BOTTOM REGULAR ...line (input grid for bottom data).write_swash_bathy_txt.m– write ASCII bathymetry in SWASHREADINP BOTTOMlayout (idla=1).
figHs.m– quick-look plot of significant wave height.watlevMovie.m– movie visualisation of water level output.postproc_main.m– example function for post-processing.
See each function’s header for arguments, defaults, and notes.
These are the current defaults used by helpers here:
- Grid regularity: assumes a regular mesh (uniform steps). Curvilinear support is a future item.
- Angles:
alpc=0(x-axis aligned with global x) unless you pass a value. - Input grid ≡ computational grid by default (
make_swash_inpgrid). - Bathymetry sign: files are written as
Out.zdirectly (often negative), and the SWASH side usesfac=-1inREADINP BOTTOM. - ASCII layout:
idla=1(= row-wise, start at upper-left, rows written top→down, left→right). - Precision: 3 decimals for bathy txt file, 0 for .sws lines
- No headers in the bathy text file (
nhedf=0).
% xIn, yIn, zIn are ny-by-nx (meshgrid-style). Toggle selects inward edge.
[Out, fig1, fig2] = bathy_extend(xIn, yIn, zIn, toggle);% CGRID (computational grid)
optsC = struct('precision',0, 'repeat','none', 'alpc',0);
[cgrid_line, cgrid_info] = make_swash_cgrid(Out, optsC);
% INPGRID BOTTOM (input grid for bottom data) — identical to CGRID here
optsI = struct('precision',0, 'alpinp',0);
[inpgrid_line, inpgrid_info] = make_swash_inpgrid(Out, optsI);
fprintf('%s\n%s\n', cgrid_line, inpgrid_line);% idla=1, nhedf=0, precision=3
[info, readinp_line] = write_swash_bathy_txt(Out, 'bathy.txt', struct('precision',0));
fprintf('%s\n', readinp_line);
% -> READINP BOTTOM -1 'bathy.txt' 1 0 FREECGRID REGULAR ...
INPGRID BOTTOM REGULAR ...
READINP BOTTOM -1 'bathy.txt' 1 0 FREE
% See headers for expected inputs; adapt to your file layout
figHs(...);
watlevMovie(...);- Units: helpers assume meters (m) and degrees (°) for angles.
- Rotation: Do not rotate your bathy grid -- it is easier to rotate your input spectra.
- NaNs:
write_swash_bathy_txtrejects NaNs by default. Clean them or add an EXCEPTION in SWASH (future helper may expose this). - Mesh counts: remember SWASH uses meshes not 'points' i.e. (
points-1) formx*/my*.
PRs welcome! Please open an issue to discuss changes, especially interface/IO formats.