Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hello , i need help #41

Closed
XDongiang opened this issue Nov 18, 2019 · 4 comments
Closed

hello , i need help #41

XDongiang opened this issue Nov 18, 2019 · 4 comments
Labels

Comments

@XDongiang
Copy link

XDongiang commented Nov 18, 2019

when i write my code i meet a problem it puzzled me
the function is :
Screenshot_20191118_203330

// definition of G_{mu,nu}
Tensor<double, 4, 4> metric()
{
    Tensor<double, 4, 4> G = {{-1., 0., 0., 0.},
                              {0., -1., 0., 0.},
                              {0., 0., -1., 0.},
                              {0., 0., 0., 1.}};
    return G;
}
Tensor<double, 4> phif222(const Tensor<double, 4>& psi2s,
                          const Tensor<double, 4>& phi,
                          const Tensor<double, 4>& f2,
                          const Tensor<double, 4>& kp,
                          const Tensor<double, 4>& km,
                          const Tensor<double, 4>& pip,
                          const Tensor<double, 4>& pim)
{
    enum { mu, a, b, r, delta, sigma, nu, lamda };
    Tensor<double, 4, 4, 4, 4> leci = leci_four();
    Tensor<double, 4, 4>       G    = metric();
    Tensor<double, 4, 4, 4, 4> leci_1 =
        einsum<Index<mu, a, b, r>, Index<mu, nu>>(leci, G);
    Tensor<double, 4, 4, 4, 4> leci_2 =
        einsum<Index<mu, a, b, r>, Index<a, nu>>(leci_1, G);
    Tensor<double, 4, 4, 4, 4> leci_3 =
        einsum<Index<mu, a, b, r>, Index<b, nu>>(leci_2, G);
    Tensor<double, 4, 4, 4, 4> leci_4 =
        einsum<Index<mu, a, b, r>, Index<r, nu>>(leci_3, G);
    ////////////////////// T^{(2)}
    Tensor<double, 4, 4> T2  = TT2(psi2s, phi, f2);
    Tensor<double, 4, 4> T2_ = einsum<Index<mu, nu>, Index<nu, delta>>(T2, G);
    ////////////////////// t^{(2)}
    Tensor<double, 4, 4> t2  = TT2(f2, pip, pim);
    Tensor<double, 4, 4> t2_ = einsum<Index<mu, nu>, Index<nu, delta>>(t2, G);
    ////////////////////// t^{(1)}
    Tensor<double, 4> t1  = TT1(phi, kp, km);
    Tensor<double, 4> t1_ = einsum<Index<nu>, Index<nu, mu>>(t1, G);
    ////////////////////// p_{psi}_alph
    Tensor<double, 4> psi2s_ = einsum<Index<mu>, Index<mu, nu>>(psi2s, G);
    ////////////////////////////////////////////////////////////////////
    auto first_1 = einsum<Index<mu, a, b, r>, Index<a>>(leci_4, psi2s_);
    auto first_2 = einsum<Index<mu, b, r>, Index<a, b>>(first_1, T2_);
    auto second_1 =
        einsum<Index<mu, delta, r>, Index<r, lamda, sigma, nu>>(first_1, leci);
    auto second_2 = einsum<Index<mu, delta, r>, Index<delta, lamda, sigma, nu>>(
        first_1, leci);
    auto third_1 =
        einsum<Index<mu, delta, lamda, sigma, nu>, Index<lamda, delta>>(
            second_1, t2_);
    auto third_2 =
        einsum<Index<mu, r, lamda, sigma, nu>, Index<lamda, r>>(second_2, t2_);
    Tensor<double, 4, 4, 4> add = third_1 + third_2;
    print(add);
    auto result  = einsum<Index<mu, sigma, nu>, Index<sigma>>(add, psi2s);
    auto result_ = einsum<Index<mu, nu>, Index<nu>>(result, t1_);
    return result_;
}

it is my code , i do not konw how to write the function use einsum , do i right in up code ?
can you help me , how to write so many term to einsum

@XDongiang
Copy link
Author

XDongiang commented Nov 18, 2019

and the leci_four is

// definition of epsilon_{mu,nu}, the whole anti-symmetric tensor
Tensor<double, 4, 4, 4, 4> leci_four()
{
    Tensor<double, 4, 4, 4, 4> leci;
    leci.zeros();
    leci(0, 1, 2, 3) = 1.;
    leci(0, 1, 3, 2) = -1.;
    leci(0, 3, 1, 2) = 1.;
    leci(3, 0, 1, 2) = -1.;
    leci(3, 0, 2, 1) = 1.;
    leci(0, 3, 2, 1) = -1.;
    leci(0, 2, 3, 1) = 1.;
    leci(0, 2, 1, 3) = -1.;
    leci(2, 0, 1, 3) = 1.;
    leci(2, 0, 3, 1) = -1.;
    leci(2, 3, 0, 1) = 1.;
    leci(3, 2, 0, 1) = -1.;
    leci(3, 2, 1, 0) = 1.;
    leci(2, 3, 1, 0) = -1.;
    leci(2, 1, 3, 0) = 1.;
    leci(2, 1, 0, 3) = -1.;
    leci(1, 2, 0, 3) = 1.;
    leci(1, 2, 3, 0) = -1.;
    leci(1, 3, 2, 0) = 1.;
    leci(3, 1, 2, 0) = -1.;
    leci(3, 1, 0, 2) = 1.;
    leci(1, 3, 0, 2) = -1.;
    leci(1, 0, 3, 2) = 1.;
    leci(1, 0, 2, 3) = -1.;
    return leci;
}

i think it may have symmetry

@romeric
Copy link
Owner

romeric commented Nov 19, 2019

What are the functions TT1 and TT2 and how does your main function that calls the function phif222 look like?

And what is the problem exactly? Does it not compile, or does it crash or do you get incorrect results?

@XDongiang
Copy link
Author

sorry , my exactly question is : how to use einsum to calculate the function
Screenshot_20191118_203330
how to determine the index order ? and

@XDongiang
Copy link
Author

i have solve my problem . and i thank if can determin the index of output , it will more easy to use the einsum . now i must to control the order of input to control the index of output .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants