36template <
typename T,
typename Tdata>
38 const MPI_Comm& mpi_comm_in,
49 this->cal_postSCF_exx(dm, mpi_comm_in, ucell, kv, orb);
50 this->init(mpi_comm_in, kv, orb.
cutoffs());
51 this->out_bands(pelec);
52 this->out_eigen_vector(parav,
psi);
53 this->out_struc(ucell);
55 std::cout <<
"rpa_pca_threshold: " << this->info.pca_threshold << std::endl;
56 std::cout <<
"rpa_ccp_rmesh_times: " << this->info.ccp_rmesh_times << std::endl;
57 std::cout <<
"rpa_lcao_exx(Ha): " << std::fixed << std::setprecision(15) << exx_cut_coulomb->Eexx / 2.0 << std::endl;
59 std::cout <<
"etxc(Ha): " << std::fixed << std::setprecision(15) << pelec->
f_en.
etxc / 2.0 << std::endl;
60 std::cout <<
"etot(Ha): " << std::fixed << std::setprecision(15) << pelec->
f_en.
etot / 2.0 << std::endl;
61 std::cout <<
"Etot_without_rpa(Ha): " << std::fixed << std::setprecision(15)
62 << (pelec->
f_en.
etot - pelec->
f_en.
etxc + exx_cut_coulomb->Eexx) / 2.0 << std::endl;
63 delete exx_cut_coulomb;
64 exx_cut_coulomb =
nullptr;
69 cal_large_Cs(ucell, orb, kv);
70 cal_abfs_overlap(ucell, orb, kv);
73 this->output_ewald_coulomb(ucell, kv, orb);
78template <
typename T,
typename Tdata>
83 this->mpi_comm = mpi_comm_in;
84 this->orb_cutoff_ = orb_cutoff;
85 this->lcaos = exx_cut_coulomb->lcaos;
87 this->MGT = exx_cut_coulomb->MGT;
91 this->abfs_shrink = exx_cut_coulomb->abfs;
95 this->abfs = exx_cut_coulomb->abfs;
102template <
typename T,
typename Tdata>
104 const MPI_Comm& mpi_comm_in,
112 this->mpi_comm = mpi_comm_in;
114 this->orb_cutoff_ = orb.
cutoffs();
118 if (exx_spacegroup_symmetry)
125 if (exx_spacegroup_symmetry)
140 const std::vector<std::map<TA, std::map<TAC, RI::Tensor<Tdata>>>>
154 if (!exx_cut_coulomb)
160 const std::vector<std::vector<std::vector<Numerical_Orbital_Lm>>> abfs_same_atom
164 this->info.kmesh_times,
165 this->info.shrink_abfs_pca_thr);
166 if (this->info.files_shrink_abfs.empty())
168 this->abfs_shrink = abfs_same_atom;
174 this->info.files_shrink_abfs,
175 this->info.kmesh_times);
178 exx_cut_coulomb->init_spencer(mpi_comm_in, ucell, kv, orb, abfs_shrink);
181 exx_cut_coulomb->init_spencer(mpi_comm_in, ucell, kv, orb);
183 this->output_cut_coulomb_cs(ucell, exx_cut_coulomb);
199template <
typename T,
typename Tdata>
205 std::map<TA, std::map<TAC, RI::Tensor<Tdata>>> Vs_cut_IJR;
206 std::map<TA, std::map<TAC, RI::Tensor<Tdata>>> Cs;
207 std::map<TA, std::map<TAC, RI::Tensor<Tdata>>> tmp;
208 std::cout <<
"Use rpa_ccp_rmesh_times=" << this->info.ccp_rmesh_times <<
" to calculate cut Coulomb" << std::endl;
212 std::vector<TA> atoms(ucell.
nat);
213 for (
int iat = 0; iat < ucell.
nat; ++iat)
215 const std::array<Tcell, Ndim> period_Vs
216 = LRI_CV_Tools::cal_latvec_range<Tcell>(1 + this->info.ccp_rmesh_times, ucell, this->orb_cutoff_);
217 const std::pair<std::vector<TA>, std::vector<std::vector<std::pair<TA, TC>>>> list_As_Vs_atoms
218 = RI::Distribute_Equally::distribute_atoms(this->mpi_comm, atoms, period_Vs, 2,
false);
219 const auto list_A0_pair_R = list_As_Vs_atoms.first;
220 const auto list_A1_pair_R = list_As_Vs_atoms.second[0];
221 std::set<TA> atoms00;
222 std::set<TA> atoms01;
223 for (
const auto& I: list_A0_pair_R)
227 for (
const auto& JR: list_A1_pair_R)
229 atoms01.insert(JR.first);
231 std::map<TA, std::map<TAC, RI::Tensor<Tdata>>> Vs_cut_IJ
234 const std::array<Tcell, Ndim> period = {p_kv->nmp[0], p_kv->nmp[1], p_kv->nmp[2]};
235 this->Vs_period = RI::RI_Tools::cal_period(Vs_cut_IJ, period);
236 this->out_coulomb_k(ucell, this->Vs_period,
"coulomb_cut_",
exx_lri_rpa);
240 this->Cs_period = RI::RI_Tools::cal_period(Cs, period);
244 this->out_Cs(ucell, this->Cs_period,
"Cs_shrinked_data_");
246 this->out_Cs(ucell, this->Cs_period,
"Cs_data_");
253template <
typename T,
typename Tdata>
260 if (!exx_full_coulomb)
264 exx_full_coulomb->init(mpi_comm, ucell, kv, orb, this->abfs_shrink);
266 exx_full_coulomb->init(mpi_comm, ucell, kv, orb, this->abfs);
267 std::map<TA, std::map<TAC, RI::Tensor<Tdata>>> Vs_full_IJR;
268 std::map<TA, std::map<TAC, RI::Tensor<Tdata>>> Cs;
269 std::map<TA, std::map<TAC, RI::Tensor<Tdata>>> tmp;
270 exx_full_coulomb->cal_ewald_coulomb(Vs_full_IJR, Cs, ucell,
PARAM.
inp.
out_ri_cv);
272 std::vector<TA> atoms(ucell.
nat);
273 for (
int iat = 0; iat < ucell.
nat; ++iat)
275 const std::array<Tcell, Ndim> period_Vs
276 = LRI_CV_Tools::cal_latvec_range<Tcell>(1 + this->ccp_rmesh_times_ewald, ucell, this->orb_cutoff_);
277 const std::pair<std::vector<TA>, std::vector<std::vector<std::pair<TA, TC>>>> list_As_Vs_atoms
278 = RI::Distribute_Equally::distribute_atoms(mpi_comm, atoms, period_Vs, 2,
false);
279 const auto list_A0_pair_R = list_As_Vs_atoms.first;
280 const auto list_A1_pair_R = list_As_Vs_atoms.second[0];
281 std::set<TA> atoms00;
282 std::set<TA> atoms01;
283 for (
const auto& I: list_A0_pair_R)
287 for (
const auto& JR: list_A1_pair_R)
289 atoms01.insert(JR.first);
291 std::map<TA, std::map<TAC, RI::Tensor<Tdata>>> Vs_full_IJ
295 const std::array<Tcell, Ndim> period = {p_kv->nmp[0], p_kv->nmp[1], p_kv->nmp[2]};
296 this->Vs_period = RI::RI_Tools::cal_period(Vs_full_IJ, period);
297 this->out_coulomb_k(ucell, this->Vs_period,
"coulomb_mat_", exx_full_coulomb);
303 delete exx_full_coulomb;
304 exx_full_coulomb =
nullptr;
310template <
typename T,
typename Tdata>
315 if (!exx_cut_coulomb)
317 exx_cut_coulomb->init_spencer(this->mpi_comm, ucell, kv, orb);
319 this->abfs = exx_cut_coulomb->abfs;
320 this->MGT = exx_cut_coulomb->MGT;
321 std::vector<TA> atoms(ucell.
nat);
322 for (
int iat = 0; iat < ucell.
nat; ++iat)
326 std::map<TA, TatomR> atoms_pos;
327 for (
int iat = 0; iat < ucell.
nat; ++iat)
332 const std::array<Tcell, Ndim> period = {p_kv->nmp[0], p_kv->nmp[1], p_kv->nmp[2]};
333 this->exx_cut_coulomb->exx_lri.set_parallel(this->mpi_comm, atoms_pos, latvec, period);
335 if (center2_obj_it == this->exx_cut_coulomb->exx_objs.end())
337 throw std::invalid_argument(
"RPA_LRI::cal_large_Cs expected a Center2 cut-Coulomb object after init_spencer.");
339 center2_obj_it->second.cv.set_orbitals(ucell,
342 exx_cut_coulomb->abfs,
343 center2_obj_it->second.abfs_ccp,
344 this->info.kmesh_times,
348 const std::array<Tcell, Ndim> period_Vs
349 = LRI_CV_Tools::cal_latvec_range<Tcell>(1 + this->info.ccp_rmesh_times, ucell, orb_cutoff_);
350 std::pair<std::vector<TA>, std::vector<std::vector<std::pair<TA, std::array<Tcell, Ndim>>>>> list_As_Vs
351 = RI::Distribute_Equally::distribute_atoms_periods(this->mpi_comm, atoms, period_Vs, 2,
false);
353 std::map<TA, std::map<TAC, RI::Tensor<Tdata>>> Vs_cut_IJR
354 = center2_obj_it->second.cv.cal_Vs(ucell, list_As_Vs.first, list_As_Vs.second[0], {{
"writable_Vws", true}});
357 const std::array<Tcell, Ndim> period_Cs = LRI_CV_Tools::cal_latvec_range<Tcell>(2, ucell, orb_cutoff_);
358 const std::pair<std::vector<TA>, std::vector<std::vector<std::pair<TA, std::array<Tcell, Ndim>>>>> list_As_Cs
359 = RI::Distribute_Equally::distribute_atoms_periods(this->mpi_comm, atoms, period_Cs, 2,
false);
360 std::pair<std::map<TA, std::map<TAC, RI::Tensor<Tdata>>>,
361 std::map<TA, std::map<TAC, std::array<RI::Tensor<Tdata>, 3>>>>
362 Cs_dCs = center2_obj_it->second.cv.cal_Cs_dCs(ucell,
364 list_As_Cs.second[0],
366 {
"writable_Cws", true},
367 {
"writable_dCws", true},
368 {
"writable_Vws", false},
369 {
"writable_dVws", false}});
372 std::map<TA, std::map<TAC, RI::Tensor<Tdata>>> tmp;
375 this->Vs_period = RI::RI_Tools::cal_period(Vs_cut_IJR, period);
379 const std::pair<std::vector<TA>, std::vector<std::vector<std::pair<TA, TC>>>> list_As_Vs_atoms
380 = RI::Distribute_Equally::distribute_atoms(this->mpi_comm, atoms, period_Vs, 2,
false);
381 const auto list_A0_pair_R = list_As_Vs_atoms.first;
382 const auto list_A1_pair_R = list_As_Vs_atoms.second[0];
383 std::set<TA> atoms00;
384 std::set<TA> atoms01;
385 for (
const auto& I: list_A0_pair_R)
389 for (
const auto& JR: list_A1_pair_R)
391 atoms01.insert(JR.first);
397 this->out_coulomb_k(ucell, this->Vs_period,
"coulomb_unshrinked_cut_", exx_cut_coulomb);
399 this->Vs_period.clear();
400 this->Vs_period.swap(tmp);
403 std::map<TA, std::map<TAC, RI::Tensor<Tdata>>>& Cs = std::get<0>(Cs_dCs);
404 this->Cs_period = RI::RI_Tools::cal_period(Cs, period);
405 this->Cs_period = exx_cut_coulomb->exx_lri.post_2D.set_tensors_map2(this->Cs_period);
406 this->out_Cs(ucell, this->Cs_period,
"Cs_data_");
408 this->Cs_period.clear();
409 this->Cs_period.swap(tmp);
410 delete exx_cut_coulomb;
411 exx_cut_coulomb =
nullptr;
417template <
typename T,
typename Tdata>
421 const auto& abfs_s = this->abfs_shrink;
428 m_abfs_abf.
MGT = this->MGT;
429 m_abfs_abf.
init(abfs_s, this->abfs, ucell, orb, this->info.kmesh_times);
432 m_abfs_abfs.
MGT = this->MGT;
433 m_abfs_abfs.
init(abfs_s, abfs_s, ucell, orb, this->info.kmesh_times);
438 std::map<TA, std::map<TAC, RI::Tensor<Tdata>>> overlap_abfs_abfs;
439 std::map<TA, std::map<TAC, RI::Tensor<Tdata>>> overlap_abfs_abf;
450 auto orb_cutoff_ = orb.
cutoffs();
451 const std::array<Tcell, Ndim> period_Vs = LRI_CV_Tools::cal_latvec_range<Tcell>(2, ucell, orb_cutoff_);
452 std::vector<TA> atoms(ucell.
nat);
453 for (
int iat = 0; iat < ucell.
nat; ++iat)
455 const std::pair<std::vector<TA>, std::vector<std::vector<std::pair<TA, std::array<Tcell, Ndim>>>>> list_As_Vs
456 = RI::Distribute_Equally::distribute_atoms_periods(this->mpi_comm, atoms, period_Vs, 2,
false);
476 using LocalMapType = std::map<std::pair<int, std::array<int, 3>>, RI::Tensor<double>>;
477 std::map<int, LocalMapType> overlap_abfs_abfs_local;
478 std::map<int, LocalMapType> overlap_abfs_abf_local;
480#pragma omp for schedule(dynamic) nowait
481 for (
size_t iA = 0; iA < list_As_Vs.first.size(); ++iA)
483 const auto& A = list_As_Vs.first[iA];
484 for (
const auto& BR: list_As_Vs.second[0])
486 const auto& B = BR.first;
487 const auto& R = BR.second;
490 const size_t IA = ucell.
iat2ia[A];
492 const size_t TB = ucell.
iat2it[B];
493 const size_t IB = ucell.
iat2ia[B];
494 const auto& tauB = ucell.
atoms[TB].
tau[IB];
501 auto& local_abfs_abfs = overlap_abfs_abfs_local[A];
502 local_abfs_abfs[{B, R}]
503 = m_abfs_abfs.template cal_overlap_matrix<double>(
TA,
511 auto& local_abfs_abf = overlap_abfs_abf_local[A];
512 local_abfs_abf[{B, R}]
513 = m_abfs_abf.template cal_overlap_matrix<double>(
TA,
523#pragma omp critical(RPA_LRI_merge)
525 for (
auto& aPair: overlap_abfs_abfs_local)
527 auto& aKey = aPair.first;
528 auto& aSubMap = aPair.second;
529 for (
auto& subPair: aSubMap)
531 auto& key = subPair.first;
532 auto& value = subPair.second;
533 overlap_abfs_abfs[aKey][key] = std::move(value);
536 for (
auto& aPair: overlap_abfs_abf_local)
538 auto& aKey = aPair.first;
539 auto& aSubMap = aPair.second;
540 for (
auto& subPair: aSubMap)
542 auto& key = subPair.first;
543 auto& value = subPair.second;
544 overlap_abfs_abf[aKey][key] = std::move(value);
550 const std::array<Tcell, Ndim> period_Vs_IJ = LRI_CV_Tools::cal_latvec_range<Tcell>(2, ucell, orb_cutoff_);
551 const std::pair<std::vector<TA>, std::vector<std::vector<std::pair<TA, TC>>>> list_As_Vs_atoms
552 = RI::Distribute_Equally::distribute_atoms(this->mpi_comm, atoms, period_Vs, 2,
false);
553 const auto list_A0_pair_R = list_As_Vs_atoms.first;
554 const auto list_A1_pair_R = list_As_Vs_atoms.second[0];
555 std::set<TA> atoms00;
556 std::set<TA> atoms01;
557 for (
const auto& I: list_A0_pair_R)
561 for (
const auto& JR: list_A1_pair_R)
563 atoms01.insert(JR.first);
565 std::map<TA, std::map<TAC, RI::Tensor<Tdata>>> overlap_abfs_abfs_IJ
567 overlap_abfs_abfs.clear();
568 std::map<TA, std::map<TAC, RI::Tensor<Tdata>>> overlap_abfs_abf_IJ
570 overlap_abfs_abf.clear();
572 out_abfs_overlap(ucell, overlap_abfs_abfs_IJ, overlap_abfs_abf_IJ,
"shrink_sinvS_", index_abfs_s, index_abfs);
575template <
typename T,
typename Tdata>
577 std::map<
TA, std::map<
TAC, RI::Tensor<Tdata>>>& overlap_abfs_abfs,
578 std::map<
TA, std::map<
TAC, RI::Tensor<Tdata>>>& overlap_abfs_abf,
579 std::string filename,
586 const auto format = std::scientific;
591 std::vector<int> mu_s_shift(ucell.
nat);
592 std::vector<int> mu_shift(ucell.
nat);
593 for (
int I = 0; I != ucell.
nat; I++)
595 mu_s_shift[I] = all_mu_s;
596 mu_shift[I] = all_mu;
597 all_mu_s += index_abfs_s[ucell.
iat2it[I]].count_size;
598 all_mu += index_abfs[ucell.
iat2it[I]].count_size;
600 const int nks_tot =
PARAM.
inp.
nspin == 2 ? (int)p_kv->get_nks() / 2 : p_kv->get_nks();
601 std::stringstream ss;
605 ofs.open(ss.str().c_str(), std::ios::out);
607 ofs << nks_tot << std::endl;
610 std::map<TA, std::map<TAq, RI::Tensor<std::complex<double>>>> olp_q_ss;
611 std::map<TA, std::map<TAq, RI::Tensor<std::complex<double>>>> olp_q_s;
612 for (
int ik = 0; ik != nks_tot; ik++)
614 for (
auto& Ip: overlap_abfs_abfs)
617 for (
auto& JPp: Ip.second)
619 auto J = JPp.first.first;
620 auto R = JPp.first.second;
622 RI::Tensor<std::complex<double>> tmp_olp_ss
623 = RI::Global_Func::convert<std::complex<double>>(JPp.second);
624 RI::Tensor<std::complex<double>> tmp_olp_s
625 = RI::Global_Func::convert<std::complex<double>>(overlap_abfs_abf[I][{J, R}]);
626 if (olp_q_ss[I][{J, q}].empty())
628 olp_q_ss[I][{J, q}] = RI::Tensor<std::complex<double>>({tmp_olp_ss.shape[0], tmp_olp_ss.shape[1]});
629 olp_q_s[I][{J, q}] = RI::Tensor<std::complex<double>>({tmp_olp_s.shape[0], tmp_olp_s.shape[1]});
633 const std::complex<double> kphase = std::complex<double>(cos(arg), sin(arg));
635 olp_q_ss[I][{J, q}] = olp_q_ss[I][{J, q}] + tmp_olp_ss * kphase;
636 olp_q_s[I][{J, q}] = olp_q_s[I][{J, q}] + tmp_olp_s * kphase;
641 for (
int I = 0; I != ucell.
nat; I++)
643 for (
int J = 0; J != ucell.
nat; J++)
645 for (
int ik = 0; ik != nks_tot; ik++)
648 if (olp_q_ss[I][{J, q}].empty())
650 auto mu = index_abfs_s[ucell.
iat2it[I]].count_size;
651 auto nu = index_abfs_s[ucell.
iat2it[J]].count_size;
652 olp_q_ss[I][{J, q}] = RI::Tensor<std::complex<double>>({mu, nu});
654 if (olp_q_s[I][{J, q}].empty())
656 auto mu = index_abfs_s[ucell.
iat2it[I]].count_size;
657 auto nu = index_abfs[ucell.
iat2it[J]].count_size;
658 olp_q_s[I][{J, q}] = RI::Tensor<std::complex<double>>({mu, nu});
660 for (
int ir = 0; ir < olp_q_ss[I][{J, q}].shape[0]; ir++)
662 for (
int ic = 0; ic < olp_q_ss[I][{J, q}].shape[1]; ic++)
664 Parallel_Reduce::reduce_all<std::complex<double>>(olp_q_ss[I][{J, q}](ir, ic));
666 for (
int ic = 0; ic < olp_q_s[I][{J, q}].shape[1]; ic++)
668 Parallel_Reduce::reduce_all<std::complex<double>>(olp_q_s[I][{J, q}](ir, ic));
677 inverse_olp(ucell, olp_q_ss, index_abfs_s);
680 for (
auto& Ip: overlap_abfs_abf)
683 size_t mu_num_s = index_abfs_s[ucell.
iat2it[I]].count_size;
684 size_t mu_num = index_abfs[ucell.
iat2it[I]].count_size;
686 for (
int ik = 0; ik != nks_tot; ik++)
688 std::map<size_t, RI::Tensor<std::complex<double>>> sinvS;
689 for (
auto& JPp: Ip.second)
691 auto J = JPp.first.first;
692 auto R = JPp.first.second;
693 if (sinvS[J].empty())
695 sinvS[J] = RI::Tensor<std::complex<double>>(
696 {overlap_abfs_abfs[I][{J, R}].shape[0], overlap_abfs_abf[I][{J, R}].shape[1]});
699 for (
const auto& pair: sinvS)
703 for (
int K = 0; K != ucell.
nat; K++)
705 sinvS[J] += olp_q_ss.at(I).at({K, q}) * olp_q_s.at(K).at({J, q});
708 for (
auto& iJU: sinvS)
711 auto& vq_J = iJU.second;
712 size_t nu_num = index_abfs[ucell.
iat2it[iJ]].count_size;
713 ofs << all_mu_s <<
" " << all_mu <<
" " << mu_s_shift[I] + 1 <<
" " << mu_s_shift[I] + mu_num_s
714 <<
" " << mu_shift[iJ] + 1 <<
" " << mu_shift[iJ] + nu_num << std::endl;
715 ofs << ik + 1 <<
" " << p_kv->wk[ik] / 2.0 *
PARAM.
inp.
nspin << std::endl;
716 for (
int i = 0;
i != vq_J.data->size();
i++)
722 ofs << std::showpoint << format << std::setprecision(prec) << (*vq_J.data)[
i].real() <<
" "
723 << std::showpoint << format << std::setprecision(prec) << (*vq_J.data)[
i].imag() <<
"\n";
735template <
typename T,
typename Tdata>
737 std::map<
TA, std::map<
TAq, RI::Tensor<std::complex<double>>>>& overlap_abfs_abfs,
742 const int nks_tot =
PARAM.
inp.
nspin == 2 ? (int)p_kv->get_nks() / 2 : p_kv->get_nks();
744 std::vector<int> mu_s_shift(ucell.
nat);
745 for (
int I = 0; I != ucell.
nat; I++)
747 mu_s_shift[I] = all_mu_s;
748 all_mu_s += index_abfs_s[ucell.
iat2it[I]].count_size;
750 RI::Tensor<std::complex<double>> olp_all = RI::Tensor<std::complex<double>>({all_mu_s, all_mu_s});
751 for (
int ik = 0; ik < nks_tot; ik++)
753 for (
auto& Ip: overlap_abfs_abfs)
756 size_t mu_s_I = index_abfs_s[ucell.
iat2it[I]].count_size;
757 for (
auto& JPp: Ip.second)
759 auto J = JPp.first.first;
760 auto q = JPp.first.second;
764 auto mu_s_J = index_abfs_s[ucell.
iat2it[J]].count_size;
765 for (
int ir = 0; ir < mu_s_I; ir++)
767 for (
int ic = 0; ic < mu_s_J; ic++)
769 olp_all(mu_s_shift[I] + ir, mu_s_shift[J] + ic) = JPp.second(ir, ic);
784 for (
int ir = 0; ir < all_mu_s; ir++)
786 for (
int ic = ir; ic < all_mu_s; ic++)
788 auto delta = std::abs(olp_all(ir, ic) - std::conj(olp_all(ic, ir)));
791 std::cout <<
"Warning: olp_all is not Hermitian!" << std::endl;
792 std::cout <<
"ik,ir,ic: " << ik <<
"," << ir <<
"," << ic << std::endl;
793 std::cout <<
"delta(ir, ic): " << delta << std::endl;
801 for (
int ir = 0; ir < all_mu_s; ir++)
803 for (
int ic = ir; ic < all_mu_s; ic++)
805 olp_inv(ic, ir) = std::conj(olp_inv(ir, ic));
809 for (
auto& Ip: overlap_abfs_abfs)
812 size_t mu_s_I = index_abfs_s[ucell.
iat2it[I]].count_size;
813 for (
auto& JPp: Ip.second)
815 auto q = JPp.first.second;
818 auto J = JPp.first.first;
819 auto mu_s_J = index_abfs_s[ucell.
iat2it[J]].count_size;
821 for (
int ir = 0; ir < mu_s_I; ir++)
823 for (
int ic = 0; ic < mu_s_J; ic++)
824 JPp.second(ir, ic) = olp_inv(mu_s_shift[I] + ir, mu_s_shift[J] + ic);
935template <
typename T,
typename Tdata>
941 const int nks_tot =
PARAM.
inp.
nspin == 2 ? p_kv->get_nks() / 2 : p_kv->get_nks();
943 const std::complex<double>
zero(0.0, 0.0);
945 for (
int ik = 0; ik < nks_tot; ik++)
947 std::stringstream ss;
948 ss <<
"KS_eigenvector_" << ik <<
".dat";
953 ofs.open(ss.str().c_str(), std::ios::out);
955 std::vector<ModuleBase::ComplexMatrix> is_wfc_ib_iw(npsin_tmp);
956 for (
int is = 0; is < npsin_tmp; is++)
959 for (
int ib_global = 0; ib_global <
PARAM.
inp.
nbands; ++ib_global)
967 for (
int ir = 0; ir <
psi.get_nbasis(); ir++)
973 std::vector<std::complex<double>> tmp = wfc_iks;
975 MPI_Allreduce(&tmp[0], &wfc_iks[0],
PARAM.
globalv.
nlocal, MPI_DOUBLE_COMPLEX, MPI_SUM, MPI_COMM_WORLD);
979 is_wfc_ib_iw[is](ib_global, iw) = wfc_iks[iw];
983 ofs << ik + 1 << std::endl;
988 for (
int is = 0; is < npsin_tmp; is++)
990 ofs << std::setw(30) << std::fixed << std::setprecision(15) << is_wfc_ib_iw[is](ib, iw).real()
991 << std::setw(30) << std::fixed << std::setprecision(15) << is_wfc_ib_iw[is](ib, iw).imag()
1001template <
typename T,
typename Tdata>
1010 const int nks_tot =
PARAM.
inp.
nspin == 2 ? (int)p_kv->get_nks() / 2 : p_kv->get_nks();
1013 std::stringstream ss;
1016 ofs.open(ss.str().c_str(), std::ios::out);
1017 ofs << lat.
e11 << std::setw(15) << lat.
e12 << std::setw(15) << lat.
e13 << std::endl;
1018 ofs << lat.
e21 << std::setw(15) << lat.
e22 << std::setw(15) << lat.
e23 << std::endl;
1019 ofs << lat.
e31 << std::setw(15) << lat.
e32 << std::setw(15) << lat.
e33 << std::endl;
1021 ofs << G_RPA.
e11 << std::setw(15) << G_RPA.
e12 << std::setw(15) << G_RPA.
e13 << std::endl;
1022 ofs << G_RPA.
e21 << std::setw(15) << G_RPA.
e22 << std::setw(15) << G_RPA.
e23 << std::endl;
1023 ofs << G_RPA.
e31 << std::setw(15) << G_RPA.
e32 << std::setw(15) << G_RPA.
e33 << std::endl;
1025 ofs << ucell.
nat << std::endl;
1027 bool direct = (Coordinate ==
"Direct");
1029 for (
int it = 0; it < ucell.
ntype; it++)
1032 for (
int ia = 0; ia < ucell.
atoms[it].
na; ia++)
1034 const double& x = direct ? ucell.
atoms[it].
tau[ia].x * ucell.
lat0
1036 const double& y = direct ? ucell.
atoms[it].
tau[ia].y * ucell.
lat0
1038 const double& z = direct ? ucell.
atoms[it].
tau[ia].z * ucell.
lat0
1040 ofs << std::setw(15) << std::fixed << std::setprecision(9) << x << std::setw(15) << std::fixed
1041 << std::setprecision(9) << y << std::setw(15) << std::fixed << std::setprecision(9) << z
1042 << std::setw(15) << 1 << std::endl;
1046 ofs << p_kv->nmp[0] << std::setw(6) << p_kv->nmp[1] << std::setw(6) << p_kv->nmp[2] << std::setw(6) << std::endl;
1048 for (
int ik = 0; ik != nks_tot; ik++)
1050 ofs << std::setw(15) << std::fixed << std::setprecision(9) << p_kv->kvec_c[ik].x * TWOPI_Bohr2A << std::setw(15)
1051 << std::fixed << std::setprecision(9) << p_kv->kvec_c[ik].y * TWOPI_Bohr2A << std::setw(15) << std::fixed
1052 << std::setprecision(9) << p_kv->kvec_c[ik].z * TWOPI_Bohr2A << std::endl;
1057 for (
int ik = 0; ik != nks_tot; ++ik)
1059 ofs << (ik + 1) << std::endl;
1066template <
typename T,
typename Tdata>
1074 const int nks_tot =
PARAM.
inp.
nspin == 2 ? (int)p_kv->get_nks() / 2 : p_kv->get_nks();
1076 std::stringstream ss;
1079 ofs.open(ss.str().c_str(), std::ios::out);
1080 ofs << nks_tot << std::endl;
1081 ofs << nspin_tmp << std::endl;
1084 ofs << (pelec->
eferm.
ef / 2.0) << std::endl;
1086 for (
int ik = 0; ik != nks_tot; ik++)
1088 for (
int is = 0; is != nspin_tmp; is++)
1090 ofs << std::setw(6) << ik + 1 << std::setw(6) << is + 1 << std::endl;
1093 ofs << std::setw(5) << ib + 1 <<
" " << std::setw(8) << pelec->
wg(ik + is * nks_tot, ib) * nks_tot
1094 << std::setw(25) << std::fixed << std::setprecision(15) << pelec->
ekb(ik + is * nks_tot, ib) / 2.0
1095 << std::setw(25) << std::fixed << std::setprecision(15)
1104template <
typename T,
typename Tdata>
1110 std::stringstream ss;
1113 ofs.open(ss.str().c_str(), std::ios::out);
1114 ofs << ucell.
nat <<
" " << 0 << std::endl;
1115 for (
auto& Ip: Cs_in)
1117 size_t I = Ip.first;
1119 for (
auto& JPp: Ip.second)
1121 size_t J = JPp.first.first;
1122 auto R = JPp.first.second;
1123 auto& tmp_Cs = JPp.second;
1126 ofs << I + 1 <<
" " << J + 1 <<
" " << R[0] <<
" " << R[1] <<
" " << R[2] <<
" " << i_num
1128 ofs << j_num <<
" " << tmp_Cs.shape[0] << std::endl;
1129 for (
int i = 0;
i != i_num;
i++)
1131 for (
int j = 0; j != j_num; j++)
1133 for (
int mu = 0; mu != tmp_Cs.shape[0]; mu++)
1135 ofs << std::setw(30) << std::fixed << std::setprecision(15) << tmp_Cs(mu,
i, j) << std::endl;
1146template <
typename T,
typename Tdata>
1148 std::map<
TA, std::map<
TAC, RI::Tensor<Tdata>>>& Vs,
1149 std::string filename,
1156 std::vector<int> mu_shift(ucell.
nat);
1159 throw std::invalid_argument(std::string(__FILE__) +
" line " + std::to_string(__LINE__));
1163 : exx_lri->
exx_objs.begin()->first;
1164 for (
int I = 0; I != ucell.
nat; I++)
1166 mu_shift[I] = all_mu;
1167 all_mu += exx_lri->
exx_objs.at(basis_method).cv.get_index_abfs_size(ucell.
iat2it[I]);
1169 const int nks_tot =
PARAM.
inp.
nspin == 2 ? (int)p_kv->get_nks() / 2 : p_kv->get_nks();
1170 std::stringstream ss;
1174 ofs.open(ss.str().c_str(), std::ios::out);
1176 ofs << nks_tot << std::endl;
1180 size_t mu_num = exx_lri->
exx_objs.at(basis_method).cv.get_index_abfs_size(ucell.
iat2it[I]);
1182 for (
int ik = 0; ik != nks_tot; ik++)
1184 std::map<size_t, RI::Tensor<std::complex<double>>> Vq_k_IJ;
1185 for (
auto& JPp: Ip.second)
1187 auto J = JPp.first.first;
1189 auto R = JPp.first.second;
1194 RI::Tensor<std::complex<double>> tmp_VR = RI::Global_Func::convert<std::complex<double>>(JPp.second);
1197 const std::complex<double> kphase = std::complex<double>(cos(arg), sin(arg));
1198 if (Vq_k_IJ[J].empty())
1200 Vq_k_IJ[J] = RI::Tensor<std::complex<double>>({tmp_VR.shape[0], tmp_VR.shape[1]});
1202 Vq_k_IJ[J] = Vq_k_IJ[J] + tmp_VR * kphase;
1204 for (
auto& vq_Jp: Vq_k_IJ)
1206 auto iJ = vq_Jp.first;
1207 auto& vq_J = vq_Jp.second;
1208 size_t nu_num = exx_lri->
exx_objs.at(basis_method).cv.get_index_abfs_size(ucell.
iat2it[iJ]);
1209 ofs << all_mu <<
" " << mu_shift[I] + 1 <<
" " << mu_shift[I] + mu_num <<
" " << mu_shift[iJ] + 1
1210 <<
" " << mu_shift[iJ] + nu_num << std::endl;
1211 ofs << ik + 1 <<
" " << p_kv->wk[ik] / 2.0 *
PARAM.
inp.
nspin << std::endl;
1212 for (
int i = 0;
i != vq_J.data->size();
i++)
1214 ofs << std::setw(25) << std::fixed << std::setprecision(15) << (*vq_J.data)[
i].real()
1215 << std::setw(25) << std::fixed << std::setprecision(15) << (*vq_J.data)[
i].imag() << std::endl;
Exx_LRI< double > exx_lri_rpa(GlobalC::exx_info.info_ri)
const std::complex< double > i
Definition cal_pLpR.cpp:46
int na
Definition atom_spec.h:27
int nw
Definition atom_spec.h:22
std::vector< ModuleBase::Vector3< double > > tau
Definition atom_spec.h:35
static void print_orbs_size(const UnitCell &ucell, const std::vector< std::vector< std::vector< Numerical_Orbital_Lm > > > &orbs, std::ostream &os)
Definition exx_abfs-construct_orbs.cpp:475
static std::vector< std::vector< std::vector< Numerical_Orbital_Lm > > > abfs_same_atom(const UnitCell &ucell, const LCAO_Orbitals &orb, const std::vector< std::vector< std::vector< Numerical_Orbital_Lm > > > &lcaos, const double kmesh_times_mot, const double times_threshold=0)
Definition exx_abfs-construct_orbs.cpp:80
static std::vector< std::vector< std::vector< Numerical_Orbital_Lm > > > change_orbs(const LCAO_Orbitals &orb_in, const double kmesh_times)
Definition exx_abfs-construct_orbs.cpp:10
static std::vector< std::vector< std::vector< Numerical_Orbital_Lm > > > construct_abfs(const LCAO_Orbitals &orbs, const std::vector< std::string > &files_abfs, const double kmesh_times=1)
Definition exx_abfs-io.cpp:12
void cal_cut_coulomb_cs(std::map< TA, std::map< TAC, RI::Tensor< Tdata > > > &Vs_cut_IJR, std::map< TA, std::map< TAC, RI::Tensor< Tdata > > > &Cs, const UnitCell &ucell, const bool write_cv=false)
Definition Exx_LRI.hpp:760
std::map< Conv_Coulomb_Pot_K::Coulomb_Method, Exx_Obj< Tdata > > exx_objs
Definition Exx_LRI.h:126
RI::Exx< TA, Tcell, Ndim, Tdata > exx_lri
Definition Exx_LRI.h:128
Definition Inverse_Matrix.h:15
int get_nkstot_full() const
Definition klist.h:78
int get_nks() const
Definition klist.h:68
std::vector< double > cutoffs() const
Definition ORB_read.cpp:39
Definition Matrix_Orbs11.h:22
void init_radial_table()
Definition Matrix_Orbs11.cpp:93
std::shared_ptr< ORB_gaunt_table > MGT
Definition Matrix_Orbs11.h:64
void init(const std::vector< std::vector< std::vector< Numerical_Orbital_Lm > > > &orb_A, const std::vector< std::vector< std::vector< Numerical_Orbital_Lm > > > &orb_B, const UnitCell &ucell, const LCAO_Orbitals &orb, const double kmesh_times)
Definition Matrix_Orbs11.cpp:12
Definition Mix_DMk_2D.h:16
std::vector< const std::vector< std::complex< double > > * > get_DMk_k_out() const
Returns the complex density matrix.
Definition Mix_DMk_2D.cpp:66
Mix_DMk_2D & set_mixing(Base_Mixing::Mixing *mixing_in)
Sets the mixing mode.
Definition Mix_DMk_2D.cpp:20
void mix(const std::vector< std::vector< double > > &dm, const bool flag_restart)
Mixes the double density matrix.
Definition Mix_DMk_2D.cpp:44
std::vector< const std::vector< double > * > get_DMk_gamma_out() const
Returns the double density matrix.
Definition Mix_DMk_2D.cpp:59
Mix_DMk_2D & set_nks(const int nks, const bool gamma_only_in)
Sets the number of k-points and gamma_only flag.
Definition Mix_DMk_2D.cpp:9
3x3 matrix and related mathamatical operations
Definition matrix3.h:19
double e13
Definition matrix3.h:26
double e31
Definition matrix3.h:26
double e11
element e_ij: i_row, j_column
Definition matrix3.h:26
double e33
Definition matrix3.h:26
double e32
Definition matrix3.h:26
double e21
Definition matrix3.h:26
double e12
Definition matrix3.h:26
double e23
Definition matrix3.h:26
double e22
Definition matrix3.h:26
3 elements vector
Definition vector3.h:24
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
Definition symmetry_rotation.h:16
void set_abfs_Lmax(const int l)
Definition symmetry_rotation.h:44
std::vector< std::vector< std::complex< double > > > restore_dm(const K_Vectors &kv, const std::vector< std::vector< std::complex< double > > > &dm_k_ibz, const Parallel_2D &pv) const
Definition symmetry_rotation.cpp:78
void cal_Ms(const K_Vectors &kv, const UnitCell &ucell, const Parallel_2D &pv)
functions to contruct rotation matrix in AO-representation
Definition symmetry_rotation.cpp:19
void find_irreducible_sector(const Symmetry &symm, const Atom *atoms, const Statistics &st, const std::vector< TC > &Rs, const TC &period, const Lattice &lat)
Definition symmetry_rotation.h:39
static int symm_flag
Definition symmetry.h:29
int local2global_row(const int ilr) const
get the global index of a local index (row)
Definition parallel_2d.h:57
int global2local_col(const int igc) const
get the local index of a global index (col)
Definition parallel_2d.h:51
Definition parallel_orbitals.h:9
const Input_para & inp
Definition parameter.h:26
const System_para & globalv
Definition parameter.h:30
std::pair< TA, Tq > TAq
Definition RPA_LRI.h:33
void cal_postSCF_exx(const elecstate::DensityMatrix< T, Tdata > &dm, const MPI_Comm &mpi_comm_in, const UnitCell &ucell, const K_Vectors &kv, const LCAO_Orbitals &orb)
Definition RPA_LRI.hpp:103
void output_cut_coulomb_cs(const UnitCell &ucell, Exx_LRI< double > *exx_lri_rpa)
Definition RPA_LRI.hpp:200
void cal_large_Cs(const UnitCell &ucell, const LCAO_Orbitals &orb, const K_Vectors &kv)
Definition RPA_LRI.hpp:311
void out_abfs_overlap(const UnitCell &ucell, std::map< TA, std::map< TAC, RI::Tensor< Tdata > > > &overlap_abfs_abfs, std::map< TA, std::map< TAC, RI::Tensor< Tdata > > > &overlap_abfs_abf, std::string filename, const ModuleBase::Element_Basis_Index::IndexLNM &index_abfs_s, const ModuleBase::Element_Basis_Index::IndexLNM &index_abfs)
Definition RPA_LRI.hpp:576
void out_Cs(const UnitCell &ucell, std::map< TA, std::map< TAC, RI::Tensor< Tdata > > > &Cs_in, std::string filename)
Definition RPA_LRI.hpp:1105
void out_bands(const elecstate::ElecState *pelec)
Definition RPA_LRI.hpp:1067
void out_coulomb_k(const UnitCell &ucell, std::map< TA, std::map< TAC, RI::Tensor< Tdata > > > &Vs, std::string filename, Exx_LRI< double > *exx_lri)
Definition RPA_LRI.hpp:1147
void inverse_olp(const UnitCell &ucell, std::map< TA, std::map< TAq, RI::Tensor< std::complex< double > > > > &overlap_abfs_abfs, const ModuleBase::Element_Basis_Index::IndexLNM &index_abfs_s)
Definition RPA_LRI.hpp:736
void postSCF(const UnitCell &ucell, const MPI_Comm &mpi_comm_in, const elecstate::DensityMatrix< T, Tdata > &dm, const elecstate::ElecState *pelec, const K_Vectors &kv, const LCAO_Orbitals &orb, const Parallel_Orbitals ¶v, const psi::Psi< T > &psi)
Definition RPA_LRI.hpp:37
void out_struc(const UnitCell &ucell)
Definition RPA_LRI.hpp:1002
int TA
Definition RPA_LRI.h:27
void output_ewald_coulomb(const UnitCell &ucell, const K_Vectors &kv, const LCAO_Orbitals &orb)
Definition RPA_LRI.hpp:254
std::pair< TA, TC > TAC
Definition RPA_LRI.h:32
void out_eigen_vector(const Parallel_Orbitals ¶v, const psi::Psi< T > &psi)
Definition RPA_LRI.hpp:936
void cal_abfs_overlap(const UnitCell &ucell, const LCAO_Orbitals &orb, const K_Vectors &kv)
Definition RPA_LRI.hpp:418
void init(const MPI_Comm &mpi_comm_in, const K_Vectors &kv_in, const std::vector< double > &orb_cutoff)
Definition RPA_LRI.hpp:79
int *& iat2it
Definition unitcell.h:75
Atom * atoms
Definition unitcell.h:45
double & lat0
Definition unitcell.h:56
ModuleBase::Matrix3 & latvec
Definition unitcell.h:63
Lattice lat
Definition unitcell.h:53
int lmax
Definition unitcell.h:213
int & ntype
Definition unitcell.h:73
ModuleSymmetry::Symmetry symm
Definition unitcell.h:83
int & nat
Definition unitcell.h:74
ModuleBase::Vector3< double > & a2
Definition unitcell.h:64
ModuleBase::Vector3< double > & a3
Definition unitcell.h:64
std::string & Coordinate
Definition unitcell.h:54
int *& iat2ia
Definition unitcell.h:76
ModuleBase::Vector3< double > & a1
Definition unitcell.h:64
Statistics st
Definition unitcell.h:72
ModuleBase::Matrix3 & G
Definition unitcell.h:67
Definition density_matrix.h:70
const std::vector< std::vector< TK > > & get_DMK_vector() const
get pointer vector of DMK
Definition density_matrix.h:198
const Parallel_Orbitals * get_paraV_pointer() const
get pointer of paraV
Definition density_matrix.h:210
Definition elecstate.h:15
fenergy f_en
energies contribute to the total free energy
Definition elecstate.h:148
ModuleBase::matrix wg
occupation weight for each k-point and band
Definition elecstate.h:158
ModuleBase::matrix ekb
band energy at each k point, each band.
Definition elecstate.h:157
Efermi eferm
fermi energies
Definition elecstate.h:149
Exx_Info exx_info
Definition exx_info.cpp:8
int MY_RANK
global index of process
Definition global_variable.cpp:21
std::ofstream ofs_running
Definition global_variable.cpp:38
Range construct_range(const LCAO_Orbitals &orb)
Definition element_basis_index-ORB.cpp:10
IndexLNM construct_index(const Range &range)
Definition element_basis_index.cpp:12
std::vector< Index_T > IndexLNM
Definition element_basis_index.h:42
std::vector< std::vector< NM > > Range
Definition element_basis_index.h:41
void DONE(std::ofstream &ofs, const std::string &description, const bool only_rank0)
Definition global_function.cpp:80
const double TWO_PI
Definition constants.h:21
const double BOHR_TO_A
Definition constants.h:55
const double Ry_to_eV
Definition constants.h:81
void TITLE(const std::string &class_name, const std::string &function_name, const bool disable)
Definition tool_title.cpp:18
void print_symrot_info_k(const ModuleSymmetry::Symmetry_rotation &symrot, const K_Vectors &kv, const UnitCell &ucell)
Definition symmetry_rotation_output.cpp:54
void print_symrot_info_R(const Symmetry_rotation &symrot, const Symmetry &symm, const int lmax_ao, const std::vector< TC > &Rs)
Definition symmetry_rotation_output.cpp:14
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:495
std::array< Tcell, 3 > Vector3_to_array3(const ModuleBase::Vector3< Tcell > &v)
Definition RI_Util.h:32
std::array< int, 3 > get_Born_vonKarmen_period(const K_Vectors &kv)
Definition RI_Util.hpp:16
std::vector< std::array< Tcell, Ndim > > get_Born_von_Karmen_cells(const std::array< Tcell, Ndim > &Born_von_Karman_period)
Definition RI_Util.hpp:34
ModuleBase::Vector3< Tcell > array3_to_Vector3(const std::array< Tcell, 3 > &v)
Definition RI_Util.h:38
Definition RPA_LRI.hpp:27
void trim_malloc_cache()
Definition RPA_LRI.hpp:28
Parameter PARAM
Definition parameter.cpp:3
#define threshold
Definition sph_bessel_recursive_test.cpp:4
double hybrid_alpha
Definition exx_info.h:30
Conv_Coulomb_Pot_K::Ccp_Type ccp_type
Definition exx_info.h:29
double ccp_rmesh_times
Definition exx_info.h:69
Exx_Info_Global info_global
Definition exx_info.h:37
Exx_Info_RI info_ri
Definition exx_info.h:86
int nlocal
total number of local basis.
Definition system_parameter.h:23
bool gamma_only_local
Definition system_parameter.h:38
double ef
Fermi energy.
Definition fp_energy.h:65
double etot
the total free energy
Definition fp_energy.h:18
double etxc
E_xc[n(r)] exchange and correlation energy.
Definition fp_energy.h:24
const std::map< std::string, std::vector< double > > zero
Definition vdwd3_autoset_xcparam.cpp:326