Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed the deprecated RungeKutta Transcription #550

Merged
merged 6 commits into from
Feb 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions benchmark/benchmark_brachistochrone.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ def brachistochrone_min_time(transcription='gauss-lobatto', num_segments=8, tran
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)

Expand Down Expand Up @@ -139,11 +135,3 @@ def benchmark_gl_30_3_color_simul_uncompressed_snopt(self):
transcription_order=3,
compressed=False)
self.run_asserts(p)

def benchmark_gl_30_3_color_simul_compressed_rk4(self):
p = brachistochrone_min_time(transcription='runge-kutta',
optimizer='SNOPT',
num_segments=30,
transcription_order=3,
compressed=True)
self.run_asserts(p)
2 changes: 1 addition & 1 deletion dymos/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
__version__ = '1.0.0-dev'

from .phase import Phase
from .transcriptions import GaussLobatto, Radau, RungeKutta
from .transcriptions import GaussLobatto, Radau
from .trajectory.trajectory import Trajectory
from .run_problem import run_problem
from .load_case import load_case
Expand Down
228 changes: 0 additions & 228 deletions dymos/examples/battery_multibranch/test/test_multibranch_trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,233 +375,5 @@ def test_optimizer_segments_direct_connections(self):
assert_near_equal(soc1m[-1], 0.18625395, 1e-6)


@use_tempdirs
class TestBatteryBranchingPhasesRungeKutta(unittest.TestCase):

def test_constraint_linkages_rk(self):
prob = om.Problem()

if optimizer == 'SNOPT':
opt = prob.driver = om.pyOptSparseDriver()
opt.options['optimizer'] = optimizer
opt.declare_coloring()

opt.opt_settings['Major iterations limit'] = 1000
opt.opt_settings['Major feasibility tolerance'] = 1.0E-6
opt.opt_settings['Major optimality tolerance'] = 1.0E-6
opt.opt_settings["Linesearch tolerance"] = 0.10
opt.opt_settings['iSumm'] = 6

else:
opt = prob.driver = om.ScipyOptimizeDriver()
opt.declare_coloring()

num_seg = 20
seg_ends, _ = lgl(num_seg + 1)

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

# First phase: normal operation.
transcription = dm.RungeKutta(num_segments=num_seg)
phase0 = dm.Phase(ode_class=BatteryODE, transcription=transcription)
traj_p0 = traj.add_phase('phase0', phase0)

traj_p0.set_time_options(fix_initial=True, fix_duration=True)
traj_p0.add_state('state_of_charge', fix_initial=True, fix_final=False,
targets=['SOC'], rate_source='dXdt:SOC')

# Second phase: normal operation.

phase1 = dm.Phase(ode_class=BatteryODE, transcription=transcription)
traj_p1 = traj.add_phase('phase1', phase1)

traj_p1.set_time_options(fix_initial=False, fix_duration=True)
traj_p1.add_state('state_of_charge', fix_initial=False, fix_final=False,
targets=['SOC'], rate_source='dXdt:SOC')
traj_p1.add_objective('time', loc='final')

# Second phase, but with battery failure.

phase1_bfail = dm.Phase(ode_class=BatteryODE, ode_init_kwargs={'num_battery': 2},
transcription=transcription)
traj_p1_bfail = traj.add_phase('phase1_bfail', phase1_bfail)

traj_p1_bfail.set_time_options(fix_initial=False, fix_duration=True)
traj_p1_bfail.add_state('state_of_charge', fix_initial=False, fix_final=False,
targets=['SOC'], rate_source='dXdt:SOC')

# Second phase, but with motor failure.

phase1_mfail = dm.Phase(ode_class=BatteryODE, ode_init_kwargs={'num_motor': 2},
transcription=transcription)
traj_p1_mfail = traj.add_phase('phase1_mfail', phase1_mfail)

traj_p1_mfail.set_time_options(fix_initial=False, fix_duration=True)
traj_p1_mfail.add_state('state_of_charge', fix_initial=False, fix_final=False,
targets=['SOC'], rate_source='dXdt:SOC')

traj.link_phases(phases=['phase0', 'phase1'], vars=['state_of_charge', 'time'])
traj.link_phases(phases=['phase0', 'phase1_bfail'], vars=['state_of_charge', 'time'])
traj.link_phases(phases=['phase0', 'phase1_mfail'], vars=['state_of_charge', 'time'])

prob.model.options['assembled_jac_type'] = 'csc'
prob.model.linear_solver = om.DirectSolver(assemble_jac=True)

prob.setup()

prob['traj.phase0.t_initial'] = 0
prob['traj.phase0.t_duration'] = 1.0*3600

prob['traj.phase1.t_initial'] = 1.0*3600
prob['traj.phase1.t_duration'] = 1.0*3600

prob['traj.phase1_bfail.t_initial'] = 1.0*3600
prob['traj.phase1_bfail.t_duration'] = 1.0*3600

prob['traj.phase1_mfail.t_initial'] = 1.0*3600
prob['traj.phase1_mfail.t_duration'] = 1.0*3600

prob.set_solver_print(level=0)
dm.run_problem(prob)

soc0 = prob['traj.phase0.states:state_of_charge']
soc1 = prob['traj.phase1.states:state_of_charge']
soc1b = prob['traj.phase1_bfail.states:state_of_charge']
soc1m = prob['traj.phase1_mfail.states:state_of_charge']

# Final value for State of Charge in each segment should be a good test.
assert_near_equal(soc0[-1], 0.63464982, 1e-4)
assert_near_equal(soc1[-1], 0.23794217, 1e-4)
assert_near_equal(soc1b[-1], 0.0281523, 1e-4)
assert_near_equal(soc1m[-1], 0.18625395, 1e-4)

