-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* removed ode options and added example of how to subclass Phase to minimize duplication of state options * Bump version: 0.14.2 → 0.15.0 * Now that ODEOptions have been removed, user_*_options are no longer necessary and have been removed. The finalize_variables method of Phase is also now unnecessary and has been removed. * Added a set_*_options method to correspond to each add_state, add_control, add_design_parameter, add_input_parameter, and add_polynomial_control method. * Various updates to travis testing.
- Loading branch information
Showing
16 changed files
with
597 additions
and
875 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[bumpversion] | ||
current_version = 0.14.2 | ||
current_version = 0.15.0 | ||
commit = True | ||
tag = False | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
============================================= | ||
Subclassing phases to reduce code duplication | ||
============================================= | ||
|
||
In many of the Dymos examples, you might notice that in each phase we metadata for time, states, | ||
controls, and parameters which determines targets for various variables in the ODE, the variable | ||
path which serves as the rate for states being integrated, and default units to be used for these | ||
variables. In a trajectory with many phases, this can lead to a lot of unnecessary code duplication. | ||
Afterall, an ODE system will generally be associated with a given set of state variables, and the | ||
rate sources, targets, and default units of those state variables *shouldn't* need to be specified | ||
each time you decide to use it. This is a pretty significant violation of the | ||
<DRY https://en.wikipedia.org/wiki/Don%27t_repeat_yourself>_ principle. | ||
|
||
|
||
The developers didn't want to require that non-standard OpenMDAO systems be used in ODEs. | ||
Thanks to recent updates to the OpenMDAO setup stack, you can now subclass | ||
Phase to associate that subclass with a particular ODE class. The `initialize`` method for that Phase-derived | ||
class can include declarations for `add_state`, `set_time_options`, `add_control`, etc., that set | ||
default behavior for states, times, controls, and parameters when that phase is used. Just remember | ||
to invoke `super(DerivedPhase, self).initialize()` at the beginning of your subclass' `initialize` method. | ||
|
||
|
||
If you want to override any options for time, states, controls, or parameters you can use the | ||
`set_time_options`, `set_state_options`, `set_control_options`, `set_polynomial_control_options`, | ||
`set_input_parameter_options`, or `set_design_parameter_options` to change any of the settings | ||
whose defaults were set in the phase definition. | ||
|
||
|
||
.. warning:: | ||
Dymos Trajectory objects need to know about the optimal control variables in Phases | ||
(time, states, controls, parameters). Therefore all of these variables must be added | ||
to a phase **prior** to setup! | ||
|
||
|
||
Consider the two-phase cannonball example. Here we use the same ODE in two phases. To reduce the | ||
amount of code needed when setting up the problem, we can create `Cannonball` phase, which always | ||
uses the CannonballODE. Since the default units, targets, and rate_source of the state variables | ||
are unchanged in each phase in which we use it, we can define CannonballPhase as follows: | ||
|
||
|
||
.. embed-code:: | ||
dymos.examples.cannonball.cannonball_phase.CannonballPhase | ||
:layout: code | ||
|
||
|
||
While the setup method could also have been used here, there will be some unit issues in the phase | ||
linkages. Definining this state metadata in `initialize`, before setup is called, ensures that Dymos | ||
has all of the necessary unit information when setting up the trajectory. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import dymos as dm | ||
from .cannonball_ode import CannonballODE | ||
|
||
|
||
class CannonballPhase(dm.Phase): | ||
""" | ||
CannonballPhase serves as a demonstration of how to subclass Phase in order to associate | ||
certain metadata of a set of states with a given ODE. | ||
""" | ||
|
||
def initialize(self): | ||
|
||
# First perform the standard phase initialization. | ||
# After this step no more options may be declared, but the options | ||
# will be available for assignment. | ||
super(CannonballPhase, self).initialize() | ||
|
||
# Here we set the ODE class to be used. | ||
# Note if this phase is instantiated with an ode_class argument it will be overridden here! | ||
self.options['ode_class'] = CannonballODE | ||
|
||
# Here we only set default units, rate_sources, and targets. | ||
# Other options are generally more problem-specific. | ||
self.add_state('r', units='m', rate_source='eom.r_dot') | ||
self.add_state('h', units='m', rate_source='eom.h_dot', targets=['atmos.h']) | ||
self.add_state('gam', units='rad', rate_source='eom.gam_dot', targets=['eom.gam']) | ||
self.add_state('v', units='m/s', rate_source='eom.v_dot', | ||
targets=['dynamic_pressure.v', 'eom.v', 'kinetic_energy.v']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.