Moon Landing Problem#

The Moon landing problem is a version of the soft landing problem presented in [Med64]. The problem is simplified to have one degree-of-freedom and normalized such that the Moon’s gravity is unity. The goal is to minimize the amount of fuel consumed or, stated differently, maximize the final mass, while bringing the lander down to the surface for a soft landing.

State and control variables#

This system has three state variables, the altitude (\(h\)), velocity (\(v\)), and mass (\(m\)) of the lander.

This system has one control variable, (\(T\)), the thrust applied to the vehicle.

The dynamics of the system are given by

(70)#\[\begin{align} \dot{h} &= v \\ \dot{v} &= -1 + \frac{T}{m} \\ \dot{m} &= -\frac{T}{2.349} \end{align}\]

Problem Definition#

We seek to maximize the final mass of the vehicle while bringing it to a soft landing.

(71)#\[\begin{align} \mathrm{Minimize} \, J &= m_f \end{align}\]

The initial conditions are

(72)#\[\begin{align} h_0 &= 1 \\ v_0 &= -0.783 \\ m_0 &= 1 \end{align}\]

and the terminal constraints are

(73)#\[\begin{align} h_f &= 0 \\ v_f &= 0 \end{align}\]

Additionally, the thrust is constrained to be positive but remain under 1.227.

(74)#\[\begin{align} 0 \le T \le 1.227 \end{align}\]

Defining the ODE#

The following implements the dynamics of the Moon landing problem described above.

import numpy as np
import openmdao.api as om


class MoonLandingProblemODE(om.ExplicitComponent):
    def initialize(self):
        self.options.declare('num_nodes', types=int)

    def setup(self):
        nn = self.options['num_nodes']

        # inputs
        self.add_input('h', val=np.ones(nn), units=None, desc='Altitude')
        self.add_input('v', val=np.ones(nn), units='1/s', desc='Velocity')
        self.add_input('m', val=np.ones(nn), units=None, desc='Mass')
        self.add_input('T', val=np.ones(nn), units=None, desc='Thrust')

        # outputs
        self.add_output('h_dot', val=np.ones(nn), units='1/s', desc='Rate of change of Altitude')
        self.add_output('v_dot', val=np.ones(nn), units='1/s**2', desc='Rate of change of Velocity')
        self.add_output('m_dot', val=np.ones(nn), units='1/s', desc='Rate of change of Mass')

        # partials
        ar = np.arange(nn)
        self.declare_partials(of='h_dot', wrt='v', rows=ar, cols=ar, val=1.0)
        self.declare_partials(of='v_dot', wrt='m', rows=ar, cols=ar)
        self.declare_partials(of='v_dot', wrt='T', rows=ar, cols=ar)
        self.declare_partials(of='m_dot', wrt='T', rows=ar, cols=ar, val=-1/2.349)
        self.declare_partials(of='m_dot', wrt='T', rows=ar, cols=ar, val=-1/2.349)

    def compute(self, inputs, outputs, discrete_inputs=None, discrete_outputs=None):
        v = inputs['v']
        m = inputs['m']
        T = inputs['T']

        outputs['h_dot'] = v
        outputs['v_dot'] = -1 + T/m
        outputs['m_dot'] = -T/2.349

    def compute_partials(self, inputs, partials, discrete_inputs=None):
        m = inputs['m']
        T = inputs['T']

        partials['v_dot', 'T'] = 1/m
        partials['v_dot', 'm'] = -T/m**2

Solving the Moon landing problem with Dymos#

The optimal solution to this problem is known to have bang-bang control. That is, the control has a “jump” that render it discontinuous in time. Capturing this behavior accurately requires the use of grid refinement for the Gauss-Lobatto and Radau pseudospectral transcriptions but the Birkhoff pseudospectral transcription can be used to handle this behavior without the use of any grid refinement. The following code shows the use of the Birkhoff pseudospectral transcription to solve the problem.

import dymos as dm

p = om.Problem(model=om.Group())
p.driver = om.pyOptSparseDriver()
p.driver.declare_coloring()
p.driver.options['optimizer'] = 'IPOPT'
p.driver.opt_settings['hessian_approximation'] = 'limited-memory'
p.driver.opt_settings['print_level'] = 0
p.driver.opt_settings['linear_solver'] = 'mumps'
p.driver.declare_coloring()

t = dm.Birkhoff(num_nodes=20)

traj = p.model.add_subsystem('traj', dm.Trajectory())
phase = dm.Phase(ode_class=MoonLandingProblemODE, transcription=t)

phase.set_time_options(fix_initial=True, fix_duration=False)
phase.add_state('h', fix_initial=True, rate_source='h_dot')
phase.add_state('v', fix_initial=True, rate_source='v_dot')
phase.add_state('m', fix_initial=True, lower=1e-3, rate_source='m_dot')
phase.add_control('T', lower=0.0, upper=1.227)

phase.add_boundary_constraint('h', loc='final', equals=0.0)
phase.add_boundary_constraint('v', loc='final', equals=0.0)

phase.add_objective('m', scaler=-1)
phase.set_simulate_options(atol=1.0E-1, rtol=1.0E-2)

traj.add_phase('phase', phase)

p.setup(check=True, force_alloc_complex=True)

