Home > fvcom_prepro > estimate_ts.m

estimate_ts

PURPOSE ^

Estimate time step at each node

SYNOPSIS ^

function [Mobj] = estimate_ts(Mobj,u,zeta)

DESCRIPTION ^

 Estimate time step at each node

 [Mobj] = function estimate_ts(Mobj)

 DESCRIPTION:
    Calculate barotropic time step

 INPUT
    Mobj = matlab mesh object
    u = anticipated maximum current speed
    zeta = anticipated maximum surface elevation

 OUTPUT:
    Mobj = matlab structure containing mesh time step

 EXAMPLE USAGE
    Mobj = estimate_ts(Mobj)

 Author(s):
    Geoff Cowles (University of Massachusetts Dartmouth)
    Pierre Cazenave (Plymouth Marine Laboratory)

 Revision history
    2012-07-14 Add great circle approximation if only provided with
    latitude and longitudes. Also add arguments to the function to define
    current velocity and tidal amplitudes.
    2016-02018 Update the help to reflect the required variables.
    2017-09-01 Tidy the code a bit.

==============================================================================

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [Mobj] = estimate_ts(Mobj,u,zeta)
0002 
0003 % Estimate time step at each node
0004 %
0005 % [Mobj] = function estimate_ts(Mobj)
0006 %
0007 % DESCRIPTION:
0008 %    Calculate barotropic time step
0009 %
0010 % INPUT
0011 %    Mobj = matlab mesh object
0012 %    u = anticipated maximum current speed
0013 %    zeta = anticipated maximum surface elevation
0014 %
0015 % OUTPUT:
0016 %    Mobj = matlab structure containing mesh time step
0017 %
0018 % EXAMPLE USAGE
0019 %    Mobj = estimate_ts(Mobj)
0020 %
0021 % Author(s):
0022 %    Geoff Cowles (University of Massachusetts Dartmouth)
0023 %    Pierre Cazenave (Plymouth Marine Laboratory)
0024 %
0025 % Revision history
0026 %    2012-07-14 Add great circle approximation if only provided with
0027 %    latitude and longitudes. Also add arguments to the function to define
0028 %    current velocity and tidal amplitudes.
0029 %    2016-02018 Update the help to reflect the required variables.
0030 %    2017-09-01 Tidy the code a bit.
0031 %
0032 %==============================================================================
0033 
0034 [~, subname] = fileparts(mfilename('fullpath'));
0035 global ftbverbose
0036 if ftbverbose
0037     fprintf('\nbegin : %s\n', subname)
0038 end
0039 
0040 %------------------------------------------------------------------------------
0041 % Set constants
0042 %------------------------------------------------------------------------------
0043 
0044 g = 9.81; % gravitational acceleration
0045 
0046 if(~Mobj.have_bath)
0047     error('can''t estimate the time step without bathymetry')
0048 end
0049 
0050 %------------------------------------------------------------------------------
0051 % Compute the time step estimate
0052 %------------------------------------------------------------------------------
0053 if Mobj.have_xy
0054     x = Mobj.x;
0055     y = Mobj.y;
0056 else
0057     % Will convert to metres when calculating element edge length
0058     x = Mobj.lon;
0059     y = Mobj.lat;
0060 end
0061 h = max(Mobj.h,0);
0062 tri = Mobj.tri;
0063 nVerts = Mobj.nVerts;
0064 nElems = Mobj.nElems;
0065 
0066 ts = inf(nVerts,1);
0067 lside = zeros(nVerts,1);
0068 for i=1:nElems
0069     n1 = tri(i,1);
0070     n2 = tri(i,2);
0071     n3 = tri(i,3);
0072     nds = [n1 n2 n3];
0073     % Check whether we have x and y values and use great circle
0074     % approximations if we don't.
0075     if Mobj.have_xy
0076         lside(i) = sqrt((x(n1)-x(n2))^2 + (y(n1)-y(n2))^2);
0077     else
0078         lside(i) = haversine(x(n1),y(n1),x(n2),y(n2));
0079     end
0080     dpth  = max(h(nds))+zeta;
0081     dpth  = max(dpth,1);
0082     ts(nds) = min(ts(nds),lside(i)/(sqrt(g*dpth) + u));
0083 end
0084 if ftbverbose
0085     fprintf('minimum time step: %f seconds\n',min(ts));
0086 end
0087 Mobj.ts = ts;
0088 Mobj.have_ts = true;
0089 Mobj.lside=lside;
0090 if ftbverbose
0091     fprintf('end   : %s\n', subname)
0092 end
0093 
0094 function km=haversine(lat1,lon1,lat2,lon2)
0095 % Haversine function to calculate first order distance measurement. Assumes
0096 % spherical Earth surface. Lifted from:
0097 %
0098 % http://www.mathworks.com/matlabcentral/fileexchange/27785
0099 %
0100 R = 6371000;                    % Earth's mean radius in metres
0101 delta_lat = lat2 - lat1;        % difference in latitude
0102 delta_lon = lon2 - lon1;        % difference in longitude
0103 a = sin(delta_lat/2)^2 + cos(lat1) * cos(lat2) * ...
0104     sin(delta_lon/2)^2;
0105 c = 2 * atan2(sqrt(a), sqrt(1-a));
0106 km = R * c;                     % distance in metres
0107

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