LifeV
PreconditionerLSC.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 PreconditionerLSC class.
30 
31  @author Gwenol Grandperrin <gwenol.grandperrin@epfl.ch>
32  @date 08-11-2010
33  */
34 
35 #ifndef PRECONDITIONERLSC_HPP
36 #define PRECONDITIONERLSC_HPP 1
37 
38 #include <lifev/core/LifeV.hpp>
39 
40 #ifdef LIFEV_HAVE_TEKO
41 
42 #include <boost/shared_ptr.hpp>
43 
44 #include <lifev/core/filter/GetPot.hpp>
45 #include <lifev/core/array/MatrixEpetra.hpp>
46 #include <lifev/core/fem/FESpace.hpp>
47 #include <lifev/core/algorithm/PreconditionerTeko.hpp>
48 #include <lifev/core/mesh/RegionMesh.hpp>
49 
50 // Teuchos includes
51 #include <Teuchos_RCP.hpp>
52 #include <Teuchos_ParameterList.hpp>
53 
54 // Teko-Package includes
55 #include <Teko_Utilities.hpp>
56 #include <Teko_InverseFactory.hpp>
57 #include <Teko_InverseLibrary.hpp>
58 #include <Teko_BlockPreconditionerFactory.hpp>
59 #include <Teko_InvLSCStrategy.hpp>
60 #include <Teko_LSCPreconditionerFactory.hpp>
61 
62 // for simplicity
63 using Teuchos::RCP;
64 using Teuchos::rcp;
65 
66 namespace LifeV
67 {
68 
69 //! PreconditionerLSC
70 /*!
71  * @author Gwenol Grandperrin
72  *
73  * The PreconditionerLSC class provides the LSC block preconditioner
74  * available in the Teko package of Trilinos
75  */
76 class PreconditionerLSC:
77  public PreconditionerTeko
78 {
79 public:
80 
81  /** @name Public Types
82  */
83  //@{
84  typedef Preconditioner super_Type;
85 
86  typedef Teko::Epetra::EpetraBlockPreconditioner preconditioner_Type;
87  typedef std::shared_ptr<preconditioner_Type> preconditionerPtr_Type;
88  typedef RegionMesh<LinearTetra> mesh_Type;
89  typedef MapEpetra map_Type;
90  typedef std::shared_ptr<FESpace<mesh_Type, map_Type> > FESpacePtr_Type;
91  typedef MatrixEpetra<Real> matrix_Type;
92  typedef std::shared_ptr<matrix_Type> matrixPtr_Type;
93 
94  typedef Teuchos::ParameterList list_Type;
95  //@}
96 
97 
98  /** @name Constructors, destructor
99  */
100  //@{
101  //! default constructor.
102 #ifdef HAVE_MPI
103  PreconditionerLSC ( std::shared_ptr<Epetra_Comm> comm = std::shared_ptr<Epetra_Comm> ( new Epetra_MpiComm ( MPI_COMM_WORLD ) ) );
104 #else
105  PreconditionerLSC ( std::shared_ptr<Epetra_Comm> comm = std::shared_ptr<Epetra_Comm> ( new Epetra_SerialComm ) );
106 #endif
107 
108  //! constructor from matrix A.
109  //! @param A EpetraMatrix<double> matrix upon which construct the preconditioner
110  // IfpackPreconditioner( matrixPtr_Type& A );
111 
112  //! default destructor
113  virtual ~PreconditionerLSC();
114 
115  //@}
116 
117  /** @name Methods
118  */
119 
120  //! Setter using GetPot
121  /*!
122  This method use GetPot to load data from a file and then set
123  the preconditioner.
124  @param dataFile is a GetPot dataFile
125  @param section is the section containing the data
126  */
127  void setDataFromGetPot ( const GetPot& dataFile,
128  const std::string& section );
129 
130  //! Method to setup the solver using Teuchos::ParameterList
131  /*!
132  @param list Teuchos::ParameterList object
133  */
134  virtual void setParameters ( Teuchos::ParameterList& list );
135 
136  void setFESpace ( FESpacePtr_Type uFESpace,
137  FESpacePtr_Type pFESpace );
138 
139  void createParametersList ( list_Type& list,
140  const GetPot& dataFile,
141  const std::string& section,
142  const std::string& subSection = "LSC" );
143 
144  //! Return an estimation of the conditionement number of the preconditioner
145  double condest ();
146 
147  //! Return the name of the preconditioner to be used in the factory
148  std::string preconditionerType()
149  {
150  return M_precType;
151  }
152 
153  //! Build the preconditioner
154  int buildPreconditioner ( matrixPtr_Type& A );
155 
156  int numBlocksRows() const;
157  int numBlocksCols() const;
158 
159 protected:
160 
161  std::string M_precType;
162  int M_velocityBlockSize;
163  int M_pressureBlockSize;
164  std::shared_ptr<Epetra_Comm> M_comm;
165 
166 };
167 
168 inline Preconditioner* createLSC()
169 {
170  return new PreconditionerLSC();
171 }
172 namespace
173 {
174 static bool registerLSC = PRECFactory::instance().registerProduct ( "LSC", &createLSC );
175 }
176 
177 } // namespace LifeV
178 
179 #endif // LIFEV_HAVE_TEKO
180 
181 #endif /* PRECONDITIONERLSC_HPP */