@@ -14,6 +14,9 @@ namespace
1414constexpr int nstate = 1 ;
1515constexpr int nbands = 3 ;
1616constexpr int nbasis = 3 ;
17+ constexpr double occupation_threshold = 1.0e-12 ;
18+ constexpr double pivot_threshold = 1.0e-14 ;
19+ constexpr double check_tolerance = 1.0e-8 ;
1720
1821void initialize_serial_orbitals (Parallel_Orbitals& pv)
1922{
@@ -72,6 +75,14 @@ const std::vector<double> coeff = {
7275 7.0 , 8.0 , 9.0 ,
7376};
7477
78+ ModuleExtrap::WfOrthonormalizeResult reorthonormalize (const Parallel_Orbitals& pv,
79+ psi::Psi<double >& wfc,
80+ const ModuleBase::matrix& occupations)
81+ {
82+ return ModuleExtrap::reorthonormalize_gamma_lcao (overlap.data (), pv, wfc, occupations,
83+ occupation_threshold, pivot_threshold, check_tolerance);
84+ }
85+
7586} // namespace
7687
7788TEST (WfSnapshotLCAO, OwnsAndRestoresData)
@@ -102,8 +113,7 @@ TEST(WfOrthonormalizeLCAO, ReorthonormalizesOccupiedSubspace)
102113 psi::Psi<double > wfc = make_psi (coeff);
103114 const ModuleBase::matrix occupations = make_occupations ();
104115
105- const ModuleExtrap::WfOrthonormalizeResult result
106- = ModuleExtrap::reorthonormalize_gamma_lcao (overlap.data (), pv, wfc, occupations);
116+ const ModuleExtrap::WfOrthonormalizeResult result = reorthonormalize (pv, wfc, occupations);
107117
108118 ASSERT_TRUE (result.ok ());
109119 EXPECT_EQ (result.nstate , nstate);
@@ -133,8 +143,7 @@ TEST(WfOrthonormalizeLCAO, DoesNotModifyPsiOnFailure)
133143 psi::Psi<double > wfc = make_psi (rank_deficient_coeff);
134144 const ModuleBase::matrix occupations = make_occupations ();
135145
136- const ModuleExtrap::WfOrthonormalizeResult result
137- = ModuleExtrap::reorthonormalize_gamma_lcao (overlap.data (), pv, wfc, occupations);
146+ const ModuleExtrap::WfOrthonormalizeResult result = reorthonormalize (pv, wfc, occupations);
138147
139148 EXPECT_EQ (result.status , ModuleExtrap::WfcExtrapStatus::OrthogonalizationFailed);
140149 for (std::size_t i = 0 ; i < rank_deficient_coeff.size (); ++i)
@@ -143,12 +152,45 @@ TEST(WfOrthonormalizeLCAO, DoesNotModifyPsiOnFailure)
143152 }
144153}
145154
155+ TEST (WfOrthonormalizeLCAO, HandlesBandDistributedCoefficients)
156+ {
157+ Parallel_Orbitals pv;
158+ initialize_serial_orbitals (pv);
159+ pv.ncol_bands = 2 ;
160+ pv.nbands = 2 ;
161+ #ifdef __MPI
162+ pv.desc_wfc [3 ] = 2 ;
163+ #endif
164+ psi::Psi<double > wfc (nstate, 2 , nbasis, nbasis, true );
165+ wfc.set_all_psi (coeff.data (), 2 * nbasis);
166+
167+ const ModuleExtrap::WfOrthonormalizeResult result = reorthonormalize (pv, wfc, make_occupations ());
168+ EXPECT_TRUE (result.ok ());
169+ }
170+
171+ TEST (WfHistoryLCAO, ReportsMissingHistory)
172+ {
173+ Parallel_Orbitals pv;
174+ initialize_serial_orbitals (pv);
175+ ModuleExtrap::WfHistoryLCAO<double > history;
176+ psi::Psi<double > predicted = make_psi (coeff);
177+
178+ const ModuleExtrap::WfExtrapApplyResult result
179+ = history.try_use_prev_wf_gamma (overlap.data (),
180+ pv,
181+ predicted,
182+ make_occupations (),
183+ pivot_threshold,
184+ check_tolerance);
185+ EXPECT_EQ (result.status , ModuleExtrap::WfcExtrapStatus::EmptyHistory);
186+ }
187+
146188TEST (WfHistoryLCAO, UsesLatestOwnedSnapshot)
147189{
148190 Parallel_Orbitals pv;
149191 initialize_serial_orbitals (pv);
150192 const ModuleBase::matrix occupations = make_occupations ();
151- ModuleExtrap::WfHistoryLCAO<double > history (ModuleExtrap::WfcExtrapMethod::UsePrevWf, 2 ) ;
193+ ModuleExtrap::WfHistoryLCAO<double > history;
152194
153195 psi::Psi<double > first = make_psi (coeff);
154196 history.update_after_scf (3 , first, occupations);
@@ -164,15 +206,16 @@ TEST(WfHistoryLCAO, UsesLatestOwnedSnapshot)
164206
165207 psi::Psi<double > predicted (nstate, nbands, nbasis, nbasis, true );
166208 const ModuleExtrap::WfExtrapApplyResult result
167- = history.try_use_prev_wf_gamma (overlap.data (), pv, predicted, occupations);
209+ = history.try_use_prev_wf_gamma (overlap.data (),
210+ pv,
211+ predicted,
212+ occupations,
213+ pivot_threshold,
214+ check_tolerance);
168215
169216 ASSERT_TRUE (result.ok ());
170217 EXPECT_EQ (result.snapshot_istep , 4 );
171- EXPECT_EQ (history.size (), 2U );
172218 EXPECT_NEAR (metric_element (predicted, overlap, 0 , 0 ), 1.0 , 1.0e-10 );
173219 EXPECT_NEAR (metric_element (predicted, overlap, 1 , 1 ), 1.0 , 1.0e-10 );
174220 EXPECT_NEAR (metric_element (predicted, overlap, 0 , 1 ), 0.0 , 1.0e-10 );
175-
176- history.set_max_depth (1 );
177- EXPECT_EQ (history.size (), 1U );
178221}
0 commit comments