%   #####                                                  
%  #     # #####   ##   #    # #####    ##   #####  #####  
%  #         #    #  #  ##   # #    #  #  #  #    # #    # 
%   #####    #   #    # # #  # #    # #    # #    # #    # 
%        #   #   ###### #  # # #    # ###### #####  #    # 
%  #     #   #   #    # #   ## #    # #    # #   #  #    # 
%   #####    #   #    # #    # #####  #    # #    # #####  
%
%  #                                      
%  #       # #    # # ##### ###### #####  
%  #       # ##  ## #   #   #      #    # 
%  #       # # ## # #   #   #####  #    # 
%  #       # #    # #   #   #      #####  
%  #       # #    # #   #   #      #   #  
%  ####### # #    # #   #   ###### #    # 
%
function [varargout] = StandardLimiter( what, varargin )
  if nargin > 1
    R   = varargin{1} ;
    Z   = zeros(size(R)) ;
    ONE = ones(size(R)) ;
  end
  switch lower(what)
  case 'charm' % [not 2nd order TVD]
    % Zhou, G, (1995), Numerical simulations of physical discontinuities in single and multi-fluid flows
    % for arbitrary Mach numbers, PhD Thesis, Chalmers Univ. of Tech., Goteborg, Sweden.
    varargout{1} = R.*(3*R+1)./((R+1).^2) ;
  case 'hcus' % [not 2nd order TVD]
    % Waterson, N P and H Deconinck, (1995), A unified approach to the design and application of bounded
    % higher-order convection schemes, VKI Preprint 1995-21.
    varargout{1} = 1.5*(R+abs(R))./(R+2) ;
  case 'hquick' % [not 2nd order TVD]
    % Waterson, N P and H Deconinck, (1995)
    varargout{1} = 2*(R+abs(R))./(R+3) ;
  case 'koren'
    % Koren, B, (1993), A robust upwind discretisation method for advection, diffusion and source terms,
    % In: Numerical Methods for Advection-Diffusion Problems, Ed. C.B.Vreugdenhil & B.Koren, Vieweg, Braunschweig, p117.
    varargout{1} = max(Z,min(2*R,min((1+2*R)/3,2*ONE))) ;
  case { 'minmod', 'minbee' } 
    % Roe, P L, (1986), Characteristic-based schemes for the Euler equations, Ann. Rev. Fluid Mech., 18, p337.
    varargout{1} = max(Z,min(ONE,R)) ;
  case { 'mc', 'monotonizedcentraldifference' } % symmetric
    % Van Leer, B, (1977), Towards the ultimate conservative difference scheme III.
    % Upstream-centered finite-difference schemes for ideal compressible flow., J. Comp. Phys., 23, p263-75.
    varargout{1} = max(Z,min((1+R)/2, 2*min(R,ONE))) ;
  case 'osher'
    % Chatkravathy, S R and S Osher, (1983), High resolution applications of the Osher upwind scheme for the Euler equations,
    % AIAA Paper 83-1943, Proc. AIAA 6th Comutational Fluid Dynamics Conference, pp 363-73.
    if nargin > 2
      beta = varargin{2} ;
    else
      beta = 1.5 ;
    end
    varargout{1} = max(Z,min(R,beta*ONE)) ;
  case 'ospre' % symmetric
    % Waterson, N P and H Deconinck, (1995)
    % A unified approach to the design and application of bounded higher-order convection schemes, VKI Preprint 1995-21.
    R2 = R.*(R+1) ;
    varargout{1} = 1.5 * R2./(R2+1);
  case 'smart' % [not 2nd order TVD]
    % Gaskell, P H and A K C Lau, (1988)
    % Curvature-compensated convective transport: SMART, a new boundedness-preserving transport algorithm
    % Int. J. Num. Meth. Fluids, 8, p617.
    varargout{1} = max(Z, min(2*R,min(4*ONE, 0.25+0.75*R))) ;
  case 'superbee' % symmetric
    % Roe, P L, (1986), Characteristic-based schemes for the Euler equations, Ann. Rev. Fluid Mech., 18, p337.
    varargout{1} = max(Z, max(min(ONE,2*R), min(2*ONE,R))) ;
  case 'sweby' % symmetric
    % Sweby, P K, (1984), High resolution schemes using flux-limiters for hyperbolic conservation laws.
    % SIAM J. Num. Anal., 21, p995-1011.
    if nargin > 2
      beta = varargin{2} ;
    else
      beta = 1.5 ;
    end
    varargout{1} = max(Z,max(min(beta*R,ONE),min(R,beta*ONE))) ;
  case 'umist'
    % Lien, F S, and M. A. Leschziner, (1994)
    % Upstream monotonic interpolation for scalar transport with application to complex turbulent flows
    % Int. J. Num. Meth. Fluids, 19, p527.
    varargout{1} = max(Z,min(2*min(R,ONE),min(0.25+0.75*R,0.75+0.25*R))) ;
  case 'vanalbada' % symmetric
    % Van Albada, G D, B. Van Leer and W. W. Roberts, (1982)
    % A comparative study of computational methods in cosmic gas dynamics, Astron. Astrophysics, 108, p76.
    varargout{1} = (R.^2+R) ./ (R.^2+1) ;
  case 'vanalbada1' % Alternative form [not 2nd order TVD] used on high spatial order schemes
    % Kermani, M. J., Gerber, A. G., and Stockie, J. M. (2003),
    % Thermodynamically Based Moisture Prediction Using Roe’s Scheme, 4th Conference of Iranian AeroSpace Society
    % Amir Kabir University of Technology, Tehran, Iran, January 27–29.
    varargout{1} = 2*R ./ (R.^2+1) ;
  case 'vanleer' % symmetric
    % Van Leer, B, (1974), Towards the ultimate conservative difference scheme II. 
    % Monotonicity and conservation combined in a second order scheme. J. Comp. Phys., 14, p361-70.
    varargout{1} = (R+abs(R)) ./ (R+1) ;
  case 'upwind'
    varargout{1} = Z ;
  case 'laxwendroff'
    varargout{1} = ONE ;
  case 'beamwarming'
    varargout{1} = R ;
  case 'fromm'
    varargout{1} = 0.5*(1+R) ;
  case 'names'
    varargout{1} = { 'charm', 'hcus', 'hquick', 'koren', 'minmod', 'mc', 'osher', 'ospre', 'smart', ...
                     'superbee', 'sweby', 'umist', 'vanalbada', 'vanalbada1', 'vanleer', 'upwind', ...
                     'laxwendroff', 'beamwarming', 'fromm' } ;
  otherwise
    error( [ 'StandardLimiter: ', what, ' unknown' ] ) ;
  end
end
