Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions include/RI/physics/GW.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// ===================
// Author: Minye Zhang, almost completely copied from Exx.h
// date: 2022.12.18
// ===================

#pragma once

// #include "Exx_Post_2D.h"
#include "../global/Global_Func-2.h"
#include "../global/Tensor.h"
#include "../ri/LRI.h"

#include <mpi.h>
#include <array>
#include <map>

namespace RI
{

//! class to compute the correlation self-energy in G0W0 approximation by space-time method
template<typename TA, typename Tcell, std::size_t Ndim, typename Tdata>
class G0W0
{
public:
using TC = std::array<Tcell,Ndim>;
using TAC = std::pair<TA,TC>;
using Tdata_real = Global_Func::To_Real_t<Tdata>;
constexpr static std::size_t Npos = Ndim; // tmp
using Tatom_pos = std::array<double,Npos>; // tmp

void set_parallel(
const MPI_Comm &mpi_comm,
const std::map<TA,Tatom_pos> &atoms_pos,
const std::array<Tatom_pos,Ndim> &latvec,
const std::array<Tcell,Ndim> &period);

void set_Cs(
const std::map<TA, std::map<TAC, Tensor<Tdata>>> &Cs,
const Tdata_real &threshold_C);
void set_csm_threshold(
const Tdata_real &threshold) { this->lri.csm.set_threshold(threshold); }

void cal_Sigc(
const std::map<TA, std::map<TAC, Tensor<Tdata>>> gf_tau,
const Tdata_real &threshold_G,
const std::map<TA, std::map<TAC, Tensor<Tdata>>> Wc_tau,
const Tdata_real &threshold_W);

std::map<TA, std::map<TAC, Tensor<Tdata>>> Sigc_tau;

public:
LRI<TA,Tcell,Ndim,Tdata> lri;

struct Flag_Finish
{
bool stru=false;
bool C=false;
};
Flag_Finish flag_finish;

MPI_Comm mpi_comm;
std::map<TA,Tatom_pos> atoms_pos;
std::array<Tatom_pos,Ndim> latvec;
std::array<Tcell,Ndim> period;
};

}

#include "GW.hpp"
71 changes: 71 additions & 0 deletions include/RI/physics/GW.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// ===================
// Author: Minye Zhang, almost completely copied from Exx.hpp
// date: 2022.12.18
// ===================
#pragma once

#include "GW.h"
#include "../ri/Label.h"

namespace RI
{

template<typename TA, typename Tcell, std::size_t Ndim, typename Tdata>
void G0W0<TA,Tcell,Ndim,Tdata>::set_parallel(
const MPI_Comm &mpi_comm_in,
const std::map<TA,Tatom_pos> &atoms_pos_in,
const std::array<Tatom_pos,Ndim> &latvec_in,
const std::array<Tcell,Ndim> &period_in)
{
this->mpi_comm = mpi_comm_in;
this->atoms_pos = atoms_pos_in;
this->latvec = latvec_in;
this->period = period_in;

this->lri.set_parallel(this->mpi_comm, this->atoms_pos, this->latvec, this->period);
this->flag_finish.stru = true;
//if()
// this->post_2D.set_parallel(this->mpi_comm, this->atoms_pos, this->period);
}

template<typename TA, typename Tcell, std::size_t Ndim, typename Tdata>
void G0W0<TA,Tcell,Ndim,Tdata>::set_Cs(
const std::map<TA, std::map<TAC, Tensor<Tdata>>> &Cs,
const Tdata_real &threshold_C)
{
this->lri.set_tensors_map2( Cs, Label::ab::a, threshold_C );
this->lri.set_tensors_map2( Cs, Label::ab::b, threshold_C );
this->flag_finish.C = true;
}


template <typename TA, typename Tcell, std::size_t Ndim, typename Tdata>
void G0W0<TA, Tcell, Ndim, Tdata>::cal_Sigc(
const std::map<TA, std::map<TAC, Tensor<Tdata>>> gf_tau,
const Tdata_real &threshold_G,
const std::map<TA, std::map<TAC, Tensor<Tdata>>> Wc_tau,
const Tdata_real &threshold_W)
{
assert(this->flag_finish.stru);
assert(this->flag_finish.C);
// setup Green's function
this->lri.set_tensors_map2( gf_tau, Label::ab::a1b1, threshold_G );
this->lri.set_tensors_map2( gf_tau, Label::ab::a1b2, threshold_G );
this->lri.set_tensors_map2( gf_tau, Label::ab::a2b1, threshold_G );
this->lri.set_tensors_map2( gf_tau, Label::ab::a2b2, threshold_G );

// setup screened Coulomb interaction
this->lri.set_tensors_map2( Wc_tau, Label::ab::a0b0, threshold_W );

std::vector<std::map<TA, std::map<TAC, Tensor<Tdata>>>> Sigc_vec(1);
this->lri.coefficients = {nullptr};
this->lri.cal(
{Label::ab_ab::a0b0_a1b1,
Label::ab_ab::a0b0_a1b2,
Label::ab_ab::a0b0_a2b1,
Label::ab_ab::a0b0_a2b2},
Sigc_vec);
this->Sigc_tau = std::move(Sigc_vec[0]);
}

} // namespace RI
27 changes: 27 additions & 0 deletions unittests/physics/GW-test.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// ===================
// Author: Minye Zhang, almost copied from Exx-test.hpp
// date: 2022.06.02
// ===================

#pragma once

#include "RI/physics/GW.h"
// #include <complex>

namespace GW_Test
{
template<typename Tdata>
void main(int argc, char *argv[])
{
int mpi_init_provide;
MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &mpi_init_provide);

RI::G0W0<int,int,1,Tdata> g0w0;
g0w0.set_parallel(MPI_COMM_WORLD, {{1,{0}},{2,{4}}}, {}, {1});
g0w0.set_csm_threshold(1E-4);
g0w0.set_Cs({}, 1E-4);
g0w0.cal_Sigc({}, 1E-4, {}, 1E-4);

MPI_Finalize();
}
}