How to use the dymos.utils.indexing.get_src_indices_by_row function in dymos

To help you get started, we’ve selected a few dymos examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github OpenMDAO / dymos / dymos / phases / optimizer_based / gauss_lobatto_phase.py View on Github external
if name in self.ode_options._parameters:
            targets = self.ode_options._parameters[name]['targets']
            dynamic = self.ode_options._parameters[name]['dynamic']
            shape = self.ode_options._parameters[name]['shape']

            if dynamic:
                disc_rows = np.zeros(self.grid_data.subset_num_nodes['state_disc'], dtype=int)
                col_rows = np.zeros(self.grid_data.subset_num_nodes['col'], dtype=int)
                disc_src_idxs = get_src_indices_by_row(disc_rows, shape)
                col_src_idxs = get_src_indices_by_row(col_rows, shape)
                if shape == (1,):
                    disc_src_idxs = disc_src_idxs.ravel()
                    col_src_idxs = col_src_idxs.ravel()
            else:
                disc_src_idxs = np.squeeze(get_src_indices_by_row([0], shape), axis=0)
                col_src_idxs = np.squeeze(get_src_indices_by_row([0], shape), axis=0)

            rhs_disc_tgts = ['rhs_disc.{0}'.format(t) for t in targets]
            connection_info.append((rhs_disc_tgts, disc_src_idxs))

            rhs_col_tgts = ['rhs_col.{0}'.format(t) for t in targets]
            connection_info.append((rhs_col_tgts, col_src_idxs))

        return connection_info
github OpenMDAO / dymos / dymos / transcriptions / pseudospectral / gauss_lobatto.py View on Github external
def setup_controls(self, phase):
        super(GaussLobatto, self).setup_controls(phase)
        grid_data = self.grid_data

        for name, options in phase.control_options.items():
            disc_idxs = grid_data.subset_node_indices['state_disc']
            col_idxs = grid_data.subset_node_indices['col']

            disc_src_idxs = get_src_indices_by_row(disc_idxs, options['shape'])
            col_src_idxs = get_src_indices_by_row(col_idxs, options['shape'])

            if options['shape'] == (1,):
                disc_src_idxs = disc_src_idxs.ravel()
                col_src_idxs = col_src_idxs.ravel()

            if phase.control_options[name]['targets']:
                targets = phase.control_options[name]['targets']

                phase.connect('control_values:{0}'.format(name),
                              ['rhs_disc.{0}'.format(t) for t in targets],
                              src_indices=disc_src_idxs, flat_src_indices=True)

                phase.connect('control_values:{0}'.format(name),
                              ['rhs_col.{0}'.format(t) for t in targets],
                              src_indices=col_src_idxs, flat_src_indices=True)
github OpenMDAO / dymos / dymos / phases / simulation / simulation_phase.py View on Github external
grid_data=self.options['grid_data'],
                                                           t_eval_per_seg=self.t_eval_per_seg,
                                                           t_initial=self.options['t_initial'],
                                                           t_duration=self.options['t_duration'])

            self.add_subsystem('interp_comp', interp_comp)

        for name, options in iteritems(self.control_options):
            ivc.add_output('implicit_controls:{0}'.format(name),
                           val=np.ones((nn,) + options['shape']),
                           units=options['units'])

            for i in range(num_seg):
                i1, i2 = gd.subset_segment_indices['control_disc'][i, :]
                seg_idxs = gd.subset_node_indices['control_disc'][i1:i2]
                src_idxs = get_src_indices_by_row(row_idxs=seg_idxs, shape=options['shape'])
                self.connect(src_name='implicit_controls:{0}'.format(name),
                             tgt_name='segment_{0}.controls:{1}'.format(i, name),
                             src_indices=src_idxs, flat_src_indices=True)

            # connect the control to the interpolator

            row_idxs = gd.subset_node_indices['control_disc']
            src_idxs = get_src_indices_by_row(row_idxs=row_idxs, shape=options['shape'])
            self.connect(src_name='implicit_controls:{0}'.format(name),
                         tgt_name='interp_comp.controls:{0}'.format(name),
                         src_indices=src_idxs, flat_src_indices=True)

            if options['targets']:
                self.connect(src_name='interp_comp.control_values:{0}'.format(name),
                             tgt_name=['ode.{0}'.format(tgt) for tgt in options['targets']])
