Add more const to uses of t_commrec and t_inputrec
[alexxy/gromacs.git] / src / gromacs / mdlib / update.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
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,2018, by the GROMACS development team, led by
7  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8  * and including many others, as listed in the AUTHORS file in the
9  * top-level source directory and at http://www.gromacs.org.
10  *
11  * GROMACS is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public License
13  * as published by the Free Software Foundation; either version 2.1
14  * of the License, or (at your option) any later version.
15  *
16  * GROMACS is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with GROMACS; if not, see
23  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
25  *
26  * If you want to redistribute modifications to GROMACS, please
27  * consider that scientific software is very special. Version
28  * control is crucial - bugs must be traceable. We will be happy to
29  * consider code for inclusion in the official distribution, but
30  * derived work must not be called official GROMACS. Details are found
31  * in the README & COPYING files - if they are missing, get the
32  * official version at http://www.gromacs.org.
33  *
34  * To help us fund GROMACS development, we humbly ask that you cite
35  * the research papers on the package. Check out http://www.gromacs.org.
36  */
37 #ifndef GMX_MDLIB_UPDATE_H
38 #define GMX_MDLIB_UPDATE_H
39
40 #include "gromacs/math/paddedvector.h"
41 #include "gromacs/math/vectypes.h"
42 #include "gromacs/timing/wallcycle.h"
43 #include "gromacs/utility/arrayref.h"
44 #include "gromacs/utility/basedefinitions.h"
45 #include "gromacs/utility/real.h"
46
47 class ekinstate_t;
48 struct gmx_constr;
49 struct gmx_ekindata_t;
50 struct gmx_enerdata_t;
51 struct gmx_multisim_t;
52 struct t_extmass;
53 struct t_fcdata;
54 struct t_graph;
55 struct t_grpopts;
56 struct t_idef;
57 struct t_inputrec;
58 struct t_mdatoms;
59 struct t_nrnb;
60 class t_state;
61
62 /* Abstract type for update */
63 struct gmx_update_t;
64
65 /* Initialize the stochastic dynamics struct */
66 gmx_update_t *init_update(const t_inputrec *ir);
67
68 /* Update pre-computed constants that depend on the reference
69  * temperature for coupling.
70  *
71  * This could change e.g. in simulated annealing. */
72 void update_temperature_constants(gmx_update_t *upd, const t_inputrec *ir);
73
74 /* Update the size of per-atom arrays (e.g. after DD re-partitioning,
75    which might increase the number of home atoms). */
76 void update_realloc(gmx_update_t *upd, int natoms);
77
78 /* Store the box at step step
79  * as a reference state for simulations with box deformation.
80  */
81 void set_deform_reference_box(gmx_update_t *upd,
82                               gmx_int64_t step, matrix box);
83
84 void update_tcouple(gmx_int64_t       step,
85                     t_inputrec       *inputrec,
86                     t_state          *state,
87                     gmx_ekindata_t   *ekind,
88                     t_extmass        *MassQ,
89                     t_mdatoms        *md
90                     );
91
92 /* Update Parrinello-Rahman, to be called before the coordinate update */
93 void update_pcouple_before_coordinates(FILE             *fplog,
94                                        gmx_int64_t       step,
95                                        const t_inputrec *inputrec,
96                                        t_state          *state,
97                                        matrix            parrinellorahmanMu,
98                                        matrix            M,
99                                        gmx_bool          bInitStep);
100
101 /* Update the box, to be called after the coordinate update.
102  * For Berendsen P-coupling, also calculates the scaling factor
103  * and scales the coordinates.
104  * When the deform option is used, scales coordinates and box here.
105  */
106 void update_pcouple_after_coordinates(FILE             *fplog,
107                                       gmx_int64_t       step,
108                                       const t_inputrec *inputrec,
109                                       const t_mdatoms  *md,
110                                       const matrix      pressure,
111                                       const matrix      forceVirial,
112                                       const matrix      constraintVirial,
113                                       const matrix      parrinellorahmanMu,
114                                       t_state          *state,
115                                       t_nrnb           *nrnb,
116                                       gmx_update_t     *upd);
117
118 void update_coords(FILE                          *fplog,
119                    gmx_int64_t                    step,
120                    t_inputrec                    *inputrec, /* input record and box stuff       */
121                    t_mdatoms                     *md,
122                    t_state                       *state,
123                    gmx::PaddedArrayRef<gmx::RVec> f, /* forces on home particles */
124                    t_fcdata                      *fcd,
125                    gmx_ekindata_t                *ekind,
126                    matrix                         M,
127                    gmx_update_t                  *upd,
128                    int                            bUpdatePart,
129                    const t_commrec               *cr, /* these shouldn't be here -- need to think about it */
130                    gmx_constr                    *constr);
131
132 /* Return TRUE if OK, FALSE in case of Shake Error */
133
134 extern gmx_bool update_randomize_velocities(t_inputrec *ir, gmx_int64_t step, const t_commrec *cr, t_mdatoms *md, t_state *state, gmx_update_t *upd, gmx_constr *constr);
135
136 void update_constraints(FILE                    *fplog,
137                         gmx_int64_t              step,
138                         real                    *dvdlambda, /* FEP stuff */
139                         const t_inputrec        *inputrec,  /* input record and box stuff       */
140                         t_mdatoms               *md,
141                         t_state                 *state,
142                         gmx_bool                 bMolPBC,
143                         t_graph                 *graph,
144                         gmx::ArrayRef<gmx::RVec> force, /* forces on home particles */
145                         t_idef                  *idef,
146                         tensor                   vir_part,
147                         const t_commrec         *cr,
148                         const gmx_multisim_t    *ms,
149                         t_nrnb                  *nrnb,
150                         gmx_wallcycle_t          wcycle,
151                         gmx_update_t            *upd,
152                         gmx_constr              *constr,
153                         gmx_bool                 bFirstHalf,
154                         gmx_bool                 bCalcVir);
155
156 /* Return TRUE if OK, FALSE in case of Shake Error */
157
158 void calc_ke_part(t_state *state, t_grpopts *opts, t_mdatoms *md,
159                   gmx_ekindata_t *ekind, t_nrnb *nrnb, gmx_bool bEkinAveVel);
160 /*
161  * Compute the partial kinetic energy for home particles;
162  * will be accumulated in the calling routine.
163  * The tensor is
164  *
165  * Ekin = SUM(i) 0.5 m[i] v[i] (x) v[i]
166  *
167  *     use v[i] = v[i] - u[i] when calculating temperature
168  *
169  * u must be accumulated already.
170  *
171  * Now also computes the contribution of the kinetic energy to the
172  * free energy
173  *
174  */
175
176
177 void
178 init_ekinstate(ekinstate_t *ekinstate, const t_inputrec *ir);
179
180 void
181 update_ekinstate(ekinstate_t *ekinstate, gmx_ekindata_t *ekind);
182
183 /*! \brief Restores data from \p ekinstate to \p ekind, then broadcasts it
184    to the rest of the simulation */
185 void
186 restore_ekinstate_from_state(const t_commrec *cr,
187                              gmx_ekindata_t *ekind, const ekinstate_t *ekinstate);
188
189 void berendsen_tcoupl(const t_inputrec *ir, const gmx_ekindata_t *ekind, real dt,
190                       std::vector<double> &therm_integral);
191
192 void andersen_tcoupl(t_inputrec *ir, gmx_int64_t step,
193                      const t_commrec *cr, const t_mdatoms *md, t_state *state, real rate, const gmx_bool *randomize, const real *boltzfac);
194
195 void nosehoover_tcoupl(t_grpopts *opts, gmx_ekindata_t *ekind, real dt,
196                        double xi[], double vxi[], t_extmass *MassQ);
197
198 void trotter_update(t_inputrec *ir, gmx_int64_t step, gmx_ekindata_t *ekind,
199                     gmx_enerdata_t *enerd, t_state *state, tensor vir, t_mdatoms *md,
200                     t_extmass *MassQ, int **trotter_seqlist, int trotter_seqno);
201
202 int **init_npt_vars(t_inputrec *ir, t_state *state, t_extmass *Mass, gmx_bool bTrotter);
203
204 real NPT_energy(const t_inputrec *ir, const t_state *state, const t_extmass *MassQ);
205 /* computes all the pressure/tempertature control energy terms to get a conserved energy */
206
207 void NBaroT_trotter(t_grpopts *opts, real dt,
208                     double xi[], double vxi[], real *veta, t_extmass *MassQ);
209
210 void vrescale_tcoupl(t_inputrec *ir, gmx_int64_t step,
211                      gmx_ekindata_t *ekind, real dt,
212                      double therm_integral[]);
213 /* Compute temperature scaling. For V-rescale it is done in update. */
214
215 void rescale_velocities(gmx_ekindata_t *ekind, t_mdatoms *mdatoms,
216                         int start, int end, rvec v[]);
217 /* Rescale the velocities with the scaling factor in ekind */
218
219 void update_annealing_target_temp(t_inputrec *ir, real t, gmx_update_t *upd);
220 /* Set reference temp for simulated annealing at time t*/
221
222 real calc_temp(real ekin, real nrdf);
223 /* Calculate the temperature */
224
225 real calc_pres(int ePBC, int nwall, matrix box, tensor ekin, tensor vir,
226                tensor pres);
227 /* Calculate the pressure tensor, returns the scalar pressure.
228  * The unit of pressure is bar.
229  */
230
231 void parrinellorahman_pcoupl(FILE *fplog, gmx_int64_t step,
232                              const t_inputrec *ir, real dt, const tensor pres,
233                              tensor box, tensor box_rel, tensor boxv,
234                              tensor M, matrix mu,
235                              gmx_bool bFirstStep);
236
237 void berendsen_pcoupl(FILE *fplog, gmx_int64_t step,
238                       const t_inputrec *ir, real dt,
239                       const tensor pres, const matrix box,
240                       const matrix force_vir, const matrix constraint_vir,
241                       matrix mu, double *baros_integral);
242
243 void berendsen_pscale(const t_inputrec *ir, const matrix mu,
244                       matrix box, matrix box_rel,
245                       int start, int nr_atoms,
246                       rvec x[], const unsigned short cFREEZE[],
247                       t_nrnb *nrnb);
248
249 void correct_ekin(FILE *log, int start, int end, rvec v[],
250                   rvec vcm, real mass[], real tmass, tensor ekin);
251 /* Correct ekin for vcm */
252
253 #endif