/usr/include/trilinos/AnasaziSaddleOperator.hpp is in libtrilinos-anasazi-dev 12.10.1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | // @HEADER
// ***********************************************************************
//
// Anasazi: Block Eigensolvers Package
// Copyright (2004) Sandia Corporation
//
// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
// license for use of this work by or on behalf of the U.S. Government.
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
// USA
// Questions? Contact Michael A. Heroux (maherou@sandia.gov)
//
// ***********************************************************************
// @HEADER
/*! \file AnasaziSaddleOperator.hpp
* \brief An operator of the form [A Y; Y' 0] where A is a sparse matrix and Y a multivector.
*
* Used by TraceMin to solve the saddle point problem.
*/
#ifndef ANASAZI_SADDLE_OPERATOR_HPP
#define ANASAZI_SADDLE_OPERATOR_HPP
#include "AnasaziConfigDefs.hpp"
#include "AnasaziSaddleContainer.hpp"
#include "AnasaziTraceMinRitzOp.hpp"
#include "Teuchos_SerialDenseSolver.hpp"
using Teuchos::RCP;
enum PrecType {NO_PREC, NONSYM, BD_PREC, HSS_PREC};
namespace Anasazi {
namespace Experimental {
template <class ScalarType, class MV, class OP>
class SaddleOperator : public TraceMinOp<ScalarType,SaddleContainer<ScalarType,MV>,OP>
{
typedef Anasazi::MultiVecTraits<ScalarType,MV> MVT;
typedef Teuchos::SerialDenseMatrix<int,ScalarType> SerialDenseMatrix;
public:
// Default constructor
SaddleOperator( ) { };
SaddleOperator( const Teuchos::RCP<OP> A, const Teuchos::RCP<const MV> B, PrecType pt=NO_PREC, const ScalarType alpha=1. );
// Applies the saddle point operator to a "multivector"
void Apply(const SaddleContainer<ScalarType,MV>& X, SaddleContainer<ScalarType,MV>& Y) const;
void removeIndices(const std::vector<int>& indicesToRemove) { A_->removeIndices(indicesToRemove); };
private:
// A is the 1-1 block, and B the 1-2 block
Teuchos::RCP<OP> A_;
Teuchos::RCP<const MV> B_;
Teuchos::RCP<SerialDenseMatrix> Schur_;
PrecType pt_;
ScalarType alpha_;
};
// Default constructor
template <class ScalarType, class MV, class OP>
SaddleOperator<ScalarType, MV, OP>::SaddleOperator( const Teuchos::RCP<OP> A, const Teuchos::RCP<const MV> B, PrecType pt, const ScalarType alpha )
{
// Get a pointer to A and B
A_ = A;
B_ = B;
pt_ = pt;
alpha_ = alpha;
if(pt == BD_PREC)
{
// Form the Schur complement
int nvecs = MVT::GetNumberVecs(*B);
Teuchos::RCP<MV> AinvB = MVT::Clone(*B,nvecs);
Schur_ = rcp(new SerialDenseMatrix(nvecs,nvecs));
A_->Apply(*B_,*AinvB);
MVT::MvTransMv(1., *B_, *AinvB, *Schur_);
}
}
// Applies the saddle point operator to a "multivector"
template <class ScalarType, class MV, class OP>
void SaddleOperator<ScalarType, MV, OP>::Apply(const SaddleContainer<ScalarType,MV>& X, SaddleContainer<ScalarType,MV>& Y) const
{
RCP<SerialDenseMatrix> Xlower = X.getLower();
RCP<SerialDenseMatrix> Ylower = Y.getLower();
if(pt_ == NO_PREC)
{
// trans does literally nothing, because the operator is symmetric
// Y.bottom = B'X.top
MVT::MvTransMv(1., *B_, *(X.upper_), *Ylower);
// Y.top = A*X.top+B*X.bottom
A_->Apply(*(X.upper_), *(Y.upper_));
MVT::MvTimesMatAddMv(1., *B_, *Xlower, 1., *(Y.upper_));
}
else if(pt_ == NONSYM)
{
// Y.bottom = -B'X.top
MVT::MvTransMv(-1., *B_, *(X.upper_), *Ylower);
// Y.top = A*X.top+B*X.bottom
A_->Apply(*(X.upper_), *(Y.upper_));
MVT::MvTimesMatAddMv(1., *B_, *Xlower, 1., *(Y.upper_));
}
else if(pt_ == BD_PREC)
{
Teuchos::SerialDenseSolver<int,ScalarType> MySolver;
// Solve A Y.X = X.X
A_->Apply(*(X.upper_),*(Y.upper_));
// So, let me tell you a funny story about how the SerialDenseSolver destroys the original matrix...
Teuchos::RCP<SerialDenseMatrix> localSchur = Teuchos::rcp(new SerialDenseMatrix(*Schur_));
// Solve the small system
MySolver.setMatrix(localSchur);
MySolver.setVectors(Ylower, Xlower);
MySolver.solve();
}
// Hermitian-Skew Hermitian splitting has some extra requirements
// We need B'B = I, which is true for standard eigenvalue problems, but not generalized
// We also need to use gmres, because our operator is no longer symmetric
else if(pt_ == HSS_PREC)
{
// std::cout << "applying preconditioner to";
// X.MvPrint(std::cout);
// Solve (H + alpha I) Y1 = X
// 1. Apply preconditioner
A_->Apply(*(X.upper_),*(Y.upper_));
// 2. Scale by 1/alpha
*Ylower = *Xlower;
Ylower->scale(1./alpha_);
// std::cout << "H preconditioning produced";
// Y.setLower(Ylower);
// Y.MvPrint(std::cout);
// Solve (S + alpha I) Y = Y1
// 1. Y_lower = (B' Y1_upper + alpha Y1_lower) / (1 + alpha^2)
Teuchos::RCP<SerialDenseMatrix> Y1_lower = Teuchos::rcp(new SerialDenseMatrix(*Ylower));
MVT::MvTransMv(1,*B_,*(Y.upper_),*Ylower);
// std::cout << "Y'b1 " << *Ylower;
Y1_lower->scale(alpha_);
// std::cout << "alpha b2 " << *Y1_lower;
*Ylower += *Y1_lower;
// std::cout << "alpha b2 + Y'b1 " << *Ylower;
Ylower->scale(1/(1+alpha_*alpha_));
// 2. Y_upper = (Y1_upper - B Y_lower) / alpha
MVT::MvTimesMatAddMv(-1/alpha_,*B_,*Ylower,1/alpha_,*(Y.upper_));
// std::cout << "preconditioning produced";
// Y.setLower(Ylower);
// Y.MvPrint(std::cout);
}
else
{
std::cout << "Not a valid preconditioner type\n";
}
Y.setLower(Ylower);
// std::cout << "result of applying operator";
// Y.MvPrint(std::cout);
}
} // End namespace Experimental
template<class ScalarType, class MV, class OP>
class OperatorTraits<ScalarType, Experimental::SaddleContainer<ScalarType,MV>, Experimental::SaddleOperator<ScalarType,MV,OP> >
{
public:
static void Apply( const Experimental::SaddleOperator<ScalarType,MV,OP>& Op,
const Experimental::SaddleContainer<ScalarType,MV>& x,
Experimental::SaddleContainer<ScalarType,MV>& y)
{ Op.Apply( x, y); };
};
} // end namespace Anasazi
#ifdef HAVE_ANASAZI_BELOS
namespace Belos {
template<class ScalarType, class MV, class OP>
class OperatorTraits<ScalarType, Anasazi::Experimental::SaddleContainer<ScalarType,MV>, Anasazi::Experimental::SaddleOperator<ScalarType,MV,OP> >
{
public:
static void Apply( const Anasazi::Experimental::SaddleOperator<ScalarType,MV,OP>& Op,
const Anasazi::Experimental::SaddleContainer<ScalarType,MV>& x,
Anasazi::Experimental::SaddleContainer<ScalarType,MV>& y)
{ Op.Apply( x, y); };
};
} // end namespace Belos
#endif
#endif
|