github OpenMDAO / dymos / dymos / transcriptions / pseudospectral / gauss_lobatto.py View on Github external
def setup_polynomial_controls(self, phase):
        super(GaussLobatto, self).setup_polynomial_controls(phase)
        grid_data = self.grid_data

        for name, options in phase.polynomial_control_options.items():
            disc_idxs = grid_data.subset_node_indices['state_disc']
            col_idxs = grid_data.subset_node_indices['col']

            disc_src_idxs = get_src_indices_by_row(disc_idxs, options['shape'])
            col_src_idxs = get_src_indices_by_row(col_idxs, options['shape'])

            if options['shape'] == (1,):
                disc_src_idxs = disc_src_idxs.ravel()
                col_src_idxs = col_src_idxs.ravel()

            if phase.polynomial_control_options[name]['targets']:
                targets = phase.polynomial_control_options[name]['targets']

                phase.connect('polynomial_control_values:{0}'.format(name),
                              ['rhs_disc.{0}'.format(t) for t in targets],
                              src_indices=disc_src_idxs, flat_src_indices=True)

                phase.connect('polynomial_control_values:{0}'.format(name),
                              ['rhs_col.{0}'.format(t) for t in targets],
                              src_indices=col_src_idxs, flat_src_indices=True)
github OpenMDAO / dymos / dymos / phases / simulation / simulation_phase.py View on Github external
deriv=2))
            self.connect(src_name='interp_comp.control_rates:{0}_rate2'.format(name),
                         tgt_name='timeseries.all_values:control_rates:{0}_rate2'.format(name))

        for name, options in iteritems(self.design_parameter_options):
            units = options['units']
            timeseries_comp._add_timeseries_output('design_parameters:{0}'.format(name),
                                                   var_class='design_parameter',
                                                   units=units)

            if self.options['ode_class'].ode_options._parameters[name]['dynamic']:
                src_idxs_raw = np.zeros(num_points, dtype=int)
                src_idxs = get_src_indices_by_row(src_idxs_raw, options['shape'])
            else:
                src_idxs_raw = np.zeros(1, dtype=int)
                src_idxs = get_src_indices_by_row(src_idxs_raw, options['shape'])

            self.connect(src_name='design_parameters:{0}'.format(name),
                         tgt_name='timeseries.all_values:design_parameters:{0}'.format(name),
                         src_indices=src_idxs, flat_src_indices=True)

        for name, options in iteritems(self.input_parameter_options):
            units = options['units']
            # target_param = options['target_param']
            timeseries_comp._add_timeseries_output('input_parameters:{0}'.format(name),
                                                   var_class='input_parameter',
                                                   units=units)

            if self.options['ode_class'].ode_options._parameters[name]['dynamic']:
                src_idxs_raw = np.zeros(num_points, dtype=int)
                src_idxs = get_src_indices_by_row(src_idxs_raw, options['shape'])
            else:
github OpenMDAO / dymos / dymos / transcriptions / pseudospectral / gauss_lobatto.py View on Github external
def setup_controls(self, phase):
        super(GaussLobatto, self).setup_controls(phase)
        grid_data = self.grid_data

        for name, options in phase.control_options.items():
            disc_idxs = grid_data.subset_node_indices['state_disc']
            col_idxs = grid_data.subset_node_indices['col']

            disc_src_idxs = get_src_indices_by_row(disc_idxs, options['shape'])
            col_src_idxs = get_src_indices_by_row(col_idxs, options['shape'])

            if options['shape'] == (1,):
                disc_src_idxs = disc_src_idxs.ravel()
                col_src_idxs = col_src_idxs.ravel()

            if phase.control_options[name]['targets']:
                targets = phase.control_options[name]['targets']

                phase.connect('control_values:{0}'.format(name),
                              ['rhs_disc.{0}'.format(t) for t in targets],
                              src_indices=disc_src_idxs, flat_src_indices=True)

                phase.connect('control_values:{0}'.format(name),
                              ['rhs_col.{0}'.format(t) for t in targets],
                              src_indices=col_src_idxs, flat_src_indices=True)
