Skip to content

Commit

Permalink
fixed load_case logic to correctly handle negative-duration phases (#…
Browse files Browse the repository at this point in the history
…1007)

* fixed load_case logic to correctly handle negative-duration phases

* applied fixed load_case logic to deprecated load_case function for older versions of OpenMDAO.
  • Loading branch information
robfalck authored Oct 17, 2023
1 parent 7fe8819 commit 45ab30c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
@use_tempdirs
class TestExampleTwoBurnOrbitRaiseConnectedRestart(unittest.TestCase):

@unittest.skip('Skipped due to a change in interpolation in scipy. Need to come up with better case loading.')
def test_ex_two_burn_orbit_raise_connected(self):
optimizer = 'IPOPT'

Expand Down Expand Up @@ -73,7 +72,6 @@ def test_restart_from_solution_radau(self):
@use_tempdirs
class TestExampleTwoBurnOrbitRaiseConnected(unittest.TestCase):

@unittest.skip('Skipped due to a change in interpolation in scipy. Need to come up with better case loading.')
def test_ex_two_burn_orbit_raise_connected(self):
optimizer = 'IPOPT'

Expand All @@ -100,7 +98,6 @@ def test_ex_two_burn_orbit_raise_connected(self):
assert_cases_equal(case1, p, tol=1.0E-8)
assert_cases_equal(sim_case1, sim_case2, tol=1.0E-8)

@unittest.skip('Skipped due to a change in interpolation in scipy. Need to come up with better case loading.')
def test_restart_from_solution_radau_to_connected(self):
optimizer = 'IPOPT'

Expand Down
8 changes: 6 additions & 2 deletions dymos/load_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,15 @@ def load_case(problem, previous_solution, deprecation_warning=True):
continue

prev_time_val = prev_vars[prev_time_path]['val']
t_initial = prev_time_val[0]
t_duration = prev_time_val[-1] - prev_time_val[0]
prev_time_val, unique_idxs = np.unique(prev_time_val, return_index=True)
prev_time_units = prev_vars[prev_time_path]['units']

t_initial = prev_time_val[0]
t_duration = prev_time_val[-1] - prev_time_val[0]
if t_duration < 0:
# Unique sorts the data. In reverse-time phases, we need to undo it.
prev_time_val = np.flip(prev_time_val, axis=0)
unique_idxs = np.flip(unique_idxs, axis=0)

ti_path = [s for s in phase_vars.keys() if s.endswith(f'{phase_name}.t_initial')]
if ti_path:
Expand Down
10 changes: 7 additions & 3 deletions dymos/phase/phase.py
Original file line number Diff line number Diff line change
Expand Up @@ -2733,13 +2733,17 @@ def load_case(self, case):

prev_timeseries_prom_path, _, _ = prev_time_path.rpartition(f'.{integration_name}')
prev_phase_prom_path, _, _ = prev_timeseries_prom_path.rpartition('.timeseries')

prev_time_val = prev_vars[prev_time_path]['val']
prev_time_val, unique_idxs = np.unique(prev_time_val, return_index=True)
prev_time_units = prev_vars[prev_time_path]['units']

t_initial = prev_time_val[0]
t_duration = prev_time_val[-1] - prev_time_val[0]
prev_time_val, unique_idxs = np.unique(prev_time_val, return_index=True)
prev_time_units = prev_vars[prev_time_path]['units']

if t_duration < 0:
# Unique sorts the data. In reverse-time phases, we need to undo it.
prev_time_val = np.flip(prev_time_val, axis=0)
unique_idxs = np.flip(unique_idxs, axis=0)

self.set_val('t_initial', t_initial, units=prev_time_units)
self.set_val('t_duration', t_duration, units=prev_time_units)
Expand Down

0 comments on commit 45ab30c

Please sign in to comment.