phase.set_time_val(initial=0.0, duration=1.0)
phase.set_state_val('h', [1.0, 0.0])
phase.set_state_val('v', [-0.783, 0.0])
phase.set_state_val('m', [1.0, 0.2])
phase.set_control_val('T', [0.0, 1.227])
dm.run_problem(p, simulate=False, simulate_kwargs={'times_per_seg': 100}, make_plots=True)
--- Constraint Report [traj] ---
    --- phase ---
        [final]   0.0000e+00 == h [None]
        [final]   0.0000e+00 == v [1/s]

INFO: checking out_of_order
INFO: checking system
INFO: checking solvers
INFO: checking dup_inputs
INFO: checking missing_recorders
INFO: checking unserializable_options
INFO: checking comp_has_no_outputs
INFO: checking auto_ivc_warnings
Model viewer data has already been recorded for Driver.
INFO: checking out_of_order
INFO: checking system
INFO: checking solvers
INFO: checking dup_inputs
INFO: checking missing_recorders
INFO: checking unserializable_options
INFO: checking comp_has_no_outputs
INFO: checking auto_ivc_warnings
Full total jacobian for problem 'problem' was computed 3 times, taking 0.09581619200002933 seconds.
Total jacobian shape: (63, 124) 
Jacobian shape: (63, 124)  (2.60% nonzero)
FWD solves: 4   REV solves: 0
Total colors vs. total size: 4 vs 124  (96.77% improvement)

Sparsity computed using tolerance: 1e-25
Time to compute sparsity:   0.0958 sec
Time to compute coloring:   0.0423 sec
Memory to compute coloring:   0.2500 MB
Coloring created on: 2024-10-02 16:49:12
Optimization Problem -- Optimization using pyOpt_sparse
================================================================================
    Objective Function: _objfunc

    Solution: 
