mission_type Derived Type

type, public, extends(numdiff_type) :: mission_type

the mission [this is a numdiff_type for organizational purposes.... rethink this maybe ...


Inherits

type~~mission_type~~InheritsGraph type~mission_type mission_type geopotential_model_pines geopotential_model_pines type~mission_type->geopotential_model_pines grav jpl_ephemeris jpl_ephemeris type~mission_type->jpl_ephemeris eph numdiff_type numdiff_type type~mission_type->numdiff_type type~moon_pa_frame moon_pa_frame type~mission_type->type~moon_pa_frame moon_pa type~patch_point patch_point type~mission_type->type~patch_point periapsis, quarter, apoapsis type~segment segment type~mission_type->type~segment segs type~segment->geopotential_model_pines grav type~segment->jpl_ephemeris eph type~segment->type~moon_pa_frame moon_pa ddeabm_class ddeabm_class type~segment->ddeabm_class type~segment_data segment_data type~segment->type~segment_data data, cached_data type~trajectory trajectory type~segment->type~trajectory traj_inertial, traj_rotating, traj_se_rotating

Inherited by

type~~mission_type~~InheritedByGraph type~mission_type mission_type type~eclipse_opt_data eclipse_opt_data type~eclipse_opt_data->type~mission_type mission type~my_solver_type my_solver_type type~my_solver_type->type~mission_type mission type~eclipse_newton_type eclipse_newton_type type~eclipse_newton_type->type~eclipse_opt_data d

Components

Type Visibility Attributes Name Initial
character(len=:), public, allocatable :: initial_guess_from_file

to read the initial guess from a JSOn file

logical, public :: use_splined_ephemeris = .false.

if true, the ephemeris is splined

real(kind=wp), public :: dt_spline_sec = 3600.0_wp

time step in seconds for spline step [1 hr]

logical, public :: pointmass_central_body = .false.

if true, the central body is a pointmass (moon). otherwise, the grav model is used.

type(geopotential_model_pines), public, pointer :: grav => null()

central body geopotential model [global]

class(jpl_ephemeris), public, pointer :: eph => null()

the ephemeris [global]

type(moon_pa_frame), public, pointer :: moon_pa => null()

the moon_pa frame interpolater [global]

logical, public :: include_pointmass_earth = .true.

if true, earth is included as a pointmass in the force model

logical, public :: include_pointmass_sun = .true.

if true, sun is included as a pointmass in the force model

logical, public :: include_pointmass_jupiter = .false.

if true, jupiter is included as a pointmass in the force model

type(segment), public, dimension(:), allocatable :: segs

the list of segments

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

opt var scale factors

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

opt var dpert factors [rename because already in base class]

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

function scale factors

character(len=20), public, dimension(:), allocatable :: xname

opt var names

character(len=:), public, allocatable :: N_or_S

'N' or 'S'

character(len=:), public, allocatable :: L1_or_L2

'L1' or 'L2'

logical, public :: solve = .true.

run the nle solver to solve the problem

logical, public :: generate_plots = .true.

to generate the python plots

logical, public :: generate_trajectory_files = .true.

to export the txt trajectory files.

logical, public :: generate_json_trajectory_file = .false.

to export the JSON trajectory file for the solution (contains inertial and rotating data). This one is used by the PyVista python script for plotting

logical, public :: generate_guess_and_solution_files = .true.

to export the json guess and solution files.

logical, public :: generate_kernel = .false.

to generate a spice kernel (bsp) of the solution [this requires the external mkspk SPICE tool]

logical, public :: generate_solution_plots = .false.

write the solution's plot data (solution_plot_data_*.json: the epochs and defects at the constraint points, for the initial guess and the solution) and run python/plot_solution.py on it (matplotlib: the epoch drift and defect plots, *.pdf and *.png)

logical, public :: generate_defect_file = .false.

generate the file that shows the pos/vel constraint defects for the solution

logical, public :: generate_eclipse_files = .false.

generate the eclipse data file for the solution

logical, public :: run_pyvista_script = .false.

run the pyvista script to generate the interacdtive 3d plot

logical, public :: generate_rp_ra_file = .false.

to generate the rp_ra file

real(kind=wp), public :: r_eclipse_bubble = 0.0_wp

radius of the "eclipse bubble" [km]

logical, public :: eclipse_optimization = .false.

after the solve, move the solution out of the Earth's shadow: the closest continuous trajectory with the shadow function at least eclipse_opt_phi_min near the eclipses (solved with sqpopt)

real(kind=wp), public :: eclipse_opt_phi_min = 0.05_wp

the shadow function required at the constraint samples (>0: a margin)

real(kind=wp), public :: eclipse_opt_bubble = 0.0_wp

eclipse bubble radius for the constraints [km]

real(kind=wp), public :: eclipse_opt_detect_phi = 0.3_wp

segments whose shadow function falls below this get an eclipse constraint

real(kind=wp), public :: eclipse_opt_detect_step = 300.0_wp

time step for checking the shadow function along the trajectory [sec]

real(kind=wp), public :: eclipse_opt_sample_step = 300.0_wp

spacing of the constraint samples [sec]

integer, public :: eclipse_opt_max_outer = 3

maximum number of passes (find the eclipses, optimize, check)

logical, public :: eclipse_opt_polish = .false.

re-converge the continuity with the Newton solver after each optimization (continuity only: only for a converged optimization, whose point is already feasible; from an unconverged one it undoes the eclipse fix)

logical, public :: eclipse_opt_newton_finish = .true.

after each optimization, a Newton solve of the continuity constraints and, as equalities (KS = eclipse_opt_phi_min), the eclipse rows that are at or near their bound (see eclipse_opt_newton_active_tol): converges the continuity without undoing the eclipse fix

real(kind=wp), public :: eclipse_opt_newton_active_tol = 0.02_wp

the Newton finish's equalities: the eclipse rows with KS below eclipse_opt_phi_min plus this (a row that falls below its bound in the finish is added, and the finish repeated)

integer, public :: eclipse_opt_newton_max_iter = 50

maximum number of iterations of each Newton finish

integer, public :: eclipse_opt_newton_solver_mode = 0

the Newton finish's sparse linear solver (nlesolver's sparsity_mode: 2-4, 6 or 7); 0: halo's solver_mode

