IFPACK  Development
Ifpack_Chebyshev.h
1 /*@HEADER
2 // ***********************************************************************
3 //
4 // Ifpack: Object-Oriented Algebraic Preconditioner Package
5 // Copyright (2002) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 //@HEADER
41 */
42 
43 #ifndef IFPACK_CHEBYSHEV_H
44 #define IFPACK_CHEBYSHEV_H
45 
46 #include "Ifpack_ConfigDefs.h"
47 #include "Ifpack_Preconditioner.h"
48 #include "Teuchos_RefCountPtr.hpp"
49 
50 namespace Teuchos {
51  class ParameterList;
52 }
53 
54 class Epetra_MultiVector;
55 class Epetra_Vector;
56 class Epetra_Map;
57 class Epetra_Comm;
58 class Epetra_Time;
59 class Epetra_Vector;
60 class Epetra_Operator;
61 class Epetra_RowMatrix;
62 
63 #ifdef HAVE_IFPACK_EPETRAEXT
64 class EpetraExt_PointToBlockDiagPermute;
65 #endif
66 
68 
105 
106 public:
107 
109 
116 
118 
124 
126  virtual ~Ifpack_Chebyshev() {};
127 
129 
136  virtual inline int SetUseTranspose(bool UseTranspose_in)
137  {
138  UseTranspose_ = UseTranspose_in;
139  return(0);
140  }
141 
143 
145 
147 
155  virtual inline int Apply(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
156 
158 
168  virtual int ApplyInverse(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
169 
171  virtual double NormInf() const
172  {
173  return(-1.0);
174  }
176 
178 
179  virtual const char * Label() const
180  {
181  return(Label_.c_str());
182  }
183 
185  virtual bool UseTranspose() const
186  {
187  return(UseTranspose_);
188  }
189 
191  virtual bool HasNormInf() const
192  {
193  return(false);
194  }
195 
197  virtual const Epetra_Comm & Comm() const;
198 
200  virtual const Epetra_Map & OperatorDomainMap() const;
201 
203  virtual const Epetra_Map & OperatorRangeMap() const;
204 
205  virtual int Initialize();
206 
207  virtual bool IsInitialized() const
208  {
209  return(IsInitialized_);
210  }
211 
213  virtual inline bool IsComputed() const
214  {
215  return(IsComputed_);
216  }
217 
219  virtual int Compute();
220 
222  virtual double GetLambdaMax(){return LambdaMax_;}
223 
225  virtual double GetLambdaMin(){return LambdaMin_;}
226 
228 
230 
231  virtual const Epetra_RowMatrix& Matrix() const
232  {
233  return(*Matrix_);
234  }
235 
237  virtual double Condest(const Ifpack_CondestType CT = Ifpack_Cheap,
238  const int MaxIters = 1550,
239  const double Tol = 1e-9,
240  Epetra_RowMatrix* Matrix_in = 0);
241 
243  virtual double Condest() const
244  {
245  return(Condest_);
246  }
247 
249  virtual int SetParameters(Teuchos::ParameterList& List);
250 
252  virtual std::ostream& Print(std::ostream & os) const;
253 
255 
257 
259  virtual int NumInitialize() const
260  {
261  return(NumInitialize_);
262  }
263 
265  virtual int NumCompute() const
266  {
267  return(NumCompute_);
268  }
269 
271  virtual int NumApplyInverse() const
272  {
273  return(NumApplyInverse_);
274  }
275 
277  virtual double InitializeTime() const
278  {
279  return(InitializeTime_);
280  }
281 
283  virtual double ComputeTime() const
284  {
285  return(ComputeTime_);
286  }
287 
289  virtual double ApplyInverseTime() const
290  {
291  return(ApplyInverseTime_);
292  }
293 
295  virtual double InitializeFlops() const
296  {
297  return(0.0);
298  }
299 
301  virtual double ComputeFlops() const
302  {
303  return(ComputeFlops_);
304  }
305 
307  virtual double ApplyInverseFlops() const
308  {
309  return(ApplyInverseFlops_);
310  }
311 
312  // @}
313  // @{ \name Utility methods
314 
316  static int PowerMethod(const Epetra_Operator& Operator,
317  const Epetra_Vector& InvPointDiagonal,
318  const int MaximumIterations,
319  double& LambdaMax,const unsigned int * RngSeed=0);
320 
322  static int CG(const Epetra_Operator& Operator,
323  const Epetra_Vector& InvPointDiagonal,
324  const int MaximumIterations,
325  double& lambda_min, double& lambda_max,const unsigned int * RngSeed=0);
326 
327 #ifdef HAVE_IFPACK_EPETRAEXT
328  // WARNING: This only works in Block Mode.
330  int CG(const int MaximumIterations,
331  double& lambda_min, double& lambda_max,const unsigned int * RngSeed=0);
333  // WARNING: This only works in Block Mode.
334  int PowerMethod(const int MaximumIterations,double& lambda_max,const unsigned int * RngSeed=0);
335 #endif
336 private:
337 
338  // @}
339  // @{ \name Private methods
340 
342  virtual void SetLabel();
343 
346  {}
347 
349  Ifpack_Chebyshev& operator=(const Ifpack_Chebyshev& rhs)
350  {
351  return(*this);
352  }
353 
354  // @{ Initializations, timing and flops
356  bool IsInitialized_;
358  bool IsComputed_;
360  int NumInitialize_;
362  int NumCompute_;
364  mutable int NumApplyInverse_;
366  double InitializeTime_;
368  double ComputeTime_;
370  mutable double ApplyInverseTime_;
372  double ComputeFlops_;
374  mutable double ApplyInverseFlops_;
375  // @}
376 
377  // @{ Settings
379  int PolyDegree_;
381  bool UseTranspose_;
383  double Condest_;
384 #if 0
385  // Unused; commented out to avoid build warnings
386 
388  bool ComputeCondest_;
389 #endif // 0
390  double EigRatio_;
394  int EigMaxIters_;
396  std::string Label_;
398  double LambdaMin_;
400  double LambdaMax_;
402  double MinDiagonalValue_;
403  // @}
404 
405  // @{ Other data
407  int NumMyRows_;
409  int NumMyNonzeros_;
411  long long NumGlobalRows_;
413  long long NumGlobalNonzeros_;
415  Teuchos::RefCountPtr<const Epetra_Operator> Operator_;
417  Teuchos::RefCountPtr<const Epetra_RowMatrix> Matrix_;
419  mutable Teuchos::RefCountPtr<Epetra_Vector> InvDiagonal_;
421  bool UseBlockMode_;
422 #ifdef HAVE_IFPACK_EPETRAEXT
423  Teuchos::ParameterList BlockList_;
425  Teuchos::RefCountPtr<EpetraExt_PointToBlockDiagPermute> InvBlockDiagonal_;
426 #endif
427 
429  bool SolveNormalEquations_;
430 
432  bool IsRowMatrix_;
434  Teuchos::RefCountPtr<Epetra_Time> Time_;
436  bool ZeroStartingSolution_;
437 
438  // @}
439 
440 };
441 
442 
443 #endif // IFPACK_CHEBYSHEV_H
Ifpack_Chebyshev::GetLambdaMin
virtual double GetLambdaMin()
Contains an approximation to the smallest eigenvalue.
Definition: Ifpack_Chebyshev.h:225
Ifpack_Chebyshev
Ifpack_Chebyshev: class for preconditioning with Chebyshev polynomials in Ifpack.
Definition: Ifpack_Chebyshev.h:104
Ifpack_Chebyshev::Matrix
virtual const Epetra_RowMatrix & Matrix() const
Returns a pointer to the matrix to be preconditioned.
Definition: Ifpack_Chebyshev.h:231
Ifpack_Chebyshev::SetUseTranspose
virtual int SetUseTranspose(bool UseTranspose_in)
Definition: Ifpack_Chebyshev.h:136
Ifpack_Chebyshev::PowerMethod
static int PowerMethod(const Epetra_Operator &Operator, const Epetra_Vector &InvPointDiagonal, const int MaximumIterations, double &LambdaMax, const unsigned int *RngSeed=0)
Simple power method to compute lambda_max.
Definition: Ifpack_Chebyshev.cpp:729
Ifpack_Chebyshev::Comm
virtual const Epetra_Comm & Comm() const
Returns a pointer to the Epetra_Comm communicator associated with this operator.
Definition: Ifpack_Chebyshev.cpp:209
Ifpack_Chebyshev::OperatorRangeMap
virtual const Epetra_Map & OperatorRangeMap() const
Returns the Epetra_Map object associated with the range of this operator.
Definition: Ifpack_Chebyshev.cpp:221
Ifpack_Chebyshev::Apply
virtual int Apply(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Applies the matrix to an Epetra_MultiVector.
Definition: Ifpack_Chebyshev.cpp:228
Ifpack_Chebyshev::UseTranspose
virtual bool UseTranspose() const
Returns the current UseTranspose setting.
Definition: Ifpack_Chebyshev.h:185
Ifpack_Chebyshev::OperatorDomainMap
virtual const Epetra_Map & OperatorDomainMap() const
Returns the Epetra_Map object associated with the domain of this operator.
Definition: Ifpack_Chebyshev.cpp:215
Ifpack_Chebyshev::InitializeFlops
virtual double InitializeFlops() const
Returns the number of flops in the initialization phase.
Definition: Ifpack_Chebyshev.h:295
Epetra_Comm
Ifpack_Chebyshev::NumApplyInverse
virtual int NumApplyInverse() const
Returns the number of calls to ApplyInverse().
Definition: Ifpack_Chebyshev.h:271
Ifpack_Chebyshev::ComputeFlops
virtual double ComputeFlops() const
Returns the number of flops in the computation phase.
Definition: Ifpack_Chebyshev.h:301
Ifpack_Chebyshev::IsComputed
virtual bool IsComputed() const
Returns true if the preconditioner has been successfully computed.
Definition: Ifpack_Chebyshev.h:213
Ifpack_Chebyshev::ComputeTime
virtual double ComputeTime() const
Returns the time spent in Compute().
Definition: Ifpack_Chebyshev.h:283
Epetra_RowMatrix
Ifpack_Chebyshev::ApplyInverseFlops
virtual double ApplyInverseFlops() const
Returns the number of flops for the application of the preconditioner.
Definition: Ifpack_Chebyshev.h:307
Ifpack_Chebyshev::HasNormInf
virtual bool HasNormInf() const
Returns true if the this object can provide an approximate Inf-norm, false otherwise.
Definition: Ifpack_Chebyshev.h:191
Ifpack_Chebyshev::CG
static int CG(const Epetra_Operator &Operator, const Epetra_Vector &InvPointDiagonal, const int MaximumIterations, double &lambda_min, double &lambda_max, const unsigned int *RngSeed=0)
Uses AztecOO's CG to estimate lambda_min and lambda_max.
Definition: Ifpack_Chebyshev.cpp:763
Ifpack_Chebyshev::NormInf
virtual double NormInf() const
Returns the infinity norm of the global matrix (not implemented)
Definition: Ifpack_Chebyshev.h:171
Epetra_Vector
Ifpack_Chebyshev::IsInitialized
virtual bool IsInitialized() const
Returns true if the preconditioner has been successfully initialized, false otherwise.
Definition: Ifpack_Chebyshev.h:207
Ifpack_Chebyshev::ApplyInverse
virtual int ApplyInverse(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Applies the preconditioner to X, returns the result in Y.
Definition: Ifpack_Chebyshev.cpp:467
Ifpack_Chebyshev::Compute
virtual int Compute()
Computes the preconditioners.
Definition: Ifpack_Chebyshev.cpp:283
Epetra_Time
Ifpack_Chebyshev::Condest
virtual double Condest() const
Returns the condition number estimate, or -1.0 if not computed.
Definition: Ifpack_Chebyshev.h:243
Ifpack_Chebyshev::InitializeTime
virtual double InitializeTime() const
Returns the time spent in Initialize().
Definition: Ifpack_Chebyshev.h:277
Epetra_MultiVector
Ifpack_Preconditioner
Ifpack_Preconditioner: basic class for preconditioning in Ifpack.
Definition: Ifpack_Preconditioner.h:136
Ifpack_Chebyshev::GetLambdaMax
virtual double GetLambdaMax()
Returns an approximation to the largest eigenvalue.
Definition: Ifpack_Chebyshev.h:222
Ifpack_Chebyshev::NumCompute
virtual int NumCompute() const
Returns the number of calls to Compute().
Definition: Ifpack_Chebyshev.h:265
Ifpack_Chebyshev::Ifpack_Chebyshev
Ifpack_Chebyshev(const Epetra_Operator *Matrix)
Ifpack_Chebyshev constructor with given Epetra_Operator/Epetra_RowMatrix.
Definition: Ifpack_Chebyshev.cpp:83
Ifpack_Chebyshev::NumInitialize
virtual int NumInitialize() const
Returns the number of calls to Initialize().
Definition: Ifpack_Chebyshev.h:259
Ifpack_Chebyshev::~Ifpack_Chebyshev
virtual ~Ifpack_Chebyshev()
Destructor.
Definition: Ifpack_Chebyshev.h:126
Ifpack_Chebyshev::SetParameters
virtual int SetParameters(Teuchos::ParameterList &List)
Sets all the parameters for the preconditioner.
Definition: Ifpack_Chebyshev.cpp:160
Ifpack_Chebyshev::ApplyInverseTime
virtual double ApplyInverseTime() const
Returns the time spent in ApplyInverse().
Definition: Ifpack_Chebyshev.h:289
Ifpack_Chebyshev::Print
virtual std::ostream & Print(std::ostream &os) const
Prints object to an output stream.
Definition: Ifpack_Chebyshev.cpp:378
Epetra_Operator
Epetra_Map
Ifpack_Chebyshev::Initialize
virtual int Initialize()
Computes all it is necessary to initialize the preconditioner.
Definition: Ifpack_Chebyshev.cpp:249