iteration_trajectory Subroutine

public subroutine iteration_trajectory(me, x, iter)

Propagate the segments for the solver's current x, and send the trajectory (joined in time order) to the solver's iteration_callback.

Arguments

Type IntentOptional Attributes Name
class(my_solver_type), intent(inout) :: me
real(kind=wp), intent(in), dimension(:) :: x

the solver's (scaled) opt vars for this iteration

integer, intent(in) :: iter

iteration number


Calls

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

Called by

proc~~iteration_trajectory~~CalledByGraph proc~iteration_trajectory iteration_trajectory proc~halo_export halo_export proc~halo_export->proc~iteration_trajectory

Source Code

    subroutine iteration_trajectory(me,x,iter)

    implicit none

    class(my_solver_type),intent(inout) :: me
    real(wp),dimension(:),intent(in) :: x  !! the solver's (scaled) opt vars for this iteration
    integer,intent(in) :: iter  !! iteration number

    integer :: iseg, i, n, ntot, istart, iend, istep, nseg
    real(wp),dimension(:),allocatable :: et
    real(wp),dimension(:,:),allocatable :: r_rot, r_inr, r_se
    real(wp),dimension(:,:),allocatable :: seg_et  !! (2,nseg) each segment's start and end times
    real(wp),dimension(:,:,:),allocatable :: seg_rot, seg_inr, seg_se  !! (3,2,nseg) and positions
    real(wp),dimension(:,:),allocatable :: defects  !! (2,nseg/2) |dr|, |dv| at each interface
    real(wp),dimension(6) :: dx

    associate (segs => me%mission%segs)

        call me%mission%put_x_in_segments(x)  ! (the segments' initial states for this iteration)

!$OMP PARALLEL DO
        do iseg = 1, size(segs)
            call segs(iseg)%traj_inertial%destroy()
            call segs(iseg)%traj_rotating%destroy()
            call segs(iseg)%traj_se_rotating%destroy()
            call segs(iseg)%propagate(mode=2)  ! [export points]
        end do
!$OMP END PARALLEL DO

        nseg = size(segs)
        n = 0
        do iseg = 1, nseg
            n = n + size(segs(iseg)%traj_inertial%et)
        end do
        allocate(et(n), r_rot(3,n), r_inr(3,n), r_se(3,n))
        allocate(seg_et(2,nseg), seg_rot(3,2,nseg), seg_inr(3,2,nseg), seg_se(3,2,nseg))
        seg_et = 0.0_wp;  seg_rot = 0.0_wp;  seg_inr = 0.0_wp;  seg_se = 0.0_wp

        ntot = 0
        do iseg = 1, size(segs)
            associate (ti => segs(iseg)%traj_inertial, tr => segs(iseg)%traj_rotating, &
                       ts => segs(iseg)%traj_se_rotating)
                n = size(ti%et)
                if (n == 0) cycle
                ! the segment's start and end (as propagated):
                seg_et(1,iseg) = ti%et(1)
                seg_et(2,iseg) = ti%et(n)
                seg_inr(:,1,iseg) = [ti%x(1), ti%y(1), ti%z(1)]
                seg_inr(:,2,iseg) = [ti%x(n), ti%y(n), ti%z(n)]
                seg_rot(:,1,iseg) = [tr%x(1), tr%y(1), tr%z(1)]
                seg_rot(:,2,iseg) = [tr%x(n), tr%y(n), tr%z(n)]
                seg_se(:,1,iseg) = [ts%x(1), ts%y(1), ts%z(1)]
                seg_se(:,2,iseg) = [ts%x(n), ts%y(n), ts%z(n)]
                ! the joined trajectory:
                if (ti%et(n) >= ti%et(1)) then
                    istart = 1;  iend = n;  istep = 1     ! forward propagated
                else
                    istart = n;  iend = 1;  istep = -1    ! backward propagated
                end if
                do i = istart, iend, istep
                    if (ntot > 0) then
                        if (ti%et(i) <= et(ntot)) cycle   ! (the segments' shared ends)
                    end if
                    ntot = ntot + 1
                    et(ntot) = ti%et(i)
                    r_inr(:,ntot) = [ti%x(i), ti%y(i), ti%z(i)]
                    r_rot(:,ntot) = [tr%x(i), tr%y(i), tr%z(i)]
                    r_se(:,ntot) = [ts%x(i), ts%y(i), ts%z(i)]
                end do
            end associate
        end do

        do iseg = 1, size(segs)
            call segs(iseg)%traj_inertial%destroy()
            call segs(iseg)%traj_rotating%destroy()
            call segs(iseg)%traj_se_rotating%destroy()
        end do

        ! the defects: segments 2k-1 and 2k end at the same point (when solved)
        allocate(defects(2, nseg/2))
        do i = 1, nseg/2
            dx = segs(2*i-1)%data%xf_rotating - segs(2*i)%data%xf_rotating
            defects(1,i) = norm2(dx(1:3))
            defects(2,i) = norm2(dx(4:6))
        end do

    end associate

    call me%iteration_callback(iter, et(1:ntot), r_rot(:,1:ntot), r_inr(:,1:ntot), r_se(:,1:ntot), &
                               seg_et, seg_rot, seg_inr, seg_se, defects)

    end subroutine iteration_trajectory