@@ -139,4 +139,66 @@ TEST_F(PWTEST,test_other)
139139#ifdef __ENABLE_FLOAT_FFTW
140140 fftwf_cleanup ();
141141#endif
142+ }
143+
144+ TEST_F (PWTEST , test_no_plane_wave_message_global_empty_k)
145+ {
146+ ModulePW::PW_Basis_K pwktest (device_flag, precision_flag);
147+ ModuleBase::Matrix3 latvec (0.2 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 1 );
148+ #ifdef __MPI
149+ pwktest.initmpi (nproc_in_pool, rank_in_pool, POOL_WORLD );
150+ #endif
151+ const int nks = 1 ;
152+ ModuleBase::Vector3<double > kvec_d[nks];
153+ kvec_d[0 ].set (0.5 , 0.5 , 0.5 );
154+
155+ pwktest.initgrids (2 , latvec, 4 , 4 , 4 );
156+ pwktest.initparameters (true , 1e-4 , nks, kvec_d);
157+ testing::internal::CaptureStdout ();
158+ pwktest.setuptransform ();
159+ std::string output = testing::internal::GetCapturedStdout ();
160+
161+ EXPECT_THAT (output,
162+ testing::HasSubstr (" No plane waves are available for this k-point across the whole pool. Please increase ecutwfc or check KPT settings." ));
163+ }
164+
165+ TEST_F (PWTEST , test_no_plane_wave_message_parallel_local_empty)
166+ {
167+ #ifndef __MPI
168+ GTEST_SKIP () << " Requires MPI ranks to simulate local-empty but global-nonempty case." ;
169+ #else
170+ if (nproc_in_pool <= 1 )
171+ {
172+ GTEST_SKIP () << " Requires more than one MPI rank." ;
173+ }
174+
175+ ModulePW::PW_Basis_K pwktest (device_flag, precision_flag);
176+ ModuleBase::Matrix3 latvec (0.2 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 1 );
177+ pwktest.initmpi (nproc_in_pool, rank_in_pool, POOL_WORLD );
178+
179+ const int nks = 1 ;
180+ ModuleBase::Vector3<double > kvec_d[nks];
181+ kvec_d[0 ].set (0.0 , 0.0 , 0.0 );
182+
183+ pwktest.initgrids (2 , latvec, 4 , 4 , 4 );
184+ pwktest.initparameters (true , 8.0 , nks, kvec_d);
185+ testing::internal::CaptureStdout ();
186+ pwktest.setuptransform ();
187+ std::string output = testing::internal::GetCapturedStdout ();
188+
189+ const int local_npwk = pwktest.npwk [0 ];
190+ int global_npwk = local_npwk;
191+ MPI_Allreduce (MPI_IN_PLACE , &global_npwk, 1 , MPI_INT , MPI_SUM , POOL_WORLD );
192+
193+ const int local_target_rank = (local_npwk == 0 && global_npwk > 0 ) ? 1 : 0 ;
194+ int any_target_rank = local_target_rank;
195+ MPI_Allreduce (MPI_IN_PLACE , &any_target_rank, 1 , MPI_INT , MPI_MAX , POOL_WORLD );
196+ EXPECT_EQ (any_target_rank, 1 );
197+
198+ if (local_target_rank == 1 )
199+ {
200+ EXPECT_THAT (output,
201+ testing::HasSubstr (" Current core has no plane waves! Please reduce the cores." ));
202+ }
203+ #endif
142204}
0 commit comments