openmdao/core/group.py
def _compute_root_scale_factors(self):
        """
        Compute scale factors for all variables.

        Returns
        -------
        dict
            Mapping of each absolute var name to its corresponding scaling factor tuple.
        """
        scale_factors = super(Group, self)._compute_root_scale_factors()

        if self._has_input_scaling:
            abs2meta_in = self._var_abs2meta
            allprocs_meta_out = self._var_allprocs_abs2meta
            for abs_in, abs_out in iteritems(self._conn_global_abs_in2out):
                meta_out = allprocs_meta_out[abs_out]
                if abs_in not in abs2meta_in:
                    # we only perform scaling on local arrays, so skip
                    continue

                meta_in = abs2meta_in[abs_in]

                ref = meta_out['ref']
                ref0 = meta_out['ref0']

                src_indices = meta_in['src_indices']

                if src_indices is not None:
                    if not (np.isscalar(ref) and np.isscalar(ref0)):
                        # TODO: if either ref or ref0 are not scalar and the output is
                        # distributed, we need to do a scatter
                        # to obtain the values needed due to global src_indices
                        if meta_out['distributed']:
                            raise RuntimeError("vector scalers with distrib vars "
                                               "not supported yet.")

                        global_shape_out = meta_out['global_shape']
                        if src_indices.ndim != 1:
                            shape_in = meta_in['shape']
                            if len(meta_out['shape']) == 1 or shape_in == src_indices.shape:
                                src_indices = src_indices.flatten()
                                src_indices = convert_neg(src_indices, src_indices.size)
                            else:
                                entries = [list(range(x)) for x in shape_in]
                                cols = np.vstack(src_indices[i] for i in product(*entries))
                                dimidxs = [convert_neg(cols[:, i], global_shape_out[i])
                                           for i in range(cols.shape[1])]
                                src_indices = np.ravel_multi_index(dimidxs, global_shape_out)

                        ref = ref[src_indices]
                        ref0 = ref0[src_indices]

                # Compute scaling arrays for inputs using a0 and a1
                # Example:
                #   Let x, x_src, x_tgt be the dimensionless variable,
                #   variable in source units, and variable in target units, resp.
                #   x_src = a0 + a1 x
                #   x_tgt = b0 + b1 x
                #   x_tgt = g(x_src) = d0 + d1 x_src
                #   b0 + b1 x = d0 + d1 a0 + d1 a1 x
                #   b0 = d0 + d1 a0
                #   b0 = g(a0)
                #   b1 = d0 + d1 a1 - d0
                #   b1 = g(a1) - g(0)

                units_in = meta_in['units']
                units_out = meta_out['units']

                if units_in is None or units_out is None or units_in == units_out:
                    a0 = ref0
                    a1 = ref - ref0
                else:
                    factor, offset = get_conversion(units_out, units_in)
                    a0 = (ref0 + offset) * factor
                    a1 = (ref - ref0) * factor

                scale_factors[abs_in] = {
                    ('input', 'phys'): (a0, a1),
                    ('input', 'norm'): (-a0 / a1, 1.0 / a1)
                }

        return scale_factors

        Compute scale factors for all variables.

        Returns
        -------
        dict
            Mapping of each absolute var name to its corresponding scaling factor tuple.
        
Compute scale factors for all variables.
Returns

