Пример #1
0
    def init_S2(self):
        """Initialize the metric on the 2-sphere, S2. 
        """
        theta = sp.symbols(self.S2[0])
        phi = sp.symbols(self.S2[1])
        g = Metric(index_dict=self.S2)
        g.convert_to_shorthand()
        g.elements['thetatheta'] = 1
        g.elements['phiphi'] = (sp.sin(theta))**2

        return g
Пример #2
0
    def init_kerr(self):
        """Initialize the Kerr metric on 4D spacetime.
        """

        t = sp.symbols(self.KERR[0])
        r = sp.symbols(self.KERR[1])
        theta = sp.symbols(self.KERR[2])
        phi = sp.symbols(self.KERR[3])
        G = sp.symbols('G')
        M = sp.symbols('M')
        rho = sp.symbols('rho')
        a = sp.symbols('a')
        Delta = sp.symbols('Delta')
        """
        Notes:
        ------
        a = J/M where J is the Komar angular momentum (see 6.48 
        in Carroll). 
        """

        Delta_expr = r**2 - 2 * G * M * r + a**2
        rho2_expr = r**2 + a**2 * (sp.cos(theta))**2

        g = Metric(index_dict=self.KERR)
        g.convert_to_shorthand()

        g.elements['tt'] = -(1 - 2 * G * M * r / rho**2)
        g.elements['tt'] = g.elements['tt'].subs(rho**2, rho2_expr)

        g.elements['tphi'] = -2 * G * M * a * r * (sp.sin(theta))**2 / rho**2
        g.elements['tphi'] = g.elements['tphi'].subs(rho**2, rho2_expr)
        g.elements['phit'] = g.elements['tphi']

        g.elements['rr'] = rho**2 / Delta
        g.elements['rr'] = g.elements['rr'].subs(rho**2, rho2_expr)
        g.elements['rr'] = g.elements['rr'].subs(Delta, Delta_expr)

        g.elements['thetatheta'] = rho**2
        g.elements['thetatheta'] = g.elements['thetatheta'].subs(
            rho**2, rho2_expr)

        g.elements['phiphi'] = ((sp.sin(theta))**2 / rho**2) * (
            (r**2 + a**2)**2 - a**2 * Delta * (sp.sin(theta))**2)
        g.elements['phiphi'] = g.elements['phiphi'].subs(rho**2, rho2_expr)
        g.elements['phiphi'] = g.elements['phiphi'].subs(Delta, Delta_expr)

        return g
Пример #3
0
    def init_deSitter(self):
        """Initialize the metric on 4D de Sitter spacetime.
        """
        t = sp.symbols(self.DESITTER[0])
        x = sp.symbols(self.DESITTER[1])
        y = sp.symbols(self.DESITTER[2])
        z = sp.symbols(self.DESITTER[3])
        H = sp.symbols('H')

        g = Metric(index_dict=self.DESITTER)
        g.convert_to_shorthand()
        g.elements['tt'] = -1
        g.elements['xx'] = sp.exp(2 * H * t)
        g.elements['yy'] = g.elements['xx']
        g.elements['zz'] = g.elements['xx']

        return g
Пример #4
0
    def init_schwarzchild(self):
        """Initialize Schwarzchild metric.
        """
        t = sp.symbols(self.SCHWARZCHILD[0])
        r = sp.symbols(self.SCHWARZCHILD[1])
        theta = sp.symbols(self.SCHWARZCHILD[2])
        phi = sp.symbols(self.SCHWARZCHILD[3])
        R = sp.symbols('R')

        g = Metric(index_dict=self.SCHWARZCHILD)
        g.convert_to_shorthand()
        g.elements['tt'] = 1 - R / r
        g.elements['rr'] = (1 - R / r)**(-1)
        g.elements['thetatheta'] = r**2
        g.elements['phiphi'] = r**2 * (sp.sin(theta))**2

        return g
