equilibrate_scales Subroutine

public subroutine equilibrate_scales(me, x)

Set the opt var scales from the sensitivities (xscale_mode=2): the Jacobian is computed at x (as the solver does, see jacobian_mode), and each variable's scale is divided by the norm of its column, so the columns of the scaled Jacobian all have unit norm. A unit change of any scaled variable then gives the same size change in the (scaled) constraints, so the solver's minimum-norm steps weigh each variable by its effect, not its units. (With the scales from the magnitudes, the 1e5 km position scale makes the positions at periapsis, where they are most sensitive, the cheapest variables to change.) The epoch scales are also multiplied by epoch_scale_factor.

x (scaled), and the scaled perturbations for the finite differences, are updated for the new scales.

Type Bound

mission_type

Arguments

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

opt var vector (scaled): in with the old scales, out with the new


Calls

proc~~equilibrate_scales~~CallsGraph proc~equilibrate_scales mission_type%equilibrate_scales compute_jacobian compute_jacobian proc~equilibrate_scales->compute_jacobian proc~cache segment%cache proc~equilibrate_scales->proc~cache proc~compute_jacobian_stm mission_type%compute_jacobian_stm proc~equilibrate_scales->proc~compute_jacobian_stm proc~get_sparsity_pattern mission_type%get_sparsity_pattern proc~equilibrate_scales->proc~get_sparsity_pattern proc~uncache segment%uncache proc~equilibrate_scales->proc~uncache set_dpert set_dpert proc~equilibrate_scales->set_dpert proc~compute_jacobian_stm->proc~get_sparsity_pattern proc~define_problem_size mission_type%define_problem_size proc~compute_jacobian_stm->proc~define_problem_size proc~earth_moon_frame_matrices earth_moon_frame_matrices proc~compute_jacobian_stm->proc~earth_moon_frame_matrices proc~propagate_segment_stm segment%propagate_segment_stm proc~compute_jacobian_stm->proc~propagate_segment_stm proc~put_x_in_segments mission_type%put_x_in_segments proc~compute_jacobian_stm->proc~put_x_in_segments proc~removed_columns mission_type%removed_columns proc~compute_jacobian_stm->proc~removed_columns proc~get_sparsity_pattern->proc~define_problem_size proc~get_sparsity_pattern->proc~removed_columns get_rv get_rv proc~earth_moon_frame_matrices->get_rv get_rv_derivative get_rv_derivative proc~earth_moon_frame_matrices->get_rv_derivative proc~two_body_rotating_frame_matrices two_body_rotating_frame_matrices proc~earth_moon_frame_matrices->proc~two_body_rotating_frame_matrices proc~propagate_segment_stm->proc~earth_moon_frame_matrices first_call first_call proc~propagate_segment_stm->first_call icrf_frame icrf_frame proc~propagate_segment_stm->icrf_frame integrate integrate proc~propagate_segment_stm->integrate proc~ballistic_derivs ballistic_derivs proc~propagate_segment_stm->proc~ballistic_derivs proc~identity_stm identity_stm proc~propagate_segment_stm->proc~identity_stm proc~set_segment_outputs segment%set_segment_outputs proc~propagate_segment_stm->proc~set_segment_outputs transform transform proc~propagate_segment_stm->transform two_body_rotating_frame two_body_rotating_frame proc~propagate_segment_stm->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 get_acc get_acc proc~ballistic_derivs->get_acc get_r get_r proc~ballistic_derivs->get_r icrf_to_iau_moon icrf_to_iau_moon proc~ballistic_derivs->icrf_to_iau_moon j2000_to_frame j2000_to_frame proc~ballistic_derivs->j2000_to_frame proc~pines_gravity pines_gravity proc~ballistic_derivs->proc~pines_gravity proc~pointmass_gravity_gradient pointmass_gravity_gradient proc~ballistic_derivs->proc~pointmass_gravity_gradient proc~third_body_gravity_gradient third_body_gravity_gradient proc~ballistic_derivs->proc~third_body_gravity_gradient third_body_gravity third_body_gravity proc~ballistic_derivs->third_body_gravity proc~set_segment_inputs->icrf_frame proc~set_segment_inputs->transform proc~set_segment_inputs->two_body_rotating_frame proc~cross cross proc~two_body_rotating_frame_matrices->proc~cross proc~cross_matrix cross_matrix proc~two_body_rotating_frame_matrices->proc~cross_matrix proc~outer outer proc~pines_gravity->proc~outer proc~point_gradient point_gradient proc~pointmass_gravity_gradient->proc~point_gradient proc~third_body_gravity_gradient->proc~point_gradient proc~point_gradient->proc~outer

Called by

proc~~equilibrate_scales~~CalledByGraph proc~equilibrate_scales mission_type%equilibrate_scales proc~initialize_the_mission mission_type%initialize_the_mission proc~initialize_the_mission->proc~equilibrate_scales proc~initialize_the_solver my_solver_type%initialize_the_solver proc~initialize_the_solver->proc~initialize_the_mission proc~halo_solver_main halo_solver_main proc~halo_solver_main->proc~initialize_the_solver

Source Code

    subroutine equilibrate_scales(me,x)

    implicit none

    class(mission_type),intent(inout) :: me
    real(wp),dimension(:),intent(inout) :: x  !! opt var vector (scaled): in with the old scales, out with the new

    real(wp),dimension(:),allocatable :: jac  !! the nonzero Jacobian elements (scaled)
    real(wp),dimension(:),allocatable :: colnorm  !! norm of each column of the scaled Jacobian
    real(wp),dimension(:),allocatable :: x_unscaled, new_scale
    integer,dimension(:),allocatable :: irow, icol
    integer :: i, k

    write(*,'(A)') ' * Scaling the variables by their sensitivities (Jacobian at the initial guess)'

    do i = 1, size(me%segs)
        call me%segs(i)%cache()
    end do
    if (me%jacobian_mode==2) then
        call me%compute_jacobian_stm(x,jac)
    else
        call me%compute_jacobian(x,jac)
    end if
    do i = 1, size(me%segs)
        call me%segs(i)%uncache()
    end do

    call me%get_sparsity_pattern(irow,icol)
    allocate(colnorm(size(x)))
    colnorm = zero
    do k = 1, size(jac)
        colnorm(icol(k)) = colnorm(icol(k)) + jac(k)**2
    end do
    colnorm = sqrt(colnorm)

    allocate(new_scale(size(x)))
    do i = 1, size(x)
        if (colnorm(i) > zero) then
            new_scale(i) = me%xscale(i) / colnorm(i)
        else
            new_scale(i) = me%xscale(i)  ! (no constraint depends on it: keep it)
        end if
        if (me%x_is_epoch(i)) new_scale(i) = new_scale(i) * me%epoch_scale_factor
    end do

    ! x and the perturbations with the new scales:
    x_unscaled = x * me%xscale + me%xoffset
    me%dpert_ = me%dpert_ * me%xscale / new_scale  ! (dpert_ is scaled: the unscaled perturbations are kept)
    me%xscale = new_scale
    x = (x_unscaled - me%xoffset) / me%xscale
    call me%set_dpert(me%dpert_)

    end subroutine equilibrate_scales