openmdao/core/total_jac.py
def compute_totals_approx(self, initialize=False):
        """
        Compute derivatives of desired quantities with respect to desired inputs.

        Uses an approximation method, e.g., fd or cs to calculate the derivatives.

        Parameters
        ----------
        initialize : bool
            Set to True to re-initialize the FD in model. This is only needed when manually
            calling compute_totals on the problem.

        Returns
        -------
        derivs : object
            Derivatives in form requested by 'return_format'.
        """
        of = self.of
        wrt = self.wrt
        model = self.model
        return_format = self.return_format

        # Prepare model for calculation by cleaning out the derivatives
        # vectors.
        for vec_name in model._lin_vec_names:
            model._vectors['input'][vec_name].set_const(0.0)
            model._vectors['output'][vec_name].set_const(0.0)
            model._vectors['residual'][vec_name].set_const(0.0)

        # Solve for derivs with the approximation_scheme.
        # This cuts out the middleman by grabbing the Jacobian directly after linearization.

        # Re-initialize so that it is clean.
        if initialize:
            if model._approx_schemes:
                method = list(model._approx_schemes)[0]
                kwargs = model._owns_approx_jac_meta
                model.approx_totals(method=method, **kwargs)
            else:
                model.approx_totals(method='fd')

        model._setup_jacobians(recurse=False)

        # Linearize Model
        model._linearize(model._assembled_jac, sub_do_ln=model._linear_solver._linearize_children())

        approx_jac = model._jacobian._subjacs_info

        of_idx = model._owns_approx_of_idx
        wrt_idx = model._owns_approx_wrt_idx

        totals = self.J_dict
        if return_format == 'flat_dict':
            for prom_out, output_name in zip(self.prom_of, of):
                for prom_in, input_name in zip(self.prom_wrt, wrt):
                    totals[prom_out, prom_in][:] = _get_subjac(approx_jac[output_name, input_name],
                                                               prom_out, prom_in, of_idx, wrt_idx)

        elif return_format in ('dict', 'array'):
            for prom_out, output_name in zip(self.prom_of, of):
                tot = totals[prom_out]
                for prom_in, input_name in zip(self.prom_wrt, wrt):
                    tot[prom_in][:] = _get_subjac(approx_jac[output_name, input_name],
                                                  prom_out, prom_in, of_idx, wrt_idx)
        else:
            msg = "Unsupported return format '%s." % return_format
            raise NotImplementedError(msg)

        if self.has_scaling:
            self._do_scaling(totals)

        if return_format == 'array':
            totals = self.J  # change back to array version

        return totals

        Compute derivatives of desired quantities with respect to desired inputs.

        Uses an approximation method, e.g., fd or cs to calculate the derivatives.

        Parameters
        ----------
        initialize : bool
            Set to True to re-initialize the FD in model. This is only needed when manually
            calling compute_totals on the problem.

        Returns
        -------
        derivs : object
            Derivatives in form requested by 'return_format'.
        
Compute derivatives of desired quantities with respect to desired inputs.
Uses an approximation method, e.g., fd or cs to calculate the derivatives.

Parameters

initialize : bool
Set to True to re-initialize the FD in model. This is only needed when manually
calling compute_totals on the problem.

Returns

