X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Florentzidx.cpp;h=ed6da8a2c65b47364bbd09efa0f3e8d82e0adef1;hp=e53d8a859011d8cd7d11e6b59fc5ec96414f254d;hb=2692a55867331a570ec7f0d957de00a996fd9d7c;hpb=6b3768e8c544739ae53321539cb4d1e3112ded1b diff --git a/ginac/lorentzidx.cpp b/ginac/lorentzidx.cpp index e53d8a85..ed6da8a2 100644 --- a/ginac/lorentzidx.cpp +++ b/ginac/lorentzidx.cpp @@ -1,11 +1,39 @@ /** @file lorentzidx.cpp * - * Implementation of GiNaC's lorentz indices. */ + * Implementation of GiNaC's Lorentz indices. */ + +/* + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ #include -#include "ginac.h" +#include "lorentzidx.h" +#include "lst.h" +#include "symbol.h" +#include "archive.h" #include "utils.h" +#include "debugmsg.h" + +#ifndef NO_NAMESPACE_GINAC +namespace GiNaC { +#endif // ndef NO_NAMESPACE_GINAC + +GINAC_IMPLEMENT_REGISTERED_CLASS(lorentzidx, idx) ////////// // default constructor, destructor, copy constructor assignment operator and helpers @@ -15,46 +43,46 @@ 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() { - debugmsg("lorentzidx destructor",LOGLEVEL_DESTRUCT); - destroy(0); + debugmsg("lorentzidx destructor",LOGLEVEL_DESTRUCT); + destroy(false); } -lorentzidx::lorentzidx(lorentzidx const & other) +lorentzidx::lorentzidx(const lorentzidx & other) { - debugmsg("lorentzidx copy constructor",LOGLEVEL_CONSTRUCT); - copy(other); + debugmsg("lorentzidx copy constructor",LOGLEVEL_CONSTRUCT); + copy(other); } -lorentzidx const & lorentzidx::operator=(lorentzidx const & other) +const lorentzidx & lorentzidx::operator=(const lorentzidx & other) { - debugmsg("lorentzidx operator=",LOGLEVEL_ASSIGNMENT); - if (this != &other) { - destroy(1); - copy(other); - } - return *this; + debugmsg("lorentzidx operator=",LOGLEVEL_ASSIGNMENT); + if (this != &other) { + destroy(true); + copy(other); + } + return *this; } // protected -void lorentzidx::copy(lorentzidx const & other) +void lorentzidx::copy(const lorentzidx & other) { - idx::copy(other); - orthogonal_only=other.orthogonal_only; - dim_parallel_space=other.dim_parallel_space; + inherited::copy(other); + orthogonal_only=other.orthogonal_only; + dim_parallel_space=other.dim_parallel_space; } void lorentzidx::destroy(bool call_parent) { - if (call_parent) idx::destroy(call_parent); + if (call_parent) inherited::destroy(call_parent); } ////////// @@ -63,134 +91,195 @@ void lorentzidx::destroy(bool call_parent) // public -lorentzidx::lorentzidx(bool cov, bool oonly, unsigned dimp) : - idx(cov), orthogonal_only(oonly), dim_parallel_space(dimp) +/** 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 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 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; } -lorentzidx::lorentzidx(string const & n, bool cov, bool oonly, unsigned dimp) - : idx(n,cov), orthogonal_only(oonly), dim_parallel_space(dimp) +/** 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; + debugmsg("lorentzidx constructor from string,bool,bool,unsigned", + LOGLEVEL_CONSTRUCT); + tinfo_key=TINFO_lorentzidx; } -lorentzidx::lorentzidx(char const * n, bool cov, bool oonly, unsigned dimp) - : idx(n,cov), orthogonal_only(oonly), dim_parallel_space(dimp) +/** 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) { - debugmsg("lorentzidx constructor from char*,bool,bool,unsigned", - LOGLEVEL_CONSTRUCT); - tinfo_key=TINFO_LORENTZIDX; + debugmsg("lorentzidx constructor from char*,bool,bool,unsigned", + LOGLEVEL_CONSTRUCT); + tinfo_key=TINFO_lorentzidx; } -lorentzidx::lorentzidx(unsigned const v, bool cov) : idx(v,cov), - orthogonal_only(false), dim_parallel_space(0) +/** 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) { - debugmsg("lorentzidx constructor from unsigned,bool",LOGLEVEL_CONSTRUCT); - tinfo_key=TINFO_LORENTZIDX; + debugmsg("lorentzidx constructor from unsigned,bool",LOGLEVEL_CONSTRUCT); + tinfo_key=TINFO_lorentzidx; } ////////// -// functions overriding virtual functions from bases classes +// archiving ////////// -// public - -basic * lorentzidx::duplicate() const +/** Construct object from archive_node. */ +lorentzidx::lorentzidx(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst) { - debugmsg("lorentzidx duplicate",LOGLEVEL_DUPLICATE); - return new lorentzidx(*this); + debugmsg("lorentzidx constructor from archive_node", LOGLEVEL_CONSTRUCT); + n.find_bool("orthogonal_only", orthogonal_only); + n.find_unsigned("pdim", dim_parallel_space); } -void lorentzidx::printraw(ostream & os) const +/** Unarchive the object. */ +ex lorentzidx::unarchive(const archive_node &n, const lst &sym_lst) { - debugmsg("lorentzidx printraw",LOGLEVEL_PRINT); - - os << "lorentzidx("; - - if (symbolic) { - os << "symbolic,name=" << name; - } else { - os << "non symbolic,value=" << value; - } - - if (covariant) { - os << ",covariant"; - } else { - os << ",contravariant"; - } - - if (orthogonal_only) { - os << ",only orthogonal components at " << dim_parallel_space - << " parallel dimensions"; - } else { - os << ",parallel and orthogonal components"; - } - - os << ",serial=" << serial; - os << ",hash=" << hashvalue << ",flags=" << flags; - os << ")"; + 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