


Write FVCOM format sponge layer file
function write_FVCOM_sponge(Mobj,filename)
DESCRIPTION:
Generate an ascii FVCOM 3.x format sponge file from Mesh object
INPUT
Mobj = Mesh object with fields:
- sponge_fac - the sponge factor.
- sponge_rad - the sponge radius.
- nSponge - the number of sponge boundary (see
add_sponge_nodes_list).
- nSponge - the node IDs of the sponge nodes.
filename = FVCOM sponge file name
OUTPUT:
FVCOM sponge file: filename
EXAMPLE USAGE
write_FVCOM_sponge(Mobj,'tst_spg.dat')
Author(s):
Geoff Cowles (University of Massachusetts Dartmouth)
Karen Thurston (National Oceanography Centre, Liverpool)
Rory O'Hara Murray (Marine Scotland Science)
Revision history
2013-01-18 Added support for variable sponge radius.
2014-10-28 Added support for variable sponge damping coefficient, by
assuming the size of the sponge_fac and sponge_rad arrays are equal the
number of sponge nodes by default.
2016-04-20 Reconcile the original behaviour (single value at each open
boundary) and the variable values for each node. Also update the help
and general formatting of the code.
2016-09-28 Allow for variable sponge coefficient and radious
==============================================================================

0001 function write_FVCOM_sponge(Mobj,filename) 0002 % Write FVCOM format sponge layer file 0003 % 0004 % function write_FVCOM_sponge(Mobj,filename) 0005 % 0006 % DESCRIPTION: 0007 % Generate an ascii FVCOM 3.x format sponge file from Mesh object 0008 % 0009 % INPUT 0010 % Mobj = Mesh object with fields: 0011 % - sponge_fac - the sponge factor. 0012 % - sponge_rad - the sponge radius. 0013 % - nSponge - the number of sponge boundary (see 0014 % add_sponge_nodes_list). 0015 % - nSponge - the node IDs of the sponge nodes. 0016 % filename = FVCOM sponge file name 0017 % 0018 % OUTPUT: 0019 % FVCOM sponge file: filename 0020 % 0021 % EXAMPLE USAGE 0022 % write_FVCOM_sponge(Mobj,'tst_spg.dat') 0023 % 0024 % Author(s): 0025 % Geoff Cowles (University of Massachusetts Dartmouth) 0026 % Karen Thurston (National Oceanography Centre, Liverpool) 0027 % Rory O'Hara Murray (Marine Scotland Science) 0028 % 0029 % Revision history 0030 % 2013-01-18 Added support for variable sponge radius. 0031 % 2014-10-28 Added support for variable sponge damping coefficient, by 0032 % assuming the size of the sponge_fac and sponge_rad arrays are equal the 0033 % number of sponge nodes by default. 0034 % 2016-04-20 Reconcile the original behaviour (single value at each open 0035 % boundary) and the variable values for each node. Also update the help 0036 % and general formatting of the code. 0037 % 2016-09-28 Allow for variable sponge coefficient and radious 0038 % 0039 %============================================================================== 0040 0041 subname = 'write_FVCOM_sponge'; 0042 0043 global ftbverbose 0044 0045 if ftbverbose 0046 fprintf('\nbegin : %s\n', subname); 0047 end 0048 0049 %------------------------------------------------------------------------------ 0050 % Parse input arguments 0051 %------------------------------------------------------------------------------ 0052 if exist('Mobj', 'var') == 0 && exist('filename', 'var') == 0 0053 error('arguments to write_FVCOM_sponge are incorrect') 0054 end 0055 0056 %------------------------------------------------------------------------------ 0057 % Correct possible errors arrising from previous Mobj storage methods 0058 %------------------------------------------------------------------------------ 0059 0060 % Make sure sponge_fac and sponge_rad are the right size. We'll also allow 0061 % a single value per open boundary. 0062 if size(Mobj.sponge_fac,2) == 1 0063 Mobj.sponge_fac = Mobj.sponge_fac(:,1) * ones(1, max(Mobj.nSpongeNodes)); 0064 elseif size(Mobj.sponge_fac, 2) == Mobj.nObs 0065 Mobj.sponge_fac = repmat(Mobj.sponge_fac, max(Mobj.nSpongeNodes), 1)'; 0066 elseif size(Mobj.sponge_fac, 2) < max(Mobj.nSpongeNodes) 0067 error('sponge_fac is an incompatible size, check it''s been written correctly.') 0068 end 0069 if size(Mobj.sponge_rad,2)==1 0070 Mobj.sponge_rad = Mobj.sponge_rad(:,1)*ones(1,max(Mobj.nSpongeNodes)); 0071 elseif size(Mobj.sponge_rad, 2) == Mobj.nObs 0072 Mobj.sponge_rad = repmat(Mobj.sponge_rad, max(Mobj.nSpongeNodes), 1)'; 0073 elseif size(Mobj.sponge_rad,2) < max(Mobj.nSpongeNodes) 0074 error('sponge_rad is an incompatible size, check it''s been written correctly.') 0075 end 0076 0077 % If there are zeros across the sponge_fac and sponge_rad arrays then 0078 % assume they are constant values and fill. This may have happened if one 0079 % sponge layer has constant values, and the second has variable values. 0080 for n=1:length(Mobj.nSpongeNodes) 0081 if sum(Mobj.sponge_fac(n,2:Mobj.nSpongeNodes(n)))==0 0082 Mobj.sponge_fac(n,2:Mobj.nSpongeNodes(n)) = Mobj.sponge_fac(n,1); 0083 end 0084 if sum(Mobj.sponge_rad(n,2:Mobj.nSpongeNodes(n)))==0 0085 Mobj.sponge_rad(n,2:Mobj.nSpongeNodes(n)) = Mobj.sponge_rad(n,1); 0086 end 0087 end 0088 0089 %------------------------------------------------------------------------------ 0090 % Dump the file 0091 %------------------------------------------------------------------------------ 0092 if ftbverbose 0093 fprintf('writing FVCOM spongefile %s\n',filename) 0094 end 0095 fid = fopen(filename,'w'); 0096 0097 if Mobj.nSponge == 0 0098 fprintf(fid,'Sponge Node Number = %d\n',0); 0099 else 0100 Total_Sponge = sum(Mobj.nSpongeNodes(1:Mobj.nSponge)); 0101 fprintf(fid,'Sponge Node Number = %d\n',Total_Sponge); 0102 for i=1:Mobj.nSponge 0103 for j=1:Mobj.nSpongeNodes(i) 0104 fprintf(fid,'%d %f %f \n',Mobj.sponge_nodes(i,j),Mobj.sponge_rad(i,j),Mobj.sponge_fac(i,j)); 0105 end 0106 end 0107 end 0108 fclose(fid); 0109 0110 if ftbverbose 0111 fprintf('end : %s\n', subname) 0112 end 0113