halo_grad Subroutine

public subroutine halo_grad(me, x, g)

Compute the gradient of the solver function (Jacobian matrix). Dense version.

Arguments

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

Calls

proc~~halo_grad~~CallsGraph proc~halo_grad halo_grad cache cache proc~halo_grad->cache compute_jacobian_dense compute_jacobian_dense proc~halo_grad->compute_jacobian_dense uncache uncache proc~halo_grad->uncache

Source Code

    subroutine halo_grad(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 (dense version)
        call me%mission%compute_jacobian_dense(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