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

Timeseries report bounds #958

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
133f106
Timeseries inputs and outputs are now tagged with dymos variable type…
robfalck Jul 26, 2023
00efc2f
reverted addition of constraint type to timeseries tags
robfalck Jul 26, 2023
3378689
added dashed lines representing bounds and circle_crosses representin…
robfalck Jul 26, 2023
14a28af
cleanup 1
robfalck Jul 26, 2023
8480d65
tests for some control rate issues
robfalck Jul 26, 2023
9453a74
Merge branch 'master' of https://github.com/OpenMDAO/dymos into times…
robfalck Aug 7, 2023
cca2e04
add_timeseries_output now updates tags of the given output name, if
robfalck Aug 7, 2023
8c2d0e6
pep8
robfalck Aug 7, 2023
6e953d8
more test cleanup
robfalck Aug 7, 2023
12acb99
Merge branch 'master' of https://github.com/OpenMDAO/dymos into times…
robfalck Aug 7, 2023
c03adf5
fix for logic on when to include control rates in the timeseries outp…
robfalck Aug 8, 2023
690b5a7
pep8
robfalck Aug 8, 2023
c64fcc7
Added ability to toggle bounds to timeseries report
robfalck Aug 8, 2023
36117c8
reimplement use_tempdirs
robfalck Aug 8, 2023
c077ba8
vanderpol problem reset
robfalck Aug 8, 2023
52b36a7
cleanup
robfalck Aug 8, 2023
50ed0ba
doc cleanup
robfalck Aug 8, 2023
a37c8be
Fixed issues with timeseries plots when the name of time in a phase i…
robfalck Aug 9, 2023
dacfad5
Merge branch 'master' of https://github.com/OpenMDAO/dymos into times…
robfalck Aug 9, 2023
e16fd24
Cleaned up representation of bound and path constraints, still need b…
robfalck Aug 9, 2023
1fc0103
Added path constraints and some cleanup
robfalck Aug 9, 2023
60a3912
Fix for older versions of OpenMDAO.
robfalck Aug 10, 2023
04086c5
more fixes for compatibility with older openmdao versions.
robfalck Aug 10, 2023
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 @@ -305,6 +305,8 @@
"phase = dm.Phase(ode_class=LaunchVehicleLinearTangentODE,\n",
" transcription=dm.GaussLobatto(num_segments=10, order=5, compressed=True))\n",
"\n",
"phase.timeseries_options['include_t_phase'] = True\n",
"\n",
"traj.add_phase('phase0', phase)\n",
"\n",
"phase.set_time_options(fix_initial=True, duration_bounds=(10, 1000),\n",
Expand Down Expand Up @@ -482,7 +484,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
"version": "3.11.4"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

import openmdao.api as om
from openmdao.utils.testing_utils import use_tempdirs
from openmdao.utils.assert_utils import assert_near_equal

import dymos as dm
from dymos.utils.testing_utils import assert_timeseries_near_equal


class BrachistochroneRateTargetODE(om.ExplicitComponent):
Expand Down Expand Up @@ -126,6 +130,7 @@ def test_brachistochrone_control_rate_targets_gauss_lobatto(self):

p.model.add_subsystem('phase0', phase)

phase.timeseries_options['include_control_rates'] = True
phase.set_time_options(fix_initial=True, duration_bounds=(.5, 10))

