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 second order centered 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
advectCentered2ndOrder2d
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 y-direction [m] |
Advective tendency
pure function advectCentered2ndOrder2dRank2(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 second
!! order centered 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
!! `advectCentered2ndOrder2d` 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 y-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)*(dy(i,j)+dy(i+1,j))*(f(m,n,i,j)+f(m,n,i+1,j)) &
- u(m,n,i,j)*(dy(i-1,j)+dy(i,j))*(f(m,n,i-1,j)+f(m,n,i,j)) &
+ v(m,n,i,j)*(dy(i,j)+dy(i,j+1))*(f(m,n,i,j)+f(m,n,i,j+1)) &
- v(m,n,i,j-1)*(dy(i,j-1)+dy(i,j))*(f(m,n,i,j-1)+f(m,n,i,j)))&
/ (dx(i,j)*dy(i,j))
enddo
endfunction advectCentered2ndOrder2dRank2