Detailed meshing guide

Compilation of different meshing projects

Creating a coarse mesh for the Gulf of Mexico + Atlantic Ocean

Script for this example: mesh_test.m

Requirements

Steps

  1. Set the parameters. These control how fine the mesh will be. Note that "resolution" misleadingly refers to the element size, so the higher the value, the less resolved the mesh will be. 

    name = 'coarse_1dt';
    bbox = [-98 -60;		% lon_min lon_max
            7.9 45.86]; 		% lat_min lat_max
    min_el    = 1e3;  		% minimum resolution in meters.
    max_el    = 15e3; 		% maximum resolution in meters. 
    max_el_ns = 5e3;        % maximum resolution nearshore in meters.
    grade     = 0.2; 		% mesh grade in decimal percent.
    R         = 2;    		% number of elements to resolve feature width.
    slope = 20;
  2. Create the geo and edge objects. I usually use DT = 1 or 2, but in practice you might need to use a smaller timestep. 

    coastline = 'GSHHS_f_L1';
    dem = 'GEBCO_2021.nc';
    
    gdat = geodata('shp',coastline, ...
                    'dem',dem, ...
                    'bbox',bbox, ...
                    'h0',min_el);
    %% STEP 3: create an edge function class
    fh = edgefx('geodata',gdat,...
                'fs',R, ...
                'max_el',max_el, ...
                'g',grade, ...
                'dt',1);
  3. Triangulate the mesh object and plot it. In this example we use automatic boundary generation. In other cases we will have to manually select boundary segments to designate (see other examples).

    % build the mesh...
    mshopts = meshgen('ef',fh,'bou',gdat,'plot_on',1,'nscreen',5,'proj','equi');
    mshopts = mshopts.build; 
    
    % Get out the msh class and put on nodestrings
    coarseMesh = mshopts.grd;
    coarseMesh = make_bc(coarseMesh,'auto',gdat); % make the boundary conditions
    plot(coarseMesh,'type','bd','proj','equi');
  4. Create bathymetry data by interpolating the DEM. WARNING: if the mesh is large then the system can run out of memory and MATLAB will crash, or worse, Linux will be unresponsive due to the way it handles out-of-memory. 

    coarseMesh = interp(coarseMesh, dem);
  5. Create fort.15 with tidal BC and save it to disk, along with the mesh (fort.14).

    coarseMesh = Make_f15(coarseMesh, '2012-08-01 00:00', '2012-11-31 00:00', 2, 'const', 'major8','tidal_database','h_tpxo9.v1.nc');
    
    %% Save to fort.14 and fort.15
    write(coarseMesh, name, 'f14');
    write(coarseMesh, name, 'f15');

Adding levees to a mesh