Example #1
0
    def get_inverse_metric_tensor(self, input_vectors=None):
        G = self.get_metric_tensor().tensor()
        G_ = MetricTensor(sympy.Matrix(G).inv().as_immutable(), self.model.input_vars)

        if input_vectors is not None:            
            G_ = self.model.apply(G_.tensor(), input_vectors)
        
        return G_
Example #2
0
 def get_metric_tensor(self, input_vectors=None):
     J = self.get_jacobian()
     me = (J.T*J)
     me.simplify()
     me = MetricTensor(me.as_immutable(), self.model.input_vars)
     
     if input_vectors is not None:            
         me = self.model.apply(me.tensor(), input_vectors)
     
     return me
Example #3
0
def test_weyl_dim3():
    list_metric = np.ones((3, 3), dtype=int).tolist()
    symbolstr = "t r theta"
    syms = sympy.symbols(symbolstr)
    metric = MetricTensor(list_metric, syms)
    obj = WeylTensor.from_metric(metric).arr
    assert obj == sympy.Array(np.zeros((3, 3), dtype=int))
Example #4
0
def test_check_ValueError_on_incorrect_config_length():
    sch = schwarzschild_metric()
    try:
        sch_new = MetricTensor(sch.tensor(), sch.syms, config="lll")
        assert False
    except ValueError:
        assert True
Example #5
0
def test_TypeError():
    list2d = np.zeros((4, 4), dtype=int).tolist()
    syms = 100
    try:
        obj = MetricTensor(list2d, syms)
        assert False
    except TypeError:
        assert True
Example #6
0
def spherical_metric():
    symbolstr = "r theta phi"
    syms = sympy.symbols(symbolstr)
    list2d = (np.zeros(shape=(3, 3), dtype=int)).tolist()
    list2d[0][0] = 1
    list2d[1][1] = syms[0]**2
    list2d[2][2] = (syms[0]**2) * (sympy.sin(syms[1])**2)
    metric = MetricTensor(list2d, syms)
    return metric
Example #7
0
def euclidean_space_metric():
    symbolstr = "e1 e2"  # let angle between e1 & e2 be theta
    syms = symbols(symbolstr)
    th = symbols("theta")
    list2d = np.zeros((2, 2), dtype=int).tolist()
    # defining the metric tensor when axis are not orthogonal
    list2d[0][0] = list2d[1][1] = 1
    list2d[1][0] = list2d[0][1] = cos(th)
    metric = MetricTensor(list2d, syms, config="ll")
    return metric
Example #8
0
def test_Schouten_dim2():
    list_metric = np.zeros((2, 2), dtype=int).tolist()
    symbolstr = "t r"
    syms = sympy.symbols(symbolstr)
    metric = MetricTensor(list_metric, syms)
    try:
        obj = SchoutenTensor.from_metric(metric)
        assert False
    except ValueError:
        assert True
Example #9
0
def anti_de_sitter_metric():
    coords = sympy.symbols("t chi theta phi")
    t, ch, th, ph = coords
    m = sympy.diag(
        -1,
        cos(t) ** 2,
        cos(t) ** 2 * sinh(ch) ** 2,
        cos(t) ** 2 * sinh(ch) ** 2 * sin(th) ** 2,
    ).tolist()
    metric = MetricTensor(m, coords)
    return metric
Example #10
0
def test_weyl_conformal_rescaling():
    # https://en.wikipedia.org/wiki/Weyl_tensor#Conformal_rescaling
    a = sympy.symbols("a")
    mw1 = anti_de_sitter_metric()
    mw2 = MetricTensor(a * mw1.tensor(), mw1.symbols(), mw1.config)
    w1 = WeylTensor.from_metric(mw1).change_config("ulll")
    w2 = WeylTensor.from_metric(mw2).change_config("ulll")
    cmp_arr = sympy.Array(np.zeros(shape=w1.tensor().shape, dtype=int))
    assert simplify_sympy_array(w1.tensor() - w2.tensor()) == cmp_arr
    assert w1.syms == w1.symbols()
    assert w1.parent_metric == w1._parent_metric
Example #11
0
def schwarzschild_metric():
    symbolstr = "t r theta phi"
    syms = sympy.symbols(symbolstr)
    G, M, c, a = sympy.symbols("G M c a")
    # using metric values of schwarschild space-time
    # a is schwarzschild radius
    list2d = np.zeros((4, 4), dtype=int).tolist()
    list2d[0][0] = 1 - (a / syms[1])
    list2d[1][1] = -1 / ((1 - (a / syms[1])) * (c ** 2))
    list2d[2][2] = -1 * (syms[1] ** 2) / (c ** 2)
    list2d[3][3] = -1 * (syms[1] ** 2) * (sympy.sin(syms[2]) ** 2) / (c ** 2)
    sch = MetricTensor(list2d, syms)
    return sch
def test_change_config():
    x, y, z = sympy.symbols("x y z")

    list3d = np.zeros((3, 3, 3), dtype=int).tolist()
    for i in range(3):
        list3d[i][i][i] = (x**i) * (y * (2 - i)) + i * z
    list3d[1][2][0] = list3d[1][0][2] = x * y * z
    list3d[2][1][0] = list3d[2][0][1] = 4 * y

    metriclist = np.identity(3).tolist()
    metric = MetricTensor(metriclist, (x, y, z), "uu")
    ch = ChristoffelSymbols(list3d, (x, y, z), "ull", parent_metric=metric)
    chr_new = ch.change_config("llu")

    for t in range(3):
        i, j, k = t % 3, (int(t / 3)) % 3, (int(t / (3**2))) % 3
        assert sympy.simplify(ch[i, j, k] - chr_new[i, j, k]) == 0
Example #13
0
 def metric_tensor(self):
     from einsteinpy.symbolic import MetricTensor
     E, F, G = self.E_F_G
     return MetricTensor([[E, F], [F, G]], self.syms, config='ll')
Example #14
0
    print(s + latex(Tel) + '\\\\')


#Define as coordenadas
t, r, theta, phi = symbols('t r theta phi')
nu = Function('nu', real=True)(t, r)
lamb = Function('lambda', real=True)(t, r)

#Define a métrica
metric = [[0 for i in range(4)] for i in range(4)]
metric[0][0] = exp(nu)
metric[1][1] = -exp(lamb)
metric[2][2] = -r**2
metric[3][3] = -r**2 * sin(theta)**2

g = MetricTensor(metric, (t, r, theta, phi))
gup = g.change_config('uu')
#Calcula o tensor de Riemann, tensor Ricci, escalar de Ricci
#e tensor de einstein
rm = RiemannCurvatureTensor.from_metric(g)
rm = rm.change_config('llll')  #Deixa covariante

ric = RicciTensor.from_metric(g)

#---------------Escrevendo os termos não nulos independentes de Riemann-----
non_zero = []
for i, el in enumerate(rm.tensor()):
    if el != 0:  #Salva só os termos não nulos
        e = simplify(el)
        a = str(int(i / 64))
        b = str(int((i % 64) / 16))