(base, n=None, metric=None, coords=None, curv=(None, None), debug=False)
return tuple(Vector.basis)
Generate basis of vector space as tuple of vectors and
        associated metric tensor as Matrix.  See str_array(base,n) for
        usage of base and n and str_array(metric) for usage of metric.

        To overide elements in the default metric use the character '#'
        in the metric string.  For example if one wishes the diagonal
        elements of the metric tensor to be zero enter metric = '0 #,# 0'.

        If the basis vectors are e1 and e2 then the default metric -

            Vector.metric = ((dot(e1,e1),dot(e1,e2)),dot(e2,e1),dot(e2,e2))

        becomes -

            Vector.metric = ((0,dot(e1,e2)),(dot(e2,e1),0)).

        The function dot returns a Symbol and is symmetric.

        The functions 'Bases' calculates the global quantities: -

            Vector.basis
                tuple of basis vectors
            Vector.base_to_index
                dictionary to convert base to base inded
            Vector.metric
                metric tensor represented as a matrix of symbols and numbers
Generate basis of vector space as tuple of vectors and
        associated metric tensor as Matrix.  See str_array(base,n) for
        usage of base and n and str_array(metric) for usage of metric.
Generate basis of vector space as tuple of vectors and associated metric tensor as Matrix . See str_array ( base n ) for usage of base and n and str_array ( metric ) for usage of metric .
def setup(base, n=None, metric=None, coords=None, curv=(None, None), debug=False):
        """
        Generate basis of vector space as tuple of vectors and
        associated metric tensor as Matrix.  See str_array(base,n) for
        usage of base and n and str_array(metric) for usage of metric.

        To overide elements in the default metric use the character '#'
        in the metric string.  For example if one wishes the diagonal
        elements of the metric tensor to be zero enter metric = '0 #,# 0'.

        If the basis vectors are e1 and e2 then the default metric -

            Vector.metric = ((dot(e1,e1),dot(e1,e2)),dot(e2,e1),dot(e2,e2))

        becomes -

            Vector.metric = ((0,dot(e1,e2)),(dot(e2,e1),0)).

        The function dot returns a Symbol and is symmetric.

        The functions 'Bases' calculates the global quantities: -

            Vector.basis
                tuple of basis vectors
            Vector.base_to_index
                dictionary to convert base to base inded
            Vector.metric
                metric tensor represented as a matrix of symbols and numbers

        """
        Vector.is_orthogonal = False
        Vector.coords = coords
        Vector.subscripts = []
        base_name_lst = base.split(' ')

        # Define basis vectors

        if '*' in base:
            base_lst = base.split('*')
            base = base_lst[0]
            Vector.subscripts = base_lst[1].split('|')
            base_name_lst = []
            for subscript in Vector.subscripts:
                base_name_lst.append(base + '_' + subscript)
        else:
            if len(base_name_lst) > 1:
                Vector.subscripts = []
                for base_name in base_name_lst:
                    tmp = base_name.split('_')
                    Vector.subscripts.append(tmp[-1])
            elif len(base_name_lst) == 1 and Vector.coords is not None:
                base_name_lst = []
                for coord in Vector.coords:
                    Vector.subscripts.append(str(coord))
                    base_name_lst.append(base + '_' + str(coord))
            else:
                raise TypeError("'%s' does not define basis vectors" % base)

        basis = []
        base_to_index = {}
        index = 0
        for base_name in base_name_lst:
            basis_vec = Vector(base_name)
            basis.append(basis_vec)
            base_to_index[basis_vec.obj] = index
            index += 1

        Vector.base_to_index = base_to_index
        Vector.basis = tuple(basis)

        # define metric tensor

        default_metric = []
        for bv1 in Vector.basis:
            row = []
            for bv2 in Vector.basis:
                row.append(Vector.basic_dot(bv1, bv2))
            default_metric.append(row)
        Vector.metric = Matrix(default_metric)
        if metric is not None:
            if metric[0] == '[' and metric[-1] == ']':
                Vector.is_orthogonal = True
                metric_str_lst = metric[1:-1].split(',')
                Vector.metric = []
                for g_ii in metric_str_lst:
                    Vector.metric.append(S(g_ii))
                Vector.metric = Matrix(Vector.metric)
            else:
                metric_str_lst = flatten(str_array(metric))
                for index in range(len(metric_str_lst)):
                    if metric_str_lst[index] != '#':
                        Vector.metric[index] = S(metric_str_lst[index])

        Vector.metric_dict = {}  # Used to calculate dot product
        N = range(len(Vector.basis))
        if Vector.is_orthogonal:
            for ii in N:
                    Vector.metric_dict[Vector.basis[ii].obj] = Vector.metric[ii]
        else:
            for irow in N:
                for icol in N:
                    Vector.metric_dict[(Vector.basis[irow].obj, Vector.basis[icol].obj)] = Vector.metric[irow, icol]

        # calculate tangent vectors and metric for curvilinear basis

        if curv != (None, None):
            X = S.Zero
            for (coef, base) in zip(curv[0], Vector.basis):
                X += coef * base.obj
            Vector.tangents = []
            for (coord, norm) in zip(Vector.coords, curv[1]):
                tau = diff(X, coord)
                tau = trigsimp(tau)
                tau /= norm
                tau = expand(tau)
                Vtau = Vector()
                Vtau.obj = tau
                Vector.tangents.append(Vtau)
            metric = []
            for tv1 in Vector.tangents:
                row = []
                for tv2 in Vector.tangents:
                    row.append(tv1 * tv2)
                metric.append(row)
            metric = Matrix(metric)
            metric = metric.applyfunc(TrigSimp)
            Vector.metric_dict = {}
            if metric.is_diagonal:
                Vector.is_orthogonal = True
                tmp_metric = []
                for ii in N:
                    tmp_metric.append(metric[ii, ii])
                    Vector.metric_dict[Vector.basis[ii].obj] = metric[ii, ii]
                Vector.metric = Matrix(tmp_metric)
            else:
                Vector.is_orthogonal = False
                Vector.metric = metric
                for irow in N:
                    for icol in N:
                        Vector.metric_dict[(Vector.basis[irow].obj, Vector.basis[icol].obj)] = Vector.metric[irow, icol]
            Vector.norm = curv[1]

            if debug:
                oprint('Tangent Vectors', Vector.tangents,
                       'Metric', Vector.metric,
                       'Metric Dictionary', Vector.metric_dict,
                       'Normalization', Vector.norm, dict_mode=True)

            # calculate derivatives of tangent vectors

            Vector.dtau_dict = None
            dtau_dict = {}

            for x in Vector.coords:
                for (tau, base) in zip(Vector.tangents, Vector.basis):
                    dtau = tau.diff(x).applyfunc(TrigSimp)
                    result = S.Zero
                    for (t, b) in zip(Vector.tangents, Vector.basis):
                        t_dtau = TrigSimp(t * dtau)
                        result += t_dtau * b.obj
                    dtau_dict[(base.obj, x)] = result

            Vector.dtau_dict = dtau_dict

            if debug:
                oprint('Basis Derivatives', Vector.dtau_dict, dict_mode=True)

        return tuple(Vector.basis)