dict
Mapping of each absolute var name to its corresponding scaling factor tuple.
Compute scale factors for all variables . Returns dict Mapping of each absolute var name to its corresponding scaling factor tuple .
def _compute_root_scale_factors(self):
        scale_factors = super(Group, self)._compute_root_scale_factors()
        if self._has_input_scaling:
            abs2meta_in = self._var_abs2meta
            allprocs_meta_out = self._var_allprocs_abs2meta
            for abs_in, abs_out in iteritems(self._conn_global_abs_in2out):
                meta_out = allprocs_meta_out[abs_out]
                if abs_in not in abs2meta_in:
                    continue
                meta_in = abs2meta_in[abs_in]
                ref = meta_out['ref']
                ref0 = meta_out['ref0']
                src_indices = meta_in['src_indices']
                if src_indices is not None:
                    if not (np.isscalar(ref) and np.isscalar(ref0)):
                        if meta_out['distributed']:
                            raise RuntimeError("vector scalers with distrib vars "
                                               "not supported yet.")
                        global_shape_out = meta_out['global_shape']
                        if src_indices.ndim != 1:
                            shape_in = meta_in['shape']
                            if len(meta_out['shape']) == 1 or shape_in == src_indices.shape:
                                src_indices = src_indices.flatten()
                                src_indices = convert_neg(src_indices, src_indices.size)
                            else:
                                entries = [list(range(x)) for x in shape_in]
                                cols = np.vstack(src_indices[i] for i in product(*entries))
                                dimidxs = [convert_neg(cols[:, i], global_shape_out[i])
                                           for i in range(cols.shape[1])]
                                src_indices = np.ravel_multi_index(dimidxs, global_shape_out)
                        ref = ref[src_indices]
                        ref0 = ref0[src_indices]
                units_in = meta_in['units']
                units_out = meta_out['units']
                if units_in is None or units_out is None or units_in == units_out:
                    a0 = ref0
                    a1 = ref - ref0
                else:
                    factor, offset = get_conversion(units_out, units_in)
                    a0 = (ref0 + offset) * factor
                    a1 = (ref - ref0) * factor
                scale_factors[abs_in] = {
                    ('input', 'phys'): (a0, a1),
                    ('input', 'norm'): (-a0 / a1, 1.0 / a1)
                }
        return scale_factors
def _compute_root_scale_factors ( self ) : scale_factors = super ( Group , self ) . _compute_root_scale_factors ( ) if self . _has_input_scaling : abs2meta_in = self . _var_abs2meta allprocs_meta_out = self . _var_allprocs_abs2meta for abs_in , abs_out in iteritems ( self . _conn_global_abs_in2out ) : meta_out = allprocs_meta_out [ abs_out ] if abs_in not in abs2meta_in : continue meta_in = abs2meta_in [ abs_in ] ref = meta_out [ 'ref' ] ref0 = meta_out [ 'ref0' ] src_indices = meta_in [ 'src_indices' ] if src_indices is not None : if not ( np . isscalar ( ref ) and np . isscalar ( ref0 ) ) : if meta_out [ 'distributed' ] : raise RuntimeError ( "vector scalers with distrib vars " "not supported yet." ) global_shape_out = meta_out [ 'global_shape' ] if src_indices . ndim != 1 : shape_in = meta_in [ 'shape' ] if len ( meta_out [ 'shape' ] ) == 1 or shape_in == src_indices . shape : src_indices = src_indices . flatten ( ) src_indices = convert_neg ( src_indices , src_indices . size ) else : entries = [ list ( range ( x ) ) for x in shape_in ] cols = np . vstack ( src_indices [ i ] for i in product ( * entries ) ) dimidxs = [ convert_neg ( cols [ : , i ] , global_shape_out [ i ] ) for i in range ( cols . shape [ 1 ] ) ] src_indices = np . ravel_multi_index ( dimidxs , global_shape_out ) ref = ref [ src_indices ] ref0 = ref0 [ src_indices ] units_in = meta_in [ 'units' ] units_out = meta_out [ 'units' ] if units_in is None or units_out is None or units_in == units_out : a0 = ref0 a1 = ref - ref0 else : factor , offset = get_conversion ( units_out , units_in ) a0 = ( ref0 + offset ) * factor a1 = ( ref - ref0 ) * factor scale_factors [ abs_in ] = { ( 'input' , 'phys' ) : ( a0 , a1 ) , ( 'input' , 'norm' ) : ( - a0 / a1 , 1.0 / a1 ) } return scale_factors
Compute scale factors for all variables.
Compute scale factors for all variables .
"""
        Compute scale factors for all variables.

        Returns
        -------
        dict
            Mapping of each absolute var name to its corresponding scaling factor tuple.
        """ # we only perform scaling on local arrays, so skip # TODO: if either ref or ref0 are not scalar and the output is # distributed, we need to do a scatter # to obtain the values needed due to global src_indices # Compute scaling arrays for inputs using a0 and a1 # Example: #   Let x, x_src, x_tgt be the dimensionless variable, #   variable in source units, and variable in target units, resp. #   x_src = a0 + a1 x #   x_tgt = b0 + b1 x #   x_tgt = g(x_src) = d0 + d1 x_src #   b0 + b1 x = d0 + d1 a0 + d1 a1 x #   b0 = d0 + d1 a0 #   b0 = g(a0) #   b1 = d0 + d1 a1 - d0 #   b1 = g(a1) - g(0)
self