LifeV
PreconditionerML.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 ML preconditioner
30 
31  @author Simone Deparis <simone.deparis@epfl.ch>
32  @contributor Gwenol Grandperrin <gwenol.grandperrin@epfl.ch>
33  @maintainer Gwenol Grandperrin <gwenol.grandperrin@epfl.ch>
34 
35  @date 09-11-0006
36  */
37 
38 #ifndef _MLPRECONDITIONER_HPP_
39 #define _MLPRECONDITIONER_HPP_
40 
41 #include <ml_MultiLevelPreconditioner.h>
42 
43 #include <lifev/core/LifeV.hpp>
44 
45 #include <lifev/core/filter/GetPot.hpp>
46 #include <lifev/core/array/MatrixEpetra.hpp>
47 #include <lifev/core/algorithm/Preconditioner.hpp>
48 #include <lifev/core/algorithm/PreconditionerIfpack.hpp>
49 
50 namespace LifeV
51 {
52 
53 //! PreconditionerML - Class of multilevels preconditioner
54 /*!
55  @author Simone Deparis <simone.deparis@epfl.ch>
56  @contributor Gwenol Grandperrin <gwenol.grandperrin@epfl.ch>
57  @maintainer Gwenol Grandperrin <gwenol.grandperrin@epfl.ch>
58 */
59 class PreconditionerML:
60  public Preconditioner
61 {
62 public:
63 
64  //! @name Public Types
65  //@{
66 
67  typedef Preconditioner super;
68 
69  typedef ML_Epetra::MultiLevelPreconditioner prec_raw_type;
70  typedef std::shared_ptr<prec_raw_type> prec_type;
71 
72  typedef super::operator_raw_type operator_raw_type;
73  typedef super::operator_type operator_type;
74 
75  //@}
76 
77 
78  //! @name Constructors & Destructor
79  //@{
80  //! Empty constructor.
81 #ifdef HAVE_MPI
82  PreconditionerML ( std::shared_ptr<Epetra_Comm> comm = std::shared_ptr<Epetra_Comm> ( new Epetra_MpiComm ( MPI_COMM_WORLD ) ) );
83 #else
84  PreconditionerML ( std::shared_ptr<Epetra_Comm> comm = std::shared_ptr<Epetra_Comm> ( new Epetra_SerialComm ) );
85 #endif
86 
87  //! destructor.
88  virtual ~PreconditionerML();
89 
90  //! Constructor from a matrix
91  /*!
92  @param matrix Matrix upon which construct the preconditioner
93  */
94  PreconditionerML ( operator_type& matrix );
95 
96  //@}
97 
98  //! @name Methods
99  //@{
100 
101  //! Build a preconditioner based on the given matrix
102  /*!
103  @param matrix Matrix upon which construct the preconditioner
104  */
105  Int buildPreconditioner ( operator_type& matrix );
106 
107  //! Reset the preconditioner
108  void resetPreconditioner();
109 
110  //! Create the list of parameters of the preconditioner
111  /*!
112  @param list A Parameter list to be filled
113  @param dataFile A GetPot object containing the data about the preconditioner
114  @param section The section in "dataFile" where to find data about the preconditioner
115  @param subSection The subsection in "dataFile" where to find data about the preconditioner
116  */
117  virtual void createParametersList ( list_Type& list,
118  const GetPot& dataFile,
119  const std::string& section,
120  const std::string& subSection )
121  {
122  createMLList ( list, dataFile, section, subSection, M_comm->MyPID() == 0 );
123  }
124 
125  //! Create the list of parameters of the preconditioner
126  /*!
127  @param list A Parameter list to be filled
128  @param dataFile A GetPot object containing the data about the preconditioner
129  @param section The section in "dataFile" where to find data about the preconditioner
130  @param subSection The subsection in "dataFile" where to find data about the preconditioner
131  */
132  static void createMLList ( list_Type& list,
133  const GetPot& dataFile,
134  const std::string& section,
135  const std::string& subSection = "ML",
136  const bool& verbose = true );
137 
138  //! Apply the inverse of the preconditioner on vector1 and store the result in vector2
139  /*!
140  @param vector1 Vector to which we apply the preconditioner
141  @param vector2 Vector to the store the result
142  */
143  virtual Int ApplyInverse ( const Epetra_MultiVector& vector1, Epetra_MultiVector& vector2 ) const
144  {
145  return M_preconditioner->ApplyInverse ( vector1, vector2 );
146  }
147 
148  //! Apply the preconditioner on vector1 and store the result in vector2
149  /*!
150  @param vector1 Vector to which we apply the preconditioner
151  @param vector2 Vector to the store the result
152  */
153  virtual Int Apply ( const Epetra_MultiVector& vector1, Epetra_MultiVector& vector2 ) const
154  {
155  return M_preconditioner->Apply ( vector1, vector2 );
156  }
157 
158  //! Show informations about the preconditioner
159  virtual void showMe ( std::ostream& output = std::cout ) const;
160 
161  //@}
162 
163 
164  //! @name Set Methods
165  //@{
166 
167  //! Set the data of the preconditioner using a GetPot object
168  /*!
169  @param dataFile A GetPot object containing the data about the preconditioner
170  @param section The section in "dataFile" where to find data about the preconditioner
171  */
172  void setDataFromGetPot ( const GetPot& dataFile,
173  const std::string& section );
174 
175  //! Set the matrix to be used transposed (or not)
176  /*!
177  @param useTranspose If true the preconditioner is transposed
178  */
179  Int SetUseTranspose ( bool useTranspose = false )
180  {
181  return M_preconditioner->SetUseTranspose (useTranspose);
182  }
183 
184  //! Set the coordinate to be used for the visualization of the aggregates
185  /*!
186  According to the Trilinos::ML manual one should setup the following variables in ML:
187  <ul>
188  <li> viz: enable
189  <li> viz: output format
190  <li> x-coordinates
191  <li> y-coordinates
192  <li> z-coordinates
193  </ul>
194  This is the reason why one has to provide these informations. In order to get an output of the aggregation one has to set
195  the variable /ML/visualization/enable to true in the datafile.
196  @see M.W. Gee, C.M. Siefert, J.J. Hu, R.S. Tuminaro and M.G. Sala. ML 5.0 Smoothed Aggregation User's Guide. Sandia National Laboratories, 2006
197  @param xCoord Shared pointer on a vector of the x coordinates of the vertices of the mesh
198  @param yCoord Shared pointer on a vector of the y coordinates of the vertices of the mesh
199  @param zCoord Shared pointer on a vector of the z coordinates of the vertices of the mesh
200  */
201  void setVerticesCoordinates (std::shared_ptr<std::vector<Real> > xCoord,
202  std::shared_ptr<std::vector<Real> > yCoord,
203  std::shared_ptr<std::vector<Real> > zCoord);
204 
205  //@}
206 
207 
208  //! @name Get Methods
209  //@{
210 
211  //! Return An estimation of the condition number of the preconditioner
212  Real condest ();
213 
214  //! Return a raw pointer on the preconditioner
215  super::prec_raw_type* preconditioner();
216 
217  //! Return a shared pointer on the preconditioner
218  super::prec_type preconditionerPtr()
219  {
220  return M_preconditioner;
221  }
222 
223  //! Return the type of preconditioner
224  std::string preconditionerType()
225  {
226  return M_precType;
227  }
228 
229  //! Return true if the preconditioner is transposed
230  bool UseTranspose()
231  {
232  return M_preconditioner->UseTranspose();
233  }
234 
235  //! Return the Range map of the operator
236  const Epetra_Map& OperatorRangeMap() const
237  {
238  return M_preconditioner->OperatorRangeMap();
239  }
240 
241  //! Return the Domain map of the operator
242  const Epetra_Map& OperatorDomainMap() const
243  {
244  return M_preconditioner->OperatorDomainMap();
245  }
246 
247  //@}
248 
249 protected:
250 
251  list_Type M_IfpackSubList;
252  std::shared_ptr<Epetra_Comm> M_comm;
253 
254 private:
255 
256  operator_type M_operator;
257 
258  prec_type M_preconditioner;
259 
260  bool M_analyze;
261 
262  bool M_visualizationDataAvailable;
263  std::shared_ptr<std::vector<Real> > M_xCoord;
264  std::shared_ptr<std::vector<Real> > M_yCoord;
265  std::shared_ptr<std::vector<Real> > M_zCoord;
266 
267 };
268 
269 
270 inline Preconditioner* createML()
271 {
272  return new PreconditionerML();
273 }
274 namespace
275 {
277 }
278 
279 
280 } // namespace LifeV
281 
282 #endif
int32_type Int
Generic integer data.
Definition: LifeV.hpp:188
double Real
Generic real data.
Definition: LifeV.hpp:175