IFPACK  Development
 All Classes Namespaces Files Functions Variables Enumerations Friends Pages
Ifpack_IHSS.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_IHSS_H
44 #define IFPACK_IHSS_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 
65 
66 namespace Teuchos {
67  class ParameterList;
68 }
69 
71 
79 class Ifpack_IHSS: public Ifpack_Preconditioner {
80 
81 public:
82  // @{ Constructors and destructors.
84 
86  Ifpack_IHSS(Epetra_RowMatrix* A);
87 
89  ~Ifpack_IHSS()
90  {
91  Destroy();
92  }
93 
94  // @}
95  // @{ Construction methods
96 
98  int Initialize();
99 
101  bool IsInitialized() const
102  {
103  return(IsInitialized_);
104  }
105 
107 
109  int Compute();
110 
112  bool IsComputed() const
113  {
114  return(IsComputed_);
115  }
116 
118  /* This method is only available if the Teuchos package is enabled.
119  This method recognizes four parameter names: relax_value,
120  absolute_threshold, relative_threshold and overlap_mode. These names are
121  case insensitive, and in each case except overlap_mode, the ParameterEntry
122  must have type double. For overlap_mode, the ParameterEntry must have
123  type Epetra_CombineMode.
124  */
125  int SetParameters(Teuchos::ParameterList& parameterlist);
126 
128 
137  int SetUseTranspose(bool UseTranspose_in) {UseTranspose_ = UseTranspose_in; return(0);};
138  // @}
139 
140  // @{ Mathematical functions.
141  // Applies the matrix to X, returns the result in Y.
142  int Apply(const Epetra_MultiVector& X,
143  Epetra_MultiVector& Y) const
144  {
145  return(Multiply(false,X,Y));
146  }
147 
148  int Multiply(bool Trans, const Epetra_MultiVector& X,
149  Epetra_MultiVector& Y) const{return A_->Multiply(Trans,X,Y);}
150 
152 
165  int ApplyInverse(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
166 
168  double Condest(const Ifpack_CondestType CT = Ifpack_Cheap,
169  const int MaxIters = 1550,
170  const double Tol = 1e-9,
171  Epetra_RowMatrix* Matrix_in = 0);
172 
174  double Condest() const
175  {
176  return(Condest_);
177  }
178 
179  // @}
180  // @{ Query methods
181 
183  const char* Label() const {return(Label_);}
184 
186  int SetLabel(const char* Label_in)
187  {
188  strcpy(Label_,Label_in);
189  return(0);
190  }
191 
193  double NormInf() const {return(0.0);};
194 
196  bool HasNormInf() const {return(false);};
197 
199  bool UseTranspose() const {return(UseTranspose_);};
200 
202  const Epetra_Map & OperatorDomainMap() const {return(A_->OperatorDomainMap());};
203 
205  const Epetra_Map & OperatorRangeMap() const{return(A_->OperatorRangeMap());};
206 
208  const Epetra_Comm & Comm() const{return(A_->Comm());};
209 
211  const Epetra_RowMatrix& Matrix() const
212  {
213  return(*A_);
214  }
215 
217  virtual std::ostream& Print(std::ostream& os) const;
218 
220  virtual int NumInitialize() const
221  {
222  return(NumInitialize_);
223  }
224 
226  virtual int NumCompute() const
227  {
228  return(NumCompute_);
229  }
230 
232  virtual int NumApplyInverse() const
233  {
234  return(NumApplyInverse_);
235  }
236 
238  virtual double InitializeTime() const
239  {
240  return(InitializeTime_);
241  }
242 
244  virtual double ComputeTime() const
245  {
246  return(ComputeTime_);
247  }
248 
250  virtual double ApplyInverseTime() const
251  {
252  return(ApplyInverseTime_);
253  }
254 
256  virtual double InitializeFlops() const
257  {
258  return(0.0);
259  }
260 
261  virtual double ComputeFlops() const
262  {
263  return(ComputeFlops_);
264  }
265 
266  virtual double ApplyInverseFlops() const
267  {
268  return(ApplyInverseFlops_);
269  }
270 
271 private:
272 
273  // @}
274  // @{ Private methods
275 
277  Ifpack_IHSS(const Ifpack_IHSS& RHS) :
278  Time_(RHS.Comm())
279  {}
280 
282  Ifpack_IHSS& operator=(const Ifpack_IHSS& /* RHS */)
283  {
284  return(*this);
285  }
286 
288  void Destroy();
289 
291 
301  int Solve(bool Trans, const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
302 
303 
304 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
305  int NumGlobalRows() const {return(A_->NumGlobalRows());};
307 
309  int NumGlobalCols() const {return(A_->NumGlobalCols());};
310 #endif
311  long long NumGlobalRows64() const {return(A_->NumGlobalRows64());};
312  long long NumGlobalCols64() const {return(A_->NumGlobalCols64());};
313 
315  int NumMyRows() const {return(A_->NumMyRows());};
316 
318  int NumMyCols() const {return(A_->NumMyCols());};
319 
321  int PowerMethod(Epetra_Operator * Op,const int MaximumIterations, double& lambda_max);
322 
324  /* Epetra_RowMatrix& Matrix()
325  {
326  return(*A_);
327  }*/
328 
329  // @}
330  // @{ Internal data
331 
333  Teuchos::RefCountPtr<Epetra_CrsMatrix> A_;
334  Teuchos::RefCountPtr<Epetra_RowMatrix> Aherm_;
335  Teuchos::RefCountPtr<Epetra_RowMatrix> Askew_;
336  Teuchos::RefCountPtr<Ifpack_Preconditioner> Pherm_;
337  Teuchos::RefCountPtr<Ifpack_Preconditioner> Pskew_;
338 
339  Teuchos::ParameterList List_;
340 
341  bool UseTranspose_;
342  double Condest_;
343 
344 
346  bool IsInitialized_;
348  bool IsComputed_;
350  char Label_[160];
352  int NumInitialize_;
354  int NumCompute_;
355 
357  int EigMaxIters_;
359  double EigRatio_;
361  double LambdaMax_;
363  double Alpha_;
365  int NumSweeps_;
366 
367 
368 
370  mutable int NumApplyInverse_;
372  double InitializeTime_;
374  double ComputeTime_;
376  mutable double ApplyInverseTime_;
378  double ComputeFlops_;
380  mutable double ApplyInverseFlops_;
382  mutable Epetra_Time Time_;
383 
384 };
385 #else
386 
387 #ifdef _MSC_VER
388 #pragma message("No EpetraEXT")
389 #else
390 #warning "No EpetraEXT"
391 #endif
392 
393 #endif
394 #endif /* IFPACK_IHSS_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().