


Generate a semistructured mesh
[Mobj] = gen_semistructured_mesh(varargin)
DESCRIPTION:
Read SMS 2dm file and bathymetry file
Store in a matlab mesh object
INPUT
lx = length of the domain in meters in the x-direction
ly = length of the domain in meters in the y-direction
nx = number of edges along the x-direction
ny = number of edges in the y-direction
cornermod = modify edges at the corners so that one cell does not have an
edge on two sides (true,false)
OUTPUT:
Mobj = matlab structure containing mesh data
EXAMPLE USAGE
Mobj = gen_semistructured_mesh(10000.,1000.,500,50)
Author(s):
Geoff Cowles (University of Massachusetts Dartmouth)
Revision history
==============================================================================

0001 function [Mobj] = gen_semistructured_mesh(lx,ly,nx,ny,cornermod) 0002 0003 % Generate a semistructured mesh 0004 % 0005 % [Mobj] = gen_semistructured_mesh(varargin) 0006 % 0007 % DESCRIPTION: 0008 % Read SMS 2dm file and bathymetry file 0009 % Store in a matlab mesh object 0010 % 0011 % INPUT 0012 % lx = length of the domain in meters in the x-direction 0013 % ly = length of the domain in meters in the y-direction 0014 % nx = number of edges along the x-direction 0015 % ny = number of edges in the y-direction 0016 % cornermod = modify edges at the corners so that one cell does not have an 0017 % edge on two sides (true,false) 0018 % 0019 % OUTPUT: 0020 % Mobj = matlab structure containing mesh data 0021 % 0022 % EXAMPLE USAGE 0023 % Mobj = gen_semistructured_mesh(10000.,1000.,500,50) 0024 % 0025 % Author(s): 0026 % Geoff Cowles (University of Massachusetts Dartmouth) 0027 % 0028 % Revision history 0029 % 0030 %============================================================================== 0031 0032 subname = 'gen_semistructured_mesh'; 0033 fprintf('\n') 0034 fprintf(['begin : ' subname '\n']) 0035 0036 userproject = false; 0037 0038 %------------------------------------------------------------------------------ 0039 % Create a blank mesh object 0040 %------------------------------------------------------------------------------ 0041 Mobj = make_blank_mesh(); 0042 coordinate = 'cartesian'; 0043 0044 %------------------------------------------------------------------------------ 0045 % set grid resolution 0046 %------------------------------------------------------------------------------ 0047 dx = lx/real(nx); 0048 dy = ly/real(ny); 0049 fprintf('making a semistructured mesh of dimensions: %f X %f\n',lx,ly) 0050 fprintf('resolution in x %f and y %f\n',dx,dy); 0051 0052 0053 %------------------------------------------------------------------------------ 0054 % build the grid 0055 %------------------------------------------------------------------------------ 0056 0057 il = nx+1; 0058 jl = ny+1; 0059 0060 % set dimensions 0061 nElems = 2*nx*ny; 0062 nVerts = il*jl; 0063 0064 % allocate memory to hold mesh and auxiliary structures 0065 tri = zeros(nElems,3); 0066 x = zeros(nVerts,1); 0067 y = zeros(nVerts,1); 0068 h = zeros(nVerts,1); 0069 lon = zeros(nVerts,1); 0070 lat = zeros(nVerts,1); 0071 ts = zeros(nVerts,1); 0072 0073 0074 % build the mesh points 0075 nn = 0; 0076 for i=1:il 0077 for j=1:jl 0078 nn = nn + 1; 0079 x(nn) = (i-1)*dx; 0080 y(nn) = (j-1)*dy; 0081 end; 0082 end; 0083 0084 % set the connectivity 0085 nn = 1; 0086 for i=1:nx 0087 for j=1:ny 0088 n2 = nn + 1; 0089 tri(nn,1) = j + (i-1)*jl; 0090 tri(nn,2) = j + i*jl; 0091 tri(nn,3) = j+1 + (i-1)*jl; 0092 tri(n2,1) = j + i*jl; 0093 tri(n2,2) = j+1 + i*jl; 0094 tri(n2,3) = j+1 + (i-1)*jl; 0095 nn = nn + 2; 0096 end; 0097 end; 0098 0099 0100 % modify the connectivity on the corners to deal with the constraint that an element cannot 0101 % have both an open and a solid boundary 0102 if(cornermod) 0103 tri(1,1) = 1; 0104 tri(1,2) = jl+2; 0105 tri(1,3) = 2; 0106 tri(2,1) = 1; 0107 tri(2,2) = jl+1; 0108 tri(2,3) = jl+2; 0109 0110 tri(2*nx*ny-1,1) = il*jl-jl-1; 0111 tri(2*nx*ny-1,2) = il*jl-1; 0112 tri(2*nx*ny-1,3) = il*jl; 0113 tri(2*nx*ny ,1) = il*jl-jl-1; 0114 tri(2*nx*ny ,2) = il*jl; 0115 tri(2*nx*ny ,3) = il*jl-jl; 0116 end; 0117 0118 0119 %------------------------------------------------------------------------------ 0120 % Transfer to Mesh structure 0121 %------------------------------------------------------------------------------ 0122 0123 Mobj.nVerts = nVerts; 0124 Mobj.nElems = nElems; 0125 Mobj.nativeCoords = coordinate; 0126 0127 Mobj.have_lonlat = false; 0128 Mobj.have_xy = true; 0129 Mobj.have_bath = false; 0130 0131 Mobj.x = x; 0132 Mobj.y = y; 0133 Mobj.ts = ts; 0134 Mobj.lon = lon; 0135 Mobj.lat = lat; 0136 Mobj.h = h; 0137 Mobj.tri = tri; 0138 0139 0140 fprintf(['end : ' subname '\n']) 0141 0142