PME force gathering tests
[alexxy/gromacs.git] / src / gromacs / ewald / tests / pmetestcommon.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2016,2017, 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.
8  *
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.
13  *
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.
18  *
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.
23  *
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.
31  *
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.
34  */
35 /*! \internal \file
36  * \brief
37  * Describes common routines and types for PME tests.
38  *
39  * \author Aleksei Iupinov <a.yupinov@gmail.com>
40  * \ingroup module_ewald
41  */
42 #ifndef GMX_EWALD_PME_TEST_COMMON_H
43 #define GMX_EWALD_PME_TEST_COMMON_H
44
45 #include <array>
46 #include <map>
47 #include <vector>
48
49 #include "gromacs/ewald/pme.h"
50 #include "gromacs/utility/arrayref.h"
51 #include "gromacs/utility/unique_cptr.h"
52
53 struct t_inputrec;
54
55 namespace gmx
56 {
57 namespace test
58 {
59
60 // Convenience typedefs
61 //! A safe pointer type for PME.
62 typedef gmx::unique_cptr<gmx_pme_t, gmx_pme_destroy> PmeSafePointer;
63 //! Charges
64 typedef ConstArrayRef<real> ChargesVector;
65 //! Coordinates
66 typedef std::vector<RVec> CoordinatesVector;
67 //! Forces
68 typedef ArrayRef<RVec> ForcesVector;
69 //! Gridline indices
70 typedef ConstArrayRef<IVec> GridLineIndicesVector;
71 //! Type of spline data
72 enum class PmeSplineDataType
73 {
74     Values,      // theta
75     Derivatives, //dtheta
76 };
77 /*! \brief Spline parameters (theta or dtheta).
78  * A reference to a single dimension's spline data; this means (atomCount * pmeOrder) values or derivatives.
79  */
80 typedef ConstArrayRef<real> SplineParamsDimVector;
81 /*! \brief Spline parameters (theta or dtheta) in all 3 dimensions
82  */
83 typedef std::array<SplineParamsDimVector, DIM> SplineParamsVector;
84
85 //! Non-zero grid values for test input; keys are 3d indices (IVec)
86 template<typename ValueType>using SparseGridValuesInput = std::map<IVec, ValueType>;
87 //! Non-zero real grid values
88 typedef SparseGridValuesInput<real> SparseRealGridValuesInput;
89 //! Non-zero grid values for test output; keys are string representations of the cells' 3d indices (IVec); this allows for better sorting.
90 template<typename ValueType>using SparseGridValuesOutput = std::map<std::string, ValueType>;
91 //! Non-zero real grid values
92 typedef SparseGridValuesOutput<real> SparseRealGridValuesOutput;
93
94 //! TODO: make proper C++ matrix for the whole Gromacs, get rid of this
95 typedef std::array<real, DIM * DIM> Matrix3x3;
96 //! PME code path being tested
97 enum class CodePath
98 {
99     CPU,    // serial CPU code
100 };
101 //! PME gathering input forces treatment
102 enum class PmeGatherInputHandling
103 {
104     Overwrite,
105     ReduceWith,
106 };
107
108 // PME stages
109
110 //! Simple PME initialization based on input, no atom data; only good for testing the initialization stage
111 PmeSafePointer pmeInitEmpty(const t_inputrec *inputRec);
112 //! PME initialization with atom data and system box
113 PmeSafePointer pmeInitWithAtoms(const t_inputrec        *inputRec,
114                                 const CoordinatesVector &coordinates,
115                                 const ChargesVector     &charges,
116                                 const Matrix3x3          box
117                                 );
118 //! PME spline computation and charge spreading
119 void pmePerformSplineAndSpread(gmx_pme_t *pme, CodePath mode,
120                                bool computeSplines, bool spreadCharges);
121 //! PME force gathering
122 void pmePerformGather(gmx_pme_t *pme, CodePath mode,
123                       PmeGatherInputHandling inputTreatment, ForcesVector &forces);
124
125 // PME state setters
126
127 //! Setting atom spline values or derivatives to be used in spread/gather
128 void pmeSetSplineData(const gmx_pme_t *pme, CodePath mode,
129                       const SplineParamsDimVector &splineValues, PmeSplineDataType type, int dimIndex);
130 //! Setting gridline indices be used in spread/gather
131 void pmeSetGridLineIndices(const gmx_pme_t *pme, CodePath mode,
132                            const GridLineIndicesVector &gridLineIndices);
133 //! Setting real grid to be used in gather
134 void pmeSetRealGrid(const gmx_pme_t *pme, CodePath mode,
135                     const SparseRealGridValuesInput &gridValues);
136
137 // PME state getters
138
139 //! Getting the single dimension's spline values or derivatives
140 SplineParamsDimVector pmeGetSplineData(const gmx_pme_t *pme, CodePath mode,
141                                        PmeSplineDataType type, int dimIndex);
142 //! Getting the gridline indices
143 GridLineIndicesVector pmeGetGridlineIndices(const gmx_pme_t *pme, CodePath mode);
144 //! Getting the real grid (spreading output of PmePerformSplineAndSpread())
145 SparseRealGridValuesOutput pmeGetRealGrid(const gmx_pme_t *pme, CodePath mode);
146
147 }
148 }
149
150 #endif