]> www.ginac.de Git - ginac.git/blob - ginac/isospin.cpp
- Derivatives are now assembled in a slightly different manner (i.e. they
[ginac.git] / ginac / isospin.cpp
1 /** @file isospin.cpp
2  *
3  *  Implementation of GiNaC's isospin objects.
4  *  No real implementation yet, to be done.     */
5
6 /*
7  *  GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany
8  *
9  *  This program is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License as published by
11  *  the Free Software Foundation; either version 2 of the License, or
12  *  (at your option) any later version.
13  *
14  *  This program is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *  GNU General Public License for more details.
18  *
19  *  You should have received a copy of the GNU General Public License
20  *  along with this program; if not, write to the Free Software
21  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23
24 #include <string>
25
26 #include "isospin.h"
27 #include "ex.h"
28 #include "ncmul.h"
29 #include "lst.h"
30 #include "archive.h"
31 #include "utils.h"
32 #include "debugmsg.h"
33
34 #ifndef NO_NAMESPACE_GINAC
35 namespace GiNaC {
36 #endif // ndef NO_NAMESPACE_GINAC
37
38 GINAC_IMPLEMENT_REGISTERED_CLASS(isospin, indexed)
39
40 //////////
41 // default constructor, destructor, copy constructor assignment operator and helpers
42 //////////
43
44 // public
45
46 isospin::isospin()
47 {
48     debugmsg("isospin default constructor",LOGLEVEL_CONSTRUCT);
49     serial=next_serial++;
50     name=autoname_prefix()+ToString(serial);
51     tinfo_key=TINFO_isospin;
52 }
53
54 isospin::~isospin()
55 {
56     debugmsg("isospin destructor",LOGLEVEL_DESTRUCT);
57     destroy(0);
58 }
59
60 isospin::isospin(const isospin & other)
61 {
62     debugmsg("isospin copy constructor",LOGLEVEL_CONSTRUCT);
63     copy (other);
64 }
65
66 const isospin & isospin::operator=(const isospin & other)
67 {
68     debugmsg("isospin operator=",LOGLEVEL_ASSIGNMENT);
69     if (this != &other) {
70         destroy(1);
71         copy(other);
72     }
73     return *this;
74 }
75
76 // protected
77
78 void isospin::copy(const isospin & other)
79 {
80     inherited::copy(other);
81     name=other.name;
82     serial=other.serial;
83 }
84
85 void isospin::destroy(bool call_parent)
86 {
87     if (call_parent) {
88         inherited::destroy(call_parent);
89     }
90 }
91
92 //////////
93 // other constructors
94 //////////
95
96 // public
97
98 isospin::isospin(const std::string & initname)
99 {
100     debugmsg("isospin constructor from string",LOGLEVEL_CONSTRUCT);
101     name=initname;
102     serial=next_serial++;
103     tinfo_key=TINFO_isospin;
104 }
105
106 //////////
107 // archiving
108 //////////
109
110 /** Construct object from archive_node. */
111 isospin::isospin(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
112 {
113     debugmsg("isospin constructor from archive_node", LOGLEVEL_CONSTRUCT);
114     serial = next_serial++;
115     if (!(n.find_string("name", name)))
116         name = autoname_prefix() + ToString(serial);
117     tinfo_key = TINFO_isospin;
118 }
119
120 /** Unarchive the object. */
121 ex isospin::unarchive(const archive_node &n, const lst &sym_lst)
122 {
123     ex s = (new isospin(n, sym_lst))->setflag(status_flags::dynallocated);
124
125     // If isospin is in sym_lst, return the existing isospin
126     for (unsigned i=0; i<sym_lst.nops(); i++) {
127         if (is_ex_of_type(sym_lst.op(i), isospin) && (ex_to_isospin(sym_lst.op(i)).name == ex_to_isospin(s).name))
128             return sym_lst.op(i);
129     }
130     return s;
131 }
132
133 /** Archive the object. */
134 void isospin::archive(archive_node &n) const
135 {
136     inherited::archive(n);
137     n.add_string("name", name);
138 }
139
140 //////////
141 // functions overriding virtual functions from bases classes
142 //////////
143
144 // public
145
146 basic * isospin::duplicate() const
147 {
148     debugmsg("isospin duplicate",LOGLEVEL_DUPLICATE);
149     return new isospin(*this);
150 }
151
152 void isospin::printraw(std::ostream & os) const
153 {
154     debugmsg("isospin printraw",LOGLEVEL_PRINT);
155     os << "isospin(" << "name=" << name << ",serial=" << serial
156        << ",indices=";
157     printrawindices(os);
158     os << ",hash=" << hashvalue << ",flags=" << flags << ")";
159 }
160
161 void isospin::printtree(std::ostream & os, unsigned indent) const
162 {
163     debugmsg("isospin printtree",LOGLEVEL_PRINT);
164     os << std::string(indent,' ') << name << " (isospin): "
165        << "serial=" << serial << ","
166        << seq.size() << "indices=";
167     printtreeindices(os,indent);
168     os << ", hash=" << hashvalue
169        << " (0x" << std::hex << hashvalue << std::dec << ")"
170        << ", flags=" << flags << std::endl;
171 }
172
173 void isospin::print(std::ostream & os, unsigned upper_precedence) const
174 {
175     debugmsg("isospin print",LOGLEVEL_PRINT);
176     os << name;
177     printindices(os);
178 }
179
180 void isospin::printcsrc(std::ostream & os, unsigned type, unsigned upper_precedence) const
181 {
182     debugmsg("isospin print csrc",LOGLEVEL_PRINT);
183     print(os,upper_precedence);
184 }
185
186 bool isospin::info(unsigned inf) const
187 {
188     return inherited::info(inf);
189 }
190
191 // protected
192
193 int isospin::compare_same_type(const basic & other) const
194 {
195     GINAC_ASSERT(other.tinfo() == TINFO_isospin);
196     const isospin *o = static_cast<const isospin *>(&other);
197     if (serial==o->serial) {
198         return inherited::compare_same_type(other);
199     }
200     return serial < o->serial ? -1 : 1;
201 }
202
203 ex isospin::simplify_ncmul(const exvector & v) const
204 {
205     return simplified_ncmul(v);
206 }
207
208 unsigned isospin::calchash(void) const
209 {
210     hashvalue=golden_ratio_hash(golden_ratio_hash(0x55555556U ^
211                                                   golden_ratio_hash(tinfo_key) ^
212                                                   serial));
213     setflag(status_flags::hash_calculated);
214     return hashvalue;
215 }
216
217 //////////
218 // virtual functions which can be overridden by derived classes
219 //////////
220
221 // none
222
223 //////////
224 // non-virtual functions in this class
225 //////////
226
227 void isospin::setname(const std::string & n)
228 {
229     name = n;
230 }
231
232 // private
233
234 std::string & isospin::autoname_prefix(void)
235 {
236     static std::string * s = new std::string("isospin");
237     return *s;
238 }
239
240 //////////
241 // static member variables
242 //////////
243
244 // private
245
246 unsigned isospin::next_serial=0;
247
248 //////////
249 // global constants
250 //////////
251
252 const isospin some_isospin;
253 const type_info & typeid_isospin=typeid(some_isospin);
254
255 #ifndef NO_NAMESPACE_GINAC
256 } // namespace GiNaC
257 #endif // ndef NO_NAMESPACE_GINAC
258