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 // Guido: we can probably separate the types from the HMC functions
82 // this will create 2 kind of implementations
83 // probably confusing the users
84 // Now keeping only one class
85
86
87 // Move this elsewhere? FIXME
88 static inline void AddLink(Field &U, LinkField &W, int mu) { // U[mu] += W
91 accelerator_for( ss, U.Grid()->oSites(), 1, {
92 U_v[ss](mu) = U_v[ss](mu) + W_v[ss]();
93 });
94 }
95
97 // Move these to another class
98 // HMC auxiliary functions
99 static inline void generate_momenta(Field &P, GridSerialRNG & sRNG, GridParallelRNG &pRNG)
100 {
101 // Zbigniew Srocinsky thesis:
102 //
103 // P(p) = N \Prod_{x\mu}e^-{1/2 Tr (p^2_mux)}
104 //
105 // p_x,mu = c_x,mu,a T_a
106 //
107 // Tr p^2 = sum_a,x,mu 1/2 (c_x,mu,a)^2
108 //
109 // Which implies P(p) = N \Prod_{x,\mu,a} e^-{1/4 c_xmua^2 }
110 //
111 // = N \Prod_{x,\mu,a} e^-{1/2 (c_xmua/sqrt{2})^2 }
112 //
113 //
114 // Expect cxmua variance sqrt(2).
115 //
116 // Must scale the momentum by sqrt(2) to invoke CPS and UKQCD conventions
117 //
118 LinkField Pmu(P.Grid());
119 Pmu = Zero();
120
121 for (int mu = 0; mu < Nd; mu++) {
122 Group::GaussianFundamentalLieAlgebraMatrix(pRNG, Pmu);
124 Pmu = Pmu*scale;
125 PokeIndex<LorentzIndex>(P, Pmu, mu);
126 }
127 }
128
129 static inline Field projectForce(Field &P) {
130 Field ret(P.Grid());
131 Group::taProj(P, ret);
132 return ret;
133 }
134
135 static inline void update_field(Field& P, Field& U, double ep){
136 //static std::chrono::duration<double> diff;
137
138 //auto start = std::chrono::high_resolution_clock::now();
141 accelerator_for(ss, P.Grid()->oSites(),1,{
142 for (int mu = 0; mu < Nd; mu++) {
143 U_v[ss](mu) = Exponentiate(P_v[ss](mu), ep, Nexp) * U_v[ss](mu);
144 U_v[ss](mu) = Group::ProjectOnGeneralGroup(U_v[ss](mu));
145 }
146 });
147 //auto end = std::chrono::high_resolution_clock::now();
148 // diff += end - start;
149 // std::cout << "Time to exponentiate matrix " << diff.count() << " s\n";
150 }
151
152 static inline RealD FieldSquareNorm(Field& U){
153 LatticeComplex Hloc(U.Grid());
154 Hloc = Zero();
155 for (int mu = 0; mu < Nd; mu++) {
156 auto Umu = PeekIndex<LorentzIndex>(U, mu);
157 Hloc += trace(Umu * Umu);
158 }
159 auto Hsum = TensorRemove(sum(Hloc));
160 return Hsum.real();
161 }
162
163 static inline void Project(Field &U) {
164 Group::ProjectOnSpecialGroup(U);
165 }
166
167 static inline void HotConfiguration(GridParallelRNG &pRNG, Field &U) {
168 Group::HotConfiguration(pRNG, U);
169 }
170
171 static inline void TepidConfiguration(GridParallelRNG &pRNG, Field &U) {
172 Group::TepidConfiguration(pRNG, U);
173 }
174
175 static inline void ColdConfiguration(GridParallelRNG &pRNG, Field &U) {
176 Group::ColdConfiguration(pRNG, U);
177 }
178
179 static const int num_colours = Group::Dimension;
180
181};
182
183
187
191
195
196
197
198
200
201#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