real(kind=wp), public :: eclipse_opt_newton_damp = 1.0e-4_wp

the Newton finish's first damping (nlesolver's damp: LSQR, LSMR, CRAIG and the Cholesky solver). The eclipse rows at their bound are nearly dependent on the continuity rows, so the undamped steps are long and fail: the finish is done in stages, the damping divided by 10 each stage, to 0

integer, public :: eclipse_opt_newton_damp_iter = 3

maximum number of iterations of each damped stage

integer, public :: eclipse_opt_objective = 1

the optimization's objective: 1 - |x - x0|^2/2 (the closest solution to the start); 0 - none (a feasibility problem, as SNOPT's feasible point mode)

logical, public :: sqpopt_solve = .false.

TEMPORARY experiment: solve the problem with sqpopt (as the eclipse optimization, with no eclipse rows) instead of nlesolver

integer, public :: eclipse_opt_newton_max_active = -1

TEMPORARY experiment: hold only this many rows (the smallest KS); <0: off

real(kind=wp), public :: eclipse_opt_newton_damp_min = 1.0e-9_wp

below this, the damping is 0 (the last stage)

real(kind=wp), public :: eclipse_opt_fd_step = 1.0e-6_wp

central-difference step for the eclipse constraint rows (scaled variables)

real(kind=wp), public :: eclipse_opt_max_step_epoch = -1.0_wp

