X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Florentzidx.cpp;h=783316c48b9f173547abcdd16cc1d70ac5baf948;hp=56b4358c4c86f4b10208d9234e471ba6d6b7f73a;hb=dad107ff48f68d45e72469a8716df375ae145cf3;hpb=15d4b353c85f8815a95d97ab977c9ca48e155574 diff --git a/ginac/lorentzidx.cpp b/ginac/lorentzidx.cpp index 56b4358c..783316c4 100644 --- a/ginac/lorentzidx.cpp +++ b/ginac/lorentzidx.cpp @@ -1,9 +1,9 @@ /** @file lorentzidx.cpp * - * Implementation of GiNaC's lorentz indices. */ + * Implementation of GiNaC's Lorentz indices. */ /* - * GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,12 +23,15 @@ #include #include "lorentzidx.h" +#include "lst.h" +#include "symbol.h" +#include "archive.h" #include "utils.h" #include "debugmsg.h" -#ifndef NO_GINAC_NAMESPACE namespace GiNaC { -#endif // ndef NO_GINAC_NAMESPACE + +GINAC_IMPLEMENT_REGISTERED_CLASS(lorentzidx, idx) ////////// // default constructor, destructor, copy constructor assignment operator and helpers @@ -38,88 +41,126 @@ namespace GiNaC { lorentzidx::lorentzidx() : orthogonal_only(false), dim_parallel_space(0) { - debugmsg("lorentzidx default constructor",LOGLEVEL_CONSTRUCT); - // serial is incremented in idx::idx() - name="mu"+ToString(serial); - tinfo_key=TINFO_lorentzidx; + debugmsg("lorentzidx default constructor",LOGLEVEL_CONSTRUCT); + // serial is incremented in idx::idx() + name = "mu" + ToString(serial); + tinfo_key = TINFO_lorentzidx; } -lorentzidx::~lorentzidx() +// protected + +void lorentzidx::copy(const lorentzidx & other) { - debugmsg("lorentzidx destructor",LOGLEVEL_DESTRUCT); - destroy(0); + inherited::copy(other); + orthogonal_only=other.orthogonal_only; + dim_parallel_space=other.dim_parallel_space; } -lorentzidx::lorentzidx(lorentzidx const & other) +void lorentzidx::destroy(bool call_parent) { - debugmsg("lorentzidx copy constructor",LOGLEVEL_CONSTRUCT); - copy(other); + if (call_parent) inherited::destroy(call_parent); } -lorentzidx const & lorentzidx::operator=(lorentzidx const & other) +////////// +// other constructors +////////// + +// public + +/** Construct symbolic Lorentz index, using an automatically generated unique name. + * + * @param cov Index is covariant (contravariant otherwise) + * @param oonly Index only lives in orthogonal space + * @param dimp Dimension of parallel space + * @return newly constructed index */ +lorentzidx::lorentzidx(bool cov, bool oonly, unsigned dimp) + : idx(cov), orthogonal_only(oonly), dim_parallel_space(dimp) { - debugmsg("lorentzidx operator=",LOGLEVEL_ASSIGNMENT); - if (this != &other) { - destroy(1); - copy(other); - } - return *this; + debugmsg("lorentzidx constructor from bool,bool,unsigned",LOGLEVEL_CONSTRUCT); + // serial is incremented in idx::idx(bool) + if (oonly) { + name="muorth"+ToString(serial); + } else { + name="mu"+ToString(serial); + } + tinfo_key=TINFO_lorentzidx; } -// protected +/** Construct symbolic Lorentz index with specified name. + * + * @param n Symbolic index name + * @param cov Index is covariant (contravariant otherwise) + * @param oonly Index only lives in orthogonal space + * @param dimp Dimension of parallel space + * @return newly constructed index */ +lorentzidx::lorentzidx(const std::string & n, bool cov, bool oonly, unsigned dimp) + : idx(n,cov), orthogonal_only(oonly), dim_parallel_space(dimp) +{ + debugmsg("lorentzidx constructor from string,bool,bool,unsigned", + LOGLEVEL_CONSTRUCT); + tinfo_key=TINFO_lorentzidx; +} -void lorentzidx::copy(lorentzidx const & other) +/** Construct symbolic Lorentz index with specified name. + * + * @param n Symbolic index name + * @param cov Index is covariant (contravariant otherwise) + * @param oonly Index only lives in orthogonal space + * @param dimp Dimension of parallel space + * @return newly constructed index */ +lorentzidx::lorentzidx(const char * n, bool cov, bool oonly, unsigned dimp) + : idx(n,cov), orthogonal_only(oonly), dim_parallel_space(dimp) { - idx::copy(other); - orthogonal_only=other.orthogonal_only; - dim_parallel_space=other.dim_parallel_space; + debugmsg("lorentzidx constructor from char*,bool,bool,unsigned", + LOGLEVEL_CONSTRUCT); + tinfo_key=TINFO_lorentzidx; } -void lorentzidx::destroy(bool call_parent) +/** Construct numeric Lorentz index with specified value. + * + * @param v Numeric index value + * @param cov Index is covariant (contravariant otherwise) + * @return newly constructed index */ +lorentzidx::lorentzidx(unsigned v, bool cov) + : idx(v,cov), orthogonal_only(false), dim_parallel_space(0) { - if (call_parent) idx::destroy(call_parent); + debugmsg("lorentzidx constructor from unsigned,bool",LOGLEVEL_CONSTRUCT); + tinfo_key=TINFO_lorentzidx; } ////////// -// other constructors +// archiving ////////// -// public - -lorentzidx::lorentzidx(bool cov, bool oonly, unsigned dimp) : - idx(cov), orthogonal_only(oonly), dim_parallel_space(dimp) +/** Construct object from archive_node. */ +lorentzidx::lorentzidx(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst) { - debugmsg("lorentzidx constructor from bool",LOGLEVEL_CONSTRUCT); - // serial is incremented in idx::idx(bool) - if (oonly) { - name="muorth"+ToString(serial); - } else { - name="mu"+ToString(serial); - } - tinfo_key=TINFO_lorentzidx; + debugmsg("lorentzidx constructor from archive_node", LOGLEVEL_CONSTRUCT); + n.find_bool("orthogonal_only", orthogonal_only); + n.find_unsigned("pdim", dim_parallel_space); } -lorentzidx::lorentzidx(string const & n, bool cov, bool oonly, unsigned dimp) - : idx(n,cov), orthogonal_only(oonly), dim_parallel_space(dimp) +/** Unarchive the object. */ +ex lorentzidx::unarchive(const archive_node &n, const lst &sym_lst) { - debugmsg("lorentzidx constructor from string,bool,bool,unsigned", - LOGLEVEL_CONSTRUCT); - tinfo_key=TINFO_lorentzidx; + ex s = (new lorentzidx(n, sym_lst))->setflag(status_flags::dynallocated); + + if (ex_to_lorentzidx(s).symbolic) { + // If lorentzidx is in sym_lst, return the existing lorentzidx + for (unsigned i=0; i(other); + + if (orthogonal_only != o.orthogonal_only) + return orthogonal_only ? -1 : 1; + if (dim_parallel_space != o.dim_parallel_space) + return dim_parallel_space < o.dim_parallel_space ? -1 : 1; + return inherited::compare_same_type(other); } -////////// -// new virtual functions which can be overridden by derived classes -////////// - -// none - ////////// // non-virtual functions in this class ////////// // public +/** Create anonymous contravariant copy of a symbolic Lorentz index. */ lorentzidx lorentzidx::create_anonymous_representative(void) const { - GINAC_ASSERT(is_symbolic()); - lorentzidx i_copy(*this); - i_copy.serial=0; - i_copy.name="anonymous_representative"; - i_copy.covariant=false; - i_copy.clearflag(status_flags::dynallocated| - status_flags::hash_calculated); - return i_copy; + GINAC_ASSERT(is_symbolic()); + lorentzidx i_copy(*this); + i_copy.serial=0; + i_copy.name="anonymous_representative"; + i_copy.covariant=false; + i_copy.clearflag(status_flags::dynallocated | + status_flags::hash_calculated); + return i_copy; } ////////// -// static member variables +// global functions ////////// -// none - -////////// -// global constants -////////// - -const lorentzidx some_lorentzidx; -type_info const & typeid_lorentzidx=typeid(some_lorentzidx); +/** Return the global symbol that represents the dimension D of spacetime. */ +ex Dim(void) +{ + static symbol *d = new symbol("dim"); + return *d; +} -#ifndef NO_GINAC_NAMESPACE } // namespace GiNaC -#endif // ndef NO_GINAC_NAMESPACE