inv Function

public function inv(A) result(A_inv)

private called by junction solve

Arguments

Type IntentOptional Attributes Name
real(kind=dp), intent(in), dimension(:,:) :: A

Return Value real(kind=dp), dimension(size(A,1),size(A,2))


Calls

proc~~inv~~CallsGraph proc~inv inv dgetrf dgetrf proc~inv->dgetrf dgetri dgetri proc~inv->dgetri proc~set_error set_error proc~inv->proc~set_error

Called by

proc~~inv~~CalledByGraph proc~inv inv proc~solve_junction solve_junction proc~solve_junction->proc~inv proc~junction_resolution_from_and_to_ports Junction_resolution_from_and_to_ports proc~junction_resolution_from_and_to_ports->proc~solve_junction proc~main_loop main_loop proc~main_loop->proc~junction_resolution_from_and_to_ports program~reims_p reims_p program~reims_p->proc~main_loop

Source Code

function inv(A) result(A_inv)
    !! private called by junction solve
    real(dp), dimension(:,:), intent(in) :: A
    real(dp), dimension(size(A,1),size(A,2)) :: A_inv

    real(dp), dimension(size(A,1)) :: work  ! work array for LaPACK
    integer, dimension(size(A,1)) :: i_piv  ! pivot indices
    integer :: n, info

    ! External procedures defined in LaPACK
    external DGETRF
    external DGETRI

    ! Store A in A_inv to prevent it from being overwritten by LaPACK
    A_inv = A
    n = size(A,1)

    ! DGETRF computes an LU factorization of a general M-by-N matrix A
    ! using partial pivoting with row interchanges.
    call DGETRF(n, n, A_inv, n, i_piv, info)

    if (info /= 0 ) then
        call set_error('matrix is numerically singular in junction inv(A)')
        return
    end if

    ! DGETRI computes the inverse of a matrix using the LU factorization
    ! computed by DGETRF.
    call DGETRI(n, A_inv, n, i_piv, work, n, info)

    if (info /= 0) then
        call set_error('matrix inversion failed in junction inv(A)')
        return
    end if
end function inv