2015-07-06 08:46:43 +01:00
|
|
|
//--------------------------------------------------------------------
|
|
|
|
/*! @file Integrator.h
|
2015-07-07 06:59:37 +01:00
|
|
|
* @brief Classes for the Molecular Dynamics integrator
|
2015-07-06 08:46:43 +01:00
|
|
|
*
|
|
|
|
* @author Guido Cossu
|
2015-07-30 09:16:04 +01:00
|
|
|
* Time-stamp: <2015-07-30 16:21:29 neo>
|
2015-07-06 08:46:43 +01:00
|
|
|
*/
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
|
|
|
|
#ifndef INTEGRATOR_INCLUDED
|
|
|
|
#define INTEGRATOR_INCLUDED
|
|
|
|
|
2015-08-30 12:18:34 +01:00
|
|
|
//class Observer;
|
2015-07-06 08:46:43 +01:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
namespace Grid{
|
|
|
|
namespace QCD{
|
|
|
|
|
|
|
|
struct IntegratorParameters{
|
2015-08-30 12:18:34 +01:00
|
|
|
|
2015-07-06 08:46:43 +01:00
|
|
|
int Nexp;
|
|
|
|
int MDsteps; // number of outer steps
|
|
|
|
RealD trajL; // trajectory length
|
|
|
|
RealD stepsize;
|
|
|
|
|
|
|
|
IntegratorParameters(int Nexp_,
|
|
|
|
int MDsteps_,
|
|
|
|
RealD trajL_):
|
2015-08-30 12:18:34 +01:00
|
|
|
Nexp(Nexp_),
|
|
|
|
MDsteps(MDsteps_),
|
|
|
|
trajL(trajL_),
|
|
|
|
stepsize(trajL/MDsteps)
|
|
|
|
{
|
|
|
|
// empty body constructor
|
|
|
|
};
|
|
|
|
|
2015-07-06 08:46:43 +01:00
|
|
|
};
|
|
|
|
|
2015-08-30 12:18:34 +01:00
|
|
|
// Should match any legal (SU(n)) gauge field
|
|
|
|
// Need to use this template to match Ncol to pass to SU<N> class
|
|
|
|
template<int Ncol,class vec> void generate_momenta(Lattice< iVector< iScalar< iMatrix<vec,Ncol> >, Nd> > & P,GridParallelRNG& pRNG){
|
|
|
|
typedef Lattice< iScalar< iScalar< iMatrix<vec,Ncol> > > > GaugeLinkField;
|
|
|
|
GaugeLinkField Pmu(P._grid);
|
|
|
|
Pmu = zero;
|
|
|
|
for(int mu=0;mu<Nd;mu++){
|
|
|
|
SU<Ncol>::GaussianLieAlgebraMatrix(pRNG, Pmu);
|
|
|
|
PokeIndex<LorentzIndex>(P, Pmu, mu);
|
|
|
|
}
|
2015-07-06 08:46:43 +01:00
|
|
|
}
|
|
|
|
|
2015-08-30 12:18:34 +01:00
|
|
|
template<class GaugeField> struct ActionLevel{
|
|
|
|
public:
|
|
|
|
|
|
|
|
typedef Action<GaugeField>* ActPtr; // now force the same colours as the rest of the code
|
|
|
|
|
|
|
|
int multiplier;
|
|
|
|
|
|
|
|
std::vector<ActPtr> actions;
|
|
|
|
|
|
|
|
ActionLevel(int mul = 1) : multiplier(mul) {
|
|
|
|
assert (mul > 0);
|
|
|
|
};
|
|
|
|
|
|
|
|
void push_back(ActPtr ptr){
|
|
|
|
actions.push_back(ptr);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class GaugeField> using ActionSet = std::vector<ActionLevel< GaugeField > >;
|
|
|
|
|
2015-07-06 08:46:43 +01:00
|
|
|
/*! @brief Class for Molecular Dynamics management */
|
2015-08-30 12:18:34 +01:00
|
|
|
template<class GaugeField, class Algorithm >
|
|
|
|
class Integrator : public Algorithm {
|
2015-08-29 17:18:43 +01:00
|
|
|
|
2015-08-30 12:18:34 +01:00
|
|
|
private:
|
2015-08-29 17:18:43 +01:00
|
|
|
|
2015-07-06 08:46:43 +01:00
|
|
|
IntegratorParameters Params;
|
2015-08-29 17:18:43 +01:00
|
|
|
|
2015-08-30 12:18:34 +01:00
|
|
|
GridParallelRNG pRNG; // Store this somewhere more sensible and pass as reference
|
|
|
|
const ActionSet<GaugeField> as;
|
|
|
|
|
|
|
|
int levels; //
|
|
|
|
double t_U; // Track time passing on each level and for U and for P
|
|
|
|
std::vector<double> t_P; //
|
2015-07-06 08:46:43 +01:00
|
|
|
|
2015-08-30 12:18:34 +01:00
|
|
|
GaugeField P; // is a pointer really necessary?
|
2015-08-29 17:18:43 +01:00
|
|
|
|
2015-08-30 12:18:34 +01:00
|
|
|
//ObserverList observers; // not yet
|
|
|
|
// typedef std::vector<Observer*> ObserverList;
|
|
|
|
// void register_observers();
|
|
|
|
// void notify_observers();
|
2015-07-06 08:46:43 +01:00
|
|
|
|
2015-08-30 12:18:34 +01:00
|
|
|
|
|
|
|
void update_P(GaugeField&U, int level,double ep){
|
2015-08-29 17:18:43 +01:00
|
|
|
t_P[level]+=ep;
|
2015-07-06 10:32:20 +01:00
|
|
|
for(int a=0; a<as[level].actions.size(); ++a){
|
2015-08-30 12:18:34 +01:00
|
|
|
GaugeField force(U._grid);
|
2015-07-06 10:32:20 +01:00
|
|
|
as[level].actions.at(a)->deriv(U,force);
|
2015-08-30 12:18:34 +01:00
|
|
|
P = P - force*ep;
|
2015-07-06 08:46:43 +01:00
|
|
|
}
|
2015-08-30 12:18:34 +01:00
|
|
|
|
2015-08-29 17:18:43 +01:00
|
|
|
std::cout<<GridLogMessage;
|
|
|
|
for(int l=0; l<level;++l) std::cout<<" ";
|
|
|
|
std::cout<<"["<<level<<"] P " << " dt "<< ep <<" : t_P "<< t_P[level] <<std::endl;
|
2015-08-30 12:18:34 +01:00
|
|
|
|
2015-07-06 08:46:43 +01:00
|
|
|
}
|
|
|
|
|
2015-08-30 12:18:34 +01:00
|
|
|
void update_U(GaugeField&U, double ep){
|
2015-07-06 08:46:43 +01:00
|
|
|
//rewrite exponential to deal automatically with the lorentz index?
|
2015-08-30 12:18:34 +01:00
|
|
|
// GaugeLinkField Umu(U._grid);
|
|
|
|
// GaugeLinkField Pmu(U._grid);
|
2015-07-06 08:46:43 +01:00
|
|
|
for (int mu = 0; mu < Nd; mu++){
|
2015-08-30 12:18:34 +01:00
|
|
|
auto Umu=PeekIndex<LorentzIndex>(U, mu);
|
|
|
|
auto Pmu=PeekIndex<LorentzIndex>(P, mu);
|
2015-07-06 08:46:43 +01:00
|
|
|
Umu = expMat(Pmu, ep, Params.Nexp)*Umu;
|
2015-07-21 05:52:59 +01:00
|
|
|
PokeIndex<LorentzIndex>(U, Umu, mu);
|
2015-07-06 08:46:43 +01:00
|
|
|
}
|
2015-08-30 12:18:34 +01:00
|
|
|
|
2015-08-29 17:18:43 +01:00
|
|
|
t_U+=ep;
|
|
|
|
int fl = levels-1;
|
|
|
|
std::cout<<GridLogMessage<<" ";
|
|
|
|
for(int l=0; l<fl;++l) std::cout<<" ";
|
|
|
|
std::cout<<"["<<fl<<"] U " << " dt "<< ep <<" : t_U "<< t_U <<std::endl;
|
2015-08-30 12:18:34 +01:00
|
|
|
|
2015-07-06 08:46:43 +01:00
|
|
|
}
|
|
|
|
|
2015-08-30 12:18:34 +01:00
|
|
|
friend void Algorithm::step (GaugeField& U,
|
|
|
|
int level,
|
|
|
|
std::vector<int>& clock,
|
|
|
|
Integrator<GaugeField,Algorithm>* Integ);
|
|
|
|
|
2015-07-06 08:46:43 +01:00
|
|
|
public:
|
2015-08-29 17:18:43 +01:00
|
|
|
|
|
|
|
Integrator(GridBase* grid,
|
|
|
|
IntegratorParameters Par,
|
2015-08-30 12:18:34 +01:00
|
|
|
ActionSet<GaugeField> & Aset):
|
2015-08-29 17:18:43 +01:00
|
|
|
Params(Par),
|
|
|
|
as(Aset),
|
2015-08-30 12:18:34 +01:00
|
|
|
P(grid),
|
2015-08-29 17:18:43 +01:00
|
|
|
pRNG(grid),
|
|
|
|
levels(Aset.size())
|
|
|
|
{
|
2015-08-30 12:18:34 +01:00
|
|
|
std::vector<int> seeds({1,2,3,4,5}); // Fixme; Pass it the RNG as a ref
|
2015-08-29 17:18:43 +01:00
|
|
|
pRNG.SeedFixedIntegers(seeds);
|
|
|
|
|
|
|
|
t_P.resize(levels,0.0);
|
|
|
|
t_U=0.0;
|
2015-07-06 08:46:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
~Integrator(){}
|
|
|
|
|
|
|
|
//Initialization of momenta and actions
|
2015-08-30 12:18:34 +01:00
|
|
|
void init(GaugeField& U){
|
2015-07-23 17:31:13 +01:00
|
|
|
std::cout<<GridLogMessage<< "Integrator init\n";
|
2015-08-30 12:18:34 +01:00
|
|
|
generate_momenta(P,pRNG);
|
2015-07-06 08:46:43 +01:00
|
|
|
for(int level=0; level< as.size(); ++level){
|
2015-07-06 10:32:20 +01:00
|
|
|
for(int actionID=0; actionID<as[level].actions.size(); ++actionID){
|
|
|
|
as[level].actions.at(actionID)->init(U, pRNG);
|
2015-07-06 08:46:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate action
|
2015-08-30 12:18:34 +01:00
|
|
|
RealD S(GaugeField& U){
|
|
|
|
|
|
|
|
LatticeComplex Hloc(U._grid); Hloc = zero;
|
2015-07-06 08:46:43 +01:00
|
|
|
// Momenta
|
|
|
|
for (int mu=0; mu <Nd; mu++){
|
2015-08-30 12:18:34 +01:00
|
|
|
auto Pmu = PeekIndex<LorentzIndex>(P, mu);
|
2015-07-06 08:46:43 +01:00
|
|
|
Hloc -= trace(Pmu*Pmu);
|
|
|
|
}
|
|
|
|
Complex Hsum = sum(Hloc);
|
|
|
|
|
|
|
|
RealD H = Hsum.real();
|
2015-08-29 17:18:43 +01:00
|
|
|
RealD Hterm;
|
2015-07-29 09:53:39 +01:00
|
|
|
std::cout<<GridLogMessage << "Momentum action H_p = "<< H << "\n";
|
2015-07-06 08:46:43 +01:00
|
|
|
|
|
|
|
// Actions
|
2015-08-29 17:18:43 +01:00
|
|
|
for(int level=0; level<as.size(); ++level){
|
|
|
|
for(int actionID=0; actionID<as[level].actions.size(); ++actionID){
|
|
|
|
Hterm = as[level].actions.at(actionID)->S(U);
|
|
|
|
std::cout<<GridLogMessage << "Level "<<level<<" term "<<actionID<<" H = "<<Hterm<<std::endl;
|
|
|
|
H += Hterm;
|
|
|
|
}
|
|
|
|
}
|
2015-07-29 09:53:39 +01:00
|
|
|
std::cout<<GridLogMessage << "Total action H = "<< H << "\n";
|
2015-07-06 08:46:43 +01:00
|
|
|
|
|
|
|
return H;
|
|
|
|
}
|
|
|
|
|
2015-08-30 12:18:34 +01:00
|
|
|
void integrate(GaugeField& U){
|
|
|
|
|
2015-07-06 08:46:43 +01:00
|
|
|
std::vector<int> clock;
|
2015-08-30 12:18:34 +01:00
|
|
|
|
2015-07-06 08:46:43 +01:00
|
|
|
clock.resize(as.size(),0);
|
2015-08-30 12:18:34 +01:00
|
|
|
|
|
|
|
// All the clock stuff is removed if we pass first, last to the step down the way
|
2015-08-29 17:18:43 +01:00
|
|
|
for(int step=0; step< Params.MDsteps; ++step){ // MD step
|
2015-08-30 12:18:34 +01:00
|
|
|
Algorithm::step(U,0,clock, (this));
|
2015-08-29 17:18:43 +01:00
|
|
|
}
|
2015-08-30 12:18:34 +01:00
|
|
|
|
|
|
|
// Check the clocks all match
|
2015-08-29 17:18:43 +01:00
|
|
|
for(int level=0; level<as.size(); ++level){
|
2015-08-30 12:18:34 +01:00
|
|
|
assert(fabs(t_U - t_P[level])<1.0e-4);
|
2015-08-29 17:18:43 +01:00
|
|
|
std::cout<<GridLogMessage<<" times["<<level<<"]= "<<t_P[level]<< " " << t_U <<std::endl;
|
|
|
|
}
|
2015-08-30 12:18:34 +01:00
|
|
|
|
2015-07-06 08:46:43 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif//INTEGRATOR_INCLUDED
|