def test_single_phase_reverse_propagation_rk(self):
prob = om.Problem()

num_seg = 10
seg_ends, _ = lgl(num_seg + 1)

# First phase: normal operation.
transcription = dm.RungeKutta(num_segments=num_seg)
phase0 = dm.Phase(ode_class=BatteryODE, transcription=transcription)
traj_p0 = prob.model.add_subsystem('phase0', phase0)

traj_p0.set_time_options(fix_initial=True, fix_duration=True)
traj_p0.add_state('state_of_charge', fix_initial=True, fix_final=False,
targets=['SOC'], rate_source='dXdt:SOC')

prob.setup()

prob['phase0.t_initial'] = 0
prob['phase0.t_duration'] = -1.0*3600
prob['phase0.states:state_of_charge'][:] = 0.63464982

prob.set_solver_print(level=0)
prob.run_model()

soc0 = prob['phase0.states:state_of_charge']
assert_near_equal(soc0[-1], 1.0, 1e-6)

def test_connected_linkages_rk(self):
prob = om.Problem()

if optimizer == 'SNOPT':
opt = prob.driver = om.pyOptSparseDriver()
opt.options['optimizer'] = optimizer
opt.declare_coloring()

opt.opt_settings['Major iterations limit'] = 1000
opt.opt_settings['Major feasibility tolerance'] = 1.0E-6
opt.opt_settings['Major optimality tolerance'] = 1.0E-6
opt.opt_settings["Linesearch tolerance"] = 0.10
opt.opt_settings['iSumm'] = 6

else:
opt = prob.driver = om.ScipyOptimizeDriver()
opt.declare_coloring()

num_seg = 20
seg_ends, _ = lgl(num_seg + 1)

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

# First phase: normal operation.

transcription = dm.RungeKutta(num_segments=num_seg)
phase0 = dm.Phase(ode_class=BatteryODE, transcription=transcription)
traj_p0 = traj.add_phase('phase0', phase0)

traj_p0.set_time_options(fix_initial=True, fix_duration=True)
traj_p0.add_state('state_of_charge', fix_initial=True, fix_final=False,
targets=['SOC'], rate_source='dXdt:SOC')

# Second phase: normal operation.

phase1 = dm.Phase(ode_class=BatteryODE, transcription=transcription)
traj_p1 = traj.add_phase('phase1', phase1)

traj_p1.set_time_options(fix_initial=False, fix_duration=True)
traj_p1.add_state('state_of_charge', fix_initial=False, fix_final=False,
targets=['SOC'], rate_source='dXdt:SOC')
traj_p1.add_objective('time', loc='final')

# Second phase, but with battery failure.

phase1_bfail = dm.Phase(ode_class=BatteryODE, ode_init_kwargs={'num_battery': 2},
transcription=transcription)
traj_p1_bfail = traj.add_phase('phase1_bfail', phase1_bfail)

traj_p1_bfail.set_time_options(fix_initial=False, fix_duration=True)
traj_p1_bfail.add_state('state_of_charge', fix_initial=False, fix_final=False,
targets=['SOC'], rate_source='dXdt:SOC')

# Second phase, but with motor failure.
phase1_mfail = dm.Phase(ode_class=BatteryODE, ode_init_kwargs={'num_motor': 2},
transcription=transcription)
traj_p1_mfail = traj.add_phase('phase1_mfail', phase1_mfail)

traj_p1_mfail.set_time_options(fix_initial=False, fix_duration=True)
traj_p1_mfail.add_state('state_of_charge', fix_initial=False, fix_final=False,
targets=['SOC'], rate_source='dXdt:SOC')

traj.link_phases(phases=['phase0', 'phase1'], vars=['state_of_charge', 'time'],
connected=True)
traj.link_phases(phases=['phase0', 'phase1_bfail'], vars=['state_of_charge', 'time'],
connected=True)
traj.link_phases(phases=['phase0', 'phase1_mfail'], vars=['state_of_charge', 'time'],
connected=True)

prob.model.options['assembled_jac_type'] = 'csc'
prob.model.linear_solver = om.DirectSolver(assemble_jac=True)

prob.setup()

prob['traj.phase0.t_initial'] = 0
prob['traj.phase0.t_duration'] = 1.0*3600

prob['traj.phase1.t_initial'] = 1.0*3600
prob['traj.phase1.t_duration'] = 1.0*3600

prob['traj.phase1_bfail.t_initial'] = 1.0*3600
prob['traj.phase1_bfail.t_duration'] = 1.0*3600

prob['traj.phase1_mfail.t_initial'] = 1.0*3600
prob['traj.phase1_mfail.t_duration'] = 1.0*3600

prob.set_solver_print(level=0)
dm.run_problem(prob)

soc0 = prob['traj.phase0.states:state_of_charge']
soc1 = prob['traj.phase1.states:state_of_charge']
soc1b = prob['traj.phase1_bfail.states:state_of_charge']
soc1m = prob['traj.phase1_mfail.states:state_of_charge']

# Final value for State of Chrage in each segment should be a good test.
assert_near_equal(soc0[-1], 0.63464982, 5e-5)
assert_near_equal(soc1[-1], 0.23794217, 5e-5)
assert_near_equal(soc1b[-1], 0.0281523, 5e-5)
assert_near_equal(soc1m[-1], 0.18625395, 5e-5)


if __name__ == '__main__': # pragma: no cover
unittest.main()
Loading