LifeV
EigenSolver.cpp
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 #include <lifev/core/algorithm/EigenSolver.hpp>
29 
30 #ifdef HAVE_TRILINOS_ANASAZI
31 
32 
33 #include <string>
34 
35 #include <Teuchos_RefCountPtrDecl.hpp>
36 #include <Teuchos_RCPBoostSharedPtrConversions.hpp>
37 
38 
39 // ===================================================
40 //! Constructors & Destructors
41 // ===================================================
42 
43 namespace LifeV
44 {
45 EigenSolver::EigenSolver (std::shared_ptr<solver_Type> const matrix, Epetra_BlockMap const& block_map, long unsigned int numvec) :
46  M_eigenVectors (new Epetra_MultiVector (block_map, numvec) ),
47  MyProblem ( new Anasazi::BasicEigenproblem<data_Type, vector_Type, solver_Type> (Teuchos::rcp (matrix), M_eigenVectors) ),
48  MyPL(),
49  MySolver()
50 {
51 }
52 
53 
54 // ===================================================
55 //! Public Methods
56 // ===================================================
57 
58 void
59 EigenSolver::setDataFromGetPot (GetPot const& data , const std::string& section)
60 {
61  int block_size = data ( (section + "block_size").c_str(), 1);
62  int max_blocks = data ( (section + "max_blocks").c_str(), 20);
63  int max_restarts = data ( (section + "max_restarts").c_str(), 50);
64  double tol = data ( (section + "tol").c_str(), 1e-8);
65  std::string which = data ( (section + "which").c_str(), "ML");
66  int nev = data ( (section + "neval").c_str(), 10); //number of eigenvalues
67  bool verbose = data ( (section + "verbose").c_str(), true);
68 
69 
70  int verbosity = Anasazi::Errors + Anasazi::Warnings;
71  if (verbose)
72  {
73  verbosity += Anasazi::FinalSummary + Anasazi::TimingDetails;
74  }
75 #ifdef HAVE_LIFEV_DEBUG
76  bool debug = data ( (section + "debug").c_str(), true);
77 
78  if (debug)
79  {
80  verbosity += Anasazi::Debug;
81  }
82 #endif
83  //
84  // Create parameter list to pass into solver manager
85  //
86 
87  MyPL.set ( "Verbosity", verbosity );
88  MyPL.set ( "Block Size", block_size );
89  MyPL.set ( "Max Blocks", max_blocks );
90  MyPL.set ( "Max Restarts", max_restarts );
91  MyPL.set ( "Tol", tol );
92  //Teuchos::RCP<Anasazi::SortManager<Real> > MySort = Teuchos::rcp( new Anasazi::BasicSort<Real>( which.c_str() ) );
93  //MyPL.set( "Sort Manager", MySort);
94 
95  MyProblem->setNEV (nev);
96 }
97 
98 
99 void
100 EigenSolver
101 ::eigenvalues (std::vector<data_Type>& realPart, std::vector<data_Type>& imgPart)
102 {
103  Anasazi::Eigensolution<data_Type, vector_Type> sol = MyProblem->getSolution();
104  std::vector<Anasazi::Value<data_Type> > evals = sol.Evals;
105  for (UInt i = 0; i < evals.size(); ++i)
106  {
107  realPart.push_back (evals[i].realpart);
108  imgPart.push_back (evals[i].imagpart);
109  }
110 }
111 
112 int
113 EigenSolver
114 ::solve()
115 {
116  bool out = MyProblem->setProblem();
117  std::cout << "problem set: " << out << std::endl;
118  MySolver.reset (new eigensolver_Type (MyProblem, MyPL) );
119  return MySolver->solve();
120 }
121 }
122 #endif