def setup ( base , n = None , metric = None , coords = None , curv = ( None , None ) , debug = False ) : Vector . is_orthogonal = False Vector . coords = coords Vector . subscripts = [ ] base_name_lst = base . split ( ' ' ) # Define basis vectors if '*' in base : base_lst = base . split ( '*' ) base = base_lst [ 0 ] Vector . subscripts = base_lst [ 1 ] . split ( '|' ) base_name_lst = [ ] for subscript in Vector . subscripts : base_name_lst . append ( base + '_' + subscript ) else : if len ( base_name_lst ) > 1 : Vector . subscripts = [ ] for base_name in base_name_lst : tmp = base_name . split ( '_' ) Vector . subscripts . append ( tmp [ - 1 ] ) elif len ( base_name_lst ) == 1 and Vector . coords is not None : base_name_lst = [ ] for coord in Vector . coords : Vector . subscripts . append ( str ( coord ) ) base_name_lst . append ( base + '_' + str ( coord ) ) else : raise TypeError ( "'%s' does not define basis vectors" % base ) basis = [ ] base_to_index = { } index = 0 for base_name in base_name_lst : basis_vec = Vector ( base_name ) basis . append ( basis_vec ) base_to_index [ basis_vec . obj ] = index index += 1 Vector . base_to_index = base_to_index Vector . basis = tuple ( basis ) # define metric tensor default_metric = [ ] for bv1 in Vector . basis : row = [ ] for bv2 in Vector . basis : row . append ( Vector . basic_dot ( bv1 , bv2 ) ) default_metric . append ( row ) Vector . metric = Matrix ( default_metric ) if metric is not None : if metric [ 0 ] == '[' and metric [ - 1 ] == ']' : Vector . is_orthogonal = True metric_str_lst = metric [ 1 : - 1 ] . split ( ',' ) Vector . metric = [ ] for g_ii in metric_str_lst : Vector . metric . append ( S ( g_ii ) ) Vector . metric = Matrix ( Vector . metric ) else : metric_str_lst = flatten ( str_array ( metric ) ) for index in range ( len ( metric_str_lst ) ) : if metric_str_lst [ index ] != '#' : Vector . metric [ index ] = S ( metric_str_lst [ index ] ) Vector . metric_dict = { } # Used to calculate dot product N = range ( len ( Vector . basis ) ) if Vector . is_orthogonal : for ii in N : Vector . metric_dict [ Vector . basis [ ii ] . obj ] = Vector . metric [ ii ] else : for irow in N : for icol in N : Vector . metric_dict [ ( Vector . basis [ irow ] . obj , Vector . basis [ icol ] . obj ) ] = Vector . metric [ irow , icol ] # calculate tangent vectors and metric for curvilinear basis if curv != ( None , None ) : X = S . Zero for ( coef , base ) in zip ( curv [ 0 ] , Vector . basis ) : X += coef * base . obj Vector . tangents = [ ] for ( coord , norm ) in zip ( Vector . coords , curv [ 1 ] ) : tau = diff ( X , coord ) tau = trigsimp ( tau ) tau /= norm tau = expand ( tau ) Vtau = Vector ( ) Vtau . obj = tau Vector . tangents . append ( Vtau ) metric = [ ] for tv1 in Vector . tangents : row = [ ] for tv2 in Vector . tangents : row . append ( tv1 * tv2 ) metric . append ( row ) metric = Matrix ( metric ) metric = metric . applyfunc ( TrigSimp ) Vector . metric_dict = { } if metric . is_diagonal : Vector . is_orthogonal = True tmp_metric = [ ] for ii in N : tmp_metric . append ( metric [ ii , ii ] ) Vector . metric_dict [ Vector . basis [ ii ] . obj ] = metric [ ii , ii ] Vector . metric = Matrix ( tmp_metric ) else : Vector . is_orthogonal = False Vector . metric = metric for irow in N : for icol in N : Vector . metric_dict [ ( Vector . basis [ irow ] . obj , Vector . basis [ icol ] . obj ) ] = Vector . metric [ irow , icol ] Vector . norm = curv [ 1 ] if debug : oprint ( 'Tangent Vectors' , Vector . tangents , 'Metric' , Vector . metric , 'Metric Dictionary' , Vector . metric_dict , 'Normalization' , Vector . norm , dict_mode = True ) # calculate derivatives of tangent vectors Vector . dtau_dict = None dtau_dict = { } for x in Vector . coords : for ( tau , base ) in zip ( Vector . tangents , Vector . basis ) : dtau = tau . diff ( x ) . applyfunc ( TrigSimp ) result = S . Zero for ( t , b ) in zip ( Vector . tangents , Vector . basis ) : t_dtau = TrigSimp ( t * dtau ) result += t_dtau * b . obj dtau_dict [ ( base . obj , x ) ] = result Vector . dtau_dict = dtau_dict if debug : oprint ( 'Basis Derivatives' , Vector . dtau_dict , dict_mode = True ) return tuple ( Vector . basis )