Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
phase0.add_state('x', rate_source=BrachistochroneODE.states['x']['rate_source'],
units=BrachistochroneODE.states['x']['units'],
fix_initial=True, fix_final=False, solve_segments=False)
phase0.add_state('y', rate_source=BrachistochroneODE.states['y']['rate_source'],
units=BrachistochroneODE.states['y']['units'],
fix_initial=True, fix_final=False, solve_segments=False)
phase0.add_state('v', rate_source=BrachistochroneODE.states['v']['rate_source'],
targets=BrachistochroneODE.states['v']['targets'],
units=BrachistochroneODE.states['v']['units'],
fix_initial=True, fix_final=False, solve_segments=False)
phase0.add_control('theta', continuity=True, rate_continuity=True,
targets=BrachistochroneODE.parameters['theta']['targets'],
units='deg', lower=0.01, upper=179.9)
phase0.add_input_parameter('g', targets=BrachistochroneODE.parameters['g']['targets'],
units='m/s**2', val=9.80665)
phase0.add_boundary_constraint('x', loc='final', equals=10)
phase0.add_boundary_constraint('y', loc='final', equals=5)
# Add alternative timeseries output to provide control inputs for the next phase
phase0.add_timeseries('timeseries2', transcription=tx1, subset='control_input')
#
# Second Phase: Integration of ArcLength
#
phase1 = dm.Phase(ode_class=BrachistochroneArclengthODE, transcription=tx1)
#
# First Phase: Standard Brachistochrone
#
num_segments = 10
transcription_order = 3
compressed = False
tx0 = dm.GaussLobatto(num_segments=num_segments,
order=transcription_order,
compressed=compressed)
tx1 = dm.Radau(num_segments=num_segments*2,
order=transcription_order*3,
compressed=compressed)
phase0 = dm.Phase(ode_class=BrachistochroneODE, transcription=tx0)
p.model.add_subsystem('phase0', phase0)
phase0.set_time_options(fix_initial=True, duration_bounds=(.5, 10))
phase0.add_state('x', rate_source=BrachistochroneODE.states['x']['rate_source'],
units=BrachistochroneODE.states['x']['units'],
fix_initial=True, fix_final=False, solve_segments=False)
phase0.add_state('y', rate_source=BrachistochroneODE.states['y']['rate_source'],
units=BrachistochroneODE.states['y']['units'],
fix_initial=True, fix_final=False, solve_segments=False)
phase0.add_state('v', rate_source=BrachistochroneODE.states['v']['rate_source'],
targets=BrachistochroneODE.states['v']['targets'],
units=BrachistochroneODE.states['v']['units'],
def test_partials(self, glm_formulation, glm_integrator):
p = Problem(model=Group())
phase = Phase('glm',
ode_class=BrachistochroneODE,
num_segments=2,
formulation=glm_formulation,
method_name=glm_integrator,
compressed=False)
p.model.add_subsystem('phase0', phase)
phase.add_control('theta', units='deg', dynamic=True,
rate_continuity=None, lower=0.01, upper=179.9)
p.setup(force_alloc_complex=True)
p.final_setup()
p['phase0.t_initial'] = 0.0
p['phase0.t_duration'] = 2.0
phase.set_values('x', [0, 10])
phase.set_values('y', [10, 5])
phase0 = dm.Phase(ode_class=BrachistochroneODE, transcription=tx0)
p.model.add_subsystem('phase0', phase0)
phase0.set_time_options(fix_initial=True, duration_bounds=(.5, 10))
phase0.add_state('x', rate_source=BrachistochroneODE.states['x']['rate_source'],
units=BrachistochroneODE.states['x']['units'],
fix_initial=True, fix_final=False, solve_segments=False)
phase0.add_state('y', rate_source=BrachistochroneODE.states['y']['rate_source'],
units=BrachistochroneODE.states['y']['units'],
fix_initial=True, fix_final=False, solve_segments=False)
phase0.add_state('v', rate_source=BrachistochroneODE.states['v']['rate_source'],
targets=BrachistochroneODE.states['v']['targets'],
units=BrachistochroneODE.states['v']['units'],
fix_initial=True, fix_final=False, solve_segments=False)
phase0.add_control('theta', continuity=True, rate_continuity=True,
targets=BrachistochroneODE.parameters['theta']['targets'],
units='deg', lower=0.01, upper=179.9)
phase0.add_input_parameter('g', targets=BrachistochroneODE.parameters['g']['targets'],
units='m/s**2', val=9.80665)
phase0.add_boundary_constraint('x', loc='final', equals=10)
phase0.add_boundary_constraint('y', loc='final', equals=5)
# Add alternative timeseries output to provide control inputs for the next phase
phase0.add_timeseries('timeseries2', transcription=tx1, subset='control_input')
p.driver.options['dynamic_simul_derivs'] = True
if transcription == 'gauss-lobatto':
t = GaussLobatto(num_segments=num_segments,
order=transcription_order,
compressed=compressed)
elif transcription == 'radau-ps':
t = Radau(num_segments=num_segments,
order=transcription_order,
compressed=compressed)
elif transcription == 'runge-kutta':
t = RungeKutta(num_segments=num_segments,
order=transcription_order,
compressed=compressed)
phase = Phase(ode_class=BrachistochroneODE, transcription=t)
p.model.add_subsystem('phase0', phase)
phase.set_time_options(fix_initial=True, duration_bounds=(.5, 10))
phase.set_state_options('x', fix_initial=True, fix_final=False, solve_segments=False)
phase.set_state_options('y', fix_initial=True, fix_final=False, solve_segments=False)
phase.set_state_options('v', fix_initial=True, fix_final=False, solve_segments=False)
phase.add_control('theta', continuity=True, rate_continuity=True,
units='deg', lower=0.01, upper=179.9)
phase.add_input_parameter('g', units='m/s**2', val=9.80665)
phase.add_boundary_constraint('x', loc='final', equals=10)
phase.add_boundary_constraint('y', loc='final', equals=5)
p.driver.options['optimizer'] = OPTIMIZER
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()
transcription = 'glm'
formulation = 'optimizer-based'
formulation = 'solver-based'
formulation = 'time-marching'
method_name = 'GaussLegendre6'
method_name = 'ImplicitMidpoint'
method_name = 'Lobatto4'
phase = Phase(transcription,
ode_class=BrachistochroneODE,
num_segments=10,
formulation=formulation,
method_name=method_name)
p.model.add_subsystem('phase0', phase)
phase.set_time_options(initial_bounds=(0, 0), duration_bounds=(.5, 10))
if 0:
phase.set_state_options('x', fix_initial=True, fix_final=True)
phase.set_state_options('y', fix_initial=True, fix_final=True)
phase.set_state_options('v', fix_initial=True)
else:
phase.add_boundary_constraint('x', loc='initial', equals=0.)
phase.add_boundary_constraint('x', loc='final', equals=10.)
phase.add_boundary_constraint('y', loc='initial', equals=10.)
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import openmdao.api as om
import dymos as dm
from dymos.examples.brachistochrone.brachistochrone_ode import BrachistochroneODE
p = om.Problem(model=om.Group())
phase = dm.Phase(ode_class=BrachistochroneODE,
transcription=dm.Radau(num_segments=4, order=[3, 5, 3, 5]))
p.model.add_subsystem('phase0', phase)
p.setup()
p['phase0.t_initial'] = 1.0
p['phase0.t_duration'] = 9.0
p.run_model()
grid_data = phase.options['transcription'].grid_data
t_all = p.get_val('phase0.timeseries.time')
t_disc = t_all[grid_data.subset_node_indices['state_disc'], 0]
t_col = t_all[grid_data.subset_node_indices['col'], 0]
def f(x): # pragma: no cover
p = Problem(model=Group())
if optimizer == 'SNOPT':
p.driver = pyOptSparseDriver()
p.driver.options['optimizer'] = optimizer
p.driver.opt_settings['Major iterations limit'] = 100
p.driver.opt_settings['Major feasibility tolerance'] = 1.0E-6
p.driver.opt_settings['Major optimality tolerance'] = 1.0E-6
p.driver.opt_settings['iSumm'] = 6
else:
p.driver = ScipyOptimizeDriver()
p.driver.options['dynamic_simul_derivs'] = dynamic_simul_derivs
phase = Phase(transcription,
ode_class=BrachistochroneODE,
num_segments=num_segments,
transcription_order=transcription_order,
compressed=compressed)
p.model.add_subsystem('phase0', phase)
phase.set_time_options(fix_initial=True, fix_duration=True)
phase.set_state_options('x', fix_initial=True, fix_final=False)
phase.set_state_options('y', fix_initial=True, fix_final=False)
phase.set_state_options('v', fix_initial=True, fix_final=False)
phase.add_control('theta', opt=False, units='deg')
phase.add_design_parameter('g', units='m/s**2', opt=False, val=9.80665)
# phase.add_design_parameter('theta', units='deg', opt=False, val=45)
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import openmdao.api as om
import dymos as dm
from dymos.examples.brachistochrone.brachistochrone_ode import BrachistochroneODE
p = om.Problem(model=om.Group())
phase = dm.Phase(ode_class=BrachistochroneODE,
transcription=dm.GaussLobatto(num_segments=4, order=[3, 5, 3, 5]))
p.model.add_subsystem('phase0', phase)
p.setup()
p['phase0.t_initial'] = 1.0
p['phase0.t_duration'] = 9.0
p.run_model()
grid_data = phase.options['transcription'].grid_data
t_all = p.get_val('phase0.timeseries.time')
t_disc = t_all[grid_data.subset_node_indices['state_disc'], 0]
t_col = t_all[grid_data.subset_node_indices['col'], 0]
def f(x): # pragma: no cover