Skip to content
This repository has been archived by the owner on Sep 27, 2021. It is now read-only.

Commit

Permalink
Merge pull request #457 from votca/piece-wize-boundaries
Browse files Browse the repository at this point in the history
Piece wize boundaries
  • Loading branch information
junghans authored Dec 7, 2019
2 parents d1ee46c + cd47b5e commit aab4105
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 24 deletions.
38 changes: 30 additions & 8 deletions include/votca/csg/boundarycondition.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,59 @@
* limitations under the License.
*
*/
#pragma once
#ifndef VOTCA_CSG_BOUNDARYCONDITION_H
#define VOTCA_CSG_BOUNDARYCONDITION_H

#ifndef _VOTCA_CSG_BOUNDARYCONDITION_H
#define _VOTCA_CSG_BOUNDARYCONDITION_H

#include <memory>
#include <votca/tools/eigen.h>

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<BoundaryCondition> Clone() const = 0;

/**
* 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() { return _box; };
const Eigen::Matrix3d &getBox() const noexcept { return _box; };

/**
* get the volume of the box
* \return box volume as double
*/
virtual double BoxVolume();
virtual double BoxVolume() const noexcept;

/**
* get shortest connection vector between r_i and r_j with respect to the
Expand All @@ -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 noexcept = 0;

protected:
Eigen::Matrix3d _box;
Expand All @@ -63,4 +85,4 @@ class BoundaryCondition {
} // namespace csg
} // namespace votca

#endif /* _VOTCA_CSG_BOUNDARYCONDITION_H */
#endif // VOTCA_CSG_BOUNDARYCONDITION_H
14 changes: 9 additions & 5 deletions include/votca/csg/openbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* limitations under the License.
*
*/

#ifndef _VOTCA_CSG_OPENBOX_H
#define _VOTCA_CSG_OPENBOX_H
#pragma once
#ifndef VOTCA_CSG_OPENBOX_H
#define VOTCA_CSG_OPENBOX_H

#include "boundarycondition.h"

Expand All @@ -29,10 +29,14 @@ class OpenBox : public BoundaryCondition {
Eigen::Vector3d BCShortestConnection(const Eigen::Vector3d &r_i,
const Eigen::Vector3d &r_j) const final;

eBoxtype getBoxType() final { return typeOpen; }
virtual std::unique_ptr<BoundaryCondition> Clone() const final {
return std::unique_ptr<BoundaryCondition>(new OpenBox(*this));
}

eBoxtype getBoxType() const noexcept final { return typeOpen; }
};

} // namespace csg
} // namespace votca

#endif /* _VOTCA_CSG_OPENBOX_H */
#endif // VOTCA_CSG_OPENBOX_H
14 changes: 9 additions & 5 deletions include/votca/csg/orthorhombicbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* limitations under the License.
*
*/

#ifndef _VOTCA_CSG_ORTHORHOMBICBOX_H
#define _VOTCA_CSG_ORTHORHOMBICBOX_H
#pragma once
#ifndef VOTCA_CSG_ORTHORHOMBICBOX_H
#define VOTCA_CSG_ORTHORHOMBICBOX_H

#include "boundarycondition.h"

Expand All @@ -29,12 +29,16 @@ class OrthorhombicBox : public BoundaryCondition {
Eigen::Vector3d BCShortestConnection(const Eigen::Vector3d &r_i,
const Eigen::Vector3d &r_j) const final;

eBoxtype getBoxType() final { return typeOrthorhombic; }
virtual std::unique_ptr<BoundaryCondition> Clone() const final {
return std::unique_ptr<BoundaryCondition>(new OrthorhombicBox(*this));
}

eBoxtype getBoxType() const noexcept final { return typeOrthorhombic; }

protected:
};

} // namespace csg
} // namespace votca

#endif /* _VOTCA_CSG_ORTHORHOMBICBOX_H */
#endif // VOTCA_CSG_ORTHORHOMBICBOX_H
14 changes: 9 additions & 5 deletions include/votca/csg/triclinicbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* limitations under the License.
*
*/

#ifndef _VOTCA_CSG_TRICLINICBOX_H
#define _VOTCA_CSG_TRICLINICBOX_H
#pragma once
#ifndef VOTCA_CSG_TRICLINICBOX_H
#define VOTCA_CSG_TRICLINICBOX_H

#include "boundarycondition.h"

Expand All @@ -29,12 +29,16 @@ class TriclinicBox : public BoundaryCondition {
Eigen::Vector3d BCShortestConnection(const Eigen::Vector3d &r_i,
const Eigen::Vector3d &r_j) const final;

eBoxtype getBoxType() final { return typeTriclinic; }
virtual std::unique_ptr<BoundaryCondition> Clone() const final {
return std::unique_ptr<BoundaryCondition>(new TriclinicBox(*this));
}

eBoxtype getBoxType() const noexcept final { return typeTriclinic; }

protected:
};

} // namespace csg
} // namespace votca

#endif /* _VOTCA_CSG_TRICLINICBOX_H */
#endif // VOTCA_CSG_TRICLINICBOX_H
4 changes: 3 additions & 1 deletion src/libcsg/boundarycondition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
namespace votca {
namespace csg {

double BoundaryCondition::BoxVolume() { return std::abs(_box.determinant()); }
double BoundaryCondition::BoxVolume() const noexcept {
return std::abs(_box.determinant());
}

} // namespace csg
} // namespace votca
1 change: 1 addition & 0 deletions src/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ foreach(PROG
test_lammpsdumpreaderwriter
test_nblist_3body
test_nblistgrid_3body
test_boundarycondition
test_pdbreader
test_tabulatedpotential
test_triplelist )
Expand Down
125 changes: 125 additions & 0 deletions src/tests/test_boundarycondition.cc
Original file line number Diff line number Diff line change
@@ -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/votca/csg/openbox.h"
#include "../../include/votca/csg/orthorhombicbox.h"
#include "../../include/votca/csg/triclinicbox.h"
#include <boost/test/floating_point_comparison.hpp>
#include <boost/test/unit_test.hpp>

#include <memory>
#include <vector>

using namespace std;
using namespace votca::csg;

BOOST_AUTO_TEST_SUITE(boundarycondition_test)

BOOST_AUTO_TEST_CASE(test_boundarycondition_initiatialization) {
vector<unique_ptr<BoundaryCondition>> boundaries;

boundaries.push_back(unique_ptr<OpenBox>(new OpenBox));
boundaries.push_back(unique_ptr<TriclinicBox>(new TriclinicBox));
boundaries.push_back(unique_ptr<OrthorhombicBox>(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<unique_ptr<BoundaryCondition>> boundaries;

boundaries.push_back(unique_ptr<OpenBox>(new OpenBox));
boundaries.push_back(unique_ptr<TriclinicBox>(new TriclinicBox));
boundaries.push_back(unique_ptr<OrthorhombicBox>(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<unique_ptr<BoundaryCondition>> boundaries;

boundaries.push_back(unique_ptr<OpenBox>(new OpenBox));
boundaries.push_back(unique_ptr<TriclinicBox>(new TriclinicBox));
boundaries.push_back(unique_ptr<OrthorhombicBox>(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<unique_ptr<BoundaryCondition>> 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()

0 comments on commit aab4105

Please sign in to comment.