File indexing completed on 2025-04-19 09:09:54
0001 #ifndef ATOOLS_Phys_Color_H
0002 #define ATOOLS_Phys_Color_H
0003
0004
0005
0006
0007
0008
0009 #include <iostream>
0010 #include <string>
0011 #ifndef USING__Color_only
0012 #include "ATOOLS/Math/MyComplex.H"
0013 #else
0014 #include <complex>
0015 typedef std::complex<double> Complex;
0016 #endif
0017 #include "ATOOLS/Org/Node.H"
0018
0019 namespace ATOOLS {
0020
0021 struct ctt {
0022
0023 enum type {
0024 number = 0,
0025 delta = 1,
0026 fundamental = 2,
0027 adjoint = 4,
0028 trace = 8
0029 };
0030
0031 };
0032
0033 class Expression;
0034
0035 class Color_Term {
0036 private:
0037
0038 ctt::type m_type;
0039
0040 public:
0041
0042
0043 inline Color_Term(const ctt::type &type):
0044 m_type(type) {}
0045
0046
0047 virtual ~Color_Term();
0048
0049
0050 virtual bool Evaluate(Expression *const expression);
0051 virtual void Print() const;
0052
0053 virtual Color_Term *GetCopy() const;
0054
0055 virtual void Delete();
0056
0057
0058 inline ctt::type Type() const { return m_type; }
0059
0060 };
0061
0062
0063
0064
0065
0066
0067
0068
0069 class CNumber: public Color_Term {
0070 public:
0071
0072 typedef std::vector<CNumber*> CNumber_Vector;
0073
0074 private:
0075
0076 static CNumber_Vector s_cnumbers;
0077
0078 Complex m_n;
0079
0080 public:
0081
0082
0083 inline CNumber(const Complex &n):
0084 Color_Term(ctt::number), m_n(n) {}
0085
0086
0087 bool Evaluate(Expression *const expression);
0088 void Print() const;
0089
0090 Color_Term *GetCopy() const;
0091
0092 static CNumber *New(const Complex &n);
0093
0094 void Delete();
0095 static void DeleteAll();
0096
0097
0098 inline Complex operator()() { return m_n; }
0099
0100 };
0101
0102
0103
0104
0105
0106
0107
0108 class Delta: public Color_Term {
0109 public:
0110
0111 typedef std::vector<Delta*> Delta_Vector;
0112
0113 private:
0114
0115 static Delta_Vector s_deltas;
0116
0117 size_t m_i, m_j;
0118
0119 public:
0120
0121
0122 inline Delta(const size_t &i,const size_t &j):
0123 Color_Term(ctt::delta), m_i(i), m_j(j) {}
0124
0125
0126 bool Evaluate(Expression *const expression);
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140 void Print() const;
0141
0142 Color_Term *GetCopy() const;
0143
0144 static Delta *New(const size_t &i,const size_t &j);
0145
0146 void Delete();
0147 static void DeleteAll();
0148
0149 inline void SetI(const size_t &i) { m_i=i; }
0150 inline void SetJ(const size_t &j) { m_j=j; }
0151
0152 };
0153
0154
0155
0156
0157
0158
0159
0160 class Fundamental: public Color_Term {
0161 public:
0162
0163 typedef std::vector<Fundamental*> Fundamental_Vector;
0164
0165 private:
0166
0167 static Fundamental_Vector s_fundamentals;
0168
0169 size_t m_a, m_i, m_j;
0170 bool m_fromf;
0171
0172
0173
0174
0175
0176
0177 friend class Delta;
0178 friend class Adjoint;
0179
0180 public:
0181
0182
0183 inline Fundamental(const size_t &a,const size_t &i,const size_t &j,
0184 const bool &fromf=false):
0185 Color_Term(ctt::fundamental), m_a(a), m_i(i), m_j(j),
0186 m_fromf(fromf) {}
0187
0188
0189 bool Evaluate(Expression *const expression);
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205 void Print() const;
0206
0207 Color_Term *GetCopy() const;
0208
0209 static Fundamental *New(const size_t &a,const size_t &i,const size_t &j,
0210 const bool &fromf=false);
0211
0212 void Delete();
0213 static void DeleteAll();
0214
0215 inline void SetA(const size_t &a) { m_a=a; }
0216 inline void SetI(const size_t &i) { m_i=i; }
0217 inline void SetJ(const size_t &j) { m_j=j; }
0218
0219 };
0220
0221
0222
0223
0224
0225
0226
0227 class Adjoint: public Color_Term {
0228 public:
0229
0230 typedef std::vector<Adjoint*> Adjoint_Vector;
0231
0232 private:
0233
0234 static Adjoint_Vector s_adjoints;
0235
0236 size_t m_a, m_b, m_c;
0237
0238 public:
0239
0240
0241 inline Adjoint(const size_t &a,const size_t &b,const size_t &c):
0242 Color_Term(ctt::adjoint), m_a(a), m_b(b), m_c(c) {}
0243
0244
0245 bool Evaluate(Expression *const expression);
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264 void Print() const;
0265
0266 Color_Term *GetCopy() const;
0267
0268 static Adjoint *New(const size_t &a,const size_t &b,const size_t &c);
0269
0270 void Delete();
0271 static void DeleteAll();
0272
0273 inline void SetA(const size_t &a) { m_a=a; }
0274 inline void SetB(const size_t &b) { m_b=b; }
0275 inline void SetC(const size_t &c) { m_c=c; }
0276
0277 };
0278
0279
0280
0281
0282
0283
0284
0285 class Trace: public Color_Term {
0286 public:
0287
0288 typedef std::vector<Trace*> Trace_Vector;
0289
0290 private:
0291
0292 static Trace_Vector s_traces;
0293
0294 size_t *ma, m_i, m_j;
0295
0296 public:
0297
0298
0299 Trace(size_t *a,const size_t &i,const size_t &j);
0300
0301
0302 ~Trace();
0303
0304
0305 bool Evaluate(Expression *const expression);
0306
0307
0308
0309
0310
0311
0312
0313
0314
0315
0316
0317 void Print() const;
0318
0319 Color_Term *GetCopy() const;
0320
0321 static Trace *New(size_t *a,const size_t &i,const size_t &j);
0322
0323 void Delete();
0324 static void DeleteAll();
0325
0326 };
0327
0328
0329
0330
0331
0332
0333
0334 class Expression: public ATOOLS::Node<Color_Term*> {
0335 public:
0336
0337 typedef std::vector<Color_Term*> Color_Term_Vector;
0338
0339 typedef std::vector<ATOOLS::Node<Color_Term*>*> Expression_Vector;
0340
0341 private:
0342
0343 static Expression_Vector s_expressions;
0344
0345 Complex m_result;
0346
0347 double m_NC, m_TR;
0348
0349 size_t m_findex, m_aindex;
0350 size_t m_evaluated, m_cindex;
0351
0352 public:
0353
0354
0355 inline Expression():
0356 Node<Color_Term*>(NULL,true), m_result(0.0,0.0), m_NC(3.0), m_TR(0.5),
0357 m_findex(0), m_aindex(0), m_evaluated(0), m_cindex(0) {}
0358
0359 inline Expression(int ma,int mf):
0360 Node<Color_Term*>(NULL,true), m_result(0.0,0.0), m_NC(3.0), m_TR(0.5),
0361 m_findex(mf+1), m_aindex(ma+1), m_evaluated(0), m_cindex(0) {}
0362
0363 Expression(const std::string &expression);
0364
0365
0366 ~Expression();
0367
0368
0369 bool Evaluate();
0370 void Print();
0371
0372 inline void Add(Expression *const expression)
0373 {
0374 (*this)().push_back(expression);
0375 (*expression)<<this;
0376 }
0377
0378 size_t Size();
0379 size_t Evaluated();
0380
0381 Expression *GetCopy() const;
0382
0383 static Expression *New(const size_t &terms);
0384
0385 void Delete();
0386 static void DeleteAll();
0387
0388 void PrintStatus(const bool endline=true,
0389 const bool print=true);
0390
0391
0392 inline Complex Result() const { return m_result; }
0393
0394 inline double NC() const { return m_NC; }
0395 inline double TR() const { return m_TR; }
0396
0397 inline size_t FIndex() { return ++m_findex; }
0398 inline size_t AIndex() { return ++m_aindex; }
0399
0400 inline size_t CIndex() const { return m_cindex; }
0401
0402 inline void SetNC(const double &nc) { m_NC=nc; }
0403 inline void SetTR(const double &tr) { m_TR=tr; }
0404
0405 };
0406
0407
0408
0409
0410
0411
0412
0413 }
0414
0415 #endif