IFPACK  Development
Ifpack_CrsRiluk.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_CRSRILUK_H_
44 #define _IFPACK_CRSRILUK_H_
45 
46 #include "Ifpack_ConfigDefs.h"
47 #include "Ifpack_ScalingType.h"
48 #include "Ifpack_IlukGraph.h"
49 #include "Epetra_CompObject.h"
50 #include "Epetra_Operator.h"
51 #include "Epetra_CrsMatrix.h"
52 #include "Epetra_Object.h"
53 #include "Epetra_MultiVector.h"
54 #include "Epetra_Vector.h"
55 #include "Epetra_Map.h"
56 class Epetra_Comm;
57 class Epetra_VbrMatrix;
58 class Epetra_RowMatrix;
59 
60 #include "Teuchos_RefCountPtr.hpp"
61 
62 namespace Teuchos {
63  class ParameterList;
64 }
65 
67 
209 class Ifpack_CrsRiluk: public Epetra_Object, public Epetra_CompObject, public virtual Epetra_Operator {
210 
211  // Give ostream << function some access to private and protected data/functions.
212 
213  friend ostream& operator << (ostream& os, const Ifpack_CrsRiluk& A);
214 
215  public:
217 
222  Ifpack_CrsRiluk(const Ifpack_IlukGraph & Graph_in);
223 
225  Ifpack_CrsRiluk(const Ifpack_CrsRiluk & Matrix);
226 
228  virtual ~Ifpack_CrsRiluk();
229 
231 
237  int InitValues(const Epetra_CrsMatrix &A);
238 
240 
246  int InitValues(const Epetra_VbrMatrix &A);
247 
249  bool ValuesInitialized() const {return(ValuesInitialized_);};
250 
252  void SetRelaxValue( double RelaxValue) {RelaxValue_ = RelaxValue; return;}
253 
255  void SetAbsoluteThreshold( double Athresh) {Athresh_ = Athresh; return;}
256 
258  void SetRelativeThreshold( double Rthresh) {Rthresh_ = Rthresh; return;}
259 
261  void SetOverlapMode( Epetra_CombineMode OverlapMode) {OverlapMode_ = OverlapMode; return;}
262 
264  /* This method is only available if the Teuchos package is enabled.
265  This method recognizes four parameter names: relax_value,
266  absolute_threshold, relative_threshold and overlap_mode. These names are
267  case insensitive, and in each case except overlap_mode, the ParameterEntry
268  must have type double. For overlap_mode, the ParameterEntry must have
269  type Epetra_CombineMode.
270  */
271  int SetParameters(const Teuchos::ParameterList& parameterlist,
272  bool cerr_warning_if_unused=false);
273 
275 
283  int Factor();
284 
286  bool Factored() const {return(Factored_);};
287 
288 
289  // Mathematical functions.
290 
291 
293 
303  int Solve(bool Trans, const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
304 
306 
316  int Multiply(bool Trans, const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
317 
319 
327  int Condest(bool Trans, double & ConditionNumberEstimate) const;
328  // Attribute access functions
329 
331  double GetRelaxValue() {return RelaxValue_;}
332 
334  double GetAbsoluteThreshold() {return Athresh_;}
335 
337  double GetRelativeThreshold() {return Rthresh_;}
338 
340  Epetra_CombineMode GetOverlapMode() {return OverlapMode_;}
341 
342 
344  int NumGlobalRows() const {return(Graph().NumGlobalRows());};
345 
347  int NumGlobalCols() const {return(Graph().NumGlobalCols());};
348 
350  int NumGlobalNonzeros() const {return(L().NumGlobalNonzeros()+U().NumGlobalNonzeros());};
351 
353  virtual int NumGlobalBlockDiagonals() const {return(Graph().NumGlobalBlockDiagonals());};
354 
356  int NumMyRows() const {return(Graph().NumMyRows());};
357 
359  int NumMyCols() const {return(Graph().NumMyCols());};
360 
362  int NumMyNonzeros() const {return(L().NumMyNonzeros()+U().NumMyNonzeros());};
363 
365  virtual int NumMyBlockDiagonals() const {return(Graph().NumMyBlockDiagonals());};
366 
368  virtual int NumMyDiagonals() const {return(NumMyDiagonals_);};
369 
371  int IndexBase() const {return(Graph().IndexBase());};
372 
374  const Ifpack_IlukGraph & Graph() const {return(Graph_);};
375 
377  const Epetra_CrsMatrix & L() const {return(*L_);};
378 
380  const Epetra_Vector & D() const {return(*D_);};
381 
383  const Epetra_CrsMatrix & U() const {return(*U_);};
384 
386 
388  const char * Label() const {return(Epetra_Object::Label());};
389 
391 
400  int SetUseTranspose(bool UseTranspose_in) {UseTranspose_ = UseTranspose_in; return(0);};
401 
403 
414  int Apply(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const {
415  return(Multiply(Ifpack_CrsRiluk::UseTranspose(), X, Y));};
416 
418 
431  int ApplyInverse(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const {
432  return(Solve(Ifpack_CrsRiluk::UseTranspose(), X, Y));};
433 
435  double NormInf() const {return(0.0);};
436 
438  bool HasNormInf() const {return(false);};
439 
441  bool UseTranspose() const {return(UseTranspose_);};
442 
444  const Epetra_Map & OperatorDomainMap() const {return(U_->OperatorDomainMap());};
445 
447  const Epetra_Map & OperatorRangeMap() const{return(L_->OperatorRangeMap());};
448 
450  const Epetra_Comm & Comm() const{return(Comm_);};
452 
453  protected:
454  void SetFactored(bool Flag) {Factored_ = Flag;};
455  void SetValuesInitialized(bool Flag) {ValuesInitialized_ = Flag;};
456  bool Allocated() const {return(Allocated_);};
457  int SetAllocated(bool Flag) {Allocated_ = Flag; return(0);};
458  int BlockGraph2PointGraph(const Epetra_CrsGraph & BG, Epetra_CrsGraph & PG, bool Upper);
459 
460  private:
461 
462 
463  int AllocateCrs();
464  int AllocateVbr();
465  int InitAllValues(const Epetra_RowMatrix & A, int MaxNumEntries);
466  int BlockMap2PointMap(const Epetra_BlockMap & BlockMap, Teuchos::RefCountPtr<Epetra_Map>* PointMap);
467  int GenerateXY(bool Trans,
468  const Epetra_MultiVector& Xin, const Epetra_MultiVector& Yin,
469  Teuchos::RefCountPtr<Epetra_MultiVector>* Xout,
470  Teuchos::RefCountPtr<Epetra_MultiVector>* Yout) const;
471  bool UserMatrixIsVbr_;
472  bool UserMatrixIsCrs_;
473  bool IsOverlapped_;
474  const Ifpack_IlukGraph & Graph_;
475  Teuchos::RefCountPtr<Epetra_Map> IlukRowMap_;
476  Teuchos::RefCountPtr<Epetra_Map> IlukDomainMap_;
477  Teuchos::RefCountPtr<Epetra_Map> IlukRangeMap_;
478  Teuchos::RefCountPtr<const Epetra_Map> U_DomainMap_;
479  Teuchos::RefCountPtr<const Epetra_Map> L_RangeMap_;
480  const Epetra_Comm & Comm_;
481  Teuchos::RefCountPtr<Epetra_CrsMatrix> L_;
482  Teuchos::RefCountPtr<Epetra_CrsMatrix> U_;
483  Teuchos::RefCountPtr<Epetra_CrsGraph> L_Graph_;
484  Teuchos::RefCountPtr<Epetra_CrsGraph> U_Graph_;
485  Teuchos::RefCountPtr<Epetra_Vector> D_;
486  bool UseTranspose_;
487 
488  int NumMyDiagonals_;
489  bool Allocated_;
490  bool ValuesInitialized_;
491  bool Factored_;
492  double RelaxValue_;
493  double Athresh_;
494  double Rthresh_;
495  mutable double Condest_;
496 
497  mutable Teuchos::RefCountPtr<Epetra_MultiVector> OverlapX_;
498  mutable Teuchos::RefCountPtr<Epetra_MultiVector> OverlapY_;
499  mutable Teuchos::RefCountPtr<Epetra_MultiVector> VbrX_;
500  mutable Teuchos::RefCountPtr<Epetra_MultiVector> VbrY_;
501  Epetra_CombineMode OverlapMode_;
502 
503 
504 };
505 
507 ostream& operator << (ostream& os, const Ifpack_CrsRiluk& A);
508 
509 #endif /* _IFPACK_CRSRILUK_H_ */
double GetRelaxValue()
Get RILU(k) relaxation parameter.
int NumMyNonzeros() const
Returns the number of nonzero entries in the local graph.
Ifpack_CrsRiluk: A class for constructing and using an incomplete lower/upper (ILU) factorization of ...
Epetra_CombineMode GetOverlapMode()
Get overlap mode type.
double NormInf() const
Returns 0.0 because this class cannot compute Inf-norm.
const Epetra_CrsMatrix & L() const
Returns the address of the L factor associated with this factored matrix.
const char * Label() const
Returns a character string describing the operator.
const Epetra_Map & OperatorRangeMap() const
Returns the Epetra_Map object associated with the range of this operator.
void SetOverlapMode(Epetra_CombineMode OverlapMode)
Set overlap mode type.
Ifpack_IlukGraph: A class for constructing level filled graphs for use with ILU(k) class precondition...
int NumGlobalCols() const
Returns the number of global matrix columns.
void SetAbsoluteThreshold(double Athresh)
Set absolute threshold value.
const Epetra_Comm & Comm() const
Returns the Epetra_BlockMap object associated with the range of this matrix operator.
void SetRelativeThreshold(double Rthresh)
Set relative threshold value.
int ApplyInverse(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Returns the result of a Epetra_Operator inverse applied to an Epetra_MultiVector X in Y...
Ifpack_ScalingType enumerable type.
const Epetra_Map & OperatorDomainMap() const
Returns the Epetra_Map object associated with the domain of this operator.
int NumMyCols() const
Returns the number of local matrix columns.
int NumGlobalRows() const
Returns the number of global matrix rows.
const Epetra_CrsMatrix & U() const
Returns the address of the L factor associated with this factored matrix.
double GetAbsoluteThreshold()
Get absolute threshold value.
virtual int NumGlobalBlockDiagonals() const
Returns the number of diagonal entries found in the global input graph.
int Apply(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Returns the result of a Epetra_Operator applied to a Epetra_MultiVector X in Y.
int IndexBase() const
Returns the index base for row and column indices for this graph.
int NumGlobalNonzeros() const
Returns the number of nonzero entries in the global graph.
bool HasNormInf() const
Returns false because this class cannot compute an Inf-norm.
bool Factored() const
If factor is completed, this query returns true, otherwise it returns false.
int NumMyRows() const
Returns the number of local matrix rows.
bool ValuesInitialized() const
If values have been initialized, this query returns true, otherwise it returns false.
void SetRelaxValue(double RelaxValue)
Set RILU(k) relaxation parameter.
const Epetra_Vector & D() const
Returns the address of the D factor associated with this factored matrix.
bool UseTranspose() const
Returns the current UseTranspose setting.
double GetRelativeThreshold()
Get relative threshold value.
int SetUseTranspose(bool UseTranspose_in)
If set true, transpose of this operator will be applied.
virtual int NumMyBlockDiagonals() const
Returns the number of diagonal entries found in the local input graph.
virtual int NumMyDiagonals() const
Returns the number of nonzero diagonal values found in matrix.
const Ifpack_IlukGraph & Graph() const
Returns the address of the Ifpack_IlukGraph associated with this factored matrix. ...