generated from TREX-CoE/qmc-lttc
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathqmc_uniform.c
51 lines (40 loc) · 1.04 KB
/
qmc_uniform.c
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
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include <time.h>
#include <stddef.h> // for size_t
#include "hydrogen.h"
#include "qmc_stats.h" // for ave_error
void uniform_montecarlo(double a, size_t nmax, double *energy) {
size_t istep;
double normalization, r[3], w, f;
*energy = 0.0;
normalization = 0.0;
for (istep = 0; istep < nmax; istep++) {
for (int i = 0; i < 3; i++) {
r[i] = drand48();
}
r[0] = -5.0 + 10.0 * r[0];
r[1] = -5.0 + 10.0 * r[1];
r[2] = -5.0 + 10.0 * r[2];
f = psi(a, r);
w = f*f;
*energy += w * e_loc(a, r);
normalization += w;
}
*energy = *energy / normalization;
}
int main(void) {
#define a 1.2
#define nmax 100000
#define nruns 30
double X[nruns];
double ave, err;
srand48(time(NULL));
for (size_t irun = 0; irun < nruns; irun++) {
uniform_montecarlo(a, nmax, &X[irun]);
}
ave_error(X, nruns, &ave, &err);
printf("E = %f +/- %f\n", ave, err);
return 0;
}