Cannonball Implicit Duration#

This example demonstrates determining the duration of a phase using a nonlinear solver to satisfy an endpoint condition. As in the multi-phase cannonball problem, we will simultaneously find the optimal design for the cannonball (its radius) and the optimal flight profile (its launch angle). However, here we will use a single phase that terminates at the condition

(96)#\[\begin{align} h(t_f) = 0 \end{align}\]

The cannonball sizing component#

This component computes the area (needed to compute drag) and mass (needed to compute energy) of a cannonball of a given radius and density.

This component sits upstream of the trajectory model and feeds its outputs to the trajectory as parameters.

import numpy as np
from scipy.interpolate import interp1d

import openmdao.api as om

import dymos as dm
from dymos.models.atmosphere.atmos_1976 import USatm1976Data

#############################################
# Component for the design part of the model
#############################################
class CannonballSizeComp(om.ExplicitComponent):
    """
    Compute the area and mass of a cannonball with a given radius and density.

    Notes
    -----
    This component is not vectorized with 'num_nodes' as is the usual way
    with Dymos, but is instead intended to compute a scalar mass and reference
    area from scalar radius and density inputs. This component does not reside
    in the ODE but instead its outputs are connected to the trajectory via
    input design parameters.
    """
    def setup(self):
        self.add_input(name='radius', val=1.0, desc='cannonball radius', units='m')
        self.add_input(name='dens', val=7870., desc='cannonball density', units='kg/m**3')

        self.add_output(name='mass', shape=(1,), desc='cannonball mass', units='kg')
        self.add_output(name='S', shape=(1,), desc='aerodynamic reference area', units='m**2')

        self.declare_partials(of='mass', wrt='dens')
        self.declare_partials(of='mass', wrt='radius')

        self.declare_partials(of='S', wrt='radius')

    def compute(self, inputs, outputs):
        radius = inputs['radius']
        dens = inputs['dens']

        outputs['mass'] = (4/3.) * dens * np.pi * radius ** 3
        outputs['S'] = np.pi * radius ** 2

    def compute_partials(self, inputs, partials):
        radius = inputs['radius']
        dens = inputs['dens']

        partials['mass', 'dens'] = (4/3.) * np.pi * radius ** 3
        partials['mass', 'radius'] = 4. * dens * np.pi * radius ** 2

        partials['S', 'radius'] = 2 * np.pi * radius

The cannonball ODE component#

This component computes the state rates and the kinetic energy of the cannonball. By calling the declare_coloring method wrt all inputs and using method 'cs', we’re telling OpenMDAO to automatically determine the sparsity pattern of the outputs with respect to the inputs, and to automatically compute those outputs using complex-step approximation.

class CannonballODE(om.ExplicitComponent):
    """
    Cannonball ODE assuming flat earth and accounting for air resistance
    """

    def initialize(self):
        self.options.declare('num_nodes', types=int)

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

        # static parameters
        self.add_input('m', units='kg')
        self.add_input('S', units='m**2')
        # 0.5 good assumption for a sphere
        self.add_input('CD', 0.5)

        # time varying inputs
        self.add_input('h', units='m', shape=nn)
        self.add_input('v', units='m/s', shape=nn)
        self.add_input('gam', units='rad', shape=nn)

        # state rates
        self.add_output('v_dot', shape=nn, units='m/s**2', tags=['dymos.state_rate_source:v'])
        self.add_output('gam_dot', shape=nn, units='rad/s', tags=['dymos.state_rate_source:gam'])
        self.add_output('h_dot', shape=nn, units='m/s', tags=['dymos.state_rate_source:h'])
        self.add_output('r_dot', shape=nn, units='m/s', tags=['dymos.state_rate_source:r'])
        self.add_output('ke', shape=nn, units='J')

        # Ask OpenMDAO to compute the partial derivatives using complex-step
        # with a partial coloring algorithm for improved performance, and use
        # a graph coloring algorithm to automatically detect the sparsity pattern.
        self.declare_coloring(wrt='*', method='cs')

        alt_data = USatm1976Data.alt * om.unit_conversion('ft', 'm')[0]
        rho_data = USatm1976Data.rho * om.unit_conversion('slug/ft**3', 'kg/m**3')[0]
        self.rho_interp = interp1d(np.array(alt_data, dtype=complex),
                                   np.array(rho_data, dtype=complex),
                                   kind='linear')

    def compute(self, inputs, outputs):

        gam = inputs['gam']
        v = inputs['v']
        h = inputs['h']
        m = inputs['m']
        S = inputs['S']
        CD = inputs['CD']

        GRAVITY = 9.80665  # m/s**2

        # handle complex-step gracefully from the interpolant
        if np.iscomplexobj(h):
            rho = self.rho_interp(inputs['h'])
        else:
            rho = self.rho_interp(inputs['h']).real

        q = 0.5*rho*inputs['v']**2
        qS = q * S
        D = qS * CD
        cgam = np.cos(gam)
        sgam = np.sin(gam)
        outputs['v_dot'] = - D/m-GRAVITY*sgam
        outputs['gam_dot'] = -(GRAVITY/v)*cgam
        outputs['h_dot'] = v*sgam
        outputs['r_dot'] = v*cgam
        outputs['ke'] = 0.5*m*v**2

