|
19 | 19 | #endif |
20 | 20 | #include "source_lcao/module_rdmft/rdmft.h" |
21 | 21 | #include "source_lcao/module_extrap/wf_history_lcao.h" |
22 | | -#include "source_lcao/module_operator_lcao/operator_lcao.h" // build overlap SR before WFN reorthonormalization |
23 | 22 | #include "source_estate/module_charge/chgmixing.h" // use charge mixing, mohan add 20251006 |
24 | 23 | #include "source_estate/module_dm/init_dm.h" // init dm from electronic wave functions |
25 | | -#include "source_estate/module_dm/cal_dm_psi.h" // rebuild DMK from extrapolated WFN |
26 | 24 | #include "source_io/module_ctrl/ctrl_runner_lcao.h" // use ctrl_runner_lcao() |
27 | 25 | #include "source_io/module_ctrl/ctrl_iter_lcao.h" // use ctrl_iter_lcao() |
28 | 26 | #include "source_io/module_ctrl/ctrl_scf_lcao.h" // use ctrl_scf_lcao() |
|
31 | 29 | #include "source_lcao/LCAO_set.h" // mohan add 20251111 |
32 | 30 | #include "source_psi/setup_psi.h" // use Setup_Psi for deallocate_psi |
33 | 31 |
|
34 | | -#include <iomanip> |
35 | | -#include <sstream> |
36 | | -#include <string> |
37 | | -#include <type_traits> |
38 | 32 |
|
39 | 33 | namespace ModuleESolver |
40 | 34 | { |
@@ -215,86 +209,17 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(UnitCell& ucell, const int istep) |
215 | 209 | } |
216 | 210 | else if(PARAM.inp.esolver_type!="tddft")//initialize DMR from WFN history if required |
217 | 211 | { |
218 | | - if (std::is_same<TK, double>::value) |
| 212 | + if (this->wf_history_lcao_ != nullptr) |
219 | 213 | { |
220 | | - if (this->wf_history_lcao_ != nullptr) |
221 | | - { |
222 | | - // The newly-created HamiltLCAO has allocated S(R), but the actual |
223 | | - // overlap values are normally filled later by updateHk() inside the |
224 | | - // eigensolver. WFN extrapolation needs S before entering SCF, so build |
225 | | - // only the overlap real-space matrix here and then fold it to S(Gamma). |
226 | | - auto* lcao_op = dynamic_cast<hamilt::OperatorLCAO<TK, TR>*>(hamilt_lcao->getOperator()); |
227 | | - if (lcao_op == nullptr) |
228 | | - { |
229 | | - ModuleBase::WARNING_QUIT("ESolver_KS_LCAO::before_scf", |
230 | | - "Failed to access the LCAO operator chain for WFN extrapolation."); |
231 | | - } |
232 | | - ModuleBase::timer::start("WFN_Extrap", "prepare_overlap"); |
233 | | - lcao_op->contributeHR(); |
234 | | - // Refresh the current Gamma-only overlap matrix before reusing the previous WFN. |
235 | | - // The layout must follow the active LCAO solver because the WFN orthonormalizer |
236 | | - // assembles distributed local blocks using the same column/row-major convention. |
237 | | - const int sk_layout = |
238 | | - ModuleBase::GlobalFunc::IS_COLUMN_MAJOR_KS_SOLVER(PARAM.inp.ks_solver) ? 1 : 0; |
239 | | - hamilt_lcao->updateSk(0, sk_layout); |
240 | | - ModuleBase::timer::end("WFN_Extrap", "prepare_overlap"); |
241 | | - |
242 | | - ModuleBase::timer::start("WFN_Extrap", "apply"); |
243 | | - const ModuleExtrap::WfExtrapApplyResult wfc_result |
244 | | - = this->wf_history_lcao_->try_use_prev_wf_gamma(hamilt_lcao->getSk(), |
245 | | - this->pv, |
246 | | - *(this->psi), |
247 | | - this->pelec->wg); |
248 | | - ModuleBase::timer::end("WFN_Extrap", "apply"); |
249 | | - if (wfc_result.ok()) |
250 | | - { |
251 | | - ModuleBase::timer::start("WFN_Extrap", "rebuild_density"); |
252 | | - elecstate::cal_dm_psi(this->dmat.dm->get_paraV_pointer(), |
253 | | - this->pelec->wg, |
254 | | - *(this->psi), |
255 | | - *(this->dmat.dm)); |
256 | | - this->dmat.dm->cal_DMR(); |
257 | | - LCAO_domain::dm2rho(this->dmat.dm->get_DMR_vector(), PARAM.inp.nspin, &this->chr); |
258 | | - ModuleBase::timer::end("WFN_Extrap", "rebuild_density"); |
259 | | - initialized_by_wfc_extrap = true; |
260 | | - |
261 | | - GlobalV::ofs_running << " WFN extrapolation: use_prev_wf from ionic step " |
262 | | - << wfc_result.snapshot_istep |
263 | | - << ", active bands = " << wfc_result.nactive_bands |
264 | | - << ", max |C^T S C - I| = " |
265 | | - << wfc_result.max_orthonormality_deviation << std::endl; |
266 | | - } |
267 | | - else |
268 | | - { |
269 | | - std::ostringstream oss; |
270 | | - oss << std::scientific << std::setprecision(16); |
271 | | - oss << "WFN extrapolation failed with status: " |
272 | | - << ModuleExtrap::to_string(wfc_result.status) << "\n\n" |
273 | | - << " snapshot_istep=" << wfc_result.snapshot_istep << "\n" |
274 | | - << " failed_state=" << wfc_result.failed_state << "\n" |
275 | | - << " failed_pivot_index=" << wfc_result.failed_pivot_index << "\n" |
276 | | - << " failed_pivot=" << wfc_result.failed_pivot << "\n" |
277 | | - << " nstate=" << wfc_result.nstate << "\n" |
278 | | - << " nbands=" << wfc_result.nbands << "\n" |
279 | | - << " nbasis=" << wfc_result.nbasis << "\n" |
280 | | - << " min_metric_diag=" << wfc_result.min_metric_diag << "\n" |
281 | | - << " max_metric_diag=" << wfc_result.max_metric_diag << "\n" |
282 | | - << " max_metric_abs=" << wfc_result.max_metric_abs << "\n" |
283 | | - << " max_metric_asymmetry=" << wfc_result.max_metric_asymmetry << "\n" |
284 | | - << " max_orthonormality_deviation=" |
285 | | - << wfc_result.max_orthonormality_deviation << "\n"; |
286 | | - const std::string message = oss.str(); |
287 | | - ModuleBase::WARNING_QUIT("ESolver_KS_LCAO::before_scf", message); |
288 | | - } |
289 | | - } |
290 | | - } |
291 | | - else |
292 | | - { |
293 | | - if (this->wf_history_lcao_ != nullptr) |
294 | | - { |
295 | | - ModuleBase::WARNING_QUIT("ESolver_KS_LCAO::before_scf", |
296 | | - "WFN extrapolation is currently supported only for the real Gamma-only NAO path."); |
297 | | - } |
| 214 | + initialized_by_wfc_extrap = this->wf_history_lcao_->initialize_gamma_density( |
| 215 | + *hamilt_lcao, |
| 216 | + this->pv, |
| 217 | + *(this->psi), |
| 218 | + this->pelec->wg, |
| 219 | + *(this->dmat.dm), |
| 220 | + this->chr, |
| 221 | + PARAM.inp.nspin, |
| 222 | + PARAM.inp.ks_solver); |
298 | 223 | } |
299 | 224 |
|
300 | 225 | if (!initialized_by_wfc_extrap) |
|
0 commit comments