Commit f2be6afa authored by Pierre Cazenave's avatar Pierre Cazenave
Browse files

Add support for matrices and some minor formatting fixes (mainly stripped trailing white space).

parent 16f54561
......@@ -4,7 +4,7 @@ function [dstar] = ST_Dstar(d,varargin)
% function [dstar] = ST_Dstar(d,varargin)
%
% DESCRIPTION:
% Convert grain size from d (m) to dimensionless D
% Convert grain size from d (m) to dimensionless D
%
% INPUT:
% d: sediment grain size in m
......@@ -16,20 +16,21 @@ function [dstar] = ST_Dstar(d,varargin)
% Dstar: nondimensional grain size
%
% EXAMPLE USAGE
% dstar = ST_Dstar(.0005,'temperature',10,'salinity',35,'sdens',2650)
% dstar = ST_Dstar(.0005,'temperature',10,'salinity',35,'sdens',2650)
%
% Author(s):
% Author(s):
% Geoff Cowles (University of Massachusetts Dartmouth)
% Pierre Cazenave (Plymouth Marine Laboratory)
%
% Revision history
%
% 2017-03-27 Add support for matrices and some minor syntax changes.
%
%==============================================================================
subname = 'ST_Dstar';
%fprintf('\n')
%fprintf(['begin : ' subname '\n'])
[~, subname] = fileparts(mfilename('fullpath'));
fprintf('\nbegin : %s\n', subname)
% constants
% constants
grav = 9.8106; %g
T = 10; %T (C)
S = 35; %S (PSU)
......@@ -49,13 +50,12 @@ for i=1:2:length(varargin)-1
case 'sal'
S = varargin{i+1};
case 'sde'
sdens = varargin{i+1};
sdens = varargin{i+1};
otherwise
error(['Can''t understand value for:' keyword]);
end; %switch keyword
end;
% calculate nu
nu = SW_Kviscosity(T,S);
......@@ -63,7 +63,12 @@ nu = SW_Kviscosity(T,S);
dens = SW_Density(T,S);
% calculate dstar
s = sdens/dens;
dstar = ([grav*(s-1)/(nu^2)])^(1/3)*d;
if isscalar(dens)
s = sdens/dens;
dstar = ([grav*(s-1)/(nu^2)])^(1/3)*d;
else
s = sdens ./ dens;
dstar = ([grav*(s-1)./(nu.^2)]).^(1/3).*d;
end
%fprintf(['end : ' subname '\n'])
fprintf('end : %s\n', subname)
function [taucr] = ST_taucr(d,varargin)
% Calculate critical shear stress in Pascals
% Calculate critical shear stress in Pascals (equivalent to N/m^2)
%
% function [wset] = ST_taucr(d,varargin)
%
......@@ -13,26 +13,26 @@ function [taucr] = ST_taucr(d,varargin)
% [optional] 'sdens' = sediment density in kg/m^3 [default=2650]
%
% OUTPUT:
% taucr: critical shear stress in N/m^2
% taucr: critical shear stress in N/m^2
%
% EXAMPLE USAGE
% TCR = ST_taucr(.0005,'temperature',10,'salinity',35,'sdens',2650)
% TCR = ST_taucr(.0005,'temperature',10,'salinity',35,'sdens',2650)
%
% Author(s):
% Author(s):
% Geoff Cowles (University of Massachusetts Dartmouth)
% Pierre Cazenave (Plymouth Marine Laboratory)
%
% References
% Soulsby Dynamics of Marine Sands (SC77)
%
% Revision history
%
% 2017-03-27 Add support for matrices.
%==============================================================================
subname = 'ST_taucr';
%fprintf('\n')
%fprintf(['begin : ' subname '\n'])
[~, subname] = fileparts(mfilename('fullpath'));
fprintf('\nbegin : %s\n', subname)
% constants
% constants
grav = 9.8106; %g
T = 10; %T (C)
S = 35; %S (PSU)
......@@ -52,7 +52,7 @@ for i=1:2:length(varargin)-1
case 'sal'
S = varargin{i+1};
case 'sde'
sdens = varargin{i+1};
sdens = varargin{i+1};
otherwise
error(['Can''t understand value for:' keyword]);
end; %switch keyword
......@@ -63,14 +63,15 @@ end;
dens = SW_Density(T,S);
% calculate dstar
dstar = ST_Dstar(d,'temp',T,'sal',S,'sdens',sdens);
dstar = ST_Dstar(d, 'temp', T, 'sal', S, 'sdens', sdens);
% calculate theta_cr
theta_cr = (0.30/(1+1.2*dstar)) + 0.055*[1 - exp(-.020*dstar)];
% calculate theta_cr and then taucr
if ismatrix(dstar)
theta_cr = (0.30./(1+1.2.*dstar)) + 0.055.*[1 - exp(-.020.*dstar)];
taucr = theta_cr.*grav.*(sdens-dens).*d;
else
theta_cr = (0.30/(1+1.2*dstar)) + 0.055*[1 - exp(-.020*dstar)];
taucr = theta_cr*grav*(sdens-dens)*d;
end
% calculate taucr
taucr = theta_cr*grav*(sdens-dens)*d;
%fprintf(['end : ' subname '\n'])
fprintf('end : %s\n', subname)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment