CHROMA
syssolver_linop_clover_mg_proto_qphix.cc
Go to the documentation of this file.
1 /*
2  * syssolver_linop_clover_mg_proto.cc
3  *
4  * Created on: Mar 23, 2017
5  * Author: bjoo
6  */
7 
8 #include "chromabase.h"
10 #include "handle.h"
11 #include "state.h"
14 
15 #include "lattice/solver.h"
16 #include "lattice/fgmres_common.h"
17 #include "lattice/qphix/invfgmres_qphix.h"
18 #include "lattice/qphix/qphix_qdp_utils.h"
19 #include "lattice/qphix/qphix_clover_linear_operator.h"
21 
22 #include <memory>
23 using namespace QDP;
24 
25 namespace Chroma
26 {
27  namespace LinOpSysSolverMGProtoQPhiXCloverEnv
28  {
29 
30  //! Anonymous namespace
31  namespace
32  {
33  //! Name to be used
34  const std::string name("MG_PROTO_QPHIX_CLOVER_INVERTER");
35 
36  //! Local registration flag
37  bool registered = false;
38  }
39 
40 
41 
42  // Double precision
44  const std::string& path,
45  Handle< FermState< LatticeFermion, multi1d<LatticeColorMatrix>, multi1d<LatticeColorMatrix> > > state,
46 
48  {
50  }
51 
52  //! Register all the factories
53  bool registerAll()
54  {
55  bool success = true;
56  if (! registered)
57  {
58 
60  registered = true;
61  }
62  return success;
63  }
64  };
65 
66  // Save me typing, by exposing this file level from here
69 
70  // Constructor
71  LinOpSysSolverMGProtoQPhiXClover::LinOpSysSolverMGProtoQPhiXClover(Handle< LinearOperator<T> > A_,
72  Handle< FermState<T,Q,Q> > state_,
73  const MGProtoSolverParams& invParam_) : A(A_), state(state_), invParam(invParam_) {}
74 
75  // Destructor
77 
78  //! Return the subset on which the operator acts
79  const Subset&
81  {
82  return A->subset();
83  }
84 
87  {
88  QDPIO::cout << "Jolly Greetings from Multigridland" << std::endl;
89  StopWatch swatch;
90  StopWatch swatch2;
91 
92  swatch.reset();
93  swatch.start();
94 
95  // Let us see if we have a Multigrid setup lying around.
96  const std::string& subspaceId = invParam.SubspaceId;
97 
98  std::shared_ptr<MGProtoHelpersQPhiX::MGPreconditioner> mg_pointer = MGProtoHelpersQPhiX::getMGPreconditioner(subspaceId);
99  if ( ! mg_pointer ) {
100  QDPIO::cout << "MG Preconditioner not found in Named Obj. Creating" << std::endl;
101 
102  // Check on the links -- they are ferm state and may already have BC's applied? need to figure that out.
104 
105  // Now get the setup
106  mg_pointer = MGProtoHelpersQPhiX::getMGPreconditioner(subspaceId);
107  }
108 
109  // Next step is to create a solver instance:
110  MG::FGMRESParams fine_solve_params;
111  fine_solve_params.MaxIter=invParam.OuterSolverMaxIters;
112  fine_solve_params.RsdTarget=toDouble(invParam.OuterSolverRsdTarget);
113  fine_solve_params.VerboseP =invParam.OuterSolverVerboseP;
114  fine_solve_params.NKrylov = invParam.OuterSolverNKrylov;
115 
116  std::shared_ptr<MG::QPhiXWilsonCloverLinearOperator > M_ptr = (mg_pointer->M);
117 
118  const LatticeInfo& info = M_ptr->GetInfo();
119  QPhiXSpinor qphix_in(info);
120  QPhiXSpinor qphix_out(info);
121 
122  MG::FGMRESSolverQPhiX FGMRESOuter(*M_ptr, fine_solve_params, (mg_pointer->v_cycle).get());
123 
124  // Solve the system
125  QDPSpinorToQPhiXSpinor(chi,qphix_in);
126  ZeroVec(qphix_out);
127 
128  swatch2.reset();
129  swatch2.start();
130  MG::LinearSolverResults res=FGMRESOuter(qphix_out,qphix_in, RELATIVE);
131  swatch2.stop();
132 
133  QPhiXSpinorToQDPSpinor(qphix_out,psi);
134 
135  {
136  T tmp;
137  tmp = zero;
138  (*A)(tmp, psi, PLUS);
139  tmp -= chi;
140  Double n2 = norm2(tmp);
141  Double n2rel = n2 / norm2(chi);
142  QDPIO::cout << "MG_PROTO_CLOVER_INVERTER: iters = "<< res.n_count << " rel resid = " << sqrt(n2rel) << std::endl;
143  if( toBool( sqrt(n2rel) > invParam.OuterSolverRsdTarget ) ) {
144  MGSolverException convergence_fail(invParam.CloverParams.Mass,
145  subspaceId,
146  res.n_count,
147  Real(sqrt(n2rel)),
149  throw convergence_fail;
150 
151  }
152  }
153  swatch.stop();
154  QDPIO::cout << "MG_PROTO_CLOVER_INVERTER_TIME: call_time = "<< swatch2.getTimeInSeconds() << " sec. total_time=" << swatch.getTimeInSeconds() << " sec." << std::endl;
155  }
156 };
157 
Primary include file for CHROMA library code.
Support class for fermion actions and linear operators.
Definition: state.h:94
Class for counted reference semantics.
Definition: handle.h:33
SystemSolverResults_t operator()(T &psi, const T &chi) const
Solve It!
const Subset & subset() const
Return the subset on which the operator acts.
static T & Instance()
Definition: singleton.h:432
Class for counted reference semantics.
static bool registered
Local registration flag.
const std::string name
Name to be used.
LinOpSystemSolver< LatticeFermion > * createFerm(XMLReader &xml_in, const std::string &path, Handle< FermState< LatticeFermion, multi1d< LatticeColorMatrix >, multi1d< LatticeColorMatrix > > > state, Handle< LinearOperator< LatticeFermion > > A)
void createMGPreconditioner(const MGProtoSolverParams &params, const multi1d< LatticeColorMatrix > &u)
shared_ptr< MGPreconditioner > getMGPreconditioner(const std::string &subspaceId)
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
LinOpSysSolverMGProtoClover::Q Q
LatticeFermion tmp
Definition: mespbg5p_w.cc:36
LinOpSysSolverMGProtoClover::T T
@ PLUS
Definition: chromabase.h:45
multi1d< LatticeFermion > chi(Ncb)
LatticeFermion psi
Definition: mespbg5p_w.cc:35
A(A, psi, r, Ncb, PLUS)
const WilsonTypeFermAct< multi1d< LatticeFermion > > Handle< const ConnectState > state
Definition: pbg5p_w.cc:28
static QOP_info_t info
Double zero
Definition: invbicg.cc:106
FloatingPoint< double > Double
Definition: gtest.h:7351
::std::string string
Definition: gtest.h:1979
Support class for fermion actions and linear operators.
Chroma::CloverFermActParams CloverParams
Holds return info from SystemSolver call.
Definition: syssolver.h:17
Factory for solving M*psi=chi where M is not hermitian or pos. def.
LatticeFermion T
Definition: t_clover.cc:11
multi1d< LatticeColorMatrix > Q
Definition: t_clover.cc:12