Generating an initial guess#

Since we will be using a nonlinear solver to converge the dynamics and the duration, a simple linear initial guess will not be sufficient. The initial guess we will use is generated from the kinematics equations that assume no atmospheric drag. We compute the state values for some duration and initial flight path angle

def initial_guess(t_dur, gam0=np.pi/3):
    t = np.linspace(0, t_dur, num=100)
    g = -9.80665
    v0 = -0.5*g*t_dur/np.sin(gam0)
    r = v0*np.cos(gam0)*t
    h = v0*np.sin(gam0)*t + 0.5*g*t**2
    v = np.sqrt(v0*np.cos(gam0)**2 + (v0*np.sin(gam0) + g*t)**2)
    gam = np.arctan2(v0*np.sin(gam0) + g*t, v0*np.cos(gam0)**2)

    guess = {'t': t, 'r': r, 'h': h, 'v': v, 'gam': gam}

    return guess

Building and running the problem#

The following code defines the components for the physical cannonball calculations and ODE problem, sets up trajectory using a single phase, and specifies the stopping condition for the phase. The initial flight path angle is free, since 45 degrees is not necessarily optimal once air resistance is taken into account.

p = om.Problem(name='cannonball_implicit_duration', model=om.Group())

p.driver = om.pyOptSparseDriver()
p.driver.options['optimizer'] = 'IPOPT'
p.driver.declare_coloring()

p.driver.opt_settings['derivative_test'] = 'first-order'
p.driver.opt_settings['mu_strategy'] = 'monotone'
p.driver.opt_settings['alpha_for_y'] = 'safer-min-dual-infeas'
p.driver.opt_settings['bound_mult_init_method'] = 'mu-based'
p.driver.opt_settings['mu_init'] = 0.01
p.driver.opt_settings['nlp_scaling_method'] = 'gradient-based'

p.set_solver_print(level=0, depth=99)

p.model.add_subsystem('size_comp', CannonballSizeComp(),
                      promotes_inputs=['radius', 'dens'])
p.model.set_input_defaults('dens', val=7.87, units='g/cm**3')
p.model.add_design_var('radius', lower=0.01, upper=0.10,
                       ref0=0.01, ref=0.10, units='m')

traj = p.model.add_subsystem('traj', dm.Trajectory())

transcription = dm.Radau(num_segments=25, order=3, compressed=False)
phase = dm.Phase(ode_class=CannonballODE, transcription=transcription)

phase = traj.add_phase('phase', phase)

# Duration is bounded to be greater than 1 to ensure the nonlinear solve
# does not converge to the initial point.
phase.set_time_options(fix_initial=True, duration_bounds=(1, 100), units='s')

# All initial states except flight path angle are fixed
# The output of the ODE which provides the rate source for each state
# is obtained from the tags used on those outputs in the ODE.
# The units of the states are automatically inferred by multiplying the units
# of those rates by the time units.
phase.add_state('r', fix_initial=True, solve_segments='forward')
phase.add_state('h', fix_initial=True, solve_segments='forward')
phase.add_state('gam', fix_initial=False, solve_segments='forward')
phase.add_state('v', fix_initial=False, solve_segments='forward')

phase.add_parameter('S', units='m**2', static_target=True)
phase.add_parameter('m', units='kg', static_target=True)
phase.add_parameter('CD', val=0.5, opt=False, static_target=True)

phase.add_boundary_constraint('ke', loc='initial',
                              upper=400000, lower=0, ref=100000)

# A duration balance is added setting altitude to zero.
# A nonlinear solver is used to find the duration of required to satisfy the condition.
phase.set_duration_balance('h', val=0.0)

# Prior to setup, this phase has the default NonlinearRunOnce and LinearRunOnce solvers.
# Because of the implicit behavior introduced by set_duration_balance, it will automatically
# use a NewtonSolver with an Armijo Goldstein linesearch.
# In this case that linesearch causes extrapolation of the atmospheric model into invalid regions.
# To account for this, we explicitly assign a NewtonSolver with a different linesearch.
phase.nonlinear_solver = om.NewtonSolver(iprint=0, solve_subsystems=True)
phase.nonlinear_solver.linesearch = None

phase.add_objective('r', loc='final', scaler=-1.0)

p.model.connect('size_comp.mass', 'traj.phase.parameters:m')
p.model.connect('size_comp.S', 'traj.phase.parameters:S')

