mirror of
https://github.com/paboyle/Grid.git
synced 2025-06-16 06:47:06 +01:00
Added laplacian operator for smearing sources
This commit is contained in:
@ -30,168 +30,57 @@ directory
|
||||
#ifndef COVARIANT_LAPLACIAN_H
|
||||
#define COVARIANT_LAPLACIAN_H
|
||||
|
||||
namespace Grid {
|
||||
namespace QCD {
|
||||
|
||||
struct LaplacianParams : Serializable {
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(LaplacianParams,
|
||||
RealD, lo,
|
||||
RealD, hi,
|
||||
int, MaxIter,
|
||||
RealD, tolerance,
|
||||
int, degree,
|
||||
int, precision);
|
||||
|
||||
// constructor
|
||||
LaplacianParams(RealD lo = 0.0,
|
||||
RealD hi = 1.0,
|
||||
int maxit = 1000,
|
||||
RealD tol = 1.0e-8,
|
||||
int degree = 10,
|
||||
int precision = 64)
|
||||
: lo(lo),
|
||||
hi(hi),
|
||||
MaxIter(maxit),
|
||||
tolerance(tol),
|
||||
degree(degree),
|
||||
precision(precision){};
|
||||
};
|
||||
|
||||
|
||||
namespace Grid
|
||||
{
|
||||
namespace QCD
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Laplacian operator L on adjoint fields
|
||||
// Laplacian operator L on fermion fields
|
||||
//
|
||||
// phi: adjoint field
|
||||
// L: D_mu^dag D_mu
|
||||
// phi: fermion field
|
||||
//
|
||||
// L phi(x) = Sum_mu [ U_mu(x)phi(x+mu)U_mu(x)^dag +
|
||||
// U_mu(x-mu)^dag phi(x-mu)U_mu(x-mu)
|
||||
// -2phi(x)]
|
||||
// L phi(x) = Sum_mu [ U_mu(x) phi(x+mu) + U_mu(x-mu) phi(x-mu) - 2phi(x)]
|
||||
//
|
||||
// Operator designed to be encapsulated by
|
||||
// an HermitianLinearOperator<.. , ..>
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
// has to inherit from a fermion implementation
|
||||
template <class Impl>
|
||||
class LaplacianAdjointField: public Metric<typename Impl::Field> {
|
||||
OperatorFunction<typename Impl::Field> &Solver;
|
||||
LaplacianParams param;
|
||||
MultiShiftFunction PowerHalf;
|
||||
MultiShiftFunction PowerInvHalf;
|
||||
class Laplacian
|
||||
{
|
||||
public:
|
||||
INHERIT_IMPL_TYPES(Impl);
|
||||
|
||||
public:
|
||||
INHERIT_GIMPL_TYPES(Impl);
|
||||
// add a bool to smear only in the spatial directions
|
||||
Laplacian(GridBase *grid, bool spatial = false)
|
||||
: U(Nd, grid), spatial_laplacian(spatial){};
|
||||
|
||||
LaplacianAdjointField(GridBase* grid, OperatorFunction<GaugeField>& S, LaplacianParams& p, const RealD k = 1.0)
|
||||
: U(Nd, grid), Solver(S), param(p), kappa(k){
|
||||
AlgRemez remez(param.lo,param.hi,param.precision);
|
||||
std::cout<<GridLogMessage << "Generating degree "<<param.degree<<" for x^(1/2)"<<std::endl;
|
||||
remez.generateApprox(param.degree,1,2);
|
||||
PowerHalf.Init(remez,param.tolerance,false);
|
||||
PowerInvHalf.Init(remez,param.tolerance,true);
|
||||
|
||||
void Mdir(const FermionField &, FermionField &, int, int) { assert(0); }
|
||||
void Mdiag(const FermionField &, FermionField &) { assert(0); }
|
||||
|
||||
};
|
||||
|
||||
void Mdir(const GaugeField&, GaugeField&, int, int){ assert(0);}
|
||||
void Mdiag(const GaugeField&, GaugeField&){ assert(0);}
|
||||
|
||||
void ImportGauge(const GaugeField& _U) {
|
||||
for (int mu = 0; mu < Nd; mu++) {
|
||||
void ImportGauge(const GaugeField &_U)
|
||||
{
|
||||
for (int mu = 0; mu < Nd; mu++)
|
||||
U[mu] = PeekIndex<LorentzIndex>(_U, mu);
|
||||
}
|
||||
}
|
||||
|
||||
void M(const GaugeField& in, GaugeField& out) {
|
||||
// in is an antihermitian matrix
|
||||
// test
|
||||
//GaugeField herm = in + adj(in);
|
||||
//std::cout << "AHermiticity: " << norm2(herm) << std::endl;
|
||||
void M(const FermionField &in, FermionField &out)
|
||||
{
|
||||
int dims = spatial_laplacian ? (Nd - 1) : Nd;
|
||||
|
||||
GaugeLinkField tmp(in._grid);
|
||||
GaugeLinkField tmp2(in._grid);
|
||||
GaugeLinkField sum(in._grid);
|
||||
|
||||
for (int nu = 0; nu < Nd; nu++) {
|
||||
sum = zero;
|
||||
GaugeLinkField in_nu = PeekIndex<LorentzIndex>(in, nu);
|
||||
GaugeLinkField out_nu(out._grid);
|
||||
for (int mu = 0; mu < Nd; mu++) {
|
||||
tmp = U[mu] * Cshift(in_nu, mu, +1) * adj(U[mu]);
|
||||
tmp2 = adj(U[mu]) * in_nu * U[mu];
|
||||
sum += tmp + Cshift(tmp2, mu, -1) - 2.0 * in_nu;
|
||||
}
|
||||
out_nu = (1.0 - kappa) * in_nu - kappa / (double(4 * Nd)) * sum;
|
||||
PokeIndex<LorentzIndex>(out, out_nu, nu);
|
||||
}
|
||||
out = -2.0 * dims * in;
|
||||
// eventually speed up with the stencil operator, if necessary
|
||||
for (int mu = 0; mu < dims; mu++)
|
||||
out += Impl::CovShiftForward(U[mu], mu, in) + Impl::CovShiftBackward(U[mu], mu, in);
|
||||
}
|
||||
|
||||
void MDeriv(const GaugeField& in, GaugeField& der) {
|
||||
// in is anti-hermitian
|
||||
RealD factor = -kappa / (double(4 * Nd));
|
||||
|
||||
for (int mu = 0; mu < Nd; mu++){
|
||||
GaugeLinkField der_mu(der._grid);
|
||||
der_mu = zero;
|
||||
for (int nu = 0; nu < Nd; nu++){
|
||||
GaugeLinkField in_nu = PeekIndex<LorentzIndex>(in, nu);
|
||||
der_mu += U[mu] * Cshift(in_nu, mu, 1) * adj(U[mu]) * in_nu;
|
||||
}
|
||||
// the minus sign comes by using the in_nu instead of the
|
||||
// adjoint in the last multiplication
|
||||
PokeIndex<LorentzIndex>(der, -2.0 * factor * der_mu, mu);
|
||||
}
|
||||
}
|
||||
|
||||
// separating this temporarily
|
||||
void MDeriv(const GaugeField& left, const GaugeField& right,
|
||||
GaugeField& der) {
|
||||
// in is anti-hermitian
|
||||
RealD factor = -kappa / (double(4 * Nd));
|
||||
|
||||
for (int mu = 0; mu < Nd; mu++) {
|
||||
GaugeLinkField der_mu(der._grid);
|
||||
der_mu = zero;
|
||||
for (int nu = 0; nu < Nd; nu++) {
|
||||
GaugeLinkField left_nu = PeekIndex<LorentzIndex>(left, nu);
|
||||
GaugeLinkField right_nu = PeekIndex<LorentzIndex>(right, nu);
|
||||
der_mu += U[mu] * Cshift(left_nu, mu, 1) * adj(U[mu]) * right_nu;
|
||||
der_mu += U[mu] * Cshift(right_nu, mu, 1) * adj(U[mu]) * left_nu;
|
||||
}
|
||||
PokeIndex<LorentzIndex>(der, -factor * der_mu, mu);
|
||||
}
|
||||
}
|
||||
|
||||
void Minv(const GaugeField& in, GaugeField& inverted){
|
||||
HermitianLinearOperator<LaplacianAdjointField<Impl>,GaugeField> HermOp(*this);
|
||||
Solver(HermOp, in, inverted);
|
||||
}
|
||||
|
||||
void MSquareRoot(GaugeField& P){
|
||||
GaugeField Gp(P._grid);
|
||||
HermitianLinearOperator<LaplacianAdjointField<Impl>,GaugeField> HermOp(*this);
|
||||
ConjugateGradientMultiShift<GaugeField> msCG(param.MaxIter,PowerHalf);
|
||||
msCG(HermOp,P,Gp);
|
||||
P = Gp;
|
||||
}
|
||||
|
||||
void MInvSquareRoot(GaugeField& P){
|
||||
GaugeField Gp(P._grid);
|
||||
HermitianLinearOperator<LaplacianAdjointField<Impl>,GaugeField> HermOp(*this);
|
||||
ConjugateGradientMultiShift<GaugeField> msCG(param.MaxIter,PowerInvHalf);
|
||||
msCG(HermOp,P,Gp);
|
||||
P = Gp;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private:
|
||||
RealD kappa;
|
||||
private:
|
||||
bool spatial_laplacian;
|
||||
std::vector<GaugeLinkField> U;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}; // Laplacian
|
||||
|
||||
} // QCD
|
||||
} // Grid
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user