phase.add_state('x', rate_source='xdot',
Expand Down Expand Up @@ -285,9 +290,9 @@ def test_brachistochrone_control_rate_targets_radau(self):
fig, ax = plt.subplots()

t_imp = p.get_val('phase0.timeseries.time')
theta_imp = p.get_val('phase0.timeseries.theta_rate')
theta_imp = p.get_val('phase0.control_rates:theta_rate')
t_exp = exp_out.get_val('phase0.timeseries.time')
theta_exp = exp_out.get_val('phase0.timeseries.theta_rate')
theta_exp = exp_out.get_val('phase0.control_rates:theta_rate')

ax.plot(t_imp, theta_imp, 'ro', label='solution')
ax.plot(t_exp, theta_exp, 'b-', label='simulated')
Expand All @@ -304,12 +309,6 @@ def test_brachistochrone_control_rate_targets_radau(self):
class TestBrachistochroneExplicitControlRateTargets(unittest.TestCase):

def test_brachistochrone_control_rate_targets_gauss_lobatto(self):
import matplotlib.pyplot as plt
plt.switch_backend('Agg')
import openmdao.api as om
from openmdao.utils.assert_utils import assert_near_equal
import dymos as dm

p = om.Problem(model=om.Group())
p.driver = om.ScipyOptimizeDriver()
p.driver.declare_coloring()
Expand Down Expand Up @@ -362,44 +361,25 @@ def test_brachistochrone_control_rate_targets_gauss_lobatto(self):
# Generate the explicitly simulated trajectory
exp_out = phase.simulate()

fig, ax = plt.subplots()
fig.suptitle('Brachistochrone Solution')
x_imp = p.get_val('phase0.timeseries.time')
y_imp = p.get_val('phase0.control_rates:theta_rate2')

x_imp = p.get_val('phase0.timeseries.x')
y_imp = p.get_val('phase0.timeseries.y')
x_exp = exp_out.get_val('phase0.timeseries.time')
y_exp = exp_out.get_val('phase0.control_rates:theta_rate2')

x_exp = exp_out.get_val('phase0.timeseries.x')
y_exp = exp_out.get_val('phase0.timeseries.y')
igd = phase.options['transcription'].grid_data
egd = exp_out.model._get_subsystem('phase0').options['transcription'].options['output_grid']

ax.plot(x_imp, y_imp, 'ro', label='solution')
ax.plot(x_exp, y_exp, 'b-', label='simulated')

ax.set_xlabel('x (m)')
ax.set_ylabel('y (m)')
ax.grid(True)
ax.legend(loc='upper right')

fig, ax = plt.subplots()

t_imp = p.get_val('phase0.timeseries.time')
theta_imp = p.get_val('phase0.timeseries.theta_rate')
t_exp = exp_out.get_val('phase0.timeseries.time')
theta_exp = exp_out.get_val('phase0.timeseries.theta_rate')

ax.plot(t_imp, theta_imp, 'ro', label='solution')
ax.plot(t_exp, theta_exp, 'b-', label='simulated')

ax.set_xlabel('time (s)')
ax.set_ylabel(r'$\theta$ (deg)')
ax.grid(True)
ax.legend(loc='upper right')

plt.show()
for row in range(igd.num_segments):
istart, iend = igd.segment_indices[row, :]
estart, eend = egd.segment_indices[row, :]
assert_timeseries_near_equal(t_ref=x_imp[istart:iend, :],
x_ref=y_imp[istart:iend, :],
t_check=x_exp[estart:eend, :],
x_check=y_exp[estart:eend, :],
rel_tolerance=1.0E-9)

def test_brachistochrone_control_rate_targets_radau(self):
import matplotlib.pyplot as plt
plt.switch_backend('Agg')
import matplotlib.pyplot as plt
import openmdao.api as om
from openmdao.utils.assert_utils import assert_near_equal
import dymos as dm
Expand All @@ -411,6 +391,7 @@ def test_brachistochrone_control_rate_targets_radau(self):
phase = dm.Phase(ode_class=BrachistochroneRateTargetODE,
transcription=dm.Radau(num_segments=10))

phase.timeseries_options['include_control_rates'] = True
p.model.add_subsystem('phase0', phase)

phase.set_time_options(fix_initial=True, duration_bounds=(.5, 10))
Expand Down Expand Up @@ -456,39 +437,23 @@ def test_brachistochrone_control_rate_targets_radau(self):
# Generate the explicitly simulated trajectory
exp_out = phase.simulate()

fig, ax = plt.subplots()
fig.suptitle('Brachistochrone Solution')
x_imp = p.get_val('phase0.timeseries.time')
y_imp = p.get_val('phase0.control_rates:theta_rate2')

x_imp = p.get_val('phase0.timeseries.x')
y_imp = p.get_val('phase0.timeseries.y')
x_exp = exp_out.get_val('phase0.timeseries.time')
y_exp = exp_out.get_val('phase0.control_rates:theta_rate2')

x_exp = exp_out.get_val('phase0.timeseries.x')
y_exp = exp_out.get_val('phase0.timeseries.y')
igd = phase.options['transcription'].grid_data
egd = exp_out.model._get_subsystem('phase0').options['transcription'].options['output_grid']

ax.plot(x_imp, y_imp, 'ro', label='solution')
ax.plot(x_exp, y_exp, 'b-', label='simulated')

ax.set_xlabel('x (m)')
ax.set_ylabel('y (m)')
ax.grid(True)
ax.legend(loc='upper right')

fig, ax = plt.subplots()

t_imp = p.get_val('phase0.timeseries.time')
theta_imp = p.get_val('phase0.timeseries.theta_rate')
t_exp = exp_out.get_val('phase0.timeseries.time')
theta_exp = exp_out.get_val('phase0.timeseries.theta_rate')

ax.plot(t_imp, theta_imp, 'ro', label='solution')
ax.plot(t_exp, theta_exp, 'b-', label='simulated')

ax.set_xlabel('time (s)')
ax.set_ylabel(r'$\theta$ (deg)')
ax.grid(True)
ax.legend(loc='upper right')

plt.show()
for row in range(igd.num_segments):
istart, iend = igd.segment_indices[row, :]
estart, eend = egd.segment_indices[row, :]
assert_timeseries_near_equal(t_ref=x_imp[istart:iend, :],
x_ref=y_imp[istart:iend, :],
t_check=x_exp[estart:eend, :],
x_check=y_exp[estart:eend, :],
rel_tolerance=1.0E-9)


@use_tempdirs
Expand Down Expand Up @@ -573,9 +538,9 @@ def test_brachistochrone_polynomial_control_rate_targets_gauss_lobatto(self):
fig, ax = plt.subplots()

t_imp = p.get_val('phase0.timeseries.time')
theta_imp = p.get_val('phase0.timeseries.theta_rate')
theta_imp = p.get_val('phase0.polynomial_control_rates:theta_rate')
t_exp = exp_out.get_val('phase0.timeseries.time')
theta_exp = exp_out.get_val('phase0.timeseries.theta_rate')
theta_exp = exp_out.get_val('phase0.polynomial_control_rates:theta_rate')

ax.plot(t_imp, theta_imp, 'ro', label='solution')
ax.plot(t_exp, theta_exp, 'b-', label='simulated')
Expand Down Expand Up @@ -667,9 +632,9 @@ def test_brachistochrone_polynomial_control_rate_targets_radau(self):
fig, ax = plt.subplots()

t_imp = p.get_val('phase0.timeseries.time')
theta_imp = p.get_val('phase0.timeseries.theta_rate')
theta_imp = p.get_val('phase0.polynomial_control_rates:theta_rate')
t_exp = exp_out.get_val('phase0.timeseries.time')
theta_exp = exp_out.get_val('phase0.timeseries.theta_rate')
theta_exp = exp_out.get_val('phase0.polynomial_control_rates:theta_rate')

ax.plot(t_imp, theta_imp, 'ro', label='solution')
ax.plot(t_exp, theta_exp, 'b-', label='simulated')
Expand All @@ -686,12 +651,6 @@ def test_brachistochrone_polynomial_control_rate_targets_radau(self):
class TestBrachistochronePolynomialControlExplicitRateTargets(unittest.TestCase):

def test_brachistochrone_polynomial_control_rate_targets_gauss_lobatto(self):
import matplotlib.pyplot as plt
plt.switch_backend('Agg')
import openmdao.api as om
from openmdao.utils.assert_utils import assert_near_equal
import dymos as dm

p = om.Problem(model=om.Group())
p.driver = om.ScipyOptimizeDriver()
p.driver.declare_coloring()
Expand Down Expand Up @@ -741,51 +700,7 @@ def test_brachistochrone_polynomial_control_rate_targets_gauss_lobatto(self):
# Test the results
assert_near_equal(p.get_val('phase0.timeseries.time')[-1], 1.8016, tolerance=1.0E-3)

# Generate the explicitly simulated trajectory
exp_out = phase.simulate()

fig, ax = plt.subplots()
fig.suptitle('Brachistochrone Solution')

x_imp = p.get_val('phase0.timeseries.x')
y_imp = p.get_val('phase0.timeseries.y')

x_exp = exp_out.get_val('phase0.timeseries.x')
y_exp = exp_out.get_val('phase0.timeseries.y')

ax.plot(x_imp, y_imp, 'ro', label='solution')
ax.plot(x_exp, y_exp, 'b-', label='simulated')

ax.set_xlabel('x (m)')
ax.set_ylabel('y (m)')
ax.grid(True)
ax.legend(loc='upper right')

fig, ax = plt.subplots()

t_imp = p.get_val('phase0.timeseries.time')
theta_imp = p.get_val('phase0.timeseries.theta_rate')
t_exp = exp_out.get_val('phase0.timeseries.time')
theta_exp = exp_out.get_val('phase0.timeseries.theta_rate')

ax.plot(t_imp, theta_imp, 'ro', label='solution')
ax.plot(t_exp, theta_exp, 'b-', label='simulated')

ax.set_xlabel('time (s)')
ax.set_ylabel(r'$\theta$ (deg)')
ax.grid(True)
ax.legend(loc='upper right')

plt.show()

def test_brachistochrone_polynomial_control_rate_targets_radau(self):
import matplotlib.pyplot as plt
plt.switch_backend('Agg')
import matplotlib.pyplot as plt
import openmdao.api as om
from openmdao.utils.assert_utils import assert_near_equal
import dymos as dm

p = om.Problem(model=om.Group())
p.driver = om.ScipyOptimizeDriver()
p.driver.declare_coloring()
Expand Down Expand Up @@ -835,43 +750,6 @@ def test_brachistochrone_polynomial_control_rate_targets_radau(self):
# Test the results
assert_near_equal(p.get_val('phase0.timeseries.time')[-1], 1.8016, tolerance=1.0E-3)

# Generate the explicitly simulated trajectory
exp_out = phase.simulate()

fig, ax = plt.subplots()
fig.suptitle('Brachistochrone Solution')

x_imp = p.get_val('phase0.timeseries.x')
y_imp = p.get_val('phase0.timeseries.y')

x_exp = exp_out.get_val('phase0.timeseries.x')
y_exp = exp_out.get_val('phase0.timeseries.y')

ax.plot(x_imp, y_imp, 'ro', label='solution')
ax.plot(x_exp, y_exp, 'b-', label='simulated')

ax.set_xlabel('x (m)')
ax.set_ylabel('y (m)')
ax.grid(True)
ax.legend(loc='upper right')

fig, ax = plt.subplots()

t_imp = p.get_val('phase0.timeseries.time')
theta_imp = p.get_val('phase0.timeseries.theta_rate')
t_exp = exp_out.get_val('phase0.timeseries.time')
theta_exp = exp_out.get_val('phase0.timeseries.theta_rate')

ax.plot(t_imp, theta_imp, 'ro', label='solution')
ax.plot(t_exp, theta_exp, 'b-', label='simulated')

ax.set_xlabel('time (s)')
ax.set_ylabel(r'$\theta$ (deg)')
ax.grid(True)
ax.legend(loc='upper right')

plt.show()


@use_tempdirs
class TestBrachistochronePolynomialControlExplicitRate2Targets(unittest.TestCase):
Expand Down
Loading