Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
vec_SU_N.h
Go to the documentation of this file.
1 
14 #ifndef VEC_SU_N_INCLUDED
15 #define VEC_SU_N_INCLUDED
16 
17 #include <cassert>
19 #include "mat_SU_N.h"
20 
21 #include "bridge_complex.h"
22 
23 namespace SU_N {
24  class Vec_SU_N {
25  private:
26  int Nc;
27  std::valarray<double> va;
28  public:
29  Vec_SU_N(int Nci = CommonParameters::Nc(), double r = 0.0)
30  : Nc(Nci), va(r, 2 * Nc) // N.B. arg ordering of valarray constructor.
31  {
32  }
33 
34  Vec_SU_N(const Vec_SU_N& v) : Nc(v.nc()), va(v.va)
35  {
36  }
37 
39  {
40  assert(Nc == v.nc());
41  va = v.va;
42  return *this;
43  }
44 
45  inline double norm() const;
46  inline double operator*(const Vec_SU_N&) const;
47 
48  inline int nc() const
49  { return Nc; }
50  Vec_SU_N& dag();
51  Vec_SU_N& zero();
52  Vec_SU_N& xI();
54 
55  Vec_SU_N& operator+=(const Vec_SU_N&);
56  Vec_SU_N& operator-=(const Vec_SU_N&);
57  Vec_SU_N& operator*=(const double&);
58  Vec_SU_N& operator/=(const double&);
59  Vec_SU_N& operator*=(const dcomplex&);
60  Vec_SU_N& operator/=(const dcomplex&);
61 
62  inline int size() const
63  { return va.size(); }
64 
65  inline double r(const int c) const
66  { return va[2 * c]; }
67  inline double i(const int c) const
68  { return va[2 * c + 1]; }
69 
70  inline void set_r(const int c, const double re)
71  { va[2 * c] = re; }
72  inline void set_i(const int c, const double im)
73  { va[2 * c + 1] = im; }
74  inline void set(const int c, const double re, const double im)
75  {
76  va[2 * c] = re;
77  va[2 * c + 1] = im;
78  }
79  };
80 
81  inline double Vec_SU_N::norm() const
82  {
83  std::valarray<double> tmp = va * va;
84 
85  return tmp.sum();
86  }
87 
88 
89  inline double Vec_SU_N::operator*(const Vec_SU_N& rhs) const
90  {
91  std::valarray<double> tmp = va * rhs.va;
92 
93  return tmp.sum();
94  }
95 
96 
98  {
99  for (int c = 0; c < Nc; ++c) {
100  va[2 * c + 1] = -va[2 * c + 1];
101  }
102  return *this;
103  }
104 
105 
107  {
108  va = 0.0;
109  return *this;
110  }
111 
112 
114  {
115  for (unsigned int c = 0; c < va.size() / 2; ++c) {
116  double tmp = va[2 * c];
117  va[2 * c] = -va[2 * c + 1];
118  va[2 * c + 1] = tmp;
119  }
120  return *this;
121  }
122 
123 
125  {
126  va = -va;
127  return *this;
128  }
129 
130 
132  {
133  va += rhs.va;
134  return *this;
135  }
136 
137 
139  {
140  va -= rhs.va;
141  return *this;
142  }
143 
144 
145  inline Vec_SU_N& Vec_SU_N::operator*=(const double& rhs)
146  {
147  va *= rhs;
148  return *this;
149  }
150 
151 
152  inline Vec_SU_N& Vec_SU_N::operator*=(const dcomplex& rhs)
153  {
154  std::valarray<double> tmp = va;
155 
156  for (unsigned int c = 0; c < va.size() / 2; ++c) {
157  va[2 * c] = (tmp[2 * c] * real(rhs) - tmp[2 * c + 1] * imag(rhs));
158  va[2 * c + 1] = (tmp[2 * c] * imag(rhs) + tmp[2 * c + 1] * real(rhs));
159  }
160  return *this;
161  }
162 
163 
164  inline Vec_SU_N& Vec_SU_N::operator/=(const double& rhs)
165  {
166  va /= rhs;
167  return *this;
168  }
169 
170 
171  inline Vec_SU_N& Vec_SU_N::operator/=(const dcomplex& rhs)
172  {
173  std::valarray<double> tmp = va;
174 
175  for (unsigned int c = 0; c < va.size() / 2; ++c) {
176  va[2 * c] = (tmp[2 * c] * real(rhs) + tmp[2 * c + 1] * imag(rhs)) / abs(rhs);
177  va[2 * c + 1] = (-tmp[2 * c] * imag(rhs) - tmp[2 * c + 1] * real(rhs)) / abs(rhs);
178  }
179  return *this;
180  }
181 
182 
183  inline const Vec_SU_N Ix(const Vec_SU_N& u)
184  {
185  int Nc = u.nc();
186  Vec_SU_N tmp(Nc);
187 
188  for (int c = 0; c < u.size() / 2; ++c) {
189  tmp.set(c, -u.i(c), u.r(c));
190  }
191  return tmp;
192  }
193 
194 
195  inline const Vec_SU_N operator+(const Vec_SU_N& v1, const Vec_SU_N& v2)
196  {
197  return Vec_SU_N(v1) += v2;
198  }
199 
200 
201  inline const Vec_SU_N operator-(const Vec_SU_N& v1, const Vec_SU_N& v2)
202  {
203  return Vec_SU_N(v1) -= v2;
204  }
205 
206 
207  inline const Vec_SU_N operator*(const Vec_SU_N& v, const double& r)
208  {
209  return Vec_SU_N(v) *= r;
210  }
211 
212 
213  inline const Vec_SU_N operator*(const double& r, const Vec_SU_N& v)
214  {
215  return Vec_SU_N(v) *= r;
216  }
217 
218 
219  inline const Vec_SU_N operator/(const Vec_SU_N& v, const double& r)
220  {
221  return Vec_SU_N(v) /= r;
222  }
223 
224 
225  inline const Vec_SU_N operator*(const Mat_SU_N& m, const Vec_SU_N& v)
226  {
227 // int Nc = CommonParameters::Nc();
228  int Nc = v.nc();
229  Vec_SU_N tmp(Nc);
230 
231  for (int a = 0; a < Nc; ++a) {
232  double re = 0.0;
233  double im = 0.0;
234  for (int b = 0; b < Nc; ++b) {
235  re += m.r(a, b) * v.r(b) - m.i(a, b) * v.i(b);
236  im += m.r(a, b) * v.i(b) + m.i(a, b) * v.r(b);
237  }
238  tmp.set(a, re, im);
239  }
240  return tmp;
241  }
242 } // namespace SU_N
243 #endif
double norm() const
Definition: vec_SU_N.h:81
double i(int c) const
Definition: mat_SU_N.h:115
double r(const int c) const
Definition: vec_SU_N.h:65
Mat_SU_N operator+(const Mat_SU_N &m1, const Mat_SU_N &m2)
Definition: mat_SU_N.h:538
Vec_SU_N & operator*=(const double &)
Definition: vec_SU_N.h:145
Vec_SU_N & operator/=(const double &)
Definition: vec_SU_N.h:164
const Vec_SU_N operator/(const Vec_SU_N &v, const double &r)
Definition: vec_SU_N.h:219
Vec_SU_N & operator+=(const Vec_SU_N &)
Definition: vec_SU_N.h:131
void set(const int c, const double re, const double im)
Definition: vec_SU_N.h:74
Vec_SU_N(const Vec_SU_N &v)
Definition: vec_SU_N.h:34
double i(const int c) const
Definition: vec_SU_N.h:67
Vec_SU_N(int Nci=CommonParameters::Nc(), double r=0.0)
Definition: vec_SU_N.h:29
int nc() const
Definition: vec_SU_N.h:48
Mat_SU_N operator-(const Mat_SU_N &m1, const Mat_SU_N &m2)
Definition: mat_SU_N.h:544
Vec_SU_N & operator=(const Vec_SU_N &v)
Definition: vec_SU_N.h:38
Vec_SU_N & xI()
Definition: vec_SU_N.h:113
Vec_SU_N & zero()
Definition: vec_SU_N.h:106
Vec_SU_N & operator-=(const Vec_SU_N &)
Definition: vec_SU_N.h:138
Mat_SU_N operator*(const Mat_SU_N &m1, const Mat_SU_N &m2)
Definition: mat_SU_N.h:550
Vec_SU_N & dag()
Definition: vec_SU_N.h:97
Vec_SU_N & operator-()
Definition: vec_SU_N.h:124
void set_r(const int c, const double re)
Definition: vec_SU_N.h:70
double r(int c) const
Definition: mat_SU_N.h:114
void set_i(const int c, const double im)
Definition: vec_SU_N.h:72
int size() const
Definition: vec_SU_N.h:62
std::valarray< double > va
Definition: vec_SU_N.h:27
const Vec_SU_N Ix(const Vec_SU_N &u)
Definition: vec_SU_N.h:183
double operator*(const Vec_SU_N &) const
Definition: vec_SU_N.h:89