14#include "../../source_base/tool_title.h"
15#include "../../source_base/timer.h"
16#include "../../source_pw/module_pwdft/global.h"
17#include <RI/global/Global_Func-1.h>
20template<
typename Tdata>
23 pthread_rwlock_init(&rwlock_Vw,NULL);
24 pthread_rwlock_init(&rwlock_Cw,NULL);
25 pthread_rwlock_init(&rwlock_dVw,NULL);
26 pthread_rwlock_init(&rwlock_dCw,NULL);
29template<
typename Tdata>
32 pthread_rwlock_destroy(&rwlock_Vw);
33 pthread_rwlock_destroy(&rwlock_Cw);
34 pthread_rwlock_destroy(&rwlock_dVw);
35 pthread_rwlock_destroy(&rwlock_dCw);
39template<
typename Tdata>
43 const std::vector<std::vector<std::vector<Numerical_Orbital_Lm>>> &lcaos_in,
44 const std::vector<std::vector<std::vector<Numerical_Orbital_Lm>>> &abfs_in,
45 const std::vector<std::vector<std::vector<Numerical_Orbital_Lm>>> &abfs_ccp_in,
46 const double &kmesh_times,
54 this->lcaos = lcaos_in;
56 this->abfs_ccp = abfs_ccp_in;
61 const double abfs_ccp_rmax
72 int Lmax_v = std::numeric_limits<double>::min();
73 this->m_abfs_abfs.init(2, ucell, orb, kmesh_times, lcaos_rmax + abfs_ccp_rmax, Lmax_v);
74 int Lmax_c = std::numeric_limits<double>::min();
76 this->m_abfslcaos_lcaos.init(1, ucell, orb, kmesh_times, lcaos_rmax, Lmax_c);
77 int Lmax = std::max(Lmax_v, Lmax_c);
84 this->m_abfs_abfs.init_radial(this->abfs_ccp, this->abfs, MGT);
85 this->m_abfs_abfs.init_radial_table();
87 this->m_abfslcaos_lcaos.init_radial(this->abfs_ccp,
91 this->m_abfslcaos_lcaos.init_radial_table();
97template <
typename Tdata>
99 return this->abfs_ccp_rcut[it0] + this->lcaos_rcut[it1];
102template <
typename Tdata>
104 return std::min(this->abfs_ccp_rcut[it0], this->lcaos_rcut[it0])
105 + this->lcaos_rcut[it1];
108template<
typename Tdata>
template<
typename Tresult>
111 const std::vector<TA>& list_A0,
112 const std::vector<TAC>& list_A1,
113 const std::map<std::string, bool>& flags,
116-> std::map<TA,std::map<TAC,Tresult>>
121 std::map<TA,std::map<TAC,Tresult>> Datas;
123 for(
size_t i0=0; i0<list_A0.size(); ++i0)
125 #pragma omp for schedule(dynamic) nowait
126 for(
size_t i1=0; i1<list_A1.size(); ++i1)
128 const TA iat0 = list_A0[i0];
129 const TA iat1 = list_A1[i1].first;
130 const TC &cell1 = list_A1[i1].second;
131 const int it0 = ucell.iat2it[iat0];
132 const int ia0 = ucell.iat2ia[iat0];
133 const int it1 = ucell.iat2it[iat1];
134 const int ia1 = ucell.iat2ia[iat1];
138 = std::min(func_cal_Rcut(it0, it1), func_cal_Rcut(it1, it0));
140 if( R_delta.
norm()*ucell.lat0 < Rcut )
142 const Tresult
Data = func_DPcal_data(it0, it1, R_delta, flags);
145 #pragma omp critical(LRI_CV_cal_datas)
146 Datas[list_A0[i0]][list_A1[i1]] =
Data;
156template<
typename Tdata>
159 const std::vector<TA> &list_A0,
160 const std::vector<TAC> &list_A1,
161 const std::map<std::string,bool> &flags)
162-> std::map<TA,std::map<TAC,RI::Tensor<Tdata>>>
166 func_DPcal_V = std::bind(
168 std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4);
171 std::placeholders::_1,
172 std::placeholders::_2);
174 return this->cal_datas(ucell,list_A0, list_A1, flags, func_cal_Rcut, func_DPcal_V);
177template<
typename Tdata>
180 const std::vector<TA> &list_A0,
181 const std::vector<TAC> &list_A1,
182 const std::map<std::string,bool> &flags)
183-> std::map<TA, std::map<TAC, std::array<RI::Tensor<Tdata>, 3>>>
187 func_DPcal_dV = std::bind(
189 std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4);
193 std::placeholders::_1,
194 std::placeholders::_2);
196 return this->cal_datas(ucell,list_A0, list_A1, flags, func_cal_Rcut, func_DPcal_dV);
199template<
typename Tdata>
202 const std::vector<TA> &list_A0,
203 const std::vector<TAC> &list_A1,
204 const std::map<std::string,bool> &flags)
206 std::map<TA, std::map<TAC, RI::Tensor<Tdata>>>,
207 std::map<TA, std::map<TAC, std::array<RI::Tensor<Tdata>, 3>>>>
211 func_DPcal_C_dC = std::bind(
213 std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4);
216 std::placeholders::_1,
217 std::placeholders::_2);
219 std::map<TA,std::map<TAC, std::pair<RI::Tensor<Tdata>, std::array<RI::Tensor<Tdata>,3>>>>
220 Cs_dCs_tmp = this->cal_datas(ucell,list_A0, list_A1, flags, func_cal_Rcut, func_DPcal_C_dC);
222 std::map<TA, std::map<TAC, RI::Tensor<Tdata>>> Cs;
223 std::map<TA, std::map<TAC, std::array<RI::Tensor<Tdata>, 3>>> dCs;
224 for (
auto& Cs_dCs_A: Cs_dCs_tmp)
225 for (
auto& Cs_dCs_B: Cs_dCs_A.second) {
226 Cs[Cs_dCs_A.first][Cs_dCs_B.first]
227 = std::move(std::get<0>(Cs_dCs_B.second));
228 if (flags.at(
"cal_dC"))
229 dCs[Cs_dCs_A.first][Cs_dCs_B.first]
230 = std::move(std::get<1>(Cs_dCs_B.second));
232 return std::make_pair(Cs, dCs);
236template<
typename Tdata>
template<
typename To11,
typename Tfunc>
241 const bool &flag_writable_o11ws,
242 pthread_rwlock_t &rwlock_o11,
244 const Tfunc &func_cal_o11)
247 pthread_rwlock_rdlock(&rwlock_o11);
248 const To11 o11_read = RI::Global_Func::find(o11ws, it0, it1, R);
249 pthread_rwlock_unlock(&rwlock_o11);
257 pthread_rwlock_rdlock(&rwlock_o11);
258 const To11 o11_transform_read = RI::Global_Func::find(o11ws, it1, it0, Rm);
259 pthread_rwlock_unlock(&rwlock_o11);
264 if(flag_writable_o11ws)
266 pthread_rwlock_wrlock(&rwlock_o11);
267 o11ws[it0][it1][R] = o11;
268 pthread_rwlock_unlock(&rwlock_o11);
274 const To11 o11 = func_cal_o11(
276 this->index_abfs, this->index_abfs,
278 if(flag_writable_o11ws)
280 pthread_rwlock_wrlock(&rwlock_o11);
281 o11ws[it0][it1][R] = o11;
282 pthread_rwlock_unlock(&rwlock_o11);
289template<
typename Tdata>
295 const std::map<std::string,bool> &flags)
297 const auto cal_overlap_matrix = std::bind(
298 &Matrix_Orbs11::cal_overlap_matrix<Tdata>,
300 std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6, std::placeholders::_7);
301 return this->DPcal_o11(it0, it1, R, flags.at(
"writable_Vws"), this->rwlock_Vw, this->Vws, cal_overlap_matrix);
304template<
typename Tdata>
305std::array<RI::Tensor<Tdata>, 3>
310 const std::map<std::string,bool> &flags)
315 const size_t size = this->index_abfs[it0].count_size;
316 const std::array<RI::Tensor<Tdata>, 3> dV = { RI::Tensor<Tdata>({size,size}), RI::Tensor<Tdata>({size,size}), RI::Tensor<Tdata>({size,size}) };
317 if(flags.at(
"writable_dVws"))
319 pthread_rwlock_wrlock(&this->rwlock_dVw);
320 this->dVws[it0][it1][R] = dV;
321 pthread_rwlock_unlock(&this->rwlock_dVw);
326 const auto cal_grad_overlap_matrix = std::bind(
327 &Matrix_Orbs11::cal_grad_overlap_matrix<Tdata>,
329 std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6, std::placeholders::_7);
330 return this->DPcal_o11(it0, it1, R, flags.at(
"writable_dVws"), this->rwlock_dVw, this->dVws, cal_grad_overlap_matrix);
334template<
typename Tdata>
335std::pair<RI::Tensor<Tdata>, std::array<RI::Tensor<Tdata>,3>>
340 const std::map<std::string,bool> &flags)
345 pthread_rwlock_rdlock(&this->rwlock_Cw);
346 const RI::Tensor<Tdata> C_read = RI::Global_Func::find(this->Cws, it0, it1, R);
347 pthread_rwlock_unlock(&this->rwlock_Cw);
348 pthread_rwlock_rdlock(&this->rwlock_dCw);
349 const std::array<RI::Tensor<Tdata>,3> dC_read = RI::Global_Func::find(this->dCws, it0, it1, R);
350 pthread_rwlock_unlock(&this->rwlock_dCw);
353 if(!C_read.empty() && flag_finish_dC)
355 return std::make_pair(C_read, dC_read);
361 const RI::Tensor<Tdata>
362 A = this->m_abfslcaos_lcaos.template cal_overlap_matrix<Tdata>(
363 it0, it1, {0,0,0}, {0,0,0},
364 this->index_abfs, this->index_lcaos, this->index_lcaos,
366 const RI::Tensor<Tdata> V = this->DPcal_V( it0, it0, {0,0,0}, {{
"writable_Vws",
true}});
369 const RI::Tensor<Tdata> C = RI::Global_Func::convert<Tdata>(0.5) *
LRI_CV_Tools::mul1(L,A);
370 if(flags.at(
"writable_Cws"))
372 pthread_rwlock_wrlock(&this->rwlock_Cw);
373 this->Cws[it0][it1][{0,0,0}] = C;
374 pthread_rwlock_unlock(&this->rwlock_Cw);
379 return std::make_pair(C, dC_read);
383 const RI::Shape_Vector sizes = {this->index_abfs[it0].count_size,
384 this->index_lcaos[it0].count_size,
385 this->index_lcaos[it0].count_size};
386 const std::array<RI::Tensor<Tdata>,3>
387 dC({RI::Tensor<Tdata>({sizes}), RI::Tensor<Tdata>({sizes}), RI::Tensor<Tdata>({sizes})});
388 if(flags.at(
"writable_dCws"))
390 pthread_rwlock_wrlock(&this->rwlock_dCw);
391 this->dCws[it0][it1][{0,0,0}] = dC;
392 pthread_rwlock_unlock(&this->rwlock_dCw);
394 return std::make_pair(C, dC);
399 const std::vector<RI::Tensor<Tdata>>
400 A = {this->m_abfslcaos_lcaos.template cal_overlap_matrix<Tdata>(
401 it0, it1, {0,0,0}, R,
402 this->index_abfs, this->index_lcaos, this->index_lcaos,
404 this->m_abfslcaos_lcaos.template cal_overlap_matrix<Tdata>(
405 it1, it0, {0,0,0}, Rm,
406 this->index_abfs, this->index_lcaos, this->index_lcaos,
409 const std::vector<std::vector<RI::Tensor<Tdata>>>
410 V = {{DPcal_V(it0, it0, {0,0,0}, {{
"writable_Vws",
true}}),
411 DPcal_V(it0, it1, R, flags)},
412 {DPcal_V(it1, it0, Rm, flags),
413 DPcal_V(it1, it1, {0,0,0}, {{
"writable_Vws",
true}})}};
415 const std::vector<std::vector<RI::Tensor<Tdata>>>
419 if(flags.at(
"writable_Cws"))
421 pthread_rwlock_wrlock(&this->rwlock_Cw);
422 this->Cws[it0][it1][R] = C[0];
424 pthread_rwlock_unlock(&this->rwlock_Cw);
429 return std::make_pair(C[0], dC_read);
433 const std::vector<std::array<RI::Tensor<Tdata>,3>>
434 dA = {this->m_abfslcaos_lcaos.template cal_grad_overlap_matrix<Tdata>(
435 it0, it1, {0,0,0}, R,
436 this->index_abfs, this->index_lcaos, this->index_lcaos,
439 this->m_abfslcaos_lcaos.template cal_grad_overlap_matrix<Tdata>(
440 it1, it0, {0,0,0}, Rm,
441 this->index_abfs, this->index_lcaos, this->index_lcaos,
444 const std::array<RI::Tensor<Tdata>,3> dV_01 = DPcal_dV(it0, it1, R, flags);
447 std::array<std::vector<RI::Tensor<Tdata>>,3>
452 std::vector<std::array<RI::Tensor<Tdata>,3>>{
455 const std::vector<std::array<RI::Tensor<Tdata>,3>>
457 if(flags.at(
"writable_dCws"))
459 pthread_rwlock_wrlock(&this->rwlock_dCw);
460 this->dCws[it0][it1][R] = dC[0];
462 pthread_rwlock_unlock(&this->rwlock_dCw);
464 return std::make_pair(C[0], dC[0]);
Definition abfs-vector3_order.h:16
static ModuleBase::Element_Basis_Index::Range construct_range(const LCAO_Orbitals &orb)
Definition exx_abfs-abfs_index.cpp:5
static double get_Rmax(const std::vector< double > &rcut)
Definition exx_abfs-construct_orbs.h:50
static std::vector< double > get_Rcut(const std::vector< std::vector< std::vector< Numerical_Orbital_Lm > > > &orb_in)
Definition exx_abfs-construct_orbs.cpp:523
std::array< RI::Tensor< Tdata >, 3 > DPcal_dV(const int it0, const int it1, const Abfs::Vector3_Order< double > &R, const std::map< std::string, bool > &flags)
Definition LRI_CV.hpp:306
std::pair< RI::Tensor< Tdata >, std::array< RI::Tensor< Tdata >, 3 > > DPcal_C_dC(const int it0, const int it1, const Abfs::Vector3_Order< double > &R, const std::map< std::string, bool > &flags)
Definition LRI_CV.hpp:336
RI::Tensor< Tdata > DPcal_V(const int it0, const int it1, const Abfs::Vector3_Order< double > &R, const std::map< std::string, bool > &flags)
Definition LRI_CV.hpp:291
std::map< TA, std::map< TAC, RI::Tensor< Tdata > > > cal_Vs(const UnitCell &ucell, const std::vector< TA > &list_A0, const std::vector< TAC > &list_A1, const std::map< std::string, bool > &flags)
Definition LRI_CV.hpp:157
std::function< double(const int it0, const int it1)> T_func_cal_Rcut
Definition LRI_CV.h:97
~LRI_CV()
Definition LRI_CV.hpp:30
std::map< TA, std::map< TAC, Tresult > > cal_datas(const UnitCell &ucell, const std::vector< TA > &list_A0, const std::vector< TAC > &list_A1, const std::map< std::string, bool > &flags, const T_func_cal_Rcut &func_cal_Rcut, const T_func_DPcal_data< Tresult > &func_DPcal_data)
std::function< Tresult(const int it0, const int it1, const Abfs::Vector3_Order< double > &R, const std::map< std::string, bool > &flags)> T_func_DPcal_data
Definition LRI_CV.h:96
LRI_CV()
Definition LRI_CV.hpp:21
int TA
Definition LRI_CV.h:27
std::pair< std::map< TA, std::map< TAC, RI::Tensor< Tdata > > >, std::map< TA, std::map< TAC, std::array< RI::Tensor< Tdata >, 3 > > > > cal_Cs_dCs(const UnitCell &ucell, const std::vector< TA > &list_A0, const std::vector< TAC > &list_A1, const std::map< std::string, bool > &flags)
Definition LRI_CV.hpp:200
std::map< TA, std::map< TAC, std::array< RI::Tensor< Tdata >, 3 > > > cal_dVs(const UnitCell &ucell, const std::vector< TA > &list_A0, const std::vector< TAC > &list_A1, const std::map< std::string, bool > &flags)
Definition LRI_CV.hpp:178
std::array< int, 3 > TC
Definition LRI_CV.h:28
double cal_C_Rcut(const int it0, const int it1)
Definition LRI_CV.hpp:103
void set_orbitals(const UnitCell &ucell, const LCAO_Orbitals &orb, const std::vector< std::vector< std::vector< Numerical_Orbital_Lm > > > &lcaos_in, const std::vector< std::vector< std::vector< Numerical_Orbital_Lm > > > &abfs_in, const std::vector< std::vector< std::vector< Numerical_Orbital_Lm > > > &abfs_ccp_in, const double &kmesh_times, ORB_gaunt_table &MGT, const bool &init_MGT, const bool &init_C)
Definition LRI_CV.hpp:40
double cal_V_Rcut(const int it0, const int it1)
Definition LRI_CV.hpp:98
To11 DPcal_o11(const int it0, const int it1, const Abfs::Vector3_Order< double > &R, const bool &flag_writable_o11ws, pthread_rwlock_t &rwlock_o11, std::map< int, std::map< int, std::map< Abfs::Vector3_Order< double >, To11 > > > &o11ws, const Tfunc &func_cal_o11)
Definition LRI_CV.hpp:237
static IndexLNM construct_index(const Range &range)
Definition element_basis_index.cpp:10
std::vector< std::vector< NM > > Range
Definition element_basis_index.h:40
3 elements vector
Definition vector3.h:22
T norm(void) const
Get the norm of a Vector3.
Definition vector3.h:187
static void tick(const std::string &class_name_in, const std::string &name_in)
Use twice at a time: the first time, set start_flag to false; the second time, calculate the time dur...
Definition timer.cpp:57
Definition ORB_gaunt_table.h:9
void init_Gaunt(const int &lmax)
Definition ORB_gaunt_table.cpp:15
void init_Gaunt_CH(const int &Lmax)
Definition ORB_gaunt_table.cpp:189
void TITLE(const std::string &class_name, const std::string &function_name, const bool disable)
Definition tool_title.cpp:18
ModuleBase::Vector3< Tcell > array3_to_Vector3(const std::array< Tcell, 3 > &v)
Definition RI_Util.h:38