largest change of a node epoch in one sqpopt iteration [days] (sqpopt's set_max_step; <=0: no limit)

real(kind=wp), public :: eclipse_opt_max_step_position = -1.0_wp

largest change of a node position component [km] (<=0: no limit)

real(kind=wp), public :: eclipse_opt_max_step_velocity = -1.0_wp

largest change of a node velocity component [km/s] (<=0: no limit)

logical, public :: eclipse_opt_equilibrate = .false.

solve the optimization with the continuity Jacobian equilibrated (its rows and columns normalized, at the converged solution), which lowers the condition number of sqpopt's QP subproblems. The objective is then measured in those units

logical, public :: eclipse_opt_single_row = .false.

one eclipse constraint for all the segments near the shadow (the KS aggregate of the segments' rows: exactly the KS of all their samples), instead of one per segment

real(kind=wp), public :: eclipse_opt_ks_rho = 100.0_wp

the KS aggregate's parameter: the constraint is within ln(N)/rho of the smallest of a segment's N samples (and below it)

integer, public :: eclipse_opt_max_iter = 100
integer, public :: eclipse_opt_print_level = 1
integer, public :: eclipse_opt_hessian_mode = 1

1: BFGS, 2: SR1

logical, public :: eclipse_opt_direct_qp = .true.
logical, public :: eclipse_opt_direct_least_squares = .true.
real(kind=wp), public :: eclipse_opt_direct_tol = 1.0e-8_wp

sqpopt qp_solver%direct_tol: the direct QP method's relative tolerance for a violated row (and for the working set's rows)

logical, public :: eclipse_opt_direct_relative_tol = .false.

sqpopt qp_solver%direct_relative_tol

logical, public :: eclipse_opt_direct_accept_inexact = .false.

sqpopt qp_solver%direct_accept_inexact

logical, public :: eclipse_opt_basis_repair = .false.

sqpopt qp_solver%sparse_qp%basis_repair

real(kind=wp), public :: eclipse_opt_basis_rel_tol = 1.0e-8_wp

sqpopt qp_solver%sparse_qp%basis_rel_tol

real(kind=wp), public :: eclipse_opt_basis_eq_slack_weight = 1.0e-6_wp

sqpopt qp_solver%sparse_qp%basis_eq_slack_weight

integer, public :: eclipse_opt_linear_solver = 2

sqpopt linear_solver: 1 MUMPS (needs a build with HAS_MUMPS), 2 QDLDL (the default), 3 dense, 4 LAPACK (see sqpopt_symmetric_solver_module)

integer, public :: eclipse_opt_factorization_threads = 1

sqpopt factorization_threads (MUMPS only)

integer, public :: eclipse_opt_direct_max_changes = 1000

sqpopt qp_solver%direct_max_changes: changes of the working set the direct QP method may make before it gives up

integer, public :: eclipse_opt_qp_solver_mode = 0

0: auto, 2: dense, 3: sparse (reduced Hessian), 4: DAQP

integer, public :: eclipse_opt_linesearch_mode = 4

1: Armijo, 2: exact, 3: watchdog, 4: filter, 5: funnel

integer, public :: eclipse_opt_lbfgs_memory = 0
real(kind=wp), public :: eclipse_opt_elastic_multiplier_limit = 0.0_wp

sqpopt elastic_multiplier_limit (0: no elastic re-solves, which skip the direct QP method)

logical, public :: eclipse_opt_scaling = .false.

(halo's variables and constraints are already scaled)

real(kind=wp), public :: eclipse_opt_scaling_max_gradient = 100.0_wp
real(kind=wp), public :: eclipse_opt_hessian_scale0 = 1.0_wp
logical, public :: eclipse_opt_inertia_control = .false.
integer, public :: eclipse_opt_merit_mode = 1

1: l1, 2: augmented Lagrangian

integer, public :: eclipse_opt_restoration_mode = 1

1: restoration phase, 2: Gauss-Newton step

real(kind=wp), public :: eclipse_opt_qp_max_step = 2.0_wp

sqpopt qp_solver%max_step: cap on the 2-norm of the step

real(kind=wp), public :: eclipse_opt_max_time = 0.0_wp

sqpopt max_time [sec] (0: no limit)

real(kind=wp), public :: eclipse_opt_epoch_scale = -1.0_wp

scale of the epoch variables in the optimization [days] (<0: halo's own, epoch_scale). It also sets how much an epoch change costs in the objective

real(kind=wp), public :: eclipse_opt_ctol = 1.0e-10_wp
real(kind=wp), public :: eclipse_opt_ktol = 1.0e-6_wp
real(kind=wp), public :: eclipse_dt_step = 3600.0_wp

dense time step output for eclipse calculations in sec [1 hour]

integer, public :: eclipse_filetype = 1

type of eclipse file: 1=csv or 2=json

logical, public :: eclipse_file_se_positions = .true.

for the JSON eclipse file: also write the Sun-Earth rotating frame positions of the points (for plotting; false gives a smaller file, faster to write and read)

integer, public :: epoch_mode = 1

1 - calendar date was specified, 2 - ephemeris time was specified

integer, public :: year = 0

epoch of first point (first periapsis crossing)

integer, public :: month = 0

epoch of first point (first periapsis crossing)

integer, public :: day = 0

epoch of first point (first periapsis crossing)

integer, public :: hour = 0

epoch of first point (first periapsis crossing)

integer, public :: minute = 0

epoch of first point (first periapsis crossing)

real(kind=wp), public :: sec = zero

epoch of first point (first periapsis crossing)

real(kind=wp), public :: et_ref = zero

ephemeris time reference epoch [sec] (all times relative to this). this is computed from the year,month,day,hour,minute,sec values if epoch_mode=1

integer, public :: n_revs = 10

Number of revs in the Halo.

real(kind=wp), public :: rtol = 1.0e-12_wp

integrator rtol

real(kind=wp), public :: atol = 1.0e-12_wp

integrator atol

real(kind=wp), public :: nlesolver_tol = 1.0e-6_wp

nlesolver tol

real(kind=wp), public :: nlesolver_tolx = 1.0e-8_wp

nlesolver tolerance for the change in the (scaled) x: the solve stops when a step changes no variable by more (make it smaller for a refinement from a converged solution, whose steps are tiny)

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

if fix_initial_r is True, this can be used to specify the initial r (moon-centered earth-moon rotating frame)

character(len=:), public, allocatable :: ephemeris_file

the JPL ephemeris file to load

character(len=:), public, allocatable :: gravfile

spherical harmonic gravity coeff file (Moon) example: 'data/grav/gggrx_0020pm_sha.tab'

character(len=:), public, allocatable :: moon_pa_file

file for moon_pa frame. example: data/moon_pa_2000_2100.csv

character(len=:), public, allocatable :: patch_point_file

Halo CR3BP patch point solution file example: 'data/L2_halos.json'

logical, public :: patch_point_file_is_periapsis = .false.

if the state in the patch point file are periapsis states (false means they are apoapsis states. the ones in L2_halos.json are apoapsis states)

type(patch_point), public :: periapsis

Patchpoint Periapse State

type(patch_point), public :: quarter

Patchpoint 1/4 Rev State

type(patch_point), public :: apoapsis

Patchpoint 1/2 Rev State

real(kind=wp), public :: period = 0.0_wp

Halo period [days]

real(kind=wp), public :: period8 = 0.0_wp

1/8 of Halo period [days]

logical, public :: fix_initial_time = .false.

to fix the initial epoch in the mission

logical, public :: fix_initial_r = .false.

fix the initial periapsis position vector (x,y,z)

integer, public :: fix_ry_at_end_of_rev = 0

fix ry at the end of the specified rev (at periapsis) not used if <= 0.

logical, public :: fix_final_ry_and_vx = .false.

fix ry and vx at the end of the last rev (at periapsis)

logical, public :: constrain_initial_rdot = .false.

impose an rdot=0 constraint on the initial point

integer, public :: solver_mode = 1

use sparse or dense solver:

  • 1 - dense (LAPACK)
  • 2 - sparse (LSQR)
  • 3 - sparse (LUSOL)
  • 4 - sparse (LMSR)
  • 5 - sparse (qr_mumps)
  • 6 - sparse (CRAIG)
  • 7 - sparse (direct)
integer, public :: jacobian_mode = 1

how the Jacobian is computed:

  • 1 - finite differences (central differences, see halo_grad_sparse)
  • 2 - analytic: the state transition matrix is integrated with each segment, and the time partials are computed analytically (see compute_jacobian_stm). Requires use_splined_ephemeris.
real(kind=wp), public :: stm_rtol = -1.0_wp

integrator rtol for the STM (<0: use rtol)

real(kind=wp), public :: stm_atol = -1.0_wp

integrator atol for the STM (<0: use atol)

logical, public :: func_with_stm = .false.

(jacobian_mode=2) propagate the segments with their STMs in every function evaluation, and keep the Jacobian, so that the solver's next Jacobian request at the same x needs no propagation (see halo_func)

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

for func_with_stm: the x of jac_cache

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

for func_with_stm: the Jacobian at jac_cache_x

integer, public :: epoch_variable_mode = 1

the epoch variables (each node's epoch) in the x vector:

  • 1 - the epochs (days from the reference epoch), each scaled by magnitude(2*t0) of its initial value (so the scale grows along the trajectory, and the later epochs are cheaper to change)
  • 2 - the offsets from the initial guess (days), all scaled by the same epoch_scale (so a change of an epoch costs the same anywhere along the trajectory, and the variables start at 0)
real(kind=wp), public :: epoch_scale = 10.0_wp

scale for the epoch variables with epoch_variable_mode=2 [days] (10 days works well for both 100 and 1120 revs; much smaller values don't converge, and 100 days lets the 100-rev solutions drift)

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

opt var offsets: x_scaled = (x - xoffset) / xscale (nonzero only for the epochs, with epoch_variable_mode=2)

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

the opt vars that are epochs

integer, public :: xscale_mode = 1

the scales of the opt vars:

  • 1 - from the magnitudes of the initial values (see initialize_the_mission; the states are scaled by at least xscale_x0)
  • 2 - from the sensitivities: each scale is divided by the norm of its column of the (scaled) Jacobian at the initial guess, so each variable's unit change gives the same size change in the constraints (see equilibrate_scales)
real(kind=wp), public :: epoch_scale_factor = 1.0_wp

with xscale_mode=2: the epoch scales are also multiplied by this (>1 makes the epochs cheaper to change, relative to the states)


Type-Bound Procedures

procedure, public :: init => initialize_the_mission

  • public subroutine initialize_the_mission(me, x)

    Initialize the mission.

    Arguments

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

    initial guess

procedure, public :: plot => plot_trajectory

  • public subroutine plot_trajectory(me, filename, export_trajectory, draw_trajectory, only_first_rev)

    Plot the trajectory using matplotlib and/or generate a text file (for MKSPK)

    Read more…

    Arguments

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

    plot file name [without extension]

    logical, intent(in), optional :: export_trajectory

    if true, a text trajectory file is also produced (that can be read by MKSPK) [default is False]

    logical, intent(in), optional :: draw_trajectory

    if true [Default], a matplotlib plot is generated

    logical, intent(in), optional :: only_first_rev

    to only do the first rev [Default is False]

procedure, public :: export_trajectory_json_file

  • public subroutine export_trajectory_json_file(me, filename, only_first_rev)

    Export the trajectory JSON file.

    Read more…

    Arguments

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

    plot file name [without extension]

    logical, intent(in), optional :: only_first_rev

    to only do the first rev [Default is False]

procedure, public :: write_optvars_to_file

  • public subroutine write_optvars_to_file(me, filename, x)

    Write the current x variables to a file (compatible with the Copernicus optvar file).

    Arguments

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

    file name [without extension]

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

    solver opt vars vector

procedure, public :: constraint_violations

  • public subroutine constraint_violations(me, x, f, funcs_to_compute)

    Computes the constraint violation vector for the mission.

    Arguments

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

    opt var vector for the mission [n]

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

    constraint violation vector for the mission [m]

    integer, intent(in), optional, dimension(:) :: funcs_to_compute

    the indices of f to compute

procedure, public :: print_constraint_defects

  • public subroutine print_constraint_defects(me, filename)

    Print the r and v constraint defect norms for each segment constraint.

    Arguments

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

    csv file to write to

procedure, public :: write_solution_plot_data

  • 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.

    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)

procedure, public :: generate_eclipse_data

  • public subroutine generate_eclipse_data(me, fileprefix, filetype)

    Propagate all the segments with a dense time step and export the Eclipsing data w.r.t. Earth. In this file, any point <0 is in eclipse.

    Read more…

    Arguments

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

    file prefix for the csv file (case name will be added)

    integer, intent(in), optional :: filetype

    type of output file: 1=csv [default] or 2=json

procedure, public :: get_problem_arrays

  • public subroutine get_problem_arrays(me, x, f)

    Get the arrays for the problem

    Arguments

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

    opt var vector [scaled]

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

    constraint violations

procedure, public :: put_x_in_segments

  • public subroutine put_x_in_segments(me, x_scaled)

    Take the x vector from the solver, and use it to populate all the segments

    Arguments

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

    opt var vector (scaled)

procedure, public :: get_x_from_json_file

  • public subroutine get_x_from_json_file(me, x)

    Read the JSON solution file and put the x vector in the mission. Can be used to restart a solution from a previous run (e.g., with different settings, as long as the fundamental problem isn't changed).

    Read more…

    Arguments

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

    scaled x vector

procedure, public :: get_scales_from_segs

  • public subroutine get_scales_from_segs(me)

    Populate the xscale and fscale problem arrays from the segment data.

    Arguments

    Type IntentOptional Attributes Name
    class(mission_type), intent(inout) :: me

procedure, public :: segs_to_propagate

  • public subroutine segs_to_propagate(me, funcs_to_compute, isegs_to_propagate)

    Given the functions to be computed, returns the segments that need to be propagated.

    Arguments

    Type IntentOptional Attributes Name
    class(mission_type), intent(inout) :: me
    integer, intent(in), optional, dimension(:) :: funcs_to_compute

    the indices of f to compute

    integer, intent(out), dimension(:), allocatable :: isegs_to_propagate

    segment numbers

procedure, public :: get_sparsity_pattern

  • public subroutine get_sparsity_pattern(me, irow, icol, linear_irow, linear_icol, linear_vals, maxgrp, ngrp)

    Returns the sparsity pattern for the "forward-backward" Halo problem.

    Arguments

    Type IntentOptional Attributes Name
    class(mission_type), intent(inout) :: me
    integer, intent(out), dimension(:), allocatable :: irow

    sparsity pattern nonzero elements row indices

    integer, intent(out), dimension(:), allocatable :: icol

    sparsity pattern nonzero elements column indices

    integer, intent(out), optional, dimension(:), allocatable :: linear_irow

    linear sparsity pattern nonzero elements row indices

    integer, intent(out), optional, dimension(:), allocatable :: linear_icol

    linear sparsity pattern nonzero elements column indices

    real(kind=wp), intent(out), optional, dimension(:), allocatable :: linear_vals

    linear sparsity values (constant elements of the Jacobian)

    integer, intent(out), optional :: maxgrp

    DSM sparsity partition

    integer, intent(out), optional, dimension(:), allocatable :: ngrp

    DSM sparsity partition

procedure, public :: removed_columns

  • public function removed_columns(me) result(cols_to_remove)

    The columns (optimization variables) of the full problem that are removed (fixed) by the problem options. The full problem has 7 columns per node ([t, rx, ry, rz, vx, vy, vz]), with nodes in time order.

    Arguments

    Type IntentOptional Attributes Name
    class(mission_type), intent(in) :: me

    Return Value integer, dimension(:), allocatable

procedure, public :: compute_jacobian_stm

  • public subroutine compute_jacobian_stm(me, x, jac)

    Compute the (scaled) sparse Jacobian analytically (jacobian_mode=2): each segment is propagated once with its state transition matrix (in parallel, see propagate_segment_stm), and the blocks are assembled.

    Read more…

    Arguments

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

    opt var vector (scaled)

    real(kind=wp), intent(out), dimension(:), allocatable :: jac

    the nonzero Jacobian elements (scaled)

procedure, public :: equilibrate_scales

  • 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.

    Read more…

    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

procedure, public :: define_problem_size

  • public pure subroutine define_problem_size(me, n, m, n_segs, n_nonzero, full_problem)

    Returns the size variables for the "forward-backward" formulation of the problem.

    Read more…

    Arguments

    Type IntentOptional Attributes Name
    class(mission_type), intent(in) :: me
    integer, intent(out), optional :: n

    number of opt vars for the solver

    integer, intent(out), optional :: m

    number of equality constraints for the solver

    integer, intent(out), optional :: n_segs

    number of segments

    integer, intent(out), optional :: n_nonzero

    number of nonzero elements in the Jacobian

    logical, intent(in), optional :: full_problem

    if true (default) always return the results for the full problem (i.e., without fixing any of the variables)

procedure, public :: get_case_name

  • public function get_case_name(me) result(case_name)

    Returns a string that can be used for file names, etc. (read the values of the global variables).

    Read more…

    Arguments

    Type IntentOptional Attributes Name
    class(mission_type), intent(in) :: me

    Return Value character(len=:), allocatable

procedure, public :: generate_patch_points

  • public subroutine generate_patch_points(me, lstar, tstar, period, x0, z0, ydot0, pp)

    Generates the patch points (unnormalized, moon-centered) from the CR3BP normalized guess.

    Arguments

    Type IntentOptional Attributes Name
    class(mission_type), intent(inout) :: me
    real(kind=wp), intent(in) :: lstar
    real(kind=wp), intent(in) :: tstar
    real(kind=wp), intent(in) :: period
    real(kind=wp), intent(in) :: x0
    real(kind=wp), intent(in) :: z0
    real(kind=wp), intent(in) :: ydot0
    type(patch_point), intent(out), dimension(3) :: pp

    periapsis, quarter, apoapsis patch points

procedure, public :: update_epoch

  • public subroutine update_epoch(me)

    Update the variables for the reference epoch in the mission class. Either computes the et from the calendar state, or vice versa.

    Arguments

    Type IntentOptional Attributes Name
    class(mission_type), intent(inout) :: me

procedure, public :: export_rp_ra_json_file

  • public subroutine export_rp_ra_json_file(me, et, rmag, rdot, filename)

    Export the rp/ra file.

    Read more…

    Arguments

    Type IntentOptional Attributes Name
    class(mission_type), intent(inout) :: me
    real(kind=wp), intent(in), dimension(:) :: et
    real(kind=wp), intent(in), dimension(:) :: rmag
    real(kind=wp), intent(in), dimension(:) :: rdot
    character(len=*), intent(in) :: filename

    file name [without extension]

Source Code

    type,extends(numdiff_type) :: mission_type

        !! the mission [this is a `numdiff_type` for
        !! organizational purposes.... rethink this maybe ...

        character(len=:),allocatable :: initial_guess_from_file !! to read the initial guess from a JSOn file

        logical :: use_splined_ephemeris = .false. !! if true, the ephemeris is splined
        real(wp) :: dt_spline_sec = 3600.0_wp !! time step in seconds for spline step [1 hr]

        logical :: pointmass_central_body = .false. !! if true, the central body is a pointmass (moon).
                                                   !! otherwise, the `grav` model is used.
        type(geopotential_model_pines),pointer :: grav => null() !! central body geopotential model [global]
        class(jpl_ephemeris),pointer :: eph => null()            !! the ephemeris [global]
        type(moon_pa_frame),pointer :: moon_pa => null() !! the moon_pa frame interpolater [global]
        logical :: include_pointmass_earth = .true. !! if true, earth is included as a pointmass in the force model
        logical :: include_pointmass_sun = .true. !! if true, sun is included as a pointmass in the force model
        logical :: include_pointmass_jupiter = .false. !! if true, jupiter is included as a pointmass in the force model

        type(segment),dimension(:),allocatable :: segs  !! the list of segments

        real(wp),dimension(:),allocatable :: xscale  !! opt var scale factors
        real(wp),dimension(:),allocatable :: dpert_  !! opt var dpert factors [rename because already in base class]
        real(wp),dimension(:),allocatable :: fscale  !! function scale factors
        character(len=20),dimension(:),allocatable :: xname !! opt var names

        character(len=:),allocatable :: N_or_S      !! 'N' or 'S'
        character(len=:),allocatable :: L1_or_L2    !! 'L1' or 'L2'

        logical :: solve = .true. !! run the nle solver to solve the problem
        logical :: generate_plots = .true.  !! to generate the python plots
        logical :: generate_trajectory_files = .true.  !! to export the txt trajectory files.
        logical :: generate_json_trajectory_file = .false. !! to export the JSON trajectory file for the solution
                                                           !! (contains inertial and rotating data). This one is used
                                                           !! by the PyVista python script for plotting
        logical :: generate_guess_and_solution_files = .true.  !! to export the json guess and solution files.
        logical :: generate_kernel = .false.  !! to generate a spice kernel (bsp) of the solution
                                              !! [this requires the external mkspk SPICE tool]
        logical :: generate_solution_plots = .false. !! write the solution's plot data (`solution_plot_data_*.json`:
                                                     !! the epochs and defects at the constraint points, for the
                                                     !! initial guess and the solution) and run
                                                     !! `python/plot_solution.py` on it (matplotlib: the epoch
                                                     !! drift and defect plots, `*.pdf` and `*.png`)
        logical :: generate_defect_file = .false. !! generate the file that shows the pos/vel
                                                  !! constraint defects for the solution
        logical :: generate_eclipse_files = .false. !! generate the eclipse data file for the solution
        logical :: run_pyvista_script = .false. !! run the pyvista script to generate the interacdtive 3d plot

        logical :: generate_rp_ra_file = .false. !! to generate the rp_ra file

        real(wp) :: r_eclipse_bubble = 0.0_wp !! radius of the "eclipse bubble" [km]

        ! eclipse optimization (see [[eclipse_optimize]], in halo_eclipse_opt_submodule):
        logical  :: eclipse_optimization = .false. !! after the solve, move the solution out of the Earth's shadow:
                                                   !! the closest continuous trajectory with the shadow function at
                                                   !! least `eclipse_opt_phi_min` near the eclipses (solved with sqpopt)
        real(wp) :: eclipse_opt_phi_min = 0.05_wp  !! the shadow function required at the constraint samples (>0: a margin)
        real(wp) :: eclipse_opt_bubble = 0.0_wp    !! eclipse bubble radius for the constraints [km]
        real(wp) :: eclipse_opt_detect_phi = 0.3_wp !! segments whose shadow function falls below this get an eclipse constraint
        real(wp) :: eclipse_opt_detect_step = 300.0_wp !! time step for checking the shadow function along the trajectory [sec]
        real(wp) :: eclipse_opt_sample_step = 300.0_wp !! spacing of the constraint samples [sec]
        integer  :: eclipse_opt_max_outer = 3 !! maximum number of passes (find the eclipses, optimize, check)
        logical  :: eclipse_opt_polish = .false. !! re-converge the continuity with the Newton solver after each optimization
                                                 !! (continuity only: only for a converged optimization, whose point is
                                                 !! already feasible; from an unconverged one it undoes the eclipse fix)
        logical  :: eclipse_opt_newton_finish = .true. !! after each optimization, a Newton solve of the continuity
                                                       !! constraints and, as equalities (KS = `eclipse_opt_phi_min`), the
                                                       !! eclipse rows that are at or near their bound (see
                                                       !! `eclipse_opt_newton_active_tol`): converges the continuity
                                                       !! without undoing the eclipse fix
        real(wp) :: eclipse_opt_newton_active_tol = 0.02_wp !! the Newton finish's equalities: the eclipse rows with
                                                            !! KS below `eclipse_opt_phi_min` plus this (a row that
                                                            !! falls below its bound in the finish is added, and
                                                            !! the finish repeated)
        integer  :: eclipse_opt_newton_max_iter = 50 !! maximum number of iterations of each Newton finish
        integer  :: eclipse_opt_newton_solver_mode = 0 !! the Newton finish's sparse linear solver (nlesolver's
                                                       !! `sparsity_mode`: 2-4, 6 or 7); 0: halo's `solver_mode`
        real(wp) :: eclipse_opt_newton_damp = 1.0e-4_wp !! the Newton finish's first damping (nlesolver's `damp`: LSQR,
                                                        !! LSMR, CRAIG and the Cholesky solver). The eclipse rows at
                                                        !! their bound are nearly dependent on the continuity rows, so
                                                        !! the undamped steps are long and fail: the finish is done in
                                                        !! stages, the damping divided by 10 each stage, to 0
        integer  :: eclipse_opt_newton_damp_iter = 3 !! maximum number of iterations of each damped stage
        integer  :: eclipse_opt_objective = 1 !! the optimization's objective: 1 - `|x - x0|^2/2` (the closest
                                              !! solution to the start); 0 - none (a feasibility problem, as
                                              !! SNOPT's feasible point mode)
        logical  :: sqpopt_solve = .false. !! TEMPORARY experiment: solve the problem with sqpopt (as the eclipse
                                           !! optimization, with no eclipse rows) instead of nlesolver
        integer  :: eclipse_opt_newton_max_active = -1 !! TEMPORARY experiment: hold only this many rows (the smallest KS); <0: off
        real(wp) :: eclipse_opt_newton_damp_min = 1.0e-9_wp !! below this, the damping is 0 (the last stage)
        real(wp) :: eclipse_opt_fd_step = 1.0e-6_wp !! central-difference step for the eclipse constraint rows (scaled variables)
        real(wp) :: eclipse_opt_max_step_epoch = -1.0_wp    !! largest change of a node epoch in one sqpopt iteration [days]
                                                            !! (sqpopt's set_max_step; <=0: no limit)
        real(wp) :: eclipse_opt_max_step_position = -1.0_wp !! largest change of a node position component [km] (<=0: no limit)
        real(wp) :: eclipse_opt_max_step_velocity = -1.0_wp !! largest change of a node velocity component [km/s] (<=0: no limit)
        logical  :: eclipse_opt_equilibrate = .false. !! solve the optimization with the continuity Jacobian equilibrated
                                                      !! (its rows and columns normalized, at the converged solution),
                                                      !! which lowers the condition number of sqpopt's QP subproblems.
                                                      !! The objective is then measured in those units
        logical  :: eclipse_opt_single_row = .false. !! one eclipse constraint for all the segments near the shadow
                                                     !! (the KS aggregate of the segments' rows: exactly the KS of all
                                                     !! their samples), instead of one per segment
        real(wp) :: eclipse_opt_ks_rho = 100.0_wp !! the KS aggregate's parameter: the constraint is within ln(N)/rho
                                                  !! of the smallest of a segment's N samples (and below it)
        ! sqpopt options (see sqpopt_options_type):
        integer  :: eclipse_opt_max_iter = 100
        integer  :: eclipse_opt_print_level = 1
        integer  :: eclipse_opt_hessian_mode = 1 !! 1: BFGS, 2: SR1
        logical  :: eclipse_opt_direct_qp = .true.
        logical  :: eclipse_opt_direct_least_squares = .true.
        real(wp) :: eclipse_opt_direct_tol = 1.0e-8_wp !! sqpopt qp_solver%direct_tol: the direct QP method's relative tolerance
                                                       !! for a violated row (and for the working set's rows)
        logical  :: eclipse_opt_direct_relative_tol = .false.   !! sqpopt qp_solver%direct_relative_tol
        logical  :: eclipse_opt_direct_accept_inexact = .false. !! sqpopt qp_solver%direct_accept_inexact
        logical  :: eclipse_opt_basis_repair = .false.   !! sqpopt qp_solver%sparse_qp%basis_repair
        real(wp) :: eclipse_opt_basis_rel_tol = 1.0e-8_wp      !! sqpopt qp_solver%sparse_qp%basis_rel_tol
        real(wp) :: eclipse_opt_basis_eq_slack_weight = 1.0e-6_wp !! sqpopt qp_solver%sparse_qp%basis_eq_slack_weight
        integer  :: eclipse_opt_linear_solver = 2 !! sqpopt linear_solver: 1 MUMPS (needs a build with HAS_MUMPS),
                                                  !! 2 QDLDL (the default), 3 dense, 4 LAPACK (see
                                                  !! sqpopt_symmetric_solver_module)
        integer  :: eclipse_opt_factorization_threads = 1 !! sqpopt factorization_threads (MUMPS only)
        integer  :: eclipse_opt_direct_max_changes = 1000 !! sqpopt qp_solver%direct_max_changes: changes of the working set
                                                           !! the direct QP method may make before it gives up
        integer  :: eclipse_opt_qp_solver_mode = 0 !! 0: auto, 2: dense, 3: sparse (reduced Hessian), 4: DAQP
        integer  :: eclipse_opt_linesearch_mode = 4 !! 1: Armijo, 2: exact, 3: watchdog, 4: filter, 5: funnel
        integer  :: eclipse_opt_lbfgs_memory = 0
        real(wp) :: eclipse_opt_elastic_multiplier_limit = 0.0_wp !! sqpopt elastic_multiplier_limit (0: no elastic
                                                                   !! re-solves, which skip the direct QP method)
        logical  :: eclipse_opt_scaling = .false. !! (halo's variables and constraints are already scaled)
        real(wp) :: eclipse_opt_scaling_max_gradient = 100.0_wp
        real(wp) :: eclipse_opt_hessian_scale0 = 1.0_wp
        logical  :: eclipse_opt_inertia_control = .false.
        integer  :: eclipse_opt_merit_mode = 1       !! 1: l1, 2: augmented Lagrangian
        integer  :: eclipse_opt_restoration_mode = 1 !! 1: restoration phase, 2: Gauss-Newton step
        real(wp) :: eclipse_opt_qp_max_step = 2.0_wp !! sqpopt qp_solver%max_step: cap on the 2-norm of the step
        real(wp) :: eclipse_opt_max_time = 0.0_wp    !! sqpopt max_time [sec] (0: no limit)
        real(wp) :: eclipse_opt_epoch_scale = -1.0_wp !! scale of the epoch variables in the optimization [days]
                                                      !! (<0: halo's own, `epoch_scale`). It also sets how much an
                                                      !! epoch change costs in the objective
        real(wp) :: eclipse_opt_ctol = 1.0e-10_wp
        real(wp) :: eclipse_opt_ktol = 1.0e-6_wp
        real(wp) :: eclipse_dt_step = 3600.0_wp !! dense time step output for eclipse calculations in sec [1 hour]
        integer :: eclipse_filetype = 1 !! type of eclipse file: 1=csv or 2=json
        logical :: eclipse_file_se_positions = .true. !! for the JSON eclipse file: also write the Sun-Earth
                                                      !! rotating frame positions of the points (for plotting;
                                                      !! false gives a smaller file, faster to write and read)

        integer :: epoch_mode = 1 !! 1 - calendar date was specified, 2 - ephemeris time was specified
        integer :: year   = 0 !! epoch of first point (first periapsis crossing)
        integer :: month  = 0 !! epoch of first point (first periapsis crossing)
        integer :: day    = 0 !! epoch of first point (first periapsis crossing)
        integer :: hour   = 0 !! epoch of first point (first periapsis crossing)
        integer :: minute = 0 !! epoch of first point (first periapsis crossing)
        real(wp) :: sec   = zero !! epoch of first point (first periapsis crossing)
        real(wp) :: et_ref = zero  !! ephemeris time reference epoch [sec]
                                   !! (all times relative to this).
                                   !! this is computed from the year,month,day,hour,minute,sec values
                                   !! if `epoch_mode=1`

        integer :: n_revs = 10  !! Number of revs in the Halo.

        real(wp) :: rtol = 1.0e-12_wp !! integrator rtol
        real(wp) :: atol = 1.0e-12_wp !! integrator atol
        real(wp) :: nlesolver_tol = 1.0e-6_wp !! nlesolver tol
        real(wp) :: nlesolver_tolx = 1.0e-8_wp !! nlesolver tolerance for the change in the (scaled) `x`:
                                               !! the solve stops when a step changes no variable by more
                                               !! (make it smaller for a refinement from a converged solution,
                                               !! whose steps are tiny)

        real(wp),dimension(:),allocatable :: initial_r
            !! if `fix_initial_r` is True, this can be used
            !! to specify the initial `r` (moon-centered earth-moon rotating frame)

        character(len=:),allocatable :: ephemeris_file !! the JPL ephemeris file to load
        ! [note: these are build using the get_third_party script in FAT.
        !  the files are platform (and maybe compiler specific)
        !  'data/eph/JPLEPH.421'               !! JPL DE421 ephemeris file [mac,gfortran]
        !  'data/eph/JPLEPH_intel_mac.421'     !! [mac,ifort]
        !  'data/eph/JPLEPH_windows_ifort.421' !! [windows,ifort]

        ! environment and integrator parameters:

        character(len=:),allocatable :: gravfile  !! spherical harmonic gravity coeff file (Moon)
        !! example: 'data/grav/gggrx_0020pm_sha.tab'

        character(len=:),allocatable ::  moon_pa_file !! file for moon_pa frame.
        !! example: `data/moon_pa_2000_2100.csv`

        character(len=:),allocatable :: patch_point_file   !! Halo CR3BP patch point solution file
        !! example: 'data/L2_halos.json'
        logical :: patch_point_file_is_periapsis = .false. !! if the state in the patch point file are periapsis states
                                                           !! (false means they are apoapsis states.
                                                           !! the ones in L2_halos.json are apoapsis states)

        ! the initial guess for the Halo:
        ! This is for the "forward/backward" version of the transcription from the paper.
        type(patch_point) :: periapsis    !! Patchpoint Periapse State
        type(patch_point) :: quarter      !! Patchpoint 1/4 Rev State
        type(patch_point) :: apoapsis     !! Patchpoint 1/2 Rev State
        real(wp) :: period  = 0.0_wp !! Halo period [days]
        real(wp) :: period8 = 0.0_wp !! 1/8 of Halo period [days]

        ! optional problem inputs
        ! [can remove some of the variables from the optimization problem]
        logical :: fix_initial_time = .false. !! to fix the initial epoch in the mission
        logical :: fix_initial_r = .false. !! fix the initial periapsis position vector (x,y,z)
        integer :: fix_ry_at_end_of_rev = 0 !! fix ry at the end of the specified rev (at periapsis)
                                            !! not used if `<= 0`.
        logical :: fix_final_ry_and_vx = .false. !! fix ry and vx at the end of the last rev (at periapsis)

        logical :: constrain_initial_rdot = .false. !! impose an rdot=0 constraint on the initial point

        integer :: solver_mode = 1  !! use sparse or dense solver:
                                    !!
                                    !! * 1 - dense (LAPACK)
                                    !! * 2 - sparse (LSQR)
                                    !! * 3 - sparse (LUSOL)
                                    !! * 4 - sparse (LMSR)
                                    !! * 5 - sparse (qr_mumps)
                                    !! * 6 - sparse (CRAIG)
                                    !! * 7 - sparse (direct)

        integer :: jacobian_mode = 1  !! how the Jacobian is computed:
                                      !!
                                      !! * 1 - finite differences (central differences, see [[halo_grad_sparse]])
                                      !! * 2 - analytic: the state transition matrix is integrated with each
                                      !!   segment, and the time partials are computed analytically
                                      !!   (see [[compute_jacobian_stm]]). Requires `use_splined_ephemeris`.
        real(wp) :: stm_rtol = -1.0_wp  !! integrator rtol for the STM (<0: use `rtol`)
        real(wp) :: stm_atol = -1.0_wp  !! integrator atol for the STM (<0: use `atol`)
        logical :: func_with_stm = .false. !! (`jacobian_mode=2`) propagate the segments with their
                                           !! STMs in every function evaluation, and keep the Jacobian,
                                           !! so that the solver's next Jacobian request at the same `x`
                                           !! needs no propagation (see [[halo_func]])
        real(wp),dimension(:),allocatable :: jac_cache_x  !! for `func_with_stm`: the `x` of `jac_cache`
        real(wp),dimension(:),allocatable :: jac_cache    !! for `func_with_stm`: the Jacobian at `jac_cache_x`
        integer :: epoch_variable_mode = 1  !! the epoch variables (each node's epoch) in the `x` vector:
                                            !!
                                            !! * 1 - the epochs (days from the reference epoch), each scaled by
                                            !!   `magnitude(2*t0)` of its initial value (so the scale grows along
                                            !!   the trajectory, and the later epochs are cheaper to change)
                                            !! * 2 - the offsets from the initial guess (days), all scaled by the
                                            !!   same `epoch_scale` (so a change of an epoch costs the same
                                            !!   anywhere along the trajectory, and the variables start at 0)
        real(wp) :: epoch_scale = 10.0_wp  !! scale for the epoch variables with `epoch_variable_mode=2` [days]
                                           !! (10 days works well for both 100 and 1120 revs; much smaller
                                           !! values don't converge, and 100 days lets the 100-rev solutions drift)
        real(wp),dimension(:),allocatable :: xoffset  !! opt var offsets: `x_scaled = (x - xoffset) / xscale`
                                                      !! (nonzero only for the epochs, with `epoch_variable_mode=2`)
        logical,dimension(:),allocatable :: x_is_epoch  !! the opt vars that are epochs
        integer :: xscale_mode = 1  !! the scales of the opt vars:
                                    !!
                                    !! * 1 - from the magnitudes of the initial values (see [[initialize_the_mission]];
                                    !!   the states are scaled by at least `xscale_x0`)
                                    !! * 2 - from the sensitivities: each scale is divided by the norm of its column
                                    !!   of the (scaled) Jacobian at the initial guess, so each variable's unit
                                    !!   change gives the same size change in the constraints
                                    !!   (see [[equilibrate_scales]])
        real(wp) :: epoch_scale_factor = 1.0_wp  !! with `xscale_mode=2`: the epoch scales are also multiplied by
                                                 !! this (>1 makes the epochs cheaper to change, relative to the states)

    contains

        procedure,public :: init => initialize_the_mission
        procedure,public :: plot => plot_trajectory
        procedure,public :: export_trajectory_json_file

        procedure,public :: write_optvars_to_file
        procedure,public :: constraint_violations
        procedure,public :: print_constraint_defects
        procedure,public :: write_solution_plot_data
        procedure,public :: generate_eclipse_data
        procedure :: get_problem_arrays
        procedure :: put_x_in_segments
        procedure :: get_x_from_json_file
        procedure :: get_scales_from_segs
        procedure :: segs_to_propagate
        procedure :: get_sparsity_pattern
        procedure :: removed_columns
        procedure :: compute_jacobian_stm
        procedure :: equilibrate_scales
        procedure :: define_problem_size
        procedure :: get_case_name
        procedure :: generate_patch_points
        procedure :: update_epoch
        procedure :: export_rp_ra_json_file

    end type mission_type