--------------------------------------------------------------------------------
    Total Time:                    0.4121
       User Objective Time :       0.0172
       User Sensitivity Time :     0.3138
       Interface Time :            0.0400
       Opt Solver Time:            0.0411
    Calls to Objective Function :      16
    Calls to Sens Function :           16


   Objectives
      Index  Name                                  Value
          0  traj.phase.boundary_vals.m    -3.952837E-01

   Variables (c - continuous, i - integer, d - discrete)
      Index  Name                          Type      Lower Bound            Value      Upper Bound     Status
          0  traj.phase.t_duration_0          c    -1.000000E+21     1.397227E+00     1.000000E+21           
          1  traj.phase.controls:T_0          c     0.000000E+00     1.900625E-07     1.227000E+00          l
          2  traj.phase.controls:T_1          c     0.000000E+00     1.200754E-08     1.227000E+00          l
          3  traj.phase.controls:T_2          c     0.000000E+00     2.042712E-09     1.227000E+00          l
          4  traj.phase.controls:T_3          c     0.000000E+00     1.360111E-09     1.227000E+00          l
          5  traj.phase.controls:T_4          c     0.000000E+00     4.448197E-09     1.227000E+00          l
          6  traj.phase.controls:T_5          c     0.000000E+00     4.256705E-01     1.227000E+00           
          7  traj.phase.controls:T_6          c     0.000000E+00     1.227000E+00     1.227000E+00          u
          8  traj.phase.controls:T_7          c     0.000000E+00     1.227000E+00     1.227000E+00          u
          9  traj.phase.controls:T_8          c     0.000000E+00     1.227000E+00     1.227000E+00          u
         10  traj.phase.controls:T_9          c     0.000000E+00     1.227000E+00     1.227000E+00          u
         11  traj.phase.controls:T_10         c     0.000000E+00     1.227000E+00     1.227000E+00          u
         12  traj.phase.controls:T_11         c     0.000000E+00     1.227000E+00     1.227000E+00          u
         13  traj.phase.controls:T_12         c     0.000000E+00     1.227000E+00     1.227000E+00          u
         14  traj.phase.controls:T_13         c     0.000000E+00     1.227000E+00     1.227000E+00          u
         15  traj.phase.controls:T_14         c     0.000000E+00     1.227000E+00     1.227000E+00          u
         16  traj.phase.controls:T_15         c     0.000000E+00     1.227000E+00     1.227000E+00          u
         17  traj.phase.controls:T_16         c     0.000000E+00     1.227000E+00     1.227000E+00          u
         18  traj.phase.controls:T_17         c     0.000000E+00     1.227000E+00     1.227000E+00          u
         19  traj.phase.controls:T_18         c     0.000000E+00     1.227000E+00     1.227000E+00          u
         20  traj.phase.controls:T_19         c     0.000000E+00     1.227000E+00     1.227000E+00          u
         21  traj.phase.states:h_0            c    -1.000000E+30     1.000000E+00     1.000000E+30           
         22  traj.phase.states:h_1            c    -1.000000E+30     9.924938E-01     1.000000E+30           
         23  traj.phase.states:h_2            c    -1.000000E+30     9.696467E-01     1.000000E+30           
         24  traj.phase.states:h_3            c    -1.000000E+30     9.305227E-01     1.000000E+30           
         25  traj.phase.states:h_4            c    -1.000000E+30     8.738058E-01     1.000000E+30           
         26  traj.phase.states:h_5            c    -1.000000E+30     7.982641E-01     1.000000E+30           
         27  traj.phase.states:h_6            c    -1.000000E+30     7.064505E-01     1.000000E+30           
         28  traj.phase.states:h_7            c    -1.000000E+30     6.061256E-01     1.000000E+30           
         29  traj.phase.states:h_8            c    -1.000000E+30     5.024707E-01     1.000000E+30           
         30  traj.phase.states:h_9            c    -1.000000E+30     3.999428E-01     1.000000E+30           
         31  traj.phase.states:h_10           c    -1.000000E+30     3.034069E-01     1.000000E+30           
         32  traj.phase.states:h_11           c    -1.000000E+30     2.170119E-01     1.000000E+30           
         33  traj.phase.states:h_12           c    -1.000000E+30     1.443228E-01     1.000000E+30           
         34  traj.phase.states:h_13           c    -1.000000E+30     8.734397E-02     1.000000E+30           
         35  traj.phase.states:h_14           c    -1.000000E+30     4.664210E-02     1.000000E+30           
         36  traj.phase.states:h_15           c    -1.000000E+30     2.082882E-02     1.000000E+30           
         37  traj.phase.states:h_16           c    -1.000000E+30     7.075257E-03     1.000000E+30           
         38  traj.phase.states:h_17           c    -1.000000E+30     1.469604E-03     1.000000E+30           
         39  traj.phase.states:h_18           c    -1.000000E+30     9.514736E-05     1.000000E+30           
         40  traj.phase.states:h_19           c    -1.000000E+30     3.584832E-17     1.000000E+30           
         41  traj.phase.state_rates:h_0       c    -1.000000E+30    -5.470143E-01     1.000000E+30           
         42  traj.phase.state_rates:h_1       c    -1.000000E+30    -5.536763E-01     1.000000E+30           
         43  traj.phase.state_rates:h_2       c    -1.000000E+30    -5.734247E-01     1.000000E+30           
         44  traj.phase.state_rates:h_3       c    -1.000000E+30    -6.058871E-01     1.000000E+30           
         45  traj.phase.state_rates:h_4       c    -1.000000E+30    -6.500537E-01     1.000000E+30           
         46  traj.phase.state_rates:h_5       c    -1.000000E+30    -6.965069E-01     1.000000E+30           
         47  traj.phase.state_rates:h_6       c    -1.000000E+30    -7.033109E-01     1.000000E+30           
         48  traj.phase.state_rates:h_7       c    -1.000000E+30    -6.772406E-01     1.000000E+30           
         49  traj.phase.state_rates:h_8       c    -1.000000E+30    -6.489352E-01     1.000000E+30           
         50  traj.phase.state_rates:h_9       c    -1.000000E+30    -6.080881E-01     1.000000E+30           
         51  traj.phase.state_rates:h_10      c    -1.000000E+30    -5.594978E-01     1.000000E+30           
         52  traj.phase.state_rates:h_11      c    -1.000000E+30    -4.988972E-01     1.000000E+30           
         53  traj.phase.state_rates:h_12      c    -1.000000E+30    -4.298995E-01     1.000000E+30           
         54  traj.phase.state_rates:h_13      c    -1.000000E+30    -3.521394E-01     1.000000E+30           
         55  traj.phase.state_rates:h_14      c    -1.000000E+30    -2.705403E-01     1.000000E+30           
         56  traj.phase.state_rates:h_15      c    -1.000000E+30    -1.889000E-01     1.000000E+30           
         57  traj.phase.state_rates:h_16      c    -1.000000E+30    -1.143464E-01     1.000000E+30           
         58  traj.phase.state_rates:h_17      c    -1.000000E+30    -5.363801E-02     1.000000E+30           
         59  traj.phase.state_rates:h_18      c    -1.000000E+30    -1.387949E-02     1.000000E+30           
         60  traj.phase.state_rates:h_19      c    -1.000000E+30    -4.691484E-18     1.000000E+30           
         61  traj.phase.final_states:h_0      c    -1.000000E+30     0.000000E+00     1.000000E+30           
         62  traj.phase.states:v_0            c    -1.000000E+30    -7.830000E-01     1.000000E+30           
         63  traj.phase.states:v_1            c    -1.000000E+30    -7.925359E-01     1.000000E+30           
         64  traj.phase.states:v_2            c    -1.000000E+30    -8.208041E-01     1.000000E+30           
         65  traj.phase.states:v_3            c    -1.000000E+30    -8.672708E-01     1.000000E+30           
         66  traj.phase.states:v_4            c    -1.000000E+30    -9.304912E-01     1.000000E+30           
         67  traj.phase.states:v_5            c    -1.000000E+30    -9.969847E-01     1.000000E+30           
         68  traj.phase.states:v_6            c    -1.000000E+30    -1.006724E+00     1.000000E+30           
         69  traj.phase.states:v_7            c    -1.000000E+30    -9.694068E-01     1.000000E+30           
         70  traj.phase.states:v_8            c    -1.000000E+30    -9.288902E-01     1.000000E+30           
         71  traj.phase.states:v_9            c    -1.000000E+30    -8.704215E-01     1.000000E+30           
         72  traj.phase.states:v_10           c    -1.000000E+30    -8.008690E-01     1.000000E+30           
         73  traj.phase.states:v_11           c    -1.000000E+30    -7.141249E-01     1.000000E+30           
         74  traj.phase.states:v_12           c    -1.000000E+30    -6.153610E-01     1.000000E+30           
         75  traj.phase.states:v_13           c    -1.000000E+30    -5.040547E-01     1.000000E+30           
         76  traj.phase.states:v_14           c    -1.000000E+30    -3.872532E-01     1.000000E+30           
         77  traj.phase.states:v_15           c    -1.000000E+30    -2.703927E-01     1.000000E+30           
         78  traj.phase.states:v_16           c    -1.000000E+30    -1.636762E-01     1.000000E+30           
         79  traj.phase.states:v_17           c    -1.000000E+30    -7.677782E-02     1.000000E+30           
         80  traj.phase.states:v_18           c    -1.000000E+30    -1.986720E-02     1.000000E+30           
         81  traj.phase.states:v_19           c    -1.000000E+30    -6.715422E-18     1.000000E+30           
         82  traj.phase.state_rates:v_0       c    -1.000000E+30    -6.986133E-01     1.000000E+30           
         83  traj.phase.state_rates:v_1       c    -1.000000E+30    -6.986134E-01     1.000000E+30           
         84  traj.phase.state_rates:v_2       c    -1.000000E+30    -6.986134E-01     1.000000E+30           
         85  traj.phase.state_rates:v_3       c    -1.000000E+30    -6.986134E-01     1.000000E+30           
         86  traj.phase.state_rates:v_4       c    -1.000000E+30    -6.986134E-01     1.000000E+30           
         87  traj.phase.state_rates:v_5       c    -1.000000E+30    -3.997705E-01     1.000000E+30           
         88  traj.phase.state_rates:v_6       c    -1.000000E+30     1.930710E-01     1.000000E+30           
         89  traj.phase.state_rates:v_7       c    -1.000000E+30     2.474667E-01     1.000000E+30           
         90  traj.phase.state_rates:v_8       c    -1.000000E+30     3.095485E-01     1.000000E+30           
         91  traj.phase.state_rates:v_9       c    -1.000000E+30     3.864465E-01     1.000000E+30           
         92  traj.phase.state_rates:v_10      c    -1.000000E+30     4.751158E-01     1.000000E+30           
         93  traj.phase.state_rates:v_11      c    -1.000000E+30     5.799643E-01     1.000000E+30           
         94  traj.phase.state_rates:v_12      c    -1.000000E+30     6.980260E-01     1.000000E+30           
         95  traj.phase.state_rates:v_13      c    -1.000000E+30     8.307085E-01     1.000000E+30           
         96  traj.phase.state_rates:v_14      c    -1.000000E+30     9.719486E-01     1.000000E+30           
         97  traj.phase.state_rates:v_15      c    -1.000000E+30     1.116772E+00     1.000000E+30           
         98  traj.phase.state_rates:v_16      c    -1.000000E+30     1.252712E+00     1.000000E+30           
         99  traj.phase.state_rates:v_17      c    -1.000000E+30     1.366703E+00     1.000000E+30           
        100  traj.phase.state_rates:v_18      c    -1.000000E+30     1.442978E+00     1.000000E+30           
        101  traj.phase.state_rates:v_19      c    -1.000000E+30     1.469952E+00     1.000000E+30           
        102  traj.phase.final_states:v_0      c    -1.000000E+30     1.466239E-29     1.000000E+30           
        103  traj.phase.states:m_0            c     1.000000E-03     1.000000E+00     1.000000E+30           
        104  traj.phase.states:m_1            c     1.000000E-03     1.000003E+00     1.000000E+30           
        105  traj.phase.states:m_2            c     1.000000E-03     9.999805E-01     1.000000E+30           
        106  traj.phase.states:m_3            c     1.000000E-03     1.000026E+00     1.000000E+30           
        107  traj.phase.states:m_4            c     1.000000E-03     1.000087E+00     1.000000E+30           
        108  traj.phase.states:m_5            c     1.000000E-03     9.951016E-01     1.000000E+30           
        109  traj.phase.states:m_6            c     1.000000E-03     9.613252E-01     1.000000E+30           
        110  traj.phase.states:m_7            c     1.000000E-03     9.060529E-01     1.000000E+30           
        111  traj.phase.states:m_8            c     1.000000E-03     8.502589E-01     1.000000E+30           
        112  traj.phase.states:m_9            c     1.000000E-03     7.900012E-01     1.000000E+30           
        113  traj.phase.states:m_10           c     1.000000E-03     7.303206E-01     1.000000E+30           
        114  traj.phase.states:m_11           c     1.000000E-03     6.704314E-01     1.000000E+30           
        115  traj.phase.states:m_12           c     1.000000E-03     6.137581E-01     1.000000E+30           
        116  traj.phase.states:m_13           c     1.000000E-03     5.605090E-01     1.000000E+30           
        117  traj.phase.states:m_14           c     1.000000E-03     5.131199E-01     1.000000E+30           
        118  traj.phase.states:m_15           c     1.000000E-03     4.721855E-01     1.000000E+30           
        119  traj.phase.states:m_16           c     1.000000E-03     4.392904E-01     1.000000E+30           
        120  traj.phase.states:m_17           c     1.000000E-03     4.150448E-01     1.000000E+30           
        121  traj.phase.states:m_18           c     1.000000E-03     4.002624E-01     1.000000E+30           
        122  traj.phase.states:m_19           c     1.000000E-03     3.952837E-01     1.000000E+30           
        123  traj.phase.state_rates:m_0       c    -1.000000E+30    -5.651950E-08     1.000000E+30           
        124  traj.phase.state_rates:m_1       c    -1.000000E+30    -3.570203E-09     1.000000E+30           
        125  traj.phase.state_rates:m_2       c    -1.000000E+30    -6.070162E-10     1.000000E+30           
        126  traj.phase.state_rates:m_3       c    -1.000000E+30    -4.040443E-10     1.000000E+30           
        127  traj.phase.state_rates:m_4       c    -1.000000E+30    -1.322227E-09     1.000000E+30           
        128  traj.phase.state_rates:m_5       c    -1.000000E+30    -1.265982E-01     1.000000E+30           
        129  traj.phase.state_rates:m_6       c    -1.000000E+30    -3.649207E-01     1.000000E+30           
        130  traj.phase.state_rates:m_7       c    -1.000000E+30    -3.649207E-01     1.000000E+30           
        131  traj.phase.state_rates:m_8       c    -1.000000E+30    -3.649207E-01     1.000000E+30           
        132  traj.phase.state_rates:m_9       c    -1.000000E+30    -3.649207E-01     1.000000E+30           
        133  traj.phase.state_rates:m_10      c    -1.000000E+30    -3.649207E-01     1.000000E+30           
        134  traj.phase.state_rates:m_11      c    -1.000000E+30    -3.649207E-01     1.000000E+30           
        135  traj.phase.state_rates:m_12      c    -1.000000E+30    -3.649207E-01     1.000000E+30           
        136  traj.phase.state_rates:m_13      c    -1.000000E+30    -3.649207E-01     1.000000E+30           
        137  traj.phase.state_rates:m_14      c    -1.000000E+30    -3.649207E-01     1.000000E+30           
        138  traj.phase.state_rates:m_15      c    -1.000000E+30    -3.649207E-01     1.000000E+30           
        139  traj.phase.state_rates:m_16      c    -1.000000E+30    -3.649207E-01     1.000000E+30           
        140  traj.phase.state_rates:m_17      c    -1.000000E+30    -3.649207E-01     1.000000E+30           
        141  traj.phase.state_rates:m_18      c    -1.000000E+30    -3.649207E-01     1.000000E+30           
        142  traj.phase.state_rates:m_19      c    -1.000000E+30    -3.649207E-01     1.000000E+30           
        143  traj.phase.final_states:m_0      c    -1.000000E+30     3.952837E-01     1.000000E+30           

   Constraints (i - inequality, e - equality)
      Index  Name                                            Type          Lower           Value           Upper    Status  Lagrange Multiplier (N/A)
          0  traj.phases.phase->final_boundary_constraint->h    e   0.000000E+00    0.000000E+00    0.000000E+00              9.00000E+100
          1  traj.phases.phase->final_boundary_constraint->v    e   0.000000E+00    1.466239E-29    0.000000E+00              9.00000E+100
          2  traj.phase.state_defects:h                         e   1.000000E+00    1.000000E+00    1.000000E+00              9.00000E+100
          3  traj.phase.state_defects:h                         e   1.000000E+00    1.000000E+00    1.000000E+00              9.00000E+100
          4  traj.phase.state_defects:h                         e   1.000000E+00    1.000000E+00    1.000000E+00              9.00000E+100
          5  traj.phase.state_defects:h                         e   1.000000E+00    1.000000E+00    1.000000E+00              9.00000E+100
          6  traj.phase.state_defects:h                         e   1.000000E+00    1.000000E+00    1.000000E+00              9.00000E+100
          7  traj.phase.state_defects:h                         e   1.000000E+00    1.000000E+00    1.000000E+00              9.00000E+100
          8  traj.phase.state_defects:h                         e   1.000000E+00    1.000000E+00    1.000000E+00              9.00000E+100
          9  traj.phase.state_defects:h                         e   1.000000E+00    1.000000E+00    1.000000E+00              9.00000E+100
         10  traj.phase.state_defects:h                         e   1.000000E+00    1.000000E+00    1.000000E+00              9.00000E+100
         11  traj.phase.state_defects:h                         e   1.000000E+00    1.000000E+00    1.000000E+00              9.00000E+100
         12  traj.phase.state_defects:h                         e   1.000000E+00    1.000000E+00    1.000000E+00              9.00000E+100
         13  traj.phase.state_defects:h                         e   1.000000E+00    1.000000E+00    1.000000E+00              9.00000E+100
         14  traj.phase.state_defects:h                         e   1.000000E+00    1.000000E+00    1.000000E+00              9.00000E+100
         15  traj.phase.state_defects:h                         e   1.000000E+00    1.000000E+00    1.000000E+00              9.00000E+100
         16  traj.phase.state_defects:h                         e   1.000000E+00    1.000000E+00    1.000000E+00              9.00000E+100
         17  traj.phase.state_defects:h                         e   1.000000E+00    1.000000E+00    1.000000E+00              9.00000E+100
         18  traj.phase.state_defects:h                         e   1.000000E+00    1.000000E+00    1.000000E+00              9.00000E+100
         19  traj.phase.state_defects:h                         e   1.000000E+00    1.000000E+00    1.000000E+00              9.00000E+100
         20  traj.phase.state_defects:h                         e   1.000000E+00    1.000000E+00    1.000000E+00              9.00000E+100
         21  traj.phase.state_defects:h                         e   1.000000E+00    1.000000E+00    1.000000E+00              9.00000E+100
         22  traj.phase.state_defects:h                         e  -1.000000E+00   -1.000000E+00   -1.000000E+00              9.00000E+100
         23  traj.phase.state_rate_defects:h                    e   0.000000E+00    0.000000E+00    0.000000E+00              9.00000E+100
         24  traj.phase.state_rate_defects:h                    e   0.000000E+00   -7.371881E-14    0.000000E+00              9.00000E+100
         25  traj.phase.state_rate_defects:h                    e   0.000000E+00   -6.938894E-14    0.000000E+00              9.00000E+100
         26  traj.phase.state_rate_defects:h                    e   0.000000E+00   -1.553202E-13    0.000000E+00              9.00000E+100
         27  traj.phase.state_rate_defects:h                    e   0.000000E+00   -2.114975E-13    0.000000E+00              9.00000E+100
         28  traj.phase.state_rate_defects:h                    e   0.000000E+00   -2.492451E-13    0.000000E+00              9.00000E+100
         29  traj.phase.state_rate_defects:h                    e   0.000000E+00   -7.283063E-14    0.000000E+00              9.00000E+100
         30  traj.phase.state_rate_defects:h                    e   0.000000E+00   -7.704948E-14    0.000000E+00              9.00000E+100
         31  traj.phase.state_rate_defects:h                    e   0.000000E+00   -9.103829E-15    0.000000E+00              9.00000E+100
         32  traj.phase.state_rate_defects:h                    e   0.000000E+00   -2.775558E-14    0.000000E+00              9.00000E+100
         33  traj.phase.state_rate_defects:h                    e   0.000000E+00    5.551115E-15    0.000000E+00              9.00000E+100
         34  traj.phase.state_rate_defects:h                    e   0.000000E+00   -6.605827E-15    0.000000E+00              9.00000E+100
         35  traj.phase.state_rate_defects:h                    e   0.000000E+00    2.831069E-15    0.000000E+00              9.00000E+100
         36  traj.phase.state_rate_defects:h                    e   0.000000E+00   -9.992007E-16    0.000000E+00              9.00000E+100
         37  traj.phase.state_rate_defects:h                    e   0.000000E+00   -9.992007E-15    0.000000E+00              9.00000E+100
         38  traj.phase.state_rate_defects:h                    e   0.000000E+00   -4.773959E-15    0.000000E+00              9.00000E+100
         39  traj.phase.state_rate_defects:h                    e   0.000000E+00   -2.363387E-14    0.000000E+00              9.00000E+100
         40  traj.phase.state_rate_defects:h                    e   0.000000E+00   -7.646661E-15    0.000000E+00              9.00000E+100
         41  traj.phase.state_rate_defects:h                    e   0.000000E+00   -2.470940E-14    0.000000E+00              9.00000E+100
         42  traj.phase.state_rate_defects:h                    e   0.000000E+00    1.108026E-29    0.000000E+00              9.00000E+100
         43  traj.phase.state_defects:v                         e  -7.830000E-01   -7.830000E-01   -7.830000E-01              9.00000E+100
         44  traj.phase.state_defects:v                         e  -7.830000E-01   -7.830000E-01   -7.830000E-01              9.00000E+100
         45  traj.phase.state_defects:v                         e  -7.830000E-01   -7.830000E-01   -7.830000E-01              9.00000E+100
         46  traj.phase.state_defects:v                         e  -7.830000E-01   -7.830000E-01   -7.830000E-01              9.00000E+100
         47  traj.phase.state_defects:v                         e  -7.830000E-01   -7.830000E-01   -7.830000E-01              9.00000E+100
         48  traj.phase.state_defects:v                         e  -7.830000E-01   -7.830000E-01   -7.830000E-01              9.00000E+100
         49  traj.phase.state_defects:v                         e  -7.830000E-01   -7.830000E-01   -7.830000E-01              9.00000E+100
         50  traj.phase.state_defects:v                         e  -7.830000E-01   -7.830000E-01   -7.830000E-01              9.00000E+100
         51  traj.phase.state_defects:v                         e  -7.830000E-01   -7.830000E-01   -7.830000E-01              9.00000E+100
         52  traj.phase.state_defects:v                         e  -7.830000E-01   -7.830000E-01   -7.830000E-01              9.00000E+100
         53  traj.phase.state_defects:v                         e  -7.830000E-01   -7.830000E-01   -7.830000E-01              9.00000E+100
         54  traj.phase.state_defects:v                         e  -7.830000E-01   -7.830000E-01   -7.830000E-01              9.00000E+100
         55  traj.phase.state_defects:v                         e  -7.830000E-01   -7.830000E-01   -7.830000E-01              9.00000E+100
         56  traj.phase.state_defects:v                         e  -7.830000E-01   -7.830000E-01   -7.830000E-01              9.00000E+100
         57  traj.phase.state_defects:v                         e  -7.830000E-01   -7.830000E-01   -7.830000E-01              9.00000E+100
         58  traj.phase.state_defects:v                         e  -7.830000E-01   -7.830000E-01   -7.830000E-01              9.00000E+100
         59  traj.phase.state_defects:v                         e  -7.830000E-01   -7.830000E-01   -7.830000E-01              9.00000E+100
         60  traj.phase.state_defects:v                         e  -7.830000E-01   -7.830000E-01   -7.830000E-01              9.00000E+100
         61  traj.phase.state_defects:v                         e  -7.830000E-01   -7.830000E-01   -7.830000E-01              9.00000E+100
         62  traj.phase.state_defects:v                         e  -7.830000E-01   -7.830000E-01   -7.830000E-01              9.00000E+100
         63  traj.phase.state_defects:v                         e   7.830000E-01    7.830000E-01    7.830000E-01              9.00000E+100
         64  traj.phase.state_rate_defects:v                    e   0.000000E+00   -1.593492E-11    0.000000E+00              9.00000E+100
         65  traj.phase.state_rate_defects:v                    e   0.000000E+00   -3.216982E-12    0.000000E+00              9.00000E+100
         66  traj.phase.state_rate_defects:v                    e   0.000000E+00   -1.696532E-12    0.000000E+00              9.00000E+100
         67  traj.phase.state_rate_defects:v                    e   0.000000E+00   -2.151168E-12    0.000000E+00              9.00000E+100
         68  traj.phase.state_rate_defects:v                    e   0.000000E+00   -3.867795E-12    0.000000E+00              9.00000E+100
         69  traj.phase.state_rate_defects:v                    e   0.000000E+00    4.051981E-12    0.000000E+00              9.00000E+100
         70  traj.phase.state_rate_defects:v                    e   0.000000E+00    1.224298E-12    0.000000E+00              9.00000E+100
         71  traj.phase.state_rate_defects:v                    e   0.000000E+00    5.514478E-13    0.000000E+00              9.00000E+100
         72  traj.phase.state_rate_defects:v                    e   0.000000E+00    2.656764E-13    0.000000E+00              9.00000E+100
         73  traj.phase.state_rate_defects:v                    e   0.000000E+00    1.876277E-13    0.000000E+00              9.00000E+100
         74  traj.phase.state_rate_defects:v                    e   0.000000E+00    1.424971E-13    0.000000E+00              9.00000E+100
         75  traj.phase.state_rate_defects:v                    e   0.000000E+00    1.012523E-13    0.000000E+00              9.00000E+100
         76  traj.phase.state_rate_defects:v                    e   0.000000E+00    9.658940E-14    0.000000E+00              9.00000E+100
         77  traj.phase.state_rate_defects:v                    e   0.000000E+00    6.683543E-14    0.000000E+00              9.00000E+100
         78  traj.phase.state_rate_defects:v                    e   0.000000E+00    6.761258E-14    0.000000E+00              9.00000E+100
         79  traj.phase.state_rate_defects:v                    e   0.000000E+00    7.416290E-14    0.000000E+00              9.00000E+100
         80  traj.phase.state_rate_defects:v                    e   0.000000E+00    9.969803E-14    0.000000E+00              9.00000E+100
         81  traj.phase.state_rate_defects:v                    e   0.000000E+00    2.537970E-13    0.000000E+00              9.00000E+100
         82  traj.phase.state_rate_defects:v                    e   0.000000E+00    7.105427E-13    0.000000E+00              9.00000E+100
         83  traj.phase.state_rate_defects:v                    e   0.000000E+00    9.913181E-12    0.000000E+00              9.00000E+100
         84  traj.phase.state_defects:m                         e   1.000000E+00    1.000000E+00    1.000000E+00              9.00000E+100
         85  traj.phase.state_defects:m                         e   1.000000E+00    1.000000E+00    1.000000E+00              9.00000E+100
         86  traj.phase.state_defects:m                         e   1.000000E+00    1.000000E+00    1.000000E+00              9.00000E+100
         87  traj.phase.state_defects:m                         e   1.000000E+00    1.000000E+00    1.000000E+00              9.00000E+100
         88  traj.phase.state_defects:m                         e   1.000000E+00    1.000000E+00    1.000000E+00              9.00000E+100
         89  traj.phase.state_defects:m                         e   1.000000E+00    1.000000E+00    1.000000E+00              9.00000E+100
         90  traj.phase.state_defects:m                         e   1.000000E+00    1.000000E+00    1.000000E+00              9.00000E+100
         91  traj.phase.state_defects:m                         e   1.000000E+00    1.000000E+00    1.000000E+00              9.00000E+100
         92  traj.phase.state_defects:m                         e   1.000000E+00    1.000000E+00    1.000000E+00              9.00000E+100
         93  traj.phase.state_defects:m                         e   1.000000E+00    1.000000E+00    1.000000E+00              9.00000E+100
         94  traj.phase.state_defects:m                         e   1.000000E+00    1.000000E+00    1.000000E+00              9.00000E+100
         95  traj.phase.state_defects:m                         e   1.000000E+00    1.000000E+00    1.000000E+00              9.00000E+100
         96  traj.phase.state_defects:m                         e   1.000000E+00    1.000000E+00    1.000000E+00              9.00000E+100
         97  traj.phase.state_defects:m                         e   1.000000E+00    1.000000E+00    1.000000E+00              9.00000E+100
         98  traj.phase.state_defects:m                         e   1.000000E+00    1.000000E+00    1.000000E+00              9.00000E+100
         99  traj.phase.state_defects:m                         e   1.000000E+00    1.000000E+00    1.000000E+00              9.00000E+100
        100  traj.phase.state_defects:m                         e   1.000000E+00    1.000000E+00    1.000000E+00              9.00000E+100
        101  traj.phase.state_defects:m                         e   1.000000E+00    1.000000E+00    1.000000E+00              9.00000E+100
        102  traj.phase.state_defects:m                         e   1.000000E+00    1.000000E+00    1.000000E+00              9.00000E+100
        103  traj.phase.state_defects:m                         e   1.000000E+00    1.000000E+00    1.000000E+00              9.00000E+100
        104  traj.phase.state_defects:m                         e  -1.000000E+00   -1.000000E+00   -1.000000E+00              9.00000E+100
        105  traj.phase.state_rate_defects:m                    e   0.000000E+00    6.783670E-12    0.000000E+00              9.00000E+100
        106  traj.phase.state_rate_defects:m                    e   0.000000E+00    9.471588E-13    0.000000E+00              9.00000E+100
        107  traj.phase.state_rate_defects:m                    e   0.000000E+00    5.043391E-13    0.000000E+00              9.00000E+100
        108  traj.phase.state_rate_defects:m                    e   0.000000E+00    4.648805E-13    0.000000E+00              9.00000E+100
        109  traj.phase.state_rate_defects:m                    e   0.000000E+00    7.062860E-13    0.000000E+00              9.00000E+100
        110  traj.phase.state_rate_defects:m                    e   0.000000E+00   -6.810386E-13    0.000000E+00              9.00000E+100
        111  traj.phase.state_rate_defects:m                    e   0.000000E+00   -3.422262E-13    0.000000E+00              9.00000E+100
        112  traj.phase.state_rate_defects:m                    e   0.000000E+00   -1.523226E-13    0.000000E+00              9.00000E+100
        113  traj.phase.state_rate_defects:m                    e   0.000000E+00   -8.643086E-14    0.000000E+00              9.00000E+100
        114  traj.phase.state_rate_defects:m                    e   0.000000E+00   -6.045164E-14    0.000000E+00              9.00000E+100
        115  traj.phase.state_rate_defects:m                    e   0.000000E+00   -4.457545E-14    0.000000E+00              9.00000E+100
        116  traj.phase.state_rate_defects:m                    e   0.000000E+00   -3.702594E-14    0.000000E+00              9.00000E+100
        117  traj.phase.state_rate_defects:m                    e   0.000000E+00   -3.153033E-14    0.000000E+00              9.00000E+100
        118  traj.phase.state_rate_defects:m                    e   0.000000E+00   -2.980949E-14    0.000000E+00              9.00000E+100
        119  traj.phase.state_rate_defects:m                    e   0.000000E+00   -2.886580E-14    0.000000E+00              9.00000E+100
        120  traj.phase.state_rate_defects:m                    e   0.000000E+00   -3.153033E-14    0.000000E+00              9.00000E+100
        121  traj.phase.state_rate_defects:m                    e   0.000000E+00   -3.635980E-14    0.000000E+00              9.00000E+100
        122  traj.phase.state_rate_defects:m                    e   0.000000E+00   -5.101475E-14    0.000000E+00              9.00000E+100
        123  traj.phase.state_rate_defects:m                    e   0.000000E+00   -9.697798E-14    0.000000E+00              9.00000E+100
        124  traj.phase.state_rate_defects:m                    e   0.000000E+00   -1.067257E-12    0.000000E+00              9.00000E+100


   Exit Status
      Inform  Description
           0  Solve Succeeded
--------------------------------------------------------------------------------
Problem: problem
Driver:  pyOptSparseDriver
  success     : True
  iterations  : 18
  runtime     : 5.9290E-01 s
  model_evals : 18
  model_time  : 1.2700E-02 s
  deriv_evals : 17
  deriv_time  : 5.7041E-02 s
  exit_status : SUCCESS
from IPython.display import HTML

# Define the path to the HTML file
html_file_path = p.get_reports_dir() / 'traj_results_report.html'
html_content = html_file_path.read_text()

# Inject CSS to control the output cell height and avoid scrollbars
html_with_custom_height = f"""
<div style="height: 800px; overflow: auto;">
    {html_content}
</div>
"""

HTML(html_with_custom_height)
trajectory results for traj

Notes on the solution#

We can see that the collocation solution accurately captures the jump in the thrust. The oscillatory behavior observed is a result of interpolation performed post solution rather than a property of the solution itself.

References#

[Med64]

J. Meditch. On the problem of optimal thrust programming for a lunar soft landing. IEEE Transactions on Automatic Control, 9(4):477–484, 1964. doi:10.1109/TAC.1964.1105758.