compute_jacobian_times_vector Subroutine

private subroutine compute_jacobian_times_vector(me, x, v, z)

Returns the product J*v, where J is the m x n Jacobian matrix and v is an n x 1 vector.

Note

This one will include the constant elements if the linear pattern is available.

Type Bound

numdiff_type

Arguments

Type IntentOptional Attributes Name
class(numdiff_type), intent(inout) :: me
real(kind=wp), intent(in), dimension(:) :: x

vector of variables (size n)

real(kind=wp), intent(in), dimension(:) :: v

vector (size n)

real(kind=wp), intent(out), dimension(:) :: z

The product J*v (size m)


Calls

proc~~compute_jacobian_times_vector~~CallsGraph proc~compute_jacobian_times_vector numerical_differentiation_module::numdiff_type%compute_jacobian_times_vector proc~compute_jacobian numerical_differentiation_module::numdiff_type%compute_jacobian proc~compute_jacobian_times_vector->proc~compute_jacobian proc~compute_perturbation_vector numerical_differentiation_module::numdiff_type%compute_perturbation_vector proc~compute_jacobian->proc~compute_perturbation_vector proc~raise_exception numerical_differentiation_module::numdiff_type%raise_exception proc~compute_jacobian->proc~raise_exception proc~compute_perturb_vector numerical_differentiation_module::numdiff_type%compute_perturb_vector proc~compute_perturbation_vector->proc~compute_perturb_vector proc~compute_perturb_vector->proc~raise_exception

Source Code

    subroutine compute_jacobian_times_vector(me,x,v,z)

    implicit none

    class(numdiff_type),intent(inout) :: me
    real(wp),dimension(:),intent(in)  :: x    !! vector of variables (size `n`)
    real(wp),dimension(:),intent(in)  :: v    !! vector (size `n`)
    real(wp),dimension(:),intent(out) :: z    !! The product `J*v` (size `m`)

    real(wp),dimension(:),allocatable :: jac !! sparse jacobian vector
    integer :: i !! counter
    integer :: r !! row number in full jacobian
    integer :: c !! column number in full jacobian

    if (me%exception_raised) return ! check for exceptions

    ! first compute the jacobian in sparse vector form:
    call me%compute_jacobian(x,jac)
    if (me%exception_raised) return ! check for exceptions

    ! initialize output vector:
    z = 0.0_wp

    if (allocated(jac)) then

        !   J    v   z
        !  ---   -   -
        !  X0X   X   X
        !  0X0 * X = X
        !  00X   X   X
        !  00X       X

        ! multiplication by input v:
        do i = 1, me%sparsity%num_nonzero_elements
            r = me%sparsity%irow(i)
            c = me%sparsity%icol(i)
            z(r) = z(r) + jac(i)*v(c)
        end do

        deallocate(jac)

    end if

    ! linear elements if available:
    do i = 1, me%sparsity%num_nonzero_linear_elements
        r = me%sparsity%linear_irow(i)
        c = me%sparsity%linear_icol(i)
        z(r) = z(r) + me%sparsity%linear_vals(i)*v(c)
    end do

    end subroutine compute_jacobian_times_vector