-
Notifications
You must be signed in to change notification settings - Fork 1
/
ho_test.cpp
73 lines (60 loc) · 1.96 KB
/
ho_test.cpp
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
65
66
67
68
69
70
71
72
73
#include "ho.h"
#include <fstream>
#include <iomanip>
#include <iostream>
int main()
{
int npts = 3001;
int n = 10;
int l = 20;
double b = 2.03644;
// Array for wavefunctions.
Eigen::ArrayXXd psi(n + 1, npts);
// Map [0 to ∞) to [0 to 1)
Eigen::ArrayXd x = Eigen::ArrayXd::LinSpaced(npts, 0, 1.0);
Eigen::ArrayXd r = x / (1.0 - x);
Eigen::ArrayXd dr = 1 / ((1.0 - x) * (1.0 - x));
try {
basis_func::ho::WaveFunctionsUptoMaxN(psi, r, n, l, b,
basis_func::Space::coordinate);
}
catch (std::exception& e) {
std::cout << e.what() << "\n";
}
Eigen::ArrayXXd output(npts - 1, 2);
output.col(0) = r.head(npts - 1);
output.col(1) = psi.row(n).head(npts - 1);
Eigen::IOFormat fmt(7, Eigen::DontAlignCols, " ", "\n");
std::ofstream file;
file.open("ho_wf.txt");
file << output.format(fmt) << "\n";
file.close();
// Wavefunction norm.
Eigen::ArrayXd psin2 = psi.row(n).square();
psin2 *= r * r * dr;
psin2.head(1) *= 0.5;
psin2.tail(1) = 0;
double norm_nn = psin2.sum() / npts;
Eigen::ArrayXd psinn1 = psi.row(n) * psi.row(n - 1);
psinn1 *= r * r * dr;
psinn1.head(1) *= 0.5;
psinn1.tail(1) = 0;
double norm_nn1 = psinn1.sum() / npts;
std::cout << "∫R_{nl} R_{nl} r^2 dr = " << std::setprecision(10) << std::fixed
<< norm_nn << "\n";
std::cout << "∫R_{nl} R_{n-1l} r^2 dr = " << norm_nn1 << "\n";
// Check if all the wave functions are normalized by matrix multiplication.
// Diagonal elements should be ~1. Off-diagonal elements should be ~0.
// Trapezoid weights.
Eigen::ArrayXd wt = Eigen::ArrayXd::Ones(npts);
wt.head(1) *= 0.5;
wt.tail(2) *= 0.5;
wt /= npts;
psi.col(npts - 1) = 0;
Eigen::ArrayXXd right_psi(n + 1, npts);
right_psi = psi.transpose().colwise() * (wt * r.square() * dr);
right_psi.row(npts - 1) = 0;
Eigen::ArrayXXd norms(n + 1, npts);
norms = (psi.matrix() * right_psi.matrix()).array();
std::cout << norms << "\n";
}