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