Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_PCEAnasaziKL.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Stokhos Package
4 //
5 // Copyright 2009 NTESS and the Stokhos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #include "Stokhos_PCEAnasaziKL.hpp"
11 #ifdef HAVE_STOKHOS_ANASAZI
12 
13 #include "AnasaziBlockKrylovSchurSolMgr.hpp"
14 #include "AnasaziBasicSort.hpp"
15 
16 Stokhos::PCEAnasaziKL::
17 PCEAnasaziKL(const Stokhos::VectorOrthogPoly<Epetra_Vector>& X_poly,
18  int num_KL_) :
19  covOp(Teuchos::rcp(new Stokhos::PCECovarianceOp(X_poly))),
20  num_KL(num_KL_)
21 {
22 }
23 
24 Stokhos::PCEAnasaziKL::
25 PCEAnasaziKL(const Teuchos::RCP<const EpetraExt::BlockVector>& X,
27  int num_KL_) :
28  covOp(Teuchos::rcp(new Stokhos::PCECovarianceOp(X, basis))),
29  num_KL(num_KL_)
30 {
31 }
32 
33 Stokhos::PCEAnasaziKL::
34 PCEAnasaziKL(const Teuchos::RCP<const Epetra_MultiVector>& X,
36  int num_KL_) :
37  covOp(Teuchos::rcp(new Stokhos::PCECovarianceOp(X, basis))),
38  num_KL(num_KL_)
39 {
40 }
41 
43 Stokhos::PCEAnasaziKL::
44 getDefaultParams() const
45 {
47 
48  params.set("Verbosity",
49  Anasazi::FinalSummary +
50  //Anasazi::TimingDetails +
51  Anasazi::Errors +
52  Anasazi::Warnings);
53  params.set("Which", "LM");
54  params.set("Block Size", 1);
55  params.set("Num Blocks", 3*num_KL);
56  params.set("Step Size", 5);
57  params.set("Maximum Restarts", 1);
58  params.set("Convergence Tolerance", 1e-12);
59 
60  return params;
61 }
62 
63 bool
64 Stokhos::PCEAnasaziKL::
65 computeKL(Teuchos::ParameterList& anasazi_params)
66 {
67  // Create an Epetra_MultiVector for an initial vector to start the solver.
68  // Note: This needs to have the same number of columns as the blocksize.
70  Teuchos::rcp(new Epetra_MultiVector(covOp->CoeffMap(),
71  anasazi_params.get<int>("Block Size")));
72  ivec->SetSeed(1);
73  ivec->Random();
74 
75  // Create the eigenproblem.
76  anasazi_problem =
77  Teuchos::rcp(new Anasazi::BasicEigenproblem<ScalarType,MV,OP>(covOp, ivec));
78 
79  // Inform the eigenproblem that the operator A is symmetric
80  anasazi_problem->setHermitian(true);
81 
82  // Set the number of eigenvalues requested
83  anasazi_problem->setNEV(num_KL);
84 
85  // Inform the eigenproblem that you are finishing passing it information
86  anasazi_problem->setProblem();
87 
88  // Initialize the Block Arnoldi solver
89  Anasazi::BlockKrylovSchurSolMgr<ScalarType,MV,OP> solverMgr(anasazi_problem,
90  anasazi_params);
91 
92  // Solve the problem to the specified tolerances or length
93  Anasazi::ReturnType returnCode = solverMgr.solve();
94 
95  // Check convergence
96  bool result = true;
97  if (returnCode != Anasazi::Converged) {
98  result = false;
99  }
100 
101  // Get solution
102  sol = anasazi_problem->getSolution();
103 
104  return result;
105 }
106 
108 Stokhos::PCEAnasaziKL::
109 getEigenvalues() const
110 {
111  Teuchos::Array<double> evals(num_KL);
112  for (int i=0; i<num_KL; i++)
113  evals[i] = std::abs(sol.Evals[i].realpart);
114  return evals;
115 }
116 
118 Stokhos::PCEAnasaziKL::
119 getEigenvectors() const
120 {
121  return sol.Evecs;
122 }
123 
124 #endif // HAVE_STOKHOS_ANASAZI
T & get(ParameterList &l, const std::string &name)
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
KOKKOS_INLINE_FUNCTION PCE< Storage > abs(const PCE< Storage > &a)