mirror of
https://github.com/paboyle/Grid.git
synced 2026-02-17 20:30:53 +00:00
Compare commits
9 Commits
hotfix/unw
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2a8084d569 | ||
|
|
6ff29f9d4f | ||
|
|
7cd3f21e6b | ||
| 4a0aaf0786 | |||
| 9c3835524c | |||
| 549351bb8a | |||
|
|
74e6b19f83 | ||
|
|
2e684028de | ||
| c54d87a472 |
@@ -97,7 +97,7 @@ public:
|
|||||||
|
|
||||||
RealD scale;
|
RealD scale;
|
||||||
|
|
||||||
ConjugateGradient<FineField> CG(1.0e-3,400,false);
|
ConjugateGradient<FineField> CG(1.0e-4,2000,false);
|
||||||
FineField noise(FineGrid);
|
FineField noise(FineGrid);
|
||||||
FineField Mn(FineGrid);
|
FineField Mn(FineGrid);
|
||||||
|
|
||||||
@@ -131,7 +131,7 @@ public:
|
|||||||
RealD scale;
|
RealD scale;
|
||||||
|
|
||||||
TrivialPrecon<FineField> simple_fine;
|
TrivialPrecon<FineField> simple_fine;
|
||||||
PrecGeneralisedConjugateResidualNonHermitian<FineField> GCR(0.001,30,DiracOp,simple_fine,12,12);
|
PrecGeneralisedConjugateResidualNonHermitian<FineField> GCR(0.001,10,DiracOp,simple_fine,30,30);
|
||||||
FineField noise(FineGrid);
|
FineField noise(FineGrid);
|
||||||
FineField src(FineGrid);
|
FineField src(FineGrid);
|
||||||
FineField guess(FineGrid);
|
FineField guess(FineGrid);
|
||||||
@@ -146,16 +146,16 @@ public:
|
|||||||
|
|
||||||
DiracOp.Op(noise,Mn); std::cout<<GridLogMessage << "noise ["<<b<<"] <n|Op|n> "<<innerProduct(noise,Mn)<<std::endl;
|
DiracOp.Op(noise,Mn); std::cout<<GridLogMessage << "noise ["<<b<<"] <n|Op|n> "<<innerProduct(noise,Mn)<<std::endl;
|
||||||
|
|
||||||
for(int i=0;i<2;i++){
|
for(int i=0;i<3;i++){
|
||||||
// void operator() (const Field &src, Field &psi){
|
// void operator() (const Field &src, Field &psi){
|
||||||
#if 1
|
#if 1
|
||||||
std::cout << GridLogMessage << " inverting on noise "<<std::endl;
|
if (i==0)std::cout << GridLogMessage << " inverting on noise "<<std::endl;
|
||||||
src = noise;
|
src = noise;
|
||||||
guess=Zero();
|
guess=Zero();
|
||||||
GCR(src,guess);
|
GCR(src,guess);
|
||||||
subspace[b] = guess;
|
subspace[b] = guess;
|
||||||
#else
|
#else
|
||||||
std::cout << GridLogMessage << " inverting on zero "<<std::endl;
|
if (i==0)std::cout << GridLogMessage << " inverting on zero "<<std::endl;
|
||||||
src=Zero();
|
src=Zero();
|
||||||
guess = noise;
|
guess = noise;
|
||||||
GCR(src,guess);
|
GCR(src,guess);
|
||||||
@@ -167,7 +167,7 @@ public:
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DiracOp.Op(noise,Mn); std::cout<<GridLogMessage << "filtered["<<b<<"] <f|Op|f> "<<innerProduct(noise,Mn)<<std::endl;
|
DiracOp.Op(noise,Mn); std::cout<<GridLogMessage << "filtered["<<b<<"] <f|Op|f> "<<innerProduct(noise,Mn)<<" <f|OpDagOp|f>"<<norm2(Mn)<<std::endl;
|
||||||
subspace[b] = noise;
|
subspace[b] = noise;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
|||||||
/* END LEGAL */
|
/* END LEGAL */
|
||||||
#include <Grid/GridCore.h>
|
#include <Grid/GridCore.h>
|
||||||
|
|
||||||
|
void GridAbort(void) { abort(); }
|
||||||
|
|
||||||
NAMESPACE_BEGIN(Grid);
|
NAMESPACE_BEGIN(Grid);
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -34,7 +36,6 @@ NAMESPACE_BEGIN(Grid);
|
|||||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
Grid_MPI_Comm CartesianCommunicator::communicator_world;
|
Grid_MPI_Comm CartesianCommunicator::communicator_world;
|
||||||
|
|
||||||
void GridAbort(void) { abort(); }
|
|
||||||
|
|
||||||
void CartesianCommunicator::Init(int *argc, char *** arv)
|
void CartesianCommunicator::Init(int *argc, char *** arv)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ template<class vobj> void Cshift_simple(Lattice<vobj>& ret,const Lattice<vobj> &
|
|||||||
void *hsend_buf = (void *)&hrhs[0];
|
void *hsend_buf = (void *)&hrhs[0];
|
||||||
void *hrecv_buf = (void *)&hret[0];
|
void *hrecv_buf = (void *)&hret[0];
|
||||||
|
|
||||||
acceleratorCopyFromDevice(&send_buf[0],&hsend_buf[0],bytes);
|
acceleratorCopyFromDevice(send_buf,hsend_buf,bytes);
|
||||||
|
|
||||||
grid->SendToRecvFrom(hsend_buf,
|
grid->SendToRecvFrom(hsend_buf,
|
||||||
xmit_to_rank,
|
xmit_to_rank,
|
||||||
@@ -132,7 +132,7 @@ template<class vobj> void Cshift_simple(Lattice<vobj>& ret,const Lattice<vobj> &
|
|||||||
recv_from_rank,
|
recv_from_rank,
|
||||||
bytes);
|
bytes);
|
||||||
|
|
||||||
acceleratorCopyToDevice(&hrecv_buf[0],&recv_buf[0],bytes);
|
acceleratorCopyToDevice(hrecv_buf,recv_buf,bytes);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -411,7 +411,7 @@ void WilsonKernels<Impl>::DhopDirKernel( StencilImpl &st, DoubledGaugeField &U,S
|
|||||||
#undef LoopBody
|
#undef LoopBody
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef GRID_SYCL
|
#if 0
|
||||||
extern "C" {
|
extern "C" {
|
||||||
ulong SYCL_EXTERNAL __attribute__((overloadable)) intel_get_cycle_counter( void );
|
ulong SYCL_EXTERNAL __attribute__((overloadable)) intel_get_cycle_counter( void );
|
||||||
uint SYCL_EXTERNAL __attribute__((overloadable)) intel_get_active_channel_mask( void );
|
uint SYCL_EXTERNAL __attribute__((overloadable)) intel_get_active_channel_mask( void );
|
||||||
|
|||||||
@@ -138,10 +138,13 @@ public:
|
|||||||
//auto start = std::chrono::high_resolution_clock::now();
|
//auto start = std::chrono::high_resolution_clock::now();
|
||||||
autoView(U_v,U,AcceleratorWrite);
|
autoView(U_v,U,AcceleratorWrite);
|
||||||
autoView(P_v,P,AcceleratorRead);
|
autoView(P_v,P,AcceleratorRead);
|
||||||
accelerator_for(ss, P.Grid()->oSites(),1,{
|
typedef typename Field::vector_object vobj;
|
||||||
|
const int Nsimd = vobj::Nsimd();
|
||||||
|
accelerator_for(ss, P.Grid()->oSites(),Nsimd,{
|
||||||
for (int mu = 0; mu < Nd; mu++) {
|
for (int mu = 0; mu < Nd; mu++) {
|
||||||
U_v[ss](mu) = Exponentiate(P_v[ss](mu), ep, Nexp) * U_v[ss](mu);
|
auto tmp = Exponentiate(P_v(ss)(mu), ep, Nexp) * U_v(ss)(mu);
|
||||||
U_v[ss](mu) = Group::ProjectOnGeneralGroup(U_v[ss](mu));
|
tmp = Group::ProjectOnGeneralGroup(tmp);
|
||||||
|
coalescedWrite(U_v[ss](mu),tmp);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
//auto end = std::chrono::high_resolution_clock::now();
|
//auto end = std::chrono::high_resolution_clock::now();
|
||||||
|
|||||||
@@ -291,8 +291,8 @@ public:
|
|||||||
int idx=0;
|
int idx=0;
|
||||||
for(int mu=0;mu<4;mu++){
|
for(int mu=0;mu<4;mu++){
|
||||||
for(int nu=0;nu<4;nu++){
|
for(int nu=0;nu<4;nu++){
|
||||||
if ( mu!=nu) GRID_ASSERT(this->StoutSmearing->SmearRho[idx]==rho);
|
if ( mu!=nu) assert(this->StoutSmearing->SmearRho[idx]==rho);
|
||||||
else GRID_ASSERT(this->StoutSmearing->SmearRho[idx]==0.0);
|
else assert(this->StoutSmearing->SmearRho[idx]==0.0);
|
||||||
idx++;
|
idx++;
|
||||||
}}
|
}}
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
@@ -825,6 +825,7 @@ public:
|
|||||||
virtual void fill_smearedSet(GaugeField &U)
|
virtual void fill_smearedSet(GaugeField &U)
|
||||||
{
|
{
|
||||||
this->ThinLinks = &U; // attach the smearing routine to the field U
|
this->ThinLinks = &U; // attach the smearing routine to the field U
|
||||||
|
std::cout << GridLogMessage << " fill_smearedSet " << WilsonLoops<PeriodicGimplR>::avgPlaquette(U) << std::endl;
|
||||||
|
|
||||||
// check the pointer is not null
|
// check the pointer is not null
|
||||||
if (this->ThinLinks == NULL)
|
if (this->ThinLinks == NULL)
|
||||||
@@ -846,6 +847,8 @@ public:
|
|||||||
ApplyMask(smeared_A,smearLvl);
|
ApplyMask(smeared_A,smearLvl);
|
||||||
smeared_B = previous_u;
|
smeared_B = previous_u;
|
||||||
ApplyMask(smeared_B,smearLvl);
|
ApplyMask(smeared_B,smearLvl);
|
||||||
|
std::cout << GridLogMessage << " smeared_A " << norm2(smeared_A) << std::endl;
|
||||||
|
std::cout << GridLogMessage << " smeared_B " << norm2(smeared_B) << std::endl;
|
||||||
// Replace only the masked portion
|
// Replace only the masked portion
|
||||||
this->SmearedSet[smearLvl] = previous_u-smeared_B + smeared_A;
|
this->SmearedSet[smearLvl] = previous_u-smeared_B + smeared_A;
|
||||||
previous_u = this->SmearedSet[smearLvl];
|
previous_u = this->SmearedSet[smearLvl];
|
||||||
@@ -934,10 +937,10 @@ public:
|
|||||||
SmearedConfigurationMasked(GridCartesian* _UGrid, unsigned int Nsmear, Smear_Stout<Gimpl>& Stout)
|
SmearedConfigurationMasked(GridCartesian* _UGrid, unsigned int Nsmear, Smear_Stout<Gimpl>& Stout)
|
||||||
: SmearedConfiguration<Gimpl>(_UGrid, Nsmear,Stout)
|
: SmearedConfiguration<Gimpl>(_UGrid, Nsmear,Stout)
|
||||||
{
|
{
|
||||||
GRID_ASSERT(Nsmear%(2*Nd)==0); // Or multiply by 8??
|
assert(Nsmear%(2*Nd)==0); // Or multiply by 8??
|
||||||
|
|
||||||
// was resized in base class
|
// was resized in base class
|
||||||
GRID_ASSERT(this->SmearedSet.size()==Nsmear);
|
assert(this->SmearedSet.size()==Nsmear);
|
||||||
|
|
||||||
GridRedBlackCartesian * UrbGrid;
|
GridRedBlackCartesian * UrbGrid;
|
||||||
UrbGrid = SpaceTimeGrid::makeFourDimRedBlackGrid(_UGrid);
|
UrbGrid = SpaceTimeGrid::makeFourDimRedBlackGrid(_UGrid);
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public:
|
|||||||
// Usual cases are not used
|
// Usual cases are not used
|
||||||
//////////////////////////////////
|
//////////////////////////////////
|
||||||
virtual void refresh(const GaugeField &U, GridSerialRNG &sRNG, GridParallelRNG &pRNG){ GRID_ASSERT(0);};
|
virtual void refresh(const GaugeField &U, GridSerialRNG &sRNG, GridParallelRNG &pRNG){ GRID_ASSERT(0);};
|
||||||
virtual RealD S(const GaugeField &U) { GRID_ASSERT(0); }
|
virtual RealD S(const GaugeField &U) { GRID_ASSERT(0); return 0; }
|
||||||
virtual void deriv(const GaugeField &U, GaugeField &dSdU) { GRID_ASSERT(0); }
|
virtual void deriv(const GaugeField &U, GaugeField &dSdU) { GRID_ASSERT(0); }
|
||||||
|
|
||||||
//////////////////////////////////
|
//////////////////////////////////
|
||||||
|
|||||||
@@ -763,11 +763,13 @@ public:
|
|||||||
){
|
){
|
||||||
// FIXME worry about duplicate with partial compression
|
// FIXME worry about duplicate with partial compression
|
||||||
// Wont happen as DWF has no duplicates, but...
|
// Wont happen as DWF has no duplicates, but...
|
||||||
AddCopy(CachedTransfers[i].recv_buf,recv_buf,rbytes);
|
// AddCopy(CachedTransfers[i].recv_buf,recv_buf,rbytes);
|
||||||
return 1;
|
// std::cout << "Duplicate dir " <<direction<<" "<<" OrthogPlane "<<OrthogPlane<<" Dest"<<DestProc <<" xbytes " <<xbytes<<" lane "<< lane<<" cb "<<cb<<std::endl;
|
||||||
}
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
|
// return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
CachedTransfers.push_back(obj);
|
CachedTransfers.push_back(obj);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -755,7 +755,7 @@ void Grid_generic_handler(int sig,siginfo_t *si,void * ptr)
|
|||||||
sig_print_uint(si->si_code);
|
sig_print_uint(si->si_code);
|
||||||
SIGLOG("\n");
|
SIGLOG("\n");
|
||||||
|
|
||||||
unw_context_t *uc= (unw_context_t *)ptr;
|
ucontext_t *uc= (ucontext_t *)ptr;
|
||||||
|
|
||||||
SIGLOG("Backtrace:\n");
|
SIGLOG("Backtrace:\n");
|
||||||
#ifdef HAVE_UNWIND
|
#ifdef HAVE_UNWIND
|
||||||
|
|||||||
10
configure.ac
10
configure.ac
@@ -409,16 +409,10 @@ AC_SEARCH_LIBS([unw_backtrace], [unwind],
|
|||||||
[have_unwind=true],
|
[have_unwind=true],
|
||||||
[AC_MSG_WARN(libunwind library was not found in your system.)])
|
[AC_MSG_WARN(libunwind library was not found in your system.)])
|
||||||
|
|
||||||
AS_CASE([$host_cpu], [x86_64],
|
AC_SEARCH_LIBS([_Ux86_64_step], [unwind-x86_64],
|
||||||
[AC_SEARCH_LIBS([_Ux86_64_step], [unwind-x86_64],
|
|
||||||
[AC_DEFINE([HAVE_UNWIND_X86_64], [1], [Define to 1 if you have the `libunwind-x86_64' library])]
|
[AC_DEFINE([HAVE_UNWIND_X86_64], [1], [Define to 1 if you have the `libunwind-x86_64' library])]
|
||||||
[have_unwind_x86_64=true],
|
[have_unwind_x86_64=true],
|
||||||
[AC_MSG_WARN(libunwind library was not found in your system.)])],
|
[AC_MSG_WARN(libunwind library was not found in your system.)])
|
||||||
[aarch64],
|
|
||||||
[AC_SEARCH_LIBS([_Uaarch64_step], [unwind-aarch64],
|
|
||||||
[AC_DEFINE([HAVE_UNWIND_AARCH64], [1], [Define to 1 if you have the `libunwind-aarch64' library])]
|
|
||||||
[have_unwind_aarch64=true],
|
|
||||||
[AC_MSG_WARN(libunwind library was not found in your system.)])])
|
|
||||||
|
|
||||||
AC_SEARCH_LIBS([SHA256_Init], [crypto],
|
AC_SEARCH_LIBS([SHA256_Init], [crypto],
|
||||||
[AC_DEFINE([HAVE_CRYPTO], [1], [Define to 1 if you have the `OpenSSL' library])]
|
[AC_DEFINE([HAVE_CRYPTO], [1], [Define to 1 if you have the `OpenSSL' library])]
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ export HDF5=/opt/cray/pe/hdf5/1.12.2.3/gnu/9.1
|
|||||||
--disable-gparity \
|
--disable-gparity \
|
||||||
--disable-fermion-reps \
|
--disable-fermion-reps \
|
||||||
--enable-shm=nvlink \
|
--enable-shm=nvlink \
|
||||||
--enable-checksum-comms=yes \
|
--enable-checksum-comms=no \
|
||||||
--enable-log-views=yes \
|
--enable-log-views=yes \
|
||||||
--enable-accelerator=sycl \
|
--enable-accelerator=sycl \
|
||||||
--enable-accelerator-aware-mpi=no \
|
--enable-accelerator-aware-mpi=no \
|
||||||
|
|||||||
@@ -368,7 +368,7 @@ int main (int argc, char ** argv)
|
|||||||
TrivialPrecon<CoarseVector> simple;
|
TrivialPrecon<CoarseVector> simple;
|
||||||
NonHermitianLinearOperator<LittleDiracOperator,CoarseVector> LinOpCoarse(LittleDiracOpPV);
|
NonHermitianLinearOperator<LittleDiracOperator,CoarseVector> LinOpCoarse(LittleDiracOpPV);
|
||||||
// PrecGeneralisedConjugateResidualNonHermitian<CoarseVector> L2PGCR(1.0e-4, 100, LinOpCoarse,simple,10,10);
|
// PrecGeneralisedConjugateResidualNonHermitian<CoarseVector> L2PGCR(1.0e-4, 100, LinOpCoarse,simple,10,10);
|
||||||
PrecGeneralisedConjugateResidualNonHermitian<CoarseVector> L2PGCR(3.0e-2, 100, LinOpCoarse,simple,10,10);
|
PrecGeneralisedConjugateResidualNonHermitian<CoarseVector> L2PGCR(1.0e-2, 200, LinOpCoarse,simple,30,30);
|
||||||
L2PGCR.Level(3);
|
L2PGCR.Level(3);
|
||||||
c_res=Zero();
|
c_res=Zero();
|
||||||
L2PGCR(c_src,c_res);
|
L2PGCR(c_src,c_res);
|
||||||
@@ -400,7 +400,7 @@ int main (int argc, char ** argv)
|
|||||||
LinOpCoarse,
|
LinOpCoarse,
|
||||||
L2PGCR);
|
L2PGCR);
|
||||||
|
|
||||||
PrecGeneralisedConjugateResidualNonHermitian<LatticeFermion> L1PGCR(1.0e-8,1000,PVdagM,TwoLevelPrecon,16,16);
|
PrecGeneralisedConjugateResidualNonHermitian<LatticeFermion> L1PGCR(1.0e-8,1000,PVdagM,TwoLevelPrecon,30,30);
|
||||||
L1PGCR.Level(1);
|
L1PGCR.Level(1);
|
||||||
|
|
||||||
f_res=Zero();
|
f_res=Zero();
|
||||||
|
|||||||
493
tests/debug/Test_general_coarse_pvdagm_svd.cc
Normal file
493
tests/debug/Test_general_coarse_pvdagm_svd.cc
Normal file
@@ -0,0 +1,493 @@
|
|||||||
|
/*************************************************************************************
|
||||||
|
|
||||||
|
Grid physics library, www.github.com/paboyle/Grid
|
||||||
|
|
||||||
|
Source file: ./tests/Test_padded_cell.cc
|
||||||
|
|
||||||
|
Copyright (C) 2023
|
||||||
|
|
||||||
|
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
|
See the full license in the file "LICENSE" in the top level distribution directory
|
||||||
|
*************************************************************************************/
|
||||||
|
/* END LEGAL */
|
||||||
|
#include <Grid/Grid.h>
|
||||||
|
#include <Grid/lattice/PaddedCell.h>
|
||||||
|
#include <Grid/stencil/GeneralLocalStencil.h>
|
||||||
|
|
||||||
|
#include <Grid/algorithms/iterative/PrecGeneralisedConjugateResidual.h>
|
||||||
|
#include <Grid/algorithms/iterative/PrecGeneralisedConjugateResidualNonHermitian.h>
|
||||||
|
#include <Grid/algorithms/iterative/BiCGSTAB.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace Grid;
|
||||||
|
|
||||||
|
template<class Matrix,class Field>
|
||||||
|
class PVdagMLinearOperator : public LinearOperatorBase<Field> {
|
||||||
|
Matrix &_Mat;
|
||||||
|
Matrix &_PV;
|
||||||
|
public:
|
||||||
|
PVdagMLinearOperator(Matrix &Mat,Matrix &PV): _Mat(Mat),_PV(PV){};
|
||||||
|
|
||||||
|
void OpDiag (const Field &in, Field &out) { assert(0); }
|
||||||
|
void OpDir (const Field &in, Field &out,int dir,int disp) { assert(0); }
|
||||||
|
void OpDirAll (const Field &in, std::vector<Field> &out){ assert(0); };
|
||||||
|
void Op (const Field &in, Field &out){
|
||||||
|
// std::cout << GridLogMessage<< "Op: PVdag M "<<std::endl;
|
||||||
|
Field tmp(in.Grid());
|
||||||
|
_Mat.M(in,tmp);
|
||||||
|
_PV.Mdag(tmp,out);
|
||||||
|
}
|
||||||
|
void AdjOp (const Field &in, Field &out){
|
||||||
|
// std::cout << GridLogMessage<<"AdjOp: Mdag PV "<<std::endl;
|
||||||
|
Field tmp(in.Grid());
|
||||||
|
_PV.M(in,tmp);
|
||||||
|
_Mat.Mdag(tmp,out);
|
||||||
|
}
|
||||||
|
void HermOpAndNorm(const Field &in, Field &out,RealD &n1,RealD &n2){
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
void HermOp(const Field &in, Field &out){
|
||||||
|
// std::cout <<GridLogMessage<< "HermOp: Mdag PV PVdag M"<<std::endl;
|
||||||
|
Field tmp(in.Grid());
|
||||||
|
Op(in,tmp);
|
||||||
|
AdjOp(tmp,out);
|
||||||
|
// std::cout << "HermOp done "<<norm2(out)<<std::endl;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template<class Matrix,class Field>
|
||||||
|
class MdagPVLinearOperator : public LinearOperatorBase<Field> {
|
||||||
|
Matrix &_Mat;
|
||||||
|
Matrix &_PV;
|
||||||
|
public:
|
||||||
|
MdagPVLinearOperator(Matrix &Mat,Matrix &PV): _Mat(Mat),_PV(PV){};
|
||||||
|
|
||||||
|
void OpDiag (const Field &in, Field &out) { assert(0); }
|
||||||
|
void OpDir (const Field &in, Field &out,int dir,int disp) { assert(0); }
|
||||||
|
void OpDirAll (const Field &in, std::vector<Field> &out){ assert(0); };
|
||||||
|
void Op (const Field &in, Field &out){
|
||||||
|
Field tmp(in.Grid());
|
||||||
|
// std::cout <<GridLogMessage<< "Op: PVdag M "<<std::endl;
|
||||||
|
_PV.M(in,tmp);
|
||||||
|
_Mat.Mdag(tmp,out);
|
||||||
|
}
|
||||||
|
void AdjOp (const Field &in, Field &out){
|
||||||
|
// std::cout <<GridLogMessage<< "AdjOp: Mdag PV "<<std::endl;
|
||||||
|
Field tmp(in.Grid());
|
||||||
|
_Mat.M(in,tmp);
|
||||||
|
_PV.Mdag(tmp,out);
|
||||||
|
}
|
||||||
|
void HermOpAndNorm(const Field &in, Field &out,RealD &n1,RealD &n2){
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
void HermOp(const Field &in, Field &out){
|
||||||
|
// std::cout << GridLogMessage<<"HermOp: PVdag M Mdag PV "<<std::endl;
|
||||||
|
Field tmp(in.Grid());
|
||||||
|
Op(in,tmp);
|
||||||
|
AdjOp(tmp,out);
|
||||||
|
// std::cout << "HermOp done "<<norm2(out)<<std::endl;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template<class Matrix,class Field>
|
||||||
|
class ShiftedPVdagMLinearOperator : public LinearOperatorBase<Field> {
|
||||||
|
Matrix &_Mat;
|
||||||
|
Matrix &_PV;
|
||||||
|
RealD shift;
|
||||||
|
public:
|
||||||
|
ShiftedPVdagMLinearOperator(RealD _shift,Matrix &Mat,Matrix &PV): shift(_shift),_Mat(Mat),_PV(PV){};
|
||||||
|
|
||||||
|
void OpDiag (const Field &in, Field &out) { assert(0); }
|
||||||
|
void OpDir (const Field &in, Field &out,int dir,int disp) { assert(0); }
|
||||||
|
void OpDirAll (const Field &in, std::vector<Field> &out){ assert(0); };
|
||||||
|
void Op (const Field &in, Field &out){
|
||||||
|
// std::cout << "Op: PVdag M "<<std::endl;
|
||||||
|
Field tmp(in.Grid());
|
||||||
|
_Mat.M(in,tmp);
|
||||||
|
_PV.Mdag(tmp,out);
|
||||||
|
out = out + shift * in;
|
||||||
|
}
|
||||||
|
void AdjOp (const Field &in, Field &out){
|
||||||
|
// std::cout << "AdjOp: Mdag PV "<<std::endl;
|
||||||
|
Field tmp(in.Grid());
|
||||||
|
_PV.M(tmp,out);
|
||||||
|
_Mat.Mdag(in,tmp);
|
||||||
|
out = out + shift * in;
|
||||||
|
}
|
||||||
|
void HermOpAndNorm(const Field &in, Field &out,RealD &n1,RealD &n2){ assert(0); }
|
||||||
|
void HermOp(const Field &in, Field &out){
|
||||||
|
// std::cout << "HermOp: Mdag PV PVdag M"<<std::endl;
|
||||||
|
Field tmp(in.Grid());
|
||||||
|
Op(in,tmp);
|
||||||
|
AdjOp(tmp,out);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template<class Fobj,class CComplex,int nbasis>
|
||||||
|
class MGPreconditionerSVD : public LinearFunction< Lattice<Fobj> > {
|
||||||
|
public:
|
||||||
|
using LinearFunction<Lattice<Fobj> >::operator();
|
||||||
|
|
||||||
|
typedef Aggregation<Fobj,CComplex,nbasis> Aggregates;
|
||||||
|
typedef typename Aggregation<Fobj,CComplex,nbasis>::FineField FineField;
|
||||||
|
typedef typename Aggregation<Fobj,CComplex,nbasis>::CoarseVector CoarseVector;
|
||||||
|
typedef typename Aggregation<Fobj,CComplex,nbasis>::CoarseMatrix CoarseMatrix;
|
||||||
|
typedef LinearOperatorBase<FineField> FineOperator;
|
||||||
|
typedef LinearFunction <FineField> FineSmoother;
|
||||||
|
typedef LinearOperatorBase<CoarseVector> CoarseOperator;
|
||||||
|
typedef LinearFunction <CoarseVector> CoarseSolver;
|
||||||
|
Aggregates & _FineToCoarse;
|
||||||
|
Aggregates & _CoarseToFine;
|
||||||
|
FineOperator & _FineOperator;
|
||||||
|
FineSmoother & _PreSmoother;
|
||||||
|
FineSmoother & _PostSmoother;
|
||||||
|
CoarseOperator & _CoarseOperator;
|
||||||
|
CoarseSolver & _CoarseSolve;
|
||||||
|
|
||||||
|
int level; void Level(int lv) {level = lv; };
|
||||||
|
|
||||||
|
MGPreconditionerSVD(Aggregates &FtoC,
|
||||||
|
Aggregates &CtoF,
|
||||||
|
FineOperator &Fine,
|
||||||
|
FineSmoother &PreSmoother,
|
||||||
|
FineSmoother &PostSmoother,
|
||||||
|
CoarseOperator &CoarseOperator_,
|
||||||
|
CoarseSolver &CoarseSolve_)
|
||||||
|
: _FineToCoarse(FtoC),
|
||||||
|
_CoarseToFine(CtoF),
|
||||||
|
_FineOperator(Fine),
|
||||||
|
_PreSmoother(PreSmoother),
|
||||||
|
_PostSmoother(PostSmoother),
|
||||||
|
_CoarseOperator(CoarseOperator_),
|
||||||
|
_CoarseSolve(CoarseSolve_),
|
||||||
|
level(1) { }
|
||||||
|
|
||||||
|
virtual void operator()(const FineField &in, FineField & out)
|
||||||
|
{
|
||||||
|
GridBase *CoarseGrid = _FineToCoarse.CoarseGrid;
|
||||||
|
// auto CoarseGrid = _CoarseOperator.Grid();
|
||||||
|
CoarseVector Csrc(CoarseGrid);
|
||||||
|
CoarseVector Csol(CoarseGrid);
|
||||||
|
FineField vec1(in.Grid());
|
||||||
|
FineField vec2(in.Grid());
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage << "Calling PreSmoother " <<std::endl;
|
||||||
|
|
||||||
|
// std::cout<<GridLogMessage << "Calling PreSmoother input residual "<<norm2(in) <<std::endl;
|
||||||
|
double t;
|
||||||
|
// Fine Smoother
|
||||||
|
// out = in;
|
||||||
|
out = Zero();
|
||||||
|
t=-usecond();
|
||||||
|
_PreSmoother(in,out);
|
||||||
|
t+=usecond();
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage << "PreSmoother took "<< t/1000.0<< "ms" <<std::endl;
|
||||||
|
|
||||||
|
// Update the residual
|
||||||
|
_FineOperator.Op(out,vec1); sub(vec1, in ,vec1);
|
||||||
|
// std::cout<<GridLogMessage <<"Residual-1 now " <<norm2(vec1)<<std::endl;
|
||||||
|
|
||||||
|
// Fine to Coarse
|
||||||
|
t=-usecond();
|
||||||
|
_FineToCoarse.ProjectToSubspace (Csrc,vec1);
|
||||||
|
t+=usecond();
|
||||||
|
std::cout<<GridLogMessage << "Project to coarse took "<< t/1000.0<< "ms" <<std::endl;
|
||||||
|
|
||||||
|
// Coarse correction
|
||||||
|
t=-usecond();
|
||||||
|
Csol = Zero();
|
||||||
|
_CoarseSolve(Csrc,Csol);
|
||||||
|
//Csol=Zero();
|
||||||
|
t+=usecond();
|
||||||
|
std::cout<<GridLogMessage << "Coarse solve took "<< t/1000.0<< "ms" <<std::endl;
|
||||||
|
|
||||||
|
// Coarse to Fine
|
||||||
|
t=-usecond();
|
||||||
|
// _CoarseOperator.PromoteFromSubspace(_Aggregates,Csol,vec1);
|
||||||
|
_CoarseToFine.PromoteFromSubspace(Csol,vec1);
|
||||||
|
add(out,out,vec1);
|
||||||
|
t+=usecond();
|
||||||
|
std::cout<<GridLogMessage << "Promote to this level took "<< t/1000.0<< "ms" <<std::endl;
|
||||||
|
|
||||||
|
// Residual
|
||||||
|
_FineOperator.Op(out,vec1); sub(vec1 ,in , vec1);
|
||||||
|
// std::cout<<GridLogMessage <<"Residual-2 now " <<norm2(vec1)<<std::endl;
|
||||||
|
|
||||||
|
// Fine Smoother
|
||||||
|
t=-usecond();
|
||||||
|
// vec2=vec1;
|
||||||
|
vec2=Zero();
|
||||||
|
_PostSmoother(vec1,vec2);
|
||||||
|
t+=usecond();
|
||||||
|
std::cout<<GridLogMessage << "PostSmoother took "<< t/1000.0<< "ms" <<std::endl;
|
||||||
|
|
||||||
|
add( out,out,vec2);
|
||||||
|
std::cout<<GridLogMessage << "Done " <<std::endl;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main (int argc, char ** argv)
|
||||||
|
{
|
||||||
|
Grid_init(&argc,&argv);
|
||||||
|
|
||||||
|
const int Ls=16;
|
||||||
|
|
||||||
|
GridCartesian * UGrid = SpaceTimeGrid::makeFourDimGrid(GridDefaultLatt(), GridDefaultSimd(Nd,vComplex::Nsimd()),GridDefaultMpi());
|
||||||
|
GridRedBlackCartesian * UrbGrid = SpaceTimeGrid::makeFourDimRedBlackGrid(UGrid);
|
||||||
|
|
||||||
|
GridCartesian * FGrid = SpaceTimeGrid::makeFiveDimGrid(Ls,UGrid);
|
||||||
|
GridRedBlackCartesian * FrbGrid = SpaceTimeGrid::makeFiveDimRedBlackGrid(Ls,UGrid);
|
||||||
|
|
||||||
|
// Construct a coarsened grid
|
||||||
|
Coordinate clatt = GridDefaultLatt();
|
||||||
|
for(int d=0;d<clatt.size();d++){
|
||||||
|
clatt[d] = clatt[d]/2;
|
||||||
|
// clatt[d] = clatt[d]/4;
|
||||||
|
}
|
||||||
|
GridCartesian *Coarse4d = SpaceTimeGrid::makeFourDimGrid(clatt, GridDefaultSimd(Nd,vComplex::Nsimd()),GridDefaultMpi());;
|
||||||
|
GridCartesian *Coarse5d = SpaceTimeGrid::makeFiveDimGrid(1,Coarse4d);
|
||||||
|
|
||||||
|
std::vector<int> seeds4({1,2,3,4});
|
||||||
|
std::vector<int> seeds5({5,6,7,8});
|
||||||
|
std::vector<int> cseeds({5,6,7,8});
|
||||||
|
GridParallelRNG RNG5(FGrid); RNG5.SeedFixedIntegers(seeds5);
|
||||||
|
GridParallelRNG RNG4(UGrid); RNG4.SeedFixedIntegers(seeds4);
|
||||||
|
GridParallelRNG CRNG(Coarse5d);CRNG.SeedFixedIntegers(cseeds);
|
||||||
|
|
||||||
|
LatticeFermion src(FGrid); random(RNG5,src);
|
||||||
|
LatticeFermion result(FGrid); result=Zero();
|
||||||
|
LatticeFermion ref(FGrid); ref=Zero();
|
||||||
|
LatticeFermion tmp(FGrid);
|
||||||
|
LatticeFermion err(FGrid);
|
||||||
|
LatticeGaugeField Umu(UGrid);
|
||||||
|
|
||||||
|
FieldMetaData header;
|
||||||
|
std::string file("ckpoint_lat.4000");
|
||||||
|
NerscIO::readConfiguration(Umu,header,file);
|
||||||
|
|
||||||
|
RealD mass=0.01;
|
||||||
|
RealD M5=1.8;
|
||||||
|
|
||||||
|
DomainWallFermionD Ddwf(Umu,*FGrid,*FrbGrid,*UGrid,*UrbGrid,mass,M5);
|
||||||
|
DomainWallFermionD Dpv(Umu,*FGrid,*FrbGrid,*UGrid,*UrbGrid,1.0,M5);
|
||||||
|
|
||||||
|
const int nbasis = 30;
|
||||||
|
const int cb = 0 ;
|
||||||
|
|
||||||
|
|
||||||
|
NextToNearestStencilGeometry5D geom(Coarse5d);
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"*******************************************"<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<std::endl;
|
||||||
|
|
||||||
|
typedef PVdagMLinearOperator<DomainWallFermionD,LatticeFermionD> PVdagM_t;
|
||||||
|
typedef MdagPVLinearOperator<DomainWallFermionD,LatticeFermionD> MdagPV_t;
|
||||||
|
typedef ShiftedPVdagMLinearOperator<DomainWallFermionD,LatticeFermionD> ShiftedPVdagM_t;
|
||||||
|
PVdagM_t PVdagM(Ddwf,Dpv);
|
||||||
|
MdagPV_t MdagPV(Ddwf,Dpv);
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(2.0,Ddwf,Dpv); // 355
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(1.0,Ddwf,Dpv); // 246
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.5,Ddwf,Dpv); // 183
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.25,Ddwf,Dpv); // 145
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.1,Ddwf,Dpv); // 134
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.1,Ddwf,Dpv); // 127 -- NULL space via inverse iteration
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.1,Ddwf,Dpv); // 57 -- NULL space via inverse iteration; 3 iterations
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.25,Ddwf,Dpv); // 57 , tighter inversion
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.25,Ddwf,Dpv); // nbasis 20 -- 49 iters
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.25,Ddwf,Dpv); // nbasis 20 -- 70 iters; asymmetric
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.25,Ddwf,Dpv); // 58; Loosen coarse, tighten fine
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.1,Ddwf,Dpv); // 56 ...
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.1,Ddwf,Dpv); // 51 ... with 24 vecs
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.1,Ddwf,Dpv); // 31 ... with 24 vecs and 2^4 blocking
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.1,Ddwf,Dpv); // 43 ... with 16 vecs and 2^4 blocking, sloppier
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.1,Ddwf,Dpv); // 35 ... with 20 vecs and 2^4 blocking
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.1,Ddwf,Dpv); // 35 ... with 20 vecs and 2^4 blocking, looser coarse
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.1,Ddwf,Dpv); // 64 ... with 20 vecs, Christoph setup, and 2^4 blocking, looser coarse
|
||||||
|
ShiftedPVdagM_t ShiftedPVdagM(0.01,Ddwf,Dpv); //
|
||||||
|
|
||||||
|
|
||||||
|
// Run power method on HOA??
|
||||||
|
PowerMethod<LatticeFermion> PM;
|
||||||
|
// PM(PVdagM,src);
|
||||||
|
// PM(MdagPV,src);
|
||||||
|
|
||||||
|
// Warning: This routine calls PVdagM.Op, not PVdagM.HermOp
|
||||||
|
typedef Aggregation<vSpinColourVector,vTComplex,nbasis> Subspace;
|
||||||
|
Subspace V(Coarse5d,FGrid,cb);
|
||||||
|
Subspace U(Coarse5d,FGrid,cb);
|
||||||
|
|
||||||
|
// Breeds right singular vectors with call to HermOp (V)
|
||||||
|
V.CreateSubspaceChebyshev(RNG5,PVdagM,
|
||||||
|
nbasis,
|
||||||
|
4000.0,0.003,
|
||||||
|
500);
|
||||||
|
|
||||||
|
// Breeds left singular vectors with call to HermOp (U)
|
||||||
|
// U.CreateSubspaceChebyshev(RNG5,PVdagM,
|
||||||
|
U.CreateSubspaceChebyshev(RNG5,MdagPV,
|
||||||
|
nbasis,
|
||||||
|
4000.0,0.003,
|
||||||
|
500);
|
||||||
|
|
||||||
|
typedef Aggregation<vSpinColourVector,vTComplex,2*nbasis> CombinedSubspace;
|
||||||
|
CombinedSubspace CombinedUV(Coarse5d,FGrid,cb);
|
||||||
|
for(int b=0;b<nbasis;b++){
|
||||||
|
CombinedUV.subspace[b] = V.subspace[b];
|
||||||
|
CombinedUV.subspace[b+nbasis] = U.subspace[b];
|
||||||
|
}
|
||||||
|
|
||||||
|
int bl, br;
|
||||||
|
std::cout <<" <V| PVdagM| V> " <<std::endl;
|
||||||
|
for(bl=0;bl<nbasis;bl++){
|
||||||
|
for(br=0;br<nbasis;br++){
|
||||||
|
PVdagM.Op(V.subspace[br],src);
|
||||||
|
std::cout <<bl<<" "<<br<<"\t"<<innerProduct(V.subspace[bl],src)<<std::endl;
|
||||||
|
}}
|
||||||
|
std::cout <<" <V| PVdagM| U> " <<std::endl;
|
||||||
|
for(bl=0;bl<nbasis;bl++){
|
||||||
|
for(br=0;br<nbasis;br++){
|
||||||
|
PVdagM.Op(U.subspace[br],src);
|
||||||
|
std::cout <<bl<<" "<<br<<"\t"<<innerProduct(V.subspace[bl],src)<<std::endl;
|
||||||
|
}}
|
||||||
|
std::cout <<" <U| PVdagM| V> " <<std::endl;
|
||||||
|
for(bl=0;bl<nbasis;bl++){
|
||||||
|
for(br=0;br<nbasis;br++){
|
||||||
|
PVdagM.Op(V.subspace[br],src);
|
||||||
|
std::cout <<bl<<" "<<br<<"\t"<<innerProduct(U.subspace[bl],src)<<std::endl;
|
||||||
|
}}
|
||||||
|
std::cout <<" <U| PVdagM| U> " <<std::endl;
|
||||||
|
for(bl=0;bl<nbasis;bl++){
|
||||||
|
for(br=0;br<nbasis;br++){
|
||||||
|
PVdagM.Op(U.subspace[br],src);
|
||||||
|
std::cout <<bl<<" "<<br<<"\t"<<innerProduct(U.subspace[bl],src)<<std::endl;
|
||||||
|
}}
|
||||||
|
|
||||||
|
typedef GeneralCoarsenedMatrix<vSpinColourVector,vTComplex,nbasis> LittleDiracOperatorV;
|
||||||
|
typedef LittleDiracOperatorV::CoarseVector CoarseVectorV;
|
||||||
|
|
||||||
|
typedef GeneralCoarsenedMatrix<vSpinColourVector,vTComplex,2*nbasis> LittleDiracOperator;
|
||||||
|
typedef LittleDiracOperator::CoarseVector CoarseVector;
|
||||||
|
|
||||||
|
V.Orthogonalise();
|
||||||
|
for(int b =0 ; b<nbasis;b++){
|
||||||
|
CoarseVectorV c_src (Coarse5d);
|
||||||
|
V.ProjectToSubspace (c_src,U.subspace[b]);
|
||||||
|
V.PromoteFromSubspace(c_src,src);
|
||||||
|
std::cout << " Completeness of U in V ["<< b<<"] "<< std::sqrt(norm2(src)/norm2(U.subspace[b]))<<std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
CoarseVector c_src (Coarse5d);
|
||||||
|
CoarseVector c_res (Coarse5d);
|
||||||
|
CoarseVector c_proj(Coarse5d);
|
||||||
|
LittleDiracOperator LittleDiracOpPV(geom,FGrid,Coarse5d);
|
||||||
|
LittleDiracOpPV.CoarsenOperator(PVdagM,CombinedUV,CombinedUV);
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"*******************************************"<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"Testing coarsened operator "<<std::endl;
|
||||||
|
|
||||||
|
Complex one(1.0);
|
||||||
|
c_src = one; // 1 in every element for vector 1.
|
||||||
|
|
||||||
|
blockPromote(c_src,err,CombinedUV.subspace);
|
||||||
|
|
||||||
|
LatticeFermion prom(FGrid);
|
||||||
|
prom=Zero();
|
||||||
|
for(int b=0;b<nbasis*2;b++){
|
||||||
|
prom=prom+CombinedUV.subspace[b];
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<"c_src "<<norm2(c_src)<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"prom "<<norm2(prom)<<std::endl;
|
||||||
|
|
||||||
|
PVdagM.Op(prom,tmp);
|
||||||
|
blockProject(c_proj,tmp,CombinedUV.subspace);
|
||||||
|
std::cout<<GridLogMessage<<" Called Big Dirac Op "<<norm2(tmp)<<std::endl;
|
||||||
|
|
||||||
|
LittleDiracOpPV.M(c_src,c_res);
|
||||||
|
std::cout<<GridLogMessage<<" Called Little Dirac Op c_src "<< norm2(c_src) << " c_res "<< norm2(c_res) <<std::endl;
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<"Little dop : "<<norm2(c_res)<<std::endl;
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<"Big dop in subspace : "<<norm2(c_proj)<<std::endl;
|
||||||
|
|
||||||
|
c_proj = c_proj - c_res;
|
||||||
|
std::cout<<GridLogMessage<<" ldop error: "<<norm2(c_proj)<<std::endl;
|
||||||
|
|
||||||
|
|
||||||
|
/**********
|
||||||
|
* Some solvers
|
||||||
|
**********
|
||||||
|
*/
|
||||||
|
|
||||||
|
///////////////////////////////////////
|
||||||
|
// Coarse grid solver test
|
||||||
|
///////////////////////////////////////
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<"******************* "<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<" Coarse Grid Solve -- Level 3 "<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"******************* "<<std::endl;
|
||||||
|
TrivialPrecon<CoarseVector> simple;
|
||||||
|
NonHermitianLinearOperator<LittleDiracOperator,CoarseVector> LinOpCoarse(LittleDiracOpPV);
|
||||||
|
// PrecGeneralisedConjugateResidualNonHermitian<CoarseVector> L2PGCR(1.0e-4, 100, LinOpCoarse,simple,10,10);
|
||||||
|
PrecGeneralisedConjugateResidualNonHermitian<CoarseVector> L2PGCR(1.0e-2, 10, LinOpCoarse,simple,20,20);
|
||||||
|
L2PGCR.Level(3);
|
||||||
|
c_res=Zero();
|
||||||
|
L2PGCR(c_src,c_res);
|
||||||
|
|
||||||
|
////////////////////////////////////////
|
||||||
|
// Fine grid smoother
|
||||||
|
////////////////////////////////////////
|
||||||
|
std::cout<<GridLogMessage<<"******************* "<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<" Fine Grid Smoother -- Level 2 "<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"******************* "<<std::endl;
|
||||||
|
TrivialPrecon<LatticeFermionD> simple_fine;
|
||||||
|
// NonHermitianLinearOperator<PVdagM_t,LatticeFermionD> LinOpSmooth(PVdagM);
|
||||||
|
PrecGeneralisedConjugateResidualNonHermitian<LatticeFermionD> SmootherGCR(0.01,1,ShiftedPVdagM,simple_fine,16,16);
|
||||||
|
SmootherGCR.Level(2);
|
||||||
|
|
||||||
|
LatticeFermionD f_src(FGrid);
|
||||||
|
LatticeFermionD f_res(FGrid);
|
||||||
|
|
||||||
|
f_src = one; // 1 in every element for vector 1.
|
||||||
|
f_res=Zero();
|
||||||
|
SmootherGCR(f_src,f_res);
|
||||||
|
|
||||||
|
typedef MGPreconditionerSVD<vSpinColourVector, vTComplex,nbasis*2> TwoLevelMG;
|
||||||
|
|
||||||
|
TwoLevelMG TwoLevelPrecon(CombinedUV,CombinedUV,
|
||||||
|
PVdagM,
|
||||||
|
simple_fine,
|
||||||
|
SmootherGCR,
|
||||||
|
LinOpCoarse,
|
||||||
|
L2PGCR);
|
||||||
|
|
||||||
|
PrecGeneralisedConjugateResidualNonHermitian<LatticeFermion> L1PGCR(1.0e-8,1000,PVdagM,TwoLevelPrecon,20,20);
|
||||||
|
L1PGCR.Level(1);
|
||||||
|
|
||||||
|
f_res=Zero();
|
||||||
|
L1PGCR(f_src,f_res);
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"*******************************************"<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<std::endl;
|
||||||
|
std::cout<<GridLogMessage << "Done "<< std::endl;
|
||||||
|
|
||||||
|
Grid_finalize();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
492
tests/debug/Test_general_coarse_pvdagm_svd_cg.cc
Normal file
492
tests/debug/Test_general_coarse_pvdagm_svd_cg.cc
Normal file
@@ -0,0 +1,492 @@
|
|||||||
|
/*************************************************************************************
|
||||||
|
|
||||||
|
Grid physics library, www.github.com/paboyle/Grid
|
||||||
|
|
||||||
|
Source file: ./tests/Test_padded_cell.cc
|
||||||
|
|
||||||
|
Copyright (C) 2023
|
||||||
|
|
||||||
|
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
|
See the full license in the file "LICENSE" in the top level distribution directory
|
||||||
|
*************************************************************************************/
|
||||||
|
/* END LEGAL */
|
||||||
|
#include <Grid/Grid.h>
|
||||||
|
#include <Grid/lattice/PaddedCell.h>
|
||||||
|
#include <Grid/stencil/GeneralLocalStencil.h>
|
||||||
|
|
||||||
|
#include <Grid/algorithms/iterative/PrecGeneralisedConjugateResidual.h>
|
||||||
|
#include <Grid/algorithms/iterative/PrecGeneralisedConjugateResidualNonHermitian.h>
|
||||||
|
#include <Grid/algorithms/iterative/BiCGSTAB.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace Grid;
|
||||||
|
|
||||||
|
template<class Matrix,class Field>
|
||||||
|
class PVdagMLinearOperator : public LinearOperatorBase<Field> {
|
||||||
|
Matrix &_Mat;
|
||||||
|
Matrix &_PV;
|
||||||
|
public:
|
||||||
|
PVdagMLinearOperator(Matrix &Mat,Matrix &PV): _Mat(Mat),_PV(PV){};
|
||||||
|
|
||||||
|
void OpDiag (const Field &in, Field &out) { assert(0); }
|
||||||
|
void OpDir (const Field &in, Field &out,int dir,int disp) { assert(0); }
|
||||||
|
void OpDirAll (const Field &in, std::vector<Field> &out){ assert(0); };
|
||||||
|
void Op (const Field &in, Field &out){
|
||||||
|
// std::cout << GridLogMessage<< "Op: PVdag M "<<std::endl;
|
||||||
|
Field tmp(in.Grid());
|
||||||
|
_Mat.M(in,tmp);
|
||||||
|
_PV.Mdag(tmp,out);
|
||||||
|
}
|
||||||
|
void AdjOp (const Field &in, Field &out){
|
||||||
|
// std::cout << GridLogMessage<<"AdjOp: Mdag PV "<<std::endl;
|
||||||
|
Field tmp(in.Grid());
|
||||||
|
_PV.M(in,tmp);
|
||||||
|
_Mat.Mdag(tmp,out);
|
||||||
|
}
|
||||||
|
void HermOpAndNorm(const Field &in, Field &out,RealD &n1,RealD &n2){
|
||||||
|
HermOp(in,out);
|
||||||
|
ComplexD dot = innerProduct(in,out);
|
||||||
|
n1=real(dot);
|
||||||
|
n2=norm2(out);
|
||||||
|
}
|
||||||
|
void HermOp(const Field &in, Field &out){
|
||||||
|
// std::cout <<GridLogMessage<< "HermOp: Mdag PV PVdag M"<<std::endl;
|
||||||
|
Field tmp(in.Grid());
|
||||||
|
Op(in,tmp);
|
||||||
|
AdjOp(tmp,out);
|
||||||
|
// std::cout << "HermOp done "<<norm2(out)<<std::endl;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template<class Matrix,class Field>
|
||||||
|
class MdagPVLinearOperator : public LinearOperatorBase<Field> {
|
||||||
|
Matrix &_Mat;
|
||||||
|
Matrix &_PV;
|
||||||
|
public:
|
||||||
|
MdagPVLinearOperator(Matrix &Mat,Matrix &PV): _Mat(Mat),_PV(PV){};
|
||||||
|
|
||||||
|
void OpDiag (const Field &in, Field &out) { assert(0); }
|
||||||
|
void OpDir (const Field &in, Field &out,int dir,int disp) { assert(0); }
|
||||||
|
void OpDirAll (const Field &in, std::vector<Field> &out){ assert(0); };
|
||||||
|
void Op (const Field &in, Field &out){
|
||||||
|
Field tmp(in.Grid());
|
||||||
|
// std::cout <<GridLogMessage<< "Op: PVdag M "<<std::endl;
|
||||||
|
_PV.M(in,tmp);
|
||||||
|
_Mat.Mdag(tmp,out);
|
||||||
|
}
|
||||||
|
void AdjOp (const Field &in, Field &out){
|
||||||
|
// std::cout <<GridLogMessage<< "AdjOp: Mdag PV "<<std::endl;
|
||||||
|
Field tmp(in.Grid());
|
||||||
|
_Mat.M(in,tmp);
|
||||||
|
_PV.Mdag(tmp,out);
|
||||||
|
}
|
||||||
|
void HermOpAndNorm(const Field &in, Field &out,RealD &n1,RealD &n2){
|
||||||
|
ComplexD dot = innerProduct(in,out);
|
||||||
|
n1=real(dot);
|
||||||
|
n2=norm2(out);
|
||||||
|
}
|
||||||
|
void HermOp(const Field &in, Field &out){
|
||||||
|
// std::cout << GridLogMessage<<"HermOp: PVdag M Mdag PV "<<std::endl;
|
||||||
|
Field tmp(in.Grid());
|
||||||
|
Op(in,tmp);
|
||||||
|
AdjOp(tmp,out);
|
||||||
|
// std::cout << "HermOp done "<<norm2(out)<<std::endl;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template<class Matrix,class Field>
|
||||||
|
class ShiftedPVdagMLinearOperator : public LinearOperatorBase<Field> {
|
||||||
|
Matrix &_Mat;
|
||||||
|
Matrix &_PV;
|
||||||
|
RealD shift;
|
||||||
|
public:
|
||||||
|
ShiftedPVdagMLinearOperator(RealD _shift,Matrix &Mat,Matrix &PV): shift(_shift),_Mat(Mat),_PV(PV){};
|
||||||
|
|
||||||
|
void OpDiag (const Field &in, Field &out) { assert(0); }
|
||||||
|
void OpDir (const Field &in, Field &out,int dir,int disp) { assert(0); }
|
||||||
|
void OpDirAll (const Field &in, std::vector<Field> &out){ assert(0); };
|
||||||
|
void Op (const Field &in, Field &out){
|
||||||
|
// std::cout << "Op: PVdag M "<<std::endl;
|
||||||
|
Field tmp(in.Grid());
|
||||||
|
_Mat.M(in,tmp);
|
||||||
|
_PV.Mdag(tmp,out);
|
||||||
|
out = out + shift * in;
|
||||||
|
}
|
||||||
|
void AdjOp (const Field &in, Field &out){
|
||||||
|
// std::cout << "AdjOp: Mdag PV "<<std::endl;
|
||||||
|
Field tmp(in.Grid());
|
||||||
|
_PV.M(tmp,out);
|
||||||
|
_Mat.Mdag(in,tmp);
|
||||||
|
out = out + shift * in;
|
||||||
|
}
|
||||||
|
void HermOpAndNorm(const Field &in, Field &out,RealD &n1,RealD &n2){ assert(0); }
|
||||||
|
void HermOp(const Field &in, Field &out){
|
||||||
|
// std::cout << "HermOp: Mdag PV PVdag M"<<std::endl;
|
||||||
|
Field tmp(in.Grid());
|
||||||
|
Op(in,tmp);
|
||||||
|
AdjOp(tmp,out);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template<class Fobj,class CComplex,int nbasis>
|
||||||
|
class MGPreconditionerSVD : public LinearFunction< Lattice<Fobj> > {
|
||||||
|
public:
|
||||||
|
using LinearFunction<Lattice<Fobj> >::operator();
|
||||||
|
|
||||||
|
typedef Aggregation<Fobj,CComplex,nbasis> Aggregates;
|
||||||
|
typedef typename Aggregation<Fobj,CComplex,nbasis>::FineField FineField;
|
||||||
|
typedef typename Aggregation<Fobj,CComplex,nbasis>::CoarseVector CoarseVector;
|
||||||
|
typedef typename Aggregation<Fobj,CComplex,nbasis>::CoarseMatrix CoarseMatrix;
|
||||||
|
typedef LinearOperatorBase<FineField> FineOperator;
|
||||||
|
typedef LinearFunction <FineField> FineSmoother;
|
||||||
|
typedef LinearOperatorBase<CoarseVector> CoarseOperator;
|
||||||
|
typedef LinearFunction <CoarseVector> CoarseSolver;
|
||||||
|
Aggregates & _FineToCoarse;
|
||||||
|
Aggregates & _CoarseToFine;
|
||||||
|
FineOperator & _FineOperator;
|
||||||
|
FineSmoother & _PreSmoother;
|
||||||
|
FineSmoother & _PostSmoother;
|
||||||
|
CoarseOperator & _CoarseOperator;
|
||||||
|
CoarseSolver & _CoarseSolve;
|
||||||
|
|
||||||
|
int level; void Level(int lv) {level = lv; };
|
||||||
|
|
||||||
|
MGPreconditionerSVD(Aggregates &FtoC,
|
||||||
|
Aggregates &CtoF,
|
||||||
|
FineOperator &Fine,
|
||||||
|
FineSmoother &PreSmoother,
|
||||||
|
FineSmoother &PostSmoother,
|
||||||
|
CoarseOperator &CoarseOperator_,
|
||||||
|
CoarseSolver &CoarseSolve_)
|
||||||
|
: _FineToCoarse(FtoC),
|
||||||
|
_CoarseToFine(CtoF),
|
||||||
|
_FineOperator(Fine),
|
||||||
|
_PreSmoother(PreSmoother),
|
||||||
|
_PostSmoother(PostSmoother),
|
||||||
|
_CoarseOperator(CoarseOperator_),
|
||||||
|
_CoarseSolve(CoarseSolve_),
|
||||||
|
level(1) { }
|
||||||
|
|
||||||
|
virtual void operator()(const FineField &in, FineField & out)
|
||||||
|
{
|
||||||
|
GridBase *CoarseGrid = _FineToCoarse.CoarseGrid;
|
||||||
|
// auto CoarseGrid = _CoarseOperator.Grid();
|
||||||
|
CoarseVector Csrc(CoarseGrid);
|
||||||
|
CoarseVector Csol(CoarseGrid);
|
||||||
|
FineField vec1(in.Grid());
|
||||||
|
FineField vec2(in.Grid());
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage << "Calling PreSmoother " <<std::endl;
|
||||||
|
|
||||||
|
// std::cout<<GridLogMessage << "Calling PreSmoother input residual "<<norm2(in) <<std::endl;
|
||||||
|
double t;
|
||||||
|
// Fine Smoother
|
||||||
|
// out = in;
|
||||||
|
out = Zero();
|
||||||
|
t=-usecond();
|
||||||
|
_PreSmoother(in,out);
|
||||||
|
t+=usecond();
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage << "PreSmoother took "<< t/1000.0<< "ms" <<std::endl;
|
||||||
|
|
||||||
|
// Update the residual
|
||||||
|
_FineOperator.Op(out,vec1); sub(vec1, in ,vec1);
|
||||||
|
// std::cout<<GridLogMessage <<"Residual-1 now " <<norm2(vec1)<<std::endl;
|
||||||
|
|
||||||
|
// Fine to Coarse
|
||||||
|
t=-usecond();
|
||||||
|
_FineToCoarse.ProjectToSubspace (Csrc,vec1);
|
||||||
|
t+=usecond();
|
||||||
|
std::cout<<GridLogMessage << "Project to coarse took "<< t/1000.0<< "ms" <<std::endl;
|
||||||
|
|
||||||
|
// Coarse correction
|
||||||
|
t=-usecond();
|
||||||
|
Csol = Zero();
|
||||||
|
_CoarseSolve(Csrc,Csol);
|
||||||
|
//Csol=Zero();
|
||||||
|
t+=usecond();
|
||||||
|
std::cout<<GridLogMessage << "Coarse solve took "<< t/1000.0<< "ms" <<std::endl;
|
||||||
|
|
||||||
|
// Coarse to Fine
|
||||||
|
t=-usecond();
|
||||||
|
// _CoarseOperator.PromoteFromSubspace(_Aggregates,Csol,vec1);
|
||||||
|
_CoarseToFine.PromoteFromSubspace(Csol,vec1);
|
||||||
|
add(out,out,vec1);
|
||||||
|
t+=usecond();
|
||||||
|
std::cout<<GridLogMessage << "Promote to this level took "<< t/1000.0<< "ms" <<std::endl;
|
||||||
|
|
||||||
|
// Residual
|
||||||
|
_FineOperator.Op(out,vec1); sub(vec1 ,in , vec1);
|
||||||
|
// std::cout<<GridLogMessage <<"Residual-2 now " <<norm2(vec1)<<std::endl;
|
||||||
|
|
||||||
|
// Fine Smoother
|
||||||
|
t=-usecond();
|
||||||
|
// vec2=vec1;
|
||||||
|
vec2=Zero();
|
||||||
|
_PostSmoother(vec1,vec2);
|
||||||
|
t+=usecond();
|
||||||
|
std::cout<<GridLogMessage << "PostSmoother took "<< t/1000.0<< "ms" <<std::endl;
|
||||||
|
|
||||||
|
add( out,out,vec2);
|
||||||
|
std::cout<<GridLogMessage << "Done " <<std::endl;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main (int argc, char ** argv)
|
||||||
|
{
|
||||||
|
Grid_init(&argc,&argv);
|
||||||
|
|
||||||
|
const int Ls=16;
|
||||||
|
|
||||||
|
GridCartesian * UGrid = SpaceTimeGrid::makeFourDimGrid(GridDefaultLatt(), GridDefaultSimd(Nd,vComplex::Nsimd()),GridDefaultMpi());
|
||||||
|
GridRedBlackCartesian * UrbGrid = SpaceTimeGrid::makeFourDimRedBlackGrid(UGrid);
|
||||||
|
|
||||||
|
GridCartesian * FGrid = SpaceTimeGrid::makeFiveDimGrid(Ls,UGrid);
|
||||||
|
GridRedBlackCartesian * FrbGrid = SpaceTimeGrid::makeFiveDimRedBlackGrid(Ls,UGrid);
|
||||||
|
|
||||||
|
// Construct a coarsened grid
|
||||||
|
Coordinate clatt = GridDefaultLatt();
|
||||||
|
for(int d=0;d<clatt.size();d++){
|
||||||
|
clatt[d] = clatt[d]/2;
|
||||||
|
// clatt[d] = clatt[d]/4;
|
||||||
|
}
|
||||||
|
GridCartesian *Coarse4d = SpaceTimeGrid::makeFourDimGrid(clatt, GridDefaultSimd(Nd,vComplex::Nsimd()),GridDefaultMpi());;
|
||||||
|
GridCartesian *Coarse5d = SpaceTimeGrid::makeFiveDimGrid(1,Coarse4d);
|
||||||
|
|
||||||
|
std::vector<int> seeds4({1,2,3,4});
|
||||||
|
std::vector<int> seeds5({5,6,7,8});
|
||||||
|
std::vector<int> cseeds({5,6,7,8});
|
||||||
|
GridParallelRNG RNG5(FGrid); RNG5.SeedFixedIntegers(seeds5);
|
||||||
|
GridParallelRNG RNG4(UGrid); RNG4.SeedFixedIntegers(seeds4);
|
||||||
|
GridParallelRNG CRNG(Coarse5d);CRNG.SeedFixedIntegers(cseeds);
|
||||||
|
|
||||||
|
LatticeFermion src(FGrid); random(RNG5,src);
|
||||||
|
LatticeFermion result(FGrid); result=Zero();
|
||||||
|
LatticeFermion ref(FGrid); ref=Zero();
|
||||||
|
LatticeFermion tmp(FGrid);
|
||||||
|
LatticeFermion err(FGrid);
|
||||||
|
LatticeGaugeField Umu(UGrid);
|
||||||
|
|
||||||
|
FieldMetaData header;
|
||||||
|
std::string file("ckpoint_lat.4000");
|
||||||
|
NerscIO::readConfiguration(Umu,header,file);
|
||||||
|
|
||||||
|
RealD mass=0.01;
|
||||||
|
RealD M5=1.8;
|
||||||
|
|
||||||
|
DomainWallFermionD Ddwf(Umu,*FGrid,*FrbGrid,*UGrid,*UrbGrid,mass,M5);
|
||||||
|
DomainWallFermionD Dpv(Umu,*FGrid,*FrbGrid,*UGrid,*UrbGrid,1.0,M5);
|
||||||
|
|
||||||
|
const int nbasis = 20;
|
||||||
|
const int cb = 0 ;
|
||||||
|
|
||||||
|
|
||||||
|
NextToNearestStencilGeometry5D geom(Coarse5d);
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"*******************************************"<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<std::endl;
|
||||||
|
|
||||||
|
typedef PVdagMLinearOperator<DomainWallFermionD,LatticeFermionD> PVdagM_t;
|
||||||
|
typedef MdagPVLinearOperator<DomainWallFermionD,LatticeFermionD> MdagPV_t;
|
||||||
|
typedef ShiftedPVdagMLinearOperator<DomainWallFermionD,LatticeFermionD> ShiftedPVdagM_t;
|
||||||
|
PVdagM_t PVdagM(Ddwf,Dpv);
|
||||||
|
MdagPV_t MdagPV(Ddwf,Dpv);
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(2.0,Ddwf,Dpv); // 355
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(1.0,Ddwf,Dpv); // 246
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.5,Ddwf,Dpv); // 183
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.25,Ddwf,Dpv); // 145
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.1,Ddwf,Dpv); // 134
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.1,Ddwf,Dpv); // 127 -- NULL space via inverse iteration
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.1,Ddwf,Dpv); // 57 -- NULL space via inverse iteration; 3 iterations
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.25,Ddwf,Dpv); // 57 , tighter inversion
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.25,Ddwf,Dpv); // nbasis 20 -- 49 iters
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.25,Ddwf,Dpv); // nbasis 20 -- 70 iters; asymmetric
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.25,Ddwf,Dpv); // 58; Loosen coarse, tighten fine
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.1,Ddwf,Dpv); // 56 ...
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.1,Ddwf,Dpv); // 51 ... with 24 vecs
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.1,Ddwf,Dpv); // 31 ... with 24 vecs and 2^4 blocking
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.1,Ddwf,Dpv); // 43 ... with 16 vecs and 2^4 blocking, sloppier
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.1,Ddwf,Dpv); // 35 ... with 20 vecs and 2^4 blocking
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.1,Ddwf,Dpv); // 35 ... with 20 vecs and 2^4 blocking, looser coarse
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.1,Ddwf,Dpv); // 64 ... with 20 vecs, Christoph setup, and 2^4 blocking, looser coarse
|
||||||
|
ShiftedPVdagM_t ShiftedPVdagM(0.01,Ddwf,Dpv); //
|
||||||
|
|
||||||
|
|
||||||
|
// Run power method on HOA??
|
||||||
|
PowerMethod<LatticeFermion> PM;
|
||||||
|
// PM(PVdagM,src);
|
||||||
|
// PM(MdagPV,src);
|
||||||
|
|
||||||
|
// Warning: This routine calls PVdagM.Op, not PVdagM.HermOp
|
||||||
|
typedef Aggregation<vSpinColourVector,vTComplex,nbasis> Subspace;
|
||||||
|
Subspace V(Coarse5d,FGrid,cb);
|
||||||
|
Subspace U(Coarse5d,FGrid,cb);
|
||||||
|
|
||||||
|
// Breeds right singular vectors with call to HermOp (V)
|
||||||
|
V.CreateSubspace(RNG5,PVdagM,nbasis);
|
||||||
|
|
||||||
|
// Breeds left singular vectors with call to HermOp (U)
|
||||||
|
// U.CreateSubspaceChebyshev(RNG5,MdagPV,
|
||||||
|
U.CreateSubspace(RNG5,PVdagM,nbasis);
|
||||||
|
|
||||||
|
typedef Aggregation<vSpinColourVector,vTComplex,2*nbasis> CombinedSubspace;
|
||||||
|
CombinedSubspace CombinedUV(Coarse5d,FGrid,cb);
|
||||||
|
for(int b=0;b<nbasis;b++){
|
||||||
|
CombinedUV.subspace[b] = V.subspace[b];
|
||||||
|
CombinedUV.subspace[b+nbasis] = U.subspace[b];
|
||||||
|
}
|
||||||
|
|
||||||
|
int bl, br;
|
||||||
|
std::cout <<" <V| PVdagM| V> " <<std::endl;
|
||||||
|
for(bl=0;bl<nbasis;bl++){
|
||||||
|
for(br=0;br<nbasis;br++){
|
||||||
|
PVdagM.Op(V.subspace[br],src);
|
||||||
|
std::cout <<bl<<" "<<br<<"\t"<<innerProduct(V.subspace[bl],src)<<std::endl;
|
||||||
|
}}
|
||||||
|
std::cout <<" <V| PVdagM| U> " <<std::endl;
|
||||||
|
for(bl=0;bl<nbasis;bl++){
|
||||||
|
for(br=0;br<nbasis;br++){
|
||||||
|
PVdagM.Op(U.subspace[br],src);
|
||||||
|
std::cout <<bl<<" "<<br<<"\t"<<innerProduct(V.subspace[bl],src)<<std::endl;
|
||||||
|
}}
|
||||||
|
std::cout <<" <U| PVdagM| V> " <<std::endl;
|
||||||
|
for(bl=0;bl<nbasis;bl++){
|
||||||
|
for(br=0;br<nbasis;br++){
|
||||||
|
PVdagM.Op(V.subspace[br],src);
|
||||||
|
std::cout <<bl<<" "<<br<<"\t"<<innerProduct(U.subspace[bl],src)<<std::endl;
|
||||||
|
}}
|
||||||
|
std::cout <<" <U| PVdagM| U> " <<std::endl;
|
||||||
|
for(bl=0;bl<nbasis;bl++){
|
||||||
|
for(br=0;br<nbasis;br++){
|
||||||
|
PVdagM.Op(U.subspace[br],src);
|
||||||
|
std::cout <<bl<<" "<<br<<"\t"<<innerProduct(U.subspace[bl],src)<<std::endl;
|
||||||
|
}}
|
||||||
|
|
||||||
|
typedef GeneralCoarsenedMatrix<vSpinColourVector,vTComplex,nbasis> LittleDiracOperatorV;
|
||||||
|
typedef LittleDiracOperatorV::CoarseVector CoarseVectorV;
|
||||||
|
|
||||||
|
typedef GeneralCoarsenedMatrix<vSpinColourVector,vTComplex,2*nbasis> LittleDiracOperator;
|
||||||
|
typedef LittleDiracOperator::CoarseVector CoarseVector;
|
||||||
|
|
||||||
|
V.Orthogonalise();
|
||||||
|
for(int b =0 ; b<nbasis;b++){
|
||||||
|
CoarseVectorV c_src (Coarse5d);
|
||||||
|
V.ProjectToSubspace (c_src,U.subspace[b]);
|
||||||
|
V.PromoteFromSubspace(c_src,src);
|
||||||
|
std::cout << " Completeness of U in V ["<< b<<"] "<< std::sqrt(norm2(src)/norm2(U.subspace[b]))<<std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
CoarseVector c_src (Coarse5d);
|
||||||
|
CoarseVector c_res (Coarse5d);
|
||||||
|
CoarseVector c_proj(Coarse5d);
|
||||||
|
LittleDiracOperator LittleDiracOpPV(geom,FGrid,Coarse5d);
|
||||||
|
LittleDiracOpPV.CoarsenOperator(PVdagM,CombinedUV,CombinedUV);
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"*******************************************"<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"Testing coarsened operator "<<std::endl;
|
||||||
|
|
||||||
|
Complex one(1.0);
|
||||||
|
c_src = one; // 1 in every element for vector 1.
|
||||||
|
|
||||||
|
blockPromote(c_src,err,CombinedUV.subspace);
|
||||||
|
|
||||||
|
LatticeFermion prom(FGrid);
|
||||||
|
prom=Zero();
|
||||||
|
for(int b=0;b<nbasis*2;b++){
|
||||||
|
prom=prom+CombinedUV.subspace[b];
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<"c_src "<<norm2(c_src)<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"prom "<<norm2(prom)<<std::endl;
|
||||||
|
|
||||||
|
PVdagM.Op(prom,tmp);
|
||||||
|
blockProject(c_proj,tmp,CombinedUV.subspace);
|
||||||
|
std::cout<<GridLogMessage<<" Called Big Dirac Op "<<norm2(tmp)<<std::endl;
|
||||||
|
|
||||||
|
LittleDiracOpPV.M(c_src,c_res);
|
||||||
|
std::cout<<GridLogMessage<<" Called Little Dirac Op c_src "<< norm2(c_src) << " c_res "<< norm2(c_res) <<std::endl;
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<"Little dop : "<<norm2(c_res)<<std::endl;
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<"Big dop in subspace : "<<norm2(c_proj)<<std::endl;
|
||||||
|
|
||||||
|
c_proj = c_proj - c_res;
|
||||||
|
std::cout<<GridLogMessage<<" ldop error: "<<norm2(c_proj)<<std::endl;
|
||||||
|
|
||||||
|
|
||||||
|
/**********
|
||||||
|
* Some solvers
|
||||||
|
**********
|
||||||
|
*/
|
||||||
|
|
||||||
|
///////////////////////////////////////
|
||||||
|
// Coarse grid solver test
|
||||||
|
///////////////////////////////////////
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<"******************* "<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<" Coarse Grid Solve -- Level 3 "<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"******************* "<<std::endl;
|
||||||
|
TrivialPrecon<CoarseVector> simple;
|
||||||
|
NonHermitianLinearOperator<LittleDiracOperator,CoarseVector> LinOpCoarse(LittleDiracOpPV);
|
||||||
|
// PrecGeneralisedConjugateResidualNonHermitian<CoarseVector> L2PGCR(1.0e-4, 100, LinOpCoarse,simple,10,10);
|
||||||
|
PrecGeneralisedConjugateResidualNonHermitian<CoarseVector> L2PGCR(1.0e-2, 10, LinOpCoarse,simple,20,20);
|
||||||
|
L2PGCR.Level(3);
|
||||||
|
c_res=Zero();
|
||||||
|
L2PGCR(c_src,c_res);
|
||||||
|
|
||||||
|
////////////////////////////////////////
|
||||||
|
// Fine grid smoother
|
||||||
|
////////////////////////////////////////
|
||||||
|
std::cout<<GridLogMessage<<"******************* "<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<" Fine Grid Smoother -- Level 2 "<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"******************* "<<std::endl;
|
||||||
|
TrivialPrecon<LatticeFermionD> simple_fine;
|
||||||
|
// NonHermitianLinearOperator<PVdagM_t,LatticeFermionD> LinOpSmooth(PVdagM);
|
||||||
|
PrecGeneralisedConjugateResidualNonHermitian<LatticeFermionD> SmootherGCR(0.01,1,ShiftedPVdagM,simple_fine,16,16);
|
||||||
|
SmootherGCR.Level(2);
|
||||||
|
|
||||||
|
LatticeFermionD f_src(FGrid);
|
||||||
|
LatticeFermionD f_res(FGrid);
|
||||||
|
|
||||||
|
f_src = one; // 1 in every element for vector 1.
|
||||||
|
f_res=Zero();
|
||||||
|
SmootherGCR(f_src,f_res);
|
||||||
|
|
||||||
|
typedef MGPreconditionerSVD<vSpinColourVector, vTComplex,nbasis*2> TwoLevelMG;
|
||||||
|
|
||||||
|
TwoLevelMG TwoLevelPrecon(CombinedUV,CombinedUV,
|
||||||
|
PVdagM,
|
||||||
|
simple_fine,
|
||||||
|
SmootherGCR,
|
||||||
|
LinOpCoarse,
|
||||||
|
L2PGCR);
|
||||||
|
|
||||||
|
PrecGeneralisedConjugateResidualNonHermitian<LatticeFermion> L1PGCR(1.0e-8,1000,PVdagM,TwoLevelPrecon,20,20);
|
||||||
|
L1PGCR.Level(1);
|
||||||
|
|
||||||
|
f_res=Zero();
|
||||||
|
L1PGCR(f_src,f_res);
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"*******************************************"<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<std::endl;
|
||||||
|
std::cout<<GridLogMessage << "Done "<< std::endl;
|
||||||
|
|
||||||
|
Grid_finalize();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
479
tests/debug/Test_general_coarse_pvdagm_svd_uv.cc
Normal file
479
tests/debug/Test_general_coarse_pvdagm_svd_uv.cc
Normal file
@@ -0,0 +1,479 @@
|
|||||||
|
/*************************************************************************************
|
||||||
|
|
||||||
|
Grid physics library, www.github.com/paboyle/Grid
|
||||||
|
|
||||||
|
Source file: ./tests/Test_padded_cell.cc
|
||||||
|
|
||||||
|
Copyright (C) 2023
|
||||||
|
|
||||||
|
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
|
See the full license in the file "LICENSE" in the top level distribution directory
|
||||||
|
*************************************************************************************/
|
||||||
|
/* END LEGAL */
|
||||||
|
#include <Grid/Grid.h>
|
||||||
|
#include <Grid/lattice/PaddedCell.h>
|
||||||
|
#include <Grid/stencil/GeneralLocalStencil.h>
|
||||||
|
|
||||||
|
#include <Grid/algorithms/iterative/PrecGeneralisedConjugateResidual.h>
|
||||||
|
#include <Grid/algorithms/iterative/PrecGeneralisedConjugateResidualNonHermitian.h>
|
||||||
|
#include <Grid/algorithms/iterative/BiCGSTAB.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace Grid;
|
||||||
|
|
||||||
|
template<class Matrix,class Field>
|
||||||
|
class PVdagMLinearOperator : public LinearOperatorBase<Field> {
|
||||||
|
Matrix &_Mat;
|
||||||
|
Matrix &_PV;
|
||||||
|
public:
|
||||||
|
PVdagMLinearOperator(Matrix &Mat,Matrix &PV): _Mat(Mat),_PV(PV){};
|
||||||
|
|
||||||
|
void OpDiag (const Field &in, Field &out) { assert(0); }
|
||||||
|
void OpDir (const Field &in, Field &out,int dir,int disp) { assert(0); }
|
||||||
|
void OpDirAll (const Field &in, std::vector<Field> &out){ assert(0); };
|
||||||
|
void Op (const Field &in, Field &out){
|
||||||
|
// std::cout << GridLogMessage<< "Op: PVdag M "<<std::endl;
|
||||||
|
Field tmp(in.Grid());
|
||||||
|
_Mat.M(in,tmp);
|
||||||
|
_PV.Mdag(tmp,out);
|
||||||
|
}
|
||||||
|
void AdjOp (const Field &in, Field &out){
|
||||||
|
// std::cout << GridLogMessage<<"AdjOp: Mdag PV "<<std::endl;
|
||||||
|
Field tmp(in.Grid());
|
||||||
|
_PV.M(in,tmp);
|
||||||
|
_Mat.Mdag(tmp,out);
|
||||||
|
}
|
||||||
|
void HermOpAndNorm(const Field &in, Field &out,RealD &n1,RealD &n2){
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
void HermOp(const Field &in, Field &out){
|
||||||
|
// std::cout <<GridLogMessage<< "HermOp: Mdag PV PVdag M"<<std::endl;
|
||||||
|
Field tmp(in.Grid());
|
||||||
|
Op(in,tmp);
|
||||||
|
AdjOp(tmp,out);
|
||||||
|
// std::cout << "HermOp done "<<norm2(out)<<std::endl;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template<class Matrix,class Field>
|
||||||
|
class MdagPVLinearOperator : public LinearOperatorBase<Field> {
|
||||||
|
Matrix &_Mat;
|
||||||
|
Matrix &_PV;
|
||||||
|
public:
|
||||||
|
MdagPVLinearOperator(Matrix &Mat,Matrix &PV): _Mat(Mat),_PV(PV){};
|
||||||
|
|
||||||
|
void OpDiag (const Field &in, Field &out) { assert(0); }
|
||||||
|
void OpDir (const Field &in, Field &out,int dir,int disp) { assert(0); }
|
||||||
|
void OpDirAll (const Field &in, std::vector<Field> &out){ assert(0); };
|
||||||
|
void Op (const Field &in, Field &out){
|
||||||
|
Field tmp(in.Grid());
|
||||||
|
// std::cout <<GridLogMessage<< "Op: PVdag M "<<std::endl;
|
||||||
|
_PV.M(in,tmp);
|
||||||
|
_Mat.Mdag(tmp,out);
|
||||||
|
}
|
||||||
|
void AdjOp (const Field &in, Field &out){
|
||||||
|
// std::cout <<GridLogMessage<< "AdjOp: Mdag PV "<<std::endl;
|
||||||
|
Field tmp(in.Grid());
|
||||||
|
_Mat.M(in,tmp);
|
||||||
|
_PV.Mdag(tmp,out);
|
||||||
|
}
|
||||||
|
void HermOpAndNorm(const Field &in, Field &out,RealD &n1,RealD &n2){
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
void HermOp(const Field &in, Field &out){
|
||||||
|
// std::cout << GridLogMessage<<"HermOp: PVdag M Mdag PV "<<std::endl;
|
||||||
|
Field tmp(in.Grid());
|
||||||
|
Op(in,tmp);
|
||||||
|
AdjOp(tmp,out);
|
||||||
|
// std::cout << "HermOp done "<<norm2(out)<<std::endl;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template<class Matrix,class Field>
|
||||||
|
class ShiftedPVdagMLinearOperator : public LinearOperatorBase<Field> {
|
||||||
|
Matrix &_Mat;
|
||||||
|
Matrix &_PV;
|
||||||
|
RealD shift;
|
||||||
|
public:
|
||||||
|
ShiftedPVdagMLinearOperator(RealD _shift,Matrix &Mat,Matrix &PV): shift(_shift),_Mat(Mat),_PV(PV){};
|
||||||
|
|
||||||
|
void OpDiag (const Field &in, Field &out) { assert(0); }
|
||||||
|
void OpDir (const Field &in, Field &out,int dir,int disp) { assert(0); }
|
||||||
|
void OpDirAll (const Field &in, std::vector<Field> &out){ assert(0); };
|
||||||
|
void Op (const Field &in, Field &out){
|
||||||
|
// std::cout << "Op: PVdag M "<<std::endl;
|
||||||
|
Field tmp(in.Grid());
|
||||||
|
_Mat.M(in,tmp);
|
||||||
|
_PV.Mdag(tmp,out);
|
||||||
|
out = out + shift * in;
|
||||||
|
}
|
||||||
|
void AdjOp (const Field &in, Field &out){
|
||||||
|
// std::cout << "AdjOp: Mdag PV "<<std::endl;
|
||||||
|
Field tmp(in.Grid());
|
||||||
|
_PV.M(tmp,out);
|
||||||
|
_Mat.Mdag(in,tmp);
|
||||||
|
out = out + shift * in;
|
||||||
|
}
|
||||||
|
void HermOpAndNorm(const Field &in, Field &out,RealD &n1,RealD &n2){ assert(0); }
|
||||||
|
void HermOp(const Field &in, Field &out){
|
||||||
|
// std::cout << "HermOp: Mdag PV PVdag M"<<std::endl;
|
||||||
|
Field tmp(in.Grid());
|
||||||
|
Op(in,tmp);
|
||||||
|
AdjOp(tmp,out);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template<class Fobj,class CComplex,int nbasis>
|
||||||
|
class MGPreconditionerSVD : public LinearFunction< Lattice<Fobj> > {
|
||||||
|
public:
|
||||||
|
using LinearFunction<Lattice<Fobj> >::operator();
|
||||||
|
|
||||||
|
typedef Aggregation<Fobj,CComplex,nbasis> Aggregates;
|
||||||
|
typedef typename Aggregation<Fobj,CComplex,nbasis>::FineField FineField;
|
||||||
|
typedef typename Aggregation<Fobj,CComplex,nbasis>::CoarseVector CoarseVector;
|
||||||
|
typedef typename Aggregation<Fobj,CComplex,nbasis>::CoarseMatrix CoarseMatrix;
|
||||||
|
typedef LinearOperatorBase<FineField> FineOperator;
|
||||||
|
typedef LinearFunction <FineField> FineSmoother;
|
||||||
|
typedef LinearOperatorBase<CoarseVector> CoarseOperator;
|
||||||
|
typedef LinearFunction <CoarseVector> CoarseSolver;
|
||||||
|
///////////////////////////////
|
||||||
|
// SVD is M = U S Vdag
|
||||||
|
//
|
||||||
|
// Define a subset of Vc and Uc in Complex_f,c matrix
|
||||||
|
// - these are the coarsening, non-square matrices
|
||||||
|
//
|
||||||
|
// Solve a coarse approx to
|
||||||
|
//
|
||||||
|
// M psi = eta
|
||||||
|
//
|
||||||
|
// via
|
||||||
|
//
|
||||||
|
// Uc^dag U S Vdag Vc Vc^dag psi = Uc^dag eta
|
||||||
|
//
|
||||||
|
// M_coarse Vc^dag psi = M_coarse psi_c = eta_c
|
||||||
|
//
|
||||||
|
///////////////////////////////
|
||||||
|
Aggregates & _U;
|
||||||
|
Aggregates & _V;
|
||||||
|
FineOperator & _FineOperator;
|
||||||
|
FineSmoother & _PreSmoother;
|
||||||
|
FineSmoother & _PostSmoother;
|
||||||
|
CoarseOperator & _CoarseOperator;
|
||||||
|
CoarseSolver & _CoarseSolve;
|
||||||
|
|
||||||
|
int level; void Level(int lv) {level = lv; };
|
||||||
|
|
||||||
|
MGPreconditionerSVD(Aggregates &U,
|
||||||
|
Aggregates &V,
|
||||||
|
FineOperator &Fine,
|
||||||
|
FineSmoother &PreSmoother,
|
||||||
|
FineSmoother &PostSmoother,
|
||||||
|
CoarseOperator &CoarseOperator_,
|
||||||
|
CoarseSolver &CoarseSolve_)
|
||||||
|
: _U(U),
|
||||||
|
_V(V),
|
||||||
|
_FineOperator(Fine),
|
||||||
|
_PreSmoother(PreSmoother),
|
||||||
|
_PostSmoother(PostSmoother),
|
||||||
|
_CoarseOperator(CoarseOperator_),
|
||||||
|
_CoarseSolve(CoarseSolve_),
|
||||||
|
level(1) { }
|
||||||
|
|
||||||
|
virtual void operator()(const FineField &in, FineField & out)
|
||||||
|
{
|
||||||
|
GridBase *CoarseGrid = _U.CoarseGrid;
|
||||||
|
// auto CoarseGrid = _CoarseOperator.Grid();
|
||||||
|
CoarseVector Csrc(CoarseGrid);
|
||||||
|
CoarseVector Csol(CoarseGrid);
|
||||||
|
FineField vec1(in.Grid());
|
||||||
|
FineField vec2(in.Grid());
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage << "Calling PreSmoother " <<std::endl;
|
||||||
|
|
||||||
|
// std::cout<<GridLogMessage << "Calling PreSmoother input residual "<<norm2(in) <<std::endl;
|
||||||
|
double t;
|
||||||
|
// Fine Smoother
|
||||||
|
// out = in;
|
||||||
|
out = Zero();
|
||||||
|
t=-usecond();
|
||||||
|
_PreSmoother(in,out);
|
||||||
|
t+=usecond();
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage << "PreSmoother took "<< t/1000.0<< "ms" <<std::endl;
|
||||||
|
|
||||||
|
// Update the residual
|
||||||
|
_FineOperator.Op(out,vec1); sub(vec1, in ,vec1);
|
||||||
|
// std::cout<<GridLogMessage <<"Residual-1 now " <<norm2(vec1)<<std::endl;
|
||||||
|
|
||||||
|
// Uc^dag U S Vdag Vc Vc^dag psi = Uc^dag eta
|
||||||
|
// Fine to Coarse
|
||||||
|
t=-usecond();
|
||||||
|
_U.ProjectToSubspace (Csrc,vec1);
|
||||||
|
t+=usecond();
|
||||||
|
std::cout<<GridLogMessage << "Project to coarse took "<< t/1000.0<< "ms" <<std::endl;
|
||||||
|
|
||||||
|
// Coarse correction
|
||||||
|
t=-usecond();
|
||||||
|
Csol = Zero();
|
||||||
|
_CoarseSolve(Csrc,Csol);
|
||||||
|
//Csol=Zero();
|
||||||
|
t+=usecond();
|
||||||
|
std::cout<<GridLogMessage << "Coarse solve took "<< t/1000.0<< "ms" <<std::endl;
|
||||||
|
|
||||||
|
// Coarse to Fine
|
||||||
|
t=-usecond();
|
||||||
|
// _CoarseOperator.PromoteFromSubspace(_Aggregates,Csol,vec1);
|
||||||
|
_V.PromoteFromSubspace(Csol,vec1);
|
||||||
|
add(out,out,vec1);
|
||||||
|
t+=usecond();
|
||||||
|
std::cout<<GridLogMessage << "Promote to this level took "<< t/1000.0<< "ms" <<std::endl;
|
||||||
|
|
||||||
|
// Residual
|
||||||
|
_FineOperator.Op(out,vec1); sub(vec1 ,in , vec1);
|
||||||
|
// std::cout<<GridLogMessage <<"Residual-2 now " <<norm2(vec1)<<std::endl;
|
||||||
|
|
||||||
|
// Fine Smoother
|
||||||
|
t=-usecond();
|
||||||
|
// vec2=vec1;
|
||||||
|
vec2=Zero();
|
||||||
|
_PostSmoother(vec1,vec2);
|
||||||
|
t+=usecond();
|
||||||
|
std::cout<<GridLogMessage << "PostSmoother took "<< t/1000.0<< "ms" <<std::endl;
|
||||||
|
|
||||||
|
add( out,out,vec2);
|
||||||
|
std::cout<<GridLogMessage << "Done " <<std::endl;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main (int argc, char ** argv)
|
||||||
|
{
|
||||||
|
Grid_init(&argc,&argv);
|
||||||
|
|
||||||
|
const int Ls=16;
|
||||||
|
|
||||||
|
GridCartesian * UGrid = SpaceTimeGrid::makeFourDimGrid(GridDefaultLatt(), GridDefaultSimd(Nd,vComplex::Nsimd()),GridDefaultMpi());
|
||||||
|
GridRedBlackCartesian * UrbGrid = SpaceTimeGrid::makeFourDimRedBlackGrid(UGrid);
|
||||||
|
|
||||||
|
GridCartesian * FGrid = SpaceTimeGrid::makeFiveDimGrid(Ls,UGrid);
|
||||||
|
GridRedBlackCartesian * FrbGrid = SpaceTimeGrid::makeFiveDimRedBlackGrid(Ls,UGrid);
|
||||||
|
|
||||||
|
// Construct a coarsened grid
|
||||||
|
Coordinate clatt = GridDefaultLatt();
|
||||||
|
for(int d=0;d<clatt.size();d++){
|
||||||
|
clatt[d] = clatt[d]/2;
|
||||||
|
// clatt[d] = clatt[d]/4;
|
||||||
|
}
|
||||||
|
GridCartesian *Coarse4d = SpaceTimeGrid::makeFourDimGrid(clatt, GridDefaultSimd(Nd,vComplex::Nsimd()),GridDefaultMpi());;
|
||||||
|
GridCartesian *Coarse5d = SpaceTimeGrid::makeFiveDimGrid(1,Coarse4d);
|
||||||
|
|
||||||
|
std::vector<int> seeds4({1,2,3,4});
|
||||||
|
std::vector<int> seeds5({5,6,7,8});
|
||||||
|
std::vector<int> cseeds({5,6,7,8});
|
||||||
|
GridParallelRNG RNG5(FGrid); RNG5.SeedFixedIntegers(seeds5);
|
||||||
|
GridParallelRNG RNG4(UGrid); RNG4.SeedFixedIntegers(seeds4);
|
||||||
|
GridParallelRNG CRNG(Coarse5d);CRNG.SeedFixedIntegers(cseeds);
|
||||||
|
|
||||||
|
LatticeFermion src(FGrid); random(RNG5,src);
|
||||||
|
LatticeFermion result(FGrid); result=Zero();
|
||||||
|
LatticeFermion ref(FGrid); ref=Zero();
|
||||||
|
LatticeFermion tmp(FGrid);
|
||||||
|
LatticeFermion err(FGrid);
|
||||||
|
LatticeGaugeField Umu(UGrid);
|
||||||
|
|
||||||
|
FieldMetaData header;
|
||||||
|
std::string file("ckpoint_lat.4000");
|
||||||
|
NerscIO::readConfiguration(Umu,header,file);
|
||||||
|
|
||||||
|
RealD mass=0.01;
|
||||||
|
RealD M5=1.8;
|
||||||
|
|
||||||
|
DomainWallFermionD Ddwf(Umu,*FGrid,*FrbGrid,*UGrid,*UrbGrid,mass,M5);
|
||||||
|
DomainWallFermionD Dpv(Umu,*FGrid,*FrbGrid,*UGrid,*UrbGrid,1.0,M5);
|
||||||
|
|
||||||
|
const int nbasis = 60;
|
||||||
|
const int cb = 0 ;
|
||||||
|
|
||||||
|
NextToNearestStencilGeometry5D geom(Coarse5d);
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"*******************************************"<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<std::endl;
|
||||||
|
|
||||||
|
typedef PVdagMLinearOperator<DomainWallFermionD,LatticeFermionD> PVdagM_t;
|
||||||
|
typedef MdagPVLinearOperator<DomainWallFermionD,LatticeFermionD> MdagPV_t;
|
||||||
|
typedef ShiftedPVdagMLinearOperator<DomainWallFermionD,LatticeFermionD> ShiftedPVdagM_t;
|
||||||
|
PVdagM_t PVdagM(Ddwf,Dpv);
|
||||||
|
MdagPV_t MdagPV(Ddwf,Dpv);
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(2.0,Ddwf,Dpv); // 355
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(1.0,Ddwf,Dpv); // 246
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.5,Ddwf,Dpv); // 183
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.25,Ddwf,Dpv); // 145
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.1,Ddwf,Dpv); // 134
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.1,Ddwf,Dpv); // 127 -- NULL space via inverse iteration
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.1,Ddwf,Dpv); // 57 -- NULL space via inverse iteration; 3 iterations
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.25,Ddwf,Dpv); // 57 , tighter inversion
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.25,Ddwf,Dpv); // nbasis 20 -- 49 iters
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.25,Ddwf,Dpv); // nbasis 20 -- 70 iters; asymmetric
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.25,Ddwf,Dpv); // 58; Loosen coarse, tighten fine
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.1,Ddwf,Dpv); // 56 ...
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.1,Ddwf,Dpv); // 51 ... with 24 vecs
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.1,Ddwf,Dpv); // 31 ... with 24 vecs and 2^4 blocking
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.1,Ddwf,Dpv); // 43 ... with 16 vecs and 2^4 blocking, sloppier
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.1,Ddwf,Dpv); // 35 ... with 20 vecs and 2^4 blocking
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.1,Ddwf,Dpv); // 35 ... with 20 vecs and 2^4 blocking, looser coarse
|
||||||
|
// ShiftedPVdagM_t ShiftedPVdagM(0.1,Ddwf,Dpv); // 64 ... with 20 vecs, Christoph setup, and 2^4 blocking, looser coarse
|
||||||
|
ShiftedPVdagM_t ShiftedPVdagM(0.01,Ddwf,Dpv); //
|
||||||
|
|
||||||
|
|
||||||
|
// Run power method on HOA??
|
||||||
|
PowerMethod<LatticeFermion> PM;
|
||||||
|
PM(PVdagM,src);
|
||||||
|
PM(MdagPV,src);
|
||||||
|
|
||||||
|
|
||||||
|
// Warning: This routine calls PVdagM.Op, not PVdagM.HermOp
|
||||||
|
typedef Aggregation<vSpinColourVector,vTComplex,nbasis> Subspace;
|
||||||
|
Subspace V(Coarse5d,FGrid,cb);
|
||||||
|
// Subspace U(Coarse5d,FGrid,cb);
|
||||||
|
|
||||||
|
// Breeds right singular vectors with call to HermOp
|
||||||
|
V.CreateSubspaceChebyshev(RNG5,PVdagM,
|
||||||
|
nbasis,
|
||||||
|
4000.0,0.003,
|
||||||
|
300);
|
||||||
|
|
||||||
|
// Breeds left singular vectors with call to HermOp
|
||||||
|
// U.CreateSubspaceChebyshev(RNG5,MdagPV,
|
||||||
|
// nbasis,
|
||||||
|
// 4000.0,0.003,
|
||||||
|
// 300);
|
||||||
|
// U.subspace=V.subspace;
|
||||||
|
|
||||||
|
// typedef Aggregation<vSpinColourVector,vTComplex,2*nbasis> CombinedSubspace;
|
||||||
|
// CombinedSubspace CombinedUV(Coarse5d,FGrid,cb);
|
||||||
|
// for(int b=0;b<nbasis;b++){
|
||||||
|
// CombinedUV.subspace[b] = V.subspace[b];
|
||||||
|
// CombinedUV.subspace[b+nbasis] = U.subspace[b];
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
// typedef GeneralCoarsenedMatrix<vSpinColourVector,vTComplex,2*nbasis> LittleDiracOperator;
|
||||||
|
typedef GeneralCoarsenedMatrix<vSpinColourVector,vTComplex,nbasis> LittleDiracOperator;
|
||||||
|
typedef LittleDiracOperator::CoarseVector CoarseVector;
|
||||||
|
LittleDiracOperator LittleDiracOpPV(geom,FGrid,Coarse5d);
|
||||||
|
LittleDiracOpPV.CoarsenOperator(PVdagM,V,V);
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"*******************************************"<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"Testing coarsened operator "<<std::endl;
|
||||||
|
|
||||||
|
CoarseVector c_src (Coarse5d);
|
||||||
|
CoarseVector c_res (Coarse5d);
|
||||||
|
CoarseVector c_proj(Coarse5d);
|
||||||
|
|
||||||
|
|
||||||
|
Complex one(1.0);
|
||||||
|
c_src = one; // 1 in every element for vector 1.
|
||||||
|
|
||||||
|
// blockPromote(c_src,err,CoarseToFine.subspace);
|
||||||
|
|
||||||
|
LatticeFermion prom(FGrid);
|
||||||
|
prom=Zero();
|
||||||
|
for(int b=0;b<nbasis;b++){
|
||||||
|
prom=prom+V.subspace[b];
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<"c_src "<<norm2(c_src)<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"prom "<<norm2(prom)<<std::endl;
|
||||||
|
|
||||||
|
PVdagM.Op(prom,tmp);
|
||||||
|
blockProject(c_proj,tmp,V.subspace);
|
||||||
|
std::cout<<GridLogMessage<<" Called Big Dirac Op "<<norm2(tmp)<<std::endl;
|
||||||
|
|
||||||
|
LittleDiracOpPV.M(c_src,c_res);
|
||||||
|
std::cout<<GridLogMessage<<" Called Little Dirac Op c_src "<< norm2(c_src) << " c_res "<< norm2(c_res) <<std::endl;
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<"Little dop : "<<norm2(c_res)<<std::endl;
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<"Big dop in subspace : "<<norm2(c_proj)<<std::endl;
|
||||||
|
|
||||||
|
c_proj = c_proj - c_res;
|
||||||
|
std::cout<<GridLogMessage<<" ldop error: "<<norm2(c_proj)<<std::endl;
|
||||||
|
|
||||||
|
|
||||||
|
/**********
|
||||||
|
* Some solvers
|
||||||
|
**********
|
||||||
|
*/
|
||||||
|
|
||||||
|
///////////////////////////////////////
|
||||||
|
// Coarse grid solver test
|
||||||
|
///////////////////////////////////////
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<"******************* "<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<" Coarse Grid Solve -- Level 3 "<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"******************* "<<std::endl;
|
||||||
|
TrivialPrecon<CoarseVector> simple;
|
||||||
|
NonHermitianLinearOperator<LittleDiracOperator,CoarseVector> LinOpCoarse(LittleDiracOpPV);
|
||||||
|
// PrecGeneralisedConjugateResidualNonHermitian<CoarseVector> L2PGCR(1.0e-4, 100, LinOpCoarse,simple,10,10);
|
||||||
|
PrecGeneralisedConjugateResidualNonHermitian<CoarseVector> L3PGCR(1.0e-4, 10, LinOpCoarse,simple,20,20);
|
||||||
|
L3PGCR.Level(3);
|
||||||
|
c_res=Zero();
|
||||||
|
L3PGCR(c_src,c_res);
|
||||||
|
|
||||||
|
////////////////////////////////////////
|
||||||
|
// Fine grid smoother
|
||||||
|
////////////////////////////////////////
|
||||||
|
std::cout<<GridLogMessage<<"******************* "<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<" Fine Grid Smoother -- Level 2 "<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"******************* "<<std::endl;
|
||||||
|
TrivialPrecon<LatticeFermionD> simple_fine;
|
||||||
|
// NonHermitianLinearOperator<PVdagM_t,LatticeFermionD> LinOpSmooth(PVdagM);
|
||||||
|
PrecGeneralisedConjugateResidualNonHermitian<LatticeFermionD> SmootherGCR(0.01,1,ShiftedPVdagM,simple_fine,16,16);
|
||||||
|
SmootherGCR.Level(2);
|
||||||
|
|
||||||
|
LatticeFermionD f_src(FGrid);
|
||||||
|
LatticeFermionD f_res(FGrid);
|
||||||
|
|
||||||
|
f_src = one; // 1 in every element for vector 1.
|
||||||
|
f_res=Zero();
|
||||||
|
SmootherGCR(f_src,f_res);
|
||||||
|
|
||||||
|
// typedef MGPreconditionerSVD<vSpinColourVector, vTComplex,nbasis*2> TwoLevelMG;
|
||||||
|
typedef MGPreconditionerSVD<vSpinColourVector, vTComplex,nbasis> TwoLevelMG;
|
||||||
|
|
||||||
|
// TwoLevelMG TwoLevelPrecon(CombinedUV,CombinedUV,
|
||||||
|
TwoLevelMG TwoLevelPrecon(V,V,
|
||||||
|
PVdagM,
|
||||||
|
simple_fine,
|
||||||
|
SmootherGCR,
|
||||||
|
LinOpCoarse,
|
||||||
|
L3PGCR);
|
||||||
|
|
||||||
|
PrecGeneralisedConjugateResidualNonHermitian<LatticeFermion> L1PGCR(1.0e-8,1000,PVdagM,TwoLevelPrecon,16,16);
|
||||||
|
L1PGCR.Level(1);
|
||||||
|
|
||||||
|
f_res=Zero();
|
||||||
|
L1PGCR(f_src,f_res);
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"*******************************************"<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<std::endl;
|
||||||
|
std::cout<<GridLogMessage << "Done "<< std::endl;
|
||||||
|
|
||||||
|
Grid_finalize();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
333
tests/debug/Test_general_coarse_wilson.cc
Normal file
333
tests/debug/Test_general_coarse_wilson.cc
Normal file
@@ -0,0 +1,333 @@
|
|||||||
|
/*************************************************************************************
|
||||||
|
|
||||||
|
Grid physics library, www.github.com/paboyle/Grid
|
||||||
|
|
||||||
|
Source file: ./tests/Test_padded_cell.cc
|
||||||
|
|
||||||
|
Copyright (C) 2023
|
||||||
|
|
||||||
|
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
|
See the full license in the file "LICENSE" in the top level distribution directory
|
||||||
|
*************************************************************************************/
|
||||||
|
/* END LEGAL */
|
||||||
|
#include <Grid/Grid.h>
|
||||||
|
#include <Grid/lattice/PaddedCell.h>
|
||||||
|
#include <Grid/stencil/GeneralLocalStencil.h>
|
||||||
|
|
||||||
|
#include <Grid/algorithms/iterative/PrecGeneralisedConjugateResidual.h>
|
||||||
|
#include <Grid/algorithms/iterative/PrecGeneralisedConjugateResidualNonHermitian.h>
|
||||||
|
#include <Grid/algorithms/iterative/BiCGSTAB.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace Grid;
|
||||||
|
|
||||||
|
template<class Fobj,class CComplex,int nbasis>
|
||||||
|
class MGPreconditioner : public LinearFunction< Lattice<Fobj> > {
|
||||||
|
public:
|
||||||
|
using LinearFunction<Lattice<Fobj> >::operator();
|
||||||
|
|
||||||
|
typedef Aggregation<Fobj,CComplex,nbasis> Aggregates;
|
||||||
|
typedef typename Aggregation<Fobj,CComplex,nbasis>::FineField FineField;
|
||||||
|
typedef typename Aggregation<Fobj,CComplex,nbasis>::CoarseVector CoarseVector;
|
||||||
|
typedef typename Aggregation<Fobj,CComplex,nbasis>::CoarseMatrix CoarseMatrix;
|
||||||
|
typedef LinearOperatorBase<FineField> FineOperator;
|
||||||
|
typedef LinearFunction <FineField> FineSmoother;
|
||||||
|
typedef LinearOperatorBase<CoarseVector> CoarseOperator;
|
||||||
|
typedef LinearFunction <CoarseVector> CoarseSolver;
|
||||||
|
Aggregates & _Aggregates;
|
||||||
|
FineOperator & _FineOperator;
|
||||||
|
FineSmoother & _PreSmoother;
|
||||||
|
FineSmoother & _PostSmoother;
|
||||||
|
CoarseOperator & _CoarseOperator;
|
||||||
|
CoarseSolver & _CoarseSolve;
|
||||||
|
|
||||||
|
int level; void Level(int lv) {level = lv; };
|
||||||
|
|
||||||
|
MGPreconditioner(Aggregates &Agg,
|
||||||
|
FineOperator &Fine,
|
||||||
|
FineSmoother &PreSmoother,
|
||||||
|
FineSmoother &PostSmoother,
|
||||||
|
CoarseOperator &CoarseOperator_,
|
||||||
|
CoarseSolver &CoarseSolve_)
|
||||||
|
: _Aggregates(Agg),
|
||||||
|
_FineOperator(Fine),
|
||||||
|
_PreSmoother(PreSmoother),
|
||||||
|
_PostSmoother(PostSmoother),
|
||||||
|
_CoarseOperator(CoarseOperator_),
|
||||||
|
_CoarseSolve(CoarseSolve_),
|
||||||
|
level(1) { }
|
||||||
|
|
||||||
|
virtual void operator()(const FineField &in, FineField & out)
|
||||||
|
{
|
||||||
|
GridBase *CoarseGrid = _Aggregates.CoarseGrid;
|
||||||
|
// auto CoarseGrid = _CoarseOperator.Grid();
|
||||||
|
CoarseVector Csrc(CoarseGrid);
|
||||||
|
CoarseVector Csol(CoarseGrid);
|
||||||
|
FineField vec1(in.Grid());
|
||||||
|
FineField vec2(in.Grid());
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage << "Calling PreSmoother " <<std::endl;
|
||||||
|
|
||||||
|
// std::cout<<GridLogMessage << "Calling PreSmoother input residual "<<norm2(in) <<std::endl;
|
||||||
|
double t;
|
||||||
|
// Fine Smoother
|
||||||
|
// out = in;
|
||||||
|
out = Zero();
|
||||||
|
t=-usecond();
|
||||||
|
_PreSmoother(in,out);
|
||||||
|
t+=usecond();
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage << "PreSmoother took "<< t/1000.0<< "ms" <<std::endl;
|
||||||
|
|
||||||
|
// Update the residual
|
||||||
|
_FineOperator.Op(out,vec1); sub(vec1, in ,vec1);
|
||||||
|
// std::cout<<GridLogMessage <<"Residual-1 now " <<norm2(vec1)<<std::endl;
|
||||||
|
|
||||||
|
// Fine to Coarse
|
||||||
|
t=-usecond();
|
||||||
|
_Aggregates.ProjectToSubspace (Csrc,vec1);
|
||||||
|
t+=usecond();
|
||||||
|
std::cout<<GridLogMessage << "Project to coarse took "<< t/1000.0<< "ms" <<std::endl;
|
||||||
|
|
||||||
|
// Coarse correction
|
||||||
|
t=-usecond();
|
||||||
|
Csol = Zero();
|
||||||
|
_CoarseSolve(Csrc,Csol);
|
||||||
|
//Csol=Zero();
|
||||||
|
t+=usecond();
|
||||||
|
std::cout<<GridLogMessage << "Coarse solve took "<< t/1000.0<< "ms" <<std::endl;
|
||||||
|
|
||||||
|
// Coarse to Fine
|
||||||
|
t=-usecond();
|
||||||
|
// _CoarseOperator.PromoteFromSubspace(_Aggregates,Csol,vec1);
|
||||||
|
_Aggregates.PromoteFromSubspace(Csol,vec1);
|
||||||
|
add(out,out,vec1);
|
||||||
|
t+=usecond();
|
||||||
|
std::cout<<GridLogMessage << "Promote to this level took "<< t/1000.0<< "ms" <<std::endl;
|
||||||
|
|
||||||
|
// Residual
|
||||||
|
_FineOperator.Op(out,vec1); sub(vec1 ,in , vec1);
|
||||||
|
// std::cout<<GridLogMessage <<"Residual-2 now " <<norm2(vec1)<<std::endl;
|
||||||
|
|
||||||
|
// Fine Smoother
|
||||||
|
t=-usecond();
|
||||||
|
// vec2=vec1;
|
||||||
|
vec2=Zero();
|
||||||
|
_PostSmoother(vec1,vec2);
|
||||||
|
t+=usecond();
|
||||||
|
std::cout<<GridLogMessage << "PostSmoother took "<< t/1000.0<< "ms" <<std::endl;
|
||||||
|
|
||||||
|
add( out,out,vec2);
|
||||||
|
std::cout<<GridLogMessage << "Done " <<std::endl;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main (int argc, char ** argv)
|
||||||
|
{
|
||||||
|
Grid_init(&argc,&argv);
|
||||||
|
|
||||||
|
const int Ls=16;
|
||||||
|
|
||||||
|
GridCartesian * UGrid = SpaceTimeGrid::makeFourDimGrid(GridDefaultLatt(), GridDefaultSimd(Nd,vComplex::Nsimd()),GridDefaultMpi());
|
||||||
|
GridRedBlackCartesian * UrbGrid = SpaceTimeGrid::makeFourDimRedBlackGrid(UGrid);
|
||||||
|
|
||||||
|
GridCartesian * FGrid = UGrid;
|
||||||
|
GridRedBlackCartesian * FrbGrid = UrbGrid;
|
||||||
|
|
||||||
|
// Construct a coarsened grid
|
||||||
|
Coordinate clatt = GridDefaultLatt();
|
||||||
|
for(int d=0;d<clatt.size();d++){
|
||||||
|
clatt[d] = clatt[d]/2;
|
||||||
|
//clatt[d] = clatt[d]/4;
|
||||||
|
}
|
||||||
|
GridCartesian *Coarse4d = SpaceTimeGrid::makeFourDimGrid(clatt, GridDefaultSimd(Nd,vComplex::Nsimd()),GridDefaultMpi());;
|
||||||
|
|
||||||
|
std::vector<int> seeds4({1,2,3,4});
|
||||||
|
std::vector<int> cseeds({5,6,7,8});
|
||||||
|
GridParallelRNG RNG4(UGrid); RNG4.SeedFixedIntegers(seeds4);
|
||||||
|
GridParallelRNG CRNG(Coarse4d);CRNG.SeedFixedIntegers(cseeds);
|
||||||
|
|
||||||
|
Complex one(1.0);
|
||||||
|
|
||||||
|
LatticeFermion src(FGrid); src=one;
|
||||||
|
LatticeFermion result(FGrid); result=Zero();
|
||||||
|
LatticeFermion ref(FGrid); ref=Zero();
|
||||||
|
LatticeFermion tmp(FGrid);
|
||||||
|
LatticeFermion err(FGrid);
|
||||||
|
LatticeFermion precsrc(FGrid);
|
||||||
|
LatticeGaugeField Umu(UGrid);
|
||||||
|
|
||||||
|
FieldMetaData header;
|
||||||
|
std::string file("ckpoint_lat");
|
||||||
|
NerscIO::readConfiguration(Umu,header,file);
|
||||||
|
|
||||||
|
RealD csw =0.0;
|
||||||
|
RealD mass=-0.92;
|
||||||
|
|
||||||
|
WilsonCloverFermionD Dw(Umu,*UGrid,*UrbGrid,mass,csw,csw);
|
||||||
|
|
||||||
|
const int nbasis = 20;
|
||||||
|
const int cb = 0 ;
|
||||||
|
LatticeFermion prom(FGrid);
|
||||||
|
|
||||||
|
typedef GeneralCoarsenedMatrix<vSpinColourVector,vTComplex,2*nbasis> LittleDiracOperator;
|
||||||
|
typedef LittleDiracOperator::CoarseVector CoarseVector;
|
||||||
|
|
||||||
|
NearestStencilGeometry4D geom(Coarse4d);
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"*******************************************"<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<std::endl;
|
||||||
|
|
||||||
|
// Warning: This routine calls Linop.Op, not LinOpo.HermOp
|
||||||
|
typedef Aggregation<vSpinColourVector,vTComplex,nbasis> Subspace;
|
||||||
|
Subspace Aggregates(Coarse4d,FGrid,cb);
|
||||||
|
|
||||||
|
NonHermitianLinearOperator<WilsonCloverFermionD,LatticeFermion> LinOpDw(Dw);
|
||||||
|
ShiftedNonHermitianLinearOperator<WilsonCloverFermionD,LatticeFermion> ShiftedLinOpDw(Dw,0.01);
|
||||||
|
|
||||||
|
Aggregates.CreateSubspaceGCR(RNG4,
|
||||||
|
LinOpDw,
|
||||||
|
nbasis);
|
||||||
|
|
||||||
|
typedef Aggregation<vSpinColourVector,vTComplex,2*nbasis> CombinedSubspace;
|
||||||
|
CombinedSubspace CombinedUV(Coarse4d,UGrid,cb);
|
||||||
|
for(int b=0;b<nbasis;b++){
|
||||||
|
Gamma G5(Gamma::Algebra::Gamma5);
|
||||||
|
CombinedUV.subspace[b] = Aggregates.subspace[b];
|
||||||
|
CombinedUV.subspace[b+nbasis] = G5*Aggregates.subspace[b];
|
||||||
|
}
|
||||||
|
|
||||||
|
LittleDiracOperator LittleDiracOp(geom,FGrid,Coarse4d);
|
||||||
|
LittleDiracOp.CoarsenOperator(LinOpDw,CombinedUV);
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"*******************************************"<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"Testing coarsened operator "<<std::endl;
|
||||||
|
|
||||||
|
CoarseVector c_src (Coarse4d);
|
||||||
|
CoarseVector c_res (Coarse4d);
|
||||||
|
CoarseVector c_proj(Coarse4d);
|
||||||
|
|
||||||
|
std::vector<LatticeFermion> subspace(2*nbasis,FGrid);
|
||||||
|
subspace=CombinedUV.subspace;
|
||||||
|
|
||||||
|
c_src = one; // 1 in every element for vector 1.
|
||||||
|
blockPromote(c_src,err,subspace);
|
||||||
|
|
||||||
|
prom=Zero();
|
||||||
|
for(int b=0;b<2*nbasis;b++){
|
||||||
|
prom=prom+subspace[b];
|
||||||
|
}
|
||||||
|
err=err-prom;
|
||||||
|
std::cout<<GridLogMessage<<"Promoted back from subspace: err "<<norm2(err)<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"c_src "<<norm2(c_src)<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"prom "<<norm2(prom)<<std::endl;
|
||||||
|
|
||||||
|
LinOpDw.Op(prom,tmp);
|
||||||
|
blockProject(c_proj,tmp,subspace);
|
||||||
|
std::cout<<GridLogMessage<<" Called Big Dirac Op "<<norm2(tmp)<<std::endl;
|
||||||
|
|
||||||
|
LittleDiracOp.M(c_src,c_res);
|
||||||
|
std::cout<<GridLogMessage<<" Called Little Dirac Op c_src "<< norm2(c_src) << " c_res "<< norm2(c_res) <<std::endl;
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<"Little dop : "<<norm2(c_res)<<std::endl;
|
||||||
|
// std::cout<<GridLogMessage<<" Little "<< c_res<<std::endl;
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<"Big dop in subspace : "<<norm2(c_proj)<<std::endl;
|
||||||
|
// std::cout<<GridLogMessage<<" Big "<< c_proj<<std::endl;
|
||||||
|
c_proj = c_proj - c_res;
|
||||||
|
std::cout<<GridLogMessage<<" ldop error: "<<norm2(c_proj)<<std::endl;
|
||||||
|
// std::cout<<GridLogMessage<<" error "<< c_proj<<std::endl;
|
||||||
|
|
||||||
|
|
||||||
|
/**********
|
||||||
|
* Some solvers
|
||||||
|
**********
|
||||||
|
*/
|
||||||
|
|
||||||
|
// CG
|
||||||
|
{
|
||||||
|
MdagMLinearOperator<WilsonFermionD,LatticeFermion> HermOp(Dw);
|
||||||
|
ConjugateGradient<LatticeFermion> CG(1.0e-8,10000);
|
||||||
|
Dw.Mdag(src,precsrc);
|
||||||
|
CG(HermOp,precsrc,result);
|
||||||
|
result=Zero();
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////
|
||||||
|
// Coarse grid solver test
|
||||||
|
///////////////////////////////////////
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<"******************* "<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<" Coarse Grid Solve -- Level 3 "<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"******************* "<<std::endl;
|
||||||
|
TrivialPrecon<CoarseVector> simple;
|
||||||
|
NonHermitianLinearOperator<LittleDiracOperator,CoarseVector> LinOpCoarse(LittleDiracOp);
|
||||||
|
ShiftedNonHermitianLinearOperator<LittleDiracOperator,CoarseVector> ShiftedLinOpCoarse(LittleDiracOp,0.001);
|
||||||
|
// ShiftedNonHermitianLinearOperator<LittleDiracOperator,CoarseVector> ShiftedLinOpCoarse(LittleDiracOp,0.01);
|
||||||
|
// ShiftedNonHermitianLinearOperator<LittleDiracOperator,CoarseVector> ShiftedLinOpCoarse(LinOpCoarse,0.001);
|
||||||
|
// PrecGeneralisedConjugateResidualNonHermitian<CoarseVector> L2PGCR(1.0e-4, 100, LinOpCoarse,simple,10,10);
|
||||||
|
// PrecGeneralisedConjugateResidualNonHermitian<CoarseVector> L2PGCR(1.0e-1, 100, LinOpCoarse,simple,30,30);
|
||||||
|
PrecGeneralisedConjugateResidualNonHermitian<CoarseVector> L2PGCR(2.0e-1, 50, ShiftedLinOpCoarse,simple,50,50);
|
||||||
|
L2PGCR.Level(3);
|
||||||
|
c_res=Zero();
|
||||||
|
L2PGCR(c_src,c_res);
|
||||||
|
|
||||||
|
////////////////////////////////////////
|
||||||
|
// Fine grid smoother
|
||||||
|
////////////////////////////////////////
|
||||||
|
std::cout<<GridLogMessage<<"******************* "<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<" Fine Grid Smoother -- Level 2 "<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"******************* "<<std::endl;
|
||||||
|
TrivialPrecon<LatticeFermionD> simple_fine;
|
||||||
|
|
||||||
|
PrecGeneralisedConjugateResidualNonHermitian<LatticeFermionD> SmootherGCR(0.1,1,ShiftedLinOpDw,simple_fine,4,4);
|
||||||
|
SmootherGCR.Level(2);
|
||||||
|
|
||||||
|
LatticeFermionD f_src(FGrid);
|
||||||
|
LatticeFermionD f_res(FGrid);
|
||||||
|
|
||||||
|
f_src = one; // 1 in every element for vector 1.
|
||||||
|
f_res=Zero();
|
||||||
|
SmootherGCR(f_src,f_res);
|
||||||
|
|
||||||
|
typedef MGPreconditioner<vSpinColourVector, vTComplex,2*nbasis> TwoLevelMG;
|
||||||
|
|
||||||
|
TwoLevelMG TwoLevelPrecon(CombinedUV,
|
||||||
|
LinOpDw,
|
||||||
|
simple_fine,
|
||||||
|
SmootherGCR,
|
||||||
|
LinOpCoarse,
|
||||||
|
L2PGCR);
|
||||||
|
|
||||||
|
PrecGeneralisedConjugateResidualNonHermitian<LatticeFermion> L1PGCR(1.0e-8,1000,LinOpDw,TwoLevelPrecon,16,16);
|
||||||
|
L1PGCR.Level(1);
|
||||||
|
|
||||||
|
f_res=Zero();
|
||||||
|
L1PGCR(f_src,f_res);
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"*******************************************"<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<std::endl;
|
||||||
|
std::cout<<GridLogMessage << "Done "<< std::endl;
|
||||||
|
|
||||||
|
Grid_finalize();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
326
tests/debug/Test_general_coarse_wilson_nog5.cc
Normal file
326
tests/debug/Test_general_coarse_wilson_nog5.cc
Normal file
@@ -0,0 +1,326 @@
|
|||||||
|
/*************************************************************************************
|
||||||
|
|
||||||
|
Grid physics library, www.github.com/paboyle/Grid
|
||||||
|
|
||||||
|
Source file: ./tests/Test_padded_cell.cc
|
||||||
|
|
||||||
|
Copyright (C) 2023
|
||||||
|
|
||||||
|
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
|
See the full license in the file "LICENSE" in the top level distribution directory
|
||||||
|
*************************************************************************************/
|
||||||
|
/* END LEGAL */
|
||||||
|
#include <Grid/Grid.h>
|
||||||
|
#include <Grid/lattice/PaddedCell.h>
|
||||||
|
#include <Grid/stencil/GeneralLocalStencil.h>
|
||||||
|
|
||||||
|
#include <Grid/algorithms/iterative/PrecGeneralisedConjugateResidual.h>
|
||||||
|
#include <Grid/algorithms/iterative/PrecGeneralisedConjugateResidualNonHermitian.h>
|
||||||
|
#include <Grid/algorithms/iterative/BiCGSTAB.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace Grid;
|
||||||
|
|
||||||
|
template<class Fobj,class CComplex,int nbasis>
|
||||||
|
class MGPreconditioner : public LinearFunction< Lattice<Fobj> > {
|
||||||
|
public:
|
||||||
|
using LinearFunction<Lattice<Fobj> >::operator();
|
||||||
|
|
||||||
|
typedef Aggregation<Fobj,CComplex,nbasis> Aggregates;
|
||||||
|
typedef typename Aggregation<Fobj,CComplex,nbasis>::FineField FineField;
|
||||||
|
typedef typename Aggregation<Fobj,CComplex,nbasis>::CoarseVector CoarseVector;
|
||||||
|
typedef typename Aggregation<Fobj,CComplex,nbasis>::CoarseMatrix CoarseMatrix;
|
||||||
|
typedef LinearOperatorBase<FineField> FineOperator;
|
||||||
|
typedef LinearFunction <FineField> FineSmoother;
|
||||||
|
typedef LinearOperatorBase<CoarseVector> CoarseOperator;
|
||||||
|
typedef LinearFunction <CoarseVector> CoarseSolver;
|
||||||
|
Aggregates & _Aggregates;
|
||||||
|
FineOperator & _FineOperator;
|
||||||
|
FineSmoother & _PreSmoother;
|
||||||
|
FineSmoother & _PostSmoother;
|
||||||
|
CoarseOperator & _CoarseOperator;
|
||||||
|
CoarseSolver & _CoarseSolve;
|
||||||
|
|
||||||
|
int level; void Level(int lv) {level = lv; };
|
||||||
|
|
||||||
|
MGPreconditioner(Aggregates &Agg,
|
||||||
|
FineOperator &Fine,
|
||||||
|
FineSmoother &PreSmoother,
|
||||||
|
FineSmoother &PostSmoother,
|
||||||
|
CoarseOperator &CoarseOperator_,
|
||||||
|
CoarseSolver &CoarseSolve_)
|
||||||
|
: _Aggregates(Agg),
|
||||||
|
_FineOperator(Fine),
|
||||||
|
_PreSmoother(PreSmoother),
|
||||||
|
_PostSmoother(PostSmoother),
|
||||||
|
_CoarseOperator(CoarseOperator_),
|
||||||
|
_CoarseSolve(CoarseSolve_),
|
||||||
|
level(1) { }
|
||||||
|
|
||||||
|
virtual void operator()(const FineField &in, FineField & out)
|
||||||
|
{
|
||||||
|
GridBase *CoarseGrid = _Aggregates.CoarseGrid;
|
||||||
|
// auto CoarseGrid = _CoarseOperator.Grid();
|
||||||
|
CoarseVector Csrc(CoarseGrid);
|
||||||
|
CoarseVector Csol(CoarseGrid);
|
||||||
|
FineField vec1(in.Grid());
|
||||||
|
FineField vec2(in.Grid());
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage << "Calling PreSmoother " <<std::endl;
|
||||||
|
|
||||||
|
// std::cout<<GridLogMessage << "Calling PreSmoother input residual "<<norm2(in) <<std::endl;
|
||||||
|
double t;
|
||||||
|
// Fine Smoother
|
||||||
|
// out = in;
|
||||||
|
out = Zero();
|
||||||
|
t=-usecond();
|
||||||
|
_PreSmoother(in,out);
|
||||||
|
t+=usecond();
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage << "PreSmoother took "<< t/1000.0<< "ms" <<std::endl;
|
||||||
|
|
||||||
|
// Update the residual
|
||||||
|
_FineOperator.Op(out,vec1); sub(vec1, in ,vec1);
|
||||||
|
// std::cout<<GridLogMessage <<"Residual-1 now " <<norm2(vec1)<<std::endl;
|
||||||
|
|
||||||
|
// Fine to Coarse
|
||||||
|
t=-usecond();
|
||||||
|
_Aggregates.ProjectToSubspace (Csrc,vec1);
|
||||||
|
t+=usecond();
|
||||||
|
std::cout<<GridLogMessage << "Project to coarse took "<< t/1000.0<< "ms" <<std::endl;
|
||||||
|
|
||||||
|
// Coarse correction
|
||||||
|
t=-usecond();
|
||||||
|
Csol = Zero();
|
||||||
|
_CoarseSolve(Csrc,Csol);
|
||||||
|
//Csol=Zero();
|
||||||
|
t+=usecond();
|
||||||
|
std::cout<<GridLogMessage << "Coarse solve took "<< t/1000.0<< "ms" <<std::endl;
|
||||||
|
|
||||||
|
// Coarse to Fine
|
||||||
|
t=-usecond();
|
||||||
|
// _CoarseOperator.PromoteFromSubspace(_Aggregates,Csol,vec1);
|
||||||
|
_Aggregates.PromoteFromSubspace(Csol,vec1);
|
||||||
|
add(out,out,vec1);
|
||||||
|
t+=usecond();
|
||||||
|
std::cout<<GridLogMessage << "Promote to this level took "<< t/1000.0<< "ms" <<std::endl;
|
||||||
|
|
||||||
|
// Residual
|
||||||
|
_FineOperator.Op(out,vec1); sub(vec1 ,in , vec1);
|
||||||
|
// std::cout<<GridLogMessage <<"Residual-2 now " <<norm2(vec1)<<std::endl;
|
||||||
|
|
||||||
|
// Fine Smoother
|
||||||
|
t=-usecond();
|
||||||
|
// vec2=vec1;
|
||||||
|
vec2=Zero();
|
||||||
|
_PostSmoother(vec1,vec2);
|
||||||
|
t+=usecond();
|
||||||
|
std::cout<<GridLogMessage << "PostSmoother took "<< t/1000.0<< "ms" <<std::endl;
|
||||||
|
|
||||||
|
add( out,out,vec2);
|
||||||
|
std::cout<<GridLogMessage << "Done " <<std::endl;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main (int argc, char ** argv)
|
||||||
|
{
|
||||||
|
Grid_init(&argc,&argv);
|
||||||
|
|
||||||
|
const int Ls=16;
|
||||||
|
|
||||||
|
GridCartesian * UGrid = SpaceTimeGrid::makeFourDimGrid(GridDefaultLatt(), GridDefaultSimd(Nd,vComplex::Nsimd()),GridDefaultMpi());
|
||||||
|
GridRedBlackCartesian * UrbGrid = SpaceTimeGrid::makeFourDimRedBlackGrid(UGrid);
|
||||||
|
|
||||||
|
GridCartesian * FGrid = UGrid;
|
||||||
|
GridRedBlackCartesian * FrbGrid = UrbGrid;
|
||||||
|
|
||||||
|
// Construct a coarsened grid
|
||||||
|
Coordinate clatt = GridDefaultLatt();
|
||||||
|
for(int d=0;d<clatt.size();d++){
|
||||||
|
clatt[d] = clatt[d]/2;
|
||||||
|
// clatt[d] = clatt[d]/4;
|
||||||
|
}
|
||||||
|
GridCartesian *Coarse4d = SpaceTimeGrid::makeFourDimGrid(clatt, GridDefaultSimd(Nd,vComplex::Nsimd()),GridDefaultMpi());;
|
||||||
|
|
||||||
|
std::vector<int> seeds4({1,2,3,4});
|
||||||
|
std::vector<int> cseeds({5,6,7,8});
|
||||||
|
GridParallelRNG RNG4(UGrid); RNG4.SeedFixedIntegers(seeds4);
|
||||||
|
GridParallelRNG CRNG(Coarse4d);CRNG.SeedFixedIntegers(cseeds);
|
||||||
|
|
||||||
|
Complex one(1.0);
|
||||||
|
|
||||||
|
LatticeFermion src(FGrid); src=one;
|
||||||
|
LatticeFermion result(FGrid); result=Zero();
|
||||||
|
LatticeFermion ref(FGrid); ref=Zero();
|
||||||
|
LatticeFermion tmp(FGrid);
|
||||||
|
LatticeFermion err(FGrid);
|
||||||
|
LatticeFermion precsrc(FGrid);
|
||||||
|
LatticeGaugeField Umu(UGrid);
|
||||||
|
|
||||||
|
FieldMetaData header;
|
||||||
|
std::string file("ckpoint_lat");
|
||||||
|
NerscIO::readConfiguration(Umu,header,file);
|
||||||
|
|
||||||
|
RealD csw =0.0;
|
||||||
|
RealD mass=-0.92;
|
||||||
|
|
||||||
|
WilsonCloverFermionD Dw(Umu,*UGrid,*UrbGrid,mass,csw,csw);
|
||||||
|
|
||||||
|
const int nbasis = 40;
|
||||||
|
const int cb = 0 ;
|
||||||
|
LatticeFermion prom(FGrid);
|
||||||
|
|
||||||
|
typedef GeneralCoarsenedMatrix<vSpinColourVector,vTComplex,nbasis> LittleDiracOperator;
|
||||||
|
typedef LittleDiracOperator::CoarseVector CoarseVector;
|
||||||
|
|
||||||
|
NearestStencilGeometry4D geom(Coarse4d);
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"*******************************************"<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<std::endl;
|
||||||
|
|
||||||
|
// Warning: This routine calls Linop.Op, not LinOpo.HermOp
|
||||||
|
typedef Aggregation<vSpinColourVector,vTComplex,nbasis> Subspace;
|
||||||
|
Subspace Aggregates(Coarse4d,FGrid,cb);
|
||||||
|
|
||||||
|
NonHermitianLinearOperator<WilsonCloverFermionD,LatticeFermion> LinOpDw(Dw);
|
||||||
|
ShiftedNonHermitianLinearOperator<WilsonCloverFermionD,LatticeFermion> ShiftedLinOpDw(Dw,0.01);
|
||||||
|
|
||||||
|
Aggregates.CreateSubspaceGCR(RNG4,
|
||||||
|
LinOpDw,
|
||||||
|
nbasis);
|
||||||
|
|
||||||
|
|
||||||
|
LittleDiracOperator LittleDiracOp(geom,FGrid,Coarse4d);
|
||||||
|
LittleDiracOp.CoarsenOperator(LinOpDw,Aggregates);
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"*******************************************"<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"Testing coarsened operator "<<std::endl;
|
||||||
|
|
||||||
|
CoarseVector c_src (Coarse4d);
|
||||||
|
CoarseVector c_res (Coarse4d);
|
||||||
|
CoarseVector c_proj(Coarse4d);
|
||||||
|
|
||||||
|
std::vector<LatticeFermion> subspace(nbasis,FGrid);
|
||||||
|
subspace=Aggregates.subspace;
|
||||||
|
|
||||||
|
c_src = one; // 1 in every element for vector 1.
|
||||||
|
blockPromote(c_src,err,subspace);
|
||||||
|
|
||||||
|
prom=Zero();
|
||||||
|
for(int b=0;b<nbasis;b++){
|
||||||
|
prom=prom+subspace[b];
|
||||||
|
}
|
||||||
|
err=err-prom;
|
||||||
|
std::cout<<GridLogMessage<<"Promoted back from subspace: err "<<norm2(err)<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"c_src "<<norm2(c_src)<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"prom "<<norm2(prom)<<std::endl;
|
||||||
|
|
||||||
|
LinOpDw.Op(prom,tmp);
|
||||||
|
blockProject(c_proj,tmp,subspace);
|
||||||
|
std::cout<<GridLogMessage<<" Called Big Dirac Op "<<norm2(tmp)<<std::endl;
|
||||||
|
|
||||||
|
LittleDiracOp.M(c_src,c_res);
|
||||||
|
std::cout<<GridLogMessage<<" Called Little Dirac Op c_src "<< norm2(c_src) << " c_res "<< norm2(c_res) <<std::endl;
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<"Little dop : "<<norm2(c_res)<<std::endl;
|
||||||
|
// std::cout<<GridLogMessage<<" Little "<< c_res<<std::endl;
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<"Big dop in subspace : "<<norm2(c_proj)<<std::endl;
|
||||||
|
// std::cout<<GridLogMessage<<" Big "<< c_proj<<std::endl;
|
||||||
|
c_proj = c_proj - c_res;
|
||||||
|
std::cout<<GridLogMessage<<" ldop error: "<<norm2(c_proj)<<std::endl;
|
||||||
|
// std::cout<<GridLogMessage<<" error "<< c_proj<<std::endl;
|
||||||
|
|
||||||
|
|
||||||
|
/**********
|
||||||
|
* Some solvers
|
||||||
|
**********
|
||||||
|
*/
|
||||||
|
|
||||||
|
// CG
|
||||||
|
{
|
||||||
|
MdagMLinearOperator<WilsonFermionD,LatticeFermion> HermOp(Dw);
|
||||||
|
ConjugateGradient<LatticeFermion> CG(1.0e-8,10000);
|
||||||
|
Dw.Mdag(src,precsrc);
|
||||||
|
CG(HermOp,precsrc,result);
|
||||||
|
result=Zero();
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////
|
||||||
|
// Coarse grid solver test
|
||||||
|
///////////////////////////////////////
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<"******************* "<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<" Coarse Grid Solve -- Level 3 "<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"******************* "<<std::endl;
|
||||||
|
TrivialPrecon<CoarseVector> simple;
|
||||||
|
NonHermitianLinearOperator<LittleDiracOperator,CoarseVector> LinOpCoarse(LittleDiracOp);
|
||||||
|
ShiftedNonHermitianLinearOperator<LittleDiracOperator,CoarseVector> ShiftedLinOpCoarse(LittleDiracOp,0.001);
|
||||||
|
// ShiftedNonHermitianLinearOperator<LittleDiracOperator,CoarseVector> ShiftedLinOpCoarse(LittleDiracOp,0.01);
|
||||||
|
// ShiftedNonHermitianLinearOperator<LittleDiracOperator,CoarseVector> ShiftedLinOpCoarse(LinOpCoarse,0.001);
|
||||||
|
// PrecGeneralisedConjugateResidualNonHermitian<CoarseVector> L2PGCR(1.0e-4, 100, LinOpCoarse,simple,10,10);
|
||||||
|
PrecGeneralisedConjugateResidualNonHermitian<CoarseVector> L2PGCR(1.0e-1, 100, LinOpCoarse,simple,30,30);
|
||||||
|
// PrecGeneralisedConjugateResidualNonHermitian<CoarseVector> L2PGCR(2.0e-1, 50, ShiftedLinOpCoarse,simple,50,50);
|
||||||
|
L2PGCR.Level(3);
|
||||||
|
c_res=Zero();
|
||||||
|
L2PGCR(c_src,c_res);
|
||||||
|
|
||||||
|
////////////////////////////////////////
|
||||||
|
// Fine grid smoother
|
||||||
|
////////////////////////////////////////
|
||||||
|
std::cout<<GridLogMessage<<"******************* "<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<" Fine Grid Smoother -- Level 2 "<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"******************* "<<std::endl;
|
||||||
|
TrivialPrecon<LatticeFermionD> simple_fine;
|
||||||
|
|
||||||
|
PrecGeneralisedConjugateResidualNonHermitian<LatticeFermionD> SmootherGCR(0.1,1,ShiftedLinOpDw,simple_fine,6,6);
|
||||||
|
SmootherGCR.Level(2);
|
||||||
|
|
||||||
|
LatticeFermionD f_src(FGrid);
|
||||||
|
LatticeFermionD f_res(FGrid);
|
||||||
|
|
||||||
|
f_src = one; // 1 in every element for vector 1.
|
||||||
|
f_res=Zero();
|
||||||
|
SmootherGCR(f_src,f_res);
|
||||||
|
|
||||||
|
typedef MGPreconditioner<vSpinColourVector, vTComplex,nbasis> TwoLevelMG;
|
||||||
|
|
||||||
|
TwoLevelMG TwoLevelPrecon(Aggregates,
|
||||||
|
LinOpDw,
|
||||||
|
simple_fine,
|
||||||
|
SmootherGCR,
|
||||||
|
LinOpCoarse,
|
||||||
|
L2PGCR);
|
||||||
|
|
||||||
|
PrecGeneralisedConjugateResidualNonHermitian<LatticeFermion> L1PGCR(1.0e-8,1000,LinOpDw,TwoLevelPrecon,16,16);
|
||||||
|
L1PGCR.Level(1);
|
||||||
|
|
||||||
|
f_res=Zero();
|
||||||
|
L1PGCR(f_src,f_res);
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"*******************************************"<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<std::endl;
|
||||||
|
std::cout<<GridLogMessage << "Done "<< std::endl;
|
||||||
|
|
||||||
|
Grid_finalize();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
320
tests/debug/Test_general_coarse_wilson_svd.cc
Normal file
320
tests/debug/Test_general_coarse_wilson_svd.cc
Normal file
@@ -0,0 +1,320 @@
|
|||||||
|
/*************************************************************************************
|
||||||
|
|
||||||
|
Grid physics library, www.github.com/paboyle/Grid
|
||||||
|
|
||||||
|
Source file: ./tests/Test_padded_cell.cc
|
||||||
|
|
||||||
|
Copyright (C) 2023
|
||||||
|
|
||||||
|
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
|
See the full license in the file "LICENSE" in the top level distribution directory
|
||||||
|
*************************************************************************************/
|
||||||
|
/* END LEGAL */
|
||||||
|
#include <Grid/Grid.h>
|
||||||
|
#include <Grid/lattice/PaddedCell.h>
|
||||||
|
#include <Grid/stencil/GeneralLocalStencil.h>
|
||||||
|
|
||||||
|
#include <Grid/algorithms/iterative/PrecGeneralisedConjugateResidual.h>
|
||||||
|
#include <Grid/algorithms/iterative/PrecGeneralisedConjugateResidualNonHermitian.h>
|
||||||
|
#include <Grid/algorithms/iterative/BiCGSTAB.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace Grid;
|
||||||
|
|
||||||
|
template<class Fobj,class CComplex,int nbasis>
|
||||||
|
class MGPreconditioner : public LinearFunction< Lattice<Fobj> > {
|
||||||
|
public:
|
||||||
|
using LinearFunction<Lattice<Fobj> >::operator();
|
||||||
|
|
||||||
|
typedef Aggregation<Fobj,CComplex,nbasis> Aggregates;
|
||||||
|
typedef typename Aggregation<Fobj,CComplex,nbasis>::FineField FineField;
|
||||||
|
typedef typename Aggregation<Fobj,CComplex,nbasis>::CoarseVector CoarseVector;
|
||||||
|
typedef typename Aggregation<Fobj,CComplex,nbasis>::CoarseMatrix CoarseMatrix;
|
||||||
|
typedef LinearOperatorBase<FineField> FineOperator;
|
||||||
|
typedef LinearFunction <FineField> FineSmoother;
|
||||||
|
typedef LinearOperatorBase<CoarseVector> CoarseOperator;
|
||||||
|
typedef LinearFunction <CoarseVector> CoarseSolver;
|
||||||
|
Aggregates & _Aggregates;
|
||||||
|
FineOperator & _FineOperator;
|
||||||
|
FineSmoother & _PreSmoother;
|
||||||
|
FineSmoother & _PostSmoother;
|
||||||
|
CoarseOperator & _CoarseOperator;
|
||||||
|
CoarseSolver & _CoarseSolve;
|
||||||
|
|
||||||
|
int level; void Level(int lv) {level = lv; };
|
||||||
|
|
||||||
|
MGPreconditioner(Aggregates &Agg,
|
||||||
|
FineOperator &Fine,
|
||||||
|
FineSmoother &PreSmoother,
|
||||||
|
FineSmoother &PostSmoother,
|
||||||
|
CoarseOperator &CoarseOperator_,
|
||||||
|
CoarseSolver &CoarseSolve_)
|
||||||
|
: _Aggregates(Agg),
|
||||||
|
_FineOperator(Fine),
|
||||||
|
_PreSmoother(PreSmoother),
|
||||||
|
_PostSmoother(PostSmoother),
|
||||||
|
_CoarseOperator(CoarseOperator_),
|
||||||
|
_CoarseSolve(CoarseSolve_),
|
||||||
|
level(1) { }
|
||||||
|
|
||||||
|
virtual void operator()(const FineField &in, FineField & out)
|
||||||
|
{
|
||||||
|
GridBase *CoarseGrid = _Aggregates.CoarseGrid;
|
||||||
|
// auto CoarseGrid = _CoarseOperator.Grid();
|
||||||
|
CoarseVector Csrc(CoarseGrid);
|
||||||
|
CoarseVector Csol(CoarseGrid);
|
||||||
|
FineField vec1(in.Grid());
|
||||||
|
FineField vec2(in.Grid());
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage << "Calling PreSmoother " <<std::endl;
|
||||||
|
|
||||||
|
// std::cout<<GridLogMessage << "Calling PreSmoother input residual "<<norm2(in) <<std::endl;
|
||||||
|
double t;
|
||||||
|
// Fine Smoother
|
||||||
|
// out = in;
|
||||||
|
out = Zero();
|
||||||
|
t=-usecond();
|
||||||
|
_PreSmoother(in,out);
|
||||||
|
t+=usecond();
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage << "PreSmoother took "<< t/1000.0<< "ms" <<std::endl;
|
||||||
|
|
||||||
|
// Update the residual
|
||||||
|
_FineOperator.Op(out,vec1); sub(vec1, in ,vec1);
|
||||||
|
// std::cout<<GridLogMessage <<"Residual-1 now " <<norm2(vec1)<<std::endl;
|
||||||
|
|
||||||
|
// Fine to Coarse
|
||||||
|
t=-usecond();
|
||||||
|
_Aggregates.ProjectToSubspace (Csrc,vec1);
|
||||||
|
t+=usecond();
|
||||||
|
std::cout<<GridLogMessage << "Project to coarse took "<< t/1000.0<< "ms" <<std::endl;
|
||||||
|
|
||||||
|
// Coarse correction
|
||||||
|
t=-usecond();
|
||||||
|
Csol = Zero();
|
||||||
|
_CoarseSolve(Csrc,Csol);
|
||||||
|
//Csol=Zero();
|
||||||
|
t+=usecond();
|
||||||
|
std::cout<<GridLogMessage << "Coarse solve took "<< t/1000.0<< "ms" <<std::endl;
|
||||||
|
|
||||||
|
// Coarse to Fine
|
||||||
|
t=-usecond();
|
||||||
|
// _CoarseOperator.PromoteFromSubspace(_Aggregates,Csol,vec1);
|
||||||
|
_Aggregates.PromoteFromSubspace(Csol,vec1);
|
||||||
|
add(out,out,vec1);
|
||||||
|
t+=usecond();
|
||||||
|
std::cout<<GridLogMessage << "Promote to this level took "<< t/1000.0<< "ms" <<std::endl;
|
||||||
|
|
||||||
|
// Residual
|
||||||
|
_FineOperator.Op(out,vec1); sub(vec1 ,in , vec1);
|
||||||
|
// std::cout<<GridLogMessage <<"Residual-2 now " <<norm2(vec1)<<std::endl;
|
||||||
|
|
||||||
|
// Fine Smoother
|
||||||
|
t=-usecond();
|
||||||
|
// vec2=vec1;
|
||||||
|
vec2=Zero();
|
||||||
|
_PostSmoother(vec1,vec2);
|
||||||
|
t+=usecond();
|
||||||
|
std::cout<<GridLogMessage << "PostSmoother took "<< t/1000.0<< "ms" <<std::endl;
|
||||||
|
|
||||||
|
add( out,out,vec2);
|
||||||
|
std::cout<<GridLogMessage << "Done " <<std::endl;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main (int argc, char ** argv)
|
||||||
|
{
|
||||||
|
Grid_init(&argc,&argv);
|
||||||
|
|
||||||
|
const int Ls=16;
|
||||||
|
|
||||||
|
GridCartesian * UGrid = SpaceTimeGrid::makeFourDimGrid(GridDefaultLatt(), GridDefaultSimd(Nd,vComplex::Nsimd()),GridDefaultMpi());
|
||||||
|
GridRedBlackCartesian * UrbGrid = SpaceTimeGrid::makeFourDimRedBlackGrid(UGrid);
|
||||||
|
|
||||||
|
GridCartesian * FGrid = UGrid;
|
||||||
|
GridRedBlackCartesian * FrbGrid = UrbGrid;
|
||||||
|
|
||||||
|
// Construct a coarsened grid
|
||||||
|
Coordinate clatt = GridDefaultLatt();
|
||||||
|
for(int d=0;d<clatt.size();d++){
|
||||||
|
clatt[d] = clatt[d]/2;
|
||||||
|
// clatt[d] = clatt[d]/4;
|
||||||
|
}
|
||||||
|
GridCartesian *Coarse4d = SpaceTimeGrid::makeFourDimGrid(clatt, GridDefaultSimd(Nd,vComplex::Nsimd()),GridDefaultMpi());;
|
||||||
|
|
||||||
|
std::vector<int> seeds4({1,2,3,4});
|
||||||
|
std::vector<int> cseeds({5,6,7,8});
|
||||||
|
GridParallelRNG RNG4(UGrid); RNG4.SeedFixedIntegers(seeds4);
|
||||||
|
GridParallelRNG CRNG(Coarse4d);CRNG.SeedFixedIntegers(cseeds);
|
||||||
|
|
||||||
|
LatticeFermion src(FGrid); random(RNG4,src);
|
||||||
|
LatticeFermion result(FGrid); result=Zero();
|
||||||
|
LatticeFermion ref(FGrid); ref=Zero();
|
||||||
|
LatticeFermion tmp(FGrid);
|
||||||
|
LatticeFermion err(FGrid);
|
||||||
|
LatticeGaugeField Umu(UGrid);
|
||||||
|
|
||||||
|
FieldMetaData header;
|
||||||
|
std::string file("ckpoint_lat");
|
||||||
|
NerscIO::readConfiguration(Umu,header,file);
|
||||||
|
|
||||||
|
RealD csw =0.0;
|
||||||
|
RealD mass=-0.92;
|
||||||
|
|
||||||
|
WilsonCloverFermionD Dw(Umu,*UGrid,*UrbGrid,mass,csw,csw);
|
||||||
|
|
||||||
|
const int nbasis = 20;
|
||||||
|
const int cb = 0 ;
|
||||||
|
LatticeFermion prom(FGrid);
|
||||||
|
|
||||||
|
typedef GeneralCoarsenedMatrix<vSpinColourVector,vTComplex,2*nbasis> LittleDiracOperator;
|
||||||
|
typedef LittleDiracOperator::CoarseVector CoarseVector;
|
||||||
|
|
||||||
|
NearestStencilGeometry4D geom(Coarse4d);
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"*******************************************"<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<std::endl;
|
||||||
|
|
||||||
|
// Warning: This routine calls Linop.Op, not LinOpo.HermOp
|
||||||
|
typedef Aggregation<vSpinColourVector,vTComplex,nbasis> Subspace;
|
||||||
|
Subspace Aggregates(Coarse4d,FGrid,cb);
|
||||||
|
|
||||||
|
MdagMLinearOperator<WilsonCloverFermionD,LatticeFermion> MdagMOpDw(Dw);
|
||||||
|
NonHermitianLinearOperator<WilsonCloverFermionD,LatticeFermion> LinOpDw(Dw);
|
||||||
|
ShiftedNonHermitianLinearOperator<WilsonCloverFermionD,LatticeFermion> ShiftedLinOpDw(Dw,0.5);
|
||||||
|
|
||||||
|
// Aggregates.CreateSubspaceGCR(RNG4,
|
||||||
|
// LinOpDw,
|
||||||
|
// nbasis);
|
||||||
|
Aggregates.CreateSubspace(RNG4,MdagMOpDw,nbasis);
|
||||||
|
|
||||||
|
typedef Aggregation<vSpinColourVector,vTComplex,2*nbasis> CombinedSubspace;
|
||||||
|
CombinedSubspace CombinedUV(Coarse4d,UGrid,cb);
|
||||||
|
for(int b=0;b<nbasis;b++){
|
||||||
|
Gamma G5(Gamma::Algebra::Gamma5);
|
||||||
|
CombinedUV.subspace[b] = Aggregates.subspace[b];
|
||||||
|
CombinedUV.subspace[b+nbasis] = G5*Aggregates.subspace[b];
|
||||||
|
}
|
||||||
|
|
||||||
|
LittleDiracOperator LittleDiracOp(geom,FGrid,Coarse4d);
|
||||||
|
LittleDiracOp.CoarsenOperator(LinOpDw,CombinedUV);
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"*******************************************"<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"Testing coarsened operator "<<std::endl;
|
||||||
|
|
||||||
|
CoarseVector c_src (Coarse4d);
|
||||||
|
CoarseVector c_res (Coarse4d);
|
||||||
|
CoarseVector c_proj(Coarse4d);
|
||||||
|
|
||||||
|
std::vector<LatticeFermion> subspace(2*nbasis,FGrid);
|
||||||
|
subspace=CombinedUV.subspace;
|
||||||
|
|
||||||
|
Complex one(1.0);
|
||||||
|
c_src = one; // 1 in every element for vector 1.
|
||||||
|
blockPromote(c_src,err,subspace);
|
||||||
|
|
||||||
|
prom=Zero();
|
||||||
|
for(int b=0;b<2*nbasis;b++){
|
||||||
|
prom=prom+subspace[b];
|
||||||
|
}
|
||||||
|
err=err-prom;
|
||||||
|
std::cout<<GridLogMessage<<"Promoted back from subspace: err "<<norm2(err)<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"c_src "<<norm2(c_src)<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"prom "<<norm2(prom)<<std::endl;
|
||||||
|
|
||||||
|
LinOpDw.Op(prom,tmp);
|
||||||
|
blockProject(c_proj,tmp,subspace);
|
||||||
|
std::cout<<GridLogMessage<<" Called Big Dirac Op "<<norm2(tmp)<<std::endl;
|
||||||
|
|
||||||
|
LittleDiracOp.M(c_src,c_res);
|
||||||
|
std::cout<<GridLogMessage<<" Called Little Dirac Op c_src "<< norm2(c_src) << " c_res "<< norm2(c_res) <<std::endl;
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<"Little dop : "<<norm2(c_res)<<std::endl;
|
||||||
|
// std::cout<<GridLogMessage<<" Little "<< c_res<<std::endl;
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<"Big dop in subspace : "<<norm2(c_proj)<<std::endl;
|
||||||
|
// std::cout<<GridLogMessage<<" Big "<< c_proj<<std::endl;
|
||||||
|
c_proj = c_proj - c_res;
|
||||||
|
std::cout<<GridLogMessage<<" ldop error: "<<norm2(c_proj)<<std::endl;
|
||||||
|
// std::cout<<GridLogMessage<<" error "<< c_proj<<std::endl;
|
||||||
|
|
||||||
|
|
||||||
|
/**********
|
||||||
|
* Some solvers
|
||||||
|
**********
|
||||||
|
*/
|
||||||
|
|
||||||
|
///////////////////////////////////////
|
||||||
|
// Coarse grid solver test
|
||||||
|
///////////////////////////////////////
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<"******************* "<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<" Coarse Grid Solve -- Level 3 "<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"******************* "<<std::endl;
|
||||||
|
TrivialPrecon<CoarseVector> simple;
|
||||||
|
NonHermitianLinearOperator<LittleDiracOperator,CoarseVector> LinOpCoarse(LittleDiracOp);
|
||||||
|
// PrecGeneralisedConjugateResidualNonHermitian<CoarseVector> L2PGCR(1.0e-4, 100, LinOpCoarse,simple,10,10);
|
||||||
|
PrecGeneralisedConjugateResidualNonHermitian<CoarseVector> L2PGCR(1.0e-2, 100, LinOpCoarse,simple,30,30);
|
||||||
|
L2PGCR.Level(3);
|
||||||
|
c_res=Zero();
|
||||||
|
L2PGCR(c_src,c_res);
|
||||||
|
|
||||||
|
////////////////////////////////////////
|
||||||
|
// Fine grid smoother
|
||||||
|
////////////////////////////////////////
|
||||||
|
std::cout<<GridLogMessage<<"******************* "<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<" Fine Grid Smoother -- Level 2 "<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"******************* "<<std::endl;
|
||||||
|
TrivialPrecon<LatticeFermionD> simple_fine;
|
||||||
|
|
||||||
|
PrecGeneralisedConjugateResidualNonHermitian<LatticeFermionD> SmootherGCR(0.01,1,ShiftedLinOpDw,simple_fine,4,4);
|
||||||
|
SmootherGCR.Level(2);
|
||||||
|
|
||||||
|
LatticeFermionD f_src(FGrid);
|
||||||
|
LatticeFermionD f_res(FGrid);
|
||||||
|
|
||||||
|
f_src = one; // 1 in every element for vector 1.
|
||||||
|
f_res=Zero();
|
||||||
|
SmootherGCR(f_src,f_res);
|
||||||
|
|
||||||
|
typedef MGPreconditioner<vSpinColourVector, vTComplex,2*nbasis> TwoLevelMG;
|
||||||
|
|
||||||
|
TwoLevelMG TwoLevelPrecon(CombinedUV,
|
||||||
|
LinOpDw,
|
||||||
|
simple_fine,
|
||||||
|
SmootherGCR,
|
||||||
|
LinOpCoarse,
|
||||||
|
L2PGCR);
|
||||||
|
|
||||||
|
PrecGeneralisedConjugateResidualNonHermitian<LatticeFermion> L1PGCR(1.0e-8,1000,LinOpDw,TwoLevelPrecon,32,32);
|
||||||
|
L1PGCR.Level(1);
|
||||||
|
|
||||||
|
f_res=Zero();
|
||||||
|
L1PGCR(f_src,f_res);
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"*******************************************"<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<std::endl;
|
||||||
|
std::cout<<GridLogMessage << "Done "<< std::endl;
|
||||||
|
|
||||||
|
Grid_finalize();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
312
tests/debug/Test_general_coarse_wilson_svd_no5g.cc
Normal file
312
tests/debug/Test_general_coarse_wilson_svd_no5g.cc
Normal file
@@ -0,0 +1,312 @@
|
|||||||
|
/*************************************************************************************
|
||||||
|
|
||||||
|
Grid physics library, www.github.com/paboyle/Grid
|
||||||
|
|
||||||
|
Source file: ./tests/Test_padded_cell.cc
|
||||||
|
|
||||||
|
Copyright (C) 2023
|
||||||
|
|
||||||
|
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
|
See the full license in the file "LICENSE" in the top level distribution directory
|
||||||
|
*************************************************************************************/
|
||||||
|
/* END LEGAL */
|
||||||
|
#include <Grid/Grid.h>
|
||||||
|
#include <Grid/lattice/PaddedCell.h>
|
||||||
|
#include <Grid/stencil/GeneralLocalStencil.h>
|
||||||
|
|
||||||
|
#include <Grid/algorithms/iterative/PrecGeneralisedConjugateResidual.h>
|
||||||
|
#include <Grid/algorithms/iterative/PrecGeneralisedConjugateResidualNonHermitian.h>
|
||||||
|
#include <Grid/algorithms/iterative/BiCGSTAB.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace Grid;
|
||||||
|
|
||||||
|
template<class Fobj,class CComplex,int nbasis>
|
||||||
|
class MGPreconditioner : public LinearFunction< Lattice<Fobj> > {
|
||||||
|
public:
|
||||||
|
using LinearFunction<Lattice<Fobj> >::operator();
|
||||||
|
|
||||||
|
typedef Aggregation<Fobj,CComplex,nbasis> Aggregates;
|
||||||
|
typedef typename Aggregation<Fobj,CComplex,nbasis>::FineField FineField;
|
||||||
|
typedef typename Aggregation<Fobj,CComplex,nbasis>::CoarseVector CoarseVector;
|
||||||
|
typedef typename Aggregation<Fobj,CComplex,nbasis>::CoarseMatrix CoarseMatrix;
|
||||||
|
typedef LinearOperatorBase<FineField> FineOperator;
|
||||||
|
typedef LinearFunction <FineField> FineSmoother;
|
||||||
|
typedef LinearOperatorBase<CoarseVector> CoarseOperator;
|
||||||
|
typedef LinearFunction <CoarseVector> CoarseSolver;
|
||||||
|
Aggregates & _Aggregates;
|
||||||
|
FineOperator & _FineOperator;
|
||||||
|
FineSmoother & _PreSmoother;
|
||||||
|
FineSmoother & _PostSmoother;
|
||||||
|
CoarseOperator & _CoarseOperator;
|
||||||
|
CoarseSolver & _CoarseSolve;
|
||||||
|
|
||||||
|
int level; void Level(int lv) {level = lv; };
|
||||||
|
|
||||||
|
MGPreconditioner(Aggregates &Agg,
|
||||||
|
FineOperator &Fine,
|
||||||
|
FineSmoother &PreSmoother,
|
||||||
|
FineSmoother &PostSmoother,
|
||||||
|
CoarseOperator &CoarseOperator_,
|
||||||
|
CoarseSolver &CoarseSolve_)
|
||||||
|
: _Aggregates(Agg),
|
||||||
|
_FineOperator(Fine),
|
||||||
|
_PreSmoother(PreSmoother),
|
||||||
|
_PostSmoother(PostSmoother),
|
||||||
|
_CoarseOperator(CoarseOperator_),
|
||||||
|
_CoarseSolve(CoarseSolve_),
|
||||||
|
level(1) { }
|
||||||
|
|
||||||
|
virtual void operator()(const FineField &in, FineField & out)
|
||||||
|
{
|
||||||
|
GridBase *CoarseGrid = _Aggregates.CoarseGrid;
|
||||||
|
// auto CoarseGrid = _CoarseOperator.Grid();
|
||||||
|
CoarseVector Csrc(CoarseGrid);
|
||||||
|
CoarseVector Csol(CoarseGrid);
|
||||||
|
FineField vec1(in.Grid());
|
||||||
|
FineField vec2(in.Grid());
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage << "Calling PreSmoother " <<std::endl;
|
||||||
|
|
||||||
|
// std::cout<<GridLogMessage << "Calling PreSmoother input residual "<<norm2(in) <<std::endl;
|
||||||
|
double t;
|
||||||
|
// Fine Smoother
|
||||||
|
// out = in;
|
||||||
|
out = Zero();
|
||||||
|
t=-usecond();
|
||||||
|
_PreSmoother(in,out);
|
||||||
|
t+=usecond();
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage << "PreSmoother took "<< t/1000.0<< "ms" <<std::endl;
|
||||||
|
|
||||||
|
// Update the residual
|
||||||
|
_FineOperator.Op(out,vec1); sub(vec1, in ,vec1);
|
||||||
|
// std::cout<<GridLogMessage <<"Residual-1 now " <<norm2(vec1)<<std::endl;
|
||||||
|
|
||||||
|
// Fine to Coarse
|
||||||
|
t=-usecond();
|
||||||
|
_Aggregates.ProjectToSubspace (Csrc,vec1);
|
||||||
|
t+=usecond();
|
||||||
|
std::cout<<GridLogMessage << "Project to coarse took "<< t/1000.0<< "ms" <<std::endl;
|
||||||
|
|
||||||
|
// Coarse correction
|
||||||
|
t=-usecond();
|
||||||
|
Csol = Zero();
|
||||||
|
_CoarseSolve(Csrc,Csol);
|
||||||
|
//Csol=Zero();
|
||||||
|
t+=usecond();
|
||||||
|
std::cout<<GridLogMessage << "Coarse solve took "<< t/1000.0<< "ms" <<std::endl;
|
||||||
|
|
||||||
|
// Coarse to Fine
|
||||||
|
t=-usecond();
|
||||||
|
// _CoarseOperator.PromoteFromSubspace(_Aggregates,Csol,vec1);
|
||||||
|
_Aggregates.PromoteFromSubspace(Csol,vec1);
|
||||||
|
add(out,out,vec1);
|
||||||
|
t+=usecond();
|
||||||
|
std::cout<<GridLogMessage << "Promote to this level took "<< t/1000.0<< "ms" <<std::endl;
|
||||||
|
|
||||||
|
// Residual
|
||||||
|
_FineOperator.Op(out,vec1); sub(vec1 ,in , vec1);
|
||||||
|
// std::cout<<GridLogMessage <<"Residual-2 now " <<norm2(vec1)<<std::endl;
|
||||||
|
|
||||||
|
// Fine Smoother
|
||||||
|
t=-usecond();
|
||||||
|
// vec2=vec1;
|
||||||
|
vec2=Zero();
|
||||||
|
_PostSmoother(vec1,vec2);
|
||||||
|
t+=usecond();
|
||||||
|
std::cout<<GridLogMessage << "PostSmoother took "<< t/1000.0<< "ms" <<std::endl;
|
||||||
|
|
||||||
|
add( out,out,vec2);
|
||||||
|
std::cout<<GridLogMessage << "Done " <<std::endl;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main (int argc, char ** argv)
|
||||||
|
{
|
||||||
|
Grid_init(&argc,&argv);
|
||||||
|
|
||||||
|
const int Ls=16;
|
||||||
|
|
||||||
|
GridCartesian * UGrid = SpaceTimeGrid::makeFourDimGrid(GridDefaultLatt(), GridDefaultSimd(Nd,vComplex::Nsimd()),GridDefaultMpi());
|
||||||
|
GridRedBlackCartesian * UrbGrid = SpaceTimeGrid::makeFourDimRedBlackGrid(UGrid);
|
||||||
|
|
||||||
|
GridCartesian * FGrid = UGrid;
|
||||||
|
GridRedBlackCartesian * FrbGrid = UrbGrid;
|
||||||
|
|
||||||
|
// Construct a coarsened grid
|
||||||
|
Coordinate clatt = GridDefaultLatt();
|
||||||
|
for(int d=0;d<clatt.size();d++){
|
||||||
|
clatt[d] = clatt[d]/2;
|
||||||
|
// clatt[d] = clatt[d]/4;
|
||||||
|
}
|
||||||
|
GridCartesian *Coarse4d = SpaceTimeGrid::makeFourDimGrid(clatt, GridDefaultSimd(Nd,vComplex::Nsimd()),GridDefaultMpi());;
|
||||||
|
|
||||||
|
std::vector<int> seeds4({1,2,3,4});
|
||||||
|
std::vector<int> cseeds({5,6,7,8});
|
||||||
|
GridParallelRNG RNG4(UGrid); RNG4.SeedFixedIntegers(seeds4);
|
||||||
|
GridParallelRNG CRNG(Coarse4d);CRNG.SeedFixedIntegers(cseeds);
|
||||||
|
|
||||||
|
LatticeFermion src(FGrid); random(RNG4,src);
|
||||||
|
LatticeFermion result(FGrid); result=Zero();
|
||||||
|
LatticeFermion ref(FGrid); ref=Zero();
|
||||||
|
LatticeFermion tmp(FGrid);
|
||||||
|
LatticeFermion err(FGrid);
|
||||||
|
LatticeGaugeField Umu(UGrid);
|
||||||
|
|
||||||
|
FieldMetaData header;
|
||||||
|
std::string file("ckpoint_lat");
|
||||||
|
NerscIO::readConfiguration(Umu,header,file);
|
||||||
|
|
||||||
|
RealD csw =0.0;
|
||||||
|
RealD mass=-0.92;
|
||||||
|
|
||||||
|
WilsonCloverFermionD Dw(Umu,*UGrid,*UrbGrid,mass,csw,csw);
|
||||||
|
|
||||||
|
const int nbasis = 40;
|
||||||
|
const int cb = 0 ;
|
||||||
|
LatticeFermion prom(FGrid);
|
||||||
|
|
||||||
|
typedef GeneralCoarsenedMatrix<vSpinColourVector,vTComplex,nbasis> LittleDiracOperator;
|
||||||
|
typedef LittleDiracOperator::CoarseVector CoarseVector;
|
||||||
|
|
||||||
|
NearestStencilGeometry4D geom(Coarse4d);
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"*******************************************"<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<std::endl;
|
||||||
|
|
||||||
|
// Warning: This routine calls Linop.Op, not LinOpo.HermOp
|
||||||
|
typedef Aggregation<vSpinColourVector,vTComplex,nbasis> Subspace;
|
||||||
|
Subspace Aggregates(Coarse4d,FGrid,cb);
|
||||||
|
|
||||||
|
MdagMLinearOperator<WilsonCloverFermionD,LatticeFermion> MdagMOpDw(Dw);
|
||||||
|
NonHermitianLinearOperator<WilsonCloverFermionD,LatticeFermion> LinOpDw(Dw);
|
||||||
|
ShiftedNonHermitianLinearOperator<WilsonCloverFermionD,LatticeFermion> ShiftedLinOpDw(Dw,0.5);
|
||||||
|
|
||||||
|
// Aggregates.CreateSubspaceGCR(RNG4,
|
||||||
|
// LinOpDw,
|
||||||
|
// nbasis);
|
||||||
|
Aggregates.CreateSubspace(RNG4,MdagMOpDw,nbasis);
|
||||||
|
|
||||||
|
LittleDiracOperator LittleDiracOp(geom,FGrid,Coarse4d);
|
||||||
|
LittleDiracOp.CoarsenOperator(LinOpDw,Aggregates);
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"*******************************************"<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"Testing coarsened operator "<<std::endl;
|
||||||
|
|
||||||
|
CoarseVector c_src (Coarse4d);
|
||||||
|
CoarseVector c_res (Coarse4d);
|
||||||
|
CoarseVector c_proj(Coarse4d);
|
||||||
|
|
||||||
|
std::vector<LatticeFermion> subspace(nbasis,FGrid);
|
||||||
|
subspace=Aggregates.subspace;
|
||||||
|
|
||||||
|
Complex one(1.0);
|
||||||
|
c_src = one; // 1 in every element for vector 1.
|
||||||
|
blockPromote(c_src,err,subspace);
|
||||||
|
|
||||||
|
prom=Zero();
|
||||||
|
for(int b=0;b<nbasis;b++){
|
||||||
|
prom=prom+subspace[b];
|
||||||
|
}
|
||||||
|
err=err-prom;
|
||||||
|
std::cout<<GridLogMessage<<"Promoted back from subspace: err "<<norm2(err)<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"c_src "<<norm2(c_src)<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"prom "<<norm2(prom)<<std::endl;
|
||||||
|
|
||||||
|
LinOpDw.Op(prom,tmp);
|
||||||
|
blockProject(c_proj,tmp,subspace);
|
||||||
|
std::cout<<GridLogMessage<<" Called Big Dirac Op "<<norm2(tmp)<<std::endl;
|
||||||
|
|
||||||
|
LittleDiracOp.M(c_src,c_res);
|
||||||
|
std::cout<<GridLogMessage<<" Called Little Dirac Op c_src "<< norm2(c_src) << " c_res "<< norm2(c_res) <<std::endl;
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<"Little dop : "<<norm2(c_res)<<std::endl;
|
||||||
|
// std::cout<<GridLogMessage<<" Little "<< c_res<<std::endl;
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<"Big dop in subspace : "<<norm2(c_proj)<<std::endl;
|
||||||
|
// std::cout<<GridLogMessage<<" Big "<< c_proj<<std::endl;
|
||||||
|
c_proj = c_proj - c_res;
|
||||||
|
std::cout<<GridLogMessage<<" ldop error: "<<norm2(c_proj)<<std::endl;
|
||||||
|
// std::cout<<GridLogMessage<<" error "<< c_proj<<std::endl;
|
||||||
|
|
||||||
|
|
||||||
|
/**********
|
||||||
|
* Some solvers
|
||||||
|
**********
|
||||||
|
*/
|
||||||
|
|
||||||
|
///////////////////////////////////////
|
||||||
|
// Coarse grid solver test
|
||||||
|
///////////////////////////////////////
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<"******************* "<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<" Coarse Grid Solve -- Level 3 "<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"******************* "<<std::endl;
|
||||||
|
TrivialPrecon<CoarseVector> simple;
|
||||||
|
NonHermitianLinearOperator<LittleDiracOperator,CoarseVector> LinOpCoarse(LittleDiracOp);
|
||||||
|
// PrecGeneralisedConjugateResidualNonHermitian<CoarseVector> L2PGCR(1.0e-4, 100, LinOpCoarse,simple,10,10);
|
||||||
|
PrecGeneralisedConjugateResidualNonHermitian<CoarseVector> L2PGCR(1.0e-2, 100, LinOpCoarse,simple,30,30);
|
||||||
|
L2PGCR.Level(3);
|
||||||
|
c_res=Zero();
|
||||||
|
L2PGCR(c_src,c_res);
|
||||||
|
|
||||||
|
////////////////////////////////////////
|
||||||
|
// Fine grid smoother
|
||||||
|
////////////////////////////////////////
|
||||||
|
std::cout<<GridLogMessage<<"******************* "<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<" Fine Grid Smoother -- Level 2 "<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"******************* "<<std::endl;
|
||||||
|
TrivialPrecon<LatticeFermionD> simple_fine;
|
||||||
|
|
||||||
|
PrecGeneralisedConjugateResidualNonHermitian<LatticeFermionD> SmootherGCR(0.01,1,ShiftedLinOpDw,simple_fine,6,6);
|
||||||
|
SmootherGCR.Level(2);
|
||||||
|
|
||||||
|
LatticeFermionD f_src(FGrid);
|
||||||
|
LatticeFermionD f_res(FGrid);
|
||||||
|
|
||||||
|
f_src = one; // 1 in every element for vector 1.
|
||||||
|
f_res=Zero();
|
||||||
|
SmootherGCR(f_src,f_res);
|
||||||
|
|
||||||
|
typedef MGPreconditioner<vSpinColourVector, vTComplex,nbasis> TwoLevelMG;
|
||||||
|
|
||||||
|
TwoLevelMG TwoLevelPrecon(Aggregates,
|
||||||
|
LinOpDw,
|
||||||
|
simple_fine,
|
||||||
|
SmootherGCR,
|
||||||
|
LinOpCoarse,
|
||||||
|
L2PGCR);
|
||||||
|
|
||||||
|
PrecGeneralisedConjugateResidualNonHermitian<LatticeFermion> L1PGCR(1.0e-8,1000,LinOpDw,TwoLevelPrecon,32,32);
|
||||||
|
L1PGCR.Level(1);
|
||||||
|
|
||||||
|
f_res=Zero();
|
||||||
|
L1PGCR(f_src,f_res);
|
||||||
|
|
||||||
|
std::cout<<GridLogMessage<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<"*******************************************"<<std::endl;
|
||||||
|
std::cout<<GridLogMessage<<std::endl;
|
||||||
|
std::cout<<GridLogMessage << "Done "<< std::endl;
|
||||||
|
|
||||||
|
Grid_finalize();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -490,7 +490,7 @@ public:
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GRID_ASSERT(s==nshift);
|
assert(s==nshift);
|
||||||
coalescedWrite(gStaple_v[ss],stencil_ss);
|
coalescedWrite(gStaple_v[ss],stencil_ss);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ void ForceTest(Action<LatticeGaugeField> &action,ConfigurationBase<LatticeGaugeF
|
|||||||
|
|
||||||
Gimpl::generate_momenta(P,sRNG,RNG4);
|
Gimpl::generate_momenta(P,sRNG,RNG4);
|
||||||
// Filter.applyFilter(P);
|
// Filter.applyFilter(P);
|
||||||
|
std::cout << GridLogMessage << "Initial momenta " << norm2(P) << std::endl;
|
||||||
|
|
||||||
action.refresh(smU,sRNG,RNG4);
|
action.refresh(smU,sRNG,RNG4);
|
||||||
|
|
||||||
@@ -70,6 +71,8 @@ void ForceTest(Action<LatticeGaugeField> &action,ConfigurationBase<LatticeGaugeF
|
|||||||
std::cout << GridLogMessage << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<std::endl;
|
std::cout << GridLogMessage << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<std::endl;
|
||||||
|
|
||||||
RealD S1 = action.S(smU);
|
RealD S1 = action.S(smU);
|
||||||
|
std::cout << GridLogMessage << "Initial action " << S1 << std::endl;
|
||||||
|
|
||||||
|
|
||||||
Gimpl::update_field(P,U,eps);
|
Gimpl::update_field(P,U,eps);
|
||||||
smU.set_Field(U);
|
smU.set_Field(U);
|
||||||
@@ -80,6 +83,7 @@ void ForceTest(Action<LatticeGaugeField> &action,ConfigurationBase<LatticeGaugeF
|
|||||||
action.deriv(smU,UdSdU);
|
action.deriv(smU,UdSdU);
|
||||||
UdSdU = Ta(UdSdU);
|
UdSdU = Ta(UdSdU);
|
||||||
// Filter.applyFilter(UdSdU);
|
// Filter.applyFilter(UdSdU);
|
||||||
|
std::cout << GridLogMessage << "Derivative " << norm2(UdSdU) << std::endl;
|
||||||
|
|
||||||
DumpSliceNorm("Force",UdSdU,Nd-1);
|
DumpSliceNorm("Force",UdSdU,Nd-1);
|
||||||
|
|
||||||
@@ -91,6 +95,7 @@ void ForceTest(Action<LatticeGaugeField> &action,ConfigurationBase<LatticeGaugeF
|
|||||||
std::cout << GridLogMessage << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<std::endl;
|
std::cout << GridLogMessage << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<std::endl;
|
||||||
|
|
||||||
RealD S2 = action.S(smU);
|
RealD S2 = action.S(smU);
|
||||||
|
std::cout << GridLogMessage << "Final action " << S1 << std::endl;
|
||||||
|
|
||||||
// Use the derivative
|
// Use the derivative
|
||||||
LatticeComplex dS(UGrid); dS = Zero();
|
LatticeComplex dS(UGrid); dS = Zero();
|
||||||
@@ -145,6 +150,8 @@ int main (int argc, char ** argv)
|
|||||||
GridParallelRNG RNG4(UGrid); RNG4.SeedFixedIntegers(seeds);
|
GridParallelRNG RNG4(UGrid); RNG4.SeedFixedIntegers(seeds);
|
||||||
SU<Nc>::HotConfiguration(RNG4,U);
|
SU<Nc>::HotConfiguration(RNG4,U);
|
||||||
#endif
|
#endif
|
||||||
|
std::cout << GridLogMessage << "Initial plaquette: " << WilsonLoops<PeriodicGimplR>::avgPlaquette(U) << std::endl;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
WilsonGaugeActionR PlaqAction(6.0);
|
WilsonGaugeActionR PlaqAction(6.0);
|
||||||
|
|||||||
Reference in New Issue
Block a user