How to use the dymos.Phase function in dymos

To help you get started, we’ve selected a few dymos examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github OpenMDAO / dymos / dymos / examples / brachistochrone / doc / test_doc_brachistochrone_tandem_phases.py View on Github external
compressed=True):

    if transcription == 'gauss-lobatto':
        t = dm.GaussLobatto(num_segments=num_segments,
                            order=transcription_order,
                            compressed=compressed)
    elif transcription == 'radau-ps':
        t = dm.Radau(num_segments=num_segments,
                     order=transcription_order,
                     compressed=compressed)
    elif transcription == 'runge-kutta':
        t = dm.RungeKutta(num_segments=num_segments,
                          order=transcription_order,
                          compressed=compressed)

    phase = dm.Phase(ode_class=BrachistochroneODE, transcription=t)

    return phase
github OpenMDAO / dymos / dymos / examples / oscillator / doc / test_doc_oscillator.py View on Github external
import dymos as dm
        import matplotlib.pyplot as plt
        plt.switch_backend('Agg')  # disable plotting to the screen

        from oscillator_ode import OscillatorODE

        # Instantiate an OpenMDAO Problem instance.
        prob = om.Problem()

        # Instantiate a Dymos Trajectory and add it to the Problem model.
        traj = dm.Trajectory()
        prob.model.add_subsystem('traj', traj)

        # Instantiate a Phase and add it to the Trajectory.
        # Here the transcription is necessary but not particularly relevant.
        phase = dm.Phase(ode_class=OscillatorODE, transcription=dm.Radau(num_segments=4))
        traj.add_phase('phase0', phase)

        # Tell Dymos the states to be propagated using the given ODE.
        phase.add_state('x', rate_source='v', targets=['x'], units='m')
        phase.add_state('v', rate_source='v_dot', targets=['v'], units='m/s')

        # The spring constant, damping coefficient, and mass are inputs to the system that are constant throughout the phase.
        phase.add_input_parameter('k', units='N/m', targets=['k'])
        phase.add_input_parameter('c', units='N*s/m', targets=['c'])
        phase.add_input_parameter('m', units='kg', targets=['m'])

        # Setup the OpenMDAO problem
        prob.setup()

        # Assign values to the times and states
        prob.set_val('traj.phase0.t_initial', 0.0)
github OpenMDAO / dymos / dymos / examples / oscillator / doc / test_doc_oscillator.py View on Github external
plt.switch_backend('Agg')  # disable plotting to the screen

        from oscillator_ode import OscillatorODE

        # Instantiate an OpenMDAO Problem instance.
        prob = om.Problem()

        # We need an optimization driver.  To solve this simple problem ScipyOptimizerDriver will work.
        prob.driver = om.ScipyOptimizeDriver()

        # Instantiate a Dymos Trajectory and add it to the Problem model.
        traj = dm.Trajectory()
        prob.model.add_subsystem('traj', traj)

        # Instantiate a Phase and add it to the Trajectory.
        phase = dm.Phase(ode_class=OscillatorODE, transcription=dm.Radau(num_segments=10))
        traj.add_phase('phase0', phase)

        # Tell Dymos that the duration of the phase is bounded.
        phase.set_time_options(fix_initial=True, fix_duration=True)

        # Tell Dymos the states to be propagated using the given ODE.
        phase.add_state('x', fix_initial=True, rate_source='v', targets=['x'], units='m')
        phase.add_state('v', fix_initial=True, rate_source='v_dot', targets=['v'], units='m/s')

        # The spring constant, damping coefficient, and mass are inputs to the system that are constant throughout the phase.
        phase.add_input_parameter('k', units='N/m', targets=['k'])
        phase.add_input_parameter('c', units='N*s/m', targets=['c'])
        phase.add_input_parameter('m', units='kg', targets=['m'])

        # Since we're using an optimization driver, an objective is required.  We'll minimize the final time in this case.
        phase.add_objective('time', loc='final')
github OpenMDAO / dymos / dymos / examples / double_integrator / ex_double_integrator.py View on Github external
def double_integrator_direct_collocation(transcription='gauss-lobatto', compressed=True):
    p = Problem(model=Group())
    p.driver = pyOptSparseDriver()
    p.driver.options['dynamic_simul_derivs'] = True

    if transcription == 'gauss-lobatto':
        transcription = GaussLobatto(num_segments=30, order=3, compressed=compressed)
    elif transcription == "radau-ps":
        transcription = Radau(num_segments=30, order=3, compressed=compressed)

    phase = Phase(ode_class=DoubleIntegratorODE, transcription=transcription)
    p.model.add_subsystem('phase0', phase)

    phase.set_time_options(fix_initial=True, fix_duration=True)

    phase.set_state_options('x', fix_initial=True)
    phase.set_state_options('v', fix_initial=True, fix_final=True)

    phase.add_control('u', units='m/s**2', scaler=0.01, continuity=False, rate_continuity=False,
                      rate2_continuity=False, lower=-1.0, upper=1.0)

    # Maximize distance travelled in one second.
    phase.add_objective('x', loc='final', scaler=-1)

    p.model.linear_solver = DirectSolver()

    p.setup(check=True)
