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

fixed load_case logic to correctly handle negative-duration phases #1007

Merged
merged 2 commits into from
Oct 17, 2023
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
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