mirror of
				https://github.com/paboyle/Grid.git
				synced 2025-11-04 05:54:32 +00:00 
			
		
		
		
	Reunitarise. Complete the HMC and integrator changes.
This commit is contained in:
		@@ -178,6 +178,7 @@ GridUnopClass(UnaryConj,conjugate(a));
 | 
			
		||||
GridUnopClass(UnaryTrace,trace(a));
 | 
			
		||||
GridUnopClass(UnaryTranspose,transpose(a));
 | 
			
		||||
GridUnopClass(UnaryTa,Ta(a));
 | 
			
		||||
GridUnopClass(UnaryProjectOnGroup,ProjectOnGroup(a));
 | 
			
		||||
GridUnopClass(UnaryReal,real(a));
 | 
			
		||||
GridUnopClass(UnaryImag,imag(a));
 | 
			
		||||
GridUnopClass(UnaryToReal,toReal(a));
 | 
			
		||||
@@ -290,6 +291,7 @@ GRID_DEF_UNOP(conjugate,UnaryConj);
 | 
			
		||||
GRID_DEF_UNOP(trace,UnaryTrace);
 | 
			
		||||
GRID_DEF_UNOP(transpose,UnaryTranspose);
 | 
			
		||||
GRID_DEF_UNOP(Ta,UnaryTa);
 | 
			
		||||
GRID_DEF_UNOP(ProjectOnGroup,UnaryProjectOnGroup);
 | 
			
		||||
GRID_DEF_UNOP(real,UnaryReal);
 | 
			
		||||
GRID_DEF_UNOP(imag,UnaryImag);
 | 
			
		||||
GRID_DEF_UNOP(toReal,UnaryToReal);
 | 
			
		||||
 
 | 
			
		||||
