Dymos: How Can I Record And Visualize Subsystem Inputs/outputs?
Solution 1:
So the timeseries
object captures time series data regardless of the transcription used. By default, it includes the "problem" variables (states, controls, input and design parameters, and time).
To record other outputs in your ODE, use the add_timeseries_output
method on Phase. It is documented here: https://openmdao.github.io/dymos/feature_reference/timeseries.html
For the aircraft example in Dymos, you can add the line:
phase.add_timeseries_output('aero.CL', units=None, shape=(1,))
Which will add a new output traj.phase0.timeseries.CL
. Theres a few things to note here:
- dotted variable names aren't allowed. So while
aero.CL
is the path of the lift coefficient relative to the top of the ODE, it will be recorded in the timeseries asCL
. If this will cause name collisions, you can override the timeseries name using theoutput_name
argument. - Currently we can't use introspection to automatically determine the units and shape of the variable to be added to the timeseries (we're working on that). So it's good practice to specify the units and shape when adding the timeseries output (and mandatory if the units are not None or the shape is not (1,).
So adding that above line to the commercial aircraft example, and adding the following to our simplified plot maker:
plot_results([('traj.phase0.timeseries.states:range', 'traj.phase0.timeseries.states:alt',
'range (NM)', 'altitude (kft)'),
('traj.phase0.timeseries.time', 'traj.phase0.timeseries.states:mass_fuel',
'time (s)', 'fuel mass (lbm)'),
('traj.phase0.timeseries.time', 'traj.phase0.timeseries.CL',
'time (s)', 'lift coefficient')],
title='Commercial Aircraft Optimization',
p_sol=p, p_sim=exp_out)
Make the following plot:
You can use an OpenMDAO recorder to store timeseries outputs in a recorded database file. For instance, to add a recorder to the optimization driver (which will save at every iteration), you'd do something like this:
p.driver.add_recorder(rec)
p.driver.recording_options['record_desvars'] = True
p.driver.recording_options['record_responses'] = True
p.driver.recording_options['record_objectives'] = True
p.driver.recording_options['record_constraints'] = True
p.driver.recording_options['includes'] = ['*timeseries*']
That last instruction will inform Dymos to record all of the outputs whose name includes "timeseries". FYI you can also add a recorder to the problem and only record the final values, instead of recording each iteration. This can save a good bit of filesize if you're not interested in the iteration history.
Post a Comment for "Dymos: How Can I Record And Visualize Subsystem Inputs/outputs?"