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;
52 lorentzidx::~lorentzidx()
54 debugmsg("lorentzidx destructor",LOGLEVEL_DESTRUCT);
58 lorentzidx::lorentzidx(const lorentzidx & other)
60 debugmsg("lorentzidx copy constructor",LOGLEVEL_CONSTRUCT);
64 const lorentzidx & lorentzidx::operator=(const lorentzidx & other)
66 debugmsg("lorentzidx operator=",LOGLEVEL_ASSIGNMENT);
76 void lorentzidx::copy(const lorentzidx & other)
78 inherited::copy(other);
79 orthogonal_only=other.orthogonal_only;
80 dim_parallel_space=other.dim_parallel_space;
83 void lorentzidx::destroy(bool call_parent)
85 if (call_parent) inherited::destroy(call_parent);
94 /** Construct symbolic Lorentz index, using an automatically generated unique name.
96 * @param cov Index is covariant (contravariant otherwise)
97 * @param oonly Index only lives in orthogonal space
98 * @param dimp Dimension of parallel space
99 * @return newly constructed index */
100 lorentzidx::lorentzidx(bool cov, bool oonly, unsigned dimp)
101 : idx(cov), orthogonal_only(oonly), dim_parallel_space(dimp)
103 debugmsg("lorentzidx constructor from bool,bool,unsigned",LOGLEVEL_CONSTRUCT);
104 // serial is incremented in idx::idx(bool)
106 name="muorth"+ToString(serial);
108 name="mu"+ToString(serial);
110 tinfo_key=TINFO_lorentzidx;
113 /** Construct symbolic Lorentz index with specified name.
115 * @param n Symbolic index name
116 * @param cov Index is covariant (contravariant otherwise)
117 * @param oonly Index only lives in orthogonal space
118 * @param dimp Dimension of parallel space
119 * @return newly constructed index */
120 lorentzidx::lorentzidx(const std::string & n, bool cov, bool oonly, unsigned dimp)
121 : idx(n,cov), orthogonal_only(oonly), dim_parallel_space(dimp)
123 debugmsg("lorentzidx constructor from string,bool,bool,unsigned",
125 tinfo_key=TINFO_lorentzidx;
128 /** Construct symbolic Lorentz index with specified name.
130 * @param n Symbolic index name
131 * @param cov Index is covariant (contravariant otherwise)
132 * @param oonly Index only lives in orthogonal space
133 * @param dimp Dimension of parallel space
134 * @return newly constructed index */
135 lorentzidx::lorentzidx(const char * n, bool cov, bool oonly, unsigned dimp)
136 : idx(n,cov), orthogonal_only(oonly), dim_parallel_space(dimp)
138 debugmsg("lorentzidx constructor from char*,bool,bool,unsigned",
140 tinfo_key=TINFO_lorentzidx;
143 /** Construct numeric Lorentz index with specified value.
145 * @param v Numeric index value
146 * @param cov Index is covariant (contravariant otherwise)
147 * @return newly constructed index */
148 lorentzidx::lorentzidx(unsigned v, bool cov)
149 : idx(v,cov), orthogonal_only(false), dim_parallel_space(0)
151 debugmsg("lorentzidx constructor from unsigned,bool",LOGLEVEL_CONSTRUCT);
152 tinfo_key=TINFO_lorentzidx;
159 /** Construct object from archive_node. */
160 lorentzidx::lorentzidx(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
162 debugmsg("lorentzidx constructor from archive_node", LOGLEVEL_CONSTRUCT);
163 n.find_bool("orthogonal_only", orthogonal_only);
164 n.find_unsigned("pdim", dim_parallel_space);
167 /** Unarchive the object. */
168 ex lorentzidx::unarchive(const archive_node &n, const lst &sym_lst)
170 ex s = (new lorentzidx(n, sym_lst))->setflag(status_flags::dynallocated);
172 if (ex_to_lorentzidx(s).symbolic) {
173 // If lorentzidx is in sym_lst, return the existing lorentzidx
174 for (unsigned i=0; i<sym_lst.nops(); i++) {
175 if (is_ex_of_type(sym_lst.op(i), lorentzidx) && (ex_to_lorentzidx(sym_lst.op(i)).name == ex_to_lorentzidx(s).name))
176 return sym_lst.op(i);
182 /** Archive the object. */
183 void lorentzidx::archive(archive_node &n) const
185 inherited::archive(n);
186 n.add_bool("orthogonal_only", orthogonal_only);
187 n.add_unsigned("pdim", dim_parallel_space);
191 // functions overriding virtual functions from bases classes
196 basic * lorentzidx::duplicate() const
198 debugmsg("lorentzidx duplicate",LOGLEVEL_DUPLICATE);
199 return new lorentzidx(*this);
202 void lorentzidx::printraw(std::ostream & os) const
204 debugmsg("lorentzidx printraw",LOGLEVEL_PRINT);
209 os << "symbolic,name=" << name;
211 os << "non symbolic,value=" << value;
217 os << ",contravariant";
220 if (orthogonal_only) {
221 os << ",only orthogonal components at " << dim_parallel_space
222 << " parallel dimensions";
224 os << ",parallel and orthogonal components";
227 os << ",serial=" << serial;
228 os << ",hash=" << hashvalue << ",flags=" << flags;
232 void lorentzidx::printtree(std::ostream & os, unsigned indent) const
234 debugmsg("lorentzidx printtree",LOGLEVEL_PRINT);
236 os << std::string(indent,' ') << "lorentzidx: ";
239 os << "symbolic,name=" << name;
241 os << "non symbolic,value=" << value;
247 os << ",contravariant";
250 if (orthogonal_only) {
251 os << ",only orthogonal components at " << dim_parallel_space
252 << " parallel dimensions";
254 os << ",parallel and orthogonal components";
257 os << ", serial=" << serial
258 << ", hash=" << hashvalue
259 << " (0x" << std::hex << hashvalue << std::dec << ")"
260 << ", flags=" << flags << std::endl;
263 void lorentzidx::print(std::ostream & os, unsigned upper_precedence) const
265 debugmsg("lorentzidx print",LOGLEVEL_PRINT);
279 bool lorentzidx::info(unsigned inf) const
281 if (inf==info_flags::lorentzidx) return true;
282 return inherited::info(inf);
286 // new virtual functions which can be overridden by derived classes
292 // non-virtual functions in this class
297 /** Create anonymous contravariant copy of a symbolic Lorentz index. */
298 lorentzidx lorentzidx::create_anonymous_representative(void) const
300 GINAC_ASSERT(is_symbolic());
301 lorentzidx i_copy(*this);
303 i_copy.name="anonymous_representative";
304 i_copy.covariant=false;
305 i_copy.clearflag(status_flags::dynallocated |
306 status_flags::hash_calculated);
311 // static member variables
320 /** Return the global symbol that represents the dimension D of spacetime. */
323 static symbol *d = new symbol("dim");
331 const lorentzidx some_lorentzidx;
332 const std::type_info & typeid_lorentzidx = typeid(some_lorentzidx);
334 #ifndef NO_NAMESPACE_GINAC
336 #endif // ndef NO_NAMESPACE_GINAC