2015-07-03 08:51:41 +01:00
|
|
|
//--------------------------------------------------------------------
|
|
|
|
/*! @file HMC.h
|
2015-07-07 06:59:37 +01:00
|
|
|
* @brief Classes for Hybrid Monte Carlo update
|
2015-07-03 08:51:41 +01:00
|
|
|
*
|
|
|
|
* @author Guido Cossu
|
2015-07-30 09:16:04 +01:00
|
|
|
* Time-stamp: <2015-07-30 16:58:26 neo>
|
2015-07-03 08:51:41 +01:00
|
|
|
*/
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
#ifndef HMC_INCLUDED
|
|
|
|
#define HMC_INCLUDED
|
|
|
|
|
|
|
|
#include <string>
|
2015-07-07 06:59:37 +01:00
|
|
|
|
2015-07-03 08:51:41 +01:00
|
|
|
|
|
|
|
namespace Grid{
|
|
|
|
namespace QCD{
|
|
|
|
|
2015-08-30 12:18:34 +01:00
|
|
|
|
2015-07-03 08:51:41 +01:00
|
|
|
struct HMCparameters{
|
2015-12-20 02:29:51 +00:00
|
|
|
|
|
|
|
Integer StartTrajectory;
|
|
|
|
Integer Trajectories; /* @brief Number of sweeps in this run */
|
|
|
|
bool MetropolisTest;
|
|
|
|
Integer NoMetropolisUntil;
|
|
|
|
|
|
|
|
HMCparameters(){
|
|
|
|
////////////////////////////// Default values
|
|
|
|
MetropolisTest = true;
|
|
|
|
NoMetropolisUntil = 10;
|
|
|
|
StartTrajectory = 0;
|
|
|
|
Trajectories = 200;
|
|
|
|
/////////////////////////////////
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class GaugeField>
|
|
|
|
class HmcObservable {
|
|
|
|
public:
|
|
|
|
virtual void TrajectoryComplete (int traj, GaugeField &U, GridSerialRNG &sRNG, GridParallelRNG & pRNG )=0;
|
2015-07-03 08:51:41 +01:00
|
|
|
};
|
2015-12-20 02:29:51 +00:00
|
|
|
|
2015-07-03 08:51:41 +01:00
|
|
|
|
2015-08-30 12:18:34 +01:00
|
|
|
// template <class GaugeField, class Integrator, class Smearer, class Boundary>
|
2015-08-30 13:39:19 +01:00
|
|
|
template <class GaugeField, class IntegratorType>
|
2015-08-30 12:18:34 +01:00
|
|
|
class HybridMonteCarlo {
|
|
|
|
private:
|
2015-07-27 10:32:28 +01:00
|
|
|
|
2015-07-03 08:51:41 +01:00
|
|
|
const HMCparameters Params;
|
2015-08-30 12:18:34 +01:00
|
|
|
|
2015-12-20 02:29:51 +00:00
|
|
|
GridSerialRNG &sRNG; // Fixme: need a RNG management strategy.
|
2015-08-30 12:18:34 +01:00
|
|
|
GridParallelRNG &pRNG; // Fixme: need a RNG management strategy.
|
2015-12-20 02:29:51 +00:00
|
|
|
GaugeField & Ucur;
|
2015-08-30 13:39:19 +01:00
|
|
|
|
2015-08-30 12:18:34 +01:00
|
|
|
IntegratorType &TheIntegrator;
|
2015-12-20 02:29:51 +00:00
|
|
|
std::vector<HmcObservable<GaugeField> *> Observables;
|
2015-07-27 10:32:28 +01:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////
|
|
|
|
// Metropolis step
|
|
|
|
/////////////////////////////////////////////////////////
|
2015-07-03 18:43:14 +01:00
|
|
|
bool metropolis_test(const RealD DeltaH){
|
2015-07-27 10:32:28 +01:00
|
|
|
|
2015-07-03 18:43:14 +01:00
|
|
|
RealD rn_test;
|
2015-07-27 10:32:28 +01:00
|
|
|
|
2015-07-03 18:43:14 +01:00
|
|
|
RealD prob = std::exp(-DeltaH);
|
2015-07-27 10:32:28 +01:00
|
|
|
|
2015-07-03 18:43:14 +01:00
|
|
|
random(sRNG,rn_test);
|
|
|
|
|
2015-07-23 17:31:13 +01:00
|
|
|
std::cout<<GridLogMessage<< "--------------------------------------------\n";
|
2015-07-30 09:16:04 +01:00
|
|
|
std::cout<<GridLogMessage<< "dH = "<<DeltaH << " Random = "<< rn_test <<"\n";
|
|
|
|
std::cout<<GridLogMessage<< "Acc. Probability = " << ((prob<1.0)? prob: 1.0)<< " ";
|
2015-07-03 18:43:14 +01:00
|
|
|
|
|
|
|
if((prob >1.0) || (rn_test <= prob)){ // accepted
|
2015-07-23 17:31:13 +01:00
|
|
|
std::cout<<GridLogMessage <<"-- ACCEPTED\n";
|
2015-07-03 18:43:14 +01:00
|
|
|
return true;
|
|
|
|
} else { // rejected
|
2015-07-23 17:31:13 +01:00
|
|
|
std::cout<<GridLogMessage <<"-- REJECTED\n";
|
2015-07-03 18:43:14 +01:00
|
|
|
return false;
|
|
|
|
}
|
2015-07-27 10:32:28 +01:00
|
|
|
|
2015-07-03 18:43:14 +01:00
|
|
|
}
|
|
|
|
|
2015-07-27 10:32:28 +01:00
|
|
|
/////////////////////////////////////////////////////////
|
|
|
|
// Evolution
|
|
|
|
/////////////////////////////////////////////////////////
|
2015-08-30 12:18:34 +01:00
|
|
|
RealD evolve_step(GaugeField& U){
|
|
|
|
|
2015-08-30 13:39:19 +01:00
|
|
|
TheIntegrator.refresh(U,pRNG); // set U and initialize P and phi's
|
2015-08-30 12:18:34 +01:00
|
|
|
|
|
|
|
RealD H0 = TheIntegrator.S(U); // initial state action
|
2015-07-27 10:32:28 +01:00
|
|
|
|
2015-07-23 17:31:13 +01:00
|
|
|
std::cout<<GridLogMessage<<"Total H before = "<< H0 << "\n";
|
2015-07-27 10:32:28 +01:00
|
|
|
|
2015-08-30 12:18:34 +01:00
|
|
|
TheIntegrator.integrate(U);
|
2015-07-03 18:43:14 +01:00
|
|
|
|
2015-08-30 12:18:34 +01:00
|
|
|
RealD H1 = TheIntegrator.S(U); // updated state action
|
|
|
|
|
2015-07-23 17:31:13 +01:00
|
|
|
std::cout<<GridLogMessage<<"Total H after = "<< H1 << "\n";
|
2015-08-30 12:18:34 +01:00
|
|
|
|
2015-07-03 18:43:14 +01:00
|
|
|
return (H1-H0);
|
|
|
|
}
|
2015-07-03 08:51:41 +01:00
|
|
|
|
|
|
|
public:
|
2015-07-27 10:32:28 +01:00
|
|
|
|
|
|
|
/////////////////////////////////////////
|
|
|
|
// Constructor
|
|
|
|
/////////////////////////////////////////
|
2015-12-20 02:29:51 +00:00
|
|
|
HybridMonteCarlo(HMCparameters Pms, IntegratorType &_Int, GridSerialRNG &_sRNG, GridParallelRNG &_pRNG, GaugeField &_U ) :
|
2015-08-30 12:18:34 +01:00
|
|
|
Params(Pms),
|
|
|
|
TheIntegrator(_Int),
|
|
|
|
sRNG(_sRNG),
|
2015-12-20 02:29:51 +00:00
|
|
|
pRNG(_pRNG),
|
|
|
|
Ucur(_U)
|
2015-08-30 12:18:34 +01:00
|
|
|
{
|
2015-07-03 18:43:14 +01:00
|
|
|
}
|
2015-07-03 08:51:41 +01:00
|
|
|
~HybridMonteCarlo(){};
|
|
|
|
|
2015-12-20 02:29:51 +00:00
|
|
|
void AddObservable(HmcObservable<GaugeField> *obs) {
|
|
|
|
Observables.push_back(obs);
|
|
|
|
}
|
2015-07-03 18:43:14 +01:00
|
|
|
|
2015-12-20 02:29:51 +00:00
|
|
|
void evolve(void){
|
2015-08-30 12:18:34 +01:00
|
|
|
|
2015-07-03 18:43:14 +01:00
|
|
|
Real DeltaH;
|
|
|
|
|
2015-12-20 02:29:51 +00:00
|
|
|
GaugeField Ucopy(Ucur._grid);
|
|
|
|
|
2015-07-04 09:47:50 +01:00
|
|
|
// Actual updates (evolve a copy Ucopy then copy back eventually)
|
2015-12-20 02:29:51 +00:00
|
|
|
for(int traj=Params.StartTrajectory; traj < Params.Trajectories+Params.StartTrajectory; ++traj){
|
|
|
|
|
|
|
|
std::cout<<GridLogMessage << "-- # Trajectory = "<< traj << "\n";
|
2015-07-05 18:24:58 +01:00
|
|
|
|
2015-12-20 02:29:51 +00:00
|
|
|
Ucopy = Ucur;
|
2015-07-29 13:02:07 +01:00
|
|
|
|
2015-07-04 09:47:50 +01:00
|
|
|
DeltaH = evolve_step(Ucopy);
|
2015-12-20 02:29:51 +00:00
|
|
|
|
|
|
|
bool accept = true;
|
|
|
|
if ( traj > Params.NoMetropolisUntil) {
|
|
|
|
accept = metropolis_test(DeltaH);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( accept ) {
|
|
|
|
Ucur = Ucopy;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int obs = 0;obs<Observables.size();obs++){
|
|
|
|
Observables[obs]->TrajectoryComplete (traj,Ucur,sRNG,pRNG);
|
|
|
|
}
|
2015-07-29 13:02:07 +01:00
|
|
|
|
2015-07-03 18:43:14 +01:00
|
|
|
}
|
|
|
|
}
|
2015-07-03 08:51:41 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}// QCD
|
|
|
|
}// Grid
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|