-
Notifications
You must be signed in to change notification settings - Fork 0
/
Wavefunction.cpp
202 lines (170 loc) · 5.06 KB
/
Wavefunction.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*
* File: Wavefunction.cpp
* Author: Sigve
*
* Created on February 4, 2012, 10:55 PM
*/
#include "Wavefunction.h"
#include <math.h>
#include "includes/lib.h"
#include "defines.h"
/*******************************************************************
*
* NAME : Wavefunction(int dim, int n_particles,
* double alpha, double beta, bool jastrow)
*
* DESCRIPTION : Constructor
*
*/
Wavefunction::Wavefunction(int dim, int n_particles, double alpha, double beta, bool jastrow, Orbital* orbital, Jastrow* jas)
: dim(dim), n_particles(n_particles), alpha(alpha), beta(beta), jastrow(jastrow), orbital(orbital), jas(jas) {
energy = 0;
slater = new Slater(dim, n_particles, orbital);
r_old = zeros(n_particles, dim);
r_new = zeros(n_particles, dim);
}
/*******************************************************************
*
* NAME : get_ratio();
*
* DESCRIPTION : Returns the R-ratio used in the Metropolis
* test.
*
*/
double Wavefunction::get_ratio() {
double R = slater->get_ratio();
if (jastrow) {
R *= jas->get_ratio(r_new, r_old);
}
return R;
}
/*******************************************************************
*
* NAME : evaluate(mat r)
*
* DESCRIPTION : Used for numerical derivates to evaulate the WF in r.
*
*/
double Wavefunction::evaluate(mat r) {
double psi;
psi = slater->evaluate(r);
// Adding the Jastrow part
if (jastrow)
psi *= exp(jas->evaluate(r));
return psi;
}
/*******************************************************************
*
* NAME : q_force(mat r)
*
*
* DESCRIPTION : q_force returns a matrix with the total
* quantum force on the particles.
*
*/
mat Wavefunction::q_force() {
mat q_f = zeros(n_particles, dim);
//#if NUMERICAL
#if 0
double h = 0.05;
mat r_plus = zeros(n_particles, dim);
mat r_minus = zeros(n_particles, dim);
// Initiating r_plus and r_minus.
r_plus = r_new;
r_minus = r_new;
// Calculating the Quantum Force numerically.
for (int i = 0; i < n_particles; i++) {
for (int j = 0; j < dim; j++) {
r_plus(i, j) += h;
r_minus(i, j) -= h;
q_f(i, j) = 2 * (evaluate(r_plus) - evaluate(r_minus)) / (2 * h * evaluate(r_new));
r_plus(i, j) = r_new(i, j);
r_minus(i, j) = r_new(i, j);
}
}
#else
rowvec gradient_slater;
rowvec gradient_jastrow;
double R = slater->get_ratio();
for (int i = 0; i < n_particles; i++) {
// Finding the Orbitals' gradient.
slater->compute_gradient(i);
gradient_slater = slater->get_gradient();
// Finding the Jastrow's gradient.
jas->compute_gradient(r_new, i);
gradient_jastrow = jas->get_gradient();
q_f.row(i) = 2 * (gradient_jastrow + gradient_slater)/R;
}
#endif
return q_f;
}
/*******************************************************************
*
* NAME : evaluate_new()
*
* DESCRIPTION : evalutates the wave function in the new position.
*
*/
void Wavefunction::evaluate_new() {
slater->set_position(r_new, active_particle);
slater->update_matrix();
}
/*******************************************************************
*
* NAME : accept_move()
*
* DESCRIPTION : The new move is accepted.
*
*/
void Wavefunction::accept_move() {
r_old = r_new;
slater->update_inverse();
slater->accept_new_position();
calculate_laplacian();
}
/*******************************************************************
*
* NAME : set_r_new(mat r_new)
*
* DESCRIPTION : Sets a new position.
*
*/
void Wavefunction::set_r_new(mat r_new, int active_particle) {
this->r_new = r_new;
this->active_particle = active_particle;
}
/*******************************************************************
*
* NAME : init_slater()
*
* DESCRIPTION : Initializes the Slater matrix with
* the initial position matrix.
*
*/
void Wavefunction::init_slater() {
slater->set_position(r_new, active_particle);
slater->init();
}
/*******************************************************************
*
* NAME : calculate_laplacian(mat r)
*
* DESCRIPTION : Calculates the Laplcian.
*
*/
void Wavefunction::calculate_laplacian() {
energy = 0;
// Looping through all particles
for (int i = 0; i < n_particles; i++) {
// Finding the Orbitals' Laplacian.
slater->compute_gradient(i);
energy += slater->get_laplacian(i);
// Finding the Jastrow factors Laplacian
jas->compute_gradient(r_old, i);
energy += jas->get_laplacian(r_old, i);
// Dot product between the gradients of the orbital- and Jastrow function.
rowvec gradient_orbital = slater->get_gradient();
rowvec gradient_jastrow = jas->get_gradient();
energy += 2 * dot(gradient_orbital, gradient_jastrow);
}
}