ShyLU  Version of the Day
shylu_amesos_schur_operator.h
1 
2 //@HEADER
3 // ************************************************************************
4 //
5 // ShyLU: Hybrid preconditioner package
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
39 //
40 // ************************************************************************
41 //@HEADER
42 
51 #ifndef IFPACK_AMESOS2_H
52 #define IFPACK_AMESOS2_H
53 
54 #include <assert.h>
55 #include <iostream>
56 #include <sstream>
57 
58 #include "ShyLUCore_config.h"
59 
60 // Epetra includes
61 #ifdef HAVE_SHYLUCORE_MPI
62 # include "Epetra_MpiComm.h"
63 #endif // HAVE_SHYLUCORE_MPI
64 #include "Epetra_SerialComm.h"
65 #include "Epetra_Time.h"
66 #include "Epetra_CrsMatrix.h"
67 #include "Epetra_MultiVector.h"
68 #include "Epetra_LinearProblem.h"
69 #include "Epetra_Operator.h"
70 
71 // Amesos includes
72 #include "Amesos.h"
73 #include "Amesos_BaseSolver.h"
74 
75 using namespace std;
76 
77 class AmesosSchurOperator: public Epetra_Operator
78 {
79  public:
80  // @{ Constructors and destructors.
82  AmesosSchurOperator(Epetra_CrsMatrix* A);
83 
86  {
87  Destroy();
88  }
89 
90  // @}
91  // @{ Construction methods
92 
94  int Initialize();
95 
97  bool IsInitialized() const
98  {
99  return(IsInitialized_);
100  }
101 
103  int Compute();
104 
106  bool IsComputed() const
107  {
108  return(IsComputed_);
109  }
110 
112  /* This method is only available if the Teuchos package is enabled.
113  This method recognizes four parameter names: relax_value,
114  absolute_threshold, relative_threshold and overlap_mode. These names are
115  case insensitive, and in each case except overlap_mode, the ParameterEntry
116  must have type double. For overlap_mode, the ParameterEntry must have
117  type Epetra_CombineMode.
118  */
119  int SetParameters(Teuchos::ParameterList& parameterlist);
120 
121  int SetUseTranspose(bool UseTranspose_in) {
122  UseTranspose_ = UseTranspose_in;
123  return(0);
124  };
125 
127  bool UseTranspose() const {return(UseTranspose_);};
128 
129 
130 
131 
132  // @}
133 
134  // @{ Mathematical functions.
135  // Applies the matrix to X, returns the result in Y.
136  int Apply(const Epetra_MultiVector& X,
137  Epetra_MultiVector& Y) const
138  {
139  return(Multiply(false,X,Y));
140  }
141 
142  int Multiply(bool Trans, const Epetra_MultiVector& X,
143  Epetra_MultiVector& Y) const{return A_->Multiply(Trans,X,Y);}
144 
146 
154  int ApplyInverse(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
155 
157  double Condest() const
158  {
159  return(-1.0);
160  }
161 
162  // @}
163  // @{ Query methods
164 
166  const char* Label() const {return(Label_);}
167 
169  int SetLabel(const char* Label_in)
170  {
171  strcpy(Label_,Label_in);
172  return(0);
173  }
174 
175 
177  double NormInf() const {return(0.0);};
178 
180  bool HasNormInf() const {return(false);};
181 
183  const Epetra_Map & OperatorDomainMap() const {return(A_->OperatorDomainMap());};
184 
186  const Epetra_Map & OperatorRangeMap() const{return(A_->OperatorRangeMap());};
187 
189  const Epetra_Comm & Comm() const{return(A_->Comm());};
190 
192  const Epetra_RowMatrix& Matrix() const
193  {
194  return(*A_);
195  }
196 
198  virtual ostream& Print(ostream& os) const;
199 
201  virtual int NumInitialize() const
202  {
203  return(NumInitialize_);
204  }
205 
207  virtual int NumCompute() const
208  {
209  return(NumCompute_);
210  }
211 
213  virtual int NumApplyInverse() const
214  {
215  return(NumApplyInverse_);
216  }
217 
219  virtual double InitializeTime() const
220  {
221  return(InitializeTime_);
222  }
223 
225  virtual double ComputeTime() const
226  {
227  return(ComputeTime_);
228  }
229 
231  virtual double ApplyInverseTime() const
232  {
233  return(ApplyInverseTime_);
234  }
235 
237  virtual double InitializeFlops() const
238  {
239  return(0.0);
240  }
241 
242  virtual double ComputeFlops() const
243  {
244  return(ComputeFlops_);
245  }
246 
247  virtual double ApplyInverseFlops() const
248  {
249  return(ApplyInverseFlops_);
250  }
251 
252  private:
253 
254  // @}
255  // @{ Private methods
256 
259  Time_(RHS.Comm())
260  {}
261 
263  AmesosSchurOperator& operator=(const AmesosSchurOperator& RHS)
264  {
265  return(*this);
266  }
267 
269  void Destroy();
270 
272  int NumGlobalRows() const {return(A_->NumGlobalRows());};
273 
275  int NumGlobalCols() const {return(A_->NumGlobalCols());};
276 
278  int NumMyRows() const {return(A_->NumMyRows());};
279 
281  int NumMyCols() const {return(A_->NumMyCols());};
282 
283  // @}
284  // @{ Internal data
285 
287  Epetra_CrsMatrix *A_;
288 
289  Teuchos::ParameterList List_;
290 
291  Teuchos::RCP<Epetra_LinearProblem> LP_; // Local problem to solve Sbar
292  Teuchos::RCP<Amesos_BaseSolver> Solver_; // Local solver for Sbar
293 
294  bool UseTranspose_;
295 
296  // double Condest_; // unused
297 
298  bool IsParallel_;
300  bool IsInitialized_;
302  bool IsComputed_;
304  char Label_[160];
306  int NumInitialize_;
308  int NumCompute_;
309 
311  mutable int NumApplyInverse_;
313  double InitializeTime_;
315  double ComputeTime_;
317  mutable double ApplyInverseTime_;
319  double ComputeFlops_;
321  mutable double ApplyInverseFlops_;
323  mutable Epetra_Time Time_;
324  // @}
325 
326 };
327 
328 #endif /* IFPACK_AMESOS2_H */
const Epetra_Comm & Comm() const
Returns the Epetra_BlockMap object associated with the range of this matrix operator.
virtual double ApplyInverseTime() const
Returns the time spent in ApplyInverse().
bool UseTranspose() const
Returns the current UseTranspose setting.
const Epetra_Map & OperatorDomainMap() const
Returns the Epetra_Map object associated with the domain of this operator.
double NormInf() const
Returns 0.0 because this class cannot compute Inf-norm.
virtual double ComputeTime() const
Returns the time spent in Compute().
bool HasNormInf() const
Returns false because this class cannot compute an Inf-norm.
virtual int NumCompute() const
Returns the number of calls to Compute().
const Epetra_Map & OperatorRangeMap() const
Returns the Epetra_Map object associated with the range of this operator.
virtual int NumApplyInverse() const
Returns the number of calls to ApplyInverse().
virtual int NumInitialize() const
Returns the number of calls to Initialize().
bool IsComputed() const
If factor is completed, this query returns true, otherwise it returns false.
double Condest() const
Returns the computed estimated condition number, or -1.0 if not computed.
const char * Label() const
Returns a character string describing the operator.
virtual double InitializeTime() const
Returns the time spent in Initialize().
bool IsInitialized() const
Returns true if the preconditioner has been successfully initialized.
virtual double InitializeFlops() const
Returns the number of flops in the initialization phase.
const Epetra_RowMatrix & Matrix() const
Returns a reference to the matrix to be preconditioned.
int SetLabel(const char *Label_in)
Sets label for this object.