LifeV
PreconditionerTeko.hpp
Go to the documentation of this file.
1 //@HEADER
2 /*
3 *******************************************************************************
4 
5  Copyright (C) 2004, 2005, 2007 EPFL, Politecnico di Milano, INRIA
6  Copyright (C) 2010 EPFL, Politecnico di Milano, Emory University
7 
8  This file is part of LifeV.
9 
10  LifeV is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  LifeV is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with LifeV. If not, see <http://www.gnu.org/licenses/>.
22 
23 *******************************************************************************
24 */
25 //@HEADER
26 
27 /*!
28  @file
29  @brief PreconditionerTeko
30 
31  @author Gwenol Grandperrin <gwenol.grandperrin@epfl.ch>
32  @maintainer Gwenol Grandperrin <gwenol.grandperrin@epfl.ch>
33 
34  @date 14-10-2010
35  */
36 
37 #ifndef PRECONDITIONERTEKO_HPP
38 #define PRECONDITIONERTEKO_HPP 1
39 
40 #include <lifev/core/LifeV.hpp>
41 
42 #ifdef LIFEV_HAVE_TEKO
43 
44 #include <vector>
45 #include <lifev/core/array/MapEpetra.hpp>
46 #include <lifev/core/algorithm/Preconditioner.hpp>
47 #include <lifev/core/algorithm/PreconditionerBlock.hpp>
48 
49 // Teuchos includes
50 #include "Teuchos_RCP.hpp"
51 
52 // Teko-Package includes
53 #include "Teko_Utilities.hpp"
54 #include "Teko_InverseFactory.hpp"
55 #include "Teko_InverseLibrary.hpp"
56 #include "Teko_BlockedEpetraOperator.hpp"
57 #include "Teko_EpetraBlockPreconditioner.hpp"
58 #include "Teko_BlockPreconditionerFactory.hpp"
59 #include "Teuchos_RCPBoostSharedPtrConversions.hpp"
60 
61 // for simplicity
62 using Teuchos::RCP;
63 using Teuchos::rcp;
64 
65 namespace LifeV
66 {
67 
68 //! PreconditionerTeko
69 /*!
70  * @author Gwenol Grandperrin
71  *
72  * The PreconditionerTeko class provides a wrapper for Trilinos
73  * block preconditioners implimented with the Teko package
74  */
75 class PreconditionerTeko:
76  public PreconditionerBlock
77 {
78 public:
79 
80  /** @name Typedefs
81  */
82  //@{
83  typedef Preconditioner super_Type;
84 
85  typedef Epetra_Operator operator_Type;
86  typedef std::shared_ptr<Epetra_Operator> operatorPtr_Type;
87 
88  typedef Teko::Epetra::EpetraBlockPreconditioner preconditioner_Type;
89  typedef std::shared_ptr<preconditioner_Type> preconditionerPtr_Type;
90 
91  typedef MatrixEpetra<Real> matrix_Type;
92  typedef std::shared_ptr<matrix_Type> matrixPtr_Type;
93  //@}
94 
95 
96  /** @name Constructors, destructor
97  */
98  //@{
99  //! default constructor.
100  PreconditionerTeko ( const std::shared_ptr<Epetra_Comm>& comm = std::shared_ptr<Epetra_Comm>() );
101 
102  /** Copy constructor*/
103  PreconditionerTeko ( PreconditionerTeko& P, const std::shared_ptr<Epetra_Comm>& comm = std::shared_ptr<Epetra_Comm>() );
104 
105  //! default virtual destructor
106  virtual ~PreconditionerTeko();
107 
108  //@}
109 
110 
111  /** @name Methods
112  */
113 
114  //! Return a pointer on the preconditioner
115  operator_Type* preconditioner();
116 
117  //! Return a pointer on the preconditioner
118  operatorPtr_Type preconditionerPtr();
119 
120  //! Reset the preconditioner
121  void resetPreconditioner();
122 
123  //! returns true if prec exists
124  bool isPreconditionerSet() const;
125 
126  virtual int SetUseTranspose ( const bool useTranspose = false );
127  virtual bool UseTranspose();
128  virtual int ApplyInverse ( const Epetra_MultiVector& X, Epetra_MultiVector& Y ) const;
129  virtual int Apply ( const Epetra_MultiVector& X, Epetra_MultiVector& Y ) const;
130  virtual const Epetra_Map& OperatorRangeMap() const;
131  virtual const Epetra_Map& OperatorDomainMap() const;
132 
133 protected:
134 
135  void buildBlockGIDs ( std::vector<std::vector<int> >& gids,
136  const MapEpetra& map,
137  const std::vector<int>& blockSizes);
138  void buildPreconditionerTeko ( RCP<Teko::BlockPreconditionerFactory> precFact,
139  matrixPtr_Type& oper,
140  const std::vector<int>& blockSizes );
141 
142  preconditionerPtr_Type M_prec;
143 
144 private:
145  matrix_Type::matrix_ptrtype M_oper;
146 
147 };
148 
149 } // namespace LifeV
150 
151 #endif // HAVE_LIFEV_TEKO
152 
153 #endif /* PRECONDITIONERTEKO_HPP */