Пример #5
0
    def init_schwarzchild_func(self):
        """Initialize Schwarzchild metric
        but the variables are now functions 
        of a parameter.
        """
        t = sp.Function(self.SCHWARZCHILD[0])
        r = sp.Function(self.SCHWARZCHILD[1])
        theta = sp.Function(self.SCHWARZCHILD[2])
        phi = sp.Function(self.SCHWARZCHILD[3])
        R = sp.symbols('R')
        y = sp.symbols('y')

        g = Metric(index_dict=self.SCHWARZCHILD)
        g.convert_to_shorthand()
        g.elements['tt'] = 1 - R * r(y)**(-1)
        g.elements['rr'] = (1 - R * r(y)**(-1))**(-1)
        g.elements['thetatheta'] = r(y)**2
        g.elements['phiphi'] = r(y)**2 * (sp.sin(theta(y)))**2

        return g
Пример #6
0
    def init_FRW(self):
        """Initialize the FRW metric on 4D spacetime.
        """

        t = sp.symbols('t')
        r = sp.symbols('r')
        kappa = sp.symbols('k')
        theta = sp.symbols('theta')
        phi = sp.symbols('phi')
        a = sp.Function('a')

        g = Metric(index_dict=self.FRW)
        g.convert_to_shorthand()

        g.elements['tt'] = -1
        g.elements['rr'] = a(t)**2 / (1 - kappa * r**2)
        g.elements['thetatheta'] = a(t)**2 * r**2
        g.elements['phiphi'] = a(t)**2 * r**2 * sp.sin(theta)**2

        return g
Пример #7
0
    def read_in_symbol_from_file(self, file_with_path, complex_symbol,
                                 symbol_type):
        from sympy.parsing.sympy_parser import parse_expr
        """Read a text file that contains a string version 
        of a complex symbol and return a complex symbol 
        with the entries that were stored in the text file. 
        Assumes that the text file has been created with 
        ``self.write_complex_symbol()``; i.e. this function
        is not fit for reading arbitrary text files. 
        """

        index_list = []
        if symbol_type == 'metric':
            constructed_symbol = Metric(index_dict=complex_symbol.index_dict)
        elif symbol_type == 'christoffel':
            constructed_symbol = Christoffel(
                index_dict=complex_symbol.index_dict)
        elif symbol_type == 'riemann':
            constructed_symbol = Riemann(index_dict=complex_symbol.index_dict)
        elif symbol_type == 'ricci':
            constructed_symbol = Ricci(index_dict=complex_symbol.index_dict)
        elif symbol_type == 'einstein':
            constructed_symbol = Einstein(index_dict=complex_symbol.index_dict)
        else:
            raise TypeError(
                'Got a bad symbol type when trying to read in a symbol from a text file.'
            )

        constructed_symbol.convert_to_shorthand()

        with open(file_with_path, 'r') as text_file:
            text = text_file.read()
            for key in complex_symbol.elements:
                index_list.append(key)
            l = len(index_list)
            #print('Here is the index list: {list}.'.format(list=index_list))
            for i in range(l):
                s = '[{ss}]'.format(ss=index_list[i])
                #print('Searching for the end of {s}...'.format(s=s))
                start = text.find(s) + len(s)  # start of the symbolic string
                #print('Found the end of {s} at {loc}.'.format(s=s, loc=start))
                if i + 1 < l:
                    t = '[{tt}]'.format(tt=index_list[i + 1])
                    #print('Searching for {t}...'.format(t=t))
                    end = text.find(t)
                    #print('Found {t} at {loc}.'.format(t=t, loc=end))
                    symbol_string = text[start:end]
                    #print('Here is the symbol we found:\n')
                    #print('\t' + symbol_string)
                    output_symbol = parse_expr(symbol_string, evaluate=False)
                else:
                    # handle the last symbol, which won't be followed
                    # by another ['xx'] flag...
                    symbol_string = text[start:]  # go to end of the string!
                    #print('Here is the symbol we found:\n')
                    #print('\t' + symbol_string)
                    output_symbol = parse_expr(symbol_string, evaluate=False)
                #print('Adding the following symbol to [{key}]:'.format(key=index_list[i]))
                constructed_symbol.elements[index_list[i]] = output_symbol
                #print(constructed_symbol.elements[index_list[i]])

            return constructed_symbol