From b365e549ab874ecf116373a461cd5a5f474d372a Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Tue, 27 Sep 2022 19:55:00 -0400 Subject: [PATCH 1/2] supports left hands volume Fixes #972. See also https://math.stackexchange.com/q/829835 --- source/lib/include/SimulationRegion_Impl.h | 6 ++---- source/lib/src/region.cc | 4 +--- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/source/lib/include/SimulationRegion_Impl.h b/source/lib/include/SimulationRegion_Impl.h index 528402b7d6..d9c19d1077 100644 --- a/source/lib/include/SimulationRegion_Impl.h +++ b/source/lib/include/SimulationRegion_Impl.h @@ -501,10 +501,8 @@ computeVolume() boxt[0*3+0] * (boxt[1*3+1]*boxt[2*3+2] - boxt[2*3+1]*boxt[1*3+2]) - boxt[0*3+1] * (boxt[1*3+0]*boxt[2*3+2] - boxt[2*3+0]*boxt[1*3+2]) + boxt[0*3+2] * (boxt[1*3+0]*boxt[2*3+1] - boxt[2*3+0]*boxt[1*3+1]); - volumei = static_cast(1.)/volume; - if (volume < 0) { - throw deepmd::deepmd_exception("Negative volume detected. Please make sure the simulation cell obeys the right-hand rule."); - } + volume = std::abs(volume); + volumei = static_cast(1.)/volume; } template diff --git a/source/lib/src/region.cc b/source/lib/src/region.cc index d8333e4929..c3411578a5 100644 --- a/source/lib/src/region.cc +++ b/source/lib/src/region.cc @@ -33,9 +33,7 @@ compute_volume(const FPTYPE * boxt) boxt[0*3+0] * (boxt[1*3+1]*boxt[2*3+2] - boxt[2*3+1]*boxt[1*3+2]) - boxt[0*3+1] * (boxt[1*3+0]*boxt[2*3+2] - boxt[2*3+0]*boxt[1*3+2]) + boxt[0*3+2] * (boxt[1*3+0]*boxt[2*3+1] - boxt[2*3+0]*boxt[1*3+1]); - if (volume < 0) { - throw deepmd::deepmd_exception("Negative volume detected. Please make sure the simulation cell obeys the right-hand rule."); - } + volume = std::abs(volume); return volume; } From 3965bc8cf2fd62e45a5c3e7e811dd6edd573cd98 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Tue, 27 Sep 2022 20:05:04 -0400 Subject: [PATCH 2/2] include cmath --- source/lib/include/SimulationRegion_Impl.h | 1 + source/lib/src/region.cc | 1 + 2 files changed, 2 insertions(+) diff --git a/source/lib/include/SimulationRegion_Impl.h b/source/lib/include/SimulationRegion_Impl.h index d9c19d1077..341ae8f1dd 100644 --- a/source/lib/include/SimulationRegion_Impl.h +++ b/source/lib/include/SimulationRegion_Impl.h @@ -6,6 +6,7 @@ #include #include #include +#include #include "errors.h" // using namespace std; diff --git a/source/lib/src/region.cc b/source/lib/src/region.cc index c3411578a5..8ce37c0584 100644 --- a/source/lib/src/region.cc +++ b/source/lib/src/region.cc @@ -1,5 +1,6 @@ #include #include +#include #include "region.h" #include "errors.h" #define BOXT_DIM 9