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