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 #include "Ifpack_ConfigDefs.h"
47 #include "Ifpack_Preconditioner.h"
48 
49 #ifdef HAVE_IFPACK_EPETRAEXT
50 #include "Ifpack_Condest.h"
51 #include "Ifpack_ScalingType.h"
52 #include "Epetra_CompObject.h"
53 #include "Epetra_MultiVector.h"
54 #include "Epetra_Vector.h"
55 #include "Epetra_CrsGraph.h"
56 #include "Epetra_CrsMatrix.h"
57 #include "Epetra_BlockMap.h"
58 #include "Epetra_Map.h"
59 #include "Epetra_Object.h"
60 #include "Epetra_Comm.h"
61 #include "Epetra_CrsMatrix.h"
62 #include "Epetra_Time.h"
63 #include "Teuchos_RefCountPtr.hpp"
64 #include "EpetraExt_Transpose_RowMatrix.h"
65 
66 
67 namespace Teuchos {
68  class ParameterList;
69 }
70 
72 
80 class Ifpack_SORa: public Ifpack_Preconditioner {
81 
82 public:
83  // @{ Constructors and destructors.
85 
87  Ifpack_SORa(Epetra_RowMatrix* A);
88 
90  ~Ifpack_SORa()
91  {
92  Destroy();
93  }
94 
95  // @}
96  // @{ Construction methods
97 
99  int Initialize();
100 
102  bool IsInitialized() const
103  {
104  return(IsInitialized_);
105  }
106 
108 
110  int Compute();
111 
113  bool IsComputed() const
114  {
115  return(IsComputed_);
116  }
117 
119  /* This method is only available if the Teuchos package is enabled.
120  This method recognizes four parameter names: relax_value,
121  absolute_threshold, relative_threshold and overlap_mode. These names are
122  case insensitive, and in each case except overlap_mode, the ParameterEntry
123  must have type double. For overlap_mode, the ParameterEntry must have
124  type Epetra_CombineMode.
125  */
126  int SetParameters(Teuchos::ParameterList& parameterlist);
127 
129 
138  int SetUseTranspose(bool UseTranspose_in) {UseTranspose_ = UseTranspose_in; return(0);};
139  // @}
140 
141  // @{ Mathematical functions.
142  // Applies the matrix to X, returns the result in Y.
143  int Apply(const Epetra_MultiVector& X,
144  Epetra_MultiVector& Y) const
145  {
146  return(Multiply(false,X,Y));
147  }
148 
149  int Multiply(bool Trans, const Epetra_MultiVector& X,
150  Epetra_MultiVector& Y) const{return A_->Multiply(Trans,X,Y);}
151 
153 
166  int ApplyInverse(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
167 
169  double Condest(const Ifpack_CondestType CT = Ifpack_Cheap,
170  const int MaxIters = 1550,
171  const double Tol = 1e-9,
172  Epetra_RowMatrix* Matrix_in = 0);
173 
175  double Condest() const
176  {
177  return(Condest_);
178  }
179 
180  // @}
181  // @{ Query methods
182 
184  const char* Label() const {return(Label_);}
185 
187  int SetLabel(const char* Label_in)
188  {
189  strcpy(Label_,Label_in);
190  return(0);
191  }
192 
194  double NormInf() const {return(0.0);};
195 
197  bool HasNormInf() const {return(false);};
198 
200  bool UseTranspose() const {return(UseTranspose_);};
201 
203  const Epetra_Map & OperatorDomainMap() const {return(A_->OperatorDomainMap());};
204 
206  const Epetra_Map & OperatorRangeMap() const{return(A_->OperatorRangeMap());};
207 
209  const Epetra_Comm & Comm() const{return(A_->Comm());};
210 
212  const Epetra_RowMatrix& Matrix() const
213  {
214  return(*A_);
215  }
216 
218  virtual double GetLambdaMax() const{return LambdaMax_;}
219 
221  virtual double GetOmega() const{if(UseGlobalDamping_) return 12.0/(11.0*LambdaMax_); else return 1.0;}
222 
224  virtual std::ostream& Print(std::ostream& os) const;
225 
227  virtual int NumInitialize() const
228  {
229  return(NumInitialize_);
230  }
231 
233  virtual int NumCompute() const
234  {
235  return(NumCompute_);
236  }
237 
239  virtual int NumApplyInverse() const
240  {
241  return(NumApplyInverse_);
242  }
243 
245  virtual double InitializeTime() const
246  {
247  return(InitializeTime_);
248  }
249 
251  virtual double ComputeTime() const
252  {
253  return(ComputeTime_);
254  }
255 
257  virtual double ApplyInverseTime() const
258  {
259  return(ApplyInverseTime_);
260  }
261 
263  virtual double InitializeFlops() const
264  {
265  return(0.0);
266  }
267 
268  virtual double ComputeFlops() const
269  {
270  return(ComputeFlops_);
271  }
272 
273  virtual double ApplyInverseFlops() const
274  {
275  return(ApplyInverseFlops_);
276  }
277 
278 private:
279 
280  // @}
281  // @{ Private methods
282 
284  Ifpack_SORa(const Ifpack_SORa& RHS) :
285  Time_(RHS.Comm())
286  {}
287 
289  Ifpack_SORa& operator=(const Ifpack_SORa& /* RHS */)
290  {
291  return(*this);
292  }
293 
295  void Destroy();
296 
298 
308  int Solve(bool Trans, const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
309 
310 
311 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
312  int NumGlobalRows() const {return(A_->NumGlobalRows());};
314 
316  int NumGlobalCols() const {return(A_->NumGlobalCols());};
317 #endif
318  long long NumGlobalRows64() const {return(A_->NumGlobalRows64());};
319  long long NumGlobalCols64() const {return(A_->NumGlobalCols64());};
320 
322  int NumMyRows() const {return(A_->NumMyRows());};
323 
325  int NumMyCols() const {return(A_->NumMyCols());};
326 
328  int PowerMethod(const int MaximumIterations, double& lambda_max,const unsigned int * RngSeed=0);
329 
331  /* Epetra_RowMatrix& Matrix()
332  {
333  return(*A_);
334  }*/
335  template<typename int_type>
336  int TCompute();
337 
338  // @}
339  // @{ Internal data
340 
342  Teuchos::RefCountPtr<Epetra_CrsMatrix> Acrs_;
343  Teuchos::RefCountPtr<Epetra_RowMatrix> A_;
344  Teuchos::RefCountPtr<Epetra_CrsMatrix> W_; // Strict lower triangle
345  Teuchos::RefCountPtr<Epetra_Vector> Wdiag_;
346  Teuchos::ParameterList List_;
347 
348  bool UseTranspose_;
349  double Condest_;
350 
351 
353  bool IsInitialized_;
355  bool IsComputed_;
357  char Label_[160];
359  int NumInitialize_;
361  int NumCompute_;
362 
364  double Alpha_;
366  double Gamma_;
368  int NumSweeps_;
370  bool IsParallel_;
372  bool HaveOAZBoundaries_;
374  bool UseInterprocDamping_;
376  bool UseGlobalDamping_;
378  double LambdaMax_;
380  double LambdaMaxBoost_;
382  int PowerMethodIters_;
383 
385  mutable int NumApplyInverse_;
387  double InitializeTime_;
389  double ComputeTime_;
391  mutable double ApplyInverseTime_;
393  double ComputeFlops_;
395  mutable double ApplyInverseFlops_;
397  mutable Epetra_Time Time_;
398 
399 };
400 #else
401 #endif
402 #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().