CHROMA
linearop.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 
3 /*! @file
4  * @brief Linear Operators
5  */
6 
7 #ifndef __linearop_h__
8 #define __linearop_h__
9 
10 #include "chromabase.h"
11 #include "fermbc.h"
12 
13 using namespace QDP::Hints;
14 
15 namespace Chroma
16 {
17 
18  //-----------------------------------------------------------------------------------
19  //! Linear Operator
20  /*! @ingroup linop
21  *
22  * Supports creation and application for linear operators that
23  * hold things like Dirac operators, etc.
24  */
25  template<typename T>
27  {
28  public:
29  //! Virtual destructor to help with cleanup;
30  virtual ~LinearOperator() {}
31 
32  //! Apply the operator onto a source std::vector
33  virtual void operator() (T& chi, const T& psi, enum PlusMinus isign) const = 0;
34 
35  //! Apply the operator onto a source std::vector to some precision
36  virtual void operator() (T& chi, const T& psi, enum PlusMinus isign,
37  Real epsilon) const
38  {
39  (*this)(chi,psi,isign);
40  }
41 
42  //! Return the subset on which the operator acts
43  virtual const Subset& subset() const = 0;
44 
45 
46  //! Return the number of flops performed by operator()
47  //! Base linop returns 0 and this can be overridden
48  virtual unsigned long nFlops() const { return 0; }
49  };
50 
51 
52  //-----------------------------------------------------------------------------------
53  //! Linear Operator to arrays
54  /*! @ingroup linop
55  *
56  * Supports creation and application for linear operators that
57  * hold things like Dirac operators, etc.
58  */
59  template<typename T>
61  {
62  public:
63  //! Virtual destructor to help with cleanup;
64  virtual ~LinearOperatorArray() {}
65 
66  //! Expected length of array index
67  virtual int size() const = 0;
68 
69  //! Apply the operator onto a source std::vector
70  virtual void operator() (multi1d<T>& chi, const multi1d<T>& psi,
71  enum PlusMinus isign) const = 0;
72 
73  //! Apply the operator onto a source std::vector to some precision
74  virtual void operator() (multi1d<T>& chi, const multi1d<T>& psi,
75  enum PlusMinus isign, Real epsilon) const
76  {
77  (*this)(chi,psi,isign);
78  }
79 
80  //! Return the subset on which the operator acts
81  virtual const Subset& subset() const = 0;
82 
83  //! Return the number of flops performed by operator()
84  //! Base linop returns 0 and this can be overridden
85  virtual unsigned long nFlops() const { return 0; };
86  };
87 
88 
89  //-----------------------------------------------------------------------------------
90  //! Differentiable Linear Operator
91  /*! @ingroup linop
92  *
93  * Supports creation and application for linear operators that
94  * hold things like Dirac operators, etc. that are differentiable
95  */
96  template<typename T, typename P, typename Q>
98  {
99  public:
100  //! Virtual destructor to help with cleanup;
101  virtual ~DiffLinearOperator() {}
102 
103  //! Return the fermion BC object for this linear operator
104  virtual const FermBC<T,P,Q>& getFermBC() const = 0;
105 
106  //! Apply the derivative of the operator onto a source std::vector
107  /*! Default implementation */
108  virtual void deriv(P& ds_u, const T& chi, const T& psi,
109  enum PlusMinus isign) const
110  {
111  QDPIO::cerr << "deriv: not implemented" << std::endl;
112  QDP_abort(1);
113  }
114 
115 
116  //! Apply the derivative of the operator onto a source std::vector to some precision
117  /*! Default implementation */
118  virtual void deriv(P& ds_u, const T& chi, const T& psi,
119  enum PlusMinus isign, const Real& epsilon) const
120  {
121  this->deriv(ds_u,chi,psi,isign);
122  }
123 
124  //! Return the force for multiple poles
125  virtual void derivMultipole(P& ds_u, const multi1d<T>& chi, const multi1d<T>&psi, enum PlusMinus isign) const
126  {
127  // Code up in terms of derivs for category default
128  ds_u.resize(Nd);
129  ds_u = zero;
130 
131  P F_tmp;
132  for(int i=0; i < chi.size(); i++) {
133  this->deriv(F_tmp, chi[i], psi[i], isign);
134  ds_u += F_tmp;
135  }
136  }
137 
138  };
139 
140 
141  //-----------------------------------------------------------------------------------
142  //! Differentiable Linear Operator
143  /*! @ingroup linop
144  *
145  * Supports creation and application for linear operators that
146  * hold things like Dirac operators, etc. that are differentiable
147  */
148  template<typename T, typename P, typename Q>
150  {
151  public:
152  //! Virtual destructor to help with cleanup;
154 
155  //! Return the fermion BC object for this linear operator
156  virtual const FermBC<T,P,Q>& getFermBC() const = 0;
157 
158  //! Apply the derivative of the operator onto a source std::vector
159  /*! Default implementation */
160  virtual void deriv(P& ds_u, const multi1d<T>& chi, const multi1d<T>& psi,
161  enum PlusMinus isign) const
162  {
163  QDPIO::cerr << "deriv: not implemented" << std::endl;
164  QDP_abort(1);
165  }
166 
167  //! Apply the derivative of the operator onto a source std::vector to some precision
168  /*! Default implementation */
169  virtual void deriv(P& ds_u, const multi1d<T>& chi, const multi1d<T>& psi,
170  enum PlusMinus isign, const Real& epsilon) const
171  {
172  deriv(ds_u,chi,psi,isign);
173  }
174  };
175 
176 
177  //----------------------------------------------------------------
178  //! Unpreconditioned linear operator including derivatives
179  /*! @ingroup linop
180  *
181  * Support for unpreconditioned linear operators with derivative
182  */
183  template<typename T, typename P, typename Q>
185  {
186  public:
187  //! Virtual destructor to help with cleanup;
189 
190  //! Only defined on the entire lattice
191  const Subset& subset() const {return all;}
192  };
193 
194 
195  //----------------------------------------------------------------
196  //! Unpreconditioned linear operator including derivatives
197  /*! @ingroup linop
198  *
199  * Support for unpreconditioned linear operators with derivative
200  */
201  template<typename T, typename P, typename Q>
203  {
204  public:
205  //! Virtual destructor to help with cleanup;
207 
208  //! Only defined on the entire lattice
209  const Subset& subset() const {return all;}
210  };
211 
212 
213  //-----------------------------------------------------------------------------------
214  //! Dslash-like Linear Operator
215  /*! @ingroup linop
216  *
217  * These are concessions/optimizations for red-black checkboarding
218  */
219  template<typename T, typename P, typename Q>
221  {
222  public:
223  //! Virtual destructor to help in cleanup
225 
226  //! Return the fermion BC object for this linear operator
227  virtual const FermBC<T,P,Q>& getFermBC() const = 0;
228 
229  //! Apply operator on both checkerboards (entire lattice)
230  virtual void operator() (T& d, const T& psi, enum PlusMinus isign) const
231  {
232  apply(d, psi, isign, 0);
233  apply(d, psi, isign, 1);
234  }
235 
236  //! Apply checkerboarded linear operator
237  /*!
238  * To avoid confusion (especially of the compilers!), call the checkerboarded
239  * apply instead of operator()
240  */
241  virtual void apply (T& chi, const T& psi, enum PlusMinus isign, int cb) const = 0;
242 
243 
244  //! Take deriv of D
245  /*!
246  * \param chi left std::vector (Read)
247  * \param psi right std::vector (Read)
248  * \param isign D'^dag or D' ( MINUS | PLUS ) resp. (Read)
249  *
250  * \return Computes \f$chi^\dag * \dot(D} * psi\f$
251  */
252  virtual void deriv(P& ds_u, const T& chi, const T& psi,
253  enum PlusMinus isign) const
254  {
255  QDPIO::cerr << "deriv: not implemented" << std::endl;
256  QDP_abort(1);
257  }
258 
259  //! Take deriv of D
260  /*!
261  * \param chi left std::vector on cb (Read)
262  * \param psi right std::vector on 1-cb (Read)
263  * \param isign D'^dag or D' ( MINUS | PLUS ) resp. (Read)
264  * \param cb Checkerboard of chi std::vector (Read)
265  *
266  * \return Computes \f$chi^\dag * \dot(D} * psi\f$
267  */
268  virtual void deriv(P& ds_u, const T& chi, const T& psi,
269  enum PlusMinus isign, int cb) const
270  {
271  QDPIO::cerr << "deriv: not implemented" << std::endl;
272  QDP_abort(1);
273  }
274 
275  virtual void derivMultipole(P& ds_u, const multi1d<T>& chi, const multi1d<T>&psi, enum PlusMinus isign) const
276  {
277  // Code up in terms of derivs for category default
278  ds_u.resize(Nd);
279  ds_u = zero;
280 
281  P F_tmp;
282  for(int i=0; i < chi.size(); i++) {
283  deriv(F_tmp, chi[i], psi[i], isign);
284  ds_u += F_tmp;
285  }
286 
287  }
288 
289 
290  virtual void derivMultipole(P& ds_u, const multi1d<T>& chi, const multi1d<T>&psi, enum PlusMinus isign,int cb) const
291  {
292  // Code up in terms of derivs for category default
293  ds_u.resize(Nd);
294  ds_u = zero;
295 
296  P F_tmp;
297  for(int i=0; i < chi.size(); i++) {
298  deriv(F_tmp, chi[i], psi[i], isign,cb);
299  ds_u += F_tmp;
300  }
301 
302  }
303  };
304 
305 
306 
307  //-----------------------------------------------------------------------------------
308  //! Dslash-like Linear Operator for arrays
309  /*! @ingroup linop
310  *
311  * These are concessions/optimizations for red-black checkboarding
312  */
313  template<typename T, typename P, typename Q>
315  {
316  public:
317  //! Virtual destructor to help in cleanup
319 
320  //! Return the fermion BC object for this linear operator
321  virtual const FermBC<T,P,Q>& getFermBC() const = 0;
322 
323  //! Expected length of array index
324  virtual int size() const = 0;
325 
326  //! Apply operator on both checkerboards (entire lattice)
327  virtual void operator() (multi1d<T>& d, const multi1d<T>& psi, enum PlusMinus isign) const
328  {
329  d.resize(size());
330  apply(d, psi, isign, 0);
331  apply(d, psi, isign, 1);
332  }
333 
334  //! Apply checkerboarded linear operator
335  /*!
336  * To avoid confusion (especially of the compilers!), call the checkerboarded
337  * apply instead of operator()
338  */
339  virtual void apply (multi1d<T>& chi, const multi1d<T>& psi, enum PlusMinus isign, int cb) const = 0;
340 
341  //! Take deriv of D
342  /*!
343  * \param chi left std::vector (Read)
344  * \param psi right std::vector (Read)
345  * \param isign D'^dag or D' ( MINUS | PLUS ) resp. (Read)
346  *
347  * \return Computes \f$chi^\dag * \dot(D} * psi\f$
348  */
349  virtual void deriv(P& ds_u, const multi1d<T>& chi, const multi1d<T>& psi,
350  enum PlusMinus isign) const
351  {
352  QDPIO::cerr << "deriv: not implemented" << std::endl;
353  QDP_abort(1);
354  }
355 
356  //! Take deriv of D
357  /*!
358  * \param chi left std::vector on cb (Read)
359  * \param psi right std::vector on 1-cb (Read)
360  * \param isign D'^dag or D' ( MINUS | PLUS ) resp. (Read)
361  * \param cb Checkerboard of chi std::vector (Read)
362  *
363  * \return Computes \f$chi^\dag * \dot(D} * psi\f$
364  */
365  virtual void deriv(P& ds_u, const multi1d<T>& chi, const multi1d<T>& psi,
366  enum PlusMinus isign, int cb) const
367  {
368  QDPIO::cerr << "deriv: not implemented" << std::endl;
369  QDP_abort(1);
370  }
371  };
372 
373 }
374 
375 
376 
377 #endif
Primary include file for CHROMA library code.
Differentiable Linear Operator.
Definition: linearop.h:150
virtual ~DiffLinearOperatorArray()
Virtual destructor to help with cleanup;.
Definition: linearop.h:153
virtual const FermBC< T, P, Q > & getFermBC() const =0
Return the fermion BC object for this linear operator.
virtual void deriv(P &ds_u, const multi1d< T > &chi, const multi1d< T > &psi, enum PlusMinus isign, const Real &epsilon) const
Apply the derivative of the operator onto a source std::vector to some precision.
Definition: linearop.h:169
virtual void deriv(P &ds_u, const multi1d< T > &chi, const multi1d< T > &psi, enum PlusMinus isign) const
Apply the derivative of the operator onto a source std::vector.
Definition: linearop.h:160
Differentiable Linear Operator.
Definition: linearop.h:98
virtual void derivMultipole(P &ds_u, const multi1d< T > &chi, const multi1d< T > &psi, enum PlusMinus isign) const
Return the force for multiple poles.
Definition: linearop.h:125
virtual void deriv(P &ds_u, const T &chi, const T &psi, enum PlusMinus isign, const Real &epsilon) const
Apply the derivative of the operator onto a source std::vector to some precision.
Definition: linearop.h:118
virtual const FermBC< T, P, Q > & getFermBC() const =0
Return the fermion BC object for this linear operator.
virtual ~DiffLinearOperator()
Virtual destructor to help with cleanup;.
Definition: linearop.h:101
virtual void deriv(P &ds_u, const T &chi, const T &psi, enum PlusMinus isign) const
Apply the derivative of the operator onto a source std::vector.
Definition: linearop.h:108
Dslash-like Linear Operator for arrays.
Definition: linearop.h:315
virtual int size() const =0
Expected length of array index.
virtual const FermBC< T, P, Q > & getFermBC() const =0
Return the fermion BC object for this linear operator.
virtual void apply(multi1d< T > &chi, const multi1d< T > &psi, enum PlusMinus isign, int cb) const =0
Apply checkerboarded linear operator.
virtual ~DslashLinearOperatorArray()
Virtual destructor to help in cleanup.
Definition: linearop.h:318
virtual void deriv(P &ds_u, const multi1d< T > &chi, const multi1d< T > &psi, enum PlusMinus isign) const
Take deriv of D.
Definition: linearop.h:349
virtual void deriv(P &ds_u, const multi1d< T > &chi, const multi1d< T > &psi, enum PlusMinus isign, int cb) const
Take deriv of D.
Definition: linearop.h:365
Dslash-like Linear Operator.
Definition: linearop.h:221
virtual void derivMultipole(P &ds_u, const multi1d< T > &chi, const multi1d< T > &psi, enum PlusMinus isign) const
Return the force for multiple poles.
Definition: linearop.h:275
virtual void derivMultipole(P &ds_u, const multi1d< T > &chi, const multi1d< T > &psi, enum PlusMinus isign, int cb) const
Definition: linearop.h:290
virtual ~DslashLinearOperator()
Virtual destructor to help in cleanup.
Definition: linearop.h:224
virtual void apply(T &chi, const T &psi, enum PlusMinus isign, int cb) const =0
Apply checkerboarded linear operator.
virtual void deriv(P &ds_u, const T &chi, const T &psi, enum PlusMinus isign, int cb) const
Take deriv of D.
Definition: linearop.h:268
virtual void deriv(P &ds_u, const T &chi, const T &psi, enum PlusMinus isign) const
Take deriv of D.
Definition: linearop.h:252
virtual const FermBC< T, P, Q > & getFermBC() const =0
Return the fermion BC object for this linear operator.
Base class for all fermion action boundary conditions.
Definition: fermbc.h:20
Linear Operator to arrays.
Definition: linearop.h:61
virtual int size() const =0
Expected length of array index.
virtual ~LinearOperatorArray()
Virtual destructor to help with cleanup;.
Definition: linearop.h:64
virtual unsigned long nFlops() const
Definition: linearop.h:85
virtual const Subset & subset() const =0
Return the subset on which the operator acts.
Linear Operator.
Definition: linearop.h:27
virtual const Subset & subset() const =0
Return the subset on which the operator acts.
virtual unsigned long nFlops() const
Definition: linearop.h:48
virtual ~LinearOperator()
Virtual destructor to help with cleanup;.
Definition: linearop.h:30
Unpreconditioned linear operator including derivatives.
Definition: linearop.h:203
const Subset & subset() const
Only defined on the entire lattice.
Definition: linearop.h:209
virtual ~UnprecLinearOperatorArray()
Virtual destructor to help with cleanup;.
Definition: linearop.h:206
Unpreconditioned linear operator including derivatives.
Definition: linearop.h:185
const Subset & subset() const
Only defined on the entire lattice.
Definition: linearop.h:191
virtual ~UnprecLinearOperator()
Virtual destructor to help with cleanup;.
Definition: linearop.h:188
Fermion action boundary conditions.
unsigned i
Definition: ldumul_w.cc:34
Nd
Definition: meslate.cc:74
int epsilon(int i, int j, int k)
multi1d< Hadron2PtContraction_t > operator()(const multi1d< LatticeColorMatrix > &u)
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
LinOpSysSolverMGProtoClover::T T
DComplex d
Definition: invbicg.cc:99
int cb
Definition: invbicg.cc:120
Double zero
Definition: invbicg.cc:106
chi
Definition: pade_trln_w.cc:24
psi
Definition: pade_trln_w.cc:191
multi1d< LatticeColorMatrix > P
Definition: t_clover.cc:13
multi1d< LatticeColorMatrix > deriv(const EvenOddPrecLinearOperator< LatticeFermion, multi1d< LatticeColorMatrix >, multi1d< LatticeColorMatrix > > &AP, const LatticeFermion &chi, const LatticeFermion &psi, enum PlusMinus isign)
Apply the operator onto a source std::vector.