2015-05-18 07:47:05 +01:00
|
|
|
#ifndef GRID_SCHUR_RED_BLACK_H
|
|
|
|
#define GRID_SCHUR_RED_BLACK_H
|
|
|
|
|
2015-05-25 13:43:58 +01:00
|
|
|
|
2015-05-18 07:47:05 +01:00
|
|
|
/*
|
|
|
|
* Red black Schur decomposition
|
|
|
|
*
|
|
|
|
* M = (Mee Meo) = (1 0 ) (Mee 0 ) (1 Mee^{-1} Meo)
|
|
|
|
* (Moe Moo) (Moe Mee^-1 1 ) (0 Moo-Moe Mee^-1 Meo) (0 1 )
|
|
|
|
* = L D U
|
|
|
|
*
|
|
|
|
* L^-1 = (1 0 )
|
|
|
|
* (-MoeMee^{-1} 1 )
|
|
|
|
* L^{dag} = ( 1 Mee^{-dag} Moe^{dag} )
|
|
|
|
* ( 0 1 )
|
|
|
|
* L^{-d} = ( 1 -Mee^{-dag} Moe^{dag} )
|
|
|
|
* ( 0 1 )
|
|
|
|
*
|
|
|
|
* U^-1 = (1 -Mee^{-1} Meo)
|
|
|
|
* (0 1 )
|
|
|
|
* U^{dag} = ( 1 0)
|
|
|
|
* (Meo^dag Mee^{-dag} 1)
|
|
|
|
* U^{-dag} = ( 1 0)
|
|
|
|
* (-Meo^dag Mee^{-dag} 1)
|
|
|
|
***********************
|
|
|
|
* M psi = eta
|
|
|
|
***********************
|
|
|
|
*Odd
|
2015-05-25 13:43:58 +01:00
|
|
|
* i) (D_oo)^{\dag} D_oo psi_o = (D_oo)^dag L^{-1} eta_o
|
|
|
|
* eta_o' = (D_oo)^dag (eta_o - Moe Mee^{-1} eta_e)
|
2015-05-18 07:47:05 +01:00
|
|
|
*Even
|
|
|
|
* ii) Mee psi_e + Meo psi_o = src_e
|
|
|
|
*
|
|
|
|
* => sol_e = M_ee^-1 * ( src_e - Meo sol_o )...
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
namespace Grid {
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Take a matrix and form a Red Black solver calling a Herm solver
|
|
|
|
// Use of RB info prevents making SchurRedBlackSolve conform to standard interface
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
2015-06-05 10:17:10 +01:00
|
|
|
template<class Field> class SchurRedBlackDiagMooeeSolve {
|
2015-05-18 07:47:05 +01:00
|
|
|
private:
|
2015-06-05 10:17:10 +01:00
|
|
|
OperatorFunction<Field> & _HermitianRBSolver;
|
2015-05-18 07:47:05 +01:00
|
|
|
int CBfactorise;
|
|
|
|
public:
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////
|
|
|
|
// Wrap the usual normal equations Schur trick
|
|
|
|
/////////////////////////////////////////////////////
|
2015-06-05 10:17:10 +01:00
|
|
|
SchurRedBlackDiagMooeeSolve(OperatorFunction<Field> &HermitianRBSolver) :
|
2015-05-25 13:43:58 +01:00
|
|
|
_HermitianRBSolver(HermitianRBSolver)
|
|
|
|
{
|
2015-05-18 07:47:05 +01:00
|
|
|
CBfactorise=0;
|
|
|
|
};
|
|
|
|
|
2015-05-25 13:43:58 +01:00
|
|
|
template<class Matrix>
|
|
|
|
void operator() (Matrix & _Matrix,const Field &in, Field &out){
|
2015-05-18 07:47:05 +01:00
|
|
|
|
|
|
|
// FIXME CGdiagonalMee not implemented virtual function
|
|
|
|
// FIXME use CBfactorise to control schur decomp
|
2015-05-31 15:09:02 +01:00
|
|
|
GridBase *grid = _Matrix.RedBlackGrid();
|
|
|
|
GridBase *fgrid= _Matrix.Grid();
|
2015-06-05 10:17:10 +01:00
|
|
|
|
|
|
|
SchurDiagMooeeOperator<Matrix,Field> _HermOpEO(_Matrix);
|
2015-05-18 07:47:05 +01:00
|
|
|
|
2015-05-25 13:43:58 +01:00
|
|
|
Field src_e(grid);
|
|
|
|
Field src_o(grid);
|
|
|
|
Field sol_e(grid);
|
|
|
|
Field sol_o(grid);
|
|
|
|
Field tmp(grid);
|
|
|
|
Field Mtmp(grid);
|
|
|
|
Field resid(fgrid);
|
|
|
|
|
2015-05-18 07:47:05 +01:00
|
|
|
pickCheckerboard(Even,src_e,in);
|
|
|
|
pickCheckerboard(Odd ,src_o,in);
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////
|
|
|
|
// src_o = Mdag * (source_o - Moe MeeInv source_e)
|
|
|
|
/////////////////////////////////////////////////////
|
2015-05-25 13:43:58 +01:00
|
|
|
_Matrix.MooeeInv(src_e,tmp); assert( tmp.checkerboard ==Even);
|
|
|
|
_Matrix.Meooe (tmp,Mtmp); assert( Mtmp.checkerboard ==Odd);
|
|
|
|
tmp=src_o-Mtmp; assert( tmp.checkerboard ==Odd);
|
2015-06-05 10:17:10 +01:00
|
|
|
|
|
|
|
// get the right MpcDag
|
|
|
|
_HermOpEO.MpcDag(tmp,src_o); assert(src_o.checkerboard ==Odd);
|
2015-05-18 07:47:05 +01:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
// Call the red-black solver
|
|
|
|
//////////////////////////////////////////////////////////////
|
2015-05-25 13:43:58 +01:00
|
|
|
std::cout << "SchurRedBlack solver calling the MpcDagMp solver" <<std::endl;
|
|
|
|
_HermitianRBSolver(_HermOpEO,src_o,sol_o); assert(sol_o.checkerboard==Odd);
|
2015-05-18 07:47:05 +01:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////
|
|
|
|
// sol_e = M_ee^-1 * ( src_e - Meo sol_o )...
|
|
|
|
///////////////////////////////////////////////////
|
2015-05-25 13:43:58 +01:00
|
|
|
_Matrix.Meooe(sol_o,tmp); assert( tmp.checkerboard ==Even);
|
|
|
|
src_e = src_e-tmp; assert( src_e.checkerboard ==Even);
|
|
|
|
_Matrix.MooeeInv(src_e,sol_e); assert( sol_e.checkerboard ==Even);
|
2015-05-18 07:47:05 +01:00
|
|
|
|
2015-05-25 13:43:58 +01:00
|
|
|
setCheckerboard(out,sol_e); assert( sol_e.checkerboard ==Even);
|
|
|
|
setCheckerboard(out,sol_o); assert( sol_o.checkerboard ==Odd );
|
|
|
|
|
|
|
|
// Verify the unprec residual
|
|
|
|
_Matrix.M(out,resid);
|
|
|
|
resid = resid-in;
|
|
|
|
RealD ns = norm2(in);
|
|
|
|
RealD nr = norm2(resid);
|
|
|
|
|
2015-06-05 10:17:10 +01:00
|
|
|
std::cout << "SchurRedBlackDiagMooee solver true unprec resid "<< sqrt(nr/ns) <<" nr "<< nr <<" ns "<<ns << std::endl;
|
2015-05-18 07:47:05 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|