LifeV
EigenSolver.hpp
Go to the documentation of this file.
1 /* -*- mode: c++ -*-*/
2 //@HEADER
3 /*
4 *******************************************************************************
5 
6  Copyright (C) 2004, 2005, 2007 EPFL, Politecnico di Milano, INRIA
7  Copyright (C) 2010 EPFL, Politecnico di Milano, Emory University
8 
9  This file is part of LifeV.
10 
11  LifeV is free software; you can redistribute it and/or modify
12  it under the terms of the GNU Lesser General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  LifeV is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  Lesser General Public License for more details.
20 
21  You should have received a copy of the GNU Lesser General Public License
22  along with LifeV. If not, see <http://www.gnu.org/licenses/>.
23 
24 *******************************************************************************
25 */
26 //@HEADER
27 
28 /**
29  \file
30  \author Paolo Crosetto <paolo.crosetto@epfl.ch>
31  \date 2009-03-25
32  \brief Class handling an eigensolver
33  */
34 
35 
36 // #ifndef HAVE_TRILINOS_ANASAZI
37 // #warning: you should use ANASAZI
38 // #else
39 
40 // #endif
41 
42 #ifdef HAVE_TRILINOS_ANASAZI
43 
44 #ifndef EIGENSOLVER_HPP
45 #define EIGENSOLVER_HPP
46 
47 
48 #include <Epetra_MultiVector.h>
49 #include <Epetra_SerialDenseVector.h>
50 #include <Epetra_Operator.h>
51 #include <Epetra_CrsMatrix.h>
52 
53 #include <Teuchos_RefCountPtrDecl.hpp>
54 
55 #include <AnasaziBlockDavidson.hpp>
56 #include <AnasaziLOBPCG.hpp>
57 #include <AnasaziBasicOutputManager.hpp>
58 #include <AnasaziBasicSort.hpp>
59 #include <AnasaziConfigDefs.hpp>
60 #include <AnasaziBasicEigenproblem.hpp>
61 #include <AnasaziBlockKrylovSchurSolMgr.hpp>
62 #include <AnasaziLOBPCGSolMgr.hpp>
63 #include <AnasaziEpetraAdapter.hpp>
64 
65 
66 #include <lifev/core/LifeV.hpp>
67 
68 #include <lifev/core/filter/GetPot.hpp>
69 
70 namespace LifeV
71 {
72 
73 class UNDEF_EIGENSOLVER_EXCEPTION;
74 
75 // namespace Epetra
76 // {
77 
78 // template <typename DataType, typename solver_Type, typename vector_Type>
79 class EigenSolver
80 {
81  /**
82  @class
83  * class handling the Anasazi BlockKrylovSchur eigensolver. It works for any Epetra_Operator:
84  * in particular in Lifev it shuld be used with the ComposedOperator, that inherits direcly
85  * from the Epetra_Operator. Since the class ComposedOperator is templated it can contain
86  * both matrices or preconditioners. See Monolithic.cpp for an example using the ComposedOperator.
87  */
88 
89 public:
90 
91  //!@name Public Types
92  //@{
93  typedef double data_Type;
94  typedef Epetra_Operator solver_Type;
95  typedef Epetra_MultiVector vector_Type;
96 
97  typedef Anasazi::BasicEigenproblem<data_Type, vector_Type, solver_Type> eigenpb_Type;
98  typedef Teuchos::RCP<Anasazi::BasicEigenproblem<data_Type, vector_Type, solver_Type> > eigenpbPtr_Type;
99  typedef Anasazi::BlockKrylovSchurSolMgr <data_Type, vector_Type, solver_Type> eigensolver_Type;
100  typedef std::shared_ptr<eigensolver_Type> eigensolverPtr_Type;
101 
102  //@}
103  //!@name Constructor and Destructor
104  //@{
105 
106  EigenSolver (std::shared_ptr<solver_Type> const matrix, Epetra_BlockMap const& block_map, long unsigned int numvec);
107 
108  virtual ~EigenSolver()
109  {}
110 
111  //@}
112  //!@name Public Methods
113  //@{
114 
115  /**sets the parameters for the eigenproblem:
116  */
117  void setDataFromGetPot ( GetPot const& dataFile, std::string const& section/*="eigensolver"*/ );
118 
119  /** set to true if the operator is symmetric*/
120  void setHermitian (bool flag)
121  {
122  MyProblem->setHermitian (flag);
123  }
124 
125  /** fills the input vectors with the real and imaginary part of the eigenvalues*/
126  void eigenvalues (std::vector< data_Type>& realPart, std::vector< data_Type>& imgPart);
127 
128  /** solves the eigenproblem*/
129  int solve();
130  //@}
131 
132 private :
133 
134  //!@name Private Members
135  //@{
136  Teuchos::RCP<vector_Type> M_eigenVectors;
137  eigenpbPtr_Type MyProblem;
138  Teuchos::ParameterList MyPL;
139  eigensolverPtr_Type MySolver;
140  //@}
141 };
142 
143 class UNDEF_EIGENSOLVER_EXCEPTION
144 {
145 public:
146  UNDEF_EIGENSOLVER_EXCEPTION() {}
147  virtual ~UNDEF_EIGENSOLVER_EXCEPTION() {}
148 };
149 
150 }
151 #endif
152 #endif