19 #ifndef SELDON_FILE_ANASAZI_CXX
22 #include "Anasazi.hxx"
24 #include "AnasaziConfigDefs.hpp"
25 #include "AnasaziBasicEigenproblem.hpp"
26 #include "AnasaziLOBPCG.hpp"
27 #include "AnasaziLOBPCGSolMgr.hpp"
28 #include "AnasaziBlockDavidson.hpp"
29 #include "AnasaziBlockDavidsonSolMgr.hpp"
30 #include "AnasaziBlockKrylovSchur.hpp"
31 #include "AnasaziBlockKrylovSchurSolMgr.hpp"
32 #include "AnasaziBasicSort.hpp"
33 #include "AnasaziBasicOutputManager.hpp"
34 #include "Teuchos_CommandLineProcessor.hpp"
36 #include "AnasaziMVOPTester.hpp"
38 #ifdef SELDON_WITH_MPI
47 #include "AnasaziMultiVec.hpp"
48 #include "MyMultiVec.hpp"
49 #include "AnasaziOperator.hpp"
50 #include "Teuchos_BLAS.hpp"
56 template<
class EigenPb,
class T>
64 enum {OPERATOR_A, OPERATOR_M, OPERATOR_OP};
68 void Apply(
const MultiVec<T>& X0, MultiVec<T>& Y0)
const;
78 template<
class EigenPb,
class T>
87 template<
class EigenPb,
class T>
89 ::Apply(
const MultiVec<T>& X0, MultiVec<T>& Y0)
const
93 int n = X.GetVecLength();
94 int nvecs = X.GetNumberVecs();
98 switch (type_operator)
103 for (
int p = 0; p < nvecs; p++)
111 if (var_eig.DiagonalMass() || var_eig.UseCholeskyFactoForMass())
114 if (var_eig.GetComputationalMode() == var_eig.REGULAR_MODE)
116 if (var_eig.DiagonalMass())
117 var_eig.MltInvSqrtDiagonalMass(xvec);
119 var_eig.SolveCholeskyMass(Seldon::SeldonTrans, xvec);
121 var_eig.MltStiffness(xvec, yvec);
123 if (var_eig.DiagonalMass())
124 var_eig.MltInvSqrtDiagonalMass(yvec);
126 var_eig.SolveCholeskyMass(Seldon::SeldonNoTrans, yvec);
130 if (var_eig.DiagonalMass())
131 var_eig.MltSqrtDiagonalMass(xvec);
133 var_eig.MltCholeskyMass(Seldon::SeldonNoTrans, xvec);
135 var_eig.ComputeSolution(xvec, yvec);
137 if (var_eig.DiagonalMass())
138 var_eig.MltSqrtDiagonalMass(yvec);
140 var_eig.MltCholeskyMass(Seldon::SeldonTrans, yvec);
145 if (var_eig.GetComputationalMode() == var_eig.INVERT_MODE)
147 if (var_eig.GetTypeSpectrum() != var_eig.CENTERED_EIGENVALUES)
149 var_eig.MltStiffness(xvec0, xvec);
150 var_eig.ComputeSolution(xvec, yvec);
154 var_eig.MltMass(xvec0, xvec);
155 var_eig.ComputeSolution(xvec, yvec);
158 else if (var_eig.GetComputationalMode() == var_eig.REGULAR_MODE)
160 var_eig.MltStiffness(xvec0, yvec);
164 cout <<
"not implemented " << endl;
169 var_eig.IncrementProdMatVect();
177 for (
int p = 0; p < nvecs; p++)
184 if (var_eig.DiagonalMass() || var_eig.UseCholeskyFactoForMass())
188 if (var_eig.GetComputationalMode() == var_eig.INVERT_MODE)
191 var_eig.MltMass(xvec, yvec);
200 cout <<
"Unknown operator " << endl;
224 z = complex<T>(x, y);
235 #ifdef SELDON_WITH_VIRTUAL
237 void FindEigenvaluesAnasazi(EigenProblem_Base<T>& var,
238 Vector<T>& eigen_values,
239 Vector<T>& lambda_imag,
240 Matrix<T, General, ColMajor>& eigen_vectors)
242 template<
class EigenProblem,
class T,
class Allocator1,
243 class Allocator2,
class Allocator3>
252 switch (var.GetTypeSorting())
259 if (var.GetTypeSpectrum() == var.SMALL_EIGENVALUES)
261 switch (var.GetTypeSorting())
270 T shiftr = var.
GetShiftValue(), shifti = var.GetImagShiftValue();
272 SetComplexZero(zero);
275 int print_level = var.GetPrintLevel();
279 typedef Anasazi::MultiVec<T> MV;
281 int nev = var.GetNbAskedEigenvalues();
283 int blockSize = var.GetNbArnoldiVectors();
284 int maxIters = var.GetNbMaximumIterations();
286 typename ClassComplexType<T>::Treal tol = var.GetStoppingCriterion();
289 Teuchos::ParameterList MyPL;
290 MyPL.set(
"Which", which);
291 MyPL.set(
"Block Size", blockSize);
292 MyPL.set(
"Maximum Iterations", maxIters);
296 MyPL.set(
"Orthogonalization",
"SVQB");
298 MyPL.set(
"Orthogonalization",
"DGKS");
300 MyPL.set(
"Verbosity", print_level);
301 MyPL.set(
"Convergence Tolerance", tol);
315 MyPL.set(
"Num Blocks", nb_blocks);
317 MyPL.set(
"Maximum Restarts", maxRestarts);
332 typedef Anasazi::Operator<T> OP;
333 Teuchos::RCP<const OP> A, M, Op;
344 Teuchos::RCP<Anasazi::BasicEigenproblem<T, MV, OP> > MyProblem;
345 if (solver == param.SOLVER_LOBPCG || solver == param.SOLVER_BD)
346 MyProblem = Teuchos::rcp(
new Anasazi::BasicEigenproblem<T, MV, OP>(A, M, ivec) );
348 MyProblem = Teuchos::rcp(
new Anasazi::BasicEigenproblem<T, MV, OP>(Op, M, ivec) );
351 bool isherm = var.IsHermitianProblem();
354 MyProblem->setNEV(nev);
356 if (var.DiagonalMass() || var.UseCholeskyFactoForMass())
359 if (var.DiagonalMass())
362 var.ComputeDiagonalMass();
365 var.FactorizeDiagonalMass();
370 var.ComputeMassForCholesky();
373 var.FactorizeCholeskyMass();
376 if (var.GetComputationalMode() == var.REGULAR_MODE)
379 var.ComputeStiffnessMatrix();
384 var.ComputeAndFactorizeStiffnessMatrix(-shiftr, one);
389 if (var.GetComputationalMode() == var.INVERT_MODE)
394 if (var.GetTypeSpectrum() != var.CENTERED_EIGENVALUES)
398 var.ComputeAndFactorizeStiffnessMatrix(one, zero);
401 var.ComputeStiffnessMatrix();
407 var.ComputeAndFactorizeStiffnessMatrix(-shiftr, one);
410 var.ComputeMassMatrix();
413 else if (var.GetComputationalMode() == var.REGULAR_MODE)
415 if (solver == param.SOLVER_BKS)
417 cout <<
"generalized eigenproblem not implemented for this solver" << endl;
425 var.ComputeStiffnessMatrix();
426 var.ComputeMassMatrix();
431 cout <<
"not implemented " << endl;
438 if (solver != param.SOLVER_BKS)
440 cout <<
"Only Block-Krylov Schur (SOLVER_BKS) "
441 <<
" can be used for nonsymmetric system" << endl;
446 MyProblem->setHermitian(isherm);
449 bool pb_set = MyProblem->setProblem();
452 cout <<
"Anasazi::BasicEigenproblem::SetProblem() failed "<< endl;
457 Teuchos::RCP< Anasazi::SolverManager<T, MV, OP> > MySolver;
458 if (solver == param.SOLVER_LOBPCG)
459 MySolver = Teuchos::rcp(
new Anasazi::LOBPCGSolMgr<T, MV, OP>(MyProblem, MyPL));
460 else if (solver == param.SOLVER_BKS)
461 MySolver = Teuchos::rcp(
new Anasazi::BlockKrylovSchurSolMgr<T, MV, OP>
463 else if (solver == param.SOLVER_BD)
464 MySolver = Teuchos::rcp(
new Anasazi::BlockDavidsonSolMgr<T, MV, OP>
468 cout <<
"Invalid Anasazi solver: " << solver << endl;
473 int returnCode = MySolver->solve();
474 if (returnCode != Anasazi::Converged)
476 cout <<
"Anasazi's solver did not converge" << endl;
481 const Anasazi::Eigensolution<T, MV>& sol = MyProblem->getSolution();
483 eigen_values.Reallocate(sol.Evals.size());
484 lambda_imag.Reallocate(sol.Evals.size());
485 eigen_vectors.Reallocate(n, sol.Evals.size());
486 typename ClassComplexType<T>::Treal lr, li;
489 for (
unsigned int i = 0; i < sol.Evals.size(); i++)
491 lr = realpart(sol.Evals[i].realpart);
492 li = realpart(sol.Evals[i].imagpart);
497 for (
int j = 0; j < n; j++)
498 eigen_vectors(j, i) = x[j];
511 #define SELDON_FILE_ANASAZI_CXX