Computes the 2-d advective tendency of an input field f given the advective velocity field u and v [m/s] and grid spacing dx and dy [m], using a first order, positive-definite upwind differencing. Fields f, u, and v are defined on a semi-staggered Arakawa C-grid:
--+---v---+---v---+---v-- | | |
j+1 u f u f u f | | | --+---v---+---v---+---v-- | | | j u f u f u f | | | --+---v---+---v---+---v-- | | | j-1 u f u f u f | i-1 | i | i+1
The differentiation range is [2:size(f,dim=1)-1,2:size(f,dim=2)-1], so 1 halo cell on each end needs to be set priod to calling this function.
This function is for 1-dimensional input arrays. It is overloaded by the
 advectUpwind1stOrder2d procedure.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=rk), | intent(in), | dimension(:,:,:,:) | :: | f | Input field to be advected | |
| real(kind=rk), | intent(in), | dimension(:,:,:,:) | :: | u | Advective velocity in x-direction [m/s] | |
| real(kind=rk), | intent(in), | dimension(:,:,:,:) | :: | v | Advective velocity in y-direction [m/s] | |
| real(kind=rk), | intent(in), | dimension(:,:) | :: | dx | Grid spacing in x-direction [m] | |
| real(kind=rk), | intent(in), | dimension(:,:) | :: | dy | Grid spacing in x-direction [m] | 
Advective tendency
pure function advectUpwind1stOrder2dRank2(f,u,v,dx,dy) result(dfdt)
  !! Computes the 2-d advective tendency of an input field f given the advective
  !! velocity field u and v [m/s] and grid spacing dx and dy [m], using a first
  !! order, positive-definite upwind differencing. Fields f, u, and v are
  !! defined on a semi-staggered Arakawa C-grid:
  !!
  !!     --+---v---+---v---+---v--
  !!       |       |       |
  !! j+1   u   f   u   f   u   f
  !!       |       |       |
  !!     --+---v---+---v---+---v--
  !!       |       |       |
  !!  j    u   f   u   f   u   f
  !!       |       |       |
  !!     --+---v---+---v---+---v--
  !!       |       |       |
  !! j-1   u   f   u   f   u   f
  !!       |  i-1  |   i   |  i+1
  !!
  !! The differentiation range is [2:size(f,dim=1)-1,2:size(f,dim=2)-1], so 1
  !! halo cell on each end needs to be set priod to calling this function.
  !!
  !! This function is for 1-dimensional input arrays. It is overloaded by the
  !! `advectUpwind1stOrder2d` procedure.
  real(kind=rk),dimension(:,:,:,:),intent(in) :: f
    !! Input field to be advected
  real(kind=rk),dimension(:,:,:,:),intent(in) :: u
    !! Advective velocity in x-direction [m/s]
  real(kind=rk),dimension(:,:,:,:),intent(in) :: v
    !! Advective velocity in y-direction [m/s]
  real(kind=rk),dimension(:,:),intent(in) :: dx
    !! Grid spacing in x-direction [m]
  real(kind=rk),dimension(:,:),intent(in) :: dy
    !! Grid spacing in x-direction [m]
  real(kind=rk),dimension(:,:,:,:),allocatable :: dfdt
    !! Advective tendency
  integer(kind=ik) :: i,j,m,n
  integer(kind=ik) :: idm,jdm,mdm,ndm
  mdm = size(f,dim=1)
  ndm = size(f,dim=2)
  idm = size(f,dim=3)
  jdm = size(f,dim=4)
  allocate(dfdt(mdm,ndm,2:idm-1,2:jdm-1))
  dfdt = 0
  do concurrent(i = 2:idm-1,j = 2:jdm-1,m = 1:mdm,n = 1:ndm)
    dfdt(m,n,i,j) = - 0.25_rk                                            &
      *((u(m,n,i+1,j)+abs(u(m,n,i+1,j)))*(dy(i,j)+dy(i+1,j))*f(m,n,i,j)  &
      + (u(m,n,i+1,j)-abs(u(m,n,i+1,j)))*(dy(i,j)+dy(i+1,j))*f(m,n,i+1,j)&
      - (u(m,n,i,j)+abs(u(m,n,i,j)))*(dy(i-1,j)+dy(i,j))*f(m,n,i-1,j)    &
      - (u(m,n,i,j)-abs(u(m,n,i,j)))*(dy(i-1,j)+dy(i,j))*f(m,n,i,j)      &
      + (v(m,n,i,j)+abs(v(m,n,i,j)))*(dx(i,j)+dx(i,j+1))*f(m,n,i,j)      &
      + (v(m,n,i,j)-abs(v(m,n,i,j)))*(dx(i,j)+dx(i,j+1))*f(m,n,i+1,j)    &
      - (v(m,n,i,j-1)+abs(v(m,n,i,j-1)))*(dx(i,j-1)+dx(i,j))*f(m,n,i-1,j)&
      - (v(m,n,i,j-1)-abs(v(m,n,i,j-1)))*(dx(i,j-1)+dx(i,j))*f(m,n,i,j)) &
      / (dx(i,j)*dy(i,j))
  enddo
endfunction advectUpwind1stOrder2dRank2