From f6f4ac3fb5330698754823c9518f670ba273696d Mon Sep 17 00:00:00 2001 From: maki49 <1579492865@qq.com> Date: Wed, 12 Jul 2023 11:26:20 +0800 Subject: [PATCH 1/2] fix a too-strict assert --- source/module_cell/module_symmetry/symmetry.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/module_cell/module_symmetry/symmetry.cpp b/source/module_cell/module_symmetry/symmetry.cpp index 73009e47fd1..daf881cdd06 100644 --- a/source/module_cell/module_symmetry/symmetry.cpp +++ b/source/module_cell/module_symmetry/symmetry.cpp @@ -2044,7 +2044,7 @@ void Symmetry::hermite_normal_form(const ModuleBase::Matrix3 &s3, ModuleBase::Ma ModuleBase::matrix check_zeros =s3.to_matrix() * b -h; for (int i=0;i<3;++i) for(int j=0;j<3;++j) - assert(equal(check_zeros(i, j), 0)); + assert(near_equal(check_zeros(i, j), 0)); return; } } From 68136c6df3afbdc88811fb96d1fae119f84d5dfa Mon Sep 17 00:00:00 2001 From: maki49 <1579492865@qq.com> Date: Wed, 19 Jul 2023 21:17:17 +0800 Subject: [PATCH 2/2] add #ifdef __DEBUG --- source/module_cell/module_symmetry/symmetry.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/source/module_cell/module_symmetry/symmetry.cpp b/source/module_cell/module_symmetry/symmetry.cpp index daf881cdd06..108e2966289 100644 --- a/source/module_cell/module_symmetry/symmetry.cpp +++ b/source/module_cell/module_symmetry/symmetry.cpp @@ -1943,14 +1943,18 @@ void Symmetry::hermite_normal_form(const ModuleBase::Matrix3 &s3, ModuleBase::Ma { ModuleBase::TITLE("Symmetry","hermite_normal_form"); // check the non-singularity and integer elements of s +#ifdef __DEBUG assert(!equal(s3.Det(), 0.0)); - auto near_equal = [this] (double x, double y) {return fabs(x-y) < 10*epsilon;}; +#endif + auto near_equal = [this](double x, double y) {return fabs(x - y) < 10 * epsilon;}; ModuleBase::matrix s = s3.to_matrix(); for (int i=0;i<3;++i) for (int j = 0;j < 3;++j) { double sij_round = std::round(s(i, j)); +#ifdef __DEBUG assert(near_equal(s(i, j), sij_round)); +#endif s(i, j) = sij_round; } @@ -2041,10 +2045,12 @@ void Symmetry::hermite_normal_form(const ModuleBase::Matrix3 &s3, ModuleBase::Ma b3.e31=b(2, 0); b3.e32=b(2, 1); b3.e33=b(2, 2); //check s*b=h - ModuleBase::matrix check_zeros =s3.to_matrix() * b -h; - for (int i=0;i<3;++i) + ModuleBase::matrix check_zeros = s3.to_matrix() * b - h; +#ifdef __DEBUG + for (int i = 0;i < 3;++i) for(int j=0;j<3;++j) assert(near_equal(check_zeros(i, j), 0)); +#endif return; } }