@@ -89,106 +89,111 @@ bool WfHistoryLCAO<TK>::latest_snapshot(WfSnapshotLCAO<TK>& snapshot) const
8989}
9090
9191template <typename TK >
92- WfExtrapApplyResult WfHistoryLCAO<TK >::try_use_prev_wf_gamma(const double * current_overlap ,
93- const Parallel_Orbitals& pv ,
94- psi::Psi<double >& psi ,
95- const ModuleBase::matrix& wg_now ,
96- const double pivot_threshold ,
97- const double check_tolerance )
92+ WfExtrapApplyResult WfHistoryLCAO<TK >::try_use_prev_wf_gamma(const TK * ,
93+ const Parallel_Orbitals&,
94+ psi::Psi<TK >& ,
95+ const ModuleBase::matrix&,
96+ const double ,
97+ const double )
9898{
9999 WfExtrapApplyResult result;
100+ result.status = WfcExtrapStatus::Unsupported;
101+ return result;
102+ }
103+
104+ template <>
105+ WfExtrapApplyResult WfHistoryLCAO<double >::try_use_prev_wf_gamma(const double * current_overlap,
106+ const Parallel_Orbitals& pv,
107+ psi::Psi<double >& psi,
108+ const ModuleBase::matrix& wg_now,
109+ const double pivot_threshold,
110+ const double check_tolerance)
111+ {
112+ WfExtrapApplyResult result;
113+
114+ if (this ->method_ != WfcExtrapMethod::UsePrevWf)
115+ {
116+ result.status = WfcExtrapStatus::Disabled;
117+ return result;
118+ }
119+
120+ if (this ->snapshots_ .empty ())
121+ {
122+ result.status = WfcExtrapStatus::EmptyHistory;
123+ return result;
124+ }
125+
126+ if (current_overlap == nullptr || !(pivot_threshold >= 0.0 ) || !(check_tolerance > 0.0 ))
127+ {
128+ result.status = WfcExtrapStatus::InvalidInput;
129+ return result;
130+ }
100131
101- if constexpr (!std::is_same<TK , double >::value)
132+ // The first PR only supports the real Gamma-only path. In this path the
133+ // first Psi dimension may label spin channels, but not physical k-points.
134+ if (!psi.get_k_first ())
102135 {
103136 result.status = WfcExtrapStatus::Unsupported;
104137 return result;
105138 }
106- else
139+
140+ const WfSnapshotLCAO<double >& snapshot = this ->snapshots_ .back ();
141+ result.snapshot_istep = snapshot.istep ;
142+
143+ if (!snapshot.compatible_with (psi, wg_now))
144+ {
145+ result.status = WfcExtrapStatus::DimensionMismatch;
146+ return result;
147+ }
148+
149+ // Work on an owned trial Psi first. The caller's Psi is not overwritten
150+ // unless the stored WFN can be loaded and reorthonormalized successfully.
151+ psi::Psi<double > psi_trial (psi);
152+ ModuleBase::timer::start (" WFN_Extrap" , " restore_snapshot" );
153+ const bool snapshot_loaded = snapshot.load_to (psi_trial);
154+ ModuleBase::timer::end (" WFN_Extrap" , " restore_snapshot" );
155+ if (!snapshot_loaded)
107156 {
108- if (this ->method_ != WfcExtrapMethod::UsePrevWf)
109- {
110- result.status = WfcExtrapStatus::Disabled;
111- return result;
112- }
113-
114- if (this ->snapshots_ .empty ())
115- {
116- result.status = WfcExtrapStatus::EmptyHistory;
117- return result;
118- }
119-
120- if (current_overlap == nullptr || !(pivot_threshold >= 0.0 ) || !(check_tolerance > 0.0 ))
121- {
122- result.status = WfcExtrapStatus::InvalidInput;
123- return result;
124- }
125-
126- // The first PR only supports the real Gamma-only path. In this path the
127- // first Psi dimension may label spin channels, but not physical k-points.
128- if (!psi.get_k_first ())
129- {
130- result.status = WfcExtrapStatus::Unsupported;
131- return result;
132- }
133-
134- const WfSnapshotLCAO<TK >& snapshot = this ->snapshots_ .back ();
135- result.snapshot_istep = snapshot.istep ;
136-
137- if (!snapshot.compatible_with (psi, wg_now))
138- {
139- result.status = WfcExtrapStatus::DimensionMismatch;
140- return result;
141- }
142-
143- // Work on an owned trial Psi first. The caller's Psi is not overwritten
144- // unless the stored WFN can be loaded and reorthonormalized successfully.
145- psi::Psi<double > psi_trial (psi);
146- ModuleBase::timer::start (" WFN_Extrap" , " restore_snapshot" );
147- const bool snapshot_loaded = snapshot.load_to (psi_trial);
148- ModuleBase::timer::end (" WFN_Extrap" , " restore_snapshot" );
149- if (!snapshot_loaded)
150- {
151- result.status = WfcExtrapStatus::DimensionMismatch;
152- return result;
153- }
154-
155- ModuleBase::timer::start (" WFN_Extrap" , " orthonormalize" );
156- const WfOrthonormalizeResult orth_result = reorthonormalize_gamma_lcao (current_overlap,
157- pv,
158- psi_trial,
159- snapshot.wg ,
160- 1.0e-12 ,
161- pivot_threshold,
162- check_tolerance);
163- ModuleBase::timer::end (" WFN_Extrap" , " orthonormalize" );
164- if (!orth_result.ok ())
165- {
166- result.status = orth_result.status ;
167- result.failed_state = orth_result.failed_state ;
168- result.failed_pivot_index = orth_result.failed_pivot_index ;
169- result.failed_pivot = orth_result.failed_pivot ;
170- result.min_metric_diag = orth_result.min_metric_diag ;
171- result.max_metric_diag = orth_result.max_metric_diag ;
172- result.max_metric_abs = orth_result.max_metric_abs ;
173- result.max_metric_asymmetry = orth_result.max_metric_asymmetry ;
174- result.nstate = orth_result.nstate ;
175- result.nbands = orth_result.nbands ;
176- result.nbasis = orth_result.nbasis ;
177- result.nactive_bands = orth_result.nactive_bands ;
178- result.max_orthonormality_deviation = orth_result.max_deviation ;
179- return result;
180- }
181-
182- psi = psi_trial;
183- result.status = WfcExtrapStatus::Success;
184- result.failed_state = -1 ;
157+ result.status = WfcExtrapStatus::DimensionMismatch;
158+ return result;
159+ }
160+
161+ ModuleBase::timer::start (" WFN_Extrap" , " orthonormalize" );
162+ const WfOrthonormalizeResult orth_result = reorthonormalize_gamma_lcao (current_overlap,
163+ pv,
164+ psi_trial,
165+ snapshot.wg ,
166+ 1.0e-12 ,
167+ pivot_threshold,
168+ check_tolerance);
169+ ModuleBase::timer::end (" WFN_Extrap" , " orthonormalize" );
170+ if (!orth_result.ok ())
171+ {
172+ result.status = orth_result.status ;
173+ result.failed_state = orth_result.failed_state ;
174+ result.failed_pivot_index = orth_result.failed_pivot_index ;
175+ result.failed_pivot = orth_result.failed_pivot ;
176+ result.min_metric_diag = orth_result.min_metric_diag ;
177+ result.max_metric_diag = orth_result.max_metric_diag ;
178+ result.max_metric_abs = orth_result.max_metric_abs ;
179+ result.max_metric_asymmetry = orth_result.max_metric_asymmetry ;
185180 result.nstate = orth_result.nstate ;
186181 result.nbands = orth_result.nbands ;
187182 result.nbasis = orth_result.nbasis ;
188183 result.nactive_bands = orth_result.nactive_bands ;
189184 result.max_orthonormality_deviation = orth_result.max_deviation ;
190185 return result;
191186 }
187+
188+ psi = psi_trial;
189+ result.status = WfcExtrapStatus::Success;
190+ result.failed_state = -1 ;
191+ result.nstate = orth_result.nstate ;
192+ result.nbands = orth_result.nbands ;
193+ result.nbasis = orth_result.nbasis ;
194+ result.nactive_bands = orth_result.nactive_bands ;
195+ result.max_orthonormality_deviation = orth_result.max_deviation ;
196+ return result;
192197}
193198
194199template <typename TK >
0 commit comments