CHROMA
syssolver_linop_clover_mg_proto.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/fine_qdpxx/invfgmres_qdpxx.h"
18 
19 using namespace QDP;
20 
21 namespace Chroma
22 {
23  namespace LinOpSysSolverMGProtoCloverEnv
24  {
25 
26  //! Anonymous namespace
27  namespace
28  {
29  //! Name to be used
30  const std::string name("MG_PROTO_CLOVER_INVERTER");
31 
32  //! Local registration flag
33  bool registered = false;
34  }
35 
36 
37 
38  // Double precision
40  const std::string& path,
41  Handle< FermState< LatticeFermion, multi1d<LatticeColorMatrix>, multi1d<LatticeColorMatrix> > > state,
42 
44  {
45  return new LinOpSysSolverMGProtoClover(A,state,MGProtoSolverParams(xml_in, path));
46  }
47 
48  //! Register all the factories
49  bool registerAll()
50  {
51  bool success = true;
52  if (! registered)
53  {
54 
56  registered = true;
57  }
58  return success;
59  }
60  };
61 
62  // Save me typing, by exposing this file level from here
65 
66  // Constructor
67  LinOpSysSolverMGProtoClover::LinOpSysSolverMGProtoClover(Handle< LinearOperator<T> > A_,
68  Handle< FermState<T,Q,Q> > state_,
69  const MGProtoSolverParams& invParam_) : A(A_), state(state_), invParam(invParam_) {}
70 
71  // Destructor
73 
74  //! Return the subset on which the operator acts
75  const Subset&
77  {
78  return A->subset();
79  }
80 
83  {
84  QDPIO::cout << "Jolly Greetings from Multigridland" << std::endl;
85  StopWatch swatch;
86  StopWatch swatch2;
87 
88  swatch.reset();
89  swatch.start();
90 
91  // Let us see if we have a Multigrid setup lying around.
92  const std::string& subspaceId = invParam.SubspaceId;
93 
94  std::shared_ptr<MGProtoHelpers::MGPreconditioner> mg_pointer = MGProtoHelpers::getMGPreconditioner(subspaceId);
95  if ( ! mg_pointer ) {
96  QDPIO::cout << "MG Preconditioner not found in Named Obj. Creating" << std::endl;
97 
98  // Check on the links -- they are ferm state and may already have BC's applied? need to figure that out.
100 
101  // Now get the setup
102  mg_pointer = MGProtoHelpers::getMGPreconditioner(subspaceId);
103  }
104 
105  // Next step is to create a solver instance:
106  MG::FGMRESParams fine_solve_params;
107  fine_solve_params.MaxIter=invParam.OuterSolverMaxIters;
108  fine_solve_params.RsdTarget=toDouble(invParam.OuterSolverRsdTarget);
109  fine_solve_params.VerboseP =invParam.OuterSolverVerboseP;
110  fine_solve_params.NKrylov = invParam.OuterSolverNKrylov;
111 
112  shared_ptr<const MG::QDPWilsonCloverLinearOperator > M_ptr = (mg_pointer->mg_levels->fine_level).M;
113 
114  MG::FGMRESSolverQDPXX FGMRESOuter(*M_ptr, fine_solve_params, (mg_pointer->v_cycle).get());
115 
116  // Solve the system
117  swatch2.reset();
118  swatch2.start();
119  MG::LinearSolverResults res=FGMRESOuter(psi, chi, RELATIVE);
120  swatch2.stop();
121 
122  {
123  T tmp;
124  tmp = zero;
125  (*A)(tmp, psi, PLUS);
126  tmp -= chi;
127  Double n2 = norm2(tmp);
128  Double n2rel = n2 / norm2(chi);
129  QDPIO::cout << "MG_PROTO_CLOVER_INVERTER: iters = "<< res.n_count << " rel resid = " << sqrt(n2rel) << std::endl;
130  }
131  swatch.stop();
132  QDPIO::cout << "MG_PROTO_CLOVER_INVERTER_TIME: call_time = "<< swatch2.getTimeInSeconds() << " sec. total_time=" << swatch.getTimeInSeconds() << " sec." << std::endl;
133  }
134 };
135 
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)
shared_ptr< MGPreconditioner > getMGPreconditioner(const std::string &subspaceId)
void createMGPreconditioner(const MGProtoSolverParams &params, const multi1d< LatticeColorMatrix > &u)
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
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.
Holds return info from SystemSolver call.
Definition: syssolver.h:17
Factory for solving M*psi=chi where M is not hermitian or pos. def.