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 | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(inout) | :: | me | |||
real(kind=wp), | intent(in), | dimension(:) | :: | x |
vector of variables (size |
|
real(kind=wp), | intent(in), | dimension(:) | :: | v |
vector (size |
|
real(kind=wp), | intent(out), | dimension(:) | :: | z |
The product |
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