//-------------------------------------------------------------------- /*! @file HMC.h * @brief Classes for Hybrid Monte Carlo update * * @author Guido Cossu * Time-stamp: <2015-07-30 16:58:26 neo> */ //-------------------------------------------------------------------- #ifndef HMC_INCLUDED #define HMC_INCLUDED #include namespace Grid{ namespace QCD{ struct HMCparameters{ 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 HmcObservable { public: virtual void TrajectoryComplete (int traj, GaugeField &U, GridSerialRNG &sRNG, GridParallelRNG & pRNG )=0; }; template class PlaquetteLogger : public HmcObservable { private: std::string Stem; public: PlaquetteLogger(std::string cf) { Stem = cf; }; void TrajectoryComplete(int traj, GaugeField &U, GridSerialRNG &sRNG, GridParallelRNG & pRNG ) { std::string file; { std::ostringstream os; os << Stem <<"."<< traj; file = os.str(); } std::ofstream of(file); RealD plaq = WilsonLoops::avgPlaquette(U); RealD rect = WilsonLoops::avgRectangle(U); of << plaq << " " << rect << std::endl; std::cout<< GridLogMessage<< "Plaquette for trajectory "<< traj << " is " << plaq < template class HybridMonteCarlo { private: const HMCparameters Params; GridSerialRNG &sRNG; // Fixme: need a RNG management strategy. GridParallelRNG &pRNG; // Fixme: need a RNG management strategy. GaugeField & Ucur; IntegratorType &TheIntegrator; std::vector *> Observables; ///////////////////////////////////////////////////////// // Metropolis step ///////////////////////////////////////////////////////// bool metropolis_test(const RealD DeltaH){ RealD rn_test; RealD prob = std::exp(-DeltaH); random(sRNG,rn_test); std::cout<1.0) || (rn_test <= prob)){ // accepted std::cout< *obs) { Observables.push_back(obs); } void evolve(void){ Real DeltaH; GaugeField Ucopy(Ucur._grid); // Actual updates (evolve a copy Ucopy then copy back eventually) for(int traj=Params.StartTrajectory; traj < Params.Trajectories+Params.StartTrajectory; ++traj){ std::cout< Params.NoMetropolisUntil) { accept = metropolis_test(DeltaH); } if ( accept ) { Ucur = Ucopy; } for(int obs = 0;obsTrajectoryComplete (traj+1,Ucur,sRNG,pRNG); } } } }; }// QCD }// Grid #endif