Skip to content

Updates to phase.interpolate, renamed to phase.interp. #592

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

Merged
merged 7 commits into from
May 12, 2021

Conversation

robfalck
Copy link
Contributor

Summary

Adds phase.interp to the API and deprecates phase.interpolate.

phase.interp is similar with a few exceptions:

  1. It now accepts the name of the variable to be interpolated. We can use this name to perform introspection and interpolate onto the correct node subset (state or control).
  2. It will now interpolate polynomial control values.
  3. The order of the arguments was changed so that name is first, followed by ys, this makes the most common use case of linear interpolation much more terse: phase.interpolate('x', [0, 10])
  4. If given a name that is not a state, control, or polynomial control, an exception will be raised if no node subset is specified.

Related Issues

Status

  • Ready for merge

Backwards incompatibilities

phase.interpolate is deprecated

New Dependencies

None

@coveralls
Copy link

coveralls commented May 10, 2021

Coverage Status

Coverage decreased (-0.009%) to 96.73% when pulling 6e25eca on robfalck:interpolate_introspection into 5398cb4 on OpenMDAO:master.

p.set_val('traj.phase0.states:x', phase.interp('x', ys=[0, 10]), units='m')
p.set_val('traj.phase0.states:y', phase.interp('y', ys=[10, 5]), units='m')
p.set_val('traj.phase0.states:v', phase.interp('v', ys=[0, 9.9]), units='m/s')
p.set_val('traj.phase0.controls:theta', phase.interp('theta', ys=[5, 100]), units='deg')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was the change in values intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not intentional but in the end only the state values matter here, since we're using fix_initial/fix_final. The control values will all change and the initial guess isn't that consequential.

p.set_val('traj.burn2.states:r', value=burn2.interp('r', [1, 3]))
p.set_val('traj.burn2.states:theta', value=burn2.interp('theta', [0, 4.0]))
p.set_val('traj.burn2.states:vr', value=burn2.interp('vr', [0, 0]))
p.set_val('traj.burn2.states:vt', value=burn2.interp('vt', [1, np.sqrt(1 / 3)]))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some value changes here too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

p['traj0.phase0.states:v'] = phase.interpolate(ys=[0, 9.9], nodes='state_input')
p.set_val('traj0.phase0.states:x', phase.interp('x', [0, 10]), units='m')
p.set_val('traj0.phase0.states:y', phase.interp('y', [10, 5]), units='m')
p.set_val('traj0.phase0.states:v', phase.interp('v', [0, 5]), units='m/s')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes here too. Wonder why you didn't need to change any asserts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, final velocity is unconstrained.

@@ -1669,6 +1675,93 @@ def interpolate(self, xs=None, ys=None, nodes='all', kind='linear', axis=0):
res = res.T
return res

def interp(self, name=None, ys=None, xs=None, nodes=None, kind='linear', axis=0):
"""
Return an array of values on interpolated to the given node subset of the phase.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wording is funny here

@robfalck robfalck merged commit d4e68bd into OpenMDAO:master May 12, 2021
@robfalck robfalck deleted the interpolate_introspection branch August 25, 2022 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

phase.interpolate can accept a variable name and then interpolate to the appropriate input node set
4 participants