1717#include < omp.h>
1818#endif
1919namespace LR_IO {
20- const std::string FILE_COARSE = " stru_out" ;
21- const std::string FILE_FINE_UNIFORM = " band_kpath_info" ;
22- const std::string FILE_FINE_NONUNIFORM = " KPT_bse" ;
23- const std::string FILE_BAND_OUT = " band_out" ;
24- const std::string FILE_BAND_KPATH = " band_kpath_info" ;
2520
2621void parse_band_out_file (const std::string& in_dir, int & nbands_file, int & nk_file, int & nspin_file, int & nocc_file)
2722{
28- std::string file = in_dir + FILE_BAND_OUT ;
23+ std::string file = in_dir + " band_out " ;
2924 std::ifstream ifs (file);
3025 if (!ifs) throw std::runtime_error (file + " not found" );
3126 std::string tmp, line;
@@ -52,7 +47,7 @@ void parse_band_out_file(const std::string& in_dir, int& nbands_file, int& nk_fi
5247
5348 if (PARAM .inp .bse_use_fine_kgrid )
5449 {
55- file = in_dir + FILE_BAND_KPATH ;
50+ file = in_dir + " band_kpath_info " ;
5651 std::ifstream ifs (file);
5752 if (!ifs) throw std::runtime_error (file + " not found" );
5853 std::string tmp;
@@ -65,151 +60,6 @@ void parse_band_out_file(const std::string& in_dir, int& nbands_file, int& nk_fi
6560 }
6661}
6762
68- #ifdef __EXX
69-
70- RI_kRlist::RI_kRlist (const UnitCell& ucell, K_Vectors* const pkv,
71- const std::string& in_dir, const int use_fine_kgrid, const std::string& out_dir)
72- : klist(pkv)
73- {
74- read_kpts_coarse (in_dir + FILE_COARSE , ucell, this ->klist , out_dir);
75- this ->klist_coarse = *this ->klist ;
76- this ->period = RI_Util::get_Born_vonKarmen_period (*klist);
77- this ->Rlist = RI_Util::get_Born_von_Karmen_cells (period);
78- // std::cout << "Rlist:" << std::endl;
79- // int count = 0;
80- // for (const auto& iR: Rlist)
81- // {
82- // count++;
83- // std::cout << "iR=" << count <<": "<< iR[0] << " " << iR[1] << " " << iR[2] << std::endl;
84- // }
85- if (use_fine_kgrid==1 )
86- {
87- read_kpts_fine (in_dir + FILE_FINE_UNIFORM , ucell, this ->klist , false , out_dir);
88- }
89- else if (use_fine_kgrid==2 )
90- {
91- read_kpts_fine (in_dir + FILE_FINE_NONUNIFORM , ucell, this ->klist , true , out_dir);
92- }
93- else if (use_fine_kgrid!=0 )
94- ModuleBase::WARNING_QUIT (" LR_IO" , " use_fine_kgrid must be 0, 1 or 2" );
95- };
96-
97- void RI_kRlist::read_kpts_coarse (const std::string& file, const UnitCell& ucell,
98- K_Vectors* const klist, const std::string& out_dir)
99- {
100- std::ifstream ifs;
101- ifs.open (file);
102- if (!ifs) throw std::runtime_error (file + " not found" );
103- std::string tmp;
104- for (int i = 0 ; i < 7 ; ++i) { std::getline (ifs, tmp); } // get the 7th line(number of atoms)
105- int nat = std::stoi (tmp);
106- for (int i = 0 ; i != nat; ++i) { std::getline (ifs, tmp); }
107- int nks_original = klist->get_nks ();
108- // std::cout << "Origianl klist (Cartesian|Direct)" << std::endl;
109- // for (int ik = 0;ik < nks_original;++ik)
110- // {
111- // std::cout << "ik=" << std::setw(5) << ik << std::setw(11) << klist->kvec_c[ik].x << std::setw(11)
112- // << klist->kvec_c[ik].y << std::setw(11) << klist->kvec_c[ik].z << " | " << std::setw(11)
113- // << klist->kvec_d[ik].x << std::setw(11) << klist->kvec_d[ik].y << std::setw(11) << klist->kvec_d[ik].z << std::endl;
114- // }
115-
116- ifs >> klist->nmp [0 ] >> klist->nmp [1 ] >> klist->nmp [2 ];
117- int nk = klist->nmp [0 ] * klist->nmp [1 ] * klist->nmp [2 ];
118- int nks = (PARAM .inp .nspin == 2 ) ? 2 * nk : nk;
119- assert (nks == nks_original);
120-
121- for (int ik = 0 ; ik < nk; ++ik)
122- {
123- ifs >> klist->kvec_c [ik].x >> klist->kvec_c [ik].y >> klist->kvec_c [ik].z ;
124- klist->kvec_c [ik] /= ModuleBase::TWO_PI * ModuleBase::BOHR_TO_A ; // in unit of 2pi/angstrom
125- klist->kvec_d [ik] = klist->kvec_c [ik] * ucell.latvec .Transpose ();
126- set_zero_if_close (klist->kvec_d [ik]);
127- klist->wk [ik] = 1.0 / double (nk);
128- }
129- if (PARAM .inp .nspin == 2 )
130- {
131- for (int ik = 0 ; ik < nk; ++ik)
132- {
133- klist->kvec_c [ik + nk] = klist->kvec_c [ik];
134- klist->kvec_d [ik + nk] = klist->kvec_d [ik];
135- klist->wk [ik + nk] = klist->wk [ik];
136- }
137- }
138-
139- std::ofstream ofs_kpts_coarse (out_dir + " kpts_coarse.dat" );
140- ofs_kpts_coarse << " kpts_coarse:" << nk << std::setw (16 ) << " ( Cartesian" << std::setw (36 )
141- << " | Direct )" << std::setw (15 ) << " | wk (normalized as sum = nk)" << std::endl;
142- for (int ik = 0 ; ik < nks; ++ik)
143- {
144- ofs_kpts_coarse << std::setw (5 ) << ik << std::setw (12 ) << klist->kvec_c [ik].x << std::setw (12 )
145- << klist->kvec_c [ik].y << std::setw (12 ) << klist->kvec_c [ik].z << " | " << std::setw (12 )
146- << klist->kvec_d [ik].x << std::setw (12 ) << klist->kvec_d [ik].y << std::setw (12 ) << klist->kvec_d [ik].z
147- << " | " << klist->wk [ik]*nk << std::endl;
148- }
149- ofs_kpts_coarse.close ();
150- }
151-
152- void RI_kRlist::read_kpts_fine (const std::string& file, const UnitCell& ucell,
153- K_Vectors* const klist, const bool is_weighted,
154- const std::string& out_dir)
155- {
156- // band_kpath_info format: first line: nband nbasis nspin nk, then kx ky kz per line (direct coords)
157- // KPT_bse format: first line = nk, then kx ky kz wk per line (direct coords, BSE weight sum=nk)
158- std::ifstream ifs;
159- ifs.open (file);
160- if (!ifs) throw std::runtime_error (file + " not found" );
161- int nk;
162- if (is_weighted) {ifs >> nk; ifs.ignore (2048 , ' \n ' );}
163- else {ifs >> nk >> nk >> nk >> nk;}
164-
165- int nks = (PARAM .inp .nspin == 2 ) ? 2 * nk : nk;
166- klist->set_nks (nks);
167- klist->set_nkstot (nks);
168- klist->set_nkstot_full (nk);
169-
170- auto klist_reset = [&klist](int kpoint_number){
171- klist->kvec_c .resize (0 ); klist->kvec_c .resize (kpoint_number);
172- klist->kvec_d .resize (0 ); klist->kvec_d .resize (kpoint_number);
173- klist->wk .resize (0 ); klist->wk .resize (kpoint_number);
174- klist->isk .resize (0 );
175- klist->ngk .resize (0 );
176- };
177- klist_reset (nks);
178-
179- for (int ik = 0 ; ik < nk; ++ik)
180- {
181- ifs >> klist->kvec_d [ik].x >> klist->kvec_d [ik].y >> klist->kvec_d [ik].z ;
182- if (is_weighted) {
183- ifs >> klist->wk [ik];
184- klist->wk [ik] /= double (nk);
185- }
186- else {klist->wk [ik] = 1.0 / double (nk);}
187- klist->kvec_c [ik] = klist->kvec_d [ik] * ucell.G ;
188- set_zero_if_close (klist->kvec_c [ik]);
189- }
190- std::cout << " Read " << nk << " k-points and weights from " << file << std::endl;
191- if (PARAM .inp .nspin == 2 )
192- {
193- for (int ik = 0 ; ik < nk; ++ik)
194- {
195- klist->kvec_c [ik + nk] = klist->kvec_c [ik];
196- klist->kvec_d [ik + nk] = klist->kvec_d [ik];
197- klist->wk [ik + nk] = klist->wk [ik];
198- }
199- }
200- std::ofstream ofs_kpts_fine (out_dir + " kpts_fine.dat" );
201- ofs_kpts_fine << " kpts_fine:" << nk << std::setw (18 ) << " ( Cartesian" << std::setw (36 )
202- << " | Direct )" << std::setw (15 ) << " | wk (normalized as sum = nk)" << std::endl;
203- for (int ik = 0 ; ik < nk; ++ik)
204- {
205- ofs_kpts_fine << std::setw (5 ) << ik << std::setw (12 ) << klist->kvec_c [ik].x << std::setw (12 )
206- << klist->kvec_c [ik].y << std::setw (12 ) << klist->kvec_c [ik].z << " | " << std::setw (12 )
207- << klist->kvec_d [ik].x << std::setw (12 ) << klist->kvec_d [ik].y << std::setw (12 ) << klist->kvec_d [ik].z
208- << " | " << klist->wk [ik]*nk << std::endl;
209- }
210- ofs_kpts_fine.close ();
211- }
212-
21363std::vector<double > read_energy_qp (const int nocc,
21464 const int nvirt,
21565 const std::string& in_dir,
@@ -579,6 +429,27 @@ void read_librpa_eigenvectors_from_band_files(psi::Psi<TK>& wfc_ks,
579429 ModuleBase::GlobalFunc::DONE (GlobalV::ofs_running, " read librpa eigenvectors." );
580430}
581431
432+ template void read_librpa_eigenvectors<double >(
433+ psi::Psi<double >& wfc_ks, psi::Psi<double >& wfc_ks_global,
434+ const std::string& in_dir, const int ncore, const int nbands_file,
435+ const int nspin_tmp, const int nspin_file, const int my_rank, Parallel_Orbitals& pmat);
436+ template void read_librpa_eigenvectors<std::complex <double >>(
437+ psi::Psi<std::complex <double >>& wfc_ks, psi::Psi<std::complex <double >>& wfc_ks_global,
438+ const std::string& in_dir, const int ncore, const int nbands_file,
439+ const int nspin_tmp, const int nspin_file, const int my_rank, Parallel_Orbitals& pmat);
440+
441+ template void read_librpa_eigenvectors_from_band_files<double >(
442+ psi::Psi<double >& wfc_ks, psi::Psi<double >& wfc_ks_global,
443+ const std::string& in_dir, const int ncore, const int nbands_file,
444+ const int nspin_tmp, const int nspin_file, const int my_rank, Parallel_Orbitals& pmat);
445+ template void read_librpa_eigenvectors_from_band_files<std::complex <double >>(
446+ psi::Psi<std::complex <double >>& wfc_ks, psi::Psi<std::complex <double >>& wfc_ks_global,
447+ const std::string& in_dir, const int ncore, const int nbands_file,
448+ const int nspin_tmp, const int nspin_file, const int my_rank, Parallel_Orbitals& pmat);
449+
450+ // ================= LRI related functions =========================
451+
452+ #ifdef __EXX
582453template <typename TCs, typename TVs> // only for blocking by atom pairs
583454TLRI <TVs> read_coulomb_mat_k (const std::string& in_dir, const TLRI <TCs>& Cs, LR_IO ::RI_kRlist& kRlist )
584455{
@@ -913,44 +784,51 @@ TLRI<Tdata> read_Ws(const TLRI<TVs>& Vs, const std::vector<TC>& Rlist)
913784 ModuleBase::GlobalFunc::DONE (GlobalV::ofs_running, " read WR files." );
914785 return Ws;
915786}
916-
917- template void read_librpa_eigenvectors<double >(
918- psi::Psi<double >& wfc_ks, psi::Psi<double >& wfc_ks_global,
919- const std::string& in_dir, const int ncore, const int nbands_file,
920- const int nspin_tmp, const int nspin_file, const int my_rank, Parallel_Orbitals& pmat);
921-
922- template void read_librpa_eigenvectors<std::complex <double >>(
923- psi::Psi<std::complex <double >>& wfc_ks, psi::Psi<std::complex <double >>& wfc_ks_global,
924- const std::string& in_dir, const int ncore, const int nbands_file,
925- const int nspin_tmp, const int nspin_file, const int my_rank, Parallel_Orbitals& pmat);
926-
927- template void read_librpa_eigenvectors_from_band_files<double >(
928- psi::Psi<double >& wfc_ks, psi::Psi<double >& wfc_ks_global,
929- const std::string& in_dir, const int ncore, const int nbands_file,
930- const int nspin_tmp, const int nspin_file, const int my_rank, Parallel_Orbitals& pmat);
931-
932- template void read_librpa_eigenvectors_from_band_files<std::complex <double >>(
933- psi::Psi<std::complex <double >>& wfc_ks, psi::Psi<std::complex <double >>& wfc_ks_global,
934- const std::string& in_dir, const int ncore, const int nbands_file,
935- const int nspin_tmp, const int nspin_file, const int my_rank, Parallel_Orbitals& pmat);
787+ template <typename T>
788+ void write_lri_R_max_norm (const TLRI <T>& tensors,
789+ const UnitCell& ucell,
790+ const std::string& filename)
791+ {
792+ std::ofstream ofs (filename);
793+ if (!ofs) { throw std::runtime_error (" Cannot open " + filename); }
794+ ofs << " # iat jat Rx Ry Rz Rnorm_bohr tensor_max_abs\n " ;
795+ ofs << std::setprecision (16 );
796+ for (const auto & iat_blocks : tensors)
797+ {
798+ for (const auto & pair_tensor : iat_blocks.second )
799+ {
800+ const int jat = pair_tensor.first .first ;
801+ const auto & R = pair_tensor.first .second ;
802+ const ModuleBase::Vector3<double > R_cart =
803+ (static_cast <double >(R[0 ]) * ucell.a1
804+ + static_cast <double >(R[1 ]) * ucell.a2
805+ + static_cast <double >(R[2 ]) * ucell.a3 ) * ucell.lat0 ;
806+ ofs << iat_blocks.first << ' ' << jat << ' '
807+ << R[0 ] << ' ' << R[1 ] << ' ' << R[2 ] << ' ' << R_cart.norm () << ' '
808+ << pair_tensor.second .norm (std::numeric_limits<double >::max ()) << ' \n ' ;
809+ }
810+ }
811+ }
936812
937813template TLRI <double > read_coulomb_mat_k<double , double >
938- (const std::string& in_dir, const TLRI <double >& Cs, LR_IO ::RI_kRlist& kRlist );
939-
814+ (const std::string& in_dir, const TLRI <double >& Cs, LR_IO ::RI_kRlist& kRlist );
940815template TLRI <std::complex <double >> read_coulomb_mat_k<std::complex <double >, std::complex <double >>
941- (const std::string& in_dir, const TLRI <std::complex <double >>& Cs, LR_IO ::RI_kRlist& kRlist );
816+ (const std::string& in_dir, const TLRI <std::complex <double >>& Cs, LR_IO ::RI_kRlist& kRlist );
942817
943818template TLRI <double > read_coulomb_mat_general_k<double , double >
944- (const std::string& in_dir, const TLRI <double >& Cs, LR_IO ::RI_kRlist& kRlist );
945-
819+ (const std::string& in_dir, const TLRI <double >& Cs, LR_IO ::RI_kRlist& kRlist );
946820template TLRI <std::complex <double >> read_coulomb_mat_general_k<std::complex <double >, std::complex <double >>
947- (const std::string& in_dir, const TLRI <std::complex <double >>& Cs, LR_IO ::RI_kRlist& kRlist );
821+ (const std::string& in_dir, const TLRI <std::complex <double >>& Cs, LR_IO ::RI_kRlist& kRlist );
948822
949823template TLRI <double > read_Ws<double , double >
950- (const TLRI <double >& Vs, const std::vector<TC >& Rlist);
951-
824+ (const TLRI <double >& Vs, const std::vector<TC >& Rlist);
952825template TLRI <std::complex <double >> read_Ws<std::complex <double >, std::complex <double >>
953- (const TLRI <std::complex <double >>& Vs, const std::vector<TC >& Rlist);
826+ (const TLRI <std::complex <double >>& Vs, const std::vector<TC >& Rlist);
827+
828+ template void write_lri_R_max_norm<double >
829+ (const TLRI <double >& tensors, const UnitCell& ucell, const std::string& filename);
830+ template void write_lri_R_max_norm<std::complex <double >>
831+ (const TLRI <std::complex <double >>& tensors, const UnitCell& ucell, const std::string& filename);
954832
955833#endif // __EXX
956834
0 commit comments