LifeV
PreconditionerComposition.hpp
Go to the documentation of this file.
1 //@HEADER
2 /*
3 ************************************************************************
4 
5  This file is part of the LifeV Applications.
6  Copyright (C) 2001-2010 EPFL, Politecnico di Milano, INRIA
7 
8  This library is free software; you can redistribute it and/or modify
9  it under the terms of the GNU Lesser General Public License as
10  published by the Free Software Foundation; either version 2.1 of the
11  License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public
19  License along with this library; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21  USA
22 
23 ************************************************************************
24 */
25 //@HEADER
26 
27 /*!
28  @file
29  @brief This file contains the PreconditionerComposition class.
30 
31  @author Gwenol Grandperrin <gwenol.grandperrin@epfl.ch>
32  @date 30-11-2010
33 
34  The class provides an efficient way of dealing with preconditioner
35  composed as a multiplication of matrices.
36  */
37 
38 #ifndef PRECONDITIONERCOMPOSITION_HPP
39 #define PRECONDITIONERCOMPOSITION_HPP 1
40 
41 #include <vector>
42 #include <boost/shared_ptr.hpp>
43 
44 #include <Teuchos_ParameterList.hpp>
45 
46 #include <lifev/core/LifeV.hpp>
47 #include <lifev/core/algorithm/Preconditioner.hpp>
48 #include <lifev/core/algorithm/ComposedOperator.hpp>
49 #include <lifev/core/array/MapEpetra.hpp>
50 #include <lifev/core/array/VectorBlockStructure.hpp>
51 
52 namespace LifeV
53 {
54 
55 //! PreconditionerComposition - Class to manage preconditioners composed by matrices multiplication.
56 /*!
57  @author Gwenol Grandperrin
58 
59  This class makes use of ComposedOperator to handle matrices composition.
60  */
62  public Preconditioner
63 {
64 public:
65 
66  //! @name Public Types
67  //@{
72  typedef ComposedOperator<operator_Type> prec_Type;
74 
77 
79  //@}
80 
81 
82  //! @name Constructor & Destructor
83  //@{
84 
85  //! Constructor
86  /*!
87  @param comm Communicator (std::shared_ptr<Epetra_Comm>() by default)
88  */
89 #ifdef HAVE_MPI
91 #else
92  PreconditionerComposition ( std::shared_ptr<Epetra_Comm> comm = std::shared_ptr<Epetra_Comm> ( new Epetra_SerialComm ) );
93 #endif
94 
95 private:
96 
97  //! Copy constructor
98  /*!
99  @param precComp PreconditionerComposition
100  */
102 
103 public:
104  //! Destructor
106 
107  //@}
108 
109  //! @name Methods
110  //@{
111 
112  virtual void createParametersList ( list_Type& list,
113  const GetPot& dataFile,
114  const std::string& section,
115  const std::string& subSection ) = 0;
116 
117  //! Build the preconditioner
118  /*!
119  @param A the base matrix for computing the preconditioner
120  */
121  virtual int buildPreconditioner ( matrixPtr_Type& A ) = 0;
122 
123  //! Reset the preconditioner
124  void resetPreconditioner();
125 
126  //! Return an estimation of the conditionement number of the preconditioner
127  Real condest();
128 
129  //@}
130 
131  //! @name Epetra Operator Interface Methods
132  //@{
133 
134  Int SetUseTranspose ( const bool useTranspose = false );
135 
136  Int Apply ( const Epetra_MultiVector& X, Epetra_MultiVector& Y ) const;
137 
138  Int ApplyInverse ( const Epetra_MultiVector& X, Epetra_MultiVector& Y ) const;
139 
140  bool UseTranspose();
141 
142  const Epetra_Map& OperatorRangeMap() const;
143 
144  const Epetra_Map& OperatorDomainMap() const;
145 
146  //@}
147 
148  //! @name Set Methods
149  //@{
150 
151  //! Setter using GetPot
152  /*!
153  This method use GetPot to load data from a file and then set
154  the preconditioner.
155  @param dataFile is a GetPot dataFile
156  @param section is the section containing the data
157  */
158  virtual void setDataFromGetPot ( const GetPot& dataFile,
159  const std::string& section ) = 0;
160 
161  //! Method to setup the solver using Teuchos::ParameterList
162  /*!
163  @param list Teuchos::ParameterList object
164  */
165  virtual void setParameters ( Teuchos::ParameterList& list ) = 0;
166 
167  /*!
168  copies the shared_ptr to the communicator in the member M_comm and builds a new instance
169  */
170  void setComm ( std::shared_ptr<Epetra_Comm> comm );
171 
172  //@}
173 
174  //! @name Get Methods
175  //@{
176 
177  //! Preconditioner is set?
178  /*!
179  * @return true
180  */
181  bool isPreconditionerSet() const;
182 
183  /** Get a standard pointer to the preconditioner. In most of the cases is more safe to use getPrecPtr(), which
184  returns a std::shared_ptr*/
186 
187  /** get a std::shared_ptr to the preconditioner. The only requirement on the preconditioner is that
188  it must derive from the Epetra_Operator object*/
190 
191  //! Return the type name of the preconditioner.
192  /*!
193  * @return type of the preconditioner
194  */
195  virtual std::string preconditionerType();
196 
197  //! Return the number of operators in the composition
198  UInt numOperators() const;
199 
200  //@}
201 
202 protected:
203 
204  //! @name Private Methods
205  //@{
206 
207  //! Add A to the right of the composition
208  int pushBack ( matrixPtr_Type A,
209  const bool useInverse = false,
210  const bool useTranspose = false );
211 
212  int pushBack ( operatorPtr_Type oper,
213  const bool useInverse = false,
214  const bool useTranspose = false,
215  matrixPtr_Type baseMatrix = matrixPtr_Type() );
216 
217  //! Use a preconditioner to build the inverse of A and add it to the right of the composition
218  int pushBack ( matrixPtr_Type A,
219  superPtr_Type preconditioner,
220  const bool useInverse = false,
221  const bool useTranspose = false );
222 
223  //! Use a preconditioner to build the inverse of A and add it to the right of the composition
224  int pushBack ( matrixPtr_Type embeddedA,
225  superPtr_Type preconditioner,
226  const VectorBlockStructure& blockStructure,
227  const UInt& blockIndex,
228  const MapEpetra& fullMap,
229  const bool useInverse = false,
230  const bool useTranspose = false,
231  const bool buildPreconditioner = true );
232 
233  int pushBack ( operatorPtr_Type embeddedOperator,
234  const VectorBlockStructure& blockStructure,
235  const UInt& blockIndex,
236  const MapEpetra& fullMap,
237  const bool useInverse,
238  const bool useTranspose );
239 
240  //@}
241 
243 
244 private:
247 };
248 
249 } // Namespace LifeV
250 
251 #endif /* PRECONDITIONERCOMPOSITION_HPP */
std::shared_ptr< super_Type > superPtr_Type
std::shared_ptr< Epetra_Comm > M_comm
int pushBack(matrixPtr_Type A, const bool useInverse=false, const bool useTranspose=false)
Add A to the right of the composition.
bool isPreconditionerSet() const
Preconditioner is set?
std::shared_ptr< prec_Type > precPtr_Type
std::shared_ptr< operator_Type > operatorPtr_Type
operator_Type * preconditioner()
Get a standard pointer to the preconditioner.
void importFromHDF5(std::string const &fileName, std::string const &matrixName="matrix")
Read a matrix from a HDF5 (.h5) file.
VectorBlockStructure - class representing the structure of a vector.
virtual std::string preconditionerType()
Return the type name of the preconditioner.
Int SetUseTranspose(const bool useTranspose=false)
Set the matrix to be used transposed (or not)
void resetPreconditioner()
Reset the preconditioner.
int32_type Int
Generic integer data.
Definition: LifeV.hpp:188
Int ApplyInverse(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Apply the inverse of the preconditioner on vector1 and store the result in vector2.
int pushBack(operatorPtr_Type embeddedOperator, const VectorBlockStructure &blockStructure, const UInt &blockIndex, const MapEpetra &fullMap, const bool useInverse, const bool useTranspose)
void updateInverseJacobian(const UInt &iQuadPt)
virtual void setParameters(Teuchos::ParameterList &list)=0
Method to setup the solver using Teuchos::ParameterList.
const Epetra_Map & OperatorRangeMap() const
Return the Range map of the operator.
int pushBack(matrixPtr_Type A, superPtr_Type preconditioner, const bool useInverse=false, const bool useTranspose=false)
Use a preconditioner to build the inverse of A and add it to the right of the composition.
Real condest()
Return an estimation of the conditionement number of the preconditioner.
PreconditionerComposition(std::shared_ptr< Epetra_Comm > comm=std::shared_ptr< Epetra_Comm >(new Epetra_MpiComm(MPI_COMM_WORLD)))
Constructor.
int pushBack(operatorPtr_Type oper, const bool useInverse=false, const bool useTranspose=false, matrixPtr_Type baseMatrix=matrixPtr_Type())
Epetra_Import const & importer()
Getter for the Epetra_Import.
Definition: MapEpetra.cpp:394
bool UseTranspose()
Return true if the preconditioner is transposed.
ComposedOperator< operator_Type > prec_Type
virtual void createParametersList(list_Type &list, const GetPot &dataFile, const std::string &section, const std::string &subSection)=0
Create the list of parameters of the preconditioner.
double Real
Generic real data.
Definition: LifeV.hpp:175
UInt numOperators() const
Return the number of operators in the composition.
Preconditioner - Abstract preconditioner class.
virtual void setDataFromGetPot(const GetPot &dataFile, const std::string &section)=0
Setter using GetPot.
const Epetra_Map & OperatorDomainMap() const
Return the Domain map of the operator.
void setComm(std::shared_ptr< Epetra_Comm > comm)
std::shared_ptr< matrix_Type > matrixPtr_Type
operatorPtr_Type preconditionerPtr()
get a std::shared_ptr to the preconditioner.
PreconditionerComposition(const PreconditionerComposition &precComp)
Copy constructor.
virtual int buildPreconditioner(matrixPtr_Type &A)=0
Build the preconditioner.
Int Apply(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Apply the inverse of the preconditioner on vector1 and store the result in vector2.
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191
std::vector< matrixPtr_Type > M_precBaseOperators
int pushBack(matrixPtr_Type embeddedA, superPtr_Type preconditioner, const VectorBlockStructure &blockStructure, const UInt &blockIndex, const MapEpetra &fullMap, const bool useInverse=false, const bool useTranspose=false, const bool buildPreconditioner=true)
Use a preconditioner to build the inverse of A and add it to the right of the composition.