File: testExcitedLanczos.cpp

package info (click to toggle)
dmrgpp 6.06-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 113,900 kB
  • sloc: cpp: 80,986; perl: 14,772; ansic: 2,923; makefile: 83; sh: 17
file content (64 lines) | stat: -rw-r--r-- 1,714 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "CrsMatrix.h"
#include "LanczosSolver.h"
#include "Matrix.h"
#include "Random48.h" // <--- is this thread safe?

int main(int argc, char* argv[])
{
	typedef double RealType;
	typedef std::complex<double> ComplexType;
	typedef PsimagLite::ParametersForSolver<double> SolverParametersType;
	typedef PsimagLite::Vector<ComplexType>::Type VectorComplexType;
	typedef PsimagLite::Vector<RealType>::Type VectorRealType;

	if (argc != 2) {
		std::cout << "USAGE: " << argv[0] << " excited\n";
		return 1;
	}

	SizeType excited = atoi(argv[1]);

	SizeType n = 4;
	PsimagLite::Matrix<ComplexType> m(n, n);
	// fill m
	m(1, 2) = -0.5;
	m(2, 1) = PsimagLite::conj(m(1, 2));
	m(0, 0) = m(3, 3) = -0.25;
	m(1, 1) = m(2, 2) = 0.25;

	std::cout << "matrix\n"
		  << m << "\n";

	PsimagLite::CrsMatrix<ComplexType> msparse(m);

	SolverParametersType params;
	params.lotaMemory = true;
	params.tolerance = -1;
	params.options = "reortho";
	PsimagLite::LanczosSolver<SolverParametersType,
	    PsimagLite::CrsMatrix<ComplexType>,
	    VectorComplexType>
	    lanczosSolver(msparse, params);

	PsimagLite::Random48<double> myrng(time(0));
	VectorComplexType initialV(n, 0.0);
	for (SizeType i = 0; i < n; ++i)
		initialV[i] = myrng() - 0.5;

	double e1 = 0;
	VectorComplexType z1(n, 0.0);
	lanczosSolver.computeOneState(e1, z1, initialV, excited);
	std::cout << "energy1=" << e1 << "\n";
	std::cout << z1 << "\n";

	VectorRealType eigs(m.rows());
	PsimagLite::diag(m, eigs, 'V');
	for (SizeType i = 0; i < m.rows(); i++) {
		std::cerr << "eigs[" << i << "]=" << eigs[i] << "\n";
	}
	VectorRealType zeig(n, 0.0);
	for (SizeType i = 0; i < m.rows(); i++) {
		zeig[i] = PsimagLite::real(m(i, 0));
	}
	std::cout << m << "\n";
}