Skip to content

Commit

Permalink
Fixed an issue with timeseries reports and the Birkhoff transcription. (
Browse files Browse the repository at this point in the history
#1040)

* gitignore updates

* Add scripts used to build joss figures

* Added a duplicate method to phase.

* Fixed some issues with fix_initial and fix_final on states. Added duplicate to AnalyticPhase and SimulationPhase, but its not implemented in SimulationPhase yet

* docstring linting

* Fixed occasional extrapolation issue in the birkhoff cannonball case.

* Removed phase duplication from Birkhoff cannonball example until it is more well behaved.

* Made phase options all members of the component options so that they're saved in the Case recorders.

* Bokeh timeseries report handles _system_options with case numbers.

* Remove superfluous system_class option from Trajectory

* traj_results_report.html is created in the cwd if reports directory does not exist.

* Phase duplicate no longer assigns to the read-only `state_options` property in Phase.

* Removed old unused method SimulationPhase.initialize_from_phase
  • Loading branch information
robfalck authored Feb 2, 2024
1 parent 7e24a7f commit e9c1ddf
Show file tree
Hide file tree
Showing 18 changed files with 840 additions and 260 deletions.
13 changes: 9 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,15 @@ fort.6
# mkdocs
/mkdocs/site

# Examples
dymos/examples/*/*/_output/
docs/examples/*/*.db
docs/dymos_book/examples/*/coloring_files/
# Docs
docs/dymos_book/_build
docs/dymos_book/_srcdocs

# Dymos and OpenMDAO files
**/*.db
**/*.sql
**/coloring_files
**/reports

# Misc files
docs/faq/*/*.pkl
Expand Down
6 changes: 6 additions & 0 deletions docs/dymos_book/api/phase_api.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@
" :noindex:\n",
"```\n",
"\n",
"## duplicate\n",
"```{eval-rst}\n",
" .. automethod:: dymos.Phase.duplicate\n",
" :noindex:\n",
"```\n",
"\n",
"## set_refine_options\n",
"```{eval-rst}\n",
" .. automethod:: dymos.Phase.set_refine_options\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,24 +350,16 @@
"\n",
"# Second Phase (descent)\n",
"transcription = dm.GaussLobatto(num_segments=5, order=3, compressed=True)\n",
"descent = dm.Phase(ode_class=CannonballODE, transcription=transcription)\n",
"# descent = dm.Phase(ode_class=CannonballODE, transcription=transcription)\n",
"descent = ascent.duplicate(transcription=transcription)\n",
"\n",
"traj.add_phase('descent', descent)\n",
"\n",
"# All initial states and time are free, since\n",
"# they will be linked to the final states of ascent.\n",
"# Final altitude is fixed, because we will set\n",
"# it to zero so that the phase ends at ground impact)\n",
"descent.set_time_options(initial_bounds=(.5, 100), duration_bounds=(.5, 100),\n",
" duration_ref=100, units='s')\n",
"descent.add_state('r')\n",
"descent.add_state('h', fix_initial=False, fix_final=True)\n",
"descent.add_state('gam', fix_initial=False, fix_final=False)\n",
"descent.add_state('v', fix_initial=False, fix_final=False)\n",
"\n",
"descent.add_parameter('S', units='m**2', static_target=True)\n",
"descent.add_parameter('m', units='kg', static_target=True)\n",
"\n",
"# Because we copied the descent phase\n",
"# - The 'fix_initial' option for time was set to False\n",
"# - All state 'fix_initial' and 'fix_final' options are set to False.\n",
"# - We only need to fix the final value of altitude so the descent phase ends at ground impact.\n",
"descent.set_state_options('h', fix_final=True)\n",
"descent.add_objective('r', loc='final', scaler=-1.0)\n",
"\n",
"# Add internally-managed design parameters to the trajectory.\n",
Expand Down Expand Up @@ -554,7 +546,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
"version": "3.11.4"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def setup(self):
rho_data = USatm1976Data.rho * om.unit_conversion('slug/ft**3', 'kg/m**3')[0]
self.rho_interp = interp1d(np.array(alt_data, dtype=complex),
np.array(rho_data, dtype=complex),
kind='linear')
kind='linear', bounds_error=False, fill_value='extrapolate')

def compute(self, inputs, outputs):

Expand Down
66 changes: 66 additions & 0 deletions dymos/phase/analytic_phase.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from copy import deepcopy

import openmdao.api as om

from .phase import Phase
Expand Down Expand Up @@ -472,3 +474,67 @@ def set_simulate_options(self, *args, **kwargs):
Simulation cannot be performed on AnalyticPhase.
"""
raise NotImplementedError('Method set_simulate_options is not available for AnalyticPhase.')

def duplicate(self, num_nodes=None, boundary_constraints=False, path_constraints=False, objectives=False,
fix_initial_time=False):
"""
Create a copy of this phase where most options and attributes are deep copies of those in the original.
By default, a deepcopy of the transcription in the original phase is used.
Boundary constraints, path constraints, and objectives are _NOT_ copied by default, but the user may opt to do so.
By default, initial time is not fixed, nor are the initial or final state values.
These also can be overridden with the appropriate arguments.
Parameters
----------
num_nodes : int or None
The number of nodes to use in the new phase, or None if it should use the same
number as the phase being duplicated.
boundary_constraints : bool
If True, retain all boundary constraints from the phase to be copied.
path_constraints : bool
If True, retain all path constraints from the phase to be copied.
objectives : bool
If True, retain all objectives from the phase to be copied.
fix_initial_time : bool
If True, fix the initial time of the returned phase.
Returns
-------
AnalyticPhase
The new phase created by duplicating this one.
"""
nn = num_nodes if num_nodes is not None else self.options['num_nodes']
ode_class = self.options['ode_class']
ode_init_kwargs = self.options['ode_init_kwargs']
auto_solvers = self.options['auto_solvers']

p = AnalyticPhase(num_nodes=nn, ode_class=ode_class, ode_init_kwargs=ode_init_kwargs,
auto_solvers=auto_solvers)

p.time_options.update(deepcopy(self.time_options))
p.time_options['fix_initial'] = fix_initial_time

for state_name, state_options in self.state_options.items():
p.state_options[state_name] = deepcopy(state_options)

for param_name, param_options in self.parameter_options.items():
p.parameter_options[param_name] = deepcopy(param_options)

p._timeseries = deepcopy(self._timeseries)

p.refine_options = deepcopy(self.refine_options)
p.simulate_options = deepcopy(self.simulate_options)
p.timeseries_options = deepcopy(self.timeseries_options)

if boundary_constraints:
p._initial_boundary_constraints = deepcopy(self._initial_boundary_constraints)
p._final_boundary_constraints = deepcopy(self._final_boundary_constraints)

if path_constraints:
p._path_constraints = deepcopy(self._path_constraints)

if objectives:
p._objectives = deepcopy(self._objectives)

return p
Loading

0 comments on commit e9c1ddf

Please sign in to comment.