Home > swan_scripts > ideal_swan_obc.m

ideal_swan_obc

PURPOSE ^

Generate idealized SWAN boundary forcing

SYNOPSIS ^

function ideal_swan_obc(SwanNodeFile,time,hs,tp,dir,inc,DirectSpread);

DESCRIPTION ^

 Generate idealized SWAN boundary forcing

 function  ideal_swan_obc(SwanNodeFile,time,hs,tp,dir,inc,DirectSpread);

 DESCRIPTION:
    interpolate Hs,Tp,Dir from WW3 from time series to unstructured SWAN forcing file
    this is an example file and will need to be modified for specific cases
    Note that for the unstructured SWAN you can specify separate TPAR files
    containing time series of hs,tp,dir for each node.  Also note that the nodes
    are not necessarily nodes of the SWAN mesh.  They are specified in arclength
    of the grid units from the first open boundary node (arclength 0).  SWAN
    assembles a boundary segment by piecing together the nodes marked as boundary 
    nodes in the node file (mark = 2).  This assumes somehow that the nodes are ordered
    sequentially along the boundary arc which is in fact a major assumption.

    Sample OBC section of a swan input file for the GoM domain is as follows where
    15 points are used to specify the boundary forcing while the domain in fact has 
    60 boundary points.  SWAN interpolates as necessary to force all the boundary nodes.
    The large numbers are the arclengths in meters

 BOUNDSPEC SIDE 2 CLOCKWISE VARIABLE FILE &
         0.00 'obc1.bnd' 1 &
     52704.26 'obc2.bnd' 1 &
    131926.06 'obc3.bnd' 1 &
    255117.10 'obc4.bnd' 1 &
    390381.71 'obc5.bnd' 1 &
    559989.50 'obc6.bnd' 1 &
    740759.98 'obc7.bnd' 1 &
    924330.66 'obc8.bnd' 1 &
   1104489.93 'obc9.bnd' 1 &
   1295381.43 'obc10.bnd' 1 &
   1480466.74 'obc11.bnd' 1 &
   1641071.70 'obc12.bnd' 1 &
   1750424.20 'obc13.bnd' 1 &
   1828825.67 'obc14.bnd' 1 &
   1951072.38 'obc15.bnd' 1

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function ideal_swan_obc(SwanNodeFile,time,hs,tp,dir,inc,DirectSpread);
0002     
0003 % Generate idealized SWAN boundary forcing
0004 %
0005 % function  ideal_swan_obc(SwanNodeFile,time,hs,tp,dir,inc,DirectSpread);
0006 %
0007 % DESCRIPTION:
0008 %    interpolate Hs,Tp,Dir from WW3 from time series to unstructured SWAN forcing file
0009 %    this is an example file and will need to be modified for specific cases
0010 %    Note that for the unstructured SWAN you can specify separate TPAR files
0011 %    containing time series of hs,tp,dir for each node.  Also note that the nodes
0012 %    are not necessarily nodes of the SWAN mesh.  They are specified in arclength
0013 %    of the grid units from the first open boundary node (arclength 0).  SWAN
0014 %    assembles a boundary segment by piecing together the nodes marked as boundary
0015 %    nodes in the node file (mark = 2).  This assumes somehow that the nodes are ordered
0016 %    sequentially along the boundary arc which is in fact a major assumption.
0017 %
0018 %    Sample OBC section of a swan input file for the GoM domain is as follows where
0019 %    15 points are used to specify the boundary forcing while the domain in fact has
0020 %    60 boundary points.  SWAN interpolates as necessary to force all the boundary nodes.
0021 %    The large numbers are the arclengths in meters
0022 %
0023 % BOUNDSPEC SIDE 2 CLOCKWISE VARIABLE FILE &
0024 %         0.00 'obc1.bnd' 1 &
0025 %     52704.26 'obc2.bnd' 1 &
0026 %    131926.06 'obc3.bnd' 1 &
0027 %    255117.10 'obc4.bnd' 1 &
0028 %    390381.71 'obc5.bnd' 1 &
0029 %    559989.50 'obc6.bnd' 1 &
0030 %    740759.98 'obc7.bnd' 1 &
0031 %    924330.66 'obc8.bnd' 1 &
0032 %   1104489.93 'obc9.bnd' 1 &
0033 %   1295381.43 'obc10.bnd' 1 &
0034 %   1480466.74 'obc11.bnd' 1 &
0035 %   1641071.70 'obc12.bnd' 1 &
0036 %   1750424.20 'obc13.bnd' 1 &
0037 %   1828825.67 'obc14.bnd' 1 &
0038 %   1951072.38 'obc15.bnd' 1
0039 
0040 % INPUT
0041 %   SwanNodeFile:   Swan node file (e.g. tst.node)
0042 %   time:           time stamp of time series in modified Julian day
0043 %   hs:             time series for significant wave height
0044 %   tp:             time series for peak period
0045 %   dir:            time series for wave direction
0046 %   inc:            dump TPAR obc forcing file every inc boundary points
0047 %   DirectSpread    directional spreading of incoming waves in degrees
0048 %
0049 % OUTPUT:
0050 %   SWAN open boundary TPAR files obcXX.bnd
0051 %   cntrllist.txt:  list of open boundary arclengths and obc file names
0052 %                   this can essentially be pasted into the swan input file
0053 %
0054 % Author(s):
0055 %    Geoff Cowles (University of Massachusetts Dartmouth)
0056 %
0057 % Revision history
0058 %
0059 %==============================================================================
0060 
0061 
0062 % read the swan node file and grab boundary nodes
0063 [num,x,y,mark] = textread(SwanNodeFile,'%d %f %f %d\n','headerlines',1);
0064 obc_nodes = find(mark==2);
0065 nobc = prod(size(obc_nodes));
0066 xtmp = x(obc_nodes);
0067 ytmp = y(obc_nodes);
0068 arc = zeros(nobc,1); 
0069 for i=2:nobc
0070   arc(i) = arc(i-1) + sqrt( (xtmp(i)-xtmp(i-1))^2 + (ytmp(i)-ytmp(i-1))^2); 
0071 end;  
0072 
0073 % shift to discrete locations
0074 pts = 1:inc:nobc;
0075 pts(end) = nobc;
0076 xobc = xtmp(pts); 
0077 yobc = ytmp(pts); 
0078 aobc = arc(pts); 
0079 nTPAR = prod(size(xobc));
0080 
0081 
0082 %---------------------------------------------------------
0083 % set TPAR files for each open boundary forcing point
0084 %---------------------------------------------------------
0085 
0086 
0087 % preallocate arrays
0088 nTimes = prod(size(time));
0089 
0090 %dump to separate swan forcing files
0091 for i=1:nTPAR
0092   fname = ['obc' num2str(i) '.bnd'];
0093   fid = fopen(fname,'w');
0094   fid = fprintf(fid,'TPAR\n');
0095   for j=1:nTimes
0096     [year,month,day,hour,mint,sec] = mjulian2greg(time(j));
0097     if(day < 10)
0098       daystr = ['0' int2str(day)];
0099     else
0100       daystr = int2str(day);
0101     end;
0102     if(month < 10)
0103       monthstr = ['0' int2str(month)];
0104     else
0105       monthstr = int2str(month);
0106     end;
0107     if(hour < 10)
0108       hourstr = ['0' int2str(hour)];
0109     else
0110       hourstr = int2str(hour);
0111     end;
0112     date = [' ' int2str(year) monthstr daystr '.' hourstr '00'];
0113     fprintf(fid,'%s %f %f %f %f\n',date,hs(j),tp(j),dir(j),DirectSpread);
0114   end;
0115   fclose(fid);
0116 end;
0117 
0118  % dump the main swan control file list
0119  fname = 'cntrllist.txt';
0120  fid = fopen(fname,'w');
0121  for i=1:nTPAR
0122    fname = [' ''obc' num2str(i) '.bnd'' '];
0123    fprintf(fid,'%12.2f %s %d %s\n',aobc(i),fname,1,'&');
0124  end;
0125

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