From 7100d4b51d2f311859b8ab747ab7d5ba931b4c3b Mon Sep 17 00:00:00 2001 From: Levi Zhou <31941107+ZhouXY-PKU@users.noreply.github.com> Date: Sun, 12 Oct 2025 14:16:57 +0800 Subject: [PATCH] Update update_cell.cpp to avoid numerical precision error issues. --- source/source_cell/update_cell.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/source/source_cell/update_cell.cpp b/source/source_cell/update_cell.cpp index 3768386e0c..187f962fd0 100644 --- a/source/source_cell/update_cell.cpp +++ b/source/source_cell/update_cell.cpp @@ -496,12 +496,13 @@ void periodic_boundary_adjustment(Atom* atoms, atom->taud[ia][ik] -= 1.0; } } - if (atom->taud[ia].x < 0 - || atom->taud[ia].y < 0 - || atom->taud[ia].z < 0 - || atom->taud[ia].x >= 1.0 - || atom->taud[ia].y >= 1.0 - || atom->taud[ia].z >= 1.0) + const double eps = 1e-12; + if (atom->taud[ia].x < -eps + || atom->taud[ia].y < -eps + || atom->taud[ia].z < -eps + || atom->taud[ia].x >= 1.0+eps + || atom->taud[ia].y >= 1.0+eps + || atom->taud[ia].z >= 1.0+eps) { GlobalV::ofs_warning << " atom type=" << it + 1 << " atom index=" << ia + 1 << std::endl; GlobalV::ofs_warning << " direct coordinate=" << atom->taud[ia].x << " "