# Finish Problem Setup
p.setup()

#############################################
# Set constants and initial guesses
#############################################
p.set_val('radius', 0.05, units='m')
p.set_val('dens', 7.87, units='g/cm**3')

p.set_val('traj.phase.parameters:CD', 0.5)

guess = initial_guess(t_dur=30.0)

phase.set_time_val(initial=0.0, duration=30.0)

phase.set_state_val('r', vals=guess['r'], time_vals=guess['t'])
phase.set_state_val('h', vals=guess['h'], time_vals=guess['t'])
phase.set_state_val('v', vals=guess['v'], time_vals=guess['t'])
phase.set_state_val('gam', vals=guess['gam'], time_vals=guess['t'], units='rad')

#####################################################
# Run the optimization and final explicit simulation
#####################################################
dm.run_problem(p, simulate=True, make_plots=True)
/usr/share/miniconda/envs/test/lib/python3.11/site-packages/dymos/transcriptions/transcription_base.py:390: OpenMDAOWarning:'traj.phases.phase' <class Phase>
  Non-default solvers are required
    implicit duration: True
    solved segments: True
    input initial: False
  Setting `traj.phases.phase.linear_solver = om.DirectSolver(iprint=2)`
  Explicitly set traj.phases.phase.linear_solver to override.
  Set `traj.phases.phase.options["auto_solvers"] = False` to disable this behavior.
--- Constraint Report [traj] ---
    --- phase ---
        [initial] 0.0000e+00 <= ke <= 4.0000e+05  [J]


'rhs_checking' is disabled for 'DirectSolver in 'traj.phases.phase' <class Phase>' but that solver has redundant adjoint solves. If it is expensive to compute derivatives for this solver, turning on 'rhs_checking' may improve performance.

Model viewer data has already been recorded for Driver.
Model viewer data has already been recorded for Driver.
Coloring for 'traj.phases.phase.rhs_all' (class CannonballODE)

Jacobian shape: (500, 303)  (0.92% nonzero)
FWD solves: 6   REV solves: 0
Total colors vs. total size: 6 vs 303  (98.02% improvement)

Sparsity computed using tolerance: 1e-25
Time to compute sparsity:   0.0906 sec
Time to compute coloring:   0.0306 sec
Memory to compute coloring:   0.5000 MB
Full total jacobian for problem 'cannonball_implicit_duration' was computed 3 times, taking 0.2586173249999888 seconds.
Total jacobian shape: (98, 100) 


Jacobian shape: (98, 100)  (24.16% nonzero)
FWD solves: 27   REV solves: 0
Total colors vs. total size: 27 vs 100  (73.00% improvement)

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

    Solution: 
