LifeV
TwoLevelPreconditioner.cpp
Go to the documentation of this file.
1 /*
2  * TwoLevelPreconditioner.cpp
3  *
4  * Created on: Oct 12, 2011
5  * Author: uvilla
6  */
7 
9 
12 
13 #include <Trilinos_version.h>
14 #include <EpetraExt_Transpose_RowMatrix.h>
15 #include <EpetraExt_MatrixMatrix.h>
16 
17 namespace LifeV
18 {
19 
20 namespace Operators
21 {
22 
25 { }
26 
28 { }
29 
31 {
32  ASSERT_PRE(M_pList.isParameter("EstensionMatrix"), "[TwoLevelPreconditioner::myCompute] pList should contain an EstensionMatrix");
33  ASSERT_PRE(M_pList.isSublist("CoarseLevel"), "[TwoLevelPreconditioner::myCompute] pList should contain a CoarseLevel sublist");
34  ASSERT_PRE(M_pList.isSublist("FineLevel"), "[TwoLevelPreconditioner::myCompute] pList should contain a FineLevel sublist");
35  ASSERT_PRE(M_rowMatrix.get() != 0, "[TwoLevelPreconditioner::myCompute] You need to SetRowMatrix first");
36 
37  rowMatrixPtr_Type E, R;
38  E = M_pList.get<rowMatrixPtr_Type>("EstensionMatrix");
39 
40  if(M_pList.isParameter("RestrictionMatrix"))
41  {
42  R = M_pList.get<rowMatrixPtr_Type>("RestrictionMatrix");
43  }
44  else
45  {
46  bool MakeDataContiguous = true;
47 #if TRILINOS_MAJOR_VERSION < 11
48  EpetraExt::RowMatrix_Transpose transposer ( MakeDataContiguous );
49 #else
50  EpetraExt::RowMatrix_Transpose transposer ( 0, !MakeDataContiguous );
51 #endif
52  R.reset( new rowMatrix_Type(dynamic_cast<rowMatrix_Type &>(transposer(*E))));
53  M_pList.set("RestricitionMatrix", R);
54  }
55 
56  rowMatrixPtr_Type AE(new rowMatrix_Type(Copy, E->RangeMap(), 0) );
57  rowMatrixPtr_Type RAE(new rowMatrix_Type(Copy, E->DomainMap(), 0) );
58  EPETRA_CHK_ERR(EpetraExt::MatrixMatrix::Multiply(*M_rowMatrix, false, *E, false, *AE));
59  EPETRA_CHK_ERR(EpetraExt::MatrixMatrix::Multiply(*R, false, *AE, false, *RAE));
60 
61  std::shared_ptr<RowMatrixPreconditioner> S(RowMatrixPreconditionerFactory::instance().createObject("Ifpack"));
62  S->SetRowMatrix(M_rowMatrix);
63  S->SetParameterList(M_pList.sublist("FineLevel"));
64  EPETRA_CHK_ERR(S->Compute());
65 
66  std::shared_ptr<ApproximatedInvertibleRowMatrix> Ac(new ApproximatedInvertibleRowMatrix);
67  Ac->SetRowMatrix(RAE);
68  Ac->SetParameterList(M_pList.sublist("CoarseLevel"));
69  EPETRA_CHK_ERR(Ac->Compute());
70 
73  prec->SetSmootherOperator(S);
76  prec->SetCoarseLevelOperator(Ac);
77 
78  M_prec.reset(prec);
79 
80  return 0;
81 }
82 
83 }
84 
85 }
void SetRestrictionOperator(const operatorPtr_Type &restrictionOper)
Set the restriction operator from the fine to coarse level.
void updateInverseJacobian(const UInt &iQuadPt)
It defines a two level methods to approximately apply the inverse of a fine level operator...
#define ASSERT_PRE(X, A)
Definition: LifeAssert.hpp:96
std::shared_ptr< rowMatrix_Type > rowMatrixPtr_Type
void SetFineLevelOperator(const operatorPtr_Type &fineLevelOper)
Set the fine level operator.
virtual int myCompute()
Abstract method myCompute implemented by the derived class.
void SetEstensionOperator(const operatorPtr_Type &estensionOper)
Set the extension operatoe from the coarse to fine level.
An operator that provides a two level approximation of the inverse of a Epetra_CsrMatrix object...
Abstract class to construct preconditioners from a matrix in Epetra_CsrFormat.