Compute the grid cell volumes Each grid is a hexahedron, whose volume is calculated by splitting it into 5 tetrahedrons, whose volume is known
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(celltype), | intent(out), | dimension(-2:imx+2,-2:jmx+2,-2:kmx+2) | :: | cells | Cell center quanties: volume and coordiantes of cell center |
|
type(nodetype), | intent(in), | dimension(-2:imx+3,-2:jmx+3,-2:kmx+3) | :: | nodes | Grid points |
subroutine compute_volumes(cells, nodes)
!< Compute the grid cell volumes
!< Each grid is a hexahedron, whose volume is calculated by
!< splitting it into 5 tetrahedrons, whose volume is known
!-----------------------------------------------------------
implicit none
type(celltype), dimension(-2:imx+2,-2:jmx+2,-2:kmx+2), intent(out) :: cells
!< Cell center quanties: volume and coordiantes of cell center
type(nodetype), dimension(-2:imx+3,-2:jmx+3,-2:kmx+3), intent(in) :: nodes
!< Grid points
integer :: i,j,k
real(wp), dimension(1:3, 1:8) :: p_list
cells(:,:,:)%volume=1.
do k = 0, kmx+0
do j = 0, jmx+0
do i = 0, imx+0
p_list(:, :) = 0.
p_list(:, 1) = (/ nodes(i,j,k)%x, nodes(i,j,k)%y, nodes(i,j,k)%z /)
p_list(:, 2) = (/ nodes(i+1,j,k)%x, nodes(i+1,j,k)%y, nodes(i+1,j,k)%z /)
p_list(:, 3) = (/ nodes(i+1,j+1,k)%x, nodes(i+1,j+1,k)%y, nodes(i+1,j+1,k)%z /)
p_list(:, 4) = (/ nodes(i,j+1,k)%x, nodes(i,j+1,k)%y, nodes(i,j+1,k)%z /)
p_list(:, 5) = (/ nodes(i,j,k+1)%x, nodes(i,j,k+1)%y, nodes(i,j,k+1)%z /)
p_list(:, 6) = (/ nodes(i+1,j,k+1)%x, nodes(i+1,j,k+1)%y, nodes(i+1,j,k+1)%z /)
p_list(:, 7) = (/ nodes(i+1,j+1,k+1)%x, nodes(i+1,j+1,k+1)%y, nodes(i+1,j+1,k+1)%z /)
p_list(:, 8) = (/ nodes(i,j+1,k+1)%x, nodes(i,j+1,k+1)%y, nodes(i,j+1,k+1)%z /)
cells(i, j, k)%volume = (vol_hexahedron(p_list))
if(cells(i,j,k)%volume<=0.0) then
if(i==0 .or. i==imx .or. j==0 .or. j==jmx .or. k==0 .or. k==kmx) then
!print*, "Ghost Cell volume negative"
cells(i, j, k)%volume = (vol_hexahedron(p_list))
else
print*, process_id, i,j,k
print*, "negative volume :", (vol_hexahedron(p_list))
STOP
end if
end if
end do
end do
end do
if(any(cells(:,:,:)%volume==0.0))then
Fatal_error
end if
if(any((cells(:,:,:)%volume)<0.0))then
Fatal_error
end if
end subroutine compute_volumes