Skip to content

Commit a9f917e

Browse files
authored
Merge pull request #2 from minyez/develop
a G0W0 class
2 parents e5b257f + d7a955b commit a9f917e

File tree

3 files changed

+167
-0
lines changed

3 files changed

+167
-0
lines changed

include/RI/physics/GW.h

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// ===================
2+
// Author: Minye Zhang, almost completely copied from Exx.h
3+
// date: 2022.12.18
4+
// ===================
5+
6+
#pragma once
7+
8+
// #include "Exx_Post_2D.h"
9+
#include "../global/Global_Func-2.h"
10+
#include "../global/Tensor.h"
11+
#include "../ri/LRI.h"
12+
13+
#include <mpi.h>
14+
#include <array>
15+
#include <map>
16+
17+
namespace RI
18+
{
19+
20+
//! class to compute the correlation self-energy in G0W0 approximation by space-time method
21+
template<typename TA, typename Tcell, std::size_t Ndim, typename Tdata>
22+
class G0W0
23+
{
24+
public:
25+
using TC = std::array<Tcell,Ndim>;
26+
using TAC = std::pair<TA,TC>;
27+
using Tdata_real = Global_Func::To_Real_t<Tdata>;
28+
constexpr static std::size_t Npos = Ndim; // tmp
29+
using Tatom_pos = std::array<double,Npos>; // tmp
30+
31+
void set_parallel(
32+
const MPI_Comm &mpi_comm,
33+
const std::map<TA,Tatom_pos> &atoms_pos,
34+
const std::array<Tatom_pos,Ndim> &latvec,
35+
const std::array<Tcell,Ndim> &period);
36+
37+
void set_Cs(
38+
const std::map<TA, std::map<TAC, Tensor<Tdata>>> &Cs,
39+
const Tdata_real &threshold_C);
40+
void set_csm_threshold(
41+
const Tdata_real &threshold) { this->lri.csm.set_threshold(threshold); }
42+
43+
void cal_Sigc(
44+
const std::map<TA, std::map<TAC, Tensor<Tdata>>> gf_tau,
45+
const Tdata_real &threshold_G,
46+
const std::map<TA, std::map<TAC, Tensor<Tdata>>> Wc_tau,
47+
const Tdata_real &threshold_W);
48+
49+
std::map<TA, std::map<TAC, Tensor<Tdata>>> Sigc_tau;
50+
51+
public:
52+
LRI<TA,Tcell,Ndim,Tdata> lri;
53+
54+
struct Flag_Finish
55+
{
56+
bool stru=false;
57+
bool C=false;
58+
};
59+
Flag_Finish flag_finish;
60+
61+
MPI_Comm mpi_comm;
62+
std::map<TA,Tatom_pos> atoms_pos;
63+
std::array<Tatom_pos,Ndim> latvec;
64+
std::array<Tcell,Ndim> period;
65+
};
66+
67+
}
68+
69+
#include "GW.hpp"

include/RI/physics/GW.hpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// ===================
2+
// Author: Minye Zhang, almost completely copied from Exx.hpp
3+
// date: 2022.12.18
4+
// ===================
5+
#pragma once
6+
7+
#include "GW.h"
8+
#include "../ri/Label.h"
9+
10+
namespace RI
11+
{
12+
13+
template<typename TA, typename Tcell, std::size_t Ndim, typename Tdata>
14+
void G0W0<TA,Tcell,Ndim,Tdata>::set_parallel(
15+
const MPI_Comm &mpi_comm_in,
16+
const std::map<TA,Tatom_pos> &atoms_pos_in,
17+
const std::array<Tatom_pos,Ndim> &latvec_in,
18+
const std::array<Tcell,Ndim> &period_in)
19+
{
20+
this->mpi_comm = mpi_comm_in;
21+
this->atoms_pos = atoms_pos_in;
22+
this->latvec = latvec_in;
23+
this->period = period_in;
24+
25+
this->lri.set_parallel(this->mpi_comm, this->atoms_pos, this->latvec, this->period);
26+
this->flag_finish.stru = true;
27+
//if()
28+
// this->post_2D.set_parallel(this->mpi_comm, this->atoms_pos, this->period);
29+
}
30+
31+
template<typename TA, typename Tcell, std::size_t Ndim, typename Tdata>
32+
void G0W0<TA,Tcell,Ndim,Tdata>::set_Cs(
33+
const std::map<TA, std::map<TAC, Tensor<Tdata>>> &Cs,
34+
const Tdata_real &threshold_C)
35+
{
36+
this->lri.set_tensors_map2( Cs, Label::ab::a, threshold_C );
37+
this->lri.set_tensors_map2( Cs, Label::ab::b, threshold_C );
38+
this->flag_finish.C = true;
39+
}
40+
41+
42+
template <typename TA, typename Tcell, std::size_t Ndim, typename Tdata>
43+
void G0W0<TA, Tcell, Ndim, Tdata>::cal_Sigc(
44+
const std::map<TA, std::map<TAC, Tensor<Tdata>>> gf_tau,
45+
const Tdata_real &threshold_G,
46+
const std::map<TA, std::map<TAC, Tensor<Tdata>>> Wc_tau,
47+
const Tdata_real &threshold_W)
48+
{
49+
assert(this->flag_finish.stru);
50+
assert(this->flag_finish.C);
51+
// setup Green's function
52+
this->lri.set_tensors_map2( gf_tau, Label::ab::a1b1, threshold_G );
53+
this->lri.set_tensors_map2( gf_tau, Label::ab::a1b2, threshold_G );
54+
this->lri.set_tensors_map2( gf_tau, Label::ab::a2b1, threshold_G );
55+
this->lri.set_tensors_map2( gf_tau, Label::ab::a2b2, threshold_G );
56+
57+
// setup screened Coulomb interaction
58+
this->lri.set_tensors_map2( Wc_tau, Label::ab::a0b0, threshold_W );
59+
60+
std::vector<std::map<TA, std::map<TAC, Tensor<Tdata>>>> Sigc_vec(1);
61+
this->lri.coefficients = {nullptr};
62+
this->lri.cal(
63+
{Label::ab_ab::a0b0_a1b1,
64+
Label::ab_ab::a0b0_a1b2,
65+
Label::ab_ab::a0b0_a2b1,
66+
Label::ab_ab::a0b0_a2b2},
67+
Sigc_vec);
68+
this->Sigc_tau = std::move(Sigc_vec[0]);
69+
}
70+
71+
} // namespace RI

unittests/physics/GW-test.hpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// ===================
2+
// Author: Minye Zhang, almost copied from Exx-test.hpp
3+
// date: 2022.06.02
4+
// ===================
5+
6+
#pragma once
7+
8+
#include "RI/physics/GW.h"
9+
// #include <complex>
10+
11+
namespace GW_Test
12+
{
13+
template<typename Tdata>
14+
void main(int argc, char *argv[])
15+
{
16+
int mpi_init_provide;
17+
MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &mpi_init_provide);
18+
19+
RI::G0W0<int,int,1,Tdata> g0w0;
20+
g0w0.set_parallel(MPI_COMM_WORLD, {{1,{0}},{2,{4}}}, {}, {1});
21+
g0w0.set_csm_threshold(1E-4);
22+
g0w0.set_Cs({}, 1E-4);
23+
g0w0.cal_Sigc({}, 1E-4, {}, 1E-4);
24+
25+
MPI_Finalize();
26+
}
27+
}

0 commit comments

Comments
 (0)