Simplify compiling GPU code for tests
[gromacs.git] / src / gromacs / mdlib / tests / constrtestdata.h
blob7374fa19243eb448696be7744910d5bede2ce679
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2018,2019,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 /*! \internal \file
36 * \brief SHAKE and LINCS tests header.
38 * Contains description and constructor for the test data accumulating object,
39 * declares CPU- and GPU-based functions used to apply SHAKE or LINCS on the
40 * test data.
42 * \author Artem Zhmurov <zhmurov@gmail.com>
43 * \ingroup module_mdlib
46 #ifndef GMX_MDLIB_TESTS_CONSTRTESTDATA_H
47 #define GMX_MDLIB_TESTS_CONSTRTESTDATA_H
49 #include <memory>
50 #include <vector>
52 #include "gromacs/gmxlib/nrnb.h"
53 #include "gromacs/gpu_utils/gpu_testutils.h"
54 #include "gromacs/math/paddedvector.h"
55 #include "gromacs/math/vec.h"
56 #include "gromacs/math/vectypes.h"
57 #include "gromacs/mdlib/gmx_omp_nthreads.h"
58 #include "gromacs/mdlib/lincs.h"
59 #include "gromacs/mdlib/shake.h"
60 #include "gromacs/mdtypes/inputrec.h"
61 #include "gromacs/mdtypes/mdatom.h"
62 #include "gromacs/pbcutil/pbc.h"
63 #include "gromacs/topology/idef.h"
64 #include "gromacs/topology/ifunc.h"
65 #include "gromacs/topology/topology.h"
67 namespace gmx
69 namespace test
72 /* \brief
73 * Constraints test data structure.
75 * Structure to collect all the necessary data, including system coordinates and topology,
76 * constraints information, etc. The structure can be reset and reused.
78 class ConstraintsTestData
80 public:
81 //! Human-friendly name for a system
82 std::string title_;
83 //! Number of atoms
84 int numAtoms_;
85 //! Topology
86 gmx_mtop_t mtop_;
87 //! Masses
88 std::vector<real> masses_;
89 //! Inverse masses
90 std::vector<real> invmass_;
91 //! Input record (info that usually in .mdp file)
92 t_inputrec ir_;
93 //! Local topology
94 std::unique_ptr<InteractionDefinitions> idef_;
95 //! MD atoms
96 t_mdatoms md_;
97 //! Computational time array (normally used to benchmark performance)
98 t_nrnb nrnb_;
100 //! Inverse timestep
101 real invdt_;
102 //! Number of flexible constraints
103 int nflexcon_ = 0;
104 //! Whether the virial should be computed
105 bool computeVirial_;
106 //! Scaled virial
107 tensor virialScaled_;
108 //! Scaled virial (reference values)
109 tensor virialScaledRef_;
110 //! If the free energy is computed
111 bool compute_dHdLambda_;
112 //! For free energy computation
113 real dHdLambda_;
114 //! For free energy computation (reference value)
115 real dHdLambdaRef_;
117 //! Coordinates before the timestep
118 PaddedVector<RVec> x_;
119 //! Coordinates after timestep, output for the constraints
120 PaddedVector<RVec> xPrime_;
121 //! Backup for coordinates (for reset)
122 PaddedVector<RVec> xPrime0_;
123 //! Intermediate set of coordinates (normally used for projection correction)
124 PaddedVector<RVec> xPrime2_;
125 //! Velocities
126 PaddedVector<RVec> v_;
127 //! Backup for velocities (for reset)
128 PaddedVector<RVec> v0_;
130 //! Constraints data (type1-i1-j1-type2-i2-j2-...)
131 std::vector<int> constraints_;
132 //! Target lengths for all constraint types
133 std::vector<real> constraintsR0_;
135 /*! \brief
136 * Constructor for the object with all parameters and variables needed by constraints algorithms.
138 * This constructor assembles stubs for all the data structures, required to initialize
139 * and apply LINCS and SHAKE constraints. The coordinates and velocities before constraining
140 * are saved to allow for reset. The constraints data are stored for testing after constraints
141 * were applied.
143 * \param[in] title Human-friendly name of the system.
144 * \param[in] numAtoms Number of atoms in the system.
145 * \param[in] masses Atom masses. Size of this vector should be equal to numAtoms.
146 * \param[in] constraints List of constraints, organized in triples of integers.
147 * First integer is the index of type for a constraint, second
148 * and third are the indices of constrained atoms. The types
149 * of constraints should be sequential but not necessarily
150 * start from zero (which is the way they normally are in
151 * GROMACS).
152 * \param[in] constraintsR0 Target values for bond lengths for bonds of each type. The
153 * size of this vector should be equal to the total number of
154 * unique types in constraints vector.
155 * \param[in] computeVirial Whether the virial should be computed.
156 * \param[in] virialScaledRef Reference values for scaled virial tensor.
157 * \param[in] compute_dHdLambda Whether free energy should be computed.
158 * \param[in] dHdLambdaRef Reference value for dHdLambda.
159 * \param[in] initialTime Initial time.
160 * \param[in] timestep Timestep.
161 * \param[in] x Coordinates before integration step.
162 * \param[in] xPrime Coordinates after integration step, but before constraining.
163 * \param[in] v Velocities before constraining.
164 * \param[in] shakeTolerance Target tolerance for SHAKE.
165 * \param[in] shakeUseSOR Use successive over-relaxation method for SHAKE iterations.
166 * The general formula is:
167 * x_n+1 = (1-omega)*x_n + omega*f(x_n),
168 * where omega = 1 if SOR is off and may be < 1 if SOR is on.
169 * \param[in] lincsNumIterations Number of iterations used to compute the inverse matrix.
170 * \param[in] lincsExpansionOrder The order for algorithm that adjusts the direction of the
171 * bond after constraints are applied.
172 * \param[in] lincsWarnAngle The threshold value for the change in bond angle. When
173 * exceeded the program will issue a warning.
176 ConstraintsTestData(const std::string& title,
177 int numAtoms,
178 std::vector<real> masses,
179 std::vector<int> constraints,
180 std::vector<real> constraintsR0,
181 bool computeVirial,
182 tensor virialScaledRef,
183 bool compute_dHdLambda,
184 float dHdLambdaRef,
185 real initialTime,
186 real timestep,
187 const std::vector<RVec>& x,
188 const std::vector<RVec>& xPrime,
189 const std::vector<RVec>& v,
190 real shakeTolerance,
191 gmx_bool shakeUseSOR,
192 int lincsNumIterations,
193 int lincsExpansionOrder,
194 real lincsWarnAngle);
196 /*! \brief
197 * Reset the data structure so it can be reused.
199 * Set the coordinates and velocities back to their values before
200 * constraining. The scaled virial tensor and dHdLambda are zeroed.
203 void reset();
206 } // namespace test
207 } // namespace gmx
209 #endif // GMX_MDLIB_TESTS_CONSTRTESTDATA_H