CHROMA
lopscl.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 
3 #ifndef __lopscl_h__
4 #define __lopscl_h__
5 
6 #include "handle.h"
7 #include "linearop.h"
8 
9 
10 namespace Chroma
11 {
12  //! Scaled Linear Operator
13  /*!
14  * \ingroup linop
15  *
16  * This routine is specific to Wilson fermions!
17  *
18  * This operator scales its input operator
19  */
20  template<typename T, class C>
21  class lopscl : public LinearOperator<T>
22  {
23  public:
24  //! Initialize pointer with existing pointer
25  /*! Requires that the pointer p is a return value of new */
26  lopscl(LinearOperator<T>* p, const C& scale_fact_) : A(p), scale_fact(scale_fact_) {}
27 
28  //! Copy pointer (one more owner)
29  lopscl(Handle< LinearOperator<T> > p, const C& scale_fact_) : A(p), scale_fact(scale_fact_) {}
30 
31  //! Destructor
32  ~lopscl() {}
33 
34  //! Subset comes from underlying operator
35  inline const Subset& subset() const {return A->subset();}
36 
37  //! Apply the operator onto a source std::vector
38  /*! For this operator, the sign is ignored */
39  inline void operator() (T& chi, const T& psi, enum PlusMinus isign) const
40  {
41  const Subset& sub = A->subset();
42  (*A)(chi, psi, isign);
43  chi[sub] *= scale_fact;
44  }
45 
46  private:
48  const C scale_fact;
49  };
50 
51  //! Scaled Linear Operator
52  /*!
53  * \ingroup linop
54  *
55  * This routine is specific to Wilson fermions!
56  *
57  * This operator scales its input operator
58  */
59  template<typename T, class C>
60  class approx_lopscl : public LinearOperator<T>
61  {
62  public:
63  //! Initialize pointer with existing pointer
64  /*! Requires that the pointer p is a return value of new */
65  approx_lopscl(LinearOperator<T>* p, const C& scale_fact_) : A(p), scale_fact(scale_fact_) {}
66 
67  //! Copy pointer (one more owner)
68  approx_lopscl(Handle< LinearOperator<T> > p, const C& scale_fact_) : A(p), scale_fact(scale_fact_) {}
69 
70  //! Destructor
72 
73  //! Subset comes from underlying operator
74  inline const Subset& subset() const {return A->subset();}
75 
76  //! Apply the operator onto a source std::vector
77  /*! For this operator, the sign is ignored */
78  inline void operator() (T& chi, const T& psi, enum PlusMinus isign) const
79  {
80  const Subset& sub = A->subset();
81  (*A)(chi, psi, isign);
82  chi[sub] *= scale_fact;
83  }
84 
85  //! Apply the operator onto a source std::vector
86  /*! For this operator, the sign is ignored */
87  inline void operator() (T& chi, const T& psi, enum PlusMinus isign, Real epsilon) const
88  {
89  const Subset& sub = A->subset();
90  (*A)(chi, psi, isign, epsilon);
91  chi[sub] *= scale_fact;
92  }
93 
94  private:
96  const C scale_fact;
97  };
98 
99 
100 
101  //! Partial specialization of scaled M operator over arrays
102  /*!
103  * \ingroup linop
104  *
105  * This routine is specific to Wilson fermions!
106  *
107  * Linear operator forming M^dag.M from an operator M
108  */
109  template<typename T, class C>
111  {
112  public:
113  //! Initialize pointer with existing pointer
114  /*! Requires that the pointer p is a return value of new */
115  lopsclArray(LinearOperatorArray<T>* p, const C& scale_fact_) : A(p), scale_fact(scale_fact_) {}
116 
117  //! Copy pointer (one more owner)
118  lopsclArray(Handle< LinearOperatorArray<T> > p, const C& scale_fact_) : A(p), scale_fact(scale_fact_) {}
119 
120  //! Destructor
122 
123  //! Length of array index
124  int size() const {return A->size();}
125 
126  //! Subset comes from underlying operator
127  inline const Subset& subset() const {return A->subset();}
128 
129  //! Apply the operator onto a source std::vector
130  /*! For this operator, the sign is ignored */
131  inline void operator() (multi1d<T>& chi, const multi1d<T>& psi, enum PlusMinus isign) const
132  {
133  const Subset& sub = A->subset();
134 
135  (*A)(chi, psi, isign);
136  for(int i = 0; i < size(); i++) {
137  chi[i][sub] *= scale_fact;
138  }
139 
140  }
141 
142  private:
144  const C scale_fact;
145  };
146 
147 
148 } // End Namespace Chroma
149 
150 
151 #endif
Class for counted reference semantics.
Definition: handle.h:33
Linear Operator to arrays.
Definition: linearop.h:61
Linear Operator.
Definition: linearop.h:27
Scaled Linear Operator.
Definition: lopscl.h:61
~approx_lopscl()
Destructor.
Definition: lopscl.h:71
const C scale_fact
Definition: lopscl.h:96
approx_lopscl(Handle< LinearOperator< T > > p, const C &scale_fact_)
Copy pointer (one more owner)
Definition: lopscl.h:68
void operator()(T &chi, const T &psi, enum PlusMinus isign) const
Apply the operator onto a source std::vector.
Definition: lopscl.h:78
const Subset & subset() const
Subset comes from underlying operator.
Definition: lopscl.h:74
Handle< LinearOperator< T > > A
Definition: lopscl.h:95
approx_lopscl(LinearOperator< T > *p, const C &scale_fact_)
Initialize pointer with existing pointer.
Definition: lopscl.h:65
Partial specialization of scaled M operator over arrays.
Definition: lopscl.h:111
void operator()(multi1d< T > &chi, const multi1d< T > &psi, enum PlusMinus isign) const
Apply the operator onto a source std::vector.
Definition: lopscl.h:131
lopsclArray(LinearOperatorArray< T > *p, const C &scale_fact_)
Initialize pointer with existing pointer.
Definition: lopscl.h:115
Handle< LinearOperatorArray< T > > A
Definition: lopscl.h:143
const C scale_fact
Definition: lopscl.h:144
lopsclArray(Handle< LinearOperatorArray< T > > p, const C &scale_fact_)
Copy pointer (one more owner)
Definition: lopscl.h:118
~lopsclArray()
Destructor.
Definition: lopscl.h:121
int size() const
Length of array index.
Definition: lopscl.h:124
const Subset & subset() const
Subset comes from underlying operator.
Definition: lopscl.h:127
Scaled Linear Operator.
Definition: lopscl.h:22
void operator()(T &chi, const T &psi, enum PlusMinus isign) const
Apply the operator onto a source std::vector.
Definition: lopscl.h:39
Handle< LinearOperator< T > > A
Definition: lopscl.h:47
const Subset & subset() const
Subset comes from underlying operator.
Definition: lopscl.h:35
const C scale_fact
Definition: lopscl.h:48
lopscl(LinearOperator< T > *p, const C &scale_fact_)
Initialize pointer with existing pointer.
Definition: lopscl.h:26
lopscl(Handle< LinearOperator< T > > p, const C &scale_fact_)
Copy pointer (one more owner)
Definition: lopscl.h:29
~lopscl()
Destructor.
Definition: lopscl.h:32
Class for counted reference semantics.
Linear Operators.
SpinMatrix C()
C = Gamma(10)
Definition: barspinmat_w.cc:29
int epsilon(int i, int j, int k)
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
LinOpSysSolverMGProtoClover::T T
int i
Definition: pbg5p_w.cc:55
multi1d< LatticeFermion > chi(Ncb)
LatticeFermion psi
Definition: mespbg5p_w.cc:35