ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
ri_2d_comm.h
Go to the documentation of this file.
1//=======================
2// AUTHOR : Peize Lin
3// DATE : 2022-08-17
4//=======================
5
6#ifndef RI_2D_COMM_H
7#define RI_2D_COMM_H
8
11#include "source_cell/klist.h"
12
13#include <RI/global/Tensor.h>
14#include <RI/ri/Cell_Nearest.h>
15#include <array>
16#include <deque>
17#include <map>
18#include <mpi.h>
19#include <set>
20#include <tuple>
21#include <vector>
22
23namespace RI_2D_Comm
24{
25using TA = int;
26using Tcell = int;
27static const size_t Ndim = 3;
28using TC = std::array<Tcell, Ndim>;
29using TAC = std::pair<TA, TC>;
30
31// public:
32template <typename Tdata, typename Tmatrix>
33extern std::vector<std::map<TA, std::map<TAC, RI::Tensor<Tdata>>>> split_m2D_ktoR(
34 const UnitCell& ucell,
35 const K_Vectors& kv,
36 const std::vector<const Tmatrix*>& mks_2D,
37 const Parallel_Blkcyclic& pv,
38 const int nspin,
39 const bool spgsym = false);
40
41template <typename Tdata, typename Tmatrix>
42extern std::vector<std::map<TA, std::map<TAC, RI::Tensor<Tdata>>>> split_m2D_ktoR_gamma(
43 const UnitCell& ucell,
44 const std::vector<const Tmatrix*>& mks_2D,
45 const Parallel_Blkcyclic& pv,
46 const int nspin);
47
48template <typename Tdata, typename Tmatrix>
49extern std::vector<std::map<TA, std::map<TAC, RI::Tensor<Tdata>>>> split_m2D_ktoR_k(
50 const UnitCell& ucell,
51 const K_Vectors& kv,
52 const std::vector<const Tmatrix*>& mks_2D,
53 const Parallel_Blkcyclic& pv,
54 const int nspin,
55 const bool spgsym = false);
56
57 // judge[is] = {s0, s1}
58 extern std::vector<std::tuple<std::set<TA>, std::set<TA>>>
59 get_2D_judge(const UnitCell& ucell, const Parallel_Blkcyclic& pv);
60
61 template<typename Tdata, typename TK>
62 extern void add_Hexx(
63 const UnitCell& ucell,
64 const K_Vectors& kv,
65 const int ik,
66 const double alpha,
67 const std::vector<std::map<TA, std::map<TAC, RI::Tensor<Tdata>>>>& Hs,
68 const Parallel_Orbitals& pv,
69 TK* hk);
70
71 template<typename Tdata, typename TR>
72 extern void add_HexxR(
73 const int current_spin,
74 const double alpha,
75 const std::vector<std::map<TA, std::map<TAC, RI::Tensor<Tdata>>>>& Hs,
76 const Parallel_Orbitals& pv,
77 const int npol,
79 const RI::Cell_Nearest<int, int, 3, double, 3>* const cell_nearest = nullptr);
80
81 template<typename Tdata>
82 extern std::vector<std::vector<Tdata>> Hexxs_to_Hk(
83 const K_Vectors &kv,
84 const Parallel_Orbitals &pv,
85 const std::vector< std::map<TA, std::map<TAC, RI::Tensor<Tdata>>>> &Hexxs,
86 const int ik);
87 template<typename Tdata>
88 std::vector<std::vector<Tdata>> pulay_mixing(
89 const Parallel_Orbitals &pv,
90 std::deque<std::vector<std::vector<Tdata>>> &Hk_seq,
91 const std::vector<std::vector<Tdata>> &Hk_new,
92 const double mixing_beta,
93 const std::string mixing_mode);
94
95 // DM(R) format conversion: the real-space (DM(R)) counterpart of split_m2D_ktoR,
96 // and the inverse of add_HexxR. dm_container is DensityMatrix::get_dmr_vec():
97 // nspin==1 : size 1 (container 0 -> spin-block 0)
98 // nspin==2 : size 2 (container is -> spin-block is)
99 // nspin==4 : size 1 (container 0 holds the 2x2 npol blocks -> spin-blocks 0,1,2,3)
100 template <typename TR, typename Tdata>
101 extern std::vector<std::map<TA, std::map<TAC, RI::Tensor<Tdata>>>> dm_container_to_Ds(
102 const std::vector<hamilt::HContainer<TR>*>& dm_container,
103 const UnitCell& ucell,
104 const Parallel_Orbitals& pv,
105 const int nspin);
106
107//private:
108 extern std::vector<int> get_ik_list(const K_Vectors &kv, const int is_k);
109 extern std::tuple<int,int,int> get_iat_iw_is_block(const UnitCell& ucell,const int& iwt);
110 extern int get_is_block(const int is_k, const int is_row_b, const int is_col_b);
111 extern std::tuple<int,int> split_is_block(const int is_b);
112 extern int get_iwt(const UnitCell& ucell, const int iat, const int iw_b, const int is_b);
113
114 template <typename TA, typename TAC, typename T>
115 extern std::map<TA, std::map<TAC, T>> comm_map2_first(const MPI_Comm& mpi_comm,
116 const std::map<TA, std::map<TAC, T>>& Ds_in,
117 const std::set<TA>& s0,
118 const std::set<TA>& s1);
119 template <typename TA, typename TAC, typename T, typename Tjudge>
120 extern std::map<TA, std::map<TAC, T>> comm_map2(const MPI_Comm& mpi_comm,
121 const std::map<TA, std::map<TAC, T>>& Ds_in,
122 const Tjudge& judge);
123 template <typename Tkey, typename Tvalue>
124 extern void set_value_add(Tkey&& key, Tvalue&& value, std::map<Tkey, Tvalue>& data);
125 template <typename Tkey0, typename Tkey1, typename Tvalue>
126 extern void set_value_add(std::tuple<Tkey0, Tkey1>&& key,
127 Tvalue&& value,
128 std::map<Tkey0, std::map<Tkey1, Tvalue>>& data);
129 template <typename Tkey, typename Tvalue>
130 extern void add_datas(std::map<Tkey, Tvalue>&& data_local, std::map<Tkey, Tvalue>& data_recv);
131 template <typename Tkey0, typename Tkey1, typename Tvalue>
132 extern void add_datas(std::map<Tkey0, std::map<Tkey1, Tvalue>>&& data_local,
133 std::map<Tkey0, std::map<Tkey1, Tvalue>>& data_recv);
134} // namespace RI_2D_Comm
135
136#include "ri_2d_comm.hpp"
137
138#endif
Class for k-points management.
Definition klist.h:20
Parallel block-cyclic matrix distribution.
Definition parallel_blkcyc.h:25
Definition parallel_orbitals.h:16
Definition rpa_lri_coeff_v1.h:11
Provide the basic information about unitcell.
Definition unitcell.h:16
Definition hcontainer.h:147
Definition hybrid_gauge_phase.cpp:10
std::vector< int > get_ik_list(const K_Vectors &kv, const int is_k)
Definition ri_2d_comm.cpp:65
std::vector< std::vector< Tdata > > pulay_mixing(const Parallel_Orbitals &pv, std::deque< std::vector< std::vector< Tdata > > > &Hk_seq, const std::vector< std::vector< Tdata > > &Hk_new, const double mixing_beta, const std::string mixing_mode)
std::array< Tcell, Ndim > TC
Definition ri_2d_comm.h:28
std::pair< TA, TC > TAC
Definition ri_2d_comm.h:29
int get_is_block(const int is_k, const int is_row_b, const int is_col_b)
Definition ri_2d_comm.cpp:91
std::map< TA, std::map< TAC, T > > comm_map2(const MPI_Comm &mpi_comm, const std::map< TA, std::map< TAC, T > > &Ds_in, const Tjudge &judge)
Definition ri_2d_comm.hpp:460
std::vector< std::map< TA, std::map< TAC, RI::Tensor< Tdata > > > > split_m2D_ktoR_gamma(const UnitCell &ucell, const std::vector< const Tmatrix * > &mks_2D, const Parallel_Blkcyclic &pv, const int nspin)
std::vector< std::map< TA, std::map< TAC, RI::Tensor< Tdata > > > > split_m2D_ktoR(const UnitCell &ucell, const K_Vectors &kv, const std::vector< const Tmatrix * > &mks_2D, const Parallel_Blkcyclic &pv, const int nspin, const bool spgsym=false)
int TA
Definition ri_2d_comm.h:25
std::vector< std::map< TA, std::map< TAC, RI::Tensor< Tdata > > > > split_m2D_ktoR_k(const UnitCell &ucell, const K_Vectors &kv, const std::vector< const Tmatrix * > &mks_2D, const Parallel_Blkcyclic &pv, const int nspin, const bool spgsym=false)
void set_value_add(Tkey &&key, Tvalue &&value, std::map< Tkey, Tvalue > &data)
Definition ri_2d_comm.hpp:480
std::vector< std::map< TA, std::map< TAC, RI::Tensor< Tdata > > > > dm_container_to_Ds(const std::vector< hamilt::HContainer< TR > * > &dm_container, const UnitCell &ucell, const Parallel_Orbitals &pv, const int nspin)
std::vector< std::tuple< std::set< TA >, std::set< TA > > > get_2D_judge(const UnitCell &ucell, const Parallel_Blkcyclic &pv)
std::tuple< int, int > split_is_block(const int is_b)
Definition ri_2d_comm.cpp:103
void add_HexxR(const int current_spin, const double alpha, const std::vector< std::map< TA, std::map< TAC, RI::Tensor< Tdata > > > > &Hs, const Parallel_Orbitals &pv, const int npol, hamilt::HContainer< TR > &HlocR, const RI::Cell_Nearest< int, int, 3, double, 3 > *const cell_nearest=nullptr)
Definition ri_2d_comm.hpp:318
std::tuple< int, int, int > get_iat_iw_is_block(const UnitCell &ucell, const int &iwt)
Definition ri_2d_comm.cpp:76
int Tcell
Definition ri_2d_comm.h:26
std::map< TA, std::map< TAC, T > > comm_map2_first(const MPI_Comm &mpi_comm, const std::map< TA, std::map< TAC, T > > &Ds_in, const std::set< TA > &s0, const std::set< TA > &s1)
Definition ri_2d_comm.hpp:448
void add_Hexx(const UnitCell &ucell, const K_Vectors &kv, const int ik, const double alpha, const std::vector< std::map< TA, std::map< TAC, RI::Tensor< Tdata > > > > &Hs, const Parallel_Orbitals &pv, TK *hk)
Definition ri_2d_comm.hpp:268
int get_iwt(const UnitCell &ucell, const int iat, const int iw_b, const int is_b)
Definition ri_2d_comm.cpp:118
void add_datas(std::map< Tkey, Tvalue > &&data_local, std::map< Tkey, Tvalue > &data_recv)
Definition ri_2d_comm.hpp:499
std::vector< std::vector< Tdata > > Hexxs_to_Hk(const K_Vectors &kv, const Parallel_Orbitals &pv, const std::vector< std::map< TA, std::map< TAC, RI::Tensor< Tdata > > > > &Hexxs, const int ik)