IFPACK  Development
 All Classes Namespaces Files Functions Variables Enumerations Friends Pages
Ifpack_SORa.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_SORA_H
44 #define IFPACK_SORA_H
45 
46 #if defined(Ifpack_SHOW_DEPRECATED_WARNINGS)
47 #ifdef __GNUC__
48 #warning "The Ifpack package is deprecated"
49 #endif
50 #endif
51 
52 #include "Ifpack_ConfigDefs.h"
53 #include "Ifpack_Preconditioner.h"
54 
55 #ifdef HAVE_IFPACK_EPETRAEXT
56 #include "Ifpack_Condest.h"
57 #include "Ifpack_ScalingType.h"
58 #include "Epetra_CompObject.h"
59 #include "Epetra_MultiVector.h"
60 #include "Epetra_Vector.h"
61 #include "Epetra_CrsGraph.h"
62 #include "Epetra_CrsMatrix.h"
63 #include "Epetra_BlockMap.h"
64 #include "Epetra_Map.h"
65 #include "Epetra_Object.h"
66 #include "Epetra_Comm.h"
67 #include "Epetra_CrsMatrix.h"
68 #include "Epetra_Time.h"
69 #include "Teuchos_RefCountPtr.hpp"
70 #include "EpetraExt_Transpose_RowMatrix.h"
71 
72 
73 namespace Teuchos {
74  class ParameterList;
75 }
76 
78 
86 class Ifpack_SORa: public Ifpack_Preconditioner {
87 
88 public:
89  // @{ Constructors and destructors.
91 
93  Ifpack_SORa(Epetra_RowMatrix* A);
94 
96  ~Ifpack_SORa()
97  {
98  Destroy();
99  }
100 
101  // @}
102  // @{ Construction methods
103 
105  int Initialize();
106 
108  bool IsInitialized() const
109  {
110  return(IsInitialized_);
111  }
112 
114 
116  int Compute();
117 
119  bool IsComputed() const
120  {
121  return(IsComputed_);
122  }
123 
125  /* This method is only available if the Teuchos package is enabled.
126  This method recognizes four parameter names: relax_value,
127  absolute_threshold, relative_threshold and overlap_mode. These names are
128  case insensitive, and in each case except overlap_mode, the ParameterEntry
129  must have type double. For overlap_mode, the ParameterEntry must have
130  type Epetra_CombineMode.
131  */
132  int SetParameters(Teuchos::ParameterList& parameterlist);
133 
135 
144  int SetUseTranspose(bool UseTranspose_in) {UseTranspose_ = UseTranspose_in; return(0);};
145  // @}
146 
147  // @{ Mathematical functions.
148  // Applies the matrix to X, returns the result in Y.
149  int Apply(const Epetra_MultiVector& X,
150  Epetra_MultiVector& Y) const
151  {
152  return(Multiply(false,X,Y));
153  }
154 
155  int Multiply(bool Trans, const Epetra_MultiVector& X,
156  Epetra_MultiVector& Y) const{return A_->Multiply(Trans,X,Y);}
157 
159 
172  int ApplyInverse(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
173 
175  double Condest(const Ifpack_CondestType CT = Ifpack_Cheap,
176  const int MaxIters = 1550,
177  const double Tol = 1e-9,
178  Epetra_RowMatrix* Matrix_in = 0);
179 
181  double Condest() const
182  {
183  return(Condest_);
184  }
185 
186  // @}
187  // @{ Query methods
188 
190  const char* Label() const {return(Label_);}
191 
193  int SetLabel(const char* Label_in)
194  {
195  strcpy(Label_,Label_in);
196  return(0);
197  }
198 
200  double NormInf() const {return(0.0);};
201 
203  bool HasNormInf() const {return(false);};
204 
206  bool UseTranspose() const {return(UseTranspose_);};
207 
209  const Epetra_Map & OperatorDomainMap() const {return(A_->OperatorDomainMap());};
210 
212  const Epetra_Map & OperatorRangeMap() const{return(A_->OperatorRangeMap());};
213 
215  const Epetra_Comm & Comm() const{return(A_->Comm());};
216 
218  const Epetra_RowMatrix& Matrix() const
219  {
220  return(*A_);
221  }
222 
224  virtual double GetLambdaMax() const{return LambdaMax_;}
225 
227  virtual double GetOmega() const{if(UseGlobalDamping_) return 12.0/(11.0*LambdaMax_); else return 1.0;}
228 
230  virtual std::ostream& Print(std::ostream& os) const;
231 
233  virtual int NumInitialize() const
234  {
235  return(NumInitialize_);
236  }
237 
239  virtual int NumCompute() const
240  {
241  return(NumCompute_);
242  }
243 
245  virtual int NumApplyInverse() const
246  {
247  return(NumApplyInverse_);
248  }
249 
251  virtual double InitializeTime() const
252  {
253  return(InitializeTime_);
254  }
255 
257  virtual double ComputeTime() const
258  {
259  return(ComputeTime_);
260  }
261 
263  virtual double ApplyInverseTime() const
264  {
265  return(ApplyInverseTime_);
266  }
267 
269  virtual double InitializeFlops() const
270  {
271  return(0.0);
272  }
273 
274  virtual double ComputeFlops() const
275  {
276  return(ComputeFlops_);
277  }
278 
279  virtual double ApplyInverseFlops() const
280  {
281  return(ApplyInverseFlops_);
282  }
283 
284 private:
285 
286  // @}
287  // @{ Private methods
288 
290  Ifpack_SORa(const Ifpack_SORa& RHS) :
291  Time_(RHS.Comm())
292  {}
293 
295  Ifpack_SORa& operator=(const Ifpack_SORa& /* RHS */)
296  {
297  return(*this);
298  }
299 
301  void Destroy();
302 
304 
314  int Solve(bool Trans, const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
315 
316 
317 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
318  int NumGlobalRows() const {return(A_->NumGlobalRows());};
320 
322  int NumGlobalCols() const {return(A_->NumGlobalCols());};
323 #endif
324  long long NumGlobalRows64() const {return(A_->NumGlobalRows64());};
325  long long NumGlobalCols64() const {return(A_->NumGlobalCols64());};
326 
328  int NumMyRows() const {return(A_->NumMyRows());};
329 
331  int NumMyCols() const {return(A_->NumMyCols());};
332 
334  int PowerMethod(const int MaximumIterations, double& lambda_max,const unsigned int * RngSeed=0);
335 
337  /* Epetra_RowMatrix& Matrix()
338  {
339  return(*A_);
340  }*/
341  template<typename int_type>
342  int TCompute();
343 
344  // @}
345  // @{ Internal data
346 
348  Teuchos::RefCountPtr<Epetra_CrsMatrix> Acrs_;
349  Teuchos::RefCountPtr<Epetra_RowMatrix> A_;
350  Teuchos::RefCountPtr<Epetra_CrsMatrix> W_; // Strict lower triangle
351  Teuchos::RefCountPtr<Epetra_Vector> Wdiag_;
352  Teuchos::ParameterList List_;
353 
354  bool UseTranspose_;
355  double Condest_;
356 
357 
359  bool IsInitialized_;
361  bool IsComputed_;
363  char Label_[160];
365  int NumInitialize_;
367  int NumCompute_;
368 
370  double Alpha_;
372  double Gamma_;
374  int NumSweeps_;
376  bool IsParallel_;
378  bool HaveOAZBoundaries_;
380  bool UseInterprocDamping_;
382  bool UseGlobalDamping_;
384  double LambdaMax_;
386  double LambdaMaxBoost_;
388  int PowerMethodIters_;
389 
391  mutable int NumApplyInverse_;
393  double InitializeTime_;
395  double ComputeTime_;
397  mutable double ApplyInverseTime_;
399  double ComputeFlops_;
401  mutable double ApplyInverseFlops_;
403  mutable Epetra_Time Time_;
404 
405 };
406 #else
407 #endif
408 #endif /* IFPACK_SORa_H */
virtual int NumInitialize() const =0
Returns the number of calls to Initialize().
virtual int SetUseTranspose(bool UseTranspose)=0
virtual double ComputeTime() const =0
Returns the time spent in Compute().
virtual double ComputeFlops() const =0
Returns the number of flops in the computation phase.
virtual double ApplyInverseTime() const =0
Returns the time spent in ApplyInverse().
virtual double ApplyInverseFlops() const =0
Returns the number of flops in the application of the preconditioner.
virtual const Epetra_RowMatrix & Matrix() const =0
Returns a pointer to the matrix to be preconditioned.
virtual bool IsInitialized() const =0
Returns true if the preconditioner has been successfully initialized, false otherwise.
virtual std::ostream & Print(std::ostream &os) const =0
Prints basic information on iostream. This function is used by operator&lt;&lt;.
virtual const Epetra_Map & OperatorDomainMap() const =0
virtual const char * Label() const =0
virtual int Initialize()=0
Computes all it is necessary to initialize the preconditioner.
virtual double InitializeTime() const =0
Returns the time spent in Initialize().
virtual int Apply(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const =0
virtual const Epetra_Map & OperatorRangeMap() const =0
virtual const Epetra_Comm & Comm() const =0
virtual int SetParameters(Teuchos::ParameterList &List)=0
Sets all parameters for the preconditioner.
virtual double Condest() const =0
Returns the computed condition number estimate, or -1.0 if not computed.
virtual bool UseTranspose() const =0
Ifpack_ScalingType enumerable type.
Ifpack_Preconditioner: basic class for preconditioning in Ifpack.
virtual int ApplyInverse(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const =0
Applies the preconditioner to vector X, returns the result in Y.
virtual double InitializeFlops() const =0
Returns the number of flops in the initialization phase.
virtual bool HasNormInf() const =0
virtual int NumCompute() const =0
Returns the number of calls to Compute().
virtual double NormInf() const =0
virtual bool IsComputed() const =0
Returns true if the preconditioner has been successfully computed, false otherwise.
virtual int Compute()=0
Computes all it is necessary to apply the preconditioner.
virtual int NumApplyInverse() const =0
Returns the number of calls to ApplyInverse().