From 5f4c8eb442f11e252c2ec2b09906f719c6915d3d Mon Sep 17 00:00:00 2001 From: Joshua Scott Brown Date: Thu, 21 Nov 2019 22:54:50 -0700 Subject: [PATCH 01/20] Added pragma once to boundarycondition --- include/votca/csg/boundarycondition.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/votca/csg/boundarycondition.h b/include/votca/csg/boundarycondition.h index a2712e7f93..d1104bac9a 100644 --- a/include/votca/csg/boundarycondition.h +++ b/include/votca/csg/boundarycondition.h @@ -14,7 +14,7 @@ * limitations under the License. * */ - +#pragma once #ifndef _VOTCA_CSG_BOUNDARYCONDITION_H #define _VOTCA_CSG_BOUNDARYCONDITION_H From 70e93e3e0f2be1167be1a4d150a6faa80ac7ecce Mon Sep 17 00:00:00 2001 From: Joshua Scott Brown Date: Thu, 21 Nov 2019 22:56:29 -0700 Subject: [PATCH 02/20] Update header define --- include/votca/csg/boundarycondition.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/votca/csg/boundarycondition.h b/include/votca/csg/boundarycondition.h index d1104bac9a..eb2bc2efb3 100644 --- a/include/votca/csg/boundarycondition.h +++ b/include/votca/csg/boundarycondition.h @@ -15,8 +15,8 @@ * */ #pragma once -#ifndef _VOTCA_CSG_BOUNDARYCONDITION_H -#define _VOTCA_CSG_BOUNDARYCONDITION_H +#ifndef VOTCA_CSG_BOUNDARYCONDITION_H +#define VOTCA_CSG_BOUNDARYCONDITION_H #include @@ -63,4 +63,4 @@ class BoundaryCondition { } // namespace csg } // namespace votca -#endif /* _VOTCA_CSG_BOUNDARYCONDITION_H */ +#endif // VOTCA_CSG_BOUNDARYCONDITION_H From 1754472cb174a47713178866196a5530a035f096 Mon Sep 17 00:00:00 2001 From: Joshua Scott Brown Date: Thu, 21 Nov 2019 23:01:36 -0700 Subject: [PATCH 03/20] Comments, unique_ptr include, const, Clone method --- include/votca/csg/boundarycondition.h | 28 ++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/include/votca/csg/boundarycondition.h b/include/votca/csg/boundarycondition.h index eb2bc2efb3..58c6a91013 100644 --- a/include/votca/csg/boundarycondition.h +++ b/include/votca/csg/boundarycondition.h @@ -18,16 +18,38 @@ #ifndef VOTCA_CSG_BOUNDARYCONDITION_H #define VOTCA_CSG_BOUNDARYCONDITION_H +#include #include namespace votca { namespace csg { +/** + * @brief Class keeps track of how the boundaries of the system are handled + * + * There are a total of 3 different boundaries: + * open - no boundaries + * orthorhombic - orthorombic boundaries + * triclinic - triclinic boundaries + * + * This class enables the correct treatement of distances beteween topology + * objects, such that distances accound for the periodic boundaries. + */ class BoundaryCondition { public: virtual ~BoundaryCondition() = default; + /** + * @brief Safe way to allow child classes to be copied + * + * The child classes must use the same method and override it with their type + * for this to work. + * + * @return standard pointer to child class + */ + virtual std::unique_ptr Clone() const = 0; + /** * set the simulation box * \param box triclinic box matrix @@ -38,13 +60,13 @@ class BoundaryCondition { * get the simulation box * \return triclinic box matrix */ - const Eigen::Matrix3d &getBox() { return _box; }; + const Eigen::Matrix3d &getBox() const { return _box; }; /** * get the volume of the box * \return box volume as double */ - virtual double BoxVolume(); + virtual double BoxVolume() const; /** * get shortest connection vector between r_i and r_j with respect to the @@ -54,7 +76,7 @@ class BoundaryCondition { const Eigen::Vector3d &r_i, const Eigen::Vector3d &r_j) const = 0; enum eBoxtype { typeAuto = 0, typeTriclinic, typeOrthorhombic, typeOpen }; - virtual eBoxtype getBoxType() = 0; + virtual eBoxtype getBoxType() const = 0; protected: Eigen::Matrix3d _box; From 92ee7862a895cc697672cbda50df9fe14829210c Mon Sep 17 00:00:00 2001 From: Joshua Scott Brown Date: Thu, 21 Nov 2019 23:02:34 -0700 Subject: [PATCH 04/20] Added pragma once to triclinic --- include/votca/csg/triclinicbox.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/votca/csg/triclinicbox.h b/include/votca/csg/triclinicbox.h index b606638513..ecf4192bc0 100644 --- a/include/votca/csg/triclinicbox.h +++ b/include/votca/csg/triclinicbox.h @@ -14,7 +14,7 @@ * limitations under the License. * */ - +#pragma once #ifndef _VOTCA_CSG_TRICLINICBOX_H #define _VOTCA_CSG_TRICLINICBOX_H From 02522cc03e51c17123d0eb93bddbce141c7ef4ad Mon Sep 17 00:00:00 2001 From: Joshua Scott Brown Date: Thu, 21 Nov 2019 23:03:33 -0700 Subject: [PATCH 05/20] Added clone method to triclinic --- include/votca/csg/triclinicbox.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/votca/csg/triclinicbox.h b/include/votca/csg/triclinicbox.h index ecf4192bc0..dab0683f47 100644 --- a/include/votca/csg/triclinicbox.h +++ b/include/votca/csg/triclinicbox.h @@ -29,6 +29,10 @@ class TriclinicBox : public BoundaryCondition { Eigen::Vector3d BCShortestConnection( const Eigen::Vector3d &r_i, const Eigen::Vector3d &r_j) const override; + virtual std::unique_ptr Clone() const override { + return std::unique_ptr(new TriclinicBox(*this)); + } + eBoxtype getBoxType() override { return typeTriclinic; } protected: From a4943d2726c55daace6bbdfbde92cddb6e236fd2 Mon Sep 17 00:00:00 2001 From: Joshua Scott Brown Date: Thu, 21 Nov 2019 23:04:13 -0700 Subject: [PATCH 06/20] Added const correctness to getBoxType method --- include/votca/csg/triclinicbox.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/votca/csg/triclinicbox.h b/include/votca/csg/triclinicbox.h index dab0683f47..1f9ed4e443 100644 --- a/include/votca/csg/triclinicbox.h +++ b/include/votca/csg/triclinicbox.h @@ -33,7 +33,7 @@ class TriclinicBox : public BoundaryCondition { return std::unique_ptr(new TriclinicBox(*this)); } - eBoxtype getBoxType() override { return typeTriclinic; } + eBoxtype getBoxType() const override { return typeTriclinic; } protected: }; From 35d50e8a5447103b24c9eba53733c9d5de61b0c9 Mon Sep 17 00:00:00 2001 From: Joshua Scott Brown Date: Thu, 21 Nov 2019 23:04:41 -0700 Subject: [PATCH 07/20] Fixed Header guards --- include/votca/csg/triclinicbox.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/votca/csg/triclinicbox.h b/include/votca/csg/triclinicbox.h index 1f9ed4e443..08c72ce218 100644 --- a/include/votca/csg/triclinicbox.h +++ b/include/votca/csg/triclinicbox.h @@ -15,8 +15,8 @@ * */ #pragma once -#ifndef _VOTCA_CSG_TRICLINICBOX_H -#define _VOTCA_CSG_TRICLINICBOX_H +#ifndef VOTCA_CSG_TRICLINICBOX_H +#define VOTCA_CSG_TRICLINICBOX_H #include "boundarycondition.h" @@ -41,4 +41,4 @@ class TriclinicBox : public BoundaryCondition { } // namespace csg } // namespace votca -#endif /* _VOTCA_CSG_TRICLINICBOX_H */ +#endif // VOTCA_CSG_TRICLINICBOX_H From 0dc90c3f4d54f4faa927a7e2c0bd3914af94c7ad Mon Sep 17 00:00:00 2001 From: Joshua Scott Brown Date: Thu, 21 Nov 2019 23:05:42 -0700 Subject: [PATCH 08/20] Added pragma once --- include/votca/csg/orthorhombicbox.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/votca/csg/orthorhombicbox.h b/include/votca/csg/orthorhombicbox.h index 48b508a19f..b788147194 100644 --- a/include/votca/csg/orthorhombicbox.h +++ b/include/votca/csg/orthorhombicbox.h @@ -14,7 +14,7 @@ * limitations under the License. * */ - +#pragma once #ifndef _VOTCA_CSG_ORTHORHOMBICBOX_H #define _VOTCA_CSG_ORTHORHOMBICBOX_H From 92f60e03746c6a2288ccfa1341eb3dd54211dff4 Mon Sep 17 00:00:00 2001 From: Joshua Scott Brown Date: Thu, 21 Nov 2019 23:06:24 -0700 Subject: [PATCH 09/20] Added const to getBoxType method --- include/votca/csg/orthorhombicbox.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/votca/csg/orthorhombicbox.h b/include/votca/csg/orthorhombicbox.h index b788147194..cf08c8e9a2 100644 --- a/include/votca/csg/orthorhombicbox.h +++ b/include/votca/csg/orthorhombicbox.h @@ -29,7 +29,7 @@ class OrthorhombicBox : public BoundaryCondition { Eigen::Vector3d BCShortestConnection( const Eigen::Vector3d &r_i, const Eigen::Vector3d &r_j) const override; - eBoxtype getBoxType() override { return typeOrthorhombic; } + eBoxtype getBoxType() const override { return typeOrthorhombic; } protected: }; From b986d5f39b6be09e16627586fb0325c9d6bfeebb Mon Sep 17 00:00:00 2001 From: Joshua Scott Brown Date: Thu, 21 Nov 2019 23:06:48 -0700 Subject: [PATCH 10/20] Fixed header guard --- include/votca/csg/orthorhombicbox.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/votca/csg/orthorhombicbox.h b/include/votca/csg/orthorhombicbox.h index cf08c8e9a2..62f5f84b31 100644 --- a/include/votca/csg/orthorhombicbox.h +++ b/include/votca/csg/orthorhombicbox.h @@ -15,8 +15,8 @@ * */ #pragma once -#ifndef _VOTCA_CSG_ORTHORHOMBICBOX_H -#define _VOTCA_CSG_ORTHORHOMBICBOX_H +#ifndef VOTCA_CSG_ORTHORHOMBICBOX_H +#define VOTCA_CSG_ORTHORHOMBICBOX_H #include "boundarycondition.h" @@ -37,4 +37,4 @@ class OrthorhombicBox : public BoundaryCondition { } // namespace csg } // namespace votca -#endif /* _VOTCA_CSG_ORTHORHOMBICBOX_H */ +#endif // VOTCA_CSG_ORTHORHOMBICBOX_H From 7cc7772ea03a4b8bbe255c896b566ed92bb01692 Mon Sep 17 00:00:00 2001 From: Joshua Scott Brown Date: Thu, 21 Nov 2019 23:07:18 -0700 Subject: [PATCH 11/20] Added clone method --- include/votca/csg/orthorhombicbox.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/votca/csg/orthorhombicbox.h b/include/votca/csg/orthorhombicbox.h index 62f5f84b31..6a5d267837 100644 --- a/include/votca/csg/orthorhombicbox.h +++ b/include/votca/csg/orthorhombicbox.h @@ -29,6 +29,10 @@ class OrthorhombicBox : public BoundaryCondition { Eigen::Vector3d BCShortestConnection( const Eigen::Vector3d &r_i, const Eigen::Vector3d &r_j) const override; + virtual std::unique_ptr Clone() const override { + return std::unique_ptr(new OrthorhombicBox(*this)); + } + eBoxtype getBoxType() const override { return typeOrthorhombic; } protected: From d7a5f8921bcfc5a553e3954cf90322dba6db0994 Mon Sep 17 00:00:00 2001 From: Joshua Scott Brown Date: Thu, 21 Nov 2019 23:07:59 -0700 Subject: [PATCH 12/20] Added pragma once to openbox --- include/votca/csg/openbox.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/votca/csg/openbox.h b/include/votca/csg/openbox.h index 7cfa6f6a30..97b89896a3 100644 --- a/include/votca/csg/openbox.h +++ b/include/votca/csg/openbox.h @@ -14,7 +14,7 @@ * limitations under the License. * */ - +#pragma once #ifndef _VOTCA_CSG_OPENBOX_H #define _VOTCA_CSG_OPENBOX_H From d83481de885a6a60397b4c77afab6c7329209a1a Mon Sep 17 00:00:00 2001 From: Joshua Scott Brown Date: Thu, 21 Nov 2019 23:08:20 -0700 Subject: [PATCH 13/20] Fixed header guard of openbox --- include/votca/csg/openbox.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/votca/csg/openbox.h b/include/votca/csg/openbox.h index 97b89896a3..eb99a7b239 100644 --- a/include/votca/csg/openbox.h +++ b/include/votca/csg/openbox.h @@ -15,8 +15,8 @@ * */ #pragma once -#ifndef _VOTCA_CSG_OPENBOX_H -#define _VOTCA_CSG_OPENBOX_H +#ifndef VOTCA_CSG_OPENBOX_H +#define VOTCA_CSG_OPENBOX_H #include "boundarycondition.h" @@ -35,4 +35,4 @@ class OpenBox : public BoundaryCondition { } // namespace csg } // namespace votca -#endif /* _VOTCA_CSG_OPENBOX_H */ +#endif // VOTCA_CSG_OPENBOX_H From fd57013faa1aad1b3b3c7e9b8cd6ffe7c7c9efcf Mon Sep 17 00:00:00 2001 From: Joshua Scott Brown Date: Thu, 21 Nov 2019 23:08:47 -0700 Subject: [PATCH 14/20] Added const correctness to getBoxType --- include/votca/csg/openbox.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/votca/csg/openbox.h b/include/votca/csg/openbox.h index eb99a7b239..7921d3fb18 100644 --- a/include/votca/csg/openbox.h +++ b/include/votca/csg/openbox.h @@ -29,7 +29,7 @@ class OpenBox : public BoundaryCondition { Eigen::Vector3d BCShortestConnection( const Eigen::Vector3d &r_i, const Eigen::Vector3d &r_j) const override; - eBoxtype getBoxType() override { return typeOpen; } + eBoxtype getBoxType() const override { return typeOpen; } }; } // namespace csg From 551ccbad71b19e43c32d5e8dbcc1cfb193f16d5b Mon Sep 17 00:00:00 2001 From: Joshua Scott Brown Date: Thu, 21 Nov 2019 23:09:12 -0700 Subject: [PATCH 15/20] Added clone method to openbox --- include/votca/csg/openbox.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/votca/csg/openbox.h b/include/votca/csg/openbox.h index 7921d3fb18..842e5d81e9 100644 --- a/include/votca/csg/openbox.h +++ b/include/votca/csg/openbox.h @@ -29,6 +29,10 @@ class OpenBox : public BoundaryCondition { Eigen::Vector3d BCShortestConnection( const Eigen::Vector3d &r_i, const Eigen::Vector3d &r_j) const override; + virtual std::unique_ptr Clone() const override { + return std::unique_ptr(new OpenBox(*this)); + } + eBoxtype getBoxType() const override { return typeOpen; } }; From b07fd6a5f779ad370d032fb0a8e5644e6359fe15 Mon Sep 17 00:00:00 2001 From: Joshua Scott Brown Date: Thu, 21 Nov 2019 23:24:32 -0700 Subject: [PATCH 16/20] Added const correctness to BoxVolume method --- src/libcsg/boundarycondition.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libcsg/boundarycondition.cc b/src/libcsg/boundarycondition.cc index 3c37e4d8d1..6d04b3eed4 100644 --- a/src/libcsg/boundarycondition.cc +++ b/src/libcsg/boundarycondition.cc @@ -21,7 +21,9 @@ namespace votca { namespace csg { -double BoundaryCondition::BoxVolume() { return std::abs(_box.determinant()); } +double BoundaryCondition::BoxVolume() const { + return std::abs(_box.determinant()); +} } // namespace csg } // namespace votca From b6e66a011a3c4a3ad5bcbdab40fa631791312ccf Mon Sep 17 00:00:00 2001 From: Joshua Scott Brown Date: Fri, 22 Nov 2019 22:29:37 -0700 Subject: [PATCH 17/20] Added final and noexcept keywords --- include/votca/csg/boundarycondition.h | 8 ++++---- include/votca/csg/openbox.h | 7 ++++--- include/votca/csg/orthorhombicbox.h | 9 ++++++--- include/votca/csg/triclinicbox.h | 7 ++++--- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/include/votca/csg/boundarycondition.h b/include/votca/csg/boundarycondition.h index 58c6a91013..d2c78a439b 100644 --- a/include/votca/csg/boundarycondition.h +++ b/include/votca/csg/boundarycondition.h @@ -54,19 +54,19 @@ class BoundaryCondition { * set the simulation box * \param box triclinic box matrix */ - void setBox(const Eigen::Matrix3d &box) { _box = box; }; + void setBox(const Eigen::Matrix3d &box) noexcept { _box = box; }; /** * get the simulation box * \return triclinic box matrix */ - const Eigen::Matrix3d &getBox() const { return _box; }; + const Eigen::Matrix3d &getBox() const noexcept { return _box; }; /** * get the volume of the box * \return box volume as double */ - virtual double BoxVolume() const; + virtual double BoxVolume() const noexcept; /** * get shortest connection vector between r_i and r_j with respect to the @@ -76,7 +76,7 @@ class BoundaryCondition { const Eigen::Vector3d &r_i, const Eigen::Vector3d &r_j) const = 0; enum eBoxtype { typeAuto = 0, typeTriclinic, typeOrthorhombic, typeOpen }; - virtual eBoxtype getBoxType() const = 0; + virtual eBoxtype getBoxType() const noexcept = 0; protected: Eigen::Matrix3d _box; diff --git a/include/votca/csg/openbox.h b/include/votca/csg/openbox.h index 842e5d81e9..262e2a4fb5 100644 --- a/include/votca/csg/openbox.h +++ b/include/votca/csg/openbox.h @@ -27,13 +27,14 @@ class OpenBox : public BoundaryCondition { public: Eigen::Vector3d BCShortestConnection( - const Eigen::Vector3d &r_i, const Eigen::Vector3d &r_j) const override; + const Eigen::Vector3d &r_i, + const Eigen::Vector3d &r_j) const override final; - virtual std::unique_ptr Clone() const override { + virtual std::unique_ptr Clone() const override final { return std::unique_ptr(new OpenBox(*this)); } - eBoxtype getBoxType() const override { return typeOpen; } + eBoxtype getBoxType() const noexcept override final { return typeOpen; } }; } // namespace csg diff --git a/include/votca/csg/orthorhombicbox.h b/include/votca/csg/orthorhombicbox.h index 6a5d267837..e7cd91d562 100644 --- a/include/votca/csg/orthorhombicbox.h +++ b/include/votca/csg/orthorhombicbox.h @@ -27,13 +27,16 @@ class OrthorhombicBox : public BoundaryCondition { public: Eigen::Vector3d BCShortestConnection( - const Eigen::Vector3d &r_i, const Eigen::Vector3d &r_j) const override; + const Eigen::Vector3d &r_i, + const Eigen::Vector3d &r_j) const override final; - virtual std::unique_ptr Clone() const override { + virtual std::unique_ptr Clone() const override final { return std::unique_ptr(new OrthorhombicBox(*this)); } - eBoxtype getBoxType() const override { return typeOrthorhombic; } + eBoxtype getBoxType() const noexcept override final { + return typeOrthorhombic; + } protected: }; diff --git a/include/votca/csg/triclinicbox.h b/include/votca/csg/triclinicbox.h index 08c72ce218..ff016011fe 100644 --- a/include/votca/csg/triclinicbox.h +++ b/include/votca/csg/triclinicbox.h @@ -27,13 +27,14 @@ class TriclinicBox : public BoundaryCondition { public: Eigen::Vector3d BCShortestConnection( - const Eigen::Vector3d &r_i, const Eigen::Vector3d &r_j) const override; + const Eigen::Vector3d &r_i, + const Eigen::Vector3d &r_j) const override final; - virtual std::unique_ptr Clone() const override { + virtual std::unique_ptr Clone() const override final { return std::unique_ptr(new TriclinicBox(*this)); } - eBoxtype getBoxType() const override { return typeTriclinic; } + eBoxtype getBoxType() const noexcept override final { return typeTriclinic; } protected: }; From 2912bcfce1a127ececf9cf9689ca59c1de1b80d9 Mon Sep 17 00:00:00 2001 From: Joshua Scott Brown Date: Fri, 22 Nov 2019 23:42:46 -0700 Subject: [PATCH 18/20] method exception specifier made consistent with method in header --- src/libcsg/boundarycondition.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcsg/boundarycondition.cc b/src/libcsg/boundarycondition.cc index 6d04b3eed4..f580f772a2 100644 --- a/src/libcsg/boundarycondition.cc +++ b/src/libcsg/boundarycondition.cc @@ -21,7 +21,7 @@ namespace votca { namespace csg { -double BoundaryCondition::BoxVolume() const { +double BoundaryCondition::BoxVolume() const noexcept { return std::abs(_box.determinant()); } From 8ef101ede44d1f800320dedf11a68e25325f6373 Mon Sep 17 00:00:00 2001 From: JoshuaSBrown Date: Fri, 6 Dec 2019 06:34:24 -0700 Subject: [PATCH 19/20] Added unit test for boundaries --- src/tests/CMakeLists.txt | 1 + src/tests/test_boundarycondition.cc | 125 ++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 src/tests/test_boundarycondition.cc diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index fd8348da9f..0ab6041fe7 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -16,6 +16,7 @@ foreach(PROG test_lammpsdumpreaderwriter test_nblist_3body test_nblistgrid_3body + test_boundarycondition test_pdbreader test_tabulatedpotential test_triplelist ) diff --git a/src/tests/test_boundarycondition.cc b/src/tests/test_boundarycondition.cc new file mode 100644 index 0000000000..04efe9f696 --- /dev/null +++ b/src/tests/test_boundarycondition.cc @@ -0,0 +1,125 @@ +/* + * Copyright 2009-2019 The VOTCA Development Team (http://www.votca.org) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#define BOOST_TEST_MAIN + +#define BOOST_TEST_MODULE pdbreader_test +#include +#include +#include "../../include/votca/csg/openbox.h" +#include "../../include/votca/csg/triclinicbox.h" +#include "../../include/votca/csg/orthorhombicbox.h" + +#include +#include +#include + +using namespace std; +using namespace votca::csg; + +BOOST_AUTO_TEST_SUITE(boundarycondition_test) + +BOOST_AUTO_TEST_CASE(test_boundarycondition_initiatialization) { + vector> boundaries; + + boundaries.push_back(unique_ptr(new OpenBox)); + boundaries.push_back(unique_ptr(new TriclinicBox)); + boundaries.push_back(unique_ptr(new OrthorhombicBox)); + + BOOST_CHECK_EQUAL(boundaries.at(0)->getBoxType(),BoundaryCondition::eBoxtype::typeOpen); + BOOST_CHECK_EQUAL(boundaries.at(1)->getBoxType(),BoundaryCondition::eBoxtype::typeTriclinic); + BOOST_CHECK_EQUAL(boundaries.at(2)->getBoxType(),BoundaryCondition::eBoxtype::typeOrthorhombic); +} + +BOOST_AUTO_TEST_CASE(test_boundarycondition_boxvolume) { + vector> boundaries; + + boundaries.push_back(unique_ptr(new OpenBox)); + boundaries.push_back(unique_ptr(new TriclinicBox)); + boundaries.push_back(unique_ptr(new OrthorhombicBox)); + + Eigen::Matrix3d box; + box << 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0; + + boundaries.at(0)->setBox(box); + boundaries.at(1)->setBox(box); + boundaries.at(2)->setBox(box); + + BOOST_CHECK_EQUAL(boundaries.at(0)->BoxVolume(),0.0); + BOOST_CHECK_EQUAL(boundaries.at(1)->BoxVolume(),0.0); + BOOST_CHECK_EQUAL(boundaries.at(2)->BoxVolume(),0.0); + + box(0,0) = 1.0; + box(1,1) = 2.0; + box(2,2) = 1.0; + + boundaries.at(0)->setBox(box); + boundaries.at(1)->setBox(box); + boundaries.at(2)->setBox(box); + + BOOST_CHECK_EQUAL(boundaries.at(0)->BoxVolume(),2.0); + BOOST_CHECK_EQUAL(boundaries.at(1)->BoxVolume(),2.0); + BOOST_CHECK_EQUAL(boundaries.at(2)->BoxVolume(),2.0); +} + +BOOST_AUTO_TEST_CASE(test_boundarycondition_clone) { + vector> boundaries; + + boundaries.push_back(unique_ptr(new OpenBox)); + boundaries.push_back(unique_ptr(new TriclinicBox)); + boundaries.push_back(unique_ptr(new OrthorhombicBox)); + + Eigen::Matrix3d box; + box << 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0; + + boundaries.at(0)->setBox(box); + boundaries.at(1)->setBox(box); + boundaries.at(2)->setBox(box); + + vector> boundaries_copy; + + boundaries_copy.push_back(boundaries.at(0)->Clone()); + boundaries_copy.push_back(boundaries.at(1)->Clone()); + boundaries_copy.push_back(boundaries.at(2)->Clone()); + + BOOST_CHECK_EQUAL(boundaries_copy.at(0)->getBoxType(),BoundaryCondition::eBoxtype::typeOpen); + BOOST_CHECK_EQUAL(boundaries_copy.at(1)->getBoxType(),BoundaryCondition::eBoxtype::typeTriclinic); + BOOST_CHECK_EQUAL(boundaries_copy.at(2)->getBoxType(),BoundaryCondition::eBoxtype::typeOrthorhombic); + + box(0,0) = 1.0; + box(1,1) = 2.0; + box(2,2) = 1.0; + + boundaries_copy.at(0)->setBox(box); + boundaries_copy.at(1)->setBox(box); + boundaries_copy.at(2)->setBox(box); + + BOOST_CHECK_EQUAL(boundaries_copy.at(0)->BoxVolume(),2.0); + BOOST_CHECK_EQUAL(boundaries_copy.at(1)->BoxVolume(),2.0); + BOOST_CHECK_EQUAL(boundaries_copy.at(2)->BoxVolume(),2.0); + + /* Ensure that the original boundaries were not altered */ + BOOST_CHECK_EQUAL(boundaries.at(0)->BoxVolume(),0.0); + BOOST_CHECK_EQUAL(boundaries.at(1)->BoxVolume(),0.0); + BOOST_CHECK_EQUAL(boundaries.at(2)->BoxVolume(),0.0); + +} +BOOST_AUTO_TEST_SUITE_END() From cd47b5e5d8f63e61525d284aeb52275746dc0ffa Mon Sep 17 00:00:00 2001 From: JoshuaSBrown Date: Fri, 6 Dec 2019 12:18:09 -0700 Subject: [PATCH 20/20] Corrected formatting, removed include from test --- include/votca/csg/openbox.h | 6 +- include/votca/csg/orthorhombicbox.h | 11 +- include/votca/csg/triclinicbox.h | 6 +- src/tests/test_boundarycondition.cc | 170 ++++++++++++++-------------- 4 files changed, 93 insertions(+), 100 deletions(-) diff --git a/include/votca/csg/openbox.h b/include/votca/csg/openbox.h index 5c6e05c9be..76669e6a49 100644 --- a/include/votca/csg/openbox.h +++ b/include/votca/csg/openbox.h @@ -26,16 +26,14 @@ namespace csg { class OpenBox : public BoundaryCondition { public: - Eigen::Vector3d BCShortestConnection( - const Eigen::Vector3d &r_i, - const Eigen::Vector3d &r_j) const final; + Eigen::Vector3d BCShortestConnection(const Eigen::Vector3d &r_i, + const Eigen::Vector3d &r_j) const final; virtual std::unique_ptr Clone() const final { return std::unique_ptr(new OpenBox(*this)); } eBoxtype getBoxType() const noexcept final { return typeOpen; } - }; } // namespace csg diff --git a/include/votca/csg/orthorhombicbox.h b/include/votca/csg/orthorhombicbox.h index eea86f1469..4ad2469789 100644 --- a/include/votca/csg/orthorhombicbox.h +++ b/include/votca/csg/orthorhombicbox.h @@ -26,18 +26,15 @@ namespace csg { class OrthorhombicBox : public BoundaryCondition { public: - Eigen::Vector3d BCShortestConnection( - const Eigen::Vector3d &r_i, - const Eigen::Vector3d &r_j) const final; + Eigen::Vector3d BCShortestConnection(const Eigen::Vector3d &r_i, + const Eigen::Vector3d &r_j) const final; virtual std::unique_ptr Clone() const final { return std::unique_ptr(new OrthorhombicBox(*this)); } - eBoxtype getBoxType() const noexcept final { - return typeOrthorhombic; - } - + eBoxtype getBoxType() const noexcept final { return typeOrthorhombic; } + protected: }; diff --git a/include/votca/csg/triclinicbox.h b/include/votca/csg/triclinicbox.h index 50f53eefc9..ef0b4a8471 100644 --- a/include/votca/csg/triclinicbox.h +++ b/include/votca/csg/triclinicbox.h @@ -26,10 +26,8 @@ namespace csg { class TriclinicBox : public BoundaryCondition { public: - - Eigen::Vector3d BCShortestConnection( - const Eigen::Vector3d &r_i, - const Eigen::Vector3d &r_j) const final; + Eigen::Vector3d BCShortestConnection(const Eigen::Vector3d &r_i, + const Eigen::Vector3d &r_j) const final; virtual std::unique_ptr Clone() const final { return std::unique_ptr(new TriclinicBox(*this)); diff --git a/src/tests/test_boundarycondition.cc b/src/tests/test_boundarycondition.cc index 04efe9f696..34b790b35e 100644 --- a/src/tests/test_boundarycondition.cc +++ b/src/tests/test_boundarycondition.cc @@ -18,15 +18,14 @@ #define BOOST_TEST_MAIN #define BOOST_TEST_MODULE pdbreader_test -#include -#include #include "../../include/votca/csg/openbox.h" -#include "../../include/votca/csg/triclinicbox.h" #include "../../include/votca/csg/orthorhombicbox.h" +#include "../../include/votca/csg/triclinicbox.h" +#include +#include -#include #include -#include +#include using namespace std; using namespace votca::csg; @@ -34,92 +33,93 @@ using namespace votca::csg; BOOST_AUTO_TEST_SUITE(boundarycondition_test) BOOST_AUTO_TEST_CASE(test_boundarycondition_initiatialization) { - vector> boundaries; - - boundaries.push_back(unique_ptr(new OpenBox)); - boundaries.push_back(unique_ptr(new TriclinicBox)); - boundaries.push_back(unique_ptr(new OrthorhombicBox)); - - BOOST_CHECK_EQUAL(boundaries.at(0)->getBoxType(),BoundaryCondition::eBoxtype::typeOpen); - BOOST_CHECK_EQUAL(boundaries.at(1)->getBoxType(),BoundaryCondition::eBoxtype::typeTriclinic); - BOOST_CHECK_EQUAL(boundaries.at(2)->getBoxType(),BoundaryCondition::eBoxtype::typeOrthorhombic); + vector> boundaries; + + boundaries.push_back(unique_ptr(new OpenBox)); + boundaries.push_back(unique_ptr(new TriclinicBox)); + boundaries.push_back(unique_ptr(new OrthorhombicBox)); + + BOOST_CHECK_EQUAL(boundaries.at(0)->getBoxType(), + BoundaryCondition::eBoxtype::typeOpen); + BOOST_CHECK_EQUAL(boundaries.at(1)->getBoxType(), + BoundaryCondition::eBoxtype::typeTriclinic); + BOOST_CHECK_EQUAL(boundaries.at(2)->getBoxType(), + BoundaryCondition::eBoxtype::typeOrthorhombic); } BOOST_AUTO_TEST_CASE(test_boundarycondition_boxvolume) { - vector> boundaries; - - boundaries.push_back(unique_ptr(new OpenBox)); - boundaries.push_back(unique_ptr(new TriclinicBox)); - boundaries.push_back(unique_ptr(new OrthorhombicBox)); - - Eigen::Matrix3d box; - box << 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0; - - boundaries.at(0)->setBox(box); - boundaries.at(1)->setBox(box); - boundaries.at(2)->setBox(box); - - BOOST_CHECK_EQUAL(boundaries.at(0)->BoxVolume(),0.0); - BOOST_CHECK_EQUAL(boundaries.at(1)->BoxVolume(),0.0); - BOOST_CHECK_EQUAL(boundaries.at(2)->BoxVolume(),0.0); - - box(0,0) = 1.0; - box(1,1) = 2.0; - box(2,2) = 1.0; - - boundaries.at(0)->setBox(box); - boundaries.at(1)->setBox(box); - boundaries.at(2)->setBox(box); - - BOOST_CHECK_EQUAL(boundaries.at(0)->BoxVolume(),2.0); - BOOST_CHECK_EQUAL(boundaries.at(1)->BoxVolume(),2.0); - BOOST_CHECK_EQUAL(boundaries.at(2)->BoxVolume(),2.0); + vector> boundaries; + + boundaries.push_back(unique_ptr(new OpenBox)); + boundaries.push_back(unique_ptr(new TriclinicBox)); + boundaries.push_back(unique_ptr(new OrthorhombicBox)); + + Eigen::Matrix3d box; + box << 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0; + + boundaries.at(0)->setBox(box); + boundaries.at(1)->setBox(box); + boundaries.at(2)->setBox(box); + + BOOST_CHECK_EQUAL(boundaries.at(0)->BoxVolume(), 0.0); + BOOST_CHECK_EQUAL(boundaries.at(1)->BoxVolume(), 0.0); + BOOST_CHECK_EQUAL(boundaries.at(2)->BoxVolume(), 0.0); + + box(0, 0) = 1.0; + box(1, 1) = 2.0; + box(2, 2) = 1.0; + + boundaries.at(0)->setBox(box); + boundaries.at(1)->setBox(box); + boundaries.at(2)->setBox(box); + + BOOST_CHECK_EQUAL(boundaries.at(0)->BoxVolume(), 2.0); + BOOST_CHECK_EQUAL(boundaries.at(1)->BoxVolume(), 2.0); + BOOST_CHECK_EQUAL(boundaries.at(2)->BoxVolume(), 2.0); } BOOST_AUTO_TEST_CASE(test_boundarycondition_clone) { - vector> boundaries; - - boundaries.push_back(unique_ptr(new OpenBox)); - boundaries.push_back(unique_ptr(new TriclinicBox)); - boundaries.push_back(unique_ptr(new OrthorhombicBox)); - - Eigen::Matrix3d box; - box << 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0; - - boundaries.at(0)->setBox(box); - boundaries.at(1)->setBox(box); - boundaries.at(2)->setBox(box); - - vector> boundaries_copy; - - boundaries_copy.push_back(boundaries.at(0)->Clone()); - boundaries_copy.push_back(boundaries.at(1)->Clone()); - boundaries_copy.push_back(boundaries.at(2)->Clone()); - - BOOST_CHECK_EQUAL(boundaries_copy.at(0)->getBoxType(),BoundaryCondition::eBoxtype::typeOpen); - BOOST_CHECK_EQUAL(boundaries_copy.at(1)->getBoxType(),BoundaryCondition::eBoxtype::typeTriclinic); - BOOST_CHECK_EQUAL(boundaries_copy.at(2)->getBoxType(),BoundaryCondition::eBoxtype::typeOrthorhombic); - - box(0,0) = 1.0; - box(1,1) = 2.0; - box(2,2) = 1.0; - - boundaries_copy.at(0)->setBox(box); - boundaries_copy.at(1)->setBox(box); - boundaries_copy.at(2)->setBox(box); - - BOOST_CHECK_EQUAL(boundaries_copy.at(0)->BoxVolume(),2.0); - BOOST_CHECK_EQUAL(boundaries_copy.at(1)->BoxVolume(),2.0); - BOOST_CHECK_EQUAL(boundaries_copy.at(2)->BoxVolume(),2.0); - - /* Ensure that the original boundaries were not altered */ - BOOST_CHECK_EQUAL(boundaries.at(0)->BoxVolume(),0.0); - BOOST_CHECK_EQUAL(boundaries.at(1)->BoxVolume(),0.0); - BOOST_CHECK_EQUAL(boundaries.at(2)->BoxVolume(),0.0); + vector> boundaries; + + boundaries.push_back(unique_ptr(new OpenBox)); + boundaries.push_back(unique_ptr(new TriclinicBox)); + boundaries.push_back(unique_ptr(new OrthorhombicBox)); + + Eigen::Matrix3d box; + box << 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0; + + boundaries.at(0)->setBox(box); + boundaries.at(1)->setBox(box); + boundaries.at(2)->setBox(box); + + vector> boundaries_copy; + + boundaries_copy.push_back(boundaries.at(0)->Clone()); + boundaries_copy.push_back(boundaries.at(1)->Clone()); + boundaries_copy.push_back(boundaries.at(2)->Clone()); + + BOOST_CHECK_EQUAL(boundaries_copy.at(0)->getBoxType(), + BoundaryCondition::eBoxtype::typeOpen); + BOOST_CHECK_EQUAL(boundaries_copy.at(1)->getBoxType(), + BoundaryCondition::eBoxtype::typeTriclinic); + BOOST_CHECK_EQUAL(boundaries_copy.at(2)->getBoxType(), + BoundaryCondition::eBoxtype::typeOrthorhombic); + + box(0, 0) = 1.0; + box(1, 1) = 2.0; + box(2, 2) = 1.0; + + boundaries_copy.at(0)->setBox(box); + boundaries_copy.at(1)->setBox(box); + boundaries_copy.at(2)->setBox(box); + + BOOST_CHECK_EQUAL(boundaries_copy.at(0)->BoxVolume(), 2.0); + BOOST_CHECK_EQUAL(boundaries_copy.at(1)->BoxVolume(), 2.0); + BOOST_CHECK_EQUAL(boundaries_copy.at(2)->BoxVolume(), 2.0); + /* Ensure that the original boundaries were not altered */ + BOOST_CHECK_EQUAL(boundaries.at(0)->BoxVolume(), 0.0); + BOOST_CHECK_EQUAL(boundaries.at(1)->BoxVolume(), 0.0); + BOOST_CHECK_EQUAL(boundaries.at(2)->BoxVolume(), 0.0); } BOOST_AUTO_TEST_SUITE_END()