Compute gradient of any input scalar
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(out), | dimension( 0:dims%imx , 0:dims%jmx , 0:dims%kmx ) | :: | grad | Output variable storing the graident of var |
|
real(kind=wp), | intent(in), | dimension(-2:dims%imx+2,-2:dims%jmx+2,-2:dims%kmx+2) | :: | var | Input variable of which graident is required |
|
type(celltype), | intent(in), | dimension(-2:dims%imx+2,-2:dims%jmx+2,-2:dims%kmx+2) | :: | cells | Input cell quantities: volume |
|
type(facetype), | intent(in), | dimension(-2:dims%imx+3,-2:dims%jmx+2,-2:dims%kmx+2) | :: | Ifaces | Input varaible which stores I faces' area and unit normal |
|
type(facetype), | intent(in), | dimension(-2:dims%imx+2,-2:dims%jmx+3,-2:dims%kmx+2) | :: | Jfaces | Input varaible which stores J faces' area and unit normal |
|
type(facetype), | intent(in), | dimension(-2:dims%imx+2,-2:dims%jmx+2,-2:dims%kmx+3) | :: | Kfaces | Input varaible which stores K faces' area and unit normal |
|
type(extent), | intent(in) | :: | dims | |||
character(len=*), | intent(in) | :: | dir | Direction with respect to which gradients are calculated |
subroutine compute_gradient_G(grad, var, cells, Ifaces, Jfaces, Kfaces, dims, dir)
!< Compute gradient of any input scalar
implicit none
type(extent), intent(in) :: dims
real(wp), dimension( 0:dims%imx , 0:dims%jmx , 0:dims%kmx ), intent(out) :: grad
!< Output variable storing the graident of var
real(wp), dimension(-2:dims%imx+2,-2:dims%jmx+2,-2:dims%kmx+2), intent(in) :: var
!< Input variable of which graident is required
character(len=*) , intent(in) :: dir
!< Direction with respect to which gradients are calculated
type(celltype), dimension(-2:dims%imx+2,-2:dims%jmx+2,-2:dims%kmx+2), intent(in) :: cells
!< Input cell quantities: volume
type(facetype), dimension(-2:dims%imx+3,-2:dims%jmx+2,-2:dims%kmx+2), intent(in) :: Ifaces
!< Input varaible which stores I faces' area and unit normal
type(facetype), dimension(-2:dims%imx+2,-2:dims%jmx+3,-2:dims%kmx+2), intent(in) :: Jfaces
!< Input varaible which stores J faces' area and unit normal
type(facetype), dimension(-2:dims%imx+2,-2:dims%jmx+2,-2:dims%kmx+3), intent(in) :: Kfaces
!< Input varaible which stores K faces' area and unit normal
integer :: i
integer :: j
integer :: k
DebugCall('compute_gradient_G')
grad(:,:,:) = 0.0
select case(dir)
case('x')
do k=0,dims%kmx
do j=0,dims%jmx
do i=0,dims%imx
grad(i,j,k) =(-(var(i-1,j ,k )+var(i,j,k))*Ifaces(i,j,k)%nx*Ifaces(i,j,k)%A &
-(var(i ,j-1,k )+var(i,j,k))*Jfaces(i,j,k)%nx*Jfaces(i,j,k)%A &
-(var(i ,j ,k-1)+var(i,j,k))*Kfaces(i,j,k)%nx*Jfaces(i,j,k)%A &
+(var(i+1,j ,k )+var(i,j,k))*Ifaces(i+1,j ,k )%nx*Ifaces(i+1,j ,k )%A &
+(var(i ,j+1,k )+var(i,j,k))*Jfaces(i ,j+1,k )%nx*Jfaces(i ,j+1,k )%A &
+(var(i ,j ,k+1)+var(i,j,k))*Kfaces(i ,j ,k+1)%nx*Kfaces(i ,j ,k+1)%A &
)/(2*cells(i,j,k)%volume)
end do
end do
end do
case('y')
do k=0,dims%kmx
do j=0,dims%jmx
do i=0,dims%imx
grad(i,j,k) =(-(var(i-1,j ,k )+var(i,j,k))*Ifaces(i,j,k)%ny*Ifaces(i,j,k)%A &
-(var(i ,j-1,k )+var(i,j,k))*Jfaces(i,j,k)%ny*Jfaces(i,j,k)%A &
-(var(i ,j ,k-1)+var(i,j,k))*Kfaces(i,j,k)%ny*Jfaces(i,j,k)%A &
+(var(i+1,j ,k )+var(i,j,k))*Ifaces(i+1,j ,k )%ny*Ifaces(i+1,j ,k )%A &
+(var(i ,j+1,k )+var(i,j,k))*Jfaces(i ,j+1,k )%ny*Jfaces(i ,j+1,k )%A &
+(var(i ,j ,k+1)+var(i,j,k))*Kfaces(i ,j ,k+1)%ny*Kfaces(i ,j ,k+1)%A &
)/(2*cells(i,j,k)%volume)
end do
end do
end do
case('z')
do k=0,dims%kmx
do j=0,dims%jmx
do i=0,dims%imx
grad(i,j,k) =(-(var(i-1,j ,k )+var(i,j,k))*Ifaces(i,j,k)%nz*Ifaces(i,j,k)%A &
-(var(i ,j-1,k )+var(i,j,k))*Jfaces(i,j,k)%nz*Jfaces(i,j,k)%A &
-(var(i ,j ,k-1)+var(i,j,k))*Kfaces(i,j,k)%nz*Jfaces(i,j,k)%A &
+(var(i+1,j ,k )+var(i,j,k))*Ifaces(i+1,j ,k )%nz*Ifaces(i+1,j ,k )%A &
+(var(i ,j+1,k )+var(i,j,k))*Jfaces(i ,j+1,k )%nz*Jfaces(i ,j+1,k )%A &
+(var(i ,j ,k+1)+var(i,j,k))*Kfaces(i ,j ,k+1)%nz*Kfaces(i ,j ,k+1)%A &
)/(2*cells(i,j,k)%volume)
end do
end do
end do
case DEFAULT
print*, "ERROR: gradient direction error"
Fatal_error
end select
if(any(isnan(grad)))then
Fatal_error
end if
end subroutine compute_gradient_G