IFPACK  Development
 All Classes Namespaces Files Functions Variables Enumerations Friends Pages
Ifpack_Polynomial.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_POLYNOMIAL_H
44 #define IFPACK_POLYNOMIAL_H
45 
46 #include "Ifpack_ConfigDefs.h"
47 #include "Ifpack_Preconditioner.h"
48 #include "Teuchos_RefCountPtr.hpp"
49 #include "Teuchos_LAPACK.hpp"
50 #include "Teuchos_SerialDenseMatrix.hpp"
51 
52 namespace Teuchos {
53  class ParameterList;
54 }
55 
56 class Epetra_MultiVector;
57 class Epetra_Vector;
58 class Epetra_Map;
59 class Epetra_Comm;
60 class Epetra_Time;
61 class Epetra_Vector;
62 class Epetra_Operator;
63 class Epetra_RowMatrix;
64 
65 #ifdef HAVE_IFPACK_EPETRAEXT
66 class EpetraExt_PointToBlockDiagPermute;
67 #endif
68 
70 
100 
101 public:
102 
104 
111 
113 
118  Ifpack_Polynomial(const Epetra_RowMatrix* Matrix);
119 
121  virtual ~Ifpack_Polynomial() {};
122 
124 
131  virtual inline int SetUseTranspose(bool UseTranspose_in)
132  {
133  UseTranspose_ = UseTranspose_in;
134  return(0);
135  }
136 
138 
140 
142 
150  virtual int Apply(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
151 
153 
163  virtual int ApplyInverse(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
164 
166  virtual double NormInf() const
167  {
168  return(-1.0);
169  }
171 
173 
174  virtual const char * Label() const
175  {
176  return(Label_.c_str());
177  }
178 
180  virtual bool UseTranspose() const
181  {
182  return(UseTranspose_);
183  }
184 
186  virtual bool HasNormInf() const
187  {
188  return(false);
189  }
190 
192  virtual const Epetra_Comm & Comm() const;
193 
195  virtual const Epetra_Map & OperatorDomainMap() const;
196 
198  virtual const Epetra_Map & OperatorRangeMap() const;
199 
200  virtual int Initialize();
201 
202  virtual bool IsInitialized() const
203  {
204  return(IsInitialized_);
205  }
206 
208  virtual inline bool IsComputed() const
209  {
210  return(IsComputed_);
211  }
212 
214  virtual int Compute();
215 
217 
218  virtual const Epetra_RowMatrix& Matrix() const
219  {
220  return(*Matrix_);
221  }
222 
224  virtual double Condest(const Ifpack_CondestType CT = Ifpack_Cheap,
225  const int MaxIters = 1550,
226  const double Tol = 1e-9,
227  Epetra_RowMatrix* Matrix_in = 0);
228 
230  virtual double Condest() const
231  {
232  return(Condest_);
233  }
234 
236  virtual int SetParameters(Teuchos::ParameterList& List);
237 
239  virtual std::ostream& Print(std::ostream & os) const;
240 
242 
244 
246  virtual int NumInitialize() const
247  {
248  return(NumInitialize_);
249  }
250 
252  virtual int NumCompute() const
253  {
254  return(NumCompute_);
255  }
256 
258  virtual int NumApplyInverse() const
259  {
260  return(NumApplyInverse_);
261  }
262 
264  virtual double InitializeTime() const
265  {
266  return(InitializeTime_);
267  }
268 
270  virtual double ComputeTime() const
271  {
272  return(ComputeTime_);
273  }
274 
276  virtual double ApplyInverseTime() const
277  {
278  return(ApplyInverseTime_);
279  }
280 
282  virtual double InitializeFlops() const
283  {
284  return(0.0);
285  }
286 
288  virtual double ComputeFlops() const
289  {
290  return(ComputeFlops_);
291  }
292 
294  virtual double ApplyInverseFlops() const
295  {
296  return(ApplyInverseFlops_);
297  }
298 
299  // @}
300  // @{ \name Utility methods
301 
303  static int PowerMethod(const Epetra_Operator& Operator,
304  const Epetra_Vector& InvPointDiagonal,
305  const int MaximumIterations,
306  double& LambdaMax);
307 
309  static int CG(const Epetra_Operator& Operator,
310  const Epetra_Vector& InvPointDiagonal,
311  const int MaximumIterations,
312  double& lambda_min, double& lambda_max);
313 
314 #ifdef HAVE_IFPACK_EPETRAEXT
315  // WARNING: This only works in Block Mode.
317  int CG(const int MaximumIterations,
318  double& lambda_min, double& lambda_max);
320  // WARNING: This only works in Block Mode.
321  int PowerMethod(const int MaximumIterations,double& lambda_max);
322 #endif
323 
325  int GMRES(const Epetra_Operator& Operator,
326  const Epetra_Vector& InvPointDiagonal,
327  const int MaximumIterations,
328  double& lambda_real_min, double& lambda_real_max,
329  double& lambda_imag_min, double& lambda_imag_max);
330 
331 private:
332 
333  // @}
334  // @{ \name Private methods
335 
337  virtual void SetLabel();
338 
340  Ifpack_Polynomial(const Ifpack_Polynomial& /* rhs */)
341  {}
342 
344  Ifpack_Polynomial& operator=(const Ifpack_Polynomial& /* rhs */)
345  {
346  return(*this);
347  }
348 
349  // @{ Initializations, timing and flops
351  bool IsInitialized_;
353  bool IsComputed_;
355  bool IsIndefinite_;
357  bool IsComplex_;
359  int NumInitialize_;
361  int NumCompute_;
363  mutable int NumApplyInverse_;
365  double InitializeTime_;
367  double ComputeTime_;
369  mutable double ApplyInverseTime_;
371  double ComputeFlops_;
373  mutable double ApplyInverseFlops_;
374  // @}
375 
376  // @{ Settings
378  int PolyDegree_;
380  int LSPointsReal_, LSPointsImag_;
382  bool UseTranspose_;
384  double Condest_;
385 #if 0
386  // Unused; commented out to avoid build warnings
387 
389  bool ComputeCondest_;
390 #endif // 0
391  double RealEigRatio_, ImagEigRatio_;
395  int EigMaxIters_;
397  std::string Label_;
399  double LambdaRealMin_, LambdaRealMax_, LambdaImagMin_, LambdaImagMax_;
401  double MinDiagonalValue_;
403  std::vector<double> coeff_;
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 
428 
430  bool SolveNormalEquations_;
431 
433  bool IsRowMatrix_;
435  Teuchos::RefCountPtr<Epetra_Time> Time_;
437  bool ZeroStartingSolution_;
438 
439  // @}
440 
441 };
442 
443 
444 #endif // IFPACK_POLYNOMIAL_H
int GMRES(const Epetra_Operator &Operator, const Epetra_Vector &InvPointDiagonal, const int MaximumIterations, double &lambda_real_min, double &lambda_real_max, double &lambda_imag_min, double &lambda_imag_max)
Uses AztecOO&#39;s GMRES to estimate the height and width of the spectrum.
virtual bool HasNormInf() const
Returns true if the this object can provide an approximate Inf-norm, false otherwise.
virtual int NumInitialize() const
Returns the number of calls to Initialize().
virtual double ComputeTime() const
Returns the time spent in Compute().
virtual bool UseTranspose() const
Returns the current UseTranspose setting.
virtual const Epetra_Map & OperatorDomainMap() const
Returns the Epetra_Map object associated with the domain of this operator.
virtual int ApplyInverse(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Applies the preconditioner to X, returns the result in Y.
virtual int Initialize()
Computes all it is necessary to initialize the preconditioner.
virtual int NumApplyInverse() const
Returns the number of calls to ApplyInverse().
virtual int SetUseTranspose(bool UseTranspose_in)
virtual double NormInf() const
Returns the infinity norm of the global matrix (not implemented)
static int CG(const Epetra_Operator &Operator, const Epetra_Vector &InvPointDiagonal, const int MaximumIterations, double &lambda_min, double &lambda_max)
Uses AztecOO&#39;s CG to estimate lambda_min and lambda_max.
virtual ~Ifpack_Polynomial()
Destructor.
virtual int Compute()
Computes the preconditioners.
virtual bool IsInitialized() const
Returns true if the preconditioner has been successfully initialized, false otherwise.
Ifpack_Preconditioner: basic class for preconditioning in Ifpack.
Ifpack_Polynomial(const Epetra_Operator *Matrix)
Ifpack_Polynomial constructor with given Epetra_Operator/Epetra_RowMatrix.
virtual int SetParameters(Teuchos::ParameterList &List)
Sets all the parameters for the preconditioner.
Ifpack_Polynomial: class for preconditioning with least squares polynomials in Ifpack.
virtual bool IsComputed() const
Returns true if the preconditioner has been successfully computed.
virtual const Epetra_RowMatrix & Matrix() const
Returns a pointer to the matrix to be preconditioned.
virtual std::ostream & Print(std::ostream &os) const
Prints object to an output stream.
virtual int Apply(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Applies the matrix to an Epetra_MultiVector.
virtual double InitializeFlops() const
Returns the number of flops in the initialization phase.
virtual int NumCompute() const
Returns the number of calls to Compute().
static int PowerMethod(const Epetra_Operator &Operator, const Epetra_Vector &InvPointDiagonal, const int MaximumIterations, double &LambdaMax)
Simple power method to compute lambda_max.
virtual double InitializeTime() const
Returns the time spent in Initialize().
virtual double ApplyInverseFlops() const
Returns the number of flops for the application of the preconditioner.
virtual double ApplyInverseTime() const
Returns the time spent in ApplyInverse().
virtual double ComputeFlops() const
Returns the number of flops in the computation phase.
virtual const Epetra_Comm & Comm() const
Returns a pointer to the Epetra_Comm communicator associated with this operator.
virtual const Epetra_Map & OperatorRangeMap() const
Returns the Epetra_Map object associated with the range of this operator.
virtual double Condest() const
Returns the condition number estimate, or -1.0 if not computed.