2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2020, 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.
35 /*! \inpublicapi \file
37 * Implements a force calculator based on GROMACS data structures.
39 * Intended for internal use inside the ForceCalculator.
41 * \author Victor Holanda <victor.holanda@cscs.ch>
42 * \author Joe Jordan <ejjordan@kth.se>
43 * \author Prashanth Kanduri <kanduri@cscs.ch>
44 * \author Sebastian Keller <keller@cscs.ch>
45 * \author Artem Zhmurov <zhmurov@gmail.com>
48 #ifndef NBLIB_LISTEDFORCES_CALCULATOR_H
49 #define NBLIB_LISTEDFORCES_CALCULATOR_H
52 #include <unordered_map>
54 #include "nblib/listed_forces/definitions.h"
69 /*! \internal \brief object to calculate listed forces
72 class ListedForceCalculator
75 using EnergyType = std::array<real, std::tuple_size<ListedInteractionData>::value>;
77 ListedForceCalculator(const ListedInteractionData& interactions,
82 /*! \brief Dispatch the listed force kernels and reduce the forces
84 * This function adds the computed listed forces to all values in the passed in forces buffer,
85 * so it can be regarded as an output only param. In case this is being used in a simulation
86 * that uses the same force buffer for both non-bonded and listed forces, this call should be
87 * made only after the compute() call from the non-bonded ForceCalculator
89 * This function also stores the forces and energies from listed interactions in the internal
90 * buffer of the ListedForceCalculator object
92 * \param[in] coordinates to be used for the force calculation
93 * \param[out] forces buffer to store the output forces
95 void compute(gmx::ArrayRef<const Vec3> coordinates, gmx::ArrayRef<Vec3> forces, bool usePbc = false);
97 //! Alternative overload with the energies in an output buffer
98 void compute(gmx::ArrayRef<const Vec3> coordinates,
99 gmx::ArrayRef<Vec3> forces,
100 EnergyType& energies,
101 bool usePbc = false);
103 /*! \brief We need to declare the destructor here to move the (still default) implementation
104 * to the .cpp file. Omitting this declaration would mean an inline destructor
105 * which can't compile because the unique_ptr dtor needs ~ForceBuffer, which is not available
106 * here because it's incomplete.
108 ~ListedForceCalculator();
113 //! the main buffer to hold the final listed forces
114 std::vector<gmx::RVec> masterForceBuffer_;
116 //! holds the array of energies computed
117 EnergyType energyBuffer_;
119 //! holds the listed interactions split into groups for multithreading
120 std::vector<ListedInteractionData> threadedInteractions_;
122 //! reduction force buffers
123 std::vector<std::unique_ptr<ForceBuffer<gmx::RVec>>> threadedForceBuffers_;
126 std::unique_ptr<PbcHolder> pbcHolder_;
128 //! compute listed forces and energies, overwrites the internal buffers
129 void computeForcesAndEnergies(gmx::ArrayRef<const Vec3> x, bool usePbc = false);
134 #endif // NBLIB_LISTEDFORCES_CALCULATOR_H