2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team.
6 * Copyright (c) 2013,2014,2015,2016,2017 by the GROMACS development team.
7 * Copyright (c) 2018,2019,2020,2021, by the GROMACS development team, led by
8 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
9 * and including many others, as listed in the AUTHORS file in the
10 * top-level source directory and at http://www.gromacs.org.
12 * GROMACS is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 2.1
15 * of the License, or (at your option) any later version.
17 * GROMACS is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with GROMACS; if not, see
24 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * If you want to redistribute modifications to GROMACS, please
28 * consider that scientific software is very special. Version
29 * control is crucial - bugs must be traceable. We will be happy to
30 * consider code for inclusion in the official distribution, but
31 * derived work must not be called official GROMACS. Details are found
32 * in the README & COPYING files - if they are missing, get the
33 * official version at http://www.gromacs.org.
35 * To help us fund GROMACS development, we humbly ask that you cite
36 * the research papers on the package. Check out http://www.gromacs.org.
38 #ifndef GMX_MDLIB_UPDATE_H
39 #define GMX_MDLIB_UPDATE_H
43 #include "gromacs/math/paddedvector.h"
44 #include "gromacs/math/vectypes.h"
45 #include "gromacs/mdtypes/md_enums.h"
46 #include "gromacs/timing/wallcycle.h"
47 #include "gromacs/utility/arrayref.h"
48 #include "gromacs/utility/basedefinitions.h"
49 #include "gromacs/utility/real.h"
53 struct gmx_enerdata_t;
70 * \brief Contains data for update phase */
74 /*! \brief Constructor
76 * \param[in] inputRecord Input record, used to construct SD object.
77 * \param[in] boxDeformation Periodic box deformation object.
79 Update(const t_inputrec& inputRecord, BoxDeformation* boxDeformation);
82 /*! \brief Get the pointer to updated coordinates
84 * Update saves the updated coordinates into separate buffer, so that constraints will have
85 * access to both updated and not update coordinates. For that, update owns a separate buffer.
86 * See finish_update(...) for details.
88 * \returns The pointer to the intermediate coordinates buffer.
90 PaddedVector<gmx::RVec>* xp();
91 /*!\brief Getter to local copy of box deformation class.
93 * \returns handle to box deformation class
95 BoxDeformation* deform() const;
96 /*! \brief Sets data that changes only at domain decomposition time.
98 * \param[in] numAtoms Updated number of atoms.
99 * \param[in] cFREEZE Group index for freezing
100 * \param[in] cTC Group index for center of mass motion removal
102 void updateAfterPartition(int numAtoms,
103 gmx::ArrayRef<const unsigned short> cFREEZE,
104 gmx::ArrayRef<const unsigned short> cTC);
106 /*! \brief Perform numerical integration step.
108 * Selects the appropriate integrator, based on the input record and performs a numerical integration step.
110 * \param[in] inputRecord Input record.
111 * \param[in] step Current timestep.
112 * \param[in] md MD atoms data.
113 * \param[in] state System state object.
114 * \param[in] f Buffer with atomic forces for home particles.
115 * \param[in] fcdata Force calculation data to update distance and orientation restraints.
116 * \param[in] ekind Kinetic energy data (for temperature coupling, energy groups, etc.).
117 * \param[in] M Parrinello-Rahman velocity scaling matrix.
118 * \param[in] updatePart What should be updated, coordinates or velocities. This enum only used in VV integrator.
119 * \param[in] cr Comunication record (Old comment: these shouldn't be here -- need to think about it).
120 * \param[in] haveConstraints If the system has constraints.
122 void update_coords(const t_inputrec& inputRecord,
126 const gmx::ArrayRefWithPadding<const gmx::RVec>& f,
127 const t_fcdata& fcdata,
128 const gmx_ekindata_t* ekind,
132 bool haveConstraints);
134 /*! \brief Finalize the coordinate update.
136 * Copy the updated coordinates to the main coordinates buffer for the atoms that are not frozen.
138 * \param[in] inputRecord Input record.
139 * \param[in] md MD atoms data.
140 * \param[in] state System state object.
141 * \param[in] wcycle Wall-clock cycle counter.
142 * \param[in] haveConstraints If the system has constraints.
144 void finish_update(const t_inputrec& inputRecord,
147 gmx_wallcycle_t wcycle,
148 bool haveConstraints);
150 /*! \brief Secong part of the SD integrator.
152 * The first part of integration is performed in the update_coords(...) method.
154 * \param[in] inputRecord Input record.
155 * \param[in] step Current timestep.
156 * \param[in] dvdlambda Free energy derivative. Contribution to be added to
157 * the bonded interactions.
158 * \param[in] md MD atoms data.
159 * \param[in] state System state object.
160 * \param[in] cr Comunication record.
161 * \param[in] nrnb Cycle counters.
162 * \param[in] wcycle Wall-clock cycle counter.
163 * \param[in] constr Constraints object. The constraints are applied
164 * on coordinates after update.
165 * \param[in] do_log If this is logging step.
166 * \param[in] do_ene If this is an energy evaluation step.
168 void update_sd_second_half(const t_inputrec& inputRecord,
175 gmx_wallcycle_t wcycle,
176 gmx::Constraints* constr,
180 /*! \brief Performs a leap-frog update without updating \p state so the constrain virial
183 void update_for_constraint_virial(const t_inputrec& inputRecord,
185 const t_state& state,
186 const gmx::ArrayRefWithPadding<const gmx::RVec>& f,
187 const gmx_ekindata_t& ekind);
189 /*! \brief Update pre-computed constants that depend on the reference temperature for coupling.
191 * This could change e.g. in simulated annealing.
193 * \param[in] inputRecord Input record.
195 void update_temperature_constants(const t_inputrec& inputRecord);
197 /*!\brief Getter for the list of the randomize groups.
199 * Needed for Andersen temperature control.
201 * \returns Reference to the groups from the SD data object.
203 const std::vector<bool>& getAndersenRandomizeGroup() const;
204 /*!\brief Getter for the list of the Boltzmann factors.
206 * Needed for Andersen temperature control.
208 * \returns Reference to the Boltzmann factors from the SD data object.
210 const std::vector<real>& getBoltzmanFactor() const;
213 //! Implementation type.
215 //! Implementation object.
216 std::unique_ptr<Impl> impl_;
222 * Compute the partial kinetic energy for home particles;
223 * will be accumulated in the calling routine.
226 * Ekin = SUM(i) 0.5 m[i] v[i] (x) v[i]
228 * use v[i] = v[i] - u[i] when calculating temperature
230 * u must be accumulated already.
232 * Now also computes the contribution of the kinetic energy to the
238 void init_ekinstate(ekinstate_t* ekinstate, const t_inputrec* ir);
240 void update_ekinstate(ekinstate_t* ekinstate, const gmx_ekindata_t* ekind);
242 /*! \brief Restores data from \p ekinstate to \p ekind, then broadcasts it
243 to the rest of the simulation */
244 void restore_ekinstate_from_state(const t_commrec* cr, gmx_ekindata_t* ekind, const ekinstate_t* ekinstate);
246 /*! \brief Computes the atom range for a thread to operate on, ensuring SIMD aligned ranges
248 * \param[in] numThreads The number of threads to divide atoms over
249 * \param[in] threadIndex The thread to get the range for
250 * \param[in] numAtoms The total number of atoms (on this rank)
251 * \param[out] startAtom The start of the atom range
252 * \param[out] endAtom The end of the atom range, note that this is in general not a multiple of the SIMD width
254 void getThreadAtomRange(int numThreads, int threadIndex, int numAtoms, int* startAtom, int* endAtom);