eclipse_gjac Subroutine

subroutine eclipse_gjac(x, g, jac_val, accuracy, status, data)

The gradient of the objective and the Jacobian values for sqpopt: halo's analytic Jacobian, then the eclipse rows (central differences).

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in), dimension(:) :: x
real(kind=wp), intent(out), dimension(:) :: g
real(kind=wp), intent(out), dimension(:) :: jac_val
integer, intent(in) :: accuracy
integer, intent(inout) :: status
class(*), intent(inout), optional :: data

Calls

proc~~eclipse_gjac~~CallsGraph proc~eclipse_gjac eclipse_gjac compute_jacobian_stm compute_jacobian_stm proc~eclipse_gjac->compute_jacobian_stm proc~epochs_in_range epochs_in_range proc~eclipse_gjac->proc~epochs_in_range proc~eval_rows eval_rows proc~eclipse_gjac->proc~eval_rows proc~scale_row_columns scale_row_columns proc~eclipse_gjac->proc~scale_row_columns r r proc~eclipse_gjac->r rows rows proc~eclipse_gjac->rows upos upos proc~eclipse_gjac->upos w w proc~eclipse_gjac->w proc~row_ks row_ks proc~eval_rows->proc~row_ks proc~destroy_trajectory trajectory%destroy_trajectory proc~row_ks->proc~destroy_trajectory proc~get_sun_fraction get_sun_fraction proc~row_ks->proc~get_sun_fraction proc~propagate_segment segment%propagate_segment proc~row_ks->proc~propagate_segment proc~set_segment_inputs segment%set_segment_inputs proc~row_ks->proc~set_segment_inputs apparent_position apparent_position proc~get_sun_fraction->apparent_position cubic_shadow_model cubic_shadow_model proc~get_sun_fraction->cubic_shadow_model from_j2000body_to_j2000ssb from_j2000body_to_j2000ssb proc~get_sun_fraction->from_j2000body_to_j2000ssb first_call first_call proc~propagate_segment->first_call icrf_frame icrf_frame proc~propagate_segment->icrf_frame integrate integrate proc~propagate_segment->integrate proc~identity_stm identity_stm proc~propagate_segment->proc~identity_stm proc~set_segment_outputs segment%set_segment_outputs proc~propagate_segment->proc~set_segment_outputs transform transform proc~propagate_segment->transform two_body_rotating_frame two_body_rotating_frame proc~propagate_segment->two_body_rotating_frame proc~set_segment_inputs->icrf_frame proc~set_segment_inputs->transform proc~set_segment_inputs->two_body_rotating_frame

Source Code

    subroutine eclipse_gjac(x, g, jac_val, accuracy, status, data)

    real(wp),dimension(:),intent(in)    :: x
    real(wp),dimension(:),intent(out)   :: g
    real(wp),dimension(:),intent(out)   :: jac_val
    integer,intent(in)                  :: accuracy
    integer,intent(inout)               :: status
    class(*),optional,intent(inout)     :: data

    real(wp),dimension(:),allocatable :: jac, ks, jr, w
    real(wp) :: rho, kmin
    integer :: k, j, o
    logical :: ok

    if (.not. present(data)) error stop 'eclipse_gjac: no data'
    select type (data)
    type is (eclipse_opt_data)
        ! (x here is the optimization's variable y = x/r: the columns are multiplied by r)
        if (data%mission%eclipse_opt_objective == 0) then
            g = zero
        else
            g = x - data%x0/data%r
        end if
        if (.not. epochs_in_range(data, x*data%r)) then
            jac_val = zero
            status = 1
            return
        end if
        call data%mission%compute_jacobian_stm(x*data%r, jac)  ! (also puts x in the segments)
        jac_val(1:data%nnz_halo) = jac * data%r(data%icol) * data%w(data%irow)
        allocate(ks(size(data%rows)), jr(sum(data%rows%ncol)))
        call eval_rows(data, ks, jr, ok=ok)
        if (.not. ok .or. any(data%mission%segs%failed)) status = 1
        call scale_row_columns(data, jr)
        if (data%single) then
            ! the aggregate's partials: the segment rows' partials, weighted by d(KS)/d(ks_k)
            rho  = data%mission%eclipse_opt_ks_rho
            kmin = minval(ks)
            w = exp(-rho*(ks - kmin))
            w = w / sum(w)
            jac_val(data%nnz_halo+1:) = zero
            o = 0
            do k = 1, size(data%rows)
                do j = 1, data%rows(k)%ncol
                    jac_val(data%nnz_halo + data%upos(o+j)) = jac_val(data%nnz_halo + data%upos(o+j)) + w(k)*jr(o+j)
                end do
                o = o + data%rows(k)%ncol
            end do
        else
            jac_val(data%nnz_halo+1:) = jr
        end if
    class default
        error stop 'eclipse_gjac: invalid data'
    end select

    end subroutine eclipse_gjac