45 typedef typename Teuchos::ScalarTraits<ScalarType>::magnitudeType MagnitudeType;
46 typedef typename Teuchos::ScalarTraits<ScalarType> SCT;
63 static void permuteVectors(
const int n,
const std::vector<int> &
perm, MV &Q, std::vector<
typename Teuchos::ScalarTraits<ScalarType>::magnitudeType >*
resids = 0);
66 static void permuteVectors(
const std::vector<int> &
perm, Teuchos::SerialDenseMatrix<int,ScalarType> &Q);
95 static void applyHouse(
int k, MV &V,
const Teuchos::SerialDenseMatrix<int,ScalarType> &H,
const std::vector<ScalarType> &
tau, Teuchos::RCP<MV>
workMV = Teuchos::null);
129 static int directSolver(
int size,
const Teuchos::SerialDenseMatrix<int,ScalarType> &KK,
130 Teuchos::RCP<
const Teuchos::SerialDenseMatrix<int,ScalarType> >
MM,
131 Teuchos::SerialDenseMatrix<int,ScalarType> &
EV,
132 std::vector<
typename Teuchos::ScalarTraits<ScalarType>::magnitudeType > &
theta,
142 static typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
errorEquality(
const MV &X,
const MV &MX, Teuchos::RCP<const OP>
M = Teuchos::null);
178 const std::vector<int> &
perm,
180 std::vector<
typename Teuchos::ScalarTraits<ScalarType>::magnitudeType >*
resids)
187 std::vector<int> index(1);
188 ScalarType
one = Teuchos::ScalarTraits<ScalarType>::one();
189 ScalarType
zero = Teuchos::ScalarTraits<ScalarType>::zero();
191 TEUCHOS_TEST_FOR_EXCEPTION(
n > MVT::GetNumberVecs(Q), std::invalid_argument,
"Anasazi::SolverUtils::permuteVectors(): argument n larger than width of input multivector.");
197 for (
i=0;
i<
n-1;
i++) {
200 for (
j=
i;
j<
n;
j++) {
215 for (
i=
n-2;
i>=0;
i--) {
227 Teuchos::RCP<MV>
tmpQ = MVT::CloneCopy( Q, index );
228 Teuchos::RCP<MV>
tmpQj = MVT::CloneViewNonConst( Q, index );
230 Teuchos::RCP<MV>
tmpQi = MVT::CloneViewNonConst( Q, index );
270 const int n = MVT::GetNumberVecs(V);
271 const ScalarType ONE = SCT::one();
272 const ScalarType ZERO = SCT::zero();
275 if (MVT::GetNumberVecs(V) == 0 || MVT::GetGlobalLength(V) == 0 ||
k == 0) {
279 if (
workMV == Teuchos::null) {
283 else if (MVT::GetNumberVecs(*
workMV) > 1) {
284 std::vector<int>
first(1);
293 TEUCHOS_TEST_FOR_EXCEPTION( H.numCols() !=
k, std::invalid_argument,
"Anasazi::SolverUtils::applyHouse(): H must have at least k columns.");
295 TEUCHOS_TEST_FOR_EXCEPTION( H.numRows() != MVT::GetNumberVecs(V), std::invalid_argument,
"Anasazi::SolverUtils::applyHouse(): Size of H,V are inconsistent.");
299 for (
int i=0;
i<
k;
i++) {
310 Teuchos::SerialDenseMatrix<int,ScalarType>
v(Teuchos::Copy,H,
n-
i,1,
i,
i);
322 Teuchos::SerialDenseMatrix<int,ScalarType>
vT(
v,Teuchos::CONJ_TRANS);
325 actV = Teuchos::null;
339 const Teuchos::SerialDenseMatrix<int,ScalarType> &KK,
340 Teuchos::RCP<
const Teuchos::SerialDenseMatrix<int,ScalarType> >
MM,
341 Teuchos::SerialDenseMatrix<int,ScalarType> &
EV,
342 std::vector<
typename Teuchos::ScalarTraits<ScalarType>::magnitudeType > &
theta,
387 Teuchos::LAPACK<int,ScalarType>
lapack;
388 Teuchos::BLAS<int,ScalarType>
blas;
396 if (KK.numCols() <
size || KK.numRows() <
size) {
400 if (
MM == Teuchos::null) {
403 else if (
MM->numCols() <
size ||
MM->numRows() <
size) {
410 if (
theta.size() < (
unsigned int)
size) {
423 std::vector<MagnitudeType>
rwork(3*
size-2);
426 std::vector<MagnitudeType>
tt(
size );
429 MagnitudeType
tol = SCT::magnitude(SCT::squareroot(SCT::eps()));
431 ScalarType
zero = Teuchos::ScalarTraits<ScalarType>::zero();
432 ScalarType
one = Teuchos::ScalarTraits<ScalarType>::one();
434 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> >
KKcopy,
MMcopy;
435 Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType> >
U;
445 U = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>(
rank,
rank) );
449 KKcopy = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( Teuchos::Copy, KK,
rank,
rank ) );
450 MMcopy = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( Teuchos::Copy, *
MM,
rank,
rank ) );
462 std::cerr << std::endl;
463 std::cerr <<
"Anasazi::SolverUtils::directSolver(): In HEGV, argument " << -
info <<
"has an illegal value.\n";
464 std::cerr << std::endl;
475 MMcopy = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( Teuchos::Copy, *
MM,
rank,
rank ) );
476 for (
int i = 0;
i <
rank; ++
i) {
477 for (
int j = 0;
j <
i; ++
j) {
478 (*MMcopy)(
i,
j) = SCT::conjugate((*
MM)(
j,
i));
484 std::logic_error,
"Anasazi::SolverUtils::directSolver() call to Teuchos::SerialDenseMatrix::multiply() returned an error.");
488 std::logic_error,
"Anasazi::SolverUtils::directSolver() call to Teuchos::SerialDenseMatrix::multiply() returned an error.");
491 for (
int i = 0;
i <
rank; ++
i) {
521 for (
int i = 0;
i <
nev; ++
i) {
532 KKcopy = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( Teuchos::Copy, KK,
size,
size ) );
533 MMcopy = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( Teuchos::Copy, *
MM,
size,
size ) );
545 std::cerr << std::endl;
546 std::cerr <<
"Anasazi::SolverUtils::directSolver(): In HEGV, argument " << -
info <<
"has an illegal value.\n";
547 std::cerr << std::endl;
554 std::cerr << std::endl;
555 std::cerr <<
"Anasazi::SolverUtils::directSolver(): In HEGV, DPOTRF or DHEEV returned an error code (" <<
info <<
").\n";
556 std::cerr << std::endl;
564 for (
int i = 0;
i <
nev; ++
i) {
575 KKcopy = Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>( Teuchos::Copy, KK,
size,
size ) );
583 std::cerr << std::endl;
585 std::cerr <<
"Anasazi::SolverUtils::directSolver(): In DHEEV, argument " << -
info <<
" has an illegal value\n";
588 std::cerr <<
"Anasazi::SolverUtils::directSolver(): In DHEEV, the algorithm failed to converge (" <<
info <<
").\n";
590 std::cerr << std::endl;
598 for (
int i = 0;
i <
nev; ++
i) {
622 MagnitudeType
maxDiff = SCT::magnitude(SCT::zero());
624 int xc = MVT::GetNumberVecs(X);
625 int mxc = MVT::GetNumberVecs(MX);
627 TEUCHOS_TEST_FOR_EXCEPTION(
xc !=
mxc,std::invalid_argument,
"Anasazi::SolverUtils::errorEquality(): input multivecs have different number of columns.");
632 MagnitudeType
maxCoeffX = SCT::magnitude(SCT::zero());
633 std::vector<MagnitudeType>
tmp(
xc );
634 MVT::MvNorm(MX,
tmp);
636 for (
int i = 0;
i <
xc; ++
i) {
640 std::vector<int> index( 1 );
642 if (
M != Teuchos::null) {
652 for (
int i = 0;
i <
xc; ++
i) {
static void permuteVectors(const int n, const std::vector< int > &perm, MV &Q, std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > *resids=0)
Permute the vectors in a multivector according to the permutation vector perm, and optionally the res...
static Teuchos::ScalarTraits< ScalarType >::magnitudeType errorEquality(const MV &X, const MV &MX, Teuchos::RCP< const OP > M=Teuchos::null)
Return the maximum coefficient of the matrix scaled by the maximum coefficient of MX.
static int directSolver(int size, const Teuchos::SerialDenseMatrix< int, ScalarType > &KK, Teuchos::RCP< const Teuchos::SerialDenseMatrix< int, ScalarType > > MM, Teuchos::SerialDenseMatrix< int, ScalarType > &EV, std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &theta, int &nev, int esType=0)
Routine for computing the first NEV generalized eigenpairs of the Hermitian pencil (KK,...
static void applyHouse(int k, MV &V, const Teuchos::SerialDenseMatrix< int, ScalarType > &H, const std::vector< ScalarType > &tau, Teuchos::RCP< MV > workMV=Teuchos::null)
Apply a sequence of Householder reflectors (from GEQRF) to a multivector, using minimal workspace.