Home > fvcom_prepro > create_HD_nest_bdy_TYPE3.m

create_HD_nest_bdy_TYPE3

PURPOSE ^

Read in AMM data and interpolate onto the boundary of FVCOM model

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

 Read in AMM data and interpolate onto the boundary of FVCOM model
 subname = 'create_HD_nest_bdy_TYPE3'

 DESCRIPTION:
    READ in the following data:
          - AMM data 
        - FVCOM Grid file (connectivity + nodes)
       - list of nesting nodes created using create_nesting_nodes.m 
    Process data:
       - Interpolate AMM data onto the FVCOM model nested boundary nodes
       
    Write output
       - Write interpolated elevation, speeds, T and S data  to Netcdf  nesting file

 INPUT [keyword pairs]:  
   modify>>>>> 'gridfile'  = fvcom mesh file

 OUTPUT:
   modify>>>>>  Mobj = matlab structure containing mesh data

 EXAMPLE USAGE
    create_wave_bdy

 Author(s):  
    Darren Price (CH2MHILL, Warrington, UK)
    Hakeem Johnson (CH2MHILL, Warrington, UK)

 Revision history
   Nov 2013: Initial version - not in the correct nesting file format
   Jan 2014: Beta version including the correct nesting format
   Mar 2014: HKJ
       - Corrected various bugs in connection with wave direction calcs..
       - Added 2 new functions: get_UxUy_DirFrom.m & get_DirFrom_UxUy.m
   2014:   DMP changed to use for HD nested boundaries
