grad_sparse Subroutine

subroutine grad_sparse(me, x, g)

compute the gradient of the function (Jacobian):

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~~grad_sparse~~CallsGraph proc~grad_sparse sparse_test::grad_sparse proc~grad sparse_test::grad proc~grad_sparse->proc~grad

Source Code

    subroutine grad_sparse(me,x,g)
        !! compute the gradient of the function (Jacobian):
        implicit none
        class(nlesolver_type),intent(inout) :: me
        real(wp),dimension(:),intent(in)    :: x
        real(wp),dimension(:),intent(out)   :: g

        real(wp),dimension(m,n) :: g_dense

        ! for this example, just convert the dense
        ! jacobian to the sparse representation
        call grad(me,x,g_dense)

        g(1) = g_dense(1,1)
        g(2) = g_dense(1,2)
        g(3) = g_dense(2,2)

        f_evals = f_evals + 2   ! to approximate forward diff derivatives

    end subroutine grad_sparse