Home > swan_scripts > calc_fetch.m

calc_fetch

PURPOSE ^

estimate wave fetch

SYNOPSIS ^

function [dir,fetch] = calc_fetch(nodefile,botfile,xp,yp,zadd);

DESCRIPTION ^

 estimate wave fetch 

 function [dir,fetch] = calc_fetch(nodefile,botfile,xp,yp,zadd);

 DESCRIPTION:
   given a SWAN mesh and bathymetry and observation point, estimate fetch for  
   range of wind directions

 INPUT 
   nodefile = SWAN unstructured node file
   botfile  = SWAN unstructure bathymetry file (positive down)
   xp       = observation point x-coordinate
   yp       = observation point y-coordinate
   zadd     = [optional] add free surface height to account for tides (m)

 OUTPUT:
    dir = direction of wind in Cartesian coordinates
    fetch = fetch for that direction in (m)

    Note:  if dir=45, this will provide the fetch for a SW wind

 EXAMPLE USAGE
   [dir,fetch] = calc_fetch('skg4.3.node','skg4.3.bot',5.3870e5,5.3506e6,-2);

 Author(s):  
    Geoff Cowles (University of Massachusetts Dartmouth)

 Revision history
   
==============================================================================

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [dir,fetch] = calc_fetch(nodefile,botfile,xp,yp,zadd);
0002 % estimate wave fetch
0003 %
0004 % function [dir,fetch] = calc_fetch(nodefile,botfile,xp,yp,zadd);
0005 %
0006 % DESCRIPTION:
0007 %   given a SWAN mesh and bathymetry and observation point, estimate fetch for
0008 %   range of wind directions
0009 %
0010 % INPUT
0011 %   nodefile = SWAN unstructured node file
0012 %   botfile  = SWAN unstructure bathymetry file (positive down)
0013 %   xp       = observation point x-coordinate
0014 %   yp       = observation point y-coordinate
0015 %   zadd     = [optional] add free surface height to account for tides (m)
0016 %
0017 % OUTPUT:
0018 %    dir = direction of wind in Cartesian coordinates
0019 %    fetch = fetch for that direction in (m)
0020 %
0021 %    Note:  if dir=45, this will provide the fetch for a SW wind
0022 %
0023 % EXAMPLE USAGE
0024 %   [dir,fetch] = calc_fetch('skg4.3.node','skg4.3.bot',5.3870e5,5.3506e6,-2);
0025 %
0026 % Author(s):
0027 %    Geoff Cowles (University of Massachusetts Dartmouth)
0028 %
0029 % Revision history
0030 %
0031 %==============================================================================
0032 
0033 %clear all; close all;
0034 %nodefile = 'skg4.3.node';
0035 %elefile = 'skg4.3.ele';
0036 %botfile = 'skg4.3.bot';
0037 %xp = 5.3870e+05;
0038 %yp = 5.3506e+06;
0039 %zeta_max = 2.5;
0040 %zeta_min = 2.5;
0041 
0042 % set number of theta-bins
0043 nbins = 32; 
0044 
0045 delta_zeta = 0.0;
0046 if(exist('zadd'))
0047   delta_zeta = zadd;
0048 end;
0049 
0050 % warning - program is terribly unrobust
0051 % to improve robustness, search along rays until the point is found
0052 % inside a boundary or dry triangle
0053 
0054 % read the node file
0055 [cnt,x,y,nmark] = textread(nodefile,'%d %f %f %d\n','headerlines',1);
0056 
0057 % read the depth file
0058 [h] = textread(botfile,'%f\n','headerlines',0);
0059 
0060 % add/subtract free surface amplitude
0061 h = h + delta_zeta;
0062 
0063 % mark all nodes that are solid wall, open boundary, or dry
0064 drynodes = find(h < 0);
0065 nmark(drynodes) = 3;
0066 solidpts = find(nmark > 0);
0067 xdry = x(solidpts);
0068 ydry = y(solidpts);
0069 
0070 % distance vector from all solidpts to point of interest
0071 dist = sqrt(   (xdry-xp).^2 + (ydry-yp).^2);
0072 ang  = atan2( (ydry-yp), (xdry-xp) );
0073 
0074 
0075 % find the wave direction corresponding to the angle between the boundary point and POI
0076 plot(dist.*cos(ang),dist.*sin(ang),'r+'); hold on;
0077 
0078 % sort the points in order of increasing angle
0079 ang = ang + pi; %convert from obs-shore to shore-obs angle
0080 
0081 % for each bin find the minimum distance
0082 dtheta = 2*pi/nbins;
0083 theta_bound = 0-dtheta/2:dtheta:2*pi+dtheta/2;
0084 theta       = 0:dtheta:2*pi;
0085 mind        = zeros(numel(theta),1);
0086 for i=1:numel(theta)
0087   pts = find( (theta_bound(i) < ang) & (ang <= theta_bound(i+1)));
0088   if(numel(pts) > 0)
0089     mind(i) = min(dist(pts)); 
0090   end;
0091 end;
0092 
0093 % make sure there are no zeros
0094 for i=2:numel(theta)-1
0095   if(mind(i) == 0.); mind(i) = max(mind(i-1),mind(i+1)); end;
0096 end;
0097 if(mind(1) == 0.); mind(1) = mind(2); end;
0098 if(mind(end) == 0.); mind(end) = mind(end-1); end;
0099 
0100 % smooth to account for diffraction
0101 for i=2:numel(theta)-1
0102   mind(i) = .5*(mind(i) + max(mind(i-1),mind(i+1))); 
0103 end;
0104 mind(1) = .5*(mind(1) + mind(2));
0105 mind(end) = .5*(mind(end) + mind(end-1));
0106 
0107 % force periodicity
0108 mind(end) = mind(1);
0109   
0110 plot(0,0,'g+','MarkerSize',5); hold on;
0111 plot(mind.*cos(theta+pi)',mind.*sin(theta+pi)');
0112 
0113 % plot a polar
0114 figure
0115 plot(theta*180/pi,mind);
0116 xlabel('wind direction (Cartesian sense)');
0117 ylabel('fetch (m)');
0118  
0119 % set return values
0120 dir = theta*180/pi;
0121 fetch = mind;
0122 
0123

Generated on Wed 20-Feb-2019 16:06:01 by m2html © 2005