function Gv=ttdGv(t,Pe,tau)

% USAGE: Gv = ttdGv(t,Pe,tau) 
% Returns the volume integrated TTD with mean age tau 
% and Peclet number Pe at time t.
% INPUTS: 
%  t = time (same units as tau)
%  Pe = Peclet number
%  tau = mean age
% Notes:
% Gv(t) = (1/L)*Integral[G(x,t),{x,0,L}]
%  where,
%   L = u*tau
%   Pe = L*u/k
%   G(x,t) = (x/sqrt(4*pi*k*t^3))*exp(-((x-u*t)^2)/(4*k*t))
%     is the TTD for the 1-d advection-diffusion equation
%  Gv(0) = Inf

% Samar Khatiwala (spk@ldeo.columbia.edu)

alpha = sqrt(Pe./(4*tau));
alphasqr = Pe./(4*tau);

Gv=(1./(sqrt(pi*Pe.*tau.*t))).*(exp(-alphasqr.*t)-exp(-alphasqr.*((t-tau).^2)./t)) ...
   + (1./(2*tau)).*(erf(alpha.*sqrt(t))+erf(alpha.*(tau-t)./sqrt(t)));
