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:
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.
| 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] |
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)
| 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 |
| integer, | public, | dimension(7) | :: | kind | = | 0 |
0: the start node's epoch, 1-6: its state |
the data the sqpopt functions need
| 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 |
||
| 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 |
||
| 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 |
|
| integer, | public, | dimension(:), allocatable | :: | ucol |
with |
||
| integer, | public, | dimension(:), allocatable | :: | upos |
with |
the Newton finish (see newton_finish): halo's continuity constraints, then the active eclipse rows as equalities
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| type(eclipse_opt_data), | public, | pointer | :: | d | => | null() | |
| integer, | public, | dimension(:), allocatable | :: | active |
the indices in |
||
| logical, | public, | dimension(:), allocatable | :: | mask |
the same, as a mask of |
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.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(eclipse_opt_data), | intent(in) | :: | d |
(allocatable: sized by the problem, so not on the stack)
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.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(eclipse_opt_data), | intent(in) | :: | d | |||
| real(kind=wp), | intent(in), | dimension(:) | :: | x |
The KS aggregate of values ks: .
Of the segments' KS rows, it is exactly the KS of all their samples.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=wp), | intent(in), | dimension(:) | :: | ks | ||
| real(kind=wp), | intent(in) | :: | rho |
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).
| Type | Intent | Optional | 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 |
The objective and the constraints for sqpopt: halo's continuity constraints, then the eclipse rows.
| Type | Intent | Optional | 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 |
The gradient of the objective and the Jacobian values for sqpopt: halo's analytic Jacobian, then the eclipse rows (central differences).
| Type | Intent | Optional | 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 |
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.
| Type | Intent | Optional | 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' |
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).
| Type | Intent | Optional | 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 |
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.
| Type | Intent | Optional | 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 |
The Newton finish's Jacobian: halo's analytic one, then the active eclipse rows (central differences, see eval_rows).
| Type | Intent | Optional | 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 |
The Newton finish's iteration printout.
| Type | Intent | Optional | 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 |
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.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(eclipse_opt_data), | intent(inout) | :: | d | |||
| real(kind=wp), | intent(in), | dimension(:) | :: | x |
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.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(eclipse_opt_data), | intent(inout) | :: | d |
Multiply the eclipse rows' partials by the optimization's variable scaling r.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(eclipse_opt_data), | intent(in) | :: | d | |||
| real(kind=wp), | intent(inout), | dimension(:) | :: | jac |
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).
| Type | Intent | Optional | 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) |
The variables a row of segment iseg depends on: the epoch and state of its start node.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | iseg | |||
| integer, | intent(in), | dimension(:) | :: | full2red | ||
| type(eclipse_row), | intent(inout) | :: | row |
Add the new rows: a segment already in the list gets the union of the sample ranges.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(eclipse_row), | intent(inout), | dimension(:), allocatable | :: | rows | ||
| type(eclipse_row), | intent(in), | dimension(:) | :: | new |
Print how far the optimization moved the solution.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(mission_type), | intent(inout) | :: | mission | |||
| real(kind=wp), | intent(in), | dimension(:) | :: | x0 | ||
| real(kind=wp), | intent(in), | dimension(:) | :: | x |
Move a converged solution out of the Earth's shadow (see the module documentation).
| Type | Intent | Optional | 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 |