github OpenMDAO / dymos / dymos / examples / finite_burn_orbit_raise / ex_finite_burn_orbit_raise.py View on Github external
def make_traj(transcription='gauss-lobatto', transcription_order=3, compressed=True,
              connected=False):

    t = {'gauss-lobatto': GaussLobatto(num_segments=20, order=transcription_order, compressed=compressed),
         'radau': Radau(num_segments=20, order=transcription_order, compressed=compressed),
         'runge-kutta': RungeKutta(num_segments=20, compressed=compressed)}

    traj = Trajectory()

    traj.add_design_parameter('c', opt=False, val=1.5, units='DU/TU')

    # First Phase (burn)

    burn1 = Phase(ode_class=FiniteBurnODE, transcription=t[transcription])

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

    burn1.set_time_options(fix_initial=True, duration_bounds=(.5, 10))
    burn1.set_state_options('r', fix_initial=True, fix_final=False, defect_scaler=100.0)
    burn1.set_state_options('theta', fix_initial=True, fix_final=False, defect_scaler=100.0)
    burn1.set_state_options('vr', fix_initial=True, fix_final=False, defect_scaler=100.0)
    burn1.set_state_options('vt', fix_initial=True, fix_final=False, defect_scaler=100.0)
    burn1.set_state_options('accel', fix_initial=True, fix_final=False)
    burn1.set_state_options('deltav', fix_initial=True, fix_final=False)
    burn1.add_control('u1', rate_continuity=True, rate2_continuity=True, units='deg', scaler=0.01,
                      rate_continuity_scaler=0.001, rate2_continuity_scaler=0.001,
                      lower=-30, upper=30)
    # Second Phase (Coast)
    coast = Phase(ode_class=FiniteBurnODE, transcription=t[transcription])
github OpenMDAO / dymos / dymos / phase / phase.py View on Github external
atol : float
            Absolute convergence tolerance for the scipy.integrate.solve_ivp method.
        rtol : float
            Relative convergence tolerance for the scipy.integrate.solve_ivp method.

        Returns
        -------
        SimulationPhase
            An instance of SimulationPhase initialized based on data from this Phase and the given
            times.  This instance has not yet been setup.
        """
        from ..transcriptions import SolveIVP

        t = self.options['transcription']

        sim_phase = dm.Phase(from_phase=self,
                             transcription=SolveIVP(grid_data=t.grid_data,
                                                    method=method,
                                                    atol=atol,
                                                    rtol=rtol,
                                                    output_nodes_per_seg=times_per_seg))

        return sim_phase
github OpenMDAO / dymos / dymos / examples / ssto / ex_ssto_moon_linear_tangent.py View on Github external
if optimizer == 'SNOPT':
        p.driver = pyOptSparseDriver()
        p.driver.options['optimizer'] = optimizer
        p.driver.options['dynamic_simul_derivs'] = True
        p.driver.opt_settings['Major iterations limit'] = 100
        p.driver.opt_settings['iSumm'] = 6
        p.driver.opt_settings['Verify level'] = 3
    else:
        p.driver = ScipyOptimizeDriver()
        p.driver.options['dynamic_simul_derivs'] = True

    t = {'gauss-lobatto': GaussLobatto(num_segments=num_seg, order=transcription_order, compressed=compressed),
         'radau-ps': Radau(num_segments=num_seg, order=transcription_order, compressed=compressed)}

    phase = Phase(ode_class=LaunchVehicleLinearTangentODE,
                  ode_init_kwargs={'central_body': 'moon'},
                  transcription=t[transcription])

    p.model.add_subsystem('phase0', phase)

    phase.set_time_options(initial_bounds=(0, 0), duration_bounds=(10, 1000))

    phase.set_state_options('x', fix_initial=True, lower=0)
    phase.set_state_options('y', fix_initial=True, lower=0)
    phase.set_state_options('vx', fix_initial=True, lower=0)
    phase.set_state_options('vy', fix_initial=True)
    phase.set_state_options('m', fix_initial=True)

    phase.add_boundary_constraint('y', loc='final', equals=1.85E5, linear=True)
    phase.add_boundary_constraint('vx', loc='final', equals=1627.0)
    phase.add_boundary_constraint('vy', loc='final', equals=0)
github OpenMDAO / dymos / mkdocs / docs / getting_started / scripts / fitter_animation_1_seg.py View on Github external
ORDER = 5
NUM_FRAMES = 20
ORDER = 3

# Instantiate an OpenMDAO Problem instance.
prob = om.Problem()

# We need an optimization driver.  To solve this simple problem ScipyOptimizerDriver will work.
prob.driver = om.ScipyOptimizeDriver()

# Instantiate a Dymos Trajectory and add it to the Problem model.
traj = dm.Trajectory()
prob.model.add_subsystem('traj', traj)

# Instantiate a Phase and add it to the Trajectory.
phase = dm.Phase(ode_class=OscillatorODE, transcription=dm.Radau(num_segments=NUM_SEG, order=ORDER, compressed=False))
traj.add_phase('phase0', phase)

# Tell Dymos that the duration of the phase is bounded.
phase.set_time_options(fix_initial=True, fix_duration=True)

# Tell Dymos the states to be propagated using the given ODE.
phase.add_state('x', fix_initial=True, rate_source='v', targets=['x'], units='m')
phase.add_state('v', fix_initial=True, rate_source='v_dot', targets=['v'], units='m/s')

# The spring constant, damping coefficient, and mass are inputs to the system that are constant throughout the phase.
phase.add_input_parameter('k', units='N/m', targets=['k'])
phase.add_input_parameter('c', units='N*s/m', targets=['c'])
phase.add_input_parameter('m', units='kg', targets=['m'])

# secondary "dense" timeseries
phase.add_timeseries('timeseries2', transcription=dm.Radau(num_segments=NUM_SEG, order=41, compressed=False))