]> www.ginac.de Git - ginac.git/blob - check/lortensor_check.cpp
- Renamed flag NO_GINAC_NAMESPACE to NO_NAMESPACE_GINAC because of m4.
[ginac.git] / check / lortensor_check.cpp
1 /** @file lortensor_check.cpp
2  *
3  *  Here we test manipulations on GiNaC's lortensors. */
4
5 /*
6  *  GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 #include <stdexcept>
24 #include <ginac/ginac.h>
25
26 #ifndef NO_NAMESPACE_GINAC
27 using namespace GiNaC;
28 #endif // ndef NO_NAMESPACE_GINAC
29
30 static unsigned lortensor_check1(void)
31 {
32     // checks simple identities of the metric tensor!
33     
34     unsigned result = 0;
35     lorentzidx mu("mu"), nu("nu");
36     ex e1, e2, e3, e4, e5, e6;
37     e1 = lortensor_g(mu,nu);
38     e2 = lortensor_g(nu,mu);
39     e3 = e1 - e2; // g(~mu,~nu) - g(~nu,~mu) = 0 !
40     e4 = lortensor_g(mu,mu.toggle_covariant());
41     e5 = lortensor_g(mu.toggle_covariant(),mu);
42     e6 = e4 - e5; // g(~mu,_mu) - g(_mu,~mu) = 0!
43     if (!e3.is_zero()) {
44         clog << e1 << "-" << e2 << " erroneously returned "
45              << e3 << " instead of 0" << endl;
46         ++result;
47     }
48     if (!e6.is_zero()) {
49         clog << e4 << "-" << e5 << " erroneously returned "
50              << e6 << " instead of 0" << endl;
51         ++result;
52     }
53
54     return result;
55 }
56
57 static unsigned lortensor_check2(void)
58 {
59     // checks simple contraction properties of an arbitrary (symmetric!) rankn lortensor!
60     
61     unsigned result = 0;
62     lorentzidx mu("mu"), nu("nu"), rho("rho");
63     ex e1, e2, e3, e4, e5, e6, e7, e8, e9, e10;
64     e1 = lortensor_g(mu,nu);
65     e2 = lortensor_g(nu,mu);
66     e3 = lortensor_rank1("p",mu.toggle_covariant());
67     e4 = lortensor_rank1("p",nu);
68     e5 = e3 * e1 - e3 * e2; // p_mu g(~mu,~nu) - p_mu g(~nu,~mu) = 0!
69     e6 = simplify_lortensor(e3 * e1) - e4; // p~nu - p~nu = 0!
70     e7 = lortensor_g(nu,rho);
71     e8 = lortensor_rank2("F",mu.toggle_covariant(),nu.toggle_covariant());
72     e9 = lortensor_rank2("F",mu.toggle_covariant(),rho);
73     e10 = simplify_lortensor(e8 * e7) - e9; // F(_mu,_nu) g(~nu,~rho) - F(_mu,~rho) = 0!
74     if (!e5.is_zero()) {
75         clog << e3 << "*" << e1 << "-" << e3 << "*" << e2 << " erroneously returned "
76              << e5 << " instead of 0" << endl;
77         ++result;
78     }
79     if (!e6.is_zero()) {    
80         clog << " simplify_lortensor(e3 * e1)" << "-" << e4 << " erroneously returned"
81              << e6 << " instead of 0" << endl;
82         ++result;
83     }
84     if (!e10.is_zero()) {        
85         clog << " simplify_lortensor(e8 * e7)" << "-" << e9 << " erroneously returned"
86              << e10 << " instead of 0" << endl;
87         ++result;
88     }
89
90     return result;
91 }
92
93 unsigned lortensor_check(void)
94 {
95     unsigned result = 0;
96     
97     cout << "checking manipulations of lortensor objects..." << flush;
98     clog << "---------manipulations of lortensor objects:" << endl;
99     
100     result += lortensor_check1();
101     result += lortensor_check2();
102     
103     if (!result) {
104         cout << " passed ";
105         clog << "(no output)" << endl;
106     } else {
107         cout << " failed ";
108     }
109     
110     return result;    
111 }