2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2020,2021, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
37 * This implements basic nblib utility tests
39 * \author Victor Holanda <victor.holanda@cscs.ch>
40 * \author Joe Jordan <ejjordan@kth.se>
41 * \author Prashanth Kanduri <kanduri@cscs.ch>
42 * \author Sebastian Keller <keller@cscs.ch>
46 #include <gtest/gtest.h>
48 #include "nblib/listed_forces/helpers.hpp"
49 #include "nblib/listed_forces/traits.h"
51 #include "testutils/testasserts.h"
61 TEST(NBlibTest, CanSplitListedWork)
63 ListedInteractionData interactions;
65 HarmonicAngleType angle(Degrees(1), 1);
66 HarmonicBondType bond(1, 1);
68 int largestIndex = 20;
69 int nSplits = 3; // split ranges: [0,5], [6,11], [12, 19]
71 std::vector<InteractionIndex<HarmonicBondType>> bondIndices{
72 { 0, 1, 0 }, { 0, 6, 0 }, { 11, 12, 0 }, { 18, 19, 0 }
74 std::vector<InteractionIndex<HarmonicAngleType>> angleIndices{
75 { 0, 1, 2, 0 }, { 0, 6, 7, 0 }, { 11, 12, 13, 0 }, { 17, 19, 18, 0 }
78 pickType<HarmonicBondType>(interactions).indices = bondIndices;
79 pickType<HarmonicAngleType>(interactions).indices = angleIndices;
81 std::vector<ListedInteractionData> splitInteractions =
82 splitListedWork(interactions, largestIndex, nSplits);
84 std::vector<InteractionIndex<HarmonicBondType>> refBondIndices0{ { 0, 1, 0 }, { 0, 6, 0 } };
85 std::vector<InteractionIndex<HarmonicAngleType>> refAngleIndices0{ { 0, 1, 2, 0 }, { 0, 6, 7, 0 } };
86 std::vector<InteractionIndex<HarmonicBondType>> refBondIndices1{ { 11, 12, 0 } };
87 std::vector<InteractionIndex<HarmonicAngleType>> refAngleIndices1{ { 11, 12, 13, 0 } };
88 std::vector<InteractionIndex<HarmonicBondType>> refBondIndices2{ { 18, 19, 0 } };
89 std::vector<InteractionIndex<HarmonicAngleType>> refAngleIndices2{ { 17, 19, 18, 0 } };
91 EXPECT_EQ(refBondIndices0, pickType<HarmonicBondType>(splitInteractions[0]).indices);
92 EXPECT_EQ(refBondIndices1, pickType<HarmonicBondType>(splitInteractions[1]).indices);
93 EXPECT_EQ(refBondIndices2, pickType<HarmonicBondType>(splitInteractions[2]).indices);
95 EXPECT_EQ(refAngleIndices0, pickType<HarmonicAngleType>(splitInteractions[0]).indices);
96 EXPECT_EQ(refAngleIndices1, pickType<HarmonicAngleType>(splitInteractions[1]).indices);
97 EXPECT_EQ(refAngleIndices2, pickType<HarmonicAngleType>(splitInteractions[2]).indices);
101 TEST(NBlibTest, ListedForceBuffer)
107 std::vector<T> masterBuffer(ncoords, vzero);
109 // the ForceBuffer is going to access indices [10-15) through the masterBuffer
110 // and the outliers internally
114 ForceBuffer<T> forceBuffer(masterBuffer.data(), rangeStart, rangeEnd);
117 T internal1{ 1, 2, 3 };
118 T internal2{ 4, 5, 6 };
119 forceBuffer[10] = internal1;
120 forceBuffer[14] = internal2;
123 T outlier{ 0, 1, 2 };
124 forceBuffer[5] = outlier;
126 std::vector<T> refMasterBuffer(ncoords, vzero);
127 refMasterBuffer[10] = internal1;
128 refMasterBuffer[14] = internal2;
130 for (size_t i = 0; i < masterBuffer.size(); ++i)
132 for (size_t m = 0; m < dimSize; ++m)
135 refMasterBuffer[i][m], masterBuffer[i][m], gmx::test::defaultRealTolerance());
139 for (size_t m = 0; m < dimSize; ++m)
141 EXPECT_REAL_EQ_TOL(outlier[m], forceBuffer[5][m], gmx::test::defaultRealTolerance());
142 EXPECT_REAL_EQ_TOL(vzero[m], forceBuffer[4][m], gmx::test::defaultRealTolerance());