X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=check%2Fexam_indexed.cpp;h=bbbbf4278f388718b29f580549a81f41fea0a441;hp=11182cb9f3479c051ffa1fa6cb7cf2b5c530f0db;hb=4dc267ddbec7fcc1ba15bf0d60d72a346c9efb26;hpb=ad5dd77c6b19c4c7b8cda7f95584f02c01d17896 diff --git a/check/exam_indexed.cpp b/check/exam_indexed.cpp index 11182cb9..bbbbf427 100644 --- a/check/exam_indexed.cpp +++ b/check/exam_indexed.cpp @@ -44,6 +44,17 @@ static unsigned check_equal_simplify(const ex &e1, const ex &e2) return 0; } +static unsigned check_equal_simplify(const ex &e1, const ex &e2, const scalar_products &sp) +{ + ex e = simplify_indexed(e1, sp) - e2; + if (!e.is_zero()) { + clog << "simplify_indexed(" << e1 << ")-" << e2 << " erroneously returned " + << e << " instead of 0" << endl; + return 1; + } + return 0; +} + static unsigned delta_check(void) { // checks identities of the delta tensor @@ -103,28 +114,85 @@ static unsigned metric_check(void) return result; } +static unsigned epsilon_check(void) +{ + // checks identities of the epsilon tensor + + unsigned result = 0; + + symbol s_mu("mu"), s_nu("nu"), s_rho("rho"), s_sigma("sigma"), s_tau("tau"); + symbol d("d"); + varidx mu(s_mu, 4), nu(s_nu, 4), rho(s_rho, 4), sigma(s_sigma, 4), tau(s_tau, 4); + + // antisymmetry + result += check_equal(lorentz_eps(mu, nu, rho, sigma) + lorentz_eps(sigma, rho, mu, nu), 0); + + // convolution is zero + result += check_equal(lorentz_eps(mu, nu, rho, nu.toggle_variance()), 0); + result += check_equal(lorentz_eps(mu, nu, mu.toggle_variance(), nu.toggle_variance()), 0); + result += check_equal_simplify(lorentz_g(mu.toggle_variance(), nu.toggle_variance()) * lorentz_eps(mu, nu, rho, sigma), 0); + + // contraction with symmetric tensor is zero + result += check_equal_simplify(lorentz_eps(mu, nu, rho, sigma) * indexed(d, indexed::symmetric, mu.toggle_variance(), nu.toggle_variance()), 0); + result += check_equal_simplify(lorentz_eps(mu, nu, rho, sigma) * indexed(d, indexed::symmetric, nu.toggle_variance(), sigma.toggle_variance(), rho.toggle_variance()), 0); + ex e = lorentz_eps(mu, nu, rho, sigma) * indexed(d, indexed::symmetric, mu.toggle_variance(), tau); + result += check_equal_simplify(e, e); + + return result; +} + static unsigned symmetry_check(void) { // check symmetric/antisymmetric objects unsigned result = 0; - symbol s_i("i"), s_j("j"), s_k("k"); - idx i(s_i, 3), j(s_j, 3), k(s_k, 3); - symbol A("A"); - ex e, e1, e2; + idx i(symbol("i"), 3), j(symbol("j"), 3), k(symbol("k"), 3), l(symbol("l"), 3); + symbol A("A"), B("B"); + ex e; result += check_equal(indexed(A, indexed::symmetric, i, j), indexed(A, indexed::symmetric, j, i)); result += check_equal(indexed(A, indexed::antisymmetric, i, j) + indexed(A, indexed::antisymmetric, j, i), 0); result += check_equal(indexed(A, indexed::antisymmetric, i, j, k) - indexed(A, indexed::antisymmetric, j, k, i), 0); + e = indexed(A, indexed::symmetric, i, j, k) * + indexed(B, indexed::antisymmetric, l, k, i); + result += check_equal_simplify(e, 0); + e = indexed(A, indexed::symmetric, i, i, j, j) * + indexed(B, indexed::antisymmetric, k, l); // GiNaC 0.8.0 had a bug here + result += check_equal_simplify(e, e); + + return result; +} + +static unsigned scalar_product_check(void) +{ + // check scalar product replacement + + unsigned result = 0; + + idx i(symbol("i"), 3), j(symbol("j"), 3); + symbol A("A"), B("B"), C("C"); + ex e; + + scalar_products sp; + sp.add(A, B, 0); // A and B are orthogonal + sp.add(A, C, 0); // A and C are orthogonal + sp.add(A, A, 4); // A^2 = 4 (A has length 2) + + e = (indexed(A + B, i) * indexed(A + C, i)).expand(expand_options::expand_indexed); + result += check_equal_simplify(e, indexed(B, i) * indexed(C, i) + 4, sp); + e = indexed(A, i, i) * indexed(B, j, j); // GiNaC 0.8.0 had a bug here + result += check_equal_simplify(e, e, sp); return result; } static unsigned edyn_check(void) { - // relativistic electrodynamics: check transformation laws of electric - // and magnetic fields by applying a Lorentz boost to the field tensor + // Relativistic electrodynamics + + // Test 1: check transformation laws of electric and magnetic fields by + // applying a Lorentz boost to the field tensor unsigned result = 0; @@ -139,23 +207,15 @@ static unsigned edyn_check(void) L.set(0, 1, -beta*gamma); L.set(1, 0, -beta*gamma); L.set(1, 1, gamma); - L.set(2, 2, 1); - L.set(3, 3, 1); + L.set(2, 2, 1); L.set(3, 3, 1); // Electromagnetic field tensor - matrix F(4, 4); - F.set(0, 1, -Ex); - F.set(1, 0, Ex); - F.set(0, 2, -Ey); - F.set(2, 0, Ey); - F.set(0, 3, -Ez); - F.set(3, 0, Ez); - F.set(1, 2, -Bz); - F.set(2, 1, Bz); - F.set(1, 3, By); - F.set(3, 1, -By); - F.set(2, 3, -Bx); - F.set(3, 2, Bx); + matrix F(4, 4, lst( + 0, -Ex, -Ey, -Ez, + Ex, 0, -Bz, By, + Ey, Bz, 0, -Bx, + Ez, -By, Bx // 0 + )); // Indices symbol s_mu("mu"), s_nu("nu"), s_rho("rho"), s_sigma("sigma"); @@ -163,8 +223,8 @@ static unsigned edyn_check(void) // Apply transformation law of second rank tensor ex e = (indexed(L, mu, rho.toggle_variance()) - * indexed(L, nu, sigma.toggle_variance()) - * indexed(F, rho, sigma)).simplify_indexed(); + * indexed(L, nu, sigma.toggle_variance()) + * indexed(F, rho, sigma)).simplify_indexed(); // Extract transformed electric and magnetic fields ex Ex_p = e.subs(lst(mu == 1, nu == 0)).normal(); @@ -182,6 +242,68 @@ static unsigned edyn_check(void) result += check_equal(By_p, gamma * (By + beta * Ez)); result += check_equal(Bz_p, gamma * (Bz - beta * Ey)); + // Test 2: check energy density and Poynting vector of electromagnetic field + + // Minkowski metric + ex eta = diag_matrix(lst(1, -1, -1, -1)); + + // Covariant field tensor + ex F_mu_nu = (indexed(eta, mu.toggle_variance(), rho.toggle_variance()) + * indexed(eta, nu.toggle_variance(), sigma.toggle_variance()) + * indexed(F, rho, sigma)).simplify_indexed(); + + // Energy-momentum tensor + ex T = (-indexed(eta, rho, sigma) * F_mu_nu.subs(s_nu == s_rho) + * F_mu_nu.subs(lst(s_mu == s_nu, s_nu == s_sigma)) + + indexed(eta, mu.toggle_variance(), nu.toggle_variance()) + * F_mu_nu.subs(lst(s_mu == s_rho, s_nu == s_sigma)) + * indexed(F, rho, sigma) / 4).simplify_indexed() / (4 * Pi); + + // Extract energy density and Poynting vector + ex E = T.subs(lst(s_mu == 0, s_nu == 0)).normal(); + ex Px = T.subs(lst(s_mu == 0, s_nu == 1)); + ex Py = T.subs(lst(s_mu == 0, s_nu == 2)); + ex Pz = T.subs(lst(s_mu == 0, s_nu == 3)); + + // Check results + result += check_equal(E, (Ex*Ex+Ey*Ey+Ez*Ez+Bx*Bx+By*By+Bz*Bz) / (8 * Pi)); + result += check_equal(Px, (Ez*By-Ey*Bz) / (4 * Pi)); + result += check_equal(Py, (Ex*Bz-Ez*Bx) / (4 * Pi)); + result += check_equal(Pz, (Ey*Bx-Ex*By) / (4 * Pi)); + + return result; +} + +static unsigned spinor_check(void) +{ + // check identities of the spinor metric + + unsigned result = 0; + + symbol psi("psi"); + spinidx A(symbol("A"), 2), B(symbol("B"), 2), C(symbol("C"), 2); + ex A_co = A.toggle_variance(), B_co = B.toggle_variance(); + ex e; + + e = spinor_metric(A_co, B_co) * spinor_metric(A, B); + result += check_equal_simplify(e, 2); + e = spinor_metric(A_co, B_co) * spinor_metric(B, A); + result += check_equal_simplify(e, -2); + e = spinor_metric(A_co, B_co) * spinor_metric(A, C); + result += check_equal_simplify(e, delta_tensor(B_co, C)); + e = spinor_metric(A_co, B_co) * spinor_metric(B, C); + result += check_equal_simplify(e, -delta_tensor(A_co, C)); + e = spinor_metric(A_co, B_co) * spinor_metric(C, A); + result += check_equal_simplify(e, -delta_tensor(B_co, C)); + e = spinor_metric(A, B) * indexed(psi, B_co); + result += check_equal_simplify(e, indexed(psi, A)); + e = spinor_metric(A, B) * indexed(psi, A_co); + result += check_equal_simplify(e, -indexed(psi, B)); + e = spinor_metric(A_co, B_co) * indexed(psi, B); + result += check_equal_simplify(e, -indexed(psi, A_co)); + e = spinor_metric(A_co, B_co) * indexed(psi, A); + result += check_equal_simplify(e, indexed(psi, B_co)); + return result; } @@ -194,8 +316,11 @@ unsigned exam_indexed(void) result += delta_check(); cout << '.' << flush; result += metric_check(); cout << '.' << flush; + result += epsilon_check(); cout << '.' << flush; result += symmetry_check(); cout << '.' << flush; + result += scalar_product_check(); cout << '.' << flush; result += edyn_check(); cout << '.' << flush; + result += spinor_check(); cout << '.' << flush; if (!result) { cout << " passed " << endl;