コード例 #1
0
ファイル: component.py プロジェクト: Richard27Yang/OpenMDAO
    def _find_partial_matches(self, of, wrt):
        """
        Find all partial derivative matches from of and wrt.

        Parameters
        ----------
        of : str or list of str
            The relative name of the residual(s) that derivatives are being computed for.
            May also contain a glob pattern.
        wrt : str or list of str
            The relative name of the variables that derivatives are taken with respect to.
            This can contain the name of any input or output variable.
            May also contain a glob pattern.

        Returns
        -------
        tuple(list, list)
            Pair of lists containing pattern matches (if any). Returns (of_matches, wrt_matches)
            where of_matches is a list of tuples (pattern, matches) and wrt_matches is a list of
            tuples (pattern, output_matches, input_matches).
        """
        of_list = [of] if isinstance(of, string_types) else of
        wrt_list = [wrt] if isinstance(wrt, string_types) else wrt
        outs = list(self._var_allprocs_prom2abs_list['output'])
        ins = list(self._var_allprocs_prom2abs_list['input'])

        of_pattern_matches = [(pattern, find_matches(pattern, outs)) for pattern in of_list]
        wrt_pattern_matches = [(pattern, find_matches(pattern, outs + ins)) for pattern in wrt_list]
        return of_pattern_matches, wrt_pattern_matches
コード例 #2
0
ファイル: component.py プロジェクト: OpenMDAO/OpenMDAO
    def _find_partial_matches(self, of, wrt):
        """
        Find all partial derivative matches from of and wrt.

        Parameters
        ----------
        of : str or list of str
            The relative name of the residual(s) that derivatives are being computed for.
            May also contain a glob pattern.
        wrt : str or list of str
            The relative name of the variables that derivatives are taken with respect to.
            This can contain the name of any input or output variable.
            May also contain a glob pattern.

        Returns
        -------
        tuple(list, list)
            Pair of lists containing pattern matches (if any). Returns (of_matches, wrt_matches)
            where of_matches is a list of tuples (pattern, matches) and wrt_matches is a list of
            tuples (pattern, output_matches, input_matches).
        """
        of_list = [of] if isinstance(of, string_types) else of
        wrt_list = [wrt] if isinstance(wrt, string_types) else wrt
        of, wrt = self._get_potential_partials_lists()

        of_pattern_matches = [(pattern, find_matches(pattern, of)) for pattern in of_list]
        wrt_pattern_matches = [(pattern, find_matches(pattern, wrt)) for pattern in wrt_list]
        return of_pattern_matches, wrt_pattern_matches
コード例 #3
0
ファイル: component.py プロジェクト: Richard27Yang/OpenMDAO
    def _get_check_partial_options(self):
        """
        Return dictionary of partial options with pattern matches processed.

        This is called by check_partials.

        Returns
        -------
        dict(wrt : (options))
            Dictionary keyed by name with tuples of options (method, form, step, step_calc)
        """
        opts = {}
        outs = list(self._var_allprocs_prom2abs_list['output'].keys())
        ins = list(self._var_allprocs_prom2abs_list['input'].keys())
        for wrt_list, method, form, step, step_calc in self._declared_partial_checks:
            for pattern in wrt_list:
                for match in find_matches(pattern, outs + ins):
                    if match in opts:
                        opt = opts[match]

                        # New assignments take precedence
                        for name, value in zip(['method', 'form', 'step', 'step_calc'],
                                               [method, form, step, step_calc]):
                            if value is not None:
                                opt[name] = value

                    else:
                        opts[match] = {'method': method,
                                       'form': form,
                                       'step': step,
                                       'step_calc': step_calc}

        return opts
コード例 #4
0
ファイル: component.py プロジェクト: feitianyiren/OpenMDAO
    def _get_check_partial_options(self):
        """
        Return dictionary of partial options with pattern matches processed.

        This is called by check_partials.

        Returns
        -------
        dict(wrt : (options))
            Dictionary keyed by name with tuples of options (method, form, step, step_calc)
        """
        opts = {}
        outs = list(self._var_allprocs_prom2abs_list['output'].keys())
        ins = list(self._var_allprocs_prom2abs_list['input'].keys())

        invalid_wrt = []

        for wrt_list, method, form, step, step_calc in self._declared_partial_checks:
            for pattern in wrt_list:
                matches = find_matches(pattern, outs + ins)

                # if a non-wildcard var name was specified and not found, save for later Exception
                if len(matches) == 0 and _valid_var_name(pattern):
                    invalid_wrt.append(pattern)

                for match in matches:
                    if match in opts:
                        opt = opts[match]

                        # New assignments take precedence
                        for name, value in zip(
                            ['method', 'form', 'step', 'step_calc'],
                            [method, form, step, step_calc]):
                            if value is not None:
                                opt[name] = value

                    else:
                        opts[match] = {
                            'method': method,
                            'form': form,
                            'step': step,
                            'step_calc': step_calc
                        }

        if invalid_wrt:
            if len(invalid_wrt) == 1:
                msg = "Invalid 'wrt' variable specified for check_partial options on Component " \
                      "'{}': '{}'.".format(self.pathname, invalid_wrt[0])
            else:
                msg = "Invalid 'wrt' variables specified for check_partial options on Component " \
                      "'{}': {}.".format(self.pathname, invalid_wrt)
            raise ValueError(msg)

        return opts
コード例 #5
0
ファイル: component.py プロジェクト: johnjasa/OpenMDAO
    def _get_check_partial_options(self):
        """
        Return dictionary of partial options with pattern matches processed.

        This is called by check_partials.

        Returns
        -------
        dict(wrt : (options))
            Dictionary keyed by name with tuples of options (method, form, step, step_calc)
        """
        opts = {}
        outs = list(self._var_allprocs_prom2abs_list['output'].keys())
        ins = list(self._var_allprocs_prom2abs_list['input'].keys())

        invalid_wrt = []

        for wrt_list, method, form, step, step_calc, directional in self._declared_partial_checks:
            for pattern in wrt_list:
                matches = find_matches(pattern, outs + ins)

                # if a non-wildcard var name was specified and not found, save for later Exception
                if len(matches) == 0 and _valid_var_name(pattern):
                    invalid_wrt.append(pattern)

                for match in matches:
                    if match in opts:
                        opt = opts[match]

                        # New assignments take precedence
                        keynames = ['method', 'form', 'step', 'step_calc', 'directional']
                        for name, value in zip(keynames,
                                               [method, form, step, step_calc, directional]):
                            if value is not None:
                                opt[name] = value

                    else:
                        opts[match] = {'method': method,
                                       'form': form,
                                       'step': step,
                                       'step_calc': step_calc,
                                       'directional': directional}

        if invalid_wrt:
            if len(invalid_wrt) == 1:
                msg = "Invalid 'wrt' variable specified for check_partial options on Component " \
                      "'{}': '{}'.".format(self.pathname, invalid_wrt[0])
            else:
                msg = "Invalid 'wrt' variables specified for check_partial options on Component " \
                      "'{}': {}.".format(self.pathname, invalid_wrt)
            raise ValueError(msg)

        return opts