Skip to content

Commit 01e6f82

Browse files
committed
update nclibxc and add input parameters
1 parent 1a66c24 commit 01e6f82

File tree

16 files changed

+57443
-37790
lines changed

16 files changed

+57443
-37790
lines changed

source/module_hamilt_general/module_xc/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ add_library(
2424
NCLibxc/LebedevGrid.cpp
2525
NCLibxc/FibonacciGrid.cpp
2626
NCLibxc/FibonacciGrid.h
27+
NCLibxc/benchmark_tests.cpp
28+
NCLibxc/gga.cpp
29+
NCLibxc/lda.cpp
30+
NCLibxc/mgga.cpp
31+
NCLibxc/math.cpp
32+
NCLibxc/print.cpp
33+
NCLibxc/torque.cpp
2734
)
2835

2936
if(ENABLE_COVERAGE)

source/module_hamilt_general/module_xc/NCLibxc/NCLibxc.cpp

Lines changed: 374 additions & 37732 deletions
Large diffs are not rendered by default.

source/module_hamilt_general/module_xc/NCLibxc/NCLibxc.h

Lines changed: 128 additions & 0 deletions
Large diffs are not rendered by default.

source/module_hamilt_general/module_xc/NCLibxc/benchmark_tests.cpp

Lines changed: 643 additions & 0 deletions
Large diffs are not rendered by default.

source/module_hamilt_general/module_xc/NCLibxc/gga.cpp

Lines changed: 37039 additions & 0 deletions
Large diffs are not rendered by default.

source/module_hamilt_general/module_xc/NCLibxc/interface_to_libxc.cpp

Lines changed: 1283 additions & 3 deletions
Large diffs are not rendered by default.

source/module_hamilt_general/module_xc/NCLibxc/interface_to_libxc.h

Lines changed: 289 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include "NCLibxc.h"
2+
#include "interface_to_libxc.h"
3+
#include <vector>
4+
#include <xc.h>
5+
6+
7+
///////////////////////////////////////////////////////////////////////////////////lda
8+
9+
// post-processing of libxc. get partial derivatives from libxc and integrate them to get the 0th,1st,2nd derivatives of the functional
10+
//Note that e is the exchange and correlation energy per electron per volume. You need to multiply by \rho before the integration.
11+
/*
12+
v1=0, v2=1, f1=0,0, f2=0,1, f3=1,1
13+
*/
14+
15+
void NCLibxc::postlibxc_lda(int xc_id, const std::vector<double>& rho_up, const std::vector<double>& rho_down,
16+
std::vector<double>& e, std::vector<double>& v1, std::vector<double>& v2,
17+
std::vector<double>& f1, std::vector<double>& f2, std::vector<double>& f3)
18+
{
19+
LibxcInterface libxc(xc_id, true); // xc_id now passed from the caller
20+
21+
std::vector<double> exc = libxc.lda_exc(rho_up, rho_down);
22+
std::vector<double> vrho_1(rho_up.size()), vrho_2(rho_down.size());
23+
libxc.lda_vxc(rho_up, rho_down, vrho_1, vrho_2);
24+
25+
std::vector<double> v2rho2_1(rho_up.size()), v2rho2_2(rho_down.size()), v2rho2_3(rho_up.size());
26+
libxc.lda_fxc(rho_up, rho_down, v2rho2_1, v2rho2_2, v2rho2_3);
27+
28+
29+
e.resize(rho_up.size());
30+
v1.resize(rho_up.size());
31+
v2.resize(rho_down.size());
32+
f1.resize(rho_up.size());
33+
f2.resize(rho_down.size());
34+
f3.resize(rho_up.size());
35+
36+
for (size_t i = 0; i < rho_up.size(); ++i) {
37+
e[i] = exc[i] ;
38+
v1[i] = vrho_1[i] ;
39+
v2[i] = vrho_2[i] ;
40+
f1[i] = v2rho2_1[i] ;
41+
f2[i] = v2rho2_2[i] ;
42+
f3[i] = v2rho2_3[i] ;
43+
}
44+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#include "NCLibxc.h"
2+
#include <iostream>
3+
#include <vector>
4+
#include <array>
5+
#include <cmath>
6+
#include <complex>
7+
#include <iomanip>
8+
#include <stdexcept>
9+
#include <fstream>
10+
11+
12+
///////////////////////////////////////////////////////////////////////////////////
13+
//Matrix
14+
15+
16+
// Pauli matrix initialization
17+
const Matrix2x2 NCLibxc::sigma_x = {{{std::complex<double>(0.0, 0.0), std::complex<double>(1.0, 0.0)},
18+
{std::complex<double>(1.0, 0.0), std::complex<double>(0.0, 0.0)}}};
19+
20+
const Matrix2x2 NCLibxc::sigma_y = {{{std::complex<double>(0.0, 0.0), std::complex<double>(0.0, -1.0)},
21+
{std::complex<double>(0.0, 1.0), std::complex<double>(0.0, 0.0)}}};
22+
23+
const Matrix2x2 NCLibxc::sigma_z = {{{std::complex<double>(1.0, 0.0), std::complex<double>(0.0, 0.0)},
24+
{std::complex<double>(0.0, 0.0), std::complex<double>(-1.0, 0.0)}}};
25+
26+
// matrix addition
27+
Matrix2x2 NCLibxc::add(const Matrix2x2 &a, const Matrix2x2 &b)
28+
{
29+
Matrix2x2 result;
30+
for (int i = 0; i < 2; ++i)
31+
{
32+
for (int j = 0; j < 2; ++j)
33+
{
34+
result[i][j] = a[i][j] + b[i][j];
35+
}
36+
}
37+
return result;
38+
}
39+
40+
// matrix scalar multiplication
41+
Matrix2x2 NCLibxc::scalar_multiply(const std::complex<double> &scalar, const Matrix2x2 &matrix)
42+
{
43+
Matrix2x2 result;
44+
for (int i = 0; i < 2; ++i)
45+
{
46+
for (int j = 0; j < 2; ++j)
47+
{
48+
result[i][j] = scalar * matrix[i][j];
49+
}
50+
}
51+
return result;
52+
}
53+
54+
55+
// construct a Pauli matrix based on x, y, z
56+
Matrix2x2 NCLibxc::construct_pauli_matrix(double x, double y, double z)
57+
{
58+
Matrix2x2 pauli_matrix = add(add(scalar_multiply(x, sigma_x), scalar_multiply(y, sigma_y)), scalar_multiply(z, sigma_z));
59+
return pauli_matrix;
60+
}
61+
62+
// identity matrix
63+
Matrix2x2 NCLibxc::identity_matrix()
64+
{
65+
Matrix2x2 result;
66+
result[0][0] = 1.0;
67+
result[0][1] = 0.0;
68+
result[1][0] = 0.0;
69+
result[1][1] = 1.0;
70+
return result;
71+
}
72+
///////////////////////////////////////////////////////////////////////////////////

source/module_hamilt_general/module_xc/NCLibxc/mgga.cpp

Lines changed: 17389 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)