vol_tetrahedron Function

private function vol_tetrahedron(p1, p2, p3, p4)

Compute the volume of a tetrahedron, given 4 points which are 1-D arrays Since we know that the determinant is to be evaluated of a 3x3 matrix, we write the expression itself

Arguments

Type IntentOptional AttributesName
real(kind=wp), intent(in), dimension(:):: p1
real(kind=wp), intent(in), dimension(:):: p2
real(kind=wp), intent(in), dimension(:):: p3
real(kind=wp), intent(in), dimension(:):: p4

Return Value real(kind=wp)


Called by

proc~~vol_tetrahedron~~CalledByGraph proc~vol_tetrahedron vol_tetrahedron proc~vol_hexahedron vol_hexahedron proc~vol_hexahedron->proc~vol_tetrahedron proc~compute_volumes compute_volumes proc~compute_volumes->proc~vol_hexahedron proc~setup_geometry setup_geometry proc~setup_geometry->proc~compute_volumes proc~setup_solver setup_solver proc~setup_solver->proc~setup_geometry proc~start_run start_run proc~start_run->proc~setup_solver program~main main program~main->proc~start_run

Contents

Source Code


Source Code

        function vol_tetrahedron(p1, p2, p3, p4)
            !< Compute the volume of a tetrahedron, given 4 points which
            !< are 1-D arrays
            !< Since we know that the determinant is to be evaluated of 
            !< a 3x3 matrix, we write the expression itself
            !-----------------------------------------------------------

            implicit none
            real(wp), dimension(:), intent(in):: p1, p2, p3, p4
            real(wp), dimension(1:3,1:3) :: A
            real(wp) :: vol_tetrahedron

            A(:, 1) = p1 - p4
            A(:, 2) = p2 - p4
            A(:, 3) = p3 - p4

            !vol_tetrahedron = A(1,1) * (A(2,2)*A(3,3) - A(2,3)*A(3,2)) + &
            !                  A(1,2) * (A(2,3)*A(3,1) - A(2,1)*A(3,3)) + &
            !                  A(1,3) * (A(2,1)*A(3,2) - A(2,2)*A(3,1))
            vol_tetrahedron = (p4(1) - p1(1))*((p2(2)-p1(2))*(p3(3)-p1(3)) - (p2(3)-p1(3))*(p3(2)-p1(2))) &
                            + (p4(2) - p1(2))*((p2(3)-p1(3))*(p3(1)-p1(1)) - (p2(1)-p1(1))*(p3(3)-p1(3))) &
                            + (p4(3) - p1(3))*((p2(1)-p1(1))*(p3(2)-p1(2)) - (p2(2)-p1(2))*(p3(1)-p1(1)))
            vol_tetrahedron = -vol_tetrahedron / 6.                  
        
        end function vol_tetrahedron