Skip to content

Commit bbe4500

Browse files
author
zxy.monado
committed
fix(kpoints): reject zero line interpolation counts
1 parent f29968d commit bbe4500

3 files changed

Lines changed: 30 additions & 2 deletions

File tree

source/source_cell/klist.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,15 +463,23 @@ void K_Vectors::interpolate_k_between(std::ifstream& ifk, std::vector<ModuleBase
463463
ifk >> ks[iks].z;
464464
ModuleBase::GlobalFunc::READ_VALUE(ifk, nkl[iks]);
465465

466-
assert(nkl[iks] >= 0);
466+
if (nkl[iks] <= 0)
467+
{
468+
ModuleBase::WARNING_QUIT("K_Vectors::interpolate_k_between",
469+
"Line-mode interpolation counts must be positive.");
470+
}
467471
nkstot += nkl[iks];
468472
/* ISSUE#3482: to distinguish different kline segments */
469473
if ((nkl[iks] == 1) && (iks != (nks_special - 1))) {
470474
kpt_segid++;
471475
}
472476
kpt_segids.push_back(kpt_segid);
473477
}
474-
assert(nkl[nks_special - 1] == 1);
478+
if (nkl[nks_special - 1] != 1)
479+
{
480+
ModuleBase::WARNING_QUIT("K_Vectors::interpolate_k_between",
481+
"The final line-mode k-point must have an interpolation count of 1.");
482+
}
475483

476484
// std::cout << " nkstot = " << nkstot << std::endl;
477485
this->renew(nkstot * nspin); // mohan fix bug 2009-09-01

source/source_cell/test/klist_test.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,21 @@ TEST_F(KlistTest, ReadKpointsLine)
395395
EXPECT_EQ(kv->get_nkstot(), 122);
396396
}
397397

398+
TEST_F(KlistTest, ReadKpointsLineRejectsZeroInterpolationCount)
399+
{
400+
ModuleSymmetry::Symmetry::symm_flag = 0;
401+
const bool gamma_only_local = false;
402+
const double kspacing[3] = {0.0, 0.0, 0.0};
403+
const std::string kmesh_type = "gamma";
404+
const double koffset[3] = {0.0, 0.0, 0.0};
405+
const std::string k_file = "./support/KPT_ZERO_LINE_COUNT";
406+
kv->nspin = 1;
407+
408+
EXPECT_EXIT(kv->read_kpoints(ucell, k_file, gamma_only_local, kspacing, kmesh_type, koffset),
409+
::testing::ExitedWithCode(1),
410+
"");
411+
}
412+
398413
TEST_F(KlistTest, ReadKpointsCartesian)
399414
{
400415
const bool gamma_only_local = false;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
K_POINTS
2+
2
3+
Line
4+
0.0 0.0 0.0 0
5+
0.5 0.0 0.0 1

0 commit comments

Comments
 (0)