@@ -73,7 +73,6 @@ namespace Grid{
 | 
			
		||||
      //      void register_observers();
 | 
			
		||||
      //      void notify_observers();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
      void update_P(GaugeField&U, int level,double ep){
 | 
			
		||||
	t_P[level]+=ep;
 | 
			
		||||
	update_P(P,U,level,ep);
 | 
			
		||||
@@ -82,6 +81,7 @@ namespace Grid{
 | 
			
		||||
	for(int l=0; l<level;++l) std::cout<<"   ";	    
 | 
			
		||||
	std::cout<<"["<<level<<"] P " << " dt "<< ep <<" : t_P "<< t_P[level] <<std::endl;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      void update_P(GaugeField &Mom,GaugeField&U, int level,double ep){
 | 
			
		||||
	for(int a=0; a<as[level].actions.size(); ++a){
 | 
			
		||||
	  GaugeField force(U._grid);
 | 
			
		||||
@@ -108,18 +108,12 @@ namespace Grid{
 | 
			
		||||
	  auto Umu=PeekIndex<LorentzIndex>(U, mu);
 | 
			
		||||
	  auto Pmu=PeekIndex<LorentzIndex>(Mom, mu);
 | 
			
		||||
	  Umu = expMat(Pmu, ep, Params.Nexp)*Umu;
 | 
			
		||||
	  ProjectOnGroup(Umu);
 | 
			
		||||
	  PokeIndex<LorentzIndex>(U, Umu, mu);
 | 
			
		||||
	}
 | 
			
		||||
      }
 | 
			
		||||
      
 | 
			
		||||
      /*
 | 
			
		||||
	friend void Algorithm::step (GaugeField& U, 
 | 
			
		||||
				   int level, 
 | 
			
		||||
				   std::vector<int>& clock,
 | 
			
		||||
				   Integrator<GaugeField,Algorithm>* Integ);
 | 
			
		||||
      */
 | 
			
		||||
 | 
			
		||||
      virtual void step (GaugeField& U,int level, std::vector<int>& clock)=0;
 | 
			
		||||
      virtual void step (GaugeField& U,int level, int first,int last)=0;
 | 
			
		||||
 | 
			
		||||
    public:
 | 
			
		||||
 | 
			
		||||
@@ -178,23 +172,28 @@ namespace Grid{
 | 
			
		||||
 | 
			
		||||
      void integrate(GaugeField& U){
 | 
			
		||||
 | 
			
		||||
	std::vector<int> clock;
 | 
			
		||||
	// reset the clocks
 | 
			
		||||
	t_U=0;
 | 
			
		||||
	for(int level=0; level<as.size(); ++level){
 | 
			
		||||
	  t_P[level]=0;
 | 
			
		||||
	}	
 | 
			
		||||
 | 
			
		||||
	clock.resize(as.size(),0);
 | 
			
		||||
 | 
			
		||||
	// All the clock stuff is removed if we pass first, last to the step down the way
 | 
			
		||||
	for(int step=0; step< Params.MDsteps; ++step){   // MD step
 | 
			
		||||
	  int first_step = (step==0);
 | 
			
		||||
	  int  last_step = (step==Params.MDsteps-1);
 | 
			
		||||
	  this->step(U,0,clock);
 | 
			
		||||
	  this->step(U,0,first_step,last_step);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Check the clocks all match
 | 
			
		||||
	// 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<<GridLogMessage<<" 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);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
      }
 | 
			
		||||
    };
 | 
			
		||||
    
 | 
			
		||||
 
 | 
			
		||||
@@ -68,12 +68,12 @@ namespace Grid{
 | 
			
		||||
 | 
			
		||||
      typedef LeapFrog<GaugeField> Algorithm;
 | 
			
		||||
 | 
			
		||||
    LeapFrog(GridBase* grid, 
 | 
			
		||||
	     IntegratorParameters Par,
 | 
			
		||||
	     ActionSet<GaugeField> & Aset): Integrator<GaugeField>(grid,Par,Aset) {};
 | 
			
		||||
      LeapFrog(GridBase* grid, 
 | 
			
		||||
	       IntegratorParameters Par,
 | 
			
		||||
	       ActionSet<GaugeField> & Aset): Integrator<GaugeField>(grid,Par,Aset) {};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
      void step (GaugeField& U, int level, std::vector<int>& clock){
 | 
			
		||||
      void step (GaugeField& U, int level,int _first, int _last){
 | 
			
		||||
 | 
			
		||||
	int fl = this->as.size() -1;
 | 
			
		||||
	// level  : current level
 | 
			
		||||
@@ -81,34 +81,27 @@ namespace Grid{
 | 
			
		||||
	// eps    : current step size
 | 
			
		||||
	
 | 
			
		||||
	// Get current level step size
 | 
			
		||||
	int fin = 2*this->Params.MDsteps;
 | 
			
		||||
	for(int l=0; l<=level; ++l) fin*= this->as[l].multiplier;
 | 
			
		||||
	fin = fin-1;
 | 
			
		||||
 | 
			
		||||
	RealD eps = this->Params.stepsize;
 | 
			
		||||
        RealD eps = this->Params.stepsize;
 | 
			
		||||
	for(int l=0; l<=level; ++l) eps/= this->as[l].multiplier;
 | 
			
		||||
	
 | 
			
		||||
	int multiplier = this->as[level].multiplier;
 | 
			
		||||
	for(int e=0; e<multiplier; ++e){
 | 
			
		||||
 | 
			
		||||
	  int first_step,last_step;
 | 
			
		||||
 | 
			
		||||
	  first_step = (clock[level]==0);
 | 
			
		||||
	  int first_step = _first && (e==0);
 | 
			
		||||
	  int last_step  = _last  && (e==multiplier-1);
 | 
			
		||||
 | 
			
		||||
	  if(first_step){    // initial half step
 | 
			
		||||
	    this->update_P(U, level,eps/2.0);	    ++clock[level];
 | 
			
		||||
	    this->update_P(U, level,eps/2.0);
 | 
			
		||||
	  }
 | 
			
		||||
 | 
			
		||||
	  if(level == fl){          // lowest level
 | 
			
		||||
	    this->update_U(U, eps);
 | 
			
		||||
	  }else{                 // recursive function call
 | 
			
		||||
	    this->step(U, level+1,clock);
 | 
			
		||||
	    this->step(U, level+1,first_step,last_step);
 | 
			
		||||
	  }
 | 
			
		||||
 | 
			
		||||
	  last_step  = (clock[level]==fin);
 | 
			
		||||
	  int mm = last_step ? 1 : 2;
 | 
			
		||||
	  this->update_P(U, level,mm*eps/2.0);	    
 | 
			
		||||
	  clock[level]+=mm;
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
      }
 | 
			
		||||
@@ -124,7 +117,7 @@ namespace Grid{
 | 
			
		||||
		   IntegratorParameters Par,
 | 
			
		||||
		   ActionSet<GaugeField> & Aset): Integrator<GaugeField>(grid,Par,Aset) {};
 | 
			
		||||
 | 
			
		||||
      void step (GaugeField& U, int level, std::vector<int>& clock){
 | 
			
		||||
      void step (GaugeField& U, int level, int _first,int _last){
 | 
			
		||||
 | 
			
		||||
	// level  : current level
 | 
			
		||||
	// fl     : final level
 | 
			
		||||
@@ -132,43 +125,38 @@ namespace Grid{
 | 
			
		||||
 | 
			
		||||
	int fl = this->as.size() -1;
 | 
			
		||||
 | 
			
		||||
	RealD eps = this->Params.stepsize;
 | 
			
		||||
	
 | 
			
		||||
	for(int l=0; l<=level; ++l) eps/= 2.0*this->as[l].multiplier;
 | 
			
		||||
	
 | 
			
		||||
	// which is final half step
 | 
			
		||||
	int fin = this->as[0].multiplier;
 | 
			
		||||
	for(int l=1; l<=level; ++l) fin*= 2.0*this->as[l].multiplier;
 | 
			
		||||
	fin = 3*this->Params.MDsteps*fin -1;
 | 
			
		||||
	RealD eps = this->Params.stepsize*2.0;                              
 | 
			
		||||
	for(int l=0; l<=level; ++l) eps/= 2.0*this->as[l].multiplier;   
 | 
			
		||||
 | 
			
		||||
	// Nesting:  2xupdate_U of size eps/2
 | 
			
		||||
	// Next level is eps/2/multiplier
 | 
			
		||||
 | 
			
		||||
	int multiplier = this->as[level].multiplier;
 | 
			
		||||
	for(int e=0; e<multiplier; ++e){       // steps per step
 | 
			
		||||
 | 
			
		||||
	  int first_step,last_step;
 | 
			
		||||
 | 
			
		||||
	  first_step = (clock[level]==0);
 | 
			
		||||
	  int first_step = _first && (e==0);
 | 
			
		||||
	  int last_step  = _last  && (e==multiplier-1);
 | 
			
		||||
 | 
			
		||||
	  if(first_step){    // initial half step 
 | 
			
		||||
	    this->update_P(U,level,lambda*eps);   ++clock[level];
 | 
			
		||||
	    this->update_P(U,level,lambda*eps);
 | 
			
		||||
	  }
 | 
			
		||||
	  
 | 
			
		||||
	  if(level == fl){          // lowest level 
 | 
			
		||||
	    this->update_U(U,0.5*eps);
 | 
			
		||||
	  }else{                 // recursive function call 
 | 
			
		||||
	    this->step(U,level+1,clock);
 | 
			
		||||
	    this->step(U,level+1,first_step,0);
 | 
			
		||||
	  }
 | 
			
		||||
	  
 | 
			
		||||
	  this->update_P(U,level,(1.0-2.0*lambda)*eps); ++clock[level];
 | 
			
		||||
	  this->update_P(U,level,(1.0-2.0*lambda)*eps);
 | 
			
		||||
	  
 | 
			
		||||
	  if(level == fl){          // lowest level 
 | 
			
		||||
	    this->update_U(U,0.5*eps);
 | 
			
		||||
	  }else{                 // recursive function call 
 | 
			
		||||
	    this->step(U,level+1,clock);
 | 
			
		||||
	    this->step(U,level+1,0,last_step);
 | 
			
		||||
	  }    
 | 
			
		||||
	  
 | 
			
		||||
	  last_step  = (clock[level]==fin);
 | 
			
		||||
	  int mm = (last_step) ? 1 : 2;
 | 
			
		||||
	  this->update_P(U,level,lambda*eps*mm); clock[level]+=mm;
 | 
			
		||||
	  this->update_P(U,level,lambda*eps*mm);
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
      }
 | 
			
		||||
@@ -207,50 +195,43 @@ namespace Grid{
 | 
			
		||||
	this->update_P(Ufg,level,ep);
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      void step (GaugeField& U, int level, std::vector<int>& clock){
 | 
			
		||||
      void step (GaugeField& U, int level, int _first,int _last){
 | 
			
		||||
 | 
			
		||||
	RealD eps = this->Params.stepsize;
 | 
			
		||||
	RealD eps = this->Params.stepsize*2.0;                              
 | 
			
		||||
	for(int l=0; l<=level; ++l) eps/= 2.0*this->as[l].multiplier;
 | 
			
		||||
 | 
			
		||||
	RealD Theta = theta*eps*eps*eps;
 | 
			
		||||
	RealD Chi   = chi*eps*eps*eps;
 | 
			
		||||
 | 
			
		||||
	int fl = this->as.size() -1;
 | 
			
		||||
	
 | 
			
		||||
	// which is final half step
 | 
			
		||||
	int fin = this->as[0].multiplier;
 | 
			
		||||
	for(int l=1; l<=level; ++l) fin*= 2.0*this->as[l].multiplier;
 | 
			
		||||
	fin = 3*this->Params.MDsteps*fin -1;
 | 
			
		||||
 | 
			
		||||
	int multiplier = this->as[level].multiplier;
 | 
			
		||||
 | 
			
		||||
	for(int e=0; e<multiplier; ++e){       // steps per step
 | 
			
		||||
 | 
			
		||||
	  int first_step,last_step;
 | 
			
		||||
 | 
			
		||||
	  first_step = (clock[level]==0);
 | 
			
		||||
	  int first_step = _first && (e==0);
 | 
			
		||||
	  int last_step  = _last  && (e==multiplier-1);
 | 
			
		||||
 | 
			
		||||
	  if(first_step){    // initial half step 
 | 
			
		||||
	    this->update_P(U,level,lambda*eps);   ++clock[level];
 | 
			
		||||
	    this->update_P(U,level,lambda*eps);
 | 
			
		||||
	  }
 | 
			
		||||
	  
 | 
			
		||||
	  if(level == fl){          // lowest level 
 | 
			
		||||
	    this->update_U(U,0.5*eps);
 | 
			
		||||
	  }else{                 // recursive function call 
 | 
			
		||||
	    this->step(U,level+1,clock);
 | 
			
		||||
	    this->step(U,level+1,first_step,0);
 | 
			
		||||
	  }
 | 
			
		||||
	  
 | 
			
		||||
	  this->FG_update_P(U,level,2*Chi/((1.0-2.0*lambda)*eps),(1.0-2.0*lambda)*eps); ++clock[level];
 | 
			
		||||
	  this->FG_update_P(U,level,2*Chi/((1.0-2.0*lambda)*eps),(1.0-2.0*lambda)*eps);
 | 
			
		||||
	  
 | 
			
		||||
	  if(level == fl){          // lowest level 
 | 
			
		||||
	    this->update_U(U,0.5*eps);
 | 
			
		||||
	  }else{                 // recursive function call 
 | 
			
		||||
	    this->step(U,level+1,clock);
 | 
			
		||||
	    this->step(U,level+1,0,last_step);
 | 
			
		||||
	  }    
 | 
			
		||||
	  
 | 
			
		||||
	  last_step  = (clock[level]==fin);
 | 
			
		||||
	  int mm = (last_step) ? 1 : 2;
 | 
			
		||||
	  this->update_P(U,level,lambda*eps*mm); clock[level]+=mm;
 | 
			
		||||
	  this->update_P(U,level,lambda*eps*mm); 
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
      }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user