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.
Nodes of different colours represent the following:
Solid arrows point from a procedure to one which it calls. Dashed
arrows point from an interface to procedures which implement that interface.
This could include the module procedures in a generic interface or the
implementation in a submodule of an interface in a parent module.
Nodes of different colours represent the following:
Solid arrows point from a procedure to one which it calls. Dashed
arrows point from an interface to procedures which implement that interface.
This could include the module procedures in a generic interface or the
implementation in a submodule of an interface in a parent module.
Source Code
subroutine equilibrate_scales(me,x)implicit none class(mission_type),intent(inout)::mereal(wp),dimension(:),intent(inout)::x!! opt var vector (scaled): in with the old scales, out with the newreal(wp),dimension(:),allocatable::jac!! the nonzero Jacobian elements (scaled)real(wp),dimension(:),allocatable::colnorm!! norm of each column of the scaled Jacobianreal(wp),dimension(:),allocatable::x_unscaled,new_scaleinteger,dimension(:),allocatable::irow,icolinteger::i,kwrite(*,'(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=zerodo k=1,size(jac)colnorm(icol(k))=colnorm(icol(k))+jac(k)**2end docolnorm=sqrt(colnorm)allocate(new_scale(size(x)))do i=1,size(x)if(colnorm(i)>zero)thennew_scale(i)=me%xscale(i)/colnorm(i)elsenew_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_factorend do! x and the perturbations with the new scales:x_unscaled=x*me%xscale+me%xoffsetme%dpert_=me%dpert_*me%xscale/new_scale! (dpert_ is scaled: the unscaled perturbations are kept)me%xscale=new_scalex=(x_unscaled-me%xoffset)/me%xscalecall me%set_dpert(me%dpert_)end subroutine equilibrate_scales