mirror of
				https://github.com/paboyle/Grid.git
				synced 2025-11-04 05:54:32 +00:00 
			
		
		
		
	Testing different versions of the Laplacian
This commit is contained in:
		@@ -47,12 +47,77 @@ class LaplacianAdjointField {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  void Mdiag(const GaugeLinkField& in, GaugeLinkField& out) { assert(0); }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  void Mdir(const GaugeLinkField& in, GaugeLinkField& out, int dir, int disp) { assert(0); }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					  // Operator with algebra vector inputs and outputs
 | 
				
			||||||
 | 
					  void M2(const AVector& in, AVector& out) {
 | 
				
			||||||
 | 
					    double kappa = 0.9;
 | 
				
			||||||
 | 
					    //Reconstruct matrix
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    GaugeLinkField tmp(in._grid);
 | 
				
			||||||
 | 
					    GaugeLinkField tmp2(in._grid);
 | 
				
			||||||
 | 
					    GaugeLinkField sum(in._grid);
 | 
				
			||||||
 | 
					    GaugeLinkField out_mat(in._grid);
 | 
				
			||||||
 | 
					    GaugeLinkField in_mat(in._grid);
 | 
				
			||||||
 | 
					    SU<Nc>::FundamentalLieAlgebraMatrix(in, in_mat);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    sum = zero;
 | 
				
			||||||
 | 
					    for (int mu = 0; mu < Nd; mu++) {
 | 
				
			||||||
 | 
					      tmp  = U[mu] * Cshift(in_mat, mu, +1) * adj(U[mu]);
 | 
				
			||||||
 | 
					      tmp2 = adj(U[mu]) * in_mat * U[mu];
 | 
				
			||||||
 | 
					      sum += tmp + Cshift(tmp2, mu, -1) - 2.0 * in_mat;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    out_mat = (1.0 - kappa) * in_mat - kappa/(double(4*Nd)) * sum;
 | 
				
			||||||
 | 
					    // Project
 | 
				
			||||||
 | 
					    SU<Nc>::projectOnAlgebra(out, out_mat);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    void M(const GaugeLinkField& in, GaugeLinkField& out) {
 | 
				
			||||||
 | 
					    double kappa = 0.999;
 | 
				
			||||||
 | 
					    //Reconstruct matrix
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    GaugeLinkField tmp(in._grid);
 | 
				
			||||||
 | 
					    GaugeLinkField tmp2(in._grid);
 | 
				
			||||||
 | 
					    GaugeLinkField sum(in._grid);
 | 
				
			||||||
 | 
					    sum = zero;
 | 
				
			||||||
 | 
					    for (int mu = 0; mu < Nd; mu++) {
 | 
				
			||||||
 | 
					      tmp  = U[mu] * Cshift(in, mu, +1) * adj(U[mu]);
 | 
				
			||||||
 | 
					      tmp2 = adj(U[mu]) * in * U[mu];
 | 
				
			||||||
 | 
					      sum += tmp + Cshift(tmp2, mu, -1) - 2.0 * in;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    out = (1.0 - kappa) * in - kappa/(double(4*Nd)) * sum;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 private:
 | 
				
			||||||
 | 
					  std::vector<GaugeLinkField> U;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					template <class Impl>
 | 
				
			||||||
 | 
					class LaplacianAlgebraField {
 | 
				
			||||||
 | 
					 public:
 | 
				
			||||||
 | 
					  INHERIT_GIMPL_TYPES(Impl);
 | 
				
			||||||
 | 
					  typedef SU<Nc>::LatticeAlgebraVector AVector;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  LaplacianAlgebraField(GridBase* grid) : U(Nd, grid){};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  void ImportGauge(const GaugeField& _U) {
 | 
				
			||||||
 | 
					    for (int mu = 0; mu < Nd; mu++) {
 | 
				
			||||||
 | 
					      U[mu] = PeekIndex<LorentzIndex>(_U, mu);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void Mdiag(const AVector& in, AVector& out) { assert(0); }
 | 
					  void Mdiag(const AVector& in, AVector& out) { assert(0); }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void Mdir(const AVector& in, AVector& out, int dir, int disp) { assert(0); }
 | 
					  void Mdir(const AVector& in, AVector& out, int dir, int disp) { assert(0); }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Operator with algebra vector inputs and outputs
 | 
				
			||||||
  void M(const AVector& in, AVector& out) {
 | 
					  void M(const AVector& in, AVector& out) {
 | 
				
			||||||
    double kappa = 0.99;
 | 
					    double kappa = 0.999;
 | 
				
			||||||
    //Reconstruct matrix
 | 
					    //Reconstruct matrix
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    GaugeLinkField tmp(in._grid);
 | 
					    GaugeLinkField tmp(in._grid);
 | 
				
			||||||
@@ -76,6 +141,8 @@ class LaplacianAdjointField {
 | 
				
			|||||||
 private:
 | 
					 private:
 | 
				
			||||||
  std::vector<GaugeLinkField> U;
 | 
					  std::vector<GaugeLinkField> U;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -50,15 +50,34 @@ int main (int argc, char ** argv)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  typedef SU<Nc>::LatticeAlgebraVector AVector;
 | 
					  typedef SU<Nc>::LatticeAlgebraVector AVector;
 | 
				
			||||||
  // Source and result in the algebra
 | 
					  // Source and result in the algebra
 | 
				
			||||||
  AVector src(&Grid); random(pRNG,src);
 | 
					  AVector src_vec(&Grid); random(pRNG, src_vec);
 | 
				
			||||||
  AVector result(&Grid); result=zero;
 | 
					  AVector result_vec(&Grid); result_vec = zero;
 | 
				
			||||||
 | 
					  LatticeColourMatrix src(&Grid); 
 | 
				
			||||||
 | 
					  SU<Nc>::FundamentalLieAlgebraMatrix(src_vec, src);
 | 
				
			||||||
 | 
					  LatticeColourMatrix result(&Grid); result=zero;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  LaplacianAdjointField<PeriodicGimplR> Laplacian(&Grid);
 | 
					  LaplacianAdjointField<PeriodicGimplR> Laplacian(&Grid);
 | 
				
			||||||
  Laplacian.ImportGauge(Umu);
 | 
					  Laplacian.ImportGauge(Umu);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  HermitianLinearOperator<LaplacianAdjointField<PeriodicGimplR>,AVector> HermOp(Laplacian);
 | 
					  HermitianLinearOperator<LaplacianAdjointField<PeriodicGimplR>,LatticeColourMatrix> HermOp(Laplacian);
 | 
				
			||||||
  ConjugateGradient<AVector> CG(1.0e-8,10000);
 | 
					  ConjugateGradient<LatticeColourMatrix> CG(1.0e-8,10000);
 | 
				
			||||||
  CG(HermOp,src,result);
 | 
					  CG(HermOp,src,result); // fastest
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Tests also the version using the algebra decomposition
 | 
				
			||||||
 | 
					  LaplacianAlgebraField<PeriodicGimplR> LaplacianAlgebra(&Grid);
 | 
				
			||||||
 | 
					  LaplacianAlgebra.ImportGauge(Umu);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  HermitianLinearOperator<LaplacianAlgebraField<PeriodicGimplR>,AVector> HermOpAlg(LaplacianAlgebra);
 | 
				
			||||||
 | 
					  ConjugateGradient<AVector> CG_Algebra(1.0e-8,10000);
 | 
				
			||||||
 | 
					  CG_Algebra(HermOpAlg,src_vec,result_vec);
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					  LatticeColourMatrix result2(&Grid);
 | 
				
			||||||
 | 
					  SU<Nc>::FundamentalLieAlgebraMatrix(result_vec, result2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  result2 -= result;
 | 
				
			||||||
 | 
					  std::cout << GridLogMessage << "Results difference " << norm2(result2) << std::endl;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  Grid_finalize();
 | 
					  Grid_finalize();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user