From 09ec9140c04e98b9a3d991181636c2dd3fad01b5 Mon Sep 17 00:00:00 2001 From: Caleb Schilly Date: Tue, 26 Sep 2023 14:18:32 -0400 Subject: [PATCH] #215: finish cxx_main.cpp --- .../test/GeneralizedDavidson/CMakeLists.txt | 9 - .../test/GeneralizedDavidson/cxx_main.cpp | 74 +-- .../cxx_main_solvertest.cpp | 490 ------------------ 3 files changed, 39 insertions(+), 534 deletions(-) delete mode 100644 packages/anasazi/tpetra/test/GeneralizedDavidson/cxx_main_solvertest.cpp diff --git a/packages/anasazi/tpetra/test/GeneralizedDavidson/CMakeLists.txt b/packages/anasazi/tpetra/test/GeneralizedDavidson/CMakeLists.txt index e97f43b7d3e9..0835f99a8add 100644 --- a/packages/anasazi/tpetra/test/GeneralizedDavidson/CMakeLists.txt +++ b/packages/anasazi/tpetra/test/GeneralizedDavidson/CMakeLists.txt @@ -1,13 +1,4 @@ -# TRIBITS_ADD_EXECUTABLE_AND_TEST( -# Tpetra_GeneralizedDavidson_solvertest -# SOURCES cxx_main_solvertest.cpp -# ARGS -# "--verbose" -# "--debug" -# COMM serial mpi -# ) - ASSERT_DEFINED(${PACKAGE_NAME}_ENABLE_Triutils) IF (${PACKAGE_NAME}_ENABLE_Triutils) TRIBITS_ADD_EXECUTABLE_AND_TEST( diff --git a/packages/anasazi/tpetra/test/GeneralizedDavidson/cxx_main.cpp b/packages/anasazi/tpetra/test/GeneralizedDavidson/cxx_main.cpp index bc0dcff08a5e..779c6f60e0aa 100644 --- a/packages/anasazi/tpetra/test/GeneralizedDavidson/cxx_main.cpp +++ b/packages/anasazi/tpetra/test/GeneralizedDavidson/cxx_main.cpp @@ -60,46 +60,49 @@ #include "AnasaziTpetraAdapter.hpp" #include "AnasaziBasicEigenproblem.hpp" #include "AnasaziGeneralizedDavidsonSolMgr.hpp" + #include +#include #include +#include #include +#include // I/O for Harwell-Boeing files #include -int main(int argc, char *argv[]) -{ -// #ifndef HAVE_TPETRA_COMPLEX_DOUBLE -// # error "Anasazi: This test requires Scalar = std::complex to be enabled in Tpetra." -// #else +template +int run(int argc, char *argv[]) { + + using ST = typename Tpetra::MultiVector::scalar_type; + using LO = typename Tpetra::MultiVector<>::local_ordinal_type; + using GO = typename Tpetra::MultiVector<>::global_ordinal_type; + using NT = typename Tpetra::MultiVector<>::node_type; + + using SCT = typename Teuchos::ScalarTraits; + using MT = typename SCT::magnitudeType; + + using OP = Tpetra::Operator; + using MV = Tpetra::MultiVector; + using OPT = Anasazi::OperatorTraits; + using MVT = Anasazi::MultiVecTraits; + + using tmap_t = Tpetra::Map; + using tcrsmatrix_t = Tpetra::CrsMatrix; + using namespace Teuchos; - using Tpetra::CrsMatrix; - using Tpetra::Map; - using Tpetra::MultiVector; - using Tpetra::Operator; using std::vector; using std::cout; using std::endl; - typedef double ST; - typedef ScalarTraits SCT; - typedef SCT::magnitudeType MT; - typedef MultiVector MV; - typedef MultiVector::global_ordinal_type GO; - typedef Operator OP; - typedef Anasazi::MultiVecTraits MVT; - typedef Anasazi::OperatorTraits OPT; - Tpetra::ScopeGuard tpetraScope (&argc, &argv); const ST ONE = SCT::one(); int info = 0; - int MyPID = 0; - - RCP > comm = Tpetra::getDefaultComm (); - MyPID = rank(*comm); + const auto comm = Tpetra::getDefaultComm (); + const int MyPID = comm->getRank(); bool testFailed; bool verbose = false; @@ -156,20 +159,20 @@ int main(int argc, char *argv[]) return -1; } // create map - RCP > map = rcp (new Map<> (dim, 0, comm)); - RCP > K = rcp(new CrsMatrix (map, rnnzmax)); + RCP map = rcp (new tmap_t (dim, 0, comm)); + RCP K = rcp(new tcrsmatrix_t (map, rnnzmax)); if (MyPID == 0) { - // Convert interleaved doubles to complex values - // HB format is compressed column. CrsMatrix is compressed row. - const double *dptr = dvals; + const ST *dptr = dvals; const int *rptr = rowind; - for (int c=0; cinsertGlobalValues (*rptr++ - 1, tuple (c), tuple (ST (dptr[0], dptr[1]))); - dptr += 2; + for (int c = 0; c < dim; ++c) { + for (int colnnz = 0; colnnz < colptr[c + 1] - colptr[c]; ++colnnz) { + ST value = dptr[0]; + K->insertGlobalValues(*rptr++ - 1, tuple(c), tuple(value)); + dptr++; } } } + if (MyPID == 0) { // Clean up. free( dvals ); @@ -184,9 +187,7 @@ int main(int argc, char *argv[]) // Create eigenproblem RCP > problem = - rcp( new Anasazi::BasicEigenproblem() ); - problem->setA(K); - problem->setInitVec(ivec); + rcp( new Anasazi::BasicEigenproblem(K,ivec) ); // // Inform the eigenproblem that the operator K is symmetric problem->setHermitian(true); @@ -302,6 +303,9 @@ int main(int argc, char *argv[]) cout << "End Result: TEST PASSED" << endl; } return 0; +} -// #endif // HAVE_TPETRA_COMPLEX_DOUBLE +int main(int argc, char *argv[]) { + return run(argc,argv); + // run(argc,argv); } diff --git a/packages/anasazi/tpetra/test/GeneralizedDavidson/cxx_main_solvertest.cpp b/packages/anasazi/tpetra/test/GeneralizedDavidson/cxx_main_solvertest.cpp deleted file mode 100644 index bf870a5ed0e2..000000000000 --- a/packages/anasazi/tpetra/test/GeneralizedDavidson/cxx_main_solvertest.cpp +++ /dev/null @@ -1,490 +0,0 @@ -// @HEADER -// *********************************************************************** -// -// Anasazi: Block Eigensolvers Package -// Copyright 2004 Sandia Corporation -// -// Under terms of Contract DE-AC04-94AL85000 with Sandia Corporation, -// the U.S. Government retains certain rights in this software. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// 1. Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// -// 3. Neither the name of the Corporation nor the names of the -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY -// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Questions? Contact Michael A. Heroux (maherou@sandia.gov) -// -// *********************************************************************** -// @HEADER -// -// This test is for the generalized Davidsoneigensolver -// -// This code does not compile due to the use of ModeLaplace1DQ1, -// which depends on Epetra. It is commented out in CMakeLists. - -// Tpetra -#include -#include -#include -#include - -// Teuchos -#include "Teuchos_SerialDenseMatrix.hpp" -#include "Teuchos_CommandLineProcessor.hpp" - -// Anasazi - -#include "AnasaziTypes.hpp" -#include "AnasaziBasicSort.hpp" -#include "AnasaziConfigDefs.hpp" -#include "AnasaziSolverUtils.hpp" -#include "AnasaziTpetraAdapter.hpp" -#include "AnasaziSVQBOrthoManager.hpp" -#include "AnasaziBasicEigenproblem.hpp" -#include "AnasaziBasicOutputManager.hpp" -#include "AnasaziStatusTestMaxIters.hpp" -#include "AnasaziGeneralizedDavidson.hpp" - -#include "ModeLaplace1DQ1.h" - - -using namespace Teuchos; -using namespace Anasazi; - - -class get_out : public std::logic_error { - public: get_out(const std::string &whatarg) : std::logic_error(whatarg) {} -}; - -template -void checks( RCP > solver, int blockSize, int maxdim, - RCP > problem, - RCP > ortho) { - GeneralizedDavidsonState state = solver->getState(); - - TEUCHOS_TEST_FOR_EXCEPTION(MVT::GetNumberVecs(*state.V) != solver->getMaxSubspaceDim(),get_out,"getMaxSubspaceDim() does not match allocated size for V"); - - TEUCHOS_TEST_FOR_EXCEPTION(&solver->getProblem() != problem.get(),get_out,"getProblem() did not return the submitted problem."); - - if (solver->isInitialized()) - { - // Generalized Davidson block size is equal to or one greater than user specified block size - // Because GeneralizedDavidson block size is variable, this check only applied to an initialized solver - TEUCHOS_TEST_FOR_EXCEPTION(solver->getBlockSize() != blockSize && solver->getBlockSize() != blockSize+1, get_out,"Solver block size does not match specified block size."); - - std::vector > ritzValues = solver->getRitzValues(); - - // check Ritz residuals - std::vector ritzResids = solver->getRitzRes2Norms(); - - // get Ritz index - std::vector ritzIndex = solver->getRitzIndex(); - - // get Ritz vector - RCP ritzVectors = solver->getRitzVectors(); - - int numRitzVecs = MVT::GetNumberVecs(*ritzVectors); - - RCP tmpVecs = MVT::Clone( *ritzVectors, numRitzVecs ); - - // Compute Ritz residuals like R = A*X - B*X*T - Teuchos::SerialDenseMatrix T(numRitzVecs,numRitzVecs); - Teuchos::RCP ritzResiduals = MVT::Clone( *ritzVectors, numRitzVecs ); - for (int i=0; igetA()), *ritzVectors, *ritzResiduals ); - if( problem->getM() != Teuchos::null ) - { - OP::Apply( *(problem->getM()), *ritzVectors, *tmpVecs ); - } - else - { - std::vector inds(numRitzVecs); - for( int i=0; i ritzVecNrm( numRitzVecs ); - MVT::MvNorm( *ritzVectors, ritzVecNrm ); - MT error; - for (int i=0; i::magnitude( ritzVecNrm[i] - 1.0 ); - TEUCHOS_TEST_FOR_EXCEPTION(error > 1e-14,get_out,"Ritz vectors are not normalized."); - } - - std::vector ritzResNrm( MVT::GetNumberVecs( *ritzResiduals ) ); - MVT::MvNorm( *ritzResiduals, ritzResNrm ); - for (int i=0; i<(int)ritzResNrm.size(); i++) { - error = Teuchos::ScalarTraits::magnitude( ritzResids[i] - ritzResNrm[i] ); - TEUCHOS_TEST_FOR_EXCEPTION(error > 1e-12,get_out,"Ritz residuals from iteration do not compare to those computed."); - } - } - else { - // not initialized - TEUCHOS_TEST_FOR_EXCEPTION(solver->getCurSubspaceDim() != 0,get_out,"In unitialized state, getCurSubspaceDim() should be 0."); - } -} - -template -void testsolver( RCP > problem, - RCP< OutputManager > printer, - RCP< MatOrthoManager > ortho, - RCP< SortManager > sorter, - ParameterList &pls,bool invalid, - GeneralizedDavidsonState initstate, bool invalidinit) -{ - // create a status tester - RCP< StatusTest > tester = rcp( new StatusTestMaxIters(1) ); - - // create the solver - RCP< GeneralizedDavidson > solver; - try { - solver = rcp( new GeneralizedDavidson(problem,sorter,printer,tester,ortho,pls) ); - TEUCHOS_TEST_FOR_EXCEPTION(invalid, get_out, "Instantiating with invalid parameters failed to throw exception.") - } - catch (const std::invalid_argument &ia) { - if (!invalid) { - printer->stream(Warnings) << "Error thrown at instantiation: " << ia.what() << std::endl; - } - TEUCHOS_TEST_FOR_EXCEPTION(!invalid, get_out, "Instantiating with valid parameters unexpectadly threw exception."); - - // caught expected exception - return; - } - - const int blockSize = pls.get("Block Size"); - const int maxdim = pls.get("Maximum Subspace Dimension"); - - SolverUtils msutils; - - // solver should be uninitialized - TEUCHOS_TEST_FOR_EXCEPTION(solver->isInitialized() != false,get_out,"Solver should be un-initialized after instantiation."); - TEUCHOS_TEST_FOR_EXCEPTION(solver->getNumIters() != 0,get_out,"Number of iterations after initialization should be zero after init.") - TEUCHOS_TEST_FOR_EXCEPTION(solver->getAuxVecs().size() != 0,get_out,"getAuxVecs() should return empty."); - checks(solver,blockSize,maxdim,problem,ortho); - - // initialize solver and perform checks - try { - solver->initialize(initstate); - TEUCHOS_TEST_FOR_EXCEPTION(invalidinit, get_out, "Initializing with invalid data failed to throw exception.") - } - catch (const std::invalid_argument &ia) { - TEUCHOS_TEST_FOR_EXCEPTION(!invalidinit, get_out, "Initializing with valid data unexpectadly threw exception."); - // caught expected exception - return; - } - - TEUCHOS_TEST_FOR_EXCEPTION(solver->isInitialized() != true,get_out,"Solver should be initialized after call to initialize()."); - TEUCHOS_TEST_FOR_EXCEPTION(solver->getNumIters() != 0,get_out,"Number of iterations should be zero.") - TEUCHOS_TEST_FOR_EXCEPTION(solver->getAuxVecs().size() != 0,get_out,"getAuxVecs() should return empty."); - TEUCHOS_TEST_FOR_EXCEPTION(solver->getCurSubspaceDim() != blockSize,get_out,"after init, getCurSubspaceDim() should be equal to block size."); - checks(solver,blockSize,maxdim,problem,ortho); - - // call iterate(); solver should perform exactly one iteration and return; status test should be passed - solver->iterate(); - TEUCHOS_TEST_FOR_EXCEPTION(tester->getStatus() != Passed,get_out,"Solver returned from iterate() but getStatus() not Passed."); - TEUCHOS_TEST_FOR_EXCEPTION(solver->isInitialized() != true,get_out,"Solver should be initialized after call to initialize()."); - TEUCHOS_TEST_FOR_EXCEPTION(solver->getNumIters() != 1,get_out,"Number of iterations should be one.") - TEUCHOS_TEST_FOR_EXCEPTION(solver->getAuxVecs().size() != 0,get_out,"getAuxVecs() should return empty."); - TEUCHOS_TEST_FOR_EXCEPTION(solver->getCurSubspaceDim() != 2*blockSize,get_out,"after one step, getCurSubspaceDim() should be 2*blockSize."); - checks(solver,blockSize,maxdim,problem,ortho); - - // reset numiters, call iterate(); solver should perform exactly one iteration and return; status test should be passed - solver->resetNumIters(); - TEUCHOS_TEST_FOR_EXCEPTION(solver->getNumIters() != 0,get_out,"Number of iterations should be zero after resetNumIters().") - solver->iterate(); - TEUCHOS_TEST_FOR_EXCEPTION(tester->getStatus() != Passed,get_out,"Solver returned from iterate() but getStatus() not Passed."); - TEUCHOS_TEST_FOR_EXCEPTION(solver->isInitialized() != true,get_out,"Solver should be initialized after call to initialize()."); - TEUCHOS_TEST_FOR_EXCEPTION(solver->getNumIters() != 0,get_out,"Number of iterations should be zero.") - TEUCHOS_TEST_FOR_EXCEPTION(solver->getAuxVecs().size() != 0,get_out,"getAuxVecs() should return empty."); - TEUCHOS_TEST_FOR_EXCEPTION(solver->getCurSubspaceDim() != 2*blockSize,get_out,"after two steps, getCurSubspaceDim() should be 2*blockSize."); - checks(solver,blockSize,maxdim,problem,ortho); -} - -template -int run(int argc, char *argv[]) -{ - using ST = typename Tpetra::MultiVector::scalar_type; - using LO = typename Tpetra::MultiVector<>::local_ordinal_type; - using GO = typename Tpetra::MultiVector<>::global_ordinal_type; - using NT = typename Tpetra::MultiVector<>::node_type; - - using MT = typename Teuchos::ScalarTraits::magnitudeType; - - using OP = Tpetra::Operator; - using MV = Tpetra::MultiVector; - using OPT = Anasazi::OperatorTraits; - using MVT = Anasazi::MultiVecTraits; - - using tmap_t = Tpetra::Map; - using tcrsmatrix_t = Tpetra::CrsMatrix; - - Teuchos::GlobalMPISession mpiSession (&argc, &argv, &std::cout); - const auto comm = Tpetra::getDefaultComm(); - - bool testFailed; - bool verbose = false; - bool debug = false; - - CommandLineProcessor cmdp(false,true); - cmdp.setOption("verbose","quiet",&verbose,"Print messages and results."); - cmdp.setOption("debug","nodebug",&debug,"Print debugging output from iteration."); - if (cmdp.parse(argc,argv) != CommandLineProcessor::PARSE_SUCCESSFUL) { - return -1; - } - if (debug) verbose = true; - - // create the output manager - int verbosity = Anasazi::Errors; - if (verbose) { - verbosity += Anasazi::Warnings; - } - if (debug) { - verbosity += Anasazi::Debug; - } - - RCP< OutputManager > printer = - rcp( new BasicOutputManager( verbosity ) ); - - printer->stream(Debug) << Anasazi_Version() << std::endl; - - // Problem information - int space_dim = 1; - std::vector brick_dim( space_dim ); - brick_dim[0] = 1.0; - std::vector elements( space_dim ); - elements[0] = 100+1; - - // Create problem - RCP testCase = rcp( new ModeLaplace1DQ1(comm, brick_dim[0], elements[0]) ); - // - // Get the stiffness and mass matrices - RCP K = rcp( const_cast(testCase->getStiffness()), false ); - RCP M = rcp( const_cast(testCase->getMass()), false ); - - // - // Create the initial vectors - const int nev = 5; - RCP ivec = rcp( new MV(K->OperatorDomainMap(), nev) ); - MVT::MvRandom( *ivec ); - // - // Create eigenproblem: one standard and one generalized - RCP > probstd = rcp( new BasicEigenproblem() ); - probstd->setA(K); - probstd->setInitVec(ivec); - RCP > probgen = rcp( new BasicEigenproblem() ); - probgen->setA(K); - probgen->setM(M); - probgen->setInitVec(ivec); - // - // Inform the eigenproblem that the operator A is not symmetric (even though it is) - probstd->setHermitian(false); - probgen->setHermitian(false); - // - // Set the number of eigenvalues requested - probstd->setNEV( nev ); - probgen->setNEV( nev ); - // - // Inform the eigenproblem that you are finishing passing it information - if ( probstd->setProblem() != true || probgen->setProblem() != true ) { - printer->stream(Warnings) << "Anasazi::BasicEigenproblem::SetProblem() returned with error." << std::endl - << "End Result: TEST FAILED" << std::endl; - return -1; - } - - // create the orthogonalization managers: one standard and one M-based - RCP< MatOrthoManager > orthostd = rcp( new SVQBOrthoManager() ); - RCP< MatOrthoManager > orthogen = rcp( new SVQBOrthoManager() ); - // create the sort manager - RCP< SortManager > sorter = rcp( new BasicSort("LM") ); - // create the parameter list specifying blockSize > nev and full orthogonalization - ParameterList pls; - - // begin testing - testFailed = false; - - try - { - GeneralizedDavidsonState istate; - - pls.set("Block Size",nev); - pls.set("Maximum Subspace Dimension",3*nev); - pls.set("Number of Ritz Vectors",nev); - printer->stream(Warnings) << "Testing solver(nev,3*nev) with standard eigenproblem..." << std::endl; - testsolver(probstd,printer,orthostd,sorter,pls,false,istate,false); - pls.set("Maximum Subspace Dimension",3*nev); - printer->stream(Warnings) << "Testing solver(nev,3*nev) with generalized eigenproblem..." << std::endl; - testsolver(probgen,printer,orthogen,sorter,pls,false,istate,false); - - pls.set("Block Size",nev); - pls.set("Maximum Subspace Dimension",4*nev); - printer->stream(Warnings) << "Testing solver(nev,4*nev) with standard eigenproblem..." << std::endl; - testsolver(probstd,printer,orthostd,sorter,pls,false,istate,false); - pls.set("Maximum Subspace Dimension",4*nev); - printer->stream(Warnings) << "Testing solver(nev,4*nev) with generalized eigenproblem..." << std::endl; - testsolver(probgen,printer,orthogen,sorter,pls,false,istate,false); - - pls.set("Block Size",2*nev); - pls.set("Maximum Subspace Dimension",4*nev); - printer->stream(Warnings) << "Testing solver(2*nev,4*nev) with standard eigenproblem..." << std::endl; - testsolver(probstd,printer,orthostd,sorter,pls,false,istate,false); - pls.set("Maximum Subspace Dimension",4*nev); - printer->stream(Warnings) << "Testing solver(2*nev,4*nev) with generalized eigenproblem..." << std::endl; - testsolver(probgen,printer,orthogen,sorter,pls,false,istate,false); - - pls.set("Block Size",nev/2); - pls.set("Maximum Subspace Dimension",3*nev); - printer->stream(Warnings) << "Testing solver(nev/2,3*nev) with standard eigenproblem..." << std::endl; - testsolver(probstd,printer,orthostd,sorter,pls,false,istate,false); - pls.set("Maximum Subspace Dimension",3*nev); - printer->stream(Warnings) << "Testing solver(nev/2,3*nev) with generalized eigenproblem..." << std::endl; - testsolver(probgen,printer,orthogen,sorter,pls,false,istate,false); - - pls.set("Block Size",nev/2); - pls.set("Maximum Subspace Dimension",4*nev); - printer->stream(Warnings) << "Testing solver(nev/2,4*nev) with standard eigenproblem..." << std::endl; - testsolver(probstd,printer,orthostd,sorter,pls,false,istate,false); - pls.set("Maximum Subspace Dimension",4*nev); - printer->stream(Warnings) << "Testing solver(nev/2,4*nev) with generalized eigenproblem..." << std::endl; - testsolver(probgen,printer,orthogen,sorter,pls,false,istate,false); - - // try with an invalid blockSize - pls.set("Block Size",0); - pls.set("Maximum Subspace Dimension",4*nev); - printer->stream(Warnings) << "Testing solver(0,4*nev) with standard eigenproblem..." << std::endl; - testsolver(probstd,printer,orthostd,sorter,pls,true,istate,false); - - // try with an invalid maxdim - pls.set("Block Size",nev); - pls.set("Maximum Subspace Dimension",0); - printer->stream(Warnings) << "Testing solver(nev,0) with standard eigenproblem..." << std::endl; - testsolver(probstd,printer,orthostd,sorter,pls,true,istate,false); - - // try with an invalid maxdim: invalid because it must be greater than nev - pls.set("Block Size",nev); - pls.set("Maximum Subspace Dimension",nev); - printer->stream(Warnings) << "Testing solver(nev,nev) with standard eigenproblem..." << std::endl; - testsolver(probstd,printer,orthostd,sorter,pls,true,istate,false); - - // try with a too-large subspace - probstd->setHermitian(true); - probstd->setProblem(); - pls.set("Maximum Subspace Dimension",100+1); - printer->stream(Warnings) << "Testing solver(4,toomany,Hermitian) with standard eigenproblem..." << std::endl; - testsolver(probstd,printer,orthostd,sorter,pls,true,istate,false); - - // try with an unset problem - // setHermitian will mark the problem as unset - probstd->setHermitian(true); - printer->stream(Warnings) << "Testing solver with unset eigenproblem..." << std::endl; - testsolver(probstd,printer,orthostd,sorter,pls,true,istate,false); - // set problem: now hermitian - probstd->setProblem(); - - // create a dummy status tester - RCP< StatusTest > dumtester = rcp( new StatusTestMaxIters(1) ); - - // try with a null problem - printer->stream(Warnings) << "Testing solver with null eigenproblem..." << std::endl; - try { - RCP< GeneralizedDavidson > solver - = rcp( new GeneralizedDavidson(Teuchos::null,sorter,printer,dumtester,orthostd,pls) ); - TEUCHOS_TEST_FOR_EXCEPTION(true,get_out,"Instantiating with invalid parameters failed to throw exception."); - } - catch (const std::invalid_argument &ia) { - // caught expected exception - } - - // try with a null sortman - printer->stream(Warnings) << "Testing solver with null sort manager..." << std::endl; - try { - RCP< GeneralizedDavidson > solver - = rcp( new GeneralizedDavidson(probstd,Teuchos::null,printer,dumtester,orthostd,pls) ); - TEUCHOS_TEST_FOR_EXCEPTION(true,get_out,"Instantiating with invalid parameters failed to throw exception."); - } - catch (const std::invalid_argument &ia) { - // caught expected exception - } - - // try with a output man problem - printer->stream(Warnings) << "Testing solver with null output manager..." << std::endl; - try { - RCP< GeneralizedDavidson > solver - = rcp( new GeneralizedDavidson(probstd,sorter,Teuchos::null,dumtester,orthostd,pls) ); - TEUCHOS_TEST_FOR_EXCEPTION(true,get_out,"Instantiating with invalid parameters failed to throw exception."); - } - catch (const std::invalid_argument &ia) { - // caught expected exception - } - - // try with a null status test - printer->stream(Warnings) << "Testing solver with null status test..." << std::endl; - try { - RCP< GeneralizedDavidson > solver - = rcp( new GeneralizedDavidson(probstd,sorter,printer,Teuchos::null,orthostd,pls) ); - TEUCHOS_TEST_FOR_EXCEPTION(true,get_out,"Instantiating with invalid parameters failed to throw exception."); - } - catch (const std::invalid_argument &ia) { - // caught expected exception - } - - // try with a null orthoman - printer->stream(Warnings) << "Testing solver with null ortho manager..." << std::endl; - try { - RCP< GeneralizedDavidson > solver - = rcp( new GeneralizedDavidson(probstd,sorter,printer,dumtester,Teuchos::null,pls) ); - TEUCHOS_TEST_FOR_EXCEPTION(true,get_out,"Instantiating with invalid parameters failed to throw exception."); - } - catch (const std::invalid_argument &ia) { - // caught expected exception - } - - } - catch (const get_out &go) { - printer->stream(Errors) << "Test failed: " << go.what() << std::endl; - testFailed = true; - } - catch (const std::exception &e) { - printer->stream(Errors) << "Caught unexpected exception: " << e.what() << std::endl; - testFailed = true; - } - - if (testFailed) { - printer->stream(Warnings) << std::endl << "End Result: TEST FAILED" << std::endl; - return -1; - } - // - // Default return value - // - printer->stream(Warnings) << std::endl << "End Result: TEST PASSED" << std::endl; - return 0; - -} // end run - -int main(int argc, char *argv[]) { - return run(argc,argv); - // run(argc,argv); -}