]> www.ginac.de Git - ginac.git/blob - ginac/isospin.cpp
1be79d590533be4a88defdad96d2ead28c35fbd8
[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-2001 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 // protected
55
56 void isospin::copy(const isospin & other)
57 {
58         inherited::copy(other);
59         name=other.name;
60         serial=other.serial;
61 }
62
63 void isospin::destroy(bool call_parent)
64 {
65         if (call_parent) {
66                 inherited::destroy(call_parent);
67         }
68 }
69
70 //////////
71 // other constructors
72 //////////
73
74 // public
75
76 isospin::isospin(const std::string & initname)
77 {
78         debugmsg("isospin constructor from string",LOGLEVEL_CONSTRUCT);
79         name=initname;
80         serial=next_serial++;
81         tinfo_key=TINFO_isospin;
82 }
83
84 //////////
85 // archiving
86 //////////
87
88 /** Construct object from archive_node. */
89 isospin::isospin(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
90 {
91         debugmsg("isospin constructor from archive_node", LOGLEVEL_CONSTRUCT);
92         serial = next_serial++;
93         if (!(n.find_string("name", name)))
94                 name = autoname_prefix() + ToString(serial);
95         tinfo_key = TINFO_isospin;
96 }
97
98 /** Unarchive the object. */
99 ex isospin::unarchive(const archive_node &n, const lst &sym_lst)
100 {
101         ex s = (new isospin(n, sym_lst))->setflag(status_flags::dynallocated);
102
103         // If isospin is in sym_lst, return the existing isospin
104         for (unsigned i=0; i<sym_lst.nops(); i++) {
105                 if (is_ex_of_type(sym_lst.op(i), isospin) && (ex_to_isospin(sym_lst.op(i)).name == ex_to_isospin(s).name))
106                         return sym_lst.op(i);
107         }
108         return s;
109 }
110
111 /** Archive the object. */
112 void isospin::archive(archive_node &n) const
113 {
114         inherited::archive(n);
115         n.add_string("name", name);
116 }
117
118 //////////
119 // functions overriding virtual functions from bases classes
120 //////////
121
122 // public
123
124 void isospin::printraw(std::ostream & os) const
125 {
126         debugmsg("isospin printraw",LOGLEVEL_PRINT);
127         os << "isospin(" << "name=" << name << ",serial=" << serial
128            << ",indices=";
129         printrawindices(os);
130         os << ",hash=" << hashvalue << ",flags=" << flags << ")";
131 }
132
133 void isospin::printtree(std::ostream & os, unsigned indent) const
134 {
135         debugmsg("isospin printtree",LOGLEVEL_PRINT);
136         os << std::string(indent,' ') << name << " (isospin): "
137            << "serial=" << serial << ","
138            << seq.size() << "indices=";
139         printtreeindices(os,indent);
140         os << ", hash=" << hashvalue
141            << " (0x" << std::hex << hashvalue << std::dec << ")"
142            << ", flags=" << flags << std::endl;
143 }
144
145 void isospin::print(std::ostream & os, unsigned upper_precedence) const
146 {
147         debugmsg("isospin print",LOGLEVEL_PRINT);
148         os << name;
149         printindices(os);
150 }
151
152 void isospin::printcsrc(std::ostream & os, unsigned type, unsigned upper_precedence) const
153 {
154         debugmsg("isospin print csrc",LOGLEVEL_PRINT);
155         print(os,upper_precedence);
156 }
157
158 bool isospin::info(unsigned inf) const
159 {
160         return inherited::info(inf);
161 }
162
163 // protected
164
165 int isospin::compare_same_type(const basic & other) const
166 {
167         GINAC_ASSERT(other.tinfo() == TINFO_isospin);
168         const isospin *o = static_cast<const isospin *>(&other);
169         if (serial==o->serial) {
170                 return inherited::compare_same_type(other);
171         }
172         return serial < o->serial ? -1 : 1;
173 }
174
175 ex isospin::simplify_ncmul(const exvector & v) const
176 {
177         return simplified_ncmul(v);
178 }
179
180 unsigned isospin::calchash(void) const
181 {
182         hashvalue = golden_ratio_hash(golden_ratio_hash(0x55555556U ^
183                     golden_ratio_hash(tinfo_key) ^ serial));
184         setflag(status_flags::hash_calculated);
185         return hashvalue;
186 }
187
188 //////////
189 // virtual functions which can be overridden by derived classes
190 //////////
191
192 // none
193
194 //////////
195 // non-virtual functions in this class
196 //////////
197
198 void isospin::setname(const std::string & n)
199 {
200         name = n;
201 }
202
203 // private
204
205 std::string & isospin::autoname_prefix(void)
206 {
207         static std::string * s = new std::string("isospin");
208         return *s;
209 }
210
211 //////////
212 // static member variables
213 //////////
214
215 // private
216
217 unsigned isospin::next_serial=0;
218
219 #ifndef NO_NAMESPACE_GINAC
220 } // namespace GiNaC
221 #endif // ndef NO_NAMESPACE_GINAC
222