From 89ffb98a45a77d559928ca08ebcad59dbef83cf2 Mon Sep 17 00:00:00 2001 From: liutao <3158793232@qq.com> Date: Thu, 16 Jan 2025 05:34:20 +0000 Subject: [PATCH 1/3] modify the type in lat0 --- source/module_cell/read_stru.cpp | 4 ++-- source/module_cell/read_stru.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source/module_cell/read_stru.cpp b/source/module_cell/read_stru.cpp index 51af080611..a312cba744 100644 --- a/source/module_cell/read_stru.cpp +++ b/source/module_cell/read_stru.cpp @@ -5,8 +5,8 @@ namespace unitcell { bool check_tau(const Atom* atoms, - const int ntype, - const int lat0) + const int& ntype, + const double& lat0) { ModuleBase::TITLE("UnitCell","check_tau"); ModuleBase::timer::tick("UnitCell","check_tau"); diff --git a/source/module_cell/read_stru.h b/source/module_cell/read_stru.h index 3827666966..cff2a0c331 100644 --- a/source/module_cell/read_stru.h +++ b/source/module_cell/read_stru.h @@ -6,8 +6,8 @@ namespace unitcell { bool check_tau(const Atom* atoms, - const int ntype, - const int lat0); + const int& ntype, + const double& lat0); bool read_atom_species(std::ifstream& ifa, std::ofstream& ofs_running, From 2f3540bccf13a7c4d2d3a4cc860b470f6838b5cb Mon Sep 17 00:00:00 2001 From: liutao <3158793232@qq.com> Date: Thu, 16 Jan 2025 06:14:44 +0000 Subject: [PATCH 2/3] add unittest for checktau --- source/module_cell/test/unitcell_test.cpp | 27 ++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/source/module_cell/test/unitcell_test.cpp b/source/module_cell/test/unitcell_test.cpp index 2a783630dc..0a41a04047 100644 --- a/source/module_cell/test/unitcell_test.cpp +++ b/source/module_cell/test/unitcell_test.cpp @@ -753,7 +753,7 @@ TEST_F(UcellTest, CheckDTau) } } -TEST_F(UcellTest, CheckTau) +TEST_F(UcellTest, CheckTauFalse) { UcellTestPrepare utp = UcellTestLib["C1H2-CheckTau"]; PARAM.input.relax_new = utp.relax_new; @@ -769,6 +769,31 @@ TEST_F(UcellTest, CheckTau) remove("checktau_warning"); } +TEST_F(UcellTest, CheckTauTrue) +{ + UcellTestPrepare utp = UcellTestLib["C1H2-CheckTau"]; + PARAM.input.relax_new = utp.relax_new; + ucell = utp.SetUcellInfo(); + GlobalV::ofs_warning.open("checktau_warning"); + int atom=0; + ucell->nat=3; + for (int it=0;itntype;it++) + { + for(int ia=0; iaatoms[it].na; ++ia) + { + + for (int i=0;i<3;i++) + { + ucell->atoms[it].tau[ia][i]=((atom+i)/(ucell->nat*3.0)); + std::cout<<"the tau is "<atoms[it].tau[ia][i]; + } + atom+=3; + } + } + EXPECT_EQ(unitcell::check_tau(ucell->atoms ,ucell->ntype, ucell->lat0),true); + GlobalV::ofs_warning.close(); +} + TEST_F(UcellTest, SelectiveDynamics) { UcellTestPrepare utp = UcellTestLib["C1H2-SD"]; From e1687159481e3d22cac43464d5d04135ebe7fc5b Mon Sep 17 00:00:00 2001 From: liutao <3158793232@qq.com> Date: Thu, 16 Jan 2025 06:36:17 +0000 Subject: [PATCH 3/3] modify the condition --- source/module_cell/test/unitcell_test.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/module_cell/test/unitcell_test.cpp b/source/module_cell/test/unitcell_test.cpp index 0a41a04047..3e93a7b44f 100644 --- a/source/module_cell/test/unitcell_test.cpp +++ b/source/module_cell/test/unitcell_test.cpp @@ -776,6 +776,9 @@ TEST_F(UcellTest, CheckTauTrue) ucell = utp.SetUcellInfo(); GlobalV::ofs_warning.open("checktau_warning"); int atom=0; + //cause the ucell->lat0 is 0.5,if the type of the check_tau has + //an int type,it will set to zero,and it will not pass the unittest + ucell->lat0=0.5; ucell->nat=3; for (int it=0;itntype;it++) { @@ -785,7 +788,6 @@ TEST_F(UcellTest, CheckTauTrue) for (int i=0;i<3;i++) { ucell->atoms[it].tau[ia][i]=((atom+i)/(ucell->nat*3.0)); - std::cout<<"the tau is "<atoms[it].tau[ia][i]; } atom+=3; }