Skip to content

Commit ce7acd0

Browse files
authored
Fix:modify cheaktau type and add unittest (#5864)
* modify the type in lat0 * add unittest for checktau * modify the condition
1 parent 7ee1e7a commit ce7acd0

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

source/module_cell/read_stru.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
namespace unitcell
66
{
77
bool check_tau(const Atom* atoms,
8-
const int ntype,
9-
const int lat0)
8+
const int& ntype,
9+
const double& lat0)
1010
{
1111
ModuleBase::TITLE("UnitCell","check_tau");
1212
ModuleBase::timer::tick("UnitCell","check_tau");

source/module_cell/read_stru.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
namespace unitcell
77
{
88
bool check_tau(const Atom* atoms,
9-
const int ntype,
10-
const int lat0);
9+
const int& ntype,
10+
const double& lat0);
1111

1212
bool read_atom_species(std::ifstream& ifa,
1313
std::ofstream& ofs_running,

source/module_cell/test/unitcell_test.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ TEST_F(UcellTest, CheckDTau)
753753
}
754754
}
755755

756-
TEST_F(UcellTest, CheckTau)
756+
TEST_F(UcellTest, CheckTauFalse)
757757
{
758758
UcellTestPrepare utp = UcellTestLib["C1H2-CheckTau"];
759759
PARAM.input.relax_new = utp.relax_new;
@@ -769,6 +769,33 @@ TEST_F(UcellTest, CheckTau)
769769
remove("checktau_warning");
770770
}
771771

772+
TEST_F(UcellTest, CheckTauTrue)
773+
{
774+
UcellTestPrepare utp = UcellTestLib["C1H2-CheckTau"];
775+
PARAM.input.relax_new = utp.relax_new;
776+
ucell = utp.SetUcellInfo();
777+
GlobalV::ofs_warning.open("checktau_warning");
778+
int atom=0;
779+
//cause the ucell->lat0 is 0.5,if the type of the check_tau has
780+
//an int type,it will set to zero,and it will not pass the unittest
781+
ucell->lat0=0.5;
782+
ucell->nat=3;
783+
for (int it=0;it<ucell->ntype;it++)
784+
{
785+
for(int ia=0; ia<ucell->atoms[it].na; ++ia)
786+
{
787+
788+
for (int i=0;i<3;i++)
789+
{
790+
ucell->atoms[it].tau[ia][i]=((atom+i)/(ucell->nat*3.0));
791+
}
792+
atom+=3;
793+
}
794+
}
795+
EXPECT_EQ(unitcell::check_tau(ucell->atoms ,ucell->ntype, ucell->lat0),true);
796+
GlobalV::ofs_warning.close();
797+
}
798+
772799
TEST_F(UcellTest, SelectiveDynamics)
773800
{
774801
UcellTestPrepare utp = UcellTestLib["C1H2-SD"];

0 commit comments

Comments
 (0)