find_rows Subroutine

subroutine find_rows(mission, x, rows, phimin, shadow_min)

Check the shadow function along the whole trajectory (every eclipse_opt_detect_step seconds), and make the rows of the segments that come near the shadow (where the shadow function, with the constraints' bubble, is below eclipse_opt_detect_phi).

Arguments

Type IntentOptional Attributes Name
class(mission_type), intent(inout) :: mission
real(kind=wp), intent(in), dimension(:) :: x
type(eclipse_row), intent(out), dimension(:), allocatable :: rows
real(kind=wp), intent(out) :: phimin

the smallest shadow function (no bubble) along the trajectory

real(kind=wp), intent(out) :: shadow_min

the time in the shadow [min] (approximate: the number of points in the shadow times the step)


Calls

proc~~find_rows~~CallsGraph proc~find_rows find_rows proc~define_problem_size mission_type%define_problem_size proc~find_rows->proc~define_problem_size proc~destroy_trajectory trajectory%destroy_trajectory proc~find_rows->proc~destroy_trajectory proc~get_sun_fraction get_sun_fraction proc~find_rows->proc~get_sun_fraction proc~propagate_segment segment%propagate_segment proc~find_rows->proc~propagate_segment proc~put_x_in_segments mission_type%put_x_in_segments proc~find_rows->proc~put_x_in_segments proc~removed_columns mission_type%removed_columns proc~find_rows->proc~removed_columns proc~row_columns row_columns proc~find_rows->proc~row_columns 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~put_x_in_segments->proc~define_problem_size extract_vector extract_vector proc~put_x_in_segments->extract_vector proc~set_segment_inputs segment%set_segment_inputs proc~put_x_in_segments->proc~set_segment_inputs proc~removed_columns->proc~define_problem_size proc~set_segment_inputs->icrf_frame proc~set_segment_inputs->transform proc~set_segment_inputs->two_body_rotating_frame

Called by

proc~~find_rows~~CalledByGraph proc~find_rows find_rows proc~eclipse_optimize eclipse_optimize proc~eclipse_optimize->proc~find_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 find_rows(mission, x, rows, phimin, shadow_min)

    class(mission_type),intent(inout) :: mission
    real(wp),dimension(:),intent(in) :: x
    type(eclipse_row),dimension(:),allocatable,intent(out) :: rows
    real(wp),intent(out) :: phimin      !! the smallest shadow function (no bubble) along the trajectory
    real(wp),intent(out) :: shadow_min  !! the time in the shadow [min] (approximate: the number of points
                                        !! in the shadow times the step)

    integer :: n_segs, iseg, i, n, n_full, nk, kmax, nr
    real(wp),dimension(:),allocatable :: seg_phimin, seg_lo, seg_hi
    integer,dimension(:),allocatable :: seg_nshadow, full2red, removed
    logical,dimension(:),allocatable :: seg_near
    real(wp) :: dt, phi0, phib, step
    real(wp),dimension(6) :: rv

    call mission%define_problem_size(n_segs=n_segs)
    call mission%define_problem_size(n=n_full, full_problem=.true.)
    call mission%put_x_in_segments(x)

    allocate(seg_phimin(n_segs), seg_lo(n_segs), seg_hi(n_segs), seg_nshadow(n_segs), seg_near(n_segs))
    seg_phimin = huge(one); seg_lo = huge(one); seg_hi = -huge(one); seg_nshadow = 0; seg_near = .false.

!$OMP PARALLEL DO PRIVATE(iseg,i,n,dt,phi0,phib,rv) SCHEDULE(dynamic)
    do iseg = 1, n_segs
        associate (seg => mission%segs(iseg))
            call seg%traj_inertial%destroy()
            call seg%traj_rotating%destroy()
            call seg%traj_se_rotating%destroy()
            call seg%propagate(mode=2, tstep=mission%eclipse_opt_detect_step)
            n = size(seg%traj_inertial%et)
            do i = 1, n
                rv = [seg%traj_inertial%x(i),  seg%traj_inertial%y(i),  seg%traj_inertial%z(i), &
                      seg%traj_inertial%vx(i), seg%traj_inertial%vy(i), seg%traj_inertial%vz(i)]
                phi0 = get_sun_fraction(seg%eph, seg%traj_inertial%et(i), rv, zero)
                if (mission%eclipse_opt_bubble > zero) then
                    phib = get_sun_fraction(seg%eph, seg%traj_inertial%et(i), rv, mission%eclipse_opt_bubble)
                else
                    phib = phi0
                end if
                seg_phimin(iseg) = min(seg_phimin(iseg), phi0)
                if (phi0 < zero) seg_nshadow(iseg) = seg_nshadow(iseg) + 1
                if (phib < mission%eclipse_opt_detect_phi) then
                    dt = abs(seg%traj_inertial%et(i) - seg%traj_inertial%et(1))  ! [sec from the start]
                    seg_near(iseg) = .true.
                    seg_lo(iseg) = min(seg_lo(iseg), dt)
                    seg_hi(iseg) = max(seg_hi(iseg), dt)
                end if
            end do
            call seg%traj_inertial%destroy()
            call seg%traj_rotating%destroy()
            call seg%traj_se_rotating%destroy()
        end associate
    end do
!$OMP END PARALLEL DO

    phimin = minval(seg_phimin)
    shadow_min = real(sum(seg_nshadow),wp) * mission%eclipse_opt_detect_step / 60.0_wp

    ! the map from the full problem's columns to x:
    removed = mission%removed_columns()
    allocate(full2red(n_full))
    full2red = 0
    nk = 0
    do i = 1, n_full
        if (any(removed==i)) cycle
        nk = nk + 1
        full2red(i) = nk
    end do

    ! the rows: the samples across the near-shadow part of each flagged segment, padded by one
    ! sample on each side (and not past the segment's last full step)
    step = mission%eclipse_opt_sample_step
    allocate(rows(count(seg_near)))
    nr = 0
    do iseg = 1, n_segs
        if (.not. seg_near(iseg)) cycle
        associate (seg => mission%segs(iseg))
            kmax = floor(abs(seg%data%tf - seg%data%t0)*day2sec/step - 1.0e-6_wp)
            nr = nr + 1
            rows(nr)%iseg = iseg
            rows(nr)%k_lo = max(0, floor(seg_lo(iseg)/step) - 1)
            rows(nr)%k_hi = min(kmax, ceiling(seg_hi(iseg)/step) + 1)
            call row_columns(iseg, full2red, rows(nr))
        end associate
    end do

    end subroutine find_rows