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.
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"
55 #include "nblib/vector.h"
68 class ForceBufferProxy;
70 /*! \internal \brief Object to calculate forces and energies of listed forces
73 class ListedForceCalculator
76 using EnergyType = std::array<real, std::tuple_size<ListedInteractionData>::value>;
78 ListedForceCalculator(const ListedInteractionData& interactions,
83 /*! \brief Dispatch the listed force kernels and reduce the forces
85 * This function adds the computed listed forces to all values in the passed in forces buffer,
86 * so it can be regarded as an output only param. In case this is being used in a simulation
87 * that uses the same force buffer for both non-bonded and listed forces, this call should be
88 * made only after the compute() call from the non-bonded ForceCalculator
90 * This function also stores the forces and energies from listed interactions in the internal
91 * buffer of the ListedForceCalculator object
93 * \param[in] coordinates input coordinates for the force calculation
94 * \param[inout] forces output for adding the forces
95 * \param[inout] shiftForces output for adding shift forces
96 * \param[out] energies output for potential energies
97 * \param[in] usePbc whether or not to consider periodic boundary conditions
99 void compute(gmx::ArrayRef<const Vec3> coordinates,
100 gmx::ArrayRef<Vec3> forces,
101 gmx::ArrayRef<Vec3> shiftForces,
102 gmx::ArrayRef<real> energies,
103 bool usePbc = false);
105 //! \brief Alternative overload without shift forces
106 void compute(gmx::ArrayRef<const Vec3> coordinates,
107 gmx::ArrayRef<Vec3> forces,
108 gmx::ArrayRef<real> energies,
109 bool usePbc = false);
111 //! \brief default, but moved to separate compilation unit
112 ~ListedForceCalculator();
117 //! holds the array of energies computed
118 EnergyType energyBuffer_;
120 //! holds the listed interactions split into groups for multithreading
121 std::vector<ListedInteractionData> threadedInteractions_;
123 //! reduction force buffers
124 std::vector<ForceBufferProxy<Vec3>> threadedForceBuffers_;
126 //! reduction shift force buffers
127 std::vector<std::vector<Vec3>> threadedShiftForceBuffers_;
130 std::unique_ptr<PbcHolder> pbcHolder_;
132 //! compute listed forces and energies, overwrites the internal buffers
133 template<class ShiftForce>
134 void computeForcesAndEnergies(gmx::ArrayRef<const Vec3> x,
135 gmx::ArrayRef<Vec3> forces,
136 [[maybe_unused]] gmx::ArrayRef<ShiftForce> shiftForces,
137 bool usePbc = false);
142 #endif // NBLIB_LISTEDFORCES_CALCULATOR_H