2016-07-08 15:40:11 +01:00
|
|
|
/*************************************************************************************
|
2016-01-02 14:51:32 +00:00
|
|
|
|
2016-07-08 15:40:11 +01:00
|
|
|
Grid physics library, www.github.com/paboyle/Grid
|
2016-01-02 14:51:32 +00:00
|
|
|
|
2016-07-08 15:40:11 +01:00
|
|
|
Source file: ./lib/qcd/hmc/integrators/Integrator.h
|
2016-01-02 14:51:32 +00:00
|
|
|
|
2016-07-08 15:40:11 +01:00
|
|
|
Copyright (C) 2015
|
2016-01-02 14:51:32 +00:00
|
|
|
|
|
|
|
Author: Azusa Yamaguchi <ayamaguc@staffmail.ed.ac.uk>
|
|
|
|
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
2016-10-10 11:54:58 +01:00
|
|
|
Author: Guido Cossu <cossu@post.kek.jp>
|
2016-01-02 14:51:32 +00:00
|
|
|
|
2016-07-08 15:40:11 +01:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
2016-01-02 14:51:32 +00:00
|
|
|
|
2016-07-08 15:40:11 +01:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2016-01-02 14:51:32 +00:00
|
|
|
|
2016-07-08 15:40:11 +01:00
|
|
|
You should have received a copy of the GNU General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2016-01-02 14:51:32 +00:00
|
|
|
|
2016-07-08 15:40:11 +01:00
|
|
|
See the full license in the file "LICENSE" in the top level distribution
|
|
|
|
directory
|
|
|
|
*************************************************************************************/
|
|
|
|
/* END LEGAL */
|
2015-07-06 08:46:43 +01:00
|
|
|
//--------------------------------------------------------------------
|
|
|
|
#ifndef INTEGRATOR_INCLUDED
|
|
|
|
#define INTEGRATOR_INCLUDED
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
2016-07-08 15:40:11 +01:00
|
|
|
namespace Grid {
|
|
|
|
namespace QCD {
|
|
|
|
|
|
|
|
struct IntegratorParameters {
|
2016-10-03 15:28:00 +01:00
|
|
|
unsigned int MDsteps; // number of outer steps
|
|
|
|
RealD trajL; // trajectory length
|
|
|
|
RealD stepsize; // trajectory stepsize
|
|
|
|
|
2016-10-14 17:22:32 +01:00
|
|
|
IntegratorParameters(int MDsteps_ = 10, RealD trajL_ = 1.0)
|
|
|
|
: MDsteps(MDsteps_),
|
2016-07-08 15:40:11 +01:00
|
|
|
trajL(trajL_),
|
|
|
|
stepsize(trajL / MDsteps){
|
|
|
|
// empty body constructor
|
2016-10-03 15:28:00 +01:00
|
|
|
};
|
|
|
|
|
2016-10-14 17:22:32 +01:00
|
|
|
void set(int MDsteps_, RealD trajL_){
|
|
|
|
MDsteps = MDsteps_;
|
|
|
|
trajL = trajL_;
|
|
|
|
stepsize = trajL/MDsteps;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-03 15:28:00 +01:00
|
|
|
void print_parameters() {
|
|
|
|
std::cout << GridLogMessage << "[Integrator] Trajectory length : " << trajL << std::endl;
|
|
|
|
std::cout << GridLogMessage << "[Integrator] Number of MD steps : " << MDsteps << std::endl;
|
|
|
|
std::cout << GridLogMessage << "[Integrator] Step size : " << stepsize << std::endl;
|
|
|
|
}
|
2016-07-08 15:40:11 +01:00
|
|
|
};
|
2015-08-30 12:18:34 +01:00
|
|
|
|
2016-07-08 15:40:11 +01:00
|
|
|
/*! @brief Class for Molecular Dynamics management */
|
2016-10-03 15:28:00 +01:00
|
|
|
template <class FieldImplementation, class SmearingPolicy, class RepresentationPolicy>
|
2016-07-08 15:40:11 +01:00
|
|
|
class Integrator {
|
|
|
|
protected:
|
2016-10-03 15:28:00 +01:00
|
|
|
typedef typename FieldImplementation::Field MomentaField; //for readability
|
|
|
|
typedef typename FieldImplementation::Field Field;
|
2015-07-06 08:46:43 +01:00
|
|
|
|
2016-10-04 11:24:08 +01:00
|
|
|
int levels; // number of integration levels
|
2016-07-08 15:40:11 +01:00
|
|
|
double t_U; // Track time passing on each level and for U and for P
|
2016-10-04 11:24:08 +01:00
|
|
|
std::vector<double> t_P;
|
2015-08-29 17:18:43 +01:00
|
|
|
|
2016-10-03 15:28:00 +01:00
|
|
|
MomentaField P;
|
2016-07-08 15:40:11 +01:00
|
|
|
SmearingPolicy& Smearer;
|
2016-07-18 12:05:23 +01:00
|
|
|
RepresentationPolicy Representations;
|
2016-10-04 11:24:08 +01:00
|
|
|
IntegratorParameters Params;
|
|
|
|
|
|
|
|
const ActionSet<Field, RepresentationPolicy> as;
|
2016-07-13 17:51:18 +01:00
|
|
|
|
2016-10-03 15:28:00 +01:00
|
|
|
void update_P(Field& U, int level, double ep) {
|
2016-07-08 15:40:11 +01:00
|
|
|
t_P[level] += ep;
|
|
|
|
update_P(P, U, level, ep);
|
2015-07-06 08:46:43 +01:00
|
|
|
|
2016-07-08 15:40:11 +01:00
|
|
|
std::cout << GridLogIntegrator << "[" << level << "] P "
|
|
|
|
<< " dt " << ep << " : t_P " << t_P[level] << std::endl;
|
|
|
|
}
|
2015-08-30 13:39:19 +01:00
|
|
|
|
2016-07-13 17:51:18 +01:00
|
|
|
// to be used by the actionlevel class to iterate
|
|
|
|
// over the representations
|
2016-07-18 12:05:23 +01:00
|
|
|
struct _updateP {
|
|
|
|
template <class FieldType, class GF, class Repr>
|
|
|
|
void operator()(std::vector<Action<FieldType>*> repr_set, Repr& Rep,
|
|
|
|
GF& Mom, GF& U, double ep) {
|
|
|
|
for (int a = 0; a < repr_set.size(); ++a) {
|
|
|
|
FieldType forceR(U._grid);
|
|
|
|
// Implement smearing only for the fundamental representation now
|
|
|
|
repr_set.at(a)->deriv(Rep.U, forceR);
|
|
|
|
GF force =
|
|
|
|
Rep.RtoFundamentalProject(forceR); // Ta for the fundamental rep
|
|
|
|
std::cout << GridLogIntegrator << "Hirep Force average: "
|
|
|
|
<< norm2(force) / (U._grid->gSites()) << std::endl;
|
2016-08-30 11:31:25 +01:00
|
|
|
Mom -= force * ep ;
|
2016-07-18 12:05:23 +01:00
|
|
|
}
|
2016-07-13 17:51:18 +01:00
|
|
|
}
|
2016-07-18 12:05:23 +01:00
|
|
|
} update_P_hireps{};
|
2016-07-13 17:51:18 +01:00
|
|
|
|
2016-10-03 15:28:00 +01:00
|
|
|
void update_P(MomentaField& Mom, Field& U, int level, double ep) {
|
2016-07-13 17:51:18 +01:00
|
|
|
// input U actually not used in the fundamental case
|
2016-07-18 12:05:23 +01:00
|
|
|
// Fundamental updates, include smearing
|
2016-07-08 15:40:11 +01:00
|
|
|
for (int a = 0; a < as[level].actions.size(); ++a) {
|
2016-10-03 15:28:00 +01:00
|
|
|
Field force(U._grid);
|
|
|
|
Field& Us = Smearer.get_U(as[level].actions.at(a)->is_smeared);
|
2016-07-08 15:40:11 +01:00
|
|
|
as[level].actions.at(a)->deriv(Us, force); // deriv should NOT include Ta
|
|
|
|
|
|
|
|
std::cout << GridLogIntegrator
|
|
|
|
<< "Smearing (on/off): " << as[level].actions.at(a)->is_smeared
|
|
|
|
<< std::endl;
|
|
|
|
if (as[level].actions.at(a)->is_smeared) Smearer.smeared_force(force);
|
2016-10-07 17:28:46 +01:00
|
|
|
force = FieldImplementation::projectForce(force); // Ta for gauge fields
|
2016-07-08 15:40:11 +01:00
|
|
|
std::cout << GridLogIntegrator
|
|
|
|
<< "Force average: " << norm2(force) / (U._grid->gSites())
|
|
|
|
<< std::endl;
|
|
|
|
Mom -= force * ep;
|
|
|
|
}
|
2016-07-18 12:05:23 +01:00
|
|
|
|
|
|
|
// Force from the other representations
|
2016-07-31 12:37:33 +01:00
|
|
|
as[level].apply(update_P_hireps, Representations, Mom, U, ep);
|
2016-07-04 15:35:37 +01:00
|
|
|
}
|
2015-08-30 13:39:19 +01:00
|
|
|
|
2016-10-03 15:28:00 +01:00
|
|
|
void update_U(Field& U, double ep) {
|
2016-07-08 15:40:11 +01:00
|
|
|
update_U(P, U, ep);
|
|
|
|
|
|
|
|
t_U += ep;
|
|
|
|
int fl = levels - 1;
|
|
|
|
std::cout << GridLogIntegrator << " "
|
|
|
|
<< "[" << fl << "] U "
|
|
|
|
<< " dt " << ep << " : t_U " << t_U << std::endl;
|
|
|
|
}
|
2016-10-03 15:28:00 +01:00
|
|
|
void update_U(MomentaField& Mom, Field& U, double ep) {
|
2016-10-03 16:20:06 +01:00
|
|
|
// exponential of Mom*U in the gauge fields case
|
|
|
|
FieldImplementation::update_field(Mom, U, ep);
|
2016-10-03 15:28:00 +01:00
|
|
|
|
2016-07-08 15:40:11 +01:00
|
|
|
// Update the smeared fields, can be implemented as observer
|
2016-10-03 15:28:00 +01:00
|
|
|
Smearer.set_Field(U);
|
|
|
|
|
2016-07-13 17:51:18 +01:00
|
|
|
// Update the higher representations fields
|
2016-07-31 12:37:33 +01:00
|
|
|
Representations.update(U); // void functions if fundamental representation
|
2016-07-08 15:40:11 +01:00
|
|
|
}
|
2015-08-29 17:18:43 +01:00
|
|
|
|
2016-10-03 15:28:00 +01:00
|
|
|
virtual void step(Field& U, int level, int first, int last) = 0;
|
2015-07-06 08:46:43 +01:00
|
|
|
|
2016-07-08 15:40:11 +01:00
|
|
|
public:
|
|
|
|
Integrator(GridBase* grid, IntegratorParameters Par,
|
2016-10-03 15:28:00 +01:00
|
|
|
ActionSet<Field, RepresentationPolicy>& Aset,
|
2016-07-18 12:05:23 +01:00
|
|
|
SmearingPolicy& Sm)
|
|
|
|
: Params(Par),
|
|
|
|
as(Aset),
|
|
|
|
P(grid),
|
|
|
|
levels(Aset.size()),
|
|
|
|
Smearer(Sm),
|
|
|
|
Representations(grid) {
|
2016-07-08 15:40:11 +01:00
|
|
|
t_P.resize(levels, 0.0);
|
|
|
|
t_U = 0.0;
|
|
|
|
// initialization of smearer delegated outside of Integrator
|
|
|
|
};
|
2015-08-30 12:18:34 +01:00
|
|
|
|
2016-07-08 15:40:11 +01:00
|
|
|
virtual ~Integrator() {}
|
|
|
|
|
2016-10-03 15:28:00 +01:00
|
|
|
virtual std::string integrator_name() = 0;
|
|
|
|
|
|
|
|
void print_parameters(){
|
|
|
|
std::cout << GridLogMessage << "[Integrator] Name : "<< integrator_name() << std::endl;
|
|
|
|
Params.print_parameters();
|
|
|
|
}
|
|
|
|
|
2016-07-18 12:05:23 +01:00
|
|
|
// to be used by the actionlevel class to iterate
|
|
|
|
// over the representations
|
|
|
|
struct _refresh {
|
|
|
|
template <class FieldType, class Repr>
|
|
|
|
void operator()(std::vector<Action<FieldType>*> repr_set, Repr& Rep,
|
|
|
|
GridParallelRNG& pRNG) {
|
2016-08-08 16:54:22 +01:00
|
|
|
for (int a = 0; a < repr_set.size(); ++a){
|
2016-07-18 12:05:23 +01:00
|
|
|
repr_set.at(a)->refresh(Rep.U, pRNG);
|
2016-08-08 16:54:22 +01:00
|
|
|
|
2016-07-28 16:44:41 +01:00
|
|
|
std::cout << GridLogDebug << "Hirep refreshing pseudofermions" << std::endl;
|
2016-07-18 12:05:23 +01:00
|
|
|
}
|
2016-08-08 16:54:22 +01:00
|
|
|
}
|
2016-07-18 12:05:23 +01:00
|
|
|
} refresh_hireps{};
|
|
|
|
|
2016-07-08 15:40:11 +01:00
|
|
|
// Initialization of momenta and actions
|
2016-10-03 15:28:00 +01:00
|
|
|
void refresh(Field& U, GridParallelRNG& pRNG) {
|
2016-10-07 17:28:46 +01:00
|
|
|
assert(P._grid == U._grid);
|
2016-07-08 15:40:11 +01:00
|
|
|
std::cout << GridLogIntegrator << "Integrator refresh\n";
|
2016-10-03 15:28:00 +01:00
|
|
|
FieldImplementation::generate_momenta(P, pRNG);
|
2016-10-07 17:28:46 +01:00
|
|
|
|
2016-07-13 17:51:18 +01:00
|
|
|
// Update the smeared fields, can be implemented as observer
|
2016-07-18 12:05:23 +01:00
|
|
|
// necessary to keep the fields updated even after a reject
|
2016-07-13 17:51:18 +01:00
|
|
|
// of the Metropolis
|
2016-10-03 15:28:00 +01:00
|
|
|
Smearer.set_Field(U);
|
2016-07-13 17:51:18 +01:00
|
|
|
// Set the (eventual) representations gauge fields
|
2016-07-31 12:37:33 +01:00
|
|
|
Representations.update(U);
|
2016-07-13 17:51:18 +01:00
|
|
|
|
2016-07-12 13:36:10 +01:00
|
|
|
// The Smearer is attached to a pointer of the gauge field
|
2016-07-13 17:51:18 +01:00
|
|
|
// automatically gets the correct field
|
2016-07-12 13:36:10 +01:00
|
|
|
// whether or not has been accepted in the previous sweep
|
2016-07-08 15:40:11 +01:00
|
|
|
for (int level = 0; level < as.size(); ++level) {
|
|
|
|
for (int actionID = 0; actionID < as[level].actions.size(); ++actionID) {
|
|
|
|
// get gauge field from the SmearingPolicy and
|
|
|
|
// based on the boolean is_smeared in actionID
|
2016-10-03 15:28:00 +01:00
|
|
|
Field& Us =
|
2016-07-08 15:40:11 +01:00
|
|
|
Smearer.get_U(as[level].actions.at(actionID)->is_smeared);
|
|
|
|
as[level].actions.at(actionID)->refresh(Us, pRNG);
|
|
|
|
}
|
2016-07-13 17:51:18 +01:00
|
|
|
|
2016-07-28 16:44:41 +01:00
|
|
|
// Refresh the higher representation actions
|
2016-07-31 12:37:33 +01:00
|
|
|
as[level].apply(refresh_hireps, Representations, pRNG);
|
2016-07-18 12:05:23 +01:00
|
|
|
}
|
2016-07-04 15:35:37 +01:00
|
|
|
}
|
2015-08-31 16:32:04 +01:00
|
|
|
|
2016-07-18 12:05:23 +01:00
|
|
|
// to be used by the actionlevel class to iterate
|
|
|
|
// over the representations
|
|
|
|
struct _S {
|
|
|
|
template <class FieldType, class Repr>
|
|
|
|
void operator()(std::vector<Action<FieldType>*> repr_set, Repr& Rep,
|
|
|
|
int level, RealD& H) {
|
2016-07-28 16:44:41 +01:00
|
|
|
|
2016-07-18 12:05:23 +01:00
|
|
|
for (int a = 0; a < repr_set.size(); ++a) {
|
|
|
|
RealD Hterm = repr_set.at(a)->S(Rep.U);
|
|
|
|
std::cout << GridLogMessage << "S Level " << level << " term " << a
|
|
|
|
<< " H Hirep = " << Hterm << std::endl;
|
|
|
|
H += Hterm;
|
2016-07-28 16:44:41 +01:00
|
|
|
|
2016-07-18 12:05:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} S_hireps{};
|
|
|
|
|
2016-07-08 15:40:11 +01:00
|
|
|
// Calculate action
|
2016-10-03 15:28:00 +01:00
|
|
|
RealD S(Field& U) { // here also U not used
|
2016-07-08 15:40:11 +01:00
|
|
|
|
2016-10-03 15:50:04 +01:00
|
|
|
RealD H = - FieldImplementation::FieldSquareNorm(P); // - trace (P*P)
|
2016-07-08 15:40:11 +01:00
|
|
|
RealD Hterm;
|
|
|
|
std::cout << GridLogMessage << "Momentum action H_p = " << H << "\n";
|
|
|
|
|
|
|
|
// Actions
|
|
|
|
for (int level = 0; level < as.size(); ++level) {
|
|
|
|
for (int actionID = 0; actionID < as[level].actions.size(); ++actionID) {
|
|
|
|
// get gauge field from the SmearingPolicy and
|
|
|
|
// based on the boolean is_smeared in actionID
|
2016-10-03 15:28:00 +01:00
|
|
|
Field& Us =
|
2016-07-08 15:40:11 +01:00
|
|
|
Smearer.get_U(as[level].actions.at(actionID)->is_smeared);
|
|
|
|
Hterm = as[level].actions.at(actionID)->S(Us);
|
|
|
|
std::cout << GridLogMessage << "S Level " << level << " term "
|
|
|
|
<< actionID << " H = " << Hterm << std::endl;
|
|
|
|
H += Hterm;
|
|
|
|
}
|
2016-07-31 12:37:33 +01:00
|
|
|
as[level].apply(S_hireps, Representations, level, H);
|
2016-07-08 15:40:11 +01:00
|
|
|
}
|
2015-08-31 16:32:04 +01:00
|
|
|
|
2016-07-08 15:40:11 +01:00
|
|
|
return H;
|
|
|
|
}
|
2015-08-31 16:32:04 +01:00
|
|
|
|
2016-10-03 15:28:00 +01:00
|
|
|
void integrate(Field& U) {
|
2016-07-08 15:40:11 +01:00
|
|
|
// reset the clocks
|
|
|
|
t_U = 0;
|
|
|
|
for (int level = 0; level < as.size(); ++level) {
|
|
|
|
t_P[level] = 0;
|
|
|
|
}
|
|
|
|
|
2016-07-18 12:05:23 +01:00
|
|
|
for (int step = 0; step < Params.MDsteps; ++step) { // MD step
|
2016-07-08 15:40:11 +01:00
|
|
|
int first_step = (step == 0);
|
|
|
|
int last_step = (step == Params.MDsteps - 1);
|
|
|
|
this->step(U, 0, first_step, last_step);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check the clocks all match on all levels
|
|
|
|
for (int level = 0; level < as.size(); ++level) {
|
|
|
|
assert(fabs(t_U - t_P[level]) < 1.0e-6); // must be the same
|
|
|
|
std::cout << GridLogIntegrator << " times[" << level
|
|
|
|
<< "]= " << t_P[level] << " " << t_U << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
// and that we indeed got to the end of the trajectory
|
|
|
|
assert(fabs(t_U - Params.trajL) < 1.0e-6);
|
|
|
|
}
|
2016-10-03 15:28:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-04 15:35:37 +01:00
|
|
|
};
|
|
|
|
}
|
2015-07-06 08:46:43 +01:00
|
|
|
}
|
2016-07-08 15:40:11 +01:00
|
|
|
#endif // INTEGRATOR_INCLUDED
|
2016-10-03 15:28:00 +01:00
|
|
|
|