Grid 0.7.0
GaugeImplTypes.h
Go to the documentation of this file.
1/*************************************************************************************
2
3Grid physics library, www.github.com/paboyle/Grid
4
5Source file: ./lib/qcd/action/gauge/GaugeImpl.h
6
7Copyright (C) 2015
8
9Author: paboyle <paboyle@ph.ed.ac.uk>
10
11This program is free software; you can redistribute it and/or modify
12it under the terms of the GNU General Public License as published by
13the Free Software Foundation; either version 2 of the License, or
14(at your option) any later version.
15
16This program is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19GNU General Public License for more details.
20
21You should have received a copy of the GNU General Public License along
22with this program; if not, write to the Free Software Foundation, Inc.,
2351 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24
25See the full license in the file "LICENSE" in the top level distribution
26directory
27*************************************************************************************/
28/* END LEGAL */
29#ifndef GRID_GAUGE_IMPL_TYPES_H
30#define GRID_GAUGE_IMPL_TYPES_H
31
32
34
35#define CPS_MD_TIME
36
37#ifdef CPS_MD_TIME
38#define HMC_MOMENTUM_DENOMINATOR (2.0)
39#else
40#define HMC_MOMENTUM_DENOMINATOR (1.0)
41#endif
42
44// Implementation dependent gauge types
46
47#define INHERIT_GIMPL_TYPES(GImpl) \
48 typedef typename GImpl::Simd Simd; \
49 typedef typename GImpl::Scalar Scalar; \
50 typedef typename GImpl::LinkField GaugeLinkField; \
51 typedef typename GImpl::Field GaugeField; \
52 typedef typename GImpl::ComplexField ComplexField;\
53 typedef typename GImpl::SiteField SiteGaugeField; \
54 typedef typename GImpl::SiteComplex SiteComplex; \
55 typedef typename GImpl::SiteLink SiteGaugeLink;
56
57#define INHERIT_FIELD_TYPES(Impl) \
58 typedef typename Impl::Simd Simd; \
59 typedef typename Impl::ComplexField ComplexField; \
60 typedef typename Impl::SiteField SiteField; \
61 typedef typename Impl::Field Field;
62
63// hardcodes the exponential approximation in the template
64template <class S, int Nrepresentation = Nc, int Nexp = 12, class Group = SU<Nc> > class GaugeImplTypes {
65public:
66 typedef S Simd;
67 typedef typename Simd::scalar_type scalar_type;
69 template <typename vtype> using iImplScalar = iScalar<iScalar<iScalar<vtype> > >;
72
76
80
81 typedef Group GaugeGroup;
82
83 // Guido: we can probably separate the types from the HMC functions
84 // this will create 2 kind of implementations
85 // probably confusing the users
86 // Now keeping only one class
87
88
89 // Move this elsewhere? FIXME
90 static inline void AddLink(Field &U, LinkField &W, int mu) { // U[mu] += W
93 accelerator_for( ss, U.Grid()->oSites(), 1, {
94 U_v[ss](mu) = U_v[ss](mu) + W_v[ss]();
95 });
96 }
97
99 // Move these to another class
100 // HMC auxiliary functions
101 static inline void generate_momenta(Field &P, GridSerialRNG & sRNG, GridParallelRNG &pRNG)
102 {
103 // Zbigniew Srocinsky thesis:
104 //
105 // P(p) = N \Prod_{x\mu}e^-{1/2 Tr (p^2_mux)}
106 //
107 // p_x,mu = c_x,mu,a T_a
108 //
109 // Tr p^2 = sum_a,x,mu 1/2 (c_x,mu,a)^2
110 //
111 // Which implies P(p) = N \Prod_{x,\mu,a} e^-{1/4 c_xmua^2 }
112 //
113 // = N \Prod_{x,\mu,a} e^-{1/2 (c_xmua/sqrt{2})^2 }
114 //
115 //
116 // Expect cxmua variance sqrt(2).
117 //
118 // Must scale the momentum by sqrt(2) to invoke CPS and UKQCD conventions
119 //
120 LinkField Pmu(P.Grid());
121 Pmu = Zero();
122
123 for (int mu = 0; mu < Nd; mu++) {
124 Group::GaussianFundamentalLieAlgebraMatrix(pRNG, Pmu);
126 Pmu = Pmu*scale;
127 PokeIndex<LorentzIndex>(P, Pmu, mu);
128 }
129 }
130
131 static inline Field projectForce(Field &P) {
132 Field ret(P.Grid());
133 Group::taProj(P, ret);
134 return ret;
135 }
136
137 static inline void update_field(Field& P, Field& U, double ep){
138 //static std::chrono::duration<double> diff;
139
140 //auto start = std::chrono::high_resolution_clock::now();
143 accelerator_for(ss, P.Grid()->oSites(),1,{
144 for (int mu = 0; mu < Nd; mu++) {
145 U_v[ss](mu) = Exponentiate(P_v[ss](mu), ep, Nexp) * U_v[ss](mu);
146 U_v[ss](mu) = Group::ProjectOnGeneralGroup(U_v[ss](mu));
147 }
148 });
149 //auto end = std::chrono::high_resolution_clock::now();
150 // diff += end - start;
151 // std::cout << "Time to exponentiate matrix " << diff.count() << " s\n";
152 }
153
154 static inline RealD FieldSquareNorm(Field& U){
155 LatticeComplex Hloc(U.Grid());
156 Hloc = Zero();
157 for (int mu = 0; mu < Nd; mu++) {
158 auto Umu = PeekIndex<LorentzIndex>(U, mu);
159 Hloc += trace(Umu * Umu);
160 }
161 auto Hsum = TensorRemove(sum(Hloc));
162 return Hsum.real();
163 }
164
165 static inline void Project(Field &U) {
166 Group::ProjectOnSpecialGroup(U);
167 }
168
169 static inline void HotConfiguration(GridParallelRNG &pRNG, Field &U) {
170 Group::HotConfiguration(pRNG, U);
171 }
172
173 static inline void TepidConfiguration(GridParallelRNG &pRNG, Field &U) {
174 Group::TepidConfiguration(pRNG, U);
175 }
176
177 static inline void ColdConfiguration(GridParallelRNG &pRNG, Field &U) {
178 Group::ColdConfiguration(pRNG, U);
179 }
180
181 static const int num_colours = Group::Dimension;
182
183};
184
185
189
193
197
198
199
200
202
203#endif // GRID_GAUGE_IMPL_TYPES_H
#define accelerator_for(iterator, num, nsimd,...)
GaugeImplTypes< vComplex, Nc, 12, Sp< Nc > > SpGimplTypesR
GaugeImplTypes< vComplexF, Nc > GimplTypesF
GaugeImplTypes< vComplexD, Nc, 12, Sp< Nc > > SpGimplTypesD
#define HMC_MOMENTUM_DENOMINATOR
GaugeImplTypes< vComplex, SU< Nc >::AdjointDimension > GimplAdjointTypesR
GaugeImplTypes< vComplexF, Nc, 12, Sp< Nc > > SpGimplTypesF
GaugeImplTypes< vComplexF, SU< Nc >::AdjointDimension > GimplAdjointTypesF
GaugeImplTypes< vComplex, Nc > GimplTypesR
GaugeImplTypes< vComplexD, SU< Nc >::AdjointDimension > GimplAdjointTypesD
GaugeImplTypes< vComplexD, Nc > GimplTypesD
accelerator_inline Grid_simd2< S, V > trace(const Grid_simd2< S, V > &arg)
accelerator_inline Grid_simd< S, V > sqrt(const Grid_simd< S, V > &r)
void PokeIndex(Lattice< vobj > &lhs, const Lattice< decltype(peekIndex< Index >(vobj(), 0))> &rhs, int i)
auto PeekIndex(const Lattice< vobj > &lhs, int i) -> Lattice< decltype(peekIndex< Index >(vobj(), i))>
vobj::scalar_object sum(const vobj *arg, Integer osites)
#define autoView(l_v, l, mode)
@ AcceleratorRead
@ AcceleratorWrite
#define NAMESPACE_BEGIN(A)
Definition Namespace.h:35
#define NAMESPACE_END(A)
Definition Namespace.h:36
static constexpr int Nd
Definition QCD.h:52
Lattice< vTComplex > LatticeComplex
Definition QCD.h:359
double RealD
Definition Simd.h:61
accelerator_inline std::enable_if<!isGridTensor< T >::value, T >::type TensorRemove(T arg)
static INTERNAL_PRECISION U
Definition Zolotarev.cc:230
static void Project(Field &U)
static void HotConfiguration(GridParallelRNG &pRNG, Field &U)
iImplGaugeField< Simd > SiteField
iImplScalar< Simd > SiteComplex
Lattice< SiteField > Field
iScalar< iScalar< iMatrix< vtype, Nrepresentation > > > iImplGaugeLink
iVector< iScalar< iMatrix< vtype, Nrepresentation > >, Nd > iImplGaugeField
Lattice< SiteComplex > ComplexField
iImplGaugeLink< Simd > SiteLink
scalar_type Scalar
static Field projectForce(Field &P)
static void TepidConfiguration(GridParallelRNG &pRNG, Field &U)
static void generate_momenta(Field &P, GridSerialRNG &sRNG, GridParallelRNG &pRNG)
static RealD FieldSquareNorm(Field &U)
Simd::scalar_type scalar_type
iScalar< iScalar< iScalar< vtype > > > iImplScalar
static void AddLink(Field &U, LinkField &W, int mu)
static void ColdConfiguration(GridParallelRNG &pRNG, Field &U)
Lattice< SiteLink > LinkField
static void update_field(Field &P, Field &U, double ep)
int oSites(void) const
GridBase * Grid(void) const
Definition Simd.h:194