Skip to content

Commit

Permalink
updated grid refinement to utilize phase.load_case
Browse files Browse the repository at this point in the history
  • Loading branch information
robfalck committed Jul 25, 2023
1 parent 7b6e6bf commit c3b8579
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
12 changes: 7 additions & 5 deletions dymos/grid_refinement/refinement.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from .hp_adaptive.hp_adaptive import HPAdaptive
from .write_iteration import write_error, write_refine_iter

import openmdao.api as om
from dymos.grid_refinement.error_estimation import check_error
from dymos.load_case import load_case, find_phases

Expand Down Expand Up @@ -35,9 +36,10 @@ def _refine_iter(problem, refine_iteration_limit=0, refine_method='hp', case_pre
refinement_methods = {'hp': HPAdaptive, 'ph': PHAdaptive}
_case_prefix = '' if case_prefix is None else f'{case_prefix}_'

failed = problem.run_driver(case_prefix=f'{_case_prefix}{refine_method}_0_'
if refine_iteration_limit > 0 else _case_prefix,
case_prefix = f'{_case_prefix}{refine_method}_0_'
failed = problem.run_driver(case_prefix=case_prefix if refine_iteration_limit > 0 else _case_prefix,
reset_iter_counts=reset_iter_counts)
problem.cleanup()

if refine_iteration_limit > 0:
out_file = 'grid_refinement.out'
Expand Down Expand Up @@ -68,7 +70,6 @@ def _refine_iter(problem, refine_iteration_limit=0, refine_method='hp', case_pre
'outputs': problem.model.list_outputs(out_stream=None, units=True, prom_name=True)}

problem.setup()

load_case(problem, prev_soln, deprecation_warning=False)
else:
prev_soln = {
Expand All @@ -79,8 +80,9 @@ def _refine_iter(problem, refine_iteration_limit=0, refine_method='hp', case_pre
}

problem.setup()

problem.load_case(prev_soln)
for phase_path in refined_phases:
phs = problem.model._get_subsystem(phase_path)
phs.load_case(prev_soln)

failed = problem.run_driver(case_prefix=f'{_case_prefix}{refine_method}_{i}_')

Expand Down
2 changes: 1 addition & 1 deletion dymos/grid_refinement/test/test_grid_refinement.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_refine_hp_non_ode_rate_sources(self):
p.driver.declare_coloring()

traj = p.model.add_subsystem('traj', dm.Trajectory())
tx = transcription = dm.Radau(num_segments=5)
tx = dm.Radau(num_segments=5)
phase = traj.add_phase('phase0', dm.Phase(ode_class=_BrysonDenhamODE, transcription=tx))

#
Expand Down
2 changes: 0 additions & 2 deletions dymos/phase/phase.py
Original file line number Diff line number Diff line change
Expand Up @@ -2709,8 +2709,6 @@ def load_case(self, case):
prev_time_val, unique_idxs = np.unique(prev_time_val, return_index=True)
prev_time_units = prev_vars[prev_time_path]['units']

print("\n".join(prev_vars.keys()))

t_initial = prev_time_val[0]
t_duration = prev_time_val[-1] - prev_time_val[0]

Expand Down
1 change: 0 additions & 1 deletion dymos/test/test_load_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ def test_load_case_lgl_to_radau(self):
outputs = dict([(o[0], o[1]) for o in case.list_outputs(units=True, shape=True,
out_stream=None)])

print(outputs)
time_val = outputs['phase0.timeseries.timeseries_comp.time']['val']
theta_val = outputs['phase0.timeseries.timeseries_comp.theta']['val']

Expand Down

0 comments on commit c3b8579

Please sign in to comment.