Compute the gradient of the solver function (Jacobian matrix). Sparse version.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(nlesolver_type), | intent(inout) | :: | me | |||
| real(kind=wp), | intent(in), | dimension(:) | :: | x | ||
| real(kind=wp), | intent(out), | dimension(:) | :: | g |
subroutine halo_grad_sparse(me,x,g) implicit none class(nlesolver_type),intent(inout) :: me real(wp),dimension(:),intent(in) :: x real(wp),dimension(:),intent(out) :: g real(wp),dimension(:),allocatable :: jac !! the jacobian matrix returned by `numdiff` ! ...note: need to modify so it doesn't ! have to return an allocatable array integer :: i !! seg number counter select type (me) class is (my_solver_type) if (jacobian_is_cached(me%mission,x)) then g = me%mission%jac_cache ! (from the function evaluation at this x) return end if ! first let's cache all the segment data: do i=1,size(me%mission%segs) call me%mission%segs(i)%cache() end do if (me%mission%jacobian_mode==2) then ! analytic: propagate each segment with its STM call me%mission%compute_jacobian_stm(x,jac) else ! use numdiff to compute the jacobian matrix (sparse version) call me%mission%compute_jacobian(x,jac) end if g = jac ! restore data just in case: do i=1,size(me%mission%segs) call me%mission%segs(i)%uncache() end do class default error stop 'invalid class in halo_grad' end select end subroutine halo_grad_sparse