QMCPACK
test_LinearMethod.cpp
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2023 QMCPACK developers.
6 //
7 // File developed by: Mark Dewing, markdewing@gmail.com
8 //
9 // File created by: Mark Dewing, markdewing@gmail.com
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 #include "catch.hpp"
15 #include <random>
16 
17 
18 namespace qmcplusplus
19 {
20 
22 
23 TEST_CASE("selectEigenvalues", "[drivers]")
24 {
25  LinearMethod lm;
26  const int Ne = 4; // Number of eigenvalues
27  const int Nv = 4; // Size of eigenvectors
28 
29  // For direct solvers, Ne == Nv, but for iterative solvers we may have Ne <= Nv;
30 
31  Matrix<Real> evecs(Ne, Nv);
32  evecs = 1.0;
33  evecs(0, 0) = 2.0;
34  evecs(1, 0) = 3.0;
35  std::vector<Real> evals{-1.2, -1.5}; // size Ne
36  std::vector<Real> selected_evec(Nv);
37  Real zerozero = -1.0;
38  Real selected_eval = lm.selectEigenvalue(evals, evecs, zerozero, selected_evec);
39 
40  // Selects the closest to zerozero - 2.0
41  CHECK(selected_eval == Approx(-1.5));
42 
43  CHECK(selected_evec[0] == Approx(1.0));
44  CHECK(selected_evec[1] == Approx(1.0 / 3.0));
45 }
46 
47 } // namespace qmcplusplus
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
QTBase::RealType RealType
Definition: Configuration.h:58
LinearMethod related functions.
TEST_CASE("complex_helper", "[type_traits]")
ForceBase::Real Real
Definition: ForceBase.cpp:26
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))
static Real selectEigenvalue(std::vector< Real > &eigenvals, Matrix< Real > &eigenvectors, Real zerozero, std::vector< Real > &ev)
Select eigenvalue and return corresponding scaled eigenvector.