|
5 | 5 | #include "source_estate/elecstate_tools.h" // use fixed_weights |
6 | 6 | #include "source_lcao/module_hcontainer/read_hcontainer.h" |
7 | 7 | #include "source_lcao/rho_tau_lcao.h" // use dm2rho |
| 8 | +#include "source_lcao/hamilt_lcao.h" // use HamiltLCAO for init_chg_hr |
| 9 | +#include "source_hsolver/hsolver_lcao.h" // use HSolverLCAO for init_chg_hr |
8 | 10 |
|
9 | 11 | template <typename TK> |
10 | 12 | void LCAO_domain::set_psi_occ_dm_chg( |
@@ -157,6 +159,57 @@ void LCAO_domain::init_hr_from_file( |
157 | 159 | return; |
158 | 160 | } |
159 | 161 |
|
| 162 | +template <typename TK, typename TR> |
| 163 | +void LCAO_domain::init_chg_hr( |
| 164 | + const std::string& readin_dir, |
| 165 | + const int nspin, |
| 166 | + hamilt::Hamilt<TK>* p_hamilt, |
| 167 | + const UnitCell& ucell, |
| 168 | + const Parallel_Orbitals* pv, |
| 169 | + psi::Psi<TK>& psi, |
| 170 | + elecstate::ElecState* pelec, |
| 171 | + elecstate::DensityMatrix<TK, double>& dm, |
| 172 | + Charge& chr, |
| 173 | + const std::string& ks_solver) |
| 174 | +{ |
| 175 | + ModuleBase::TITLE("LCAO_domain", "init_chg_hr"); |
| 176 | + |
| 177 | + auto* hamilt_lcao = dynamic_cast<hamilt::HamiltLCAO<TK, TR>*>(p_hamilt); |
| 178 | + if (!hamilt_lcao) |
| 179 | + { |
| 180 | + ModuleBase::WARNING_QUIT("LCAO_domain::init_chg_hr", "p_hamilt is not HamiltLCAO"); |
| 181 | + } |
| 182 | + |
| 183 | + // Step 1: Read HR from file(s) |
| 184 | + if (nspin == 2) |
| 185 | + { |
| 186 | + // nspin=2: load spin-up into first half of hRS2, spin-down into second half |
| 187 | + const std::string hrfile_up = readin_dir + "/hrs1_nao.csr"; |
| 188 | + LCAO_domain::init_hr_from_file<TR>(hrfile_up, hamilt_lcao->getHR(), ucell, pv); |
| 189 | + |
| 190 | + // switch hR data pointer to spin-down half, then read hrs2 |
| 191 | + auto& hRS2 = hamilt_lcao->getHRS2(); |
| 192 | + hamilt_lcao->getHR()->allocate(hRS2.data() + hRS2.size() / 2, 0); |
| 193 | + const std::string hrfile_down = readin_dir + "/hrs2_nao.csr"; |
| 194 | + LCAO_domain::init_hr_from_file<TR>(hrfile_down, hamilt_lcao->getHR(), ucell, pv); |
| 195 | + |
| 196 | + // restore hR to spin-up half |
| 197 | + hamilt_lcao->getHR()->allocate(hRS2.data(), 0); |
| 198 | + } |
| 199 | + else |
| 200 | + { |
| 201 | + const std::string hrfile = readin_dir + "/hrs1_nao.csr"; |
| 202 | + LCAO_domain::init_hr_from_file<TR>(hrfile, hamilt_lcao->getHR(), ucell, pv); |
| 203 | + } |
| 204 | + |
| 205 | + // Step 2: Mark HR as loaded from file (skip operator recalculation) |
| 206 | + p_hamilt->refresh(false); |
| 207 | + |
| 208 | + // Step 3: Diagonalize to get wavefunctions and charge density |
| 209 | + hsolver::HSolverLCAO<TK> hsolver_lcao_obj(pv, ks_solver); |
| 210 | + hsolver_lcao_obj.solve(p_hamilt, psi, pelec, dm, chr, nspin, 0); |
| 211 | +} |
| 212 | + |
160 | 213 |
|
161 | 214 |
|
162 | 215 | template void LCAO_domain::set_psi_occ_dm_chg<double>( |
@@ -247,3 +300,37 @@ template void LCAO_domain::init_hr_from_file<std::complex<double>>( |
247 | 300 | hamilt::HContainer<std::complex<double>>* hmat, |
248 | 301 | const UnitCell& ucell, |
249 | 302 | const Parallel_Orbitals* pv); |
| 303 | + |
| 304 | +template void LCAO_domain::init_chg_hr<double, double>( |
| 305 | + const std::string& readin_dir, |
| 306 | + const int nspin, |
| 307 | + hamilt::Hamilt<double>* p_hamilt, |
| 308 | + const UnitCell& ucell, |
| 309 | + const Parallel_Orbitals* pv, |
| 310 | + psi::Psi<double>& psi, |
| 311 | + elecstate::ElecState* pelec, |
| 312 | + elecstate::DensityMatrix<double, double>& dm, |
| 313 | + Charge& chr, |
| 314 | + const std::string& ks_solver); |
| 315 | +template void LCAO_domain::init_chg_hr<std::complex<double>, double>( |
| 316 | + const std::string& readin_dir, |
| 317 | + const int nspin, |
| 318 | + hamilt::Hamilt<std::complex<double>>* p_hamilt, |
| 319 | + const UnitCell& ucell, |
| 320 | + const Parallel_Orbitals* pv, |
| 321 | + psi::Psi<std::complex<double>>& psi, |
| 322 | + elecstate::ElecState* pelec, |
| 323 | + elecstate::DensityMatrix<std::complex<double>, double>& dm, |
| 324 | + Charge& chr, |
| 325 | + const std::string& ks_solver); |
| 326 | +template void LCAO_domain::init_chg_hr<std::complex<double>, std::complex<double>>( |
| 327 | + const std::string& readin_dir, |
| 328 | + const int nspin, |
| 329 | + hamilt::Hamilt<std::complex<double>>* p_hamilt, |
| 330 | + const UnitCell& ucell, |
| 331 | + const Parallel_Orbitals* pv, |
| 332 | + psi::Psi<std::complex<double>>& psi, |
| 333 | + elecstate::ElecState* pelec, |
| 334 | + elecstate::DensityMatrix<std::complex<double>, double>& dm, |
| 335 | + Charge& chr, |
| 336 | + const std::string& ks_solver); |
0 commit comments