write_solution_plot_data Subroutine

public subroutine write_solution_plot_data(me, filename, x_guess, x)

Write the data for the solution plots (generate_solution_plots, see python/plot_solution.py): for the initial guess and the solution, the epochs at the constraint points (where segments 2k-1 and 2k end) and the defects there (|dr|, |dv| in the rotating frame). The segments are left with the solution.

Type Bound

mission_type

Arguments

Type IntentOptional Attributes Name
class(mission_type), intent(inout) :: me
character(len=*), intent(in) :: filename

the JSON file to write

real(kind=wp), intent(in), dimension(:) :: x_guess

the initial guess (scaled)

real(kind=wp), intent(in), dimension(:) :: x

the solution (scaled)


Calls

proc~~write_solution_plot_data~~CallsGraph proc~write_solution_plot_data mission_type%write_solution_plot_data add add proc~write_solution_plot_data->add destroy destroy proc~write_solution_plot_data->destroy initialize initialize proc~write_solution_plot_data->initialize proc~constraint_violations mission_type%constraint_violations proc~write_solution_plot_data->proc~constraint_violations proc~define_problem_size mission_type%define_problem_size proc~write_solution_plot_data->proc~define_problem_size proc~get_case_name mission_type%get_case_name proc~write_solution_plot_data->proc~get_case_name proc~get_problem_arrays mission_type%get_problem_arrays proc~constraint_violations->proc~get_problem_arrays proc~propagate_segment segment%propagate_segment proc~constraint_violations->proc~propagate_segment proc~put_x_in_segments mission_type%put_x_in_segments proc~constraint_violations->proc~put_x_in_segments proc~segs_to_propagate mission_type%segs_to_propagate proc~constraint_violations->proc~segs_to_propagate proc~int_to_string int_to_string proc~get_case_name->proc~int_to_string fill_vector fill_vector proc~get_problem_arrays->fill_vector proc~compute_rdot compute_rdot proc~get_problem_arrays->proc~compute_rdot 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~segs_to_propagate->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~~write_solution_plot_data~~CalledByGraph proc~write_solution_plot_data mission_type%write_solution_plot_data proc~halo_solver_main halo_solver_main proc~halo_solver_main->proc~write_solution_plot_data

Source Code

    subroutine write_solution_plot_data(me, filename, x_guess, x)

    class(mission_type),intent(inout) :: me
    character(len=*),intent(in) :: filename  !! the JSON file to write
    real(wp),dimension(:),intent(in) :: x_guess  !! the initial guess (scaled)
    real(wp),dimension(:),intent(in) :: x  !! the solution (scaled)

    type(json_file) :: json
    real(wp),dimension(:),allocatable :: f, et_g, dr_g, dv_g, et_s, dr_s, dv_s
    integer :: m, n_segs

    call me%define_problem_size(m=m, n_segs=n_segs)
    allocate(f(m))
    call evaluate(x_guess, et_g, dr_g, dv_g)
    call evaluate(x, et_s, dr_s, dv_s)  ! (last: the segments are left with the solution)

    call json%initialize(compress_vectors=.true.)
    call json%add('case',        me%get_case_name())
    call json%add('et_ref',      me%et_ref)
    call json%add('n_revs',      me%n_revs)
    call json%add('epoch_variable_mode', me%epoch_variable_mode)
    call json%add('xscale_mode', me%xscale_mode)
    call json%add('jacobian_mode', me%jacobian_mode)
    call json%add('et_guess',    et_g)  ! [sec]
    call json%add('dr_guess',    dr_g)  ! [km]
    call json%add('dv_guess',    dv_g)  ! [km/s]
    call json%add('et_solution', et_s)
    call json%add('dr_solution', dr_s)
    call json%add('dv_solution', dv_s)
    call json%print(filename)
    call json%destroy()

    contains

        subroutine evaluate(xx, et, dr, dv)
            !! the epochs and defects at the constraint points for `xx`
            real(wp),dimension(:),intent(in) :: xx
            real(wp),dimension(:),allocatable,intent(out) :: et, dr, dv
            integer :: k
            call me%constraint_violations(xx, f)  ! (propagates all the segments)
            f = f * me%fscale  ! (unscaled: km and km/s)
            allocate(et(n_segs/2), dr(n_segs/2), dv(n_segs/2))
            do k = 1, n_segs/2
                associate (seg => me%segs(2*k-1))
                    et(k) = seg%data%et_ref + seg%data%tf*day2sec
                end associate
                dr(k) = norm2(f(6*k-5:6*k-3))
                dv(k) = norm2(f(6*k-2:6*k))
            end do
        end subroutine evaluate

    end subroutine write_solution_plot_data