6#include <RI/distribute/Distribute_Equally.h>
25 std::vector<Tk> kindex_map_in(this->
nk);
26 for (
int ik = 0; ik < this->
nk; ++ik)
32 int task_sizes = this->
ucell.nat * this->
ucell.nat * this->nk * this->nk;
33 std::cout <<
"Total Molecular LRI tasks: " << task_sizes <<
", number of MPI processes: " <<
nproc << std::endl;
34 this->
LR_lri.set_parallel(MPI_COMM_WORLD, (std::size_t)this->
ucell.nat, (std::size_t)this->nk, this->kRlist.period);
35 for (
int k1 : this->
LR_lri.k1_indices)
40 int proc_ntasks = this->
LR_lri.list_I.size() * this->
LR_lri.list_J.size() * this->
LR_lri.k1_indices.size() * this->
LR_lri.k2_indices.size();
42 <<
" handles " << proc_ntasks <<
" tasks." << std::endl;
54 std::set<int> all_atoms;
55 for (
int i = 0; i < this->
ucell.nat; ++i)
58 for (
int j = 0; j < this->
ucell.nat; ++j)
60 for (
const TC R_original : this->
kRlist.Rlist)
62 const TC R =
cell_nearest.cell_nearest_direction(i, j, R_original, dist);
72 std::set<TA> set_I(this->
LR_lri.list_I.begin(), this->LR_lri.list_I.end());
73 std::set<TA> set_J(this->
LR_lri.list_J.begin(), this->LR_lri.list_J.end());
74 std::set<TA> set_IJ(this->
LR_lri.list_IJ.begin(), this->LR_lri.list_IJ.end());
88 TLRI<T>& Cs_LRI = this->
LR_lri.lrik.data_pool.at(
"Cs_").Ds_ab;
90 TLRI<T>& Vs_LRI = this->
LR_lri.lrik.data_pool.at(
"Vs_").Ds_ab;
92 TLRI<T>& Ws_LRI = this->
LR_lri.lrik.data_pool.at(
"Ws_").Ds_ab;
115 using namespace RI::Array_Operator;
116 const Tk k_unit{1.0, 1.0, 1.0};
120 bool operator()(
const Tk& lhs,
const Tk& rhs)
const {
121 constexpr double eps = 1e-6;
122 for (
int i = 0; i < 3; ++i)
123 if (std::abs(lhs[i] - rhs[i]) > eps)
return lhs[i] < rhs[i];
128 auto frac_to_cart = [&](
const Tk& k_frac) ->
Tk {
131 return Tk{v_cart.
x, v_cart.
y, v_cart.
z};
133 auto cart_to_frac = [&](
const Tk& k_cart) ->
Tk {
136 return Tk{v_frac.
x, v_frac.
y, v_frac.
z};
138 auto cart_dist = [&](
const Tk& q1,
const Tk& q2) ->
double {
139 Tk dq_frac = cart_to_frac({q1[0]-q2[0], q1[1]-q2[1], q1[2]-q2[2]});
140 for (
int i = 0; i < 3; ++i) dq_frac[i] -= std::round(dq_frac[i]);
141 Tk dq_cart = frac_to_cart(dq_frac);
142 return std::sqrt(dq_cart[0]*dq_cart[0] + dq_cart[1]*dq_cart[1] + dq_cart[2]*dq_cart[2]);
147 std::map<Tk, std::vector<std::pair<int, int>>, kComparator> q2kpair_tmp;
148 for (
int k1 : this->
LR_lri.k1_indices)
149 for (
int k2 : this->
LR_lri.k2_indices)
151 Tk q = (this->
LR_lri.kindex_map[k2] - this->
LR_lri.kindex_map[k1]) % k_unit;
152 q2kpair_tmp[q].emplace_back(k1, k2);
154 this->
LR_lri.q2kpair.insert(std::make_move_iterator(q2kpair_tmp.begin()), std::make_move_iterator(q2kpair_tmp.end()));
166 std::map<Tk, std::vector<std::pair<int, int>>, kComparator> q2kpair_tmp;
167 for (
int k1 : this->
LR_lri.k1_indices)
168 for (
int k2 : this->
LR_lri.k2_indices)
170 const Tk q_diff = this->
LR_lri.kindex_map[k2] - this->
LR_lri.kindex_map[k1];
172 for (
int i = 0; i < 3; ++i) { q_frac[i] -= std::round(q_frac[i]); }
173 Tk q_cart = frac_to_cart(q_frac);
174 double q_norm = std::sqrt(q_cart[0] * q_cart[0] + q_cart[1] * q_cart[1] + q_cart[2] * q_cart[2]);
177 Tk q_key = q_diff % k_unit;
178 q2kpair_tmp[q_key].emplace_back(k1, k2);
181 this->
LR_lri.q2kpair.insert(std::make_move_iterator(q2kpair_tmp.begin()), std::make_move_iterator(q2kpair_tmp.end()));
185 std::set<Tk, kComparator> q_coarse_set;
188 for (
int ik1 = 0; ik1 < nk_coarse; ++ik1)
191 for (
int ik2 = 0; ik2 < nk_coarse; ++ik2)
194 q_coarse_set.insert((ck2 - ck1) % k_unit);
197 std::vector<Tk> q_coarse_list(q_coarse_set.begin(), q_coarse_set.end());
198 std::vector<Tk> q_coarse_cart;
199 for (
const Tk& q : q_coarse_list) q_coarse_cart.push_back(frac_to_cart(q));
201 for (
int k1 : this->
LR_lri.k1_indices)
203 Tk k1_frac = this->
LR_lri.kindex_map[k1];
204 for (
int k2 : this->
LR_lri.k2_indices)
206 Tk k2_frac = this->
LR_lri.kindex_map[k2];
207 Tk q_frac = (k2_frac - k1_frac) % k_unit;
208 Tk q_cart = frac_to_cart(q_frac);
209 double q_norm = std::sqrt(q_cart[0]*q_cart[0] + q_cart[1]*q_cart[1] + q_cart[2]*q_cart[2]);
218 double min_dist = std::numeric_limits<double>::max();
220 for (std::size_t iq = 0; iq < q_coarse_cart.size(); ++iq)
222 double d = cart_dist(q_cart, q_coarse_cart[iq]);
223 if (d < min_dist) { min_dist = d; nearest = iq; }
225 q_target = q_coarse_list[nearest];
227 this->
LR_lri.q2kpair[q_target].emplace_back(k1, k2);
232 for (
auto& pair : this->
LR_lri.q2kpair)
234 this->
LR_lri.q_list.push_back(pair.first);
239 std::ofstream ofs_qlist(this->
out_dir +
"qlist_" + std::to_string(this->
my_rank+1) +
".dat");
240 ofs_qlist <<
"q_list: size = " << this->
LR_lri.q_list.size() << std::endl;
241 ofs_qlist <<
"(direct coords) | (Cartesian, 2*pi/lat0)" << std::endl;
242 ofs_qlist << std::fixed << std::setprecision(4);
243 for (
const Tk& q : this->
LR_lri.q_list)
245 Tk qc = frac_to_cart(q);
246 ofs_qlist <<
"(" << std::setw(6) << q[0] <<
"," << std::setw(6) << q[1]
247 <<
"," << std::setw(6) << q[2] <<
") | (" << std::setw(7) << qc[0]
248 <<
"," << std::setw(7) << qc[1] <<
"," << std::setw(7) << qc[2] <<
")" << std::endl;
250 ofs_qlist << std::defaultfloat;
255std::map<int, std::map<TA, RI::Tensor<T>>>
260 std::map<int, std::map<TA, RI::Tensor<T>>> psi_map;
261 const std::size_t nmo =
psi_ks.get_nbands();
262 for (
const int ik : k_list)
264 auto& psi_map_k = psi_map[ik];
265 for (
int iat = 0; iat < this->
ucell.nat; ++iat)
271#pragma omp parallel for schedule(static)
273 for (
const auto& ik : k_list)
275 auto& psi_map_k = psi_map.at(ik);
276 for (
int iat = 0; iat < this->
ucell.nat; ++iat)
278 const int it = this->
ucell.iat2it[iat];
279 const std::size_t nw = this->
ucell.atoms[it].nw;
281 for (
int im = 0; im < nmo; ++im)
283 for (
int iw = 0; iw < nw; ++iw)
285 t(im, iw) =
psi_ks(ik, im, this->
ucell.get_iat2iwt()[iat]+iw);
288 psi_map_k.at(iat) = std::move(t);
const UnitCell & ucell
Definition molecular_lri.h:159
RI::LR< int, int, 3, T > LR_lri
Definition molecular_lri.h:38
const int nvirt
Definition molecular_lri.h:165
const int nocc
Definition molecular_lri.h:164
void build_q_to_kpair_map(int mode, double threshold)
build q_list and q2kpair mapping according to approximation mode
Definition molecular_lri.hpp:112
const int my_rank
Definition molecular_lri.h:172
const int bse_q_approx_mode
Definition molecular_lri.h:168
const double bse_q_approx_threshold
Definition molecular_lri.h:169
std::vector< bool > is_local_k1
Definition molecular_lri.h:174
const std::string out_dir
Definition molecular_lri.h:171
void print_k(std::ostream &ofs, const std::vector< Tk > &kindex_map, const std::vector< int > &vec, const std::string name)
=============== print ====================
Definition molecular_lri.h:114
const K_Vectors & kv
Definition molecular_lri.h:161
const LR_IO::RI_kRlist & kRlist
Definition molecular_lri.h:162
RI::Cell_Nearest< int, int, 3, double, 3 > cell_nearest
Definition molecular_lri.h:39
const int nproc
Definition molecular_lri.h:173
void print_a(std::ostream &ofs, const std::vector< int > &vec, const std::string name)
Definition molecular_lri.h:129
const bool out_ri_cv
Definition molecular_lri.h:170
void init(TLRI< T > &Cs_in, TLRI< T > &Vs_in, TLRI< T > &Ws_in, const Exx_Info_RI &info_ri)
=============== calculation interface ====================
Definition molecular_lri.hpp:19
const int nk
Definition molecular_lri.h:160
const psi::Psi< T > & psi_ks
Definition molecular_lri.h:167
std::map< int, std::map< TA, RI::Tensor< T > > > transform_psi_k(const psi::Psi< T > &psi_ks, const std::vector< int > &k_list)
transform psi to <k, <iat, tensor{nmo, iat.nw}>>, mo is not sliced
Definition molecular_lri.hpp:256
Class for k-points management.
Definition klist.h:20
int get_nkstot_nospin() const
Definition klist.h:81
3 elements vector
Definition vector3.h:21
T x
Definition vector3.h:23
T y
Definition vector3.h:24
T z
Definition vector3.h:25
static void start(void)
Start total time calculation.
Definition timer.cpp:44
static void end(const std::string &class_name_in, const std::string &name_in)
Definition timer.cpp:109
std::vector< ModuleBase::Vector3< double > > kvec_d
Direct coordinates of the points.
Definition reciprocal_grid.h:57
Definition rpa_lri_coeff_v1.h:11
bool move_R_tensor(TLRI< T > &tensor_map, const TA ia, const TA ja, const TC &R_original, const TC &R_new)
Definition bse_util.h:42
Definition hamilt_bse.cpp:10
std::array< int, 3 > TC
Definition molecular_lri.h:26
std::map< TA, std::map< TAC, RI::Tensor< T > > > TLRI
Definition molecular_lri.h:32
std::array< double, 3 > Tk
Definition molecular_lri.h:27
int NPROC
global number of process
Definition global_variable.cpp:19
std::ofstream ofs_running
Definition global_variable.cpp:38
void DONE(std::ofstream &ofs, const std::string &description, const bool only_rank0)
Definition global_function.cpp:78
void TITLE(const std::string &class_name, const std::string &function_name, const bool disable)
Definition tool_title.cpp:18
std::array< Tcell, 3 > Vector3_to_array3(const ModuleBase::Vector3< Tcell > &v)
Definition ri_util.h:26
#define threshold
Definition sph_bessel_rec_test.cpp:4
Definition exx_info_ri.h:11
double C_threshold
Definition exx_info_ri.h:22
double V_threshold
Definition exx_info_ri.h:23