==============================================================================

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 
0002 % Read in AMM data and interpolate onto the boundary of FVCOM model
0003 % subname = 'create_HD_nest_bdy_TYPE3'
0004 %
0005 % DESCRIPTION:
0006 %    READ in the following data:
0007 %          - AMM data
0008 %        - FVCOM Grid file (connectivity + nodes)
0009 %       - list of nesting nodes created using create_nesting_nodes.m
0010 %    Process data:
0011 %       - Interpolate AMM data onto the FVCOM model nested boundary nodes
0012 %
0013 %    Write output
0014 %       - Write interpolated elevation, speeds, T and S data  to Netcdf  nesting file
0015 %
0016 % INPUT [keyword pairs]:
0017 %   modify>>>>> 'gridfile'  = fvcom mesh file
0018 %
0019 % OUTPUT:
0020 %   modify>>>>>  Mobj = matlab structure containing mesh data
0021 %
0022 % EXAMPLE USAGE
0023 %    create_wave_bdy
0024 %
0025 % Author(s):
0026 %    Darren Price (CH2MHILL, Warrington, UK)
0027 %    Hakeem Johnson (CH2MHILL, Warrington, UK)
0028 %
0029 % Revision history
0030 %   Nov 2013: Initial version - not in the correct nesting file format
0031 %   Jan 2014: Beta version including the correct nesting format
0032 %   Mar 2014: HKJ
0033 %       - Corrected various bugs in connection with wave direction calcs..
0034 %       - Added 2 new functions: get_UxUy_DirFrom.m & get_DirFrom_UxUy.m
0035 %   2014:   DMP changed to use for HD nested boundaries
0036 %==============================================================================
0037 
0038 
0039 % clear
0040 %%
0041 %create nesting nodes - commented out here as run seperately during
0042 %debugging
0043 
0044 % create_nesting_nodes;
0045 %%
0046 
0047 clear all;
0048 subname = 'create_HD_nest_bdy';
0049 
0050 global ftbverbose;
0051 if(ftbverbose);
0052   fprintf('\n')
0053   fprintf(['begin : ' subname '\n'])
0054 end
0055 %%
0056 %---------------------------------------------------------
0057 % user specify input data & parameters ...
0058 %---------------------------------------------------------
0059 % work & data folders ...
0060 % directories default values
0061 FVCOM_root = '\\hand-fs-01\maritime\Projects\Scottish Waters\Calcs\Models\WLLS\mesh10\nesting\';
0062 cd(FVCOM_root);
0063 workDir='\\hand-fs-01\maritime\Projects\Scottish Waters\Calcs\Models\WLLS\mesh10\nesting\';
0064 dataDir='\\hand-fs-01\maritime\Projects\Scottish Waters\Calcs\Models\WLLS\mesh10\mesh\';
0065 % AMMDir='C:\Users\iapostol\Documents\Miscellaneous_IGA\ApostolidouIG\Modelling\ScottishWaters\AMM_2011\';
0066 AMMDir='\\uwa2v1th5j\Scottish_waters_mainbackup\Scottish_Waters\Scottish_Waters_AMM_2011\'; %external hard disk
0067 %AMMDir='C:\PROJECTS\WLLS\AMM_2011\';
0068 %AMMDir='X:\Scottish_Waters\Scottish_Waters_AMM_2011\';
0069 disp('hard coded in time shift back 24.5 hours ');
0070 shift=-24.5/24;  %shift found in results for ramWLLS_3
0071 
0072 nsiglay=10;
0073 
0074 basename = 'WLLS_v3smth';
0075 
0076 meshFile=[basename '_grd.dat'];
0077 bathFile=[basename '_dep.dat'];
0078 obcFile=[basename '_node_nest.dat'];
0079 bdyobcFile=[basename '_obc.dat'];
0080 
0081 % output file
0082 HDFile = [basename '2011May_10fshift24p5hours_coldstart_node_nest.nc'];
0083 MyTitle=['WLLS model boundary conditions for mesh' meshFile];
0084 
0085 
0086     % define weighting for type 3 nesting
0087     % in this case we are only using one element width with weights on the
0088     % nodes on boundary and on other nodes on the elements on boundary
0089     weight_node1=0.75; %on boundary
0090     weight_node2=0.25; %inside boundary
0091     weight_elem_val=0.5;
0092     
0093     NEST_TYPE='TYPE3';
0094 
0095 
0096 
0097 % set start & end time
0098 
0099 StartDate = [2011,05,01,1,0,0]; %n.b start and end dates not used all data is written
0100 EndDate   = [2011,05,30,1,0,0];  % changed from: [2009,12,31,21,00,0]
0101 %EndDate   = [2011,05,3,8,0,0];  %---------------------------------------------------------
0102 
0103 %smooth introduction  (similar to iramp, but for velocities and temp/salinity - was required for initial shock due to velocity being introduced  not all models require this though)
0104  smoothtime= 12.0; % number of hours in which to introduce forcing lineary
0105     speed_init=0;  % initial conditions
0106     salinity_init=35.0;
0107     temp_init=10.0;
0108     surfaceElevation_init=0.0;
0109 
0110 
0111 
0112 % set full file names ...
0113 %---------------------------------------------------------
0114 meshFile     = [dataDir meshFile];
0115 bathFile     = [dataDir bathFile];
0116 obcFile      = [workDir obcFile];
0117 bdyobcFile   = [dataDir bdyobcFile];
0118 HDFile     = [workDir HDFile]; 
0119 %%
0120 %---------------------------------------------------------
0121 % Read data into matlab
0122 % 1) grid mesh; 2)boundary nodes; 3) UKMO data files  ...
0123 %---------------------------------------------------------
0124 % get fvcom grid file in as mesh object ...
0125 FV_Mesh = read_fvcom_mesh_lonlat(meshFile);        % ... from matlab toolbox
0126 FV_Mesh.have_bath = true;
0127 FV_Mesh.h = read_fvcom_bath(bathFile);
0128 
0129 % get  nesting nodes and associated lat/lon coord file
0130 FV_OBC = get_HD_nesting_nodes(obcFile);
0131 for i=1:FV_OBC.nVerts
0132     inode = FV_OBC.nnodesID(i);
0133     FV_OBC.lon(i) = FV_Mesh.lon(inode);
0134     FV_OBC.lat(i) = FV_Mesh.lat(inode);
0135     FV_OBC.h(i) = FV_Mesh.h(inode);
0136 end
0137 FV_OBC.x = FV_OBC.lon;   % temp solution
0138 FV_OBC.y = FV_OBC.lat;   % temp solution
0139 figure(1);
0140 scatter(FV_OBC.lon,FV_OBC.lat,5,FV_OBC.h);shading flat;caxis([0 100]);colorbar;
0141 
0142 %---------------------------------------------------------------------
0143 % get elements at boundary & element centres
0144 %---------------------------------------------------------------------
0145 % get elements at boundary
0146 T = FV_Mesh.tri;
0147 X1 = FV_Mesh.lon;
0148 Y1 = FV_Mesh.lat;
0149 P = [X1,Y1];
0150 TR = triangulation(T,P);
0151 vi = FV_OBC.nnodesID;
0152 ti = vertexAttachments(TR,vi);
0153 % arrange data in one row (i.e. several columns); since elements overlap, get unique elements
0154 temp1 = [ti{:}]';
0155 %bdcell = temp1(temp1~=0);
0156 bdcell = unique(temp1,'stable');  
0157 nCells = length(bdcell);
0158 
0159 % get elements at boundary that have nodes in the supplied wave node
0160 % nesting file..
0161 kElem = 0;
0162 for i=1:nCells
0163     ielem = bdcell(i);
0164     v(1) = FV_Mesh.tri(ielem,1);
0165     v(2) = FV_Mesh.tri(ielem,2);
0166     v(3) = FV_Mesh.tri(ielem,3);
0167     chk2 = ismember(v(1:3),vi);
0168     if(sum(chk2) == 3)
0169         kElem = kElem +1;
0170         bdElem(kElem,1) = ielem;
0171     end
0172 end
0173 %triplot(T, X1, Y1);
0174 %hold on;
0175 disp('finished getting elements at boundary');
0176 
0177 %---------------------------------------------------------------------
0178 % get co-ordinates at element centres
0179 %---------------------------------------------------------------------
0180 nElems = length(bdElem);
0181 FV_OBC.nElems  = nElems;
0182 FV_OBC.nElemID = bdElem;
0183 
0184 % get element centres
0185 IC = incenter(TR,bdElem);
0186 lonc = IC(:,1)';        % arrange in one row
0187 latc = IC(:,2)';        % arrange in one row
0188 FV_OBC.lonc = lonc;
0189 FV_OBC.latc = latc;
0190 FV_OBC.xc = lonc;   % temp solution
0191 FV_OBC.yc = latc;   % temp solution
0192 
0193 % get element nodes & arrange in required format
0194 nv = zeros(3,nElems);
0195 for i=1:nElems
0196     ielem = bdElem(i);
0197     nv(1,i) = FV_Mesh.tri(ielem,1);
0198     nv(2,i) = FV_Mesh.tri(ielem,2);
0199     nv(3,i) = FV_Mesh.tri(ielem,3);
0200 end
0201 FV_OBC.nv = nv;
0202 FV_OBC.tri=nv;
0203 disp('finished getting co-ordinates of element centres at boundary');
0204 
0205 
0206 %get number of layers
0207 
0208 FV_OBC.nsiglay=nsiglay;
0209 FV_OBC.nsiglev=nsiglay+1;
0210 inc = 1/real(nsiglay);
0211 siglev = 0:-inc:-1;
0212 siglay = nan(1, nsiglay);
0213 for i=1:nsiglay
0214     siglay(i) = mean(siglev(i:i+1));
0215 end
0216 
0217 FV_OBC.siglay=siglay;
0218 FV_OBC.siglev=siglev;
0219 
0220 %---------------------------------------------------------
0221 % Interpolate AMM data onto mesh
0222 %---------------------------------------------------------
0223 
0224 %call get_AMM to read in elevation, UV and T/S (via call to another
0225 %function) data and store in FV_OBC
0226 FV_OBC = get_AMM_ZUV(FV_OBC,StartDate,EndDate,AMMDir);
0227 
0228 
0229 
0230   
0231 %plot output
0232 
0233 % plot boundary values ??
0234 if(0)
0235     figure(1);
0236     hold on;
0237     for j = 1:100 % time
0238         clf;
0239         scatter(FV_OBC.lon,FV_OBC.lat,5,Hs(j,:)');
0240         pause;%(3);
0241     end    
0242 end
0243   
0244 %%
0245 if(1)    %Due to a shock at the beginning when introducing the nesting from a hot
0246     %start (obtained at the end of a cold start) the first x hours of velocity will be
0247     %gradually built up.  Also ramp up temperature and salinity
0248     %when running from cold you should have a constant temperature and salinity
0249     timeinterval=((FV_OBC.time(2)-FV_OBC.time(1))*24.);
0250     numiters=ceil((smoothtime/timeinterval)+1);
0251     shiftiter=-1*ceil(shift.*24/timeinterval);
0252 %smooth introduction of water level and speed
0253 FV_OBC.daUvel(FV_OBC.daUvel==0.00)=0.00001;
0254 FV_OBC.daVvel(FV_OBC.daVvel==0.00)=0.00001;
0255 FV_OBC.u(FV_OBC.u==0.00)=0.00001;
0256 FV_OBC.v(FV_OBC.v==0.00)=0.00001;
0257 FV_OBC.surfaceElevation(FV_OBC.surfaceElevation==0.00)=0.00001;
0258     for ielem=1:FV_OBC.nElems
0259         
0260         interpua=(speed_init:((FV_OBC.daUvel(ielem,numiters)-speed_init)/(numiters-1)):FV_OBC.daUvel(ielem,numiters));
0261         interpva=(speed_init:((FV_OBC.daVvel(ielem,numiters)-speed_init)/(numiters-1)):FV_OBC.daVvel(ielem,numiters));
0262         
0263         FV_OBC.daUvel(ielem,1+shiftiter:numiters+shiftiter)=interpua;
0264         FV_OBC.daVvel(ielem,1+shiftiter:numiters+shiftiter)=interpva;
0265         
0266         for ilay=1:FV_OBC.nsiglay
0267             interpu=(speed_init:((FV_OBC.u(ielem,ilay,numiters)-speed_init)/(numiters-1)):FV_OBC.u(ielem,ilay,numiters));
0268             interpv=(speed_init:((FV_OBC.v(ielem,ilay,numiters)-speed_init)/(numiters-1)):FV_OBC.v(ielem,ilay,numiters));
0269             
0270             FV_OBC.u(ielem,ilay,1+shiftiter:numiters+shiftiter)=interpu;
0271             FV_OBC.v(ielem,ilay,1+shiftiter:numiters+shiftiter)=interpv;
0272         end
0273     end
0274     
0275     for inode=1:FV_OBC.nVerts
0276         
0277         interpsurfaceElevation=(surfaceElevation_init:((FV_OBC.surfaceElevation(inode,numiters)-surfaceElevation_init)/(numiters-1)):FV_OBC.surfaceElevation(inode,numiters));
0278         FV_OBC.surfaceElevation(inode,1+shiftiter:numiters+shiftiter)=interpsurfaceElevation;
0279         
0280         for ilay=1:FV_OBC.nsiglay
0281             interpsalinity=(salinity_init:((FV_OBC.salinity(inode,ilay,numiters)-salinity_init)/(numiters-1)):FV_OBC.salinity(inode,ilay,numiters));
0282             interptemperature=(temp_init:((FV_OBC.temperature(inode,ilay,numiters)-temp_init)/(numiters-1)):FV_OBC.temperature(inode,ilay,numiters));
0283             
0284             FV_OBC.salinity(inode,ilay,1+shiftiter:numiters+shiftiter)=interpsalinity;
0285             FV_OBC.temperature(inode,ilay,1+shiftiter:numiters+shiftiter)=interptemperature;
0286             
0287                         
0288         end
0289     end
0290 
0291 end
0292 
0293 
0294 figure(150);
0295 plot(squeeze(FV_OBC.surfaceElevation(23,:)));
0296 figure(151);
0297 plot(squeeze(FV_OBC.salinity(23,1,:)));
0298 figure(152);
0299 hold on;
0300 plot(squeeze(FV_OBC.daUvel(23,:)),'k-');
0301 plot(squeeze(FV_OBC.daVvel(23,:)),'r-');
0302 %%
0303 %weighting for type 3 nesting
0304 OBCnodes= get_HD_OBC(bdyobcFile);
0305 nodes_on_bdy=OBCnodes.nnodesID;
0306 
0307 [I]=ismember(FV_OBC.nnodesID,nodes_on_bdy); % nodes on boundary with weight 1
0308 [Jval, J]=setdiff(FV_OBC.nnodesID,nodes_on_bdy); %need an array of nodes not on bdy for weight 2
0309 weight_node_val=ones(FV_OBC.nVerts,1);
0310 weight_elem_val=weight_elem_val.*ones(FV_OBC.nElems,1);% element weight
0311 
0312 weight_node_val(I)=weight_node_val(I).*weight_node1;
0313 weight_node_val(J)=weight_node_val(J).*weight_node2;
0314 %now repeat matrices for time dimension
0315 FV_OBC.weight_node_val=repmat(weight_node_val,1,numel(FV_OBC.time));
0316 FV_OBC.weight_elem_val=repmat(weight_elem_val,1,numel(FV_OBC.time));
0317 
0318 
0319 
0320 FV_OBC.NEST_TYPE=NEST_TYPE;
0321 
0322 
0323   
0324 % now output boundary data to the FVCOM netcdf format
0325   
0326 write_nesting_bdy_file(FV_OBC, FV_OBC.time-datenum(1858,11,17,0,0,0)+shift, HDFile, MyTitle);
0327 
0328 disp('net cdf wave file written');

Generated on Wed 10-Aug-2016 16:44:39 by m2html © 2005