Computes the advective tendency of an input field f given the advective velocity field u [m/s] and grid spacing dx [m], using a first order, positive-definite upwind differencing. Fields f and u are defined on a semi-staggered Arakawa C-grid:
--u---f---u---f---u---f-- | i-1 | i | i+1
The differentiation range is [2,size(f)-1], so 1 halo cell on each end needs to be set priod to calling this function.
This function is for 2-dimensional input arrays. It is overloaded by the
advectUpwind1stOrder1d
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 [m/s] |
|
real(kind=rk), | intent(in), | dimension(:) | :: | dx | Grid spacing [m] |
Advective tendency
pure function advectUpwind1stOrder1dRank1(f,u,dx) result(dfdt)
!! Computes the advective tendency of an input field f given the advective
!! velocity field u [m/s] and grid spacing dx [m], using a first order,
!! positive-definite upwind differencing. Fields f and u are defined on a
!! semi-staggered Arakawa C-grid:
!!
!! --u---f---u---f---u---f--
!! | i-1 | i | i+1
!!
!! The differentiation range is [2,size(f)-1], so 1 halo cell on each end
!! needs to be set priod to calling this function.
!!
!! This function is for 2-dimensional input arrays. It is overloaded by the
!! `advectUpwind1stOrder1d` procedure.
real(kind=rk),dimension(:,:),intent(in) :: f
!! Input field to be advected
real(kind=rk),dimension(:,:),intent(in) :: u
!! Advective velocity [m/s]
real(kind=rk),dimension(:),intent(in) :: dx
!! Grid spacing [m]
real(kind=rk),dimension(:,:),allocatable :: dfdt
!! Advective tendency
integer(kind=ik) :: i,m
integer(kind=ik) :: idm,mdm
mdm = size(f,dim=1)
idm = size(f,dim=2)
allocate(dfdt(mdm,2:idm-1))
dfdt = 0
do concurrent(i = 2:idm-1,m = 1:mdm)
dfdt(m,i) = - 0.5_rk*((u(m,i+1)+abs(u(m,i+1)))*f(m,i) &
+ (u(m,i+1)-abs(u(m,i+1)))*f(m,i+1)&
- (u(m,i)+abs(u(m,i)))*f(m,i-1) &
- (u(m,i)-abs(u(m,i)))*f(m,i)) &
/ dx(i)
enddo
endfunction advectUpwind1stOrder1dRank1