Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix an assert in symmetry #2720

Merged
merged 2 commits into from
Jul 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions source/module_cell/module_symmetry/symmetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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(equal(check_zeros(i, j), 0));
assert(near_equal(check_zeros(i, j), 0));
#endif
return;
}
}