derivs : object
Derivatives in form requested by 'return_format'.
Compute derivatives of desired quantities with respect to desired inputs . Uses an approximation method e . g . fd or cs to calculate the derivatives . Parameters initialize : bool Set to True to re - initialize the FD in model . This is only needed when manually calling compute_totals on the problem . Returns derivs : object Derivatives in form requested by ' return_format ' .
def compute_totals_approx(self, initialize=False):
        of = self.of
        wrt = self.wrt
        model = self.model
        return_format = self.return_format
        for vec_name in model._lin_vec_names:
            model._vectors['input'][vec_name].set_const(0.0)
            model._vectors['output'][vec_name].set_const(0.0)
            model._vectors['residual'][vec_name].set_const(0.0)
        if initialize:
            if model._approx_schemes:
                method = list(model._approx_schemes)[0]
                kwargs = model._owns_approx_jac_meta
                model.approx_totals(method=method, **kwargs)
            else:
                model.approx_totals(method='fd')
        model._setup_jacobians(recurse=False)
        model._linearize(model._assembled_jac, sub_do_ln=model._linear_solver._linearize_children())
        approx_jac = model._jacobian._subjacs_info
        of_idx = model._owns_approx_of_idx
        wrt_idx = model._owns_approx_wrt_idx
        totals = self.J_dict
        if return_format == 'flat_dict':
            for prom_out, output_name in zip(self.prom_of, of):
                for prom_in, input_name in zip(self.prom_wrt, wrt):
                    totals[prom_out, prom_in][:] = _get_subjac(approx_jac[output_name, input_name],
                                                               prom_out, prom_in, of_idx, wrt_idx)
        elif return_format in ('dict', 'array'):
            for prom_out, output_name in zip(self.prom_of, of):
                tot = totals[prom_out]
                for prom_in, input_name in zip(self.prom_wrt, wrt):
                    tot[prom_in][:] = _get_subjac(approx_jac[output_name, input_name],
                                                  prom_out, prom_in, of_idx, wrt_idx)
        else:
            msg = "Unsupported return format '%s." % return_format
            raise NotImplementedError(msg)
        if self.has_scaling:
            self._do_scaling(totals)
        if return_format == 'array':
            totals = self.J  
        return totals
def compute_totals_approx ( self , initialize = False ) : of = self . of wrt = self . wrt model = self . model return_format = self . return_format for vec_name in model . _lin_vec_names : model . _vectors [ 'input' ] [ vec_name ] . set_const ( 0.0 ) model . _vectors [ 'output' ] [ vec_name ] . set_const ( 0.0 ) model . _vectors [ 'residual' ] [ vec_name ] . set_const ( 0.0 ) if initialize : if model . _approx_schemes : method = list ( model . _approx_schemes ) [ 0 ] kwargs = model . _owns_approx_jac_meta model . approx_totals ( method = method , ** kwargs ) else : model . approx_totals ( method = 'fd' ) model . _setup_jacobians ( recurse = False ) model . _linearize ( model . _assembled_jac , sub_do_ln = model . _linear_solver . _linearize_children ( ) ) approx_jac = model . _jacobian . _subjacs_info of_idx = model . _owns_approx_of_idx wrt_idx = model . _owns_approx_wrt_idx totals = self . J_dict if return_format == 'flat_dict' : for prom_out , output_name in zip ( self . prom_of , of ) : for prom_in , input_name in zip ( self . prom_wrt , wrt ) : totals [ prom_out , prom_in ] [ : ] = _get_subjac ( approx_jac [ output_name , input_name ] , prom_out , prom_in , of_idx , wrt_idx ) elif return_format in ( 'dict' , 'array' ) : for prom_out , output_name in zip ( self . prom_of , of ) : tot = totals [ prom_out ] for prom_in , input_name in zip ( self . prom_wrt , wrt ) : tot [ prom_in ] [ : ] = _get_subjac ( approx_jac [ output_name , input_name ] , prom_out , prom_in , of_idx , wrt_idx ) else : msg = "Unsupported return format '%s." % return_format raise NotImplementedError ( msg ) if self . has_scaling : self . _do_scaling ( totals ) if return_format == 'array' : totals = self . J return totals
Compute derivatives of desired quantities with respect to desired inputs.
Compute derivatives of desired quantities with respect to desired inputs .
"""
        Compute derivatives of desired quantities with respect to desired inputs.

        Uses an approximation method, e.g., fd or cs to calculate the derivatives.

        Parameters
        ----------
        initialize : bool
            Set to True to re-initialize the FD in model. This is only needed when manually
            calling compute_totals on the problem.

        Returns
        -------
        derivs : object
            Derivatives in form requested by 'return_format'.
        """ # Prepare model for calculation by cleaning out the derivatives # vectors. # Solve for derivs with the approximation_scheme. # This cuts out the middleman by grabbing the Jacobian directly after linearization. # Re-initialize so that it is clean. # Linearize Model # change back to array version
self
initialize