halo_grad_sparse Subroutine

public subroutine halo_grad_sparse(me, x, g)

Compute the gradient of the solver function (Jacobian matrix). Sparse 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_sparse~~CallsGraph proc~halo_grad_sparse halo_grad_sparse cache cache proc~halo_grad_sparse->cache compute_jacobian compute_jacobian proc~halo_grad_sparse->compute_jacobian uncache uncache proc~halo_grad_sparse->uncache

Source Code

    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