Stokhos Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
Stokhos_PCEAnasaziKL.cpp
Go to the documentation of this file.
1// @HEADER
2// ***********************************************************************
3//
4// Stokhos Package
5// Copyright (2009) Sandia Corporation
6//
7// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8// license for use of this work by or on behalf of the U.S. Government.
9//
10// Redistribution and use in source and binary forms, with or without
11// modification, are permitted provided that the following conditions are
12// met:
13//
14// 1. Redistributions of source code must retain the above copyright
15// notice, this list of conditions and the following disclaimer.
16//
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// 3. Neither the name of the Corporation nor the names of the
22// contributors may be used to endorse or promote products derived from
23// this software without specific prior written permission.
24//
25// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36//
37// Questions? Contact Eric T. Phipps (etphipp@sandia.gov).
38//
39// ***********************************************************************
40// @HEADER
41
43#ifdef HAVE_STOKHOS_ANASAZI
44
45#include "AnasaziBlockKrylovSchurSolMgr.hpp"
46#include "AnasaziBasicSort.hpp"
47
48Stokhos::PCEAnasaziKL::
49PCEAnasaziKL(const Stokhos::VectorOrthogPoly<Epetra_Vector>& X_poly,
50 int num_KL_) :
51 covOp(Teuchos::rcp(new Stokhos::PCECovarianceOp(X_poly))),
52 num_KL(num_KL_)
53{
54}
55
56Stokhos::PCEAnasaziKL::
57PCEAnasaziKL(const Teuchos::RCP<const EpetraExt::BlockVector>& X,
59 int num_KL_) :
60 covOp(Teuchos::rcp(new Stokhos::PCECovarianceOp(X, basis))),
61 num_KL(num_KL_)
62{
63}
64
65Stokhos::PCEAnasaziKL::
66PCEAnasaziKL(const Teuchos::RCP<const Epetra_MultiVector>& X,
68 int num_KL_) :
69 covOp(Teuchos::rcp(new Stokhos::PCECovarianceOp(X, basis))),
70 num_KL(num_KL_)
71{
72}
73
74Teuchos::ParameterList
75Stokhos::PCEAnasaziKL::
76getDefaultParams() const
77{
78 Teuchos::ParameterList params;
79
80 params.set("Verbosity",
81 Anasazi::FinalSummary +
82 //Anasazi::TimingDetails +
83 Anasazi::Errors +
84 Anasazi::Warnings);
85 params.set("Which", "LM");
86 params.set("Block Size", 1);
87 params.set("Num Blocks", 3*num_KL);
88 params.set("Step Size", 5);
89 params.set("Maximum Restarts", 1);
90 params.set("Convergence Tolerance", 1e-12);
91
92 return params;
93}
94
95bool
96Stokhos::PCEAnasaziKL::
97computeKL(Teuchos::ParameterList& anasazi_params)
98{
99 // Create an Epetra_MultiVector for an initial vector to start the solver.
100 // Note: This needs to have the same number of columns as the blocksize.
101 Teuchos::RCP<Epetra_MultiVector> ivec =
102 Teuchos::rcp(new Epetra_MultiVector(covOp->CoeffMap(),
103 anasazi_params.get<int>("Block Size")));
104 ivec->SetSeed(1);
105 ivec->Random();
106
107 // Create the eigenproblem.
108 anasazi_problem =
109 Teuchos::rcp(new Anasazi::BasicEigenproblem<ScalarType,MV,OP>(covOp, ivec));
110
111 // Inform the eigenproblem that the operator A is symmetric
112 anasazi_problem->setHermitian(true);
113
114 // Set the number of eigenvalues requested
115 anasazi_problem->setNEV(num_KL);
116
117 // Inform the eigenproblem that you are finishing passing it information
118 anasazi_problem->setProblem();
119
120 // Initialize the Block Arnoldi solver
121 Anasazi::BlockKrylovSchurSolMgr<ScalarType,MV,OP> solverMgr(anasazi_problem,
122 anasazi_params);
123
124 // Solve the problem to the specified tolerances or length
125 Anasazi::ReturnType returnCode = solverMgr.solve();
126
127 // Check convergence
128 bool result = true;
129 if (returnCode != Anasazi::Converged) {
130 result = false;
131 }
132
133 // Get solution
134 sol = anasazi_problem->getSolution();
135
136 return result;
137}
138
139Teuchos::Array<double>
140Stokhos::PCEAnasaziKL::
141getEigenvalues() const
142{
143 Teuchos::Array<double> evals(num_KL);
144 for (int i=0; i<num_KL; i++)
145 evals[i] = std::abs(sol.Evals[i].realpart);
146 return evals;
147}
148
149Teuchos::RCP<Epetra_MultiVector>
150Stokhos::PCEAnasaziKL::
151getEigenvectors() const
152{
153 return sol.Evecs;
154}
155
156#endif // HAVE_STOKHOS_ANASAZI
Abstract base class for multivariate orthogonal polynomials.
A container class storing an orthogonal polynomial whose coefficients are vectors,...
Top-level namespace for Stokhos classes and functions.