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) ! first let's cache all the segment data: do i=1,size(me%mission%segs) call me%mission%segs(i)%cache() end do ! use numdiff to compute the jacobian matrix (sparse version) call me%mission%compute_jacobian(x,jac) 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