CUDA version of LINCS constraints.
[gromacs.git] / src / gromacs / mdlib / lincs_cuda.h
blobb3c8f0e165ef68c30621dd0563b4cc2126649596
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2019, 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 /*! \libinternal \file
37 * \brief Declaration of high-level functions of CUDA implementation of LINCS.
39 * \todo This should only list interfaces needed for libgromacs clients.
41 * \author Artem Zhmurov <zhmurov@gmail.com>
43 * \ingroup module_mdlib
44 * \inlibraryapi
46 #ifndef GMX_MDLIB_LINCS_CUDA_H
47 #define GMX_MDLIB_LINCS_CUDA_H
50 #include "gromacs/mdlib/constr.h"
51 #include "gromacs/mdtypes/mdatom.h"
52 #include "gromacs/topology/idef.h"
53 #include "gromacs/utility/classhelpers.h"
55 namespace gmx
58 class LincsCuda
61 public:
62 /*! \brief Constructor.
64 * \param[in] numAtoms Number of atoms
65 * \param[in] numIterations Number of iteration for the correction of the projection.
66 * \param[in] expansionOrder Order of the matrix inversion algorithm.
68 LincsCuda(int numAtoms,
69 int numIterations,
70 int expansionOrder);
71 ~LincsCuda();
73 /*! \brief Apply LINCS.
75 * Applies LINCS to coordinates and velocities, Method uses this class data structures
76 * which should be updated when needed using update method.
78 * \param[in] updateVelocities If the velocities should be constrained.
79 * \param[in] invdt Reciprocal timestep (to scale Lagrange
80 * multipliers when velocities are updated)
81 * \param[in] computeVirial If virial should be updated.
82 * \param[in,out] virialScaled Scaled virial tensor to be updated.
84 void apply(bool updateVelocities,
85 real invdt,
86 bool computeVirial,
87 tensor virialScaled);
89 /*! \brief
90 * Update data-structures (e.g. after NB search step).
92 * Updates the constraints data. Should be called if the particles were sorted,
93 * redistributed between domains, etc.
95 * Information about constraints should be taken from:
96 * idef.il[F_CONSTR].iatoms --- type (T) of constraint and two atom indexes (i1, i2)
97 * idef.iparams[T].constr.dA --- target length for constraint of type T
98 * From t_mdatom, the code should take:
99 * md.invmass --- array of inverse square root of masses for each atom in the system.
101 * \param[in] idef Local topology data to get information on constraints from.
102 * \param[in] md Atoms data to get atom masses from.
104 void set(const t_idef &idef,
105 const t_mdatoms &md);
107 /*! \brief
108 * Update PBC data.
110 * \param[in] pbc The PBC data in t_pbc format.
112 void setPbc(const t_pbc *pbc);
114 /*! \brief
115 * Copy coordinates from provided CPU location to GPU.
117 * Copies the coordinates before the integration step (x) and coordinates
118 * after the integration step (xp) from the provided CPU location to GPU.
119 * The data are assumed to be in float3/fvec format (single precision).
121 * \param[in] h_x CPU pointer where coordinates should be copied from.
122 * \param[in] h_xp CPU pointer where coordinates should be copied from.
124 void copyCoordinatesToGpu(const rvec *h_x, const rvec *h_xp);
126 /*! \brief
127 * Copy velocities from provided CPU location to GPU.
129 * Nothing is done if the argument provided is a nullptr.
130 * The data are assumed to be in float3/fvec format (single precision).
132 * \param[in] h_v CPU pointer where velocities should be copied from.
134 void copyVelocitiesToGpu(const rvec *h_v);
136 /*! \brief
137 * Copy coordinates from GPU to provided CPU location.
139 * Copies the constrained coordinates to the provided location. The coordinates
140 * are assumed to be in float3/fvec format (single precision).
142 * \param[out] h_xp CPU pointer where coordinates should be copied to.
144 void copyCoordinatesFromGpu(rvec *h_xp);
146 /*! \brief
147 * Copy velocities from GPU to provided CPU location.
149 * The velocities are assumed to be in float3/fvec format (single precision).
151 * \param[in] h_v Pointer to velocities data.
153 void copyVelocitiesFromGpu(rvec *h_v);
155 /*! \brief
156 * Set the internal GPU-memory x, xprime and v pointers.
158 * Data is not copied. The data are assumed to be in float3/fvec format
159 * (float3 is used internally, but the data layout should be identical).
161 * \param[in] d_x Pointer to the coordinates before integrator update (on GPU)
162 * \param[in] d_xp Pointer to the coordinates after integrator update, before update (on GPU)
163 * \param[in] d_v Pointer to the velocities before integrator update (on GPU)
165 void setXVPointers(rvec *d_x, rvec *d_xp, rvec *d_v);
167 private:
168 class Impl;
169 gmx::PrivateImplPointer<Impl> impl_;
173 } // namespace gmx
175 #endif