


create a list of the nesting boundary nodes
subname = 'create_nesting_nodes'
DESCRIPTION:
READ in the following data:
- FVCOM OBC file
- FVCOM Grid file (connectivity + nodes)
Process data:
- Extract all nodes belonging to elements at the boundary
Write output
- Write Node nesting file
INPUT :
FVCOM OBC file and Grid file
OUTPUT:
Node nesting file
EXAMPLE USAGE
create_nesting_nodes
Author(s):
Hakeem Johnson (CH2MHILL, Warrington, UK)
Darren Price(CH2MHILL, Warrington, UK)
Revision history
Jan 2014: Beta version including the correct nesting format
==============================================================================

0001 0002 % create a list of the nesting boundary nodes 0003 % subname = 'create_nesting_nodes' 0004 % 0005 % DESCRIPTION: 0006 % READ in the following data: 0007 % - FVCOM OBC file 0008 % - FVCOM Grid file (connectivity + nodes) 0009 % Process data: 0010 % - Extract all nodes belonging to elements at the boundary 0011 % Write output 0012 % - Write Node nesting file 0013 % 0014 % INPUT : 0015 % FVCOM OBC file and Grid file 0016 % 0017 % OUTPUT: 0018 % Node nesting file 0019 % 0020 % EXAMPLE USAGE 0021 % create_nesting_nodes 0022 % 0023 % Author(s): 0024 % Hakeem Johnson (CH2MHILL, Warrington, UK) 0025 % Darren Price(CH2MHILL, Warrington, UK) 0026 % 0027 % Revision history 0028 % Jan 2014: Beta version including the correct nesting format 0029 %============================================================================== 0030 0031 clear; 0032 subname = 'create_nesting_nodes'; 0033 0034 global ftbverbose; 0035 if(ftbverbose); 0036 fprintf('\n') 0037 fprintf(['begin : ' subname '\n']) 0038 end 0039 0040 %--------------------------------------------------------- 0041 % user specify input data & parameters ... 0042 %--------------------------------------------------------- 0043 % work & data folders ... 0044 workDir='\\hand-fs-01\maritime\Projects\Scottish Waters\Calcs\Models\WLLS\mesh10\nesting\'; 0045 dataDir='\\hand-fs-01\maritime\Projects\Scottish Waters\Calcs\Models\WLLS\mesh10\mesh\'; 0046 basename = 'WLLS_v3smth'; 0047 % input file names 0048 meshFile=[basename '_grd.dat']; 0049 obcFile=[basename '_obc.dat']; 0050 0051 % output file 0052 NestNodesFile = [basename '_node_nest.dat']; 0053 0054 %--------------------------------------------------------- 0055 % set full file names ... 0056 %--------------------------------------------------------- 0057 meshFile = [dataDir meshFile]; 0058 obcFile = [dataDir obcFile]; 0059 NestNodesFile = [workDir NestNodesFile]; 0060 checkfile(meshFile); 0061 checkfile(obcFile); 0062 0063 %--------------------------------------------------------- 0064 % Read data into matlab 0065 % 1) grid mesh; 2)boundary nodes; ... 0066 %--------------------------------------------------------- 0067 % get fvcom grid file in as mesh object ... 0068 FV_Mesh = read_fvcom_mesh_lonlat(meshFile); % ... from matlab toolbox 0069 0070 % get wave nesting nodes and associated lat/lon coord file 0071 FV_OBC = get_HD_OBC(obcFile); 0072 0073 %--------------------------------------------------------------------- 0074 % get elements at boundary & element centres 0075 %--------------------------------------------------------------------- 0076 % get elements at boundary 0077 T = FV_Mesh.tri; 0078 X1 = FV_Mesh.lon; 0079 Y1 = FV_Mesh.lat; 0080 P = [X1,Y1]; 0081 TR = triangulation(T,P); 0082 vi = FV_OBC.nnodesID; 0083 ti = vertexAttachments(TR,vi); 0084 % arrange as column data; since elements overlap, get unique elements 0085 temp1 = [ti{:}]'; 0086 % bdcell = unique(temp1,'stable'); 0087 bdcell = unique(temp1); 0088 nCells = numel(bdcell); 0089 0090 nElems = nCells; 0091 bdElem = bdcell; 0092 0093 % get element nodes & arrange in required format 0094 nv= zeros(3*nElems,1); 0095 k = 1; 0096 for i=1:nElems 0097 ielem = bdElem(i); 0098 nv(k) = FV_Mesh.tri(ielem,1); 0099 nv(k+1) = FV_Mesh.tri(ielem,2); 0100 nv(k+2) = FV_Mesh.tri(ielem,3); 0101 k = k+3; 0102 end 0103 0104 % I don't think preserving the order is the problem - remove next line 0105 % nestNodeID= unique(nv,'stable'); 0106 nestNodeID= unique(nv); 0107 nestNodes = numel(nestNodeID); 0108 out = ones(nestNodes,3); 0109 for i=1:nestNodes 0110 out(i,1) = i; 0111 out(i,2) = nestNodeID(i); 0112 end 0113 0114 %------------------------------------------------------------------------------ 0115 % Dump the file 0116 %------------------------------------------------------------------------------ 0117 0118 filename = NestNodesFile; 0119 if(ftbverbose); fprintf('writing FVCOM obc %s\n',filename); end; 0120 0121 %------------------------------------------------------------------------------ 0122 % Check output file 0123 %------------------------------------------------------------------------------ 0124 fid = fopen(filename,'w'); 0125 fprintf(fid,'Nest_Node Number = %12d\n',nestNodes); 0126 fprintf(fid,'No. Node_ID Node_Type\n'); 0127 for i=1:nestNodes 0128 fprintf(fid,'%12d %12d %12d\n',out(i,:)); 0129 end 0130 0131 fclose(fid); 0132 0133 disp('finished creating nesting file');