halo_eclipse_opt_submodule Submodule

Eclipse optimization: moves a converged solution out of the Earth's shadow.

Starting from the converged solution x0, it finds the closest continuous trajectory (in halo's scaled variables) that stays out of the shadow near the eclipses:

  • minimize
  • subject to the continuity constraints (halo's)
  • and, for each segment that comes near the shadow,

with the SQP solver sqpopt. is the cubic shadow model (Williams et al., 2023), which is smooth inside and outside the shadow. are its values at samples every eclipse_opt_sample_step seconds from the segment's start, across the part of the segment near the shadow, and KS is their Kreisselmeier-Steinhauser aggregate , : a smooth lower bound of the smallest sample (within of it), so the constraint keeps every sample at or above . One row per segment, not one per sample: the samples of a segment all depend on the same few variables (its start node), and a row for each would make the QP's working sets dependent (sqpopt's direct method then cycles).

Following the 2023 paper's process, the constraints are added only where the trajectory comes near the shadow, and the trajectory is checked again after each optimization (with new rows where needed). Each pass ends with a Newton solve of the continuity constraints and the eclipse rows at their bound, as equalities (eclipse_opt_newton_finish), to bring the defects back to the usual level without undoing the eclipse fix.

The continuity rows of the Jacobian are halo's analytic ones. The eclipse rows (7 nonzeros each: the epoch and state of the segment's start node; the samples are at fixed offsets from the start) are computed by central differences, propagating only that segment.

See docs/eclipse_optimization_plan.md.


Uses

    • sqpopt_problem_module
    • sqpopt_options_module
    • sqpopt_module
    • sqpopt_qp_solver_module
    • iso_fortran_env
    • sqpopt_types_module
  • module~~halo_eclipse_opt_submodule~~UsesGraph module~halo_eclipse_opt_submodule halo_eclipse_opt_submodule iso_fortran_env iso_fortran_env module~halo_eclipse_opt_submodule->iso_fortran_env module~halo_module halo_module module~halo_eclipse_opt_submodule->module~halo_module sqpopt_module sqpopt_module module~halo_eclipse_opt_submodule->sqpopt_module sqpopt_options_module sqpopt_options_module module~halo_eclipse_opt_submodule->sqpopt_options_module sqpopt_problem_module sqpopt_problem_module module~halo_eclipse_opt_submodule->sqpopt_problem_module sqpopt_qp_solver_module sqpopt_qp_solver_module module~halo_eclipse_opt_submodule->sqpopt_qp_solver_module sqpopt_types_module sqpopt_types_module module~halo_eclipse_opt_submodule->sqpopt_types_module bspline_module bspline_module module~halo_module->bspline_module ddeabm_module ddeabm_module module~halo_module->ddeabm_module fortran_astrodynamics_toolkit fortran_astrodynamics_toolkit module~halo_module->fortran_astrodynamics_toolkit json_module json_module module~halo_module->json_module module~astro_partials_module astro_partials_module module~halo_module->module~astro_partials_module module~config_file_module config_file_module module~halo_module->module~config_file_module module~halo_utilities_module halo_utilities_module module~halo_module->module~halo_utilities_module module~parameters_module parameters_module module~halo_module->module~parameters_module module~splined_ephemeris_module splined_ephemeris_module module~halo_module->module~splined_ephemeris_module module~splined_moon_frame_module splined_moon_frame_module module~halo_module->module~splined_moon_frame_module module~text_buffer_module text_buffer_module module~halo_module->module~text_buffer_module nlesolver_module nlesolver_module module~halo_module->nlesolver_module numerical_differentiation_module numerical_differentiation_module module~halo_module->numerical_differentiation_module pyplot_module pyplot_module module~halo_module->pyplot_module module~halo_kinds_module halo_kinds_module module~astro_partials_module->module~halo_kinds_module module~config_file_module->json_module module~config_file_module->module~parameters_module module~halo_utilities_module->iso_fortran_env module~halo_utilities_module->fortran_astrodynamics_toolkit module~halo_utilities_module->module~parameters_module module~halo_utilities_module->module~splined_ephemeris_module module~halo_utilities_module->module~halo_kinds_module module~parameters_module->fortran_astrodynamics_toolkit module~parameters_module->module~halo_kinds_module module~splined_ephemeris_module->iso_fortran_env module~splined_ephemeris_module->bspline_module module~splined_ephemeris_module->fortran_astrodynamics_toolkit module~splined_ephemeris_module->module~halo_kinds_module module~splined_moon_frame_module->bspline_module csv_module csv_module module~splined_moon_frame_module->csv_module module~splined_moon_frame_module->module~halo_kinds_module module~text_buffer_module->iso_fortran_env ieee_arithmetic ieee_arithmetic module~text_buffer_module->ieee_arithmetic module~text_buffer_module->module~halo_kinds_module module~halo_kinds_module->iso_fortran_env

Variables

Type Visibility Attributes Name Initial
integer, private, parameter, dimension(8) :: start_node = [1, 2, 2, 3, 3, 4, 4, 5]
integer, private, parameter, dimension(8) :: tf_node = [1, 1, 3, 3, 3, 3, 5, 5]

Derived Types

type ::  eclipse_row

an eclipse constraint: the KS aggregate of the shadow function at the samples k_lo to k_hi of a segment (sample k is k*eclipse_opt_sample_step seconds from the segment's start, along its direction of propagation)

Components

Type Visibility Attributes Name Initial
integer, public :: iseg = 0
integer, public :: k_lo = 0
integer, public :: k_hi = 0
logical, public :: tf_with_t0 = .false.

if the segment's final epoch moves with its start node's epoch

integer, public :: ncol = 0

number of variables it depends on

integer, public, dimension(7) :: col = 0

their indices in x

integer, public, dimension(7) :: kind = 0

0: the start node's epoch, 1-6: its state

type ::  eclipse_opt_data

the data the sqpopt functions need

Components

Type Visibility Attributes Name Initial
type(mission_type), public, pointer :: mission => null()
real(kind=wp), public, dimension(:), allocatable :: x0

the solution before the optimization (scaled)

real(kind=wp), public, dimension(:), allocatable :: r

the optimization's variables are x/r (see eclipse_opt_epoch_scale)

type(eclipse_row), public, dimension(:), allocatable :: rows
integer, public :: m_halo = 0

number of halo's constraints

integer, public, dimension(:), allocatable :: icol

the columns of halo's Jacobian nonzeros

integer, public, dimension(:), allocatable :: irow

the rows of halo's Jacobian nonzeros

real(kind=wp), public, dimension(:), allocatable :: w

weights of halo's constraint rows in the optimization (see eclipse_opt_equilibrate; 1 otherwise)

integer, public :: nnz_halo = 0

number of nonzeros of halo's Jacobian

logical, public :: single = .false.

one eclipse row for all the segments: the KS aggregate of the segments' rows (see eclipse_opt_single_row)

integer, public, dimension(:), allocatable :: ucol

with single: the row's columns (the union of the segments')

integer, public, dimension(:), allocatable :: upos

with single: the index in ucol of each segment row's column

type, extends(nlesolver_type) ::  eclipse_newton_type

the Newton finish (see newton_finish): halo's continuity constraints, then the active eclipse rows as equalities

Components

Type Visibility Attributes Name Initial
type(eclipse_opt_data), public, pointer :: d => null()
integer, public, dimension(:), allocatable :: active

the indices in d%rows of the rows that are equalities

logical, public, dimension(:), allocatable :: mask

the same, as a mask of d%rows


Functions

function step_limits(d) result(lim)

The largest change of each of the optimization's variables in one sqpopt iteration (problem%set_max_step), from the limits in physical units (eclipse_opt_max_step_*): a variable's unscaled value is y*r*xscale (plus its offset), so its limit is limit/(r*xscale). A variable without a limit gets sqpopt_infinity.

Arguments

Type IntentOptional Attributes Name
type(eclipse_opt_data), intent(in) :: d

Return Value real(kind=wp), dimension(:), allocatable

(allocatable: sized by the problem, so not on the stack)

function epochs_in_range(d, x) result(ok)

If all the node epochs of x (halo's scaled variables) are within the range of the splined ephemeris (2 periods before the reference epoch to 2 periods after the last rev, see initialize_the_mission), less a margin of half a period. A trial point of the optimization can be far off.

Arguments

Type IntentOptional Attributes Name
type(eclipse_opt_data), intent(in) :: d
real(kind=wp), intent(in), dimension(:) :: x

Return Value logical

pure function ks_aggregate(ks, rho) result(agg)

The KS aggregate of values ks: . Of the segments' KS rows, it is exactly the KS of all their samples.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in), dimension(:) :: ks
real(kind=wp), intent(in) :: rho

Return Value real(kind=wp)

function row_ks(mission, seg, row, t0, tf, x0_rotating, ok) result(ks)

The KS aggregate of the shadow function at a row's samples, for the given start epoch, final epoch [days] and initial rotating-frame state (a copy of the segment is propagated, with output every eclipse_opt_sample_step seconds).

Arguments

Type IntentOptional Attributes Name
class(mission_type), intent(in) :: mission
type(segment), intent(in) :: seg
type(eclipse_row), intent(in) :: row
real(kind=wp), intent(in) :: t0
real(kind=wp), intent(in) :: tf
real(kind=wp), intent(in), dimension(6) :: x0_rotating
logical, intent(out) :: ok

false if the segment has none of the row's samples (e.g., a trial point that moved its epochs far): the row can't be evaluated there

Return Value real(kind=wp)


Subroutines

subroutine eclipse_fc(x, f, c, status, data)

The objective and the constraints for sqpopt: halo's continuity constraints, then the eclipse rows.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in), dimension(:) :: x
real(kind=wp), intent(out) :: f
real(kind=wp), intent(out), dimension(:) :: c
integer, intent(inout) :: status
class(*), intent(inout), optional :: data

subroutine eclipse_gjac(x, g, jac_val, accuracy, status, data)

The gradient of the objective and the Jacobian values for sqpopt: halo's analytic Jacobian, then the eclipse rows (central differences).

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in), dimension(:) :: x
real(kind=wp), intent(out), dimension(:) :: g
real(kind=wp), intent(out), dimension(:) :: jac_val
integer, intent(in) :: accuracy
integer, intent(inout) :: status
class(*), intent(inout), optional :: data

subroutine eval_rows(d, ks, jac, ok, only)

The eclipse rows (and, optionally, their partials, in the order of the rows' columns), for the x already in the segments. The rows (segments) are done in parallel.

Arguments

Type IntentOptional Attributes Name
type(eclipse_opt_data), intent(inout) :: d
real(kind=wp), intent(out), dimension(:) :: ks
real(kind=wp), intent(out), optional, dimension(:) :: jac
logical, intent(out), optional :: ok

false if a row couldn't be evaluated (see row_ks)

logical, intent(in), optional, dimension(:) :: only

evaluate only these rows (the others' ks are 0, and their partials are not set)

subroutine newton_finish(d, x)

The Newton finish (eclipse_opt_newton_finish): from the optimization's point, solve halo's continuity constraints and, as equalities , the eclipse rows that are at or near their bound ( plus eclipse_opt_newton_active_tol), with halo's minimum-norm Newton solver (nlesolver, with halo's sparse linear solver). The optimization's point is near feasible but its continuity isn't converged; a solve of the continuity alone (eclipse_opt_polish) moves the trajectory back into the shadow, but with the active rows held at their bound it can't. A row left free that falls below its bound is added to the equalities, and the solve repeated (from where it ended).

Arguments

Type IntentOptional Attributes Name
type(eclipse_opt_data), intent(inout), target :: d
real(kind=wp), intent(inout), dimension(:) :: x

the optimization's point (halo's scaled variables); replaced by the solution

subroutine newton_func(me, x, f)

The Newton finish's functions: halo's continuity constraints, then KS - phi_min of the active eclipse rows. A point that can't be evaluated (outside the splined ephemeris, or an integrator failure) gets large values, so the line search backs off.

Arguments

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

halo's scaled variables

real(kind=wp), intent(out), dimension(:) :: f

the functions

subroutine newton_grad(me, x, g)

The Newton finish's Jacobian: halo's analytic one, then the active eclipse rows (central differences, see eval_rows).

Arguments

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

halo's scaled variables

real(kind=wp), intent(out), dimension(:) :: g

the Jacobian's nonzeros

subroutine newton_export(me, x, f, iter)

The Newton finish's iteration printout.

Arguments

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

the variables

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

the functions

integer, intent(in) :: iter

the iteration

subroutine equilibrate(d, x)

Equilibrate the continuity Jacobian at x for the optimization (eclipse_opt_equilibrate): alternately normalize its rows (weights w) and its columns (the variables' factors r, the optimization's variables being x/r), a few times, so that the rows and the columns all have 2-norms near 1. This lowers the condition number of the KKT systems of sqpopt's QP subproblems (for 100 revolutions, J's condition number goes from 8e4 to 7e2). The objective, |x/r - x0/r|^2/2, is then measured in these units.

Arguments

Type IntentOptional Attributes Name
type(eclipse_opt_data), intent(inout) :: d
real(kind=wp), intent(in), dimension(:) :: x

subroutine union_columns(d)

With single: the columns of the single eclipse row (the union of the segment rows'), and where each segment row's column is in them.

Arguments

Type IntentOptional Attributes Name
type(eclipse_opt_data), intent(inout) :: d

subroutine scale_row_columns(d, jac)

Multiply the eclipse rows' partials by the optimization's variable scaling r.

Arguments

Type IntentOptional Attributes Name
type(eclipse_opt_data), intent(in) :: d
real(kind=wp), intent(inout), dimension(:) :: jac

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)

subroutine row_columns(iseg, full2red, row)

The variables a row of segment iseg depends on: the epoch and state of its start node.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: iseg
integer, intent(in), dimension(:) :: full2red
type(eclipse_row), intent(inout) :: row

subroutine merge_rows(rows, new)

Add the new rows: a segment already in the list gets the union of the sample ranges.

Arguments

Type IntentOptional Attributes Name
type(eclipse_row), intent(inout), dimension(:), allocatable :: rows
type(eclipse_row), intent(in), dimension(:) :: new

subroutine report_change(mission, x0, x)

Print how far the optimization moved the solution.

Arguments

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

Module Subroutines

module subroutine eclipse_optimize(me, x)

Move a converged solution out of the Earth's shadow (see the module documentation).

Arguments

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

the converged solution (scaled); replaced by the result