Grid 0.7.0
Metric.h
Go to the documentation of this file.
1/*************************************************************************************
2
3Grid physics library, www.github.com/paboyle/Grid
4
5Source file: ./lib/qcd/hmc/integrators/Integrator.h
6
7Copyright (C) 2015
8
9Author: Guido Cossu <guido.cossu@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 //--------------------------------------------------------------------
30#pragma once
31
33
34template <typename Field>
35class Metric{
36public:
37 virtual void ImportGauge(const Field&) = 0;
38 virtual void M(const Field&, Field&) = 0;
39 virtual void Minv(const Field&, Field&) = 0;
40 virtual void MSquareRoot(Field&) = 0;
41 virtual void MInvSquareRoot(Field&) = 0;
42 virtual void MDeriv(const Field&, Field&) = 0;
43 virtual void MDeriv(const Field&, const Field&, Field&) = 0;
44};
45
46
47// Need a trivial operator
48template <typename Field>
49class TrivialMetric : public Metric<Field>{
50public:
51 virtual void ImportGauge(const Field&){};
52 virtual void M(const Field& in, Field& out){
53 out = in;
54 }
55 virtual void Minv(const Field& in, Field& out){
56 out = in;
57 }
58 virtual void MSquareRoot(Field& P){
59 // do nothing
60 }
61 virtual void MInvSquareRoot(Field& P){
62 // do nothing
63 }
64 virtual void MDeriv(const Field& in, Field& out){
65 out = Zero();
66 }
67 virtual void MDeriv(const Field& left, const Field& right, Field& out){
68 out = Zero();
69 }
70
71};
72
74// Generalised momenta
76
77template <typename Implementation>
79public:
80 typedef typename Implementation::Field MomentaField; //for readability
81 typedef typename Implementation::GaugeLinkField MomentaLinkField; //for readability
84
85 // Auxiliary fields
86 // not hard coded but inherit the type from the metric
87 // created Nd new fields
88 // hide these in the metric?
89 //typedef Lattice<iVector<iScalar<iMatrix<vComplex, Nc> >, Nd/2 > > AuxiliaryMomentaType;
92
94
95 // Correct
97 // Generate a distribution for
98 // P^dag G P
99 // where G = M^-1
100
101 // Generate gaussian momenta
102 Implementation::generate_momenta(Mom, sRNG, pRNG);
103 // Modify the distribution with the metric
104 M.MSquareRoot(Mom);
105
106 if (1) {
107 // Auxiliary momenta
108 // do nothing if trivial, so hide in the metric
109 MomentaField AuxMomTemp(Mom.Grid());
110 Implementation::generate_momenta(AuxMom, sRNG, pRNG);
111 Implementation::generate_momenta(AuxField, sRNG, pRNG);
112 // Modify the distribution with the metric
113 // Aux^dag M Aux
114 M.MInvSquareRoot(AuxMom); // AuxMom = M^{-1/2} AuxMomTemp
115 }
116 }
117
118 // Correct
120 MomentaField inv(Mom.Grid());
121 inv = Zero();
122 M.Minv(Mom, inv);
123 LatticeComplex Hloc(Mom.Grid());
124 Hloc = Zero();
125 for (int mu = 0; mu < Nd; mu++) {
126 // This is not very general
127 // hide in the metric
128 auto Mom_mu = PeekIndex<LorentzIndex>(Mom, mu);
129 auto inv_mu = PeekIndex<LorentzIndex>(inv, mu);
130 Hloc += trace(Mom_mu * inv_mu);
131 }
132
133 if (1) {
134 // Auxiliary Fields
135 // hide in the metric
136 M.M(AuxMom, inv);
137 for (int mu = 0; mu < Nd; mu++) {
138 // This is not very general
139 // hide in the operators
140 auto inv_mu = PeekIndex<LorentzIndex>(inv, mu);
141 auto am_mu = PeekIndex<LorentzIndex>(AuxMom, mu);
142 auto af_mu = PeekIndex<LorentzIndex>(AuxField, mu);
143 Hloc += trace(am_mu * inv_mu);// p M p
144 Hloc += trace(af_mu * af_mu);
145 }
146 }
147
148 auto Hsum = TensorRemove(sum(Hloc));
149 return Hsum.real();
150 }
151
152 // Correct
154
155 // Compute the derivative of the kinetic term
156 // with respect to the gauge field
157 MomentaField MDer(in.Grid());
158 MomentaField X(in.Grid());
159 X = Zero();
160 M.Minv(in, X); // X = G in
161 M.MDeriv(X, MDer); // MDer = U * dS/dU
162 der = Implementation::projectForce(MDer); // Ta if gauge fields
163
164 }
165
167 der = Zero();
168 if (1){
169 // Auxiliary fields
170 MomentaField der_temp(der.Grid());
171 MomentaField X(der.Grid());
172 X=Zero();
173 //M.M(AuxMom, X); // X = M Aux
174 // Two derivative terms
175 // the Mderiv need separation of left and right terms
176 M.MDeriv(AuxMom, der);
177
178
179 // this one should not be necessary (identical to the previous one)
180 //M.MDeriv(X, AuxMom, der_temp); der += der_temp;
181
182 der = -1.0*Implementation::projectForce(der);
183 }
184 }
185
187 der = Zero();
188 M.Minv(Mom, der);
189 // is the projection necessary here?
190 // no for fields in the algebra
191 der = Implementation::projectForce(der);
192 }
193
195 if(1){
196 AuxMom -= ep * AuxField;
197 }
198 }
199
201 if (1) {
202 MomentaField tmp(AuxMom.Grid());
203 MomentaField tmp2(AuxMom.Grid());
204 M.M(AuxMom, tmp);
205 // M.M(tmp, tmp2);
206 AuxField += ep * tmp; // M^2 AuxMom
207 // factor of 2?
208 }
209 }
210
211};
212
214
accelerator_inline Grid_simd2< S, V > trace(const Grid_simd2< S, V > &arg)
auto PeekIndex(const Lattice< vobj > &lhs, int i) -> Lattice< decltype(peekIndex< Index >(vobj(), i))>
vobj::scalar_object sum(const vobj *arg, Integer osites)
#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)
void DerivativeU(MomentaField &in, MomentaField &der)
Definition Metric.h:153
MomentaField AuxMom
Definition Metric.h:90
GeneralisedMomenta(GridBase *grid, Metric< MomentaField > &M)
Definition Metric.h:93
void update_auxiliary_fields(RealD ep)
Definition Metric.h:200
void MomentaDistribution(GridSerialRNG &sRNG, GridParallelRNG &pRNG)
Definition Metric.h:96
Implementation::Field MomentaField
Definition Metric.h:80
void update_auxiliary_momenta(RealD ep)
Definition Metric.h:194
Metric< MomentaField > & M
Definition Metric.h:82
Implementation::GaugeLinkField MomentaLinkField
Definition Metric.h:81
MomentaField AuxField
Definition Metric.h:91
void DerivativeP(MomentaField &der)
Definition Metric.h:186
RealD MomentaAction()
Definition Metric.h:119
MomentaField Mom
Definition Metric.h:83
void AuxiliaryFieldsDerivative(MomentaField &der)
Definition Metric.h:166
virtual void MSquareRoot(Field &)=0
virtual void ImportGauge(const Field &)=0
virtual void MDeriv(const Field &, const Field &, Field &)=0
virtual void M(const Field &, Field &)=0
virtual void MDeriv(const Field &, Field &)=0
virtual void MInvSquareRoot(Field &)=0
virtual void Minv(const Field &, Field &)=0
virtual void MInvSquareRoot(Field &P)
Definition Metric.h:61
virtual void MDeriv(const Field &left, const Field &right, Field &out)
Definition Metric.h:67
virtual void Minv(const Field &in, Field &out)
Definition Metric.h:55
virtual void M(const Field &in, Field &out)
Definition Metric.h:52
virtual void MDeriv(const Field &in, Field &out)
Definition Metric.h:64
virtual void MSquareRoot(Field &P)
Definition Metric.h:58
virtual void ImportGauge(const Field &)
Definition Metric.h:51
Definition Simd.h:194