--------------------------------------------------------------------------------
    Total Time:                   16.5382
       User Objective Time :      13.9506
       User Sensitivity Time :     2.2749
       Interface Time :            0.1671
       Opt Solver Time:            0.1456
    Calls to Objective Function :     239
    Calls to Sens Function :           55


   Objectives
      Index  Name                           Value
          0  traj.phase.states:r    -3.182962E+03

   Variables (c - continuous, i - integer, d - discrete)
      Index  Name                       Type      Lower Bound            Value      Upper Bound     Status
          0  radius_0                      c     0.000000E+00     3.540939E-01     1.000000E+00           
          1  traj.phase.t_duration_0       c     1.000000E+00     1.000000E+02     1.000000E+02          u
          2  traj.phase.states:r_0         c    -1.000000E+21     4.358669E+02     1.000000E+21           
          3  traj.phase.states:r_1         c    -1.000000E+21     7.590741E+02     1.000000E+21           
          4  traj.phase.states:r_2         c    -1.000000E+21     1.017857E+03     1.000000E+21           
          5  traj.phase.states:r_3         c    -1.000000E+21     1.234831E+03     1.000000E+21           
          6  traj.phase.states:r_4         c    -1.000000E+21     1.422453E+03     1.000000E+21           
          7  traj.phase.states:r_5         c    -1.000000E+21     1.588316E+03     1.000000E+21           
          8  traj.phase.states:r_6         c    -1.000000E+21     1.737381E+03     1.000000E+21           
          9  traj.phase.states:r_7         c    -1.000000E+21     1.873054E+03     1.000000E+21           
         10  traj.phase.states:r_8         c    -1.000000E+21     1.997754E+03     1.000000E+21           
         11  traj.phase.states:r_9         c    -1.000000E+21     2.113240E+03     1.000000E+21           
         12  traj.phase.states:r_10        c    -1.000000E+21     2.220813E+03     1.000000E+21           
         13  traj.phase.states:r_11        c    -1.000000E+21     2.321446E+03     1.000000E+21           
         14  traj.phase.states:r_12        c    -1.000000E+21     2.415862E+03     1.000000E+21           
         15  traj.phase.states:r_13        c    -1.000000E+21     2.504609E+03     1.000000E+21           
         16  traj.phase.states:r_14        c    -1.000000E+21     2.588097E+03     1.000000E+21           
         17  traj.phase.states:r_15        c    -1.000000E+21     2.666639E+03     1.000000E+21           
         18  traj.phase.states:r_16        c    -1.000000E+21     2.740483E+03     1.000000E+21           
         19  traj.phase.states:r_17        c    -1.000000E+21     2.809828E+03     1.000000E+21           
         20  traj.phase.states:r_18        c    -1.000000E+21     2.874850E+03     1.000000E+21           
         21  traj.phase.states:r_19        c    -1.000000E+21     2.935708E+03     1.000000E+21           
         22  traj.phase.states:r_20        c    -1.000000E+21     2.992555E+03     1.000000E+21           
         23  traj.phase.states:r_21        c    -1.000000E+21     3.045544E+03     1.000000E+21           
         24  traj.phase.states:r_22        c    -1.000000E+21     3.094833E+03     1.000000E+21           
         25  traj.phase.states:r_23        c    -1.000000E+21     3.140584E+03     1.000000E+21           
         26  traj.phase.states:h_0         c    -1.000000E+21     2.675246E+02     1.000000E+21           
         27  traj.phase.states:h_1         c    -1.000000E+21     4.559862E+02     1.000000E+21           
         28  traj.phase.states:h_2         c    -1.000000E+21     5.966683E+02     1.000000E+21           
         29  traj.phase.states:h_3         c    -1.000000E+21     7.042126E+02     1.000000E+21           
         30  traj.phase.states:h_4         c    -1.000000E+21     7.866604E+02     1.000000E+21           
         31  traj.phase.states:h_5         c    -1.000000E+21     8.488963E+02     1.000000E+21           
         32  traj.phase.states:h_6         c    -1.000000E+21     8.941007E+02     1.000000E+21           
         33  traj.phase.states:h_7         c    -1.000000E+21     9.244542E+02     1.000000E+21           
         34  traj.phase.states:h_8         c    -1.000000E+21     9.415152E+02     1.000000E+21           
         35  traj.phase.states:h_9         c    -1.000000E+21     9.464412E+02     1.000000E+21           
         36  traj.phase.states:h_10        c    -1.000000E+21     9.401270E+02     1.000000E+21           
         37  traj.phase.states:h_11        c    -1.000000E+21     9.232973E+02     1.000000E+21           
         38  traj.phase.states:h_12        c    -1.000000E+21     8.965701E+02     1.000000E+21           
         39  traj.phase.states:h_13        c    -1.000000E+21     8.605033E+02     1.000000E+21           
         40  traj.phase.states:h_14        c    -1.000000E+21     8.156262E+02     1.000000E+21           
         41  traj.phase.states:h_15        c    -1.000000E+21     7.624607E+02     1.000000E+21           
         42  traj.phase.states:h_16        c    -1.000000E+21     7.015341E+02     1.000000E+21           
         43  traj.phase.states:h_17        c    -1.000000E+21     6.333833E+02     1.000000E+21           
         44  traj.phase.states:h_18        c    -1.000000E+21     5.585557E+02     1.000000E+21           
         45  traj.phase.states:h_19        c    -1.000000E+21     4.776046E+02     1.000000E+21           
         46  traj.phase.states:h_20        c    -1.000000E+21     3.910839E+02     1.000000E+21           
         47  traj.phase.states:h_21        c    -1.000000E+21     2.995404E+02     1.000000E+21           
         48  traj.phase.states:h_22        c    -1.000000E+21     2.035072E+02     1.000000E+21           
         49  traj.phase.states:h_23        c    -1.000000E+21     1.034977E+02     1.000000E+21           
         50  traj.phase.states:gam_0       c    -1.000000E+21     5.588424E-01     1.000000E+21           
         51  traj.phase.states:gam_1       c    -1.000000E+21     5.398186E-01     1.000000E+21           
         52  traj.phase.states:gam_2       c    -1.000000E+21     5.135922E-01     1.000000E+21           
         53  traj.phase.states:gam_3       c    -1.000000E+21     4.797863E-01     1.000000E+21           
         54  traj.phase.states:gam_4       c    -1.000000E+21     4.379029E-01     1.000000E+21           
         55  traj.phase.states:gam_5       c    -1.000000E+21     3.873723E-01     1.000000E+21           
         56  traj.phase.states:gam_6       c    -1.000000E+21     3.276275E-01     1.000000E+21           
         57  traj.phase.states:gam_7       c    -1.000000E+21     2.582142E-01     1.000000E+21           
         58  traj.phase.states:gam_8       c    -1.000000E+21     1.789451E-01     1.000000E+21           
         59  traj.phase.states:gam_9       c    -1.000000E+21     9.009145E-02     1.000000E+21           
         60  traj.phase.states:gam_10      c    -1.000000E+21    -7.423020E-03     1.000000E+21           
         61  traj.phase.states:gam_11      c    -1.000000E+21    -1.118970E-01     1.000000E+21           
         62  traj.phase.states:gam_12      c    -1.000000E+21    -2.208805E-01     1.000000E+21           
         63  traj.phase.states:gam_13      c    -1.000000E+21    -3.314120E-01     1.000000E+21           
         64  traj.phase.states:gam_14      c    -1.000000E+21    -4.404248E-01     1.000000E+21           
         65  traj.phase.states:gam_15      c    -1.000000E+21    -5.451909E-01     1.000000E+21           
         66  traj.phase.states:gam_16      c    -1.000000E+21    -6.436480E-01     1.000000E+21           
         67  traj.phase.states:gam_17      c    -1.000000E+21    -7.345244E-01     1.000000E+21           
         68  traj.phase.states:gam_18      c    -1.000000E+21    -8.172791E-01     1.000000E+21           
         69  traj.phase.states:gam_19      c    -1.000000E+21    -8.919361E-01     1.000000E+21           
         70  traj.phase.states:gam_20      c    -1.000000E+21    -9.588926E-01     1.000000E+21           
         71  traj.phase.states:gam_21      c    -1.000000E+21    -1.018753E+00     1.000000E+21           
         72  traj.phase.states:gam_22      c    -1.000000E+21    -1.072207E+00     1.000000E+21           
         73  traj.phase.states:gam_23      c    -1.000000E+21    -1.119950E+00     1.000000E+21           
         74  traj.phase.states:gam_24      c    -1.000000E+21    -1.162642E+00     1.000000E+21           
         75  traj.phase.states:v_0         c    -1.000000E+21     5.750200E+02     1.000000E+21           
         76  traj.phase.states:v_1         c    -1.000000E+21     3.997227E+02     1.000000E+21           
         77  traj.phase.states:v_2         c    -1.000000E+21     3.060110E+02     1.000000E+21           
         78  traj.phase.states:v_3         c    -1.000000E+21     2.471802E+02     1.000000E+21           
         79  traj.phase.states:v_4         c    -1.000000E+21     2.066205E+02     1.000000E+21           
         80  traj.phase.states:v_5         c    -1.000000E+21     1.769413E+02     1.000000E+21           
         81  traj.phase.states:v_6         c    -1.000000E+21     1.543746E+02     1.000000E+21           
         82  traj.phase.states:v_7         c    -1.000000E+21     1.368146E+02     1.000000E+21           
         83  traj.phase.states:v_8         c    -1.000000E+21     1.230084E+02     1.000000E+21           
         84  traj.phase.states:v_9         c    -1.000000E+21     1.121738E+02     1.000000E+21           
         85  traj.phase.states:v_10        c    -1.000000E+21     1.037991E+02     1.000000E+21           
         86  traj.phase.states:v_11        c    -1.000000E+21     9.752646E+01     1.000000E+21           
         87  traj.phase.states:v_12        c    -1.000000E+21     9.307779E+01     1.000000E+21           
         88  traj.phase.states:v_13        c    -1.000000E+21     9.020964E+01     1.000000E+21           
         89  traj.phase.states:v_14        c    -1.000000E+21     8.868763E+01     1.000000E+21           
         90  traj.phase.states:v_15        c    -1.000000E+21     8.827834E+01     1.000000E+21           
         91  traj.phase.states:v_16        c    -1.000000E+21     8.875205E+01     1.000000E+21           
         92  traj.phase.states:v_17        c    -1.000000E+21     8.989109E+01     1.000000E+21           
         93  traj.phase.states:v_18        c    -1.000000E+21     9.149866E+01     1.000000E+21           
         94  traj.phase.states:v_19        c    -1.000000E+21     9.340455E+01     1.000000E+21           
         95  traj.phase.states:v_20        c    -1.000000E+21     9.546736E+01     1.000000E+21           
         96  traj.phase.states:v_21        c    -1.000000E+21     9.757524E+01     1.000000E+21           
         97  traj.phase.states:v_22        c    -1.000000E+21     9.964293E+01     1.000000E+21           
         98  traj.phase.states:v_23        c    -1.000000E+21     1.016075E+02     1.000000E+21           
         99  traj.phase.states:v_24        c    -1.000000E+21     1.034255E+02     1.000000E+21           

   Constraints (i - inequality, e - equality)
      Index  Name                                               Type          Lower           Value           Upper    Status  Lagrange Multiplier (N/A)
          0  traj.phase.continuity_comp.defect_states:r            e   0.000000E+00   -9.663381E-12    0.000000E+00              9.00000E+100
          1  traj.phase.continuity_comp.defect_states:r            e   0.000000E+00   -1.284661E-11    0.000000E+00              9.00000E+100
          2  traj.phase.continuity_comp.defect_states:r            e   0.000000E+00   -1.136868E-11    0.000000E+00              9.00000E+100
          3  traj.phase.continuity_comp.defect_states:r            e   0.000000E+00   -1.000444E-11    0.000000E+00              9.00000E+100
          4  traj.phase.continuity_comp.defect_states:r            e   0.000000E+00   -8.412826E-12    0.000000E+00              9.00000E+100
          5  traj.phase.continuity_comp.defect_states:r            e   0.000000E+00   -7.275958E-12    0.000000E+00              9.00000E+100
          6  traj.phase.continuity_comp.defect_states:r            e   0.000000E+00   -6.366463E-12    0.000000E+00              9.00000E+100
          7  traj.phase.continuity_comp.defect_states:r            e   0.000000E+00   -5.002221E-12    0.000000E+00              9.00000E+100
          8  traj.phase.continuity_comp.defect_states:r            e   0.000000E+00   -4.320100E-12    0.000000E+00              9.00000E+100
          9  traj.phase.continuity_comp.defect_states:r            e   0.000000E+00   -5.002221E-12    0.000000E+00              9.00000E+100
         10  traj.phase.continuity_comp.defect_states:r            e   0.000000E+00   -3.637979E-12    0.000000E+00              9.00000E+100
         11  traj.phase.continuity_comp.defect_states:r            e   0.000000E+00   -2.728484E-12    0.000000E+00              9.00000E+100
         12  traj.phase.continuity_comp.defect_states:r            e   0.000000E+00   -2.728484E-12    0.000000E+00              9.00000E+100
         13  traj.phase.continuity_comp.defect_states:r            e   0.000000E+00   -2.273737E-12    0.000000E+00              9.00000E+100
         14  traj.phase.continuity_comp.defect_states:r            e   0.000000E+00   -3.183231E-12    0.000000E+00              9.00000E+100
         15  traj.phase.continuity_comp.defect_states:r            e   0.000000E+00   -3.183231E-12    0.000000E+00              9.00000E+100
         16  traj.phase.continuity_comp.defect_states:r            e   0.000000E+00   -4.547474E-13    0.000000E+00              9.00000E+100
         17  traj.phase.continuity_comp.defect_states:r            e   0.000000E+00   -4.547474E-13    0.000000E+00              9.00000E+100
         18  traj.phase.continuity_comp.defect_states:r            e   0.000000E+00   -2.273737E-12    0.000000E+00              9.00000E+100
         19  traj.phase.continuity_comp.defect_states:r            e   0.000000E+00   -1.364242E-12    0.000000E+00              9.00000E+100
         20  traj.phase.continuity_comp.defect_states:r            e   0.000000E+00   -9.094947E-13    0.000000E+00              9.00000E+100
         21  traj.phase.continuity_comp.defect_states:r            e   0.000000E+00    4.547474E-13    0.000000E+00              9.00000E+100
         22  traj.phase.continuity_comp.defect_states:r            e   0.000000E+00   -4.547474E-13    0.000000E+00              9.00000E+100
         23  traj.phase.continuity_comp.defect_states:r            e   0.000000E+00    4.547474E-13    0.000000E+00              9.00000E+100
         24  traj.phase.continuity_comp.defect_states:h            e   0.000000E+00   -2.330580E-11    0.000000E+00              9.00000E+100
         25  traj.phase.continuity_comp.defect_states:h            e   0.000000E+00   -1.483613E-11    0.000000E+00              9.00000E+100
         26  traj.phase.continuity_comp.defect_states:h            e   0.000000E+00   -9.549694E-12    0.000000E+00              9.00000E+100
         27  traj.phase.continuity_comp.defect_states:h            e   0.000000E+00   -6.139089E-12    0.000000E+00              9.00000E+100
         28  traj.phase.continuity_comp.defect_states:h            e   0.000000E+00   -3.751666E-12    0.000000E+00              9.00000E+100
         29  traj.phase.continuity_comp.defect_states:h            e   0.000000E+00   -2.273737E-12    0.000000E+00              9.00000E+100
         30  traj.phase.continuity_comp.defect_states:h            e   0.000000E+00   -1.364242E-12    0.000000E+00              9.00000E+100
         31  traj.phase.continuity_comp.defect_states:h            e   0.000000E+00   -7.958079E-13    0.000000E+00              9.00000E+100
         32  traj.phase.continuity_comp.defect_states:h            e   0.000000E+00    2.273737E-13    0.000000E+00              9.00000E+100
         33  traj.phase.continuity_comp.defect_states:h            e   0.000000E+00    4.547474E-13    0.000000E+00              9.00000E+100
         34  traj.phase.continuity_comp.defect_states:h            e   0.000000E+00    3.410605E-13    0.000000E+00              9.00000E+100
         35  traj.phase.continuity_comp.defect_states:h            e   0.000000E+00    7.958079E-13    0.000000E+00              9.00000E+100
         36  traj.phase.continuity_comp.defect_states:h            e   0.000000E+00    7.958079E-13    0.000000E+00              9.00000E+100
         37  traj.phase.continuity_comp.defect_states:h            e   0.000000E+00    1.591616E-12    0.000000E+00              9.00000E+100
         38  traj.phase.continuity_comp.defect_states:h            e   0.000000E+00    2.273737E-12    0.000000E+00              9.00000E+100
         39  traj.phase.continuity_comp.defect_states:h            e   0.000000E+00    2.955858E-12    0.000000E+00              9.00000E+100
         40  traj.phase.continuity_comp.defect_states:h            e   0.000000E+00    3.524292E-12    0.000000E+00              9.00000E+100
         41  traj.phase.continuity_comp.defect_states:h            e   0.000000E+00    3.979039E-12    0.000000E+00              9.00000E+100
         42  traj.phase.continuity_comp.defect_states:h            e   0.000000E+00    4.433787E-12    0.000000E+00              9.00000E+100
         43  traj.phase.continuity_comp.defect_states:h            e   0.000000E+00    5.002221E-12    0.000000E+00              9.00000E+100
         44  traj.phase.continuity_comp.defect_states:h            e   0.000000E+00    5.343281E-12    0.000000E+00              9.00000E+100
         45  traj.phase.continuity_comp.defect_states:h            e   0.000000E+00    5.513812E-12    0.000000E+00              9.00000E+100
         46  traj.phase.continuity_comp.defect_states:h            e   0.000000E+00    5.883294E-12    0.000000E+00              9.00000E+100
         47  traj.phase.continuity_comp.defect_states:h            e   0.000000E+00    6.195933E-12    0.000000E+00              9.00000E+100
         48  traj.phase.continuity_comp.defect_states:gam          e   0.000000E+00    1.887379E-15    0.000000E+00              9.00000E+100
         49  traj.phase.continuity_comp.defect_states:gam          e   0.000000E+00    1.776357E-15    0.000000E+00              9.00000E+100
         50  traj.phase.continuity_comp.defect_states:gam          e   0.000000E+00    2.442491E-15    0.000000E+00              9.00000E+100
         51  traj.phase.continuity_comp.defect_states:gam          e   0.000000E+00    3.164136E-15    0.000000E+00              9.00000E+100
         52  traj.phase.continuity_comp.defect_states:gam          e   0.000000E+00    4.274359E-15    0.000000E+00              9.00000E+100
         53  traj.phase.continuity_comp.defect_states:gam          e   0.000000E+00    5.884182E-15    0.000000E+00              9.00000E+100
         54  traj.phase.continuity_comp.defect_states:gam          e   0.000000E+00    7.882583E-15    0.000000E+00              9.00000E+100
         55  traj.phase.continuity_comp.defect_states:gam          e   0.000000E+00    9.547918E-15    0.000000E+00              9.00000E+100
         56  traj.phase.continuity_comp.defect_states:gam          e   0.000000E+00    1.193490E-14    0.000000E+00              9.00000E+100
         57  traj.phase.continuity_comp.defect_states:gam          e   0.000000E+00    1.283956E-14    0.000000E+00              9.00000E+100
         58  traj.phase.continuity_comp.defect_states:gam          e   0.000000E+00    1.300349E-14    0.000000E+00              9.00000E+100
         59  traj.phase.continuity_comp.defect_states:gam          e   0.000000E+00    1.204592E-14    0.000000E+00              9.00000E+100
         60  traj.phase.continuity_comp.defect_states:gam          e   0.000000E+00    9.936496E-15    0.000000E+00              9.00000E+100
         61  traj.phase.continuity_comp.defect_states:gam          e   0.000000E+00    7.216450E-15    0.000000E+00              9.00000E+100
         62  traj.phase.continuity_comp.defect_states:gam          e   0.000000E+00    4.884981E-15    0.000000E+00              9.00000E+100
         63  traj.phase.continuity_comp.defect_states:gam          e   0.000000E+00    2.331468E-15    0.000000E+00              9.00000E+100
         64  traj.phase.continuity_comp.defect_states:gam          e   0.000000E+00    1.776357E-15    0.000000E+00              9.00000E+100
         65  traj.phase.continuity_comp.defect_states:gam          e   0.000000E+00    6.661338E-16    0.000000E+00              9.00000E+100
         66  traj.phase.continuity_comp.defect_states:gam          e   0.000000E+00    5.551115E-16    0.000000E+00              9.00000E+100
         67  traj.phase.continuity_comp.defect_states:gam          e   0.000000E+00    3.330669E-16    0.000000E+00              9.00000E+100
         68  traj.phase.continuity_comp.defect_states:gam          e   0.000000E+00    6.661338E-16    0.000000E+00              9.00000E+100
         69  traj.phase.continuity_comp.defect_states:gam          e   0.000000E+00   -4.440892E-16    0.000000E+00              9.00000E+100
         70  traj.phase.continuity_comp.defect_states:gam          e   0.000000E+00    2.220446E-16    0.000000E+00              9.00000E+100
         71  traj.phase.continuity_comp.defect_states:gam          e   0.000000E+00    4.440892E-16    0.000000E+00              9.00000E+100
         72  traj.phase.continuity_comp.defect_states:v            e   0.000000E+00    2.273737E-11    0.000000E+00              9.00000E+100
         73  traj.phase.continuity_comp.defect_states:v            e   0.000000E+00    8.526513E-12    0.000000E+00              9.00000E+100
         74  traj.phase.continuity_comp.defect_states:v            e   0.000000E+00    4.263256E-12    0.000000E+00              9.00000E+100
         75  traj.phase.continuity_comp.defect_states:v            e   0.000000E+00    2.444267E-12    0.000000E+00              9.00000E+100
         76  traj.phase.continuity_comp.defect_states:v            e   0.000000E+00    1.676881E-12    0.000000E+00              9.00000E+100
         77  traj.phase.continuity_comp.defect_states:v            e   0.000000E+00    1.165290E-12    0.000000E+00              9.00000E+100
         78  traj.phase.continuity_comp.defect_states:v            e   0.000000E+00    7.958079E-13    0.000000E+00              9.00000E+100
         79  traj.phase.continuity_comp.defect_states:v            e   0.000000E+00    5.968559E-13    0.000000E+00              9.00000E+100
         80  traj.phase.continuity_comp.defect_states:v            e   0.000000E+00    3.552714E-13    0.000000E+00              9.00000E+100
         81  traj.phase.continuity_comp.defect_states:v            e   0.000000E+00    1.563194E-13    0.000000E+00              9.00000E+100
         82  traj.phase.continuity_comp.defect_states:v            e   0.000000E+00    2.842171E-14    0.000000E+00              9.00000E+100
         83  traj.phase.continuity_comp.defect_states:v            e   0.000000E+00   -5.684342E-14    0.000000E+00              9.00000E+100
         84  traj.phase.continuity_comp.defect_states:v            e   0.000000E+00   -1.563194E-13    0.000000E+00              9.00000E+100
         85  traj.phase.continuity_comp.defect_states:v            e   0.000000E+00   -1.847411E-13    0.000000E+00              9.00000E+100
         86  traj.phase.continuity_comp.defect_states:v            e   0.000000E+00   -2.273737E-13    0.000000E+00              9.00000E+100
         87  traj.phase.continuity_comp.defect_states:v            e   0.000000E+00   -1.847411E-13    0.000000E+00              9.00000E+100
         88  traj.phase.continuity_comp.defect_states:v            e   0.000000E+00   -9.947598E-14    0.000000E+00              9.00000E+100
         89  traj.phase.continuity_comp.defect_states:v            e   0.000000E+00   -7.105427E-14    0.000000E+00              9.00000E+100
         90  traj.phase.continuity_comp.defect_states:v            e   0.000000E+00   -1.421085E-14    0.000000E+00              9.00000E+100
         91  traj.phase.continuity_comp.defect_states:v            e   0.000000E+00    7.105427E-14    0.000000E+00              9.00000E+100
         92  traj.phase.continuity_comp.defect_states:v            e   0.000000E+00    1.136868E-13    0.000000E+00              9.00000E+100
         93  traj.phase.continuity_comp.defect_states:v            e   0.000000E+00    1.705303E-13    0.000000E+00              9.00000E+100
         94  traj.phase.continuity_comp.defect_states:v            e   0.000000E+00    2.557954E-13    0.000000E+00              9.00000E+100
         95  traj.phase.continuity_comp.defect_states:v            e   0.000000E+00    2.415845E-13    0.000000E+00              9.00000E+100
         96  traj.phases.phase->initial_boundary_constraint->ke    i   0.000000E+00    4.000000E+00    4.000000E+00         u    9.00000E+100


   Exit Status
      Inform  Description
           0  Solve Succeeded
--------------------------------------------------------------------------------
Simulating trajectory traj
Model viewer data has already been recorded for Driver.
Done simulating trajectory traj
Problem: cannonball_implicit_duration
Driver:  pyOptSparseDriver
  success     : True
  iterations  : 240
  runtime     : 1.7222E+01 s
  model_evals : 240
  model_time  : 1.3874E+01 s
  deriv_evals : 55
  deriv_time  : 2.0011E+00 s
  exit_status : SUCCESS

Displaying the timeseries data#

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