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 advectUpwind1stOrder2dRank0(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
integer(kind=ik) :: idm,jdm
idm = size(f,dim=1)
jdm = size(f,dim=2)
allocate(dfdt(2:idm-1,2:jdm-1))
dfdt = 0
do concurrent(i = 2:idm-1,j = 2:jdm-1)
dfdt(i,j) = - 0.25_rk &
*((u(i+1,j)+abs(u(i+1,j)))*(dy(i,j)+dy(i+1,j))*f(i,j) &
+ (u(i+1,j)-abs(u(i+1,j)))*(dy(i,j)+dy(i+1,j))*f(i+1,j)&
- (u(i,j)+abs(u(i,j)))*(dy(i-1,j)+dy(i,j))*f(i-1,j) &
- (u(i,j)-abs(u(i,j)))*(dy(i-1,j)+dy(i,j))*f(i,j) &
+ (v(i,j)+abs(v(i,j)))*(dx(i,j)+dx(i,j+1))*f(i,j) &
+ (v(i,j)-abs(v(i,j)))*(dx(i,j)+dx(i,j+1))*f(i+1,j) &
- (v(i,j-1)+abs(v(i,j-1)))*(dx(i,j-1)+dx(i,j))*f(i-1,j)&
- (v(i,j-1)-abs(v(i,j-1)))*(dx(i,j-1)+dx(i,j))*f(i,j)) &
/ (dx(i,j)*dy(i,j))
enddo
endfunction advectUpwind1stOrder2dRank0