github OpenMDAO / dymos / dymos / transcriptions / pseudospectral / pseudospectral_base.py View on Github external
time_units=time_units))

        phase.connect('dt_dstau', ('collocation_constraint.dt_dstau'),
                      src_indices=grid_data.subset_node_indices['col'])

        # Add the continuity constraint component if necessary
        if num_seg > 1:
            segment_end_idxs = grid_data.subset_node_indices['segment_ends']
            state_disc_idxs = grid_data.subset_node_indices['state_disc']

            if not self.options['compressed']:
                state_input_subidxs = np.where(np.in1d(state_disc_idxs, segment_end_idxs))[0]

                for name, options in phase.state_options.items():
                    shape = options['shape']
                    flattened_src_idxs = get_src_indices_by_row(state_input_subidxs, shape=shape,
                                                                flat=True)
                    phase.connect('states:{0}'.format(name),
                                  'continuity_comp.states:{}'.format(name),
                                  src_indices=flattened_src_idxs, flat_src_indices=True)

            for name, options in phase.control_options.items():
                control_src_name = 'control_values:{0}'.format(name)

                # The sub-indices of control_disc indices that are segment ends
                segment_end_idxs = grid_data.subset_node_indices['segment_ends']
                src_idxs = get_src_indices_by_row(segment_end_idxs, options['shape'], flat=True)

                phase.connect(control_src_name,
                              'continuity_comp.controls:{0}'.format(name),
                              src_indices=src_idxs, flat_src_indices=True)
github OpenMDAO / dymos / dymos / phases / optimizer_based / radau_pseudospectral_phase.py View on Github external
var_class=self._classify_var(name),
                                                   shape=options['shape'],
                                                   units=get_rate_units(control_units,
                                                                        time_units,
                                                                        deriv=2))
            self.connect(src_name='control_rates:{0}_rate2'.format(name),
                         tgt_name='timeseries.all_values:control_rates:{0}_rate2'.format(name))

        for name, options in iteritems(self.polynomial_control_options):
            control_units = options['units']
            timeseries_comp._add_timeseries_output('polynomial_controls:{0}'.format(name),
                                                   var_class=self._classify_var(name),
                                                   shape=options['shape'],
                                                   units=control_units)
            src_rows = gd.subset_node_indices['all']
            src_idxs = get_src_indices_by_row(src_rows, options['shape'])
            self.connect(src_name='polynomial_control_values:{0}'.format(name),
                         tgt_name='timeseries.all_values:'
                                  'polynomial_controls:{0}'.format(name),
                         src_indices=src_idxs, flat_src_indices=True)

            # # Control rates
            timeseries_comp._add_timeseries_output('polynomial_control_rates:{0}_rate'.format(name),
                                                   var_class=self._classify_var(name),
                                                   shape=options['shape'],
                                                   units=get_rate_units(control_units,
                                                                        time_units,
                                                                        deriv=1))
            self.connect(src_name='polynomial_control_rates:{0}_rate'.format(name),
                         tgt_name='timeseries.all_values:polynomial_control_rates:'
                                  '{0}_rate'.format(name))
github OpenMDAO / dymos / dymos / transcriptions / runge_kutta / runge_kutta.py View on Github external
phase.connect(src_name=src, tgt_name=tgt,
                              src_indices=src_idxs, flat_src_indices=True)

            elif var_type in ('polynomial_control_rate', 'polynomial_control_rate2'):
                src_idxs = get_src_indices_by_row(seg_end_idxs, shape=options['shape'])

                src = 'polynomial_control_rates:{0}'.format(var)
                tgt = 'path_constraints.all_values:{0}'.format(con_name)

                phase.connect(src_name=src, tgt_name=tgt,
                              src_indices=src_idxs, flat_src_indices=True)

            else:
                # Failed to find variable, assume it is in the ODE
                src_rows = np.arange(num_seg * 2, dtype=int)
                src_idxs = get_src_indices_by_row(src_rows, shape=options['shape'])

                src = 'ode.{0}'.format(var)
                tgt = 'path_constraints.all_values:{0}'.format(con_name)

                phase.connect(src_name=src, tgt_name=tgt,
                              src_indices=src_idxs, flat_src_indices=True)
github OpenMDAO / dymos / dymos / transcriptions / pseudospectral / gauss_lobatto.py View on Github external
elif var_type == 'input_parameter':
            rate_path = 'input_parameters:{0}_out'.format(var)
            node_idxs = np.zeros(gd.subset_num_nodes[nodes], dtype=int)
        # Failed to find variable, it must be an ODE output
        else:
            # Failed to find variable, assume it is in the RHS
            if nodes == 'col':
                rate_path = 'rhs_col.{0}'.format(var)
                node_idxs = np.arange(gd.subset_num_nodes[nodes], dtype=int)
            elif nodes == 'state_disc':
                rate_path = 'rhs_disc.{0}'.format(var)
                node_idxs = np.arange(gd.subset_num_nodes[nodes], dtype=int)
            else:
                raise ValueError('Unabled to find rate path for variable {0} at '
                                 'node subset {1}'.format(var, nodes))
        src_idxs = get_src_indices_by_row(node_idxs, shape=shape)

        return rate_path, src_idxs