1 /** @file lorentzidx.cpp
3 * Implementation of GiNaC's Lorentz indices. */
6 * GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany
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.
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.
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
25 #include "lorentzidx.h"
32 #ifndef NO_NAMESPACE_GINAC
34 #endif // ndef NO_NAMESPACE_GINAC
36 GINAC_IMPLEMENT_REGISTERED_CLASS(lorentzidx, idx)
39 // default constructor, destructor, copy constructor assignment operator and helpers
44 lorentzidx::lorentzidx() : orthogonal_only(false), dim_parallel_space(0)
46 debugmsg("lorentzidx default constructor",LOGLEVEL_CONSTRUCT);
47 // serial is incremented in idx::idx()
48 name = "mu" + ToString(serial);
49 tinfo_key = TINFO_lorentzidx;
54 void lorentzidx::copy(const lorentzidx & other)
56 inherited::copy(other);
57 orthogonal_only=other.orthogonal_only;
58 dim_parallel_space=other.dim_parallel_space;
61 void lorentzidx::destroy(bool call_parent)
63 if (call_parent) inherited::destroy(call_parent);
72 /** Construct symbolic Lorentz index, using an automatically generated unique name.
74 * @param cov Index is covariant (contravariant otherwise)
75 * @param oonly Index only lives in orthogonal space
76 * @param dimp Dimension of parallel space
77 * @return newly constructed index */
78 lorentzidx::lorentzidx(bool cov, bool oonly, unsigned dimp)
79 : idx(cov), orthogonal_only(oonly), dim_parallel_space(dimp)
81 debugmsg("lorentzidx constructor from bool,bool,unsigned",LOGLEVEL_CONSTRUCT);
82 // serial is incremented in idx::idx(bool)
84 name="muorth"+ToString(serial);
86 name="mu"+ToString(serial);
88 tinfo_key=TINFO_lorentzidx;
91 /** Construct symbolic Lorentz index with specified name.
93 * @param n Symbolic index name
94 * @param cov Index is covariant (contravariant otherwise)
95 * @param oonly Index only lives in orthogonal space
96 * @param dimp Dimension of parallel space
97 * @return newly constructed index */
98 lorentzidx::lorentzidx(const std::string & n, bool cov, bool oonly, unsigned dimp)
99 : idx(n,cov), orthogonal_only(oonly), dim_parallel_space(dimp)
101 debugmsg("lorentzidx constructor from string,bool,bool,unsigned",
103 tinfo_key=TINFO_lorentzidx;
106 /** Construct symbolic Lorentz index with specified name.
108 * @param n Symbolic index name
109 * @param cov Index is covariant (contravariant otherwise)
110 * @param oonly Index only lives in orthogonal space
111 * @param dimp Dimension of parallel space
112 * @return newly constructed index */
113 lorentzidx::lorentzidx(const char * n, bool cov, bool oonly, unsigned dimp)
114 : idx(n,cov), orthogonal_only(oonly), dim_parallel_space(dimp)
116 debugmsg("lorentzidx constructor from char*,bool,bool,unsigned",
118 tinfo_key=TINFO_lorentzidx;
121 /** Construct numeric Lorentz index with specified value.
123 * @param v Numeric index value
124 * @param cov Index is covariant (contravariant otherwise)
125 * @return newly constructed index */
126 lorentzidx::lorentzidx(unsigned v, bool cov)
127 : idx(v,cov), orthogonal_only(false), dim_parallel_space(0)
129 debugmsg("lorentzidx constructor from unsigned,bool",LOGLEVEL_CONSTRUCT);
130 tinfo_key=TINFO_lorentzidx;
137 /** Construct object from archive_node. */
138 lorentzidx::lorentzidx(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
140 debugmsg("lorentzidx constructor from archive_node", LOGLEVEL_CONSTRUCT);
141 n.find_bool("orthogonal_only", orthogonal_only);
142 n.find_unsigned("pdim", dim_parallel_space);
145 /** Unarchive the object. */
146 ex lorentzidx::unarchive(const archive_node &n, const lst &sym_lst)
148 ex s = (new lorentzidx(n, sym_lst))->setflag(status_flags::dynallocated);
150 if (ex_to_lorentzidx(s).symbolic) {
151 // If lorentzidx is in sym_lst, return the existing lorentzidx
152 for (unsigned i=0; i<sym_lst.nops(); i++) {
153 if (is_ex_of_type(sym_lst.op(i), lorentzidx) && (ex_to_lorentzidx(sym_lst.op(i)).name == ex_to_lorentzidx(s).name))
154 return sym_lst.op(i);
160 /** Archive the object. */
161 void lorentzidx::archive(archive_node &n) const
163 inherited::archive(n);
164 n.add_bool("orthogonal_only", orthogonal_only);
165 n.add_unsigned("pdim", dim_parallel_space);
169 // functions overriding virtual functions from bases classes
174 void lorentzidx::printraw(std::ostream & os) const
176 debugmsg("lorentzidx printraw",LOGLEVEL_PRINT);
181 os << "symbolic,name=" << name;
183 os << "non symbolic,value=" << value;
189 os << ",contravariant";
192 if (orthogonal_only) {
193 os << ",only orthogonal components at " << dim_parallel_space
194 << " parallel dimensions";
196 os << ",parallel and orthogonal components";
199 os << ",serial=" << serial;
200 os << ",hash=" << hashvalue << ",flags=" << flags;
204 void lorentzidx::printtree(std::ostream & os, unsigned indent) const
206 debugmsg("lorentzidx printtree",LOGLEVEL_PRINT);
208 os << std::string(indent,' ') << "lorentzidx: ";
211 os << "symbolic,name=" << name;
213 os << "non symbolic,value=" << value;
219 os << ",contravariant";
222 if (orthogonal_only) {
223 os << ",only orthogonal components at " << dim_parallel_space
224 << " parallel dimensions";
226 os << ",parallel and orthogonal components";
229 os << ", serial=" << serial
230 << ", hash=" << hashvalue
231 << " (0x" << std::hex << hashvalue << std::dec << ")"
232 << ", flags=" << flags << std::endl;
235 void lorentzidx::print(std::ostream & os, unsigned upper_precedence) const
237 debugmsg("lorentzidx print",LOGLEVEL_PRINT);
251 bool lorentzidx::info(unsigned inf) const
253 if (inf==info_flags::lorentzidx) return true;
254 return inherited::info(inf);
257 int lorentzidx::compare_same_type(const basic & other) const
259 GINAC_ASSERT(is_of_type(other, lorentzidx));
260 const lorentzidx &o = static_cast<const lorentzidx &>(other);
262 if (orthogonal_only != o.orthogonal_only)
263 return orthogonal_only ? -1 : 1;
264 if (dim_parallel_space != o.dim_parallel_space)
265 return dim_parallel_space < o.dim_parallel_space ? -1 : 1;
266 return inherited::compare_same_type(other);
270 // non-virtual functions in this class
275 /** Create anonymous contravariant copy of a symbolic Lorentz index. */
276 lorentzidx lorentzidx::create_anonymous_representative(void) const
278 GINAC_ASSERT(is_symbolic());
279 lorentzidx i_copy(*this);
281 i_copy.name="anonymous_representative";
282 i_copy.covariant=false;
283 i_copy.clearflag(status_flags::dynallocated |
284 status_flags::hash_calculated);
292 /** Return the global symbol that represents the dimension D of spacetime. */
295 static symbol *d = new symbol("dim");
299 #ifndef NO_NAMESPACE_GINAC
301 #endif // ndef NO_NAMESPACE_GINAC