Returns a centered-difference of a 2-d array along dimension dim, with
first order differencing applied for the boundary points. This procedure is
overloaded by the generic procedure diff
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=rk), | intent(in), | dimension(:,:) | :: | x | Input array |
|
integer(kind=ik), | intent(in) | :: | dim | Dimension along which to differentiate |
Nodes of different colours represent the following:
Solid arrows point from a procedure to one which it calls. Dashed arrows point from an interface to procedures which implement that interface. This could include the module procedures in a generic interface or the implementation in a submodule of an interface in a parent module.
pure function diff_2d(x,dim) result(dx)
!! Returns a centered-difference of a 2-d array along dimension dim, with
!! first order differencing applied for the boundary points. This procedure is
!! overloaded by the generic procedure `diff`.
real(kind=rk),dimension(:,:),intent(in) :: x
!! Input array
integer(kind=ik),intent(in) :: dim
!! Dimension along which to differentiate
real(kind=rk),dimension(:,:),allocatable :: dx
integer(kind=ik) :: idm,jdm
idm = size(x,dim=1)
jdm = size(x,dim=2)
allocate(dx(idm,jdm))
if(idm == 0)then
return
elseif(idm == 1)then
dx = 0
return
endif
if(dim == 1)then
dx(2:idm-1,:) = 0.5_rk*(x(3:idm,:)-x(1:idm-2,:))
dx(1,:) = x(2,:)-x(1,:)
dx(idm,:) = x(idm,:)-x(idm-1,:)
elseif(dim == 2)then
dx(:,2:idm-1) = 0.5_rk*(x(:,3:idm)-x(:,1:idm-2))
dx(:,1) = x(2,:)-x(:,1)
dx(:,idm) = x(:,idm)-x(:,idm-1)
else
dx = 0
endif
endfunction diff_2d