40#include <boost/test/unit_test.hpp>
49using namespace LibUtilities;
55 const std::vector<NekDouble> &offDiagonal)
62 [[maybe_unused]]
const bool &flag)
64 std::fill(output.data(), output.data() + output.size(), 0.0);
87 const std::string filename =
88 "/tmp/nektar_linsys_iter_eigenvalue_session.xml";
89 std::ofstream sessionFile(filename);
90 sessionFile <<
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
92 <<
" <CONDITIONS />\n"
96 char arg0[] =
"LinearAlgebraUnitTests";
97 char *argv[] = {arg0,
nullptr};
98 std::vector<std::string> filenames = {filename};
104 const std::vector<NekDouble> &diagonal,
105 const std::vector<NekDouble> &offDiagonal)
107 const int n = diagonal.size();
108 std::vector<NekDouble> matrix(n * n, 0.0);
109 for (
int i = 0; i < n; ++i)
111 matrix[i + i * n] = diagonal[i];
114 matrix[i + (i + 1) * n] = offDiagonal[i];
115 matrix[i + 1 + i * n] = offDiagonal[i];
124 std::vector<NekDouble> a = matrix;
129 const char jobvl =
'N';
130 const char jobvr =
'N';
134 Lapack::Dgeev(jobvl, jobvr, n, a.data(), n, wr.data(), wi.data(), &dum, 1,
135 &dum, 1, work.data(), work.size(), info);
136 BOOST_REQUIRE_EQUAL(info, 0);
138 return *std::max_element(wr.data(), wr.data() + n);
143 return *std::max_element(values.data(), values.data() + values.size());
148 const std::vector<NekDouble> diagonal = {4.0, 5.0, 6.0, 7.0, 30.0};
149 const std::vector<NekDouble> offDiagonal = {0.5, -0.35, 0.4, -0.2};
150 const int n = diagonal.size();
157 key.m_NekLinSysMaxIterations = 10;
158 key.m_NekLinSysTolerance = 1.0e-13;
175 BOOST_REQUIRE_EQUAL(computed.size(), n);
176 BOOST_CHECK_SMALL(std::abs(
MaxValue(computed) - reference) / reference,
182 const std::vector<NekDouble> diagonal = {4.0, 5.0, 6.0, 7.0, 30.0};
183 const std::vector<NekDouble> offDiagonal = {0.5, -0.35, 0.4, -0.2};
184 const int n = diagonal.size();
191 key.m_NekLinSysMaxIterations = n - 1;
192 key.m_NekLinSysTolerance = 1.0e-13;
193 key.m_LinSysMaxStorage = n - 1;
194 key.m_KrylovMaxHessMatBand = n;
212 BOOST_REQUIRE_EQUAL(computed.size(), n);
213 BOOST_CHECK_SMALL(std::abs(
MaxValue(computed) - reference) / reference,
LibUtilities::SessionReaderSharedPtr session
tBasePtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
const Array< OneD, NekDouble > & GetEigenValues()
void SetEigenValueFlags(const bool computeEV, const bool outputEV)
void SetFlagWarnings(bool in)
void SetSysOperators(const NekSysOperators &in)
int SolveSystem(const int nGlobal, const Array< OneD, const NekDouble > &pInput, Array< OneD, NekDouble > &pOutput, const int nDir=0)
void DefineNekSysLhsEval(FuncPointerT func, ObjectPointerT obj)
static SessionReaderSharedPtr CreateInstance(int argc, char *argv[])
Creates an instance of the SessionReader class.
std::vector< NekDouble > m_diagonal
BandedMatrixOperator(const std::vector< NekDouble > &diagonal, const std::vector< NekDouble > &offDiagonal)
std::vector< NekDouble > m_offDiagonal
void Apply(const Array< OneD, const NekDouble > &input, Array< OneD, NekDouble > &output, const bool &flag)
static void Dgeev(const char &uplo, const char &lrev, const int &n, const double *a, const int &lda, double *wr, double *wi, double *rev, const int &ldr, double *lev, const int &ldv, double *work, const int &lwork, int &info)
Solve general real matrix eigenproblem.
std::shared_ptr< SessionReader > SessionReaderSharedPtr
CommFactory & GetCommFactory()
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
SessionReaderSharedPtr CreateTestSession()
NekDouble MaxRealEigenvalueFromLapack(const std::vector< NekDouble > &matrix, const int n)
BOOST_AUTO_TEST_CASE(TestCGComputesMaximumEigenvalue)
NekDouble MaxValue(const Array< OneD, const NekDouble > &values)
std::vector< NekDouble > CreateBandedMatrix(const std::vector< NekDouble > &diagonal, const std::vector< NekDouble > &offDiagonal)