1
0
mirror of https://github.com/TREX-CoE/qmc-lttc.git synced 2024-12-21 11:53:58 +01:00

Solutions in C up to 2.2

This commit is contained in:
Panadestein 2021-04-25 00:33:50 +02:00
parent b820c75e3c
commit b15ea4b02f
3 changed files with 77 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
plt_dat
data

48
hydrogen.h Normal file
View File

@ -0,0 +1,48 @@
#include <math.h>
#include <stdio.h>
double potential(double *r, const int l) {
double pot;
pot = 0.0;
for (int i = 0; i < l; ++i) {
pot += r[i] * r[i];
}
if (pot > 0.0) {
return -1.0 / sqrt(pot);
}
return -1;
}
double psi(double a, double *r, const int l) {
double psival, rnorm;
psival = 0.0;
rnorm = 0.0;
for (int i = 0; i < l; ++i) {
rnorm += r[i]*r[i];
}
rnorm = sqrt(rnorm);
psival = exp(-a * rnorm);
return psival;
}
double kinetic(double a, double *r, const int l) {
double rnorm;
for (int i = 0; i < l; ++i) {
rnorm += r[i]*r[i];
}
rnorm = sqrt(rnorm);
return a * (1 / rnorm - 0.5 * a);
}
double e_loc(double a, double *r, const int l) {
return kinetic(a, r, l) + potential(r, l);
}

27
plot_hydrogen.c Normal file
View File

@ -0,0 +1,27 @@
#include "hydrogen.h"
int main() {
const double a[6] = {0.1, 0.2, 0.5, 1., 1.5, 2.};
const int sizex = 50;
double x[sizex], dx;
dx = 10.0 / (sizex - 1);
for (int i = 0; i < sizex; ++i) {
x[i] = -5.0 + (i - 1) * dx;
}
FILE * fil;
fil = fopen("./data", "w+");
for (int i; i < 6; ++i) {
for (int j = 0; j < sizex; ++j) {
fprintf(fil, "%lf %lf\n", x[j], e_loc(a[i], &x[j], 1));
}
fprintf(fil, "\n\n");
}
fclose(fil);
return 0;
}