eval_rows Subroutine

subroutine eval_rows(d, ks, jac, ok, only)

The eclipse rows (and, optionally, their partials, in the order of the rows' columns), for the x already in the segments. The rows (segments) are done in parallel.

Arguments

Type IntentOptional Attributes Name
type(eclipse_opt_data), intent(inout) :: d
real(kind=wp), intent(out), dimension(:) :: ks
real(kind=wp), intent(out), optional, dimension(:) :: jac
logical, intent(out), optional :: ok

false if a row couldn't be evaluated (see row_ks)

logical, intent(in), optional, dimension(:) :: only

evaluate only these rows (the others' ks are 0, and their partials are not set)


Calls

proc~~eval_rows~~CallsGraph proc~eval_rows eval_rows 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

Called by

proc~~eval_rows~~CalledByGraph proc~eval_rows eval_rows proc~eclipse_fc eclipse_fc proc~eclipse_fc->proc~eval_rows proc~eclipse_gjac eclipse_gjac proc~eclipse_gjac->proc~eval_rows proc~eclipse_optimize eclipse_optimize proc~eclipse_optimize->proc~eval_rows proc~newton_finish newton_finish proc~eclipse_optimize->proc~newton_finish proc~newton_finish->proc~eval_rows proc~newton_func newton_func proc~newton_finish->proc~newton_func proc~newton_func->proc~eval_rows proc~newton_grad newton_grad proc~newton_grad->proc~eval_rows interface~eclipse_optimize my_solver_type%eclipse_optimize interface~eclipse_optimize->proc~eclipse_optimize proc~halo_solver_main halo_solver_main proc~halo_solver_main->interface~eclipse_optimize

Source Code

    subroutine eval_rows(d, ks, jac, ok, only)

    type(eclipse_opt_data),intent(inout) :: d
    real(wp),dimension(:),intent(out) :: ks
    real(wp),dimension(:),intent(out),optional :: jac
    logical,intent(out),optional :: ok  !! false if a row couldn't be evaluated (see [[row_ks]])
    logical,dimension(:),intent(in),optional :: only !! evaluate only these rows (the others' `ks` are 0,
                                                     !! and their partials are not set)

    integer :: k, j, offset
    integer,dimension(:),allocatable :: first_nz  !! index in `jac` of each row's first nonzero, minus 1
    real(wp) :: t0, tf, dt, h, fp, fm
    real(wp),dimension(6) :: x0r, xp
    real(wp) :: tp0, tpf
    logical :: ok_k, all_ok

    allocate(first_nz(size(d%rows)))
    offset = 0
    do k = 1, size(d%rows)
        first_nz(k) = offset
        offset = offset + d%rows(k)%ncol
    end do
    h = d%mission%eclipse_opt_fd_step
    all_ok = .true.

!$OMP PARALLEL DO PRIVATE(k,j,t0,tf,dt,x0r,xp,tp0,tpf,fp,fm,ok_k) SCHEDULE(dynamic)
    do k = 1, size(d%rows)
        if (present(only)) then
            if (.not. only(k)) then
                ks(k) = zero
                cycle
            end if
        end if
        associate (row => d%rows(k), seg => d%mission%segs(d%rows(k)%iseg))
            t0  = seg%data%t0
            tf  = seg%data%tf
            x0r = seg%data%x0_rotating
            ks(k) = row_ks(d%mission, seg, row, t0, tf, x0r, ok_k)
            if (.not. ok_k) all_ok = .false.
            if (present(jac)) then
                do j = 1, row%ncol
                    dt = h * d%mission%xscale(row%col(j))  ! the unscaled change [days, km or km/s]
                    call perturbed(row, j, t0, tf, x0r, +dt, tp0, tpf, xp)
                    fp = row_ks(d%mission, seg, row, tp0, tpf, xp, ok_k)
                    if (.not. ok_k) all_ok = .false.
                    call perturbed(row, j, t0, tf, x0r, -dt, tp0, tpf, xp)
                    fm = row_ks(d%mission, seg, row, tp0, tpf, xp, ok_k)
                    if (.not. ok_k) all_ok = .false.
                    jac(first_nz(k)+j) = (fp - fm) / (2.0_wp*h)
                end do
            end if
        end associate
    end do
!$OMP END PARALLEL DO
    if (present(ok)) ok = all_ok

    contains

        pure subroutine perturbed(row, j, t0, tf, x0r, delta, tp0, tpf, xp)
        !! the segment's inputs with variable `j` of the row changed by `delta`
        !! (everything is passed in: an internal procedure would see the host's
        !! variables, not the OpenMP thread's private copies)
        type(eclipse_row),intent(in) :: row
        integer,intent(in) :: j
        real(wp),intent(in) :: t0, tf, delta
        real(wp),dimension(6),intent(in) :: x0r
        real(wp),intent(out) :: tp0, tpf
        real(wp),dimension(6),intent(out) :: xp
        tp0 = t0; tpf = tf; xp = x0r
        select case (row%kind(j))
        case (0)
            tp0 = t0 + delta
            if (row%tf_with_t0) tpf = tf + delta
        case (1:6)
            xp(row%kind(j)) = x0r(row%kind(j)) + delta
        end select
        end subroutine perturbed

    end subroutine eval_rows