Create math module
[alexxy/gromacs.git] / src / gromacs / legacyheaders / 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, 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
38 #ifndef _update_h
39 #define _update_h
40
41 #include "typedefs.h"
42 #include "mshift.h"
43 #include "tgroup.h"
44 #include "network.h"
45 #include "pull.h"
46 #include "gmx_random.h"
47
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51
52 /* Abstract type for stochastic dynamics */
53 typedef struct gmx_update *gmx_update_t;
54
55 /* Initialize the stochastic dynamics struct */
56 gmx_update_t init_update(t_inputrec *ir);
57
58 /* Store the random state from sd in state */
59 void get_stochd_state(gmx_update_t sd, t_state *state);
60
61 /* Set the random in sd from state */
62 void set_stochd_state(gmx_update_t sd, t_state *state);
63
64 /* Store the box at step step
65  * as a reference state for simulations with box deformation.
66  */
67 void set_deform_reference_box(gmx_update_t upd,
68                               gmx_int64_t step, matrix box);
69
70 void update_tcouple(gmx_int64_t       step,
71                     t_inputrec       *inputrec,
72                     t_state          *state,
73                     gmx_ekindata_t   *ekind,
74                     gmx_update_t      upd,
75                     t_extmass        *MassQ,
76                     t_mdatoms        *md
77                     );
78
79 void update_pcouple(FILE             *fplog,
80                     gmx_int64_t       step,
81                     t_inputrec       *inputrec,
82                     t_state          *state,
83                     matrix            pcoupl_mu,
84                     matrix            M,
85                     gmx_bool          bInitStep);
86
87 void update_coords(FILE             *fplog,
88                    gmx_int64_t       step,
89                    t_inputrec       *inputrec, /* input record and box stuff    */
90                    t_mdatoms        *md,
91                    t_state          *state,
92                    gmx_bool          bMolPBC,
93                    rvec             *f, /* forces on home particles */
94                    gmx_bool          bDoLR,
95                    rvec             *f_lr,
96                    t_fcdata         *fcd,
97                    gmx_ekindata_t   *ekind,
98                    matrix            M,
99                    gmx_update_t      upd,
100                    gmx_bool          bInitStep,
101                    int               bUpdatePart,
102                    t_commrec        *cr, /* these shouldn't be here -- need to think about it */
103                    t_nrnb           *nrnb,
104                    gmx_constr_t      constr,
105                    t_idef           *idef);
106
107 /* Return TRUE if OK, FALSE in case of Shake Error */
108
109 extern gmx_bool update_randomize_velocities(t_inputrec *ir, gmx_int64_t step, t_mdatoms *md, t_state *state, gmx_update_t upd, t_idef *idef, gmx_constr_t constr);
110
111 void update_constraints(FILE             *fplog,
112                         gmx_int64_t       step,
113                         real             *dvdlambda, /* FEP stuff */
114                         t_inputrec       *inputrec,  /* input record and box stuff      */
115                         gmx_ekindata_t   *ekind,
116                         t_mdatoms        *md,
117                         t_state          *state,
118                         gmx_bool          bMolPBC,
119                         t_graph          *graph,
120                         rvec              force[], /* forces on home particles */
121                         t_idef           *idef,
122                         tensor            vir_part,
123                         t_commrec        *cr,
124                         t_nrnb           *nrnb,
125                         gmx_wallcycle_t   wcycle,
126                         gmx_update_t      upd,
127                         gmx_constr_t      constr,
128                         gmx_bool          bFirstHalf,
129                         gmx_bool          bCalcVir,
130                         real              vetanew);
131
132 /* Return TRUE if OK, FALSE in case of Shake Error */
133
134 void update_box(FILE             *fplog,
135                 gmx_int64_t       step,
136                 t_inputrec       *inputrec, /* input record and box stuff       */
137                 t_mdatoms        *md,
138                 t_state          *state,
139                 rvec              force[], /* forces on home particles */
140                 matrix           *scale_tot,
141                 matrix            pcoupl_mu,
142                 t_nrnb           *nrnb,
143                 gmx_update_t      upd);
144 /* Return TRUE if OK, FALSE in case of Shake Error */
145
146 void calc_ke_part(t_state *state, t_grpopts *opts, t_mdatoms *md,
147                   gmx_ekindata_t *ekind, t_nrnb *nrnb, gmx_bool bEkinAveVel, gmx_bool bSaveOld);
148 /*
149  * Compute the partial kinetic energy for home particles;
150  * will be accumulated in the calling routine.
151  * The tensor is
152  *
153  * Ekin = SUM(i) 0.5 m[i] v[i] (x) v[i]
154  *
155  *     use v[i] = v[i] - u[i] when calculating temperature
156  *
157  * u must be accumulated already.
158  *
159  * Now also computes the contribution of the kinetic energy to the
160  * free energy
161  *
162  */
163
164
165 void
166 init_ekinstate(ekinstate_t *ekinstate, const t_inputrec *ir);
167
168 void
169 update_ekinstate(ekinstate_t *ekinstate, gmx_ekindata_t *ekind);
170
171 void
172 restore_ekinstate_from_state(t_commrec *cr,
173                              gmx_ekindata_t *ekind, ekinstate_t *ekinstate);
174
175 void berendsen_tcoupl(t_inputrec *ir, gmx_ekindata_t *ekind, real dt);
176
177 void andersen_tcoupl(t_inputrec *ir, t_mdatoms *md, t_state *state, gmx_rng_t rng, real rate, t_idef *idef, int nblocks, int *sblock, gmx_bool *randatom, int *randatom_list, gmx_bool *randomize, real *boltzfac);
178
179 void nosehoover_tcoupl(t_grpopts *opts, gmx_ekindata_t *ekind, real dt,
180                        double xi[], double vxi[], t_extmass *MassQ);
181
182 t_state *init_bufstate(const t_state *template_state);
183
184 void destroy_bufstate(t_state *state);
185
186 void trotter_update(t_inputrec *ir, gmx_int64_t step, gmx_ekindata_t *ekind,
187                     gmx_enerdata_t *enerd, t_state *state, tensor vir, t_mdatoms *md,
188                     t_extmass *MassQ, int **trotter_seqlist, int trotter_seqno);
189
190 int **init_npt_vars(t_inputrec *ir, t_state *state, t_extmass *Mass, gmx_bool bTrotter);
191
192 real NPT_energy(t_inputrec *ir, t_state *state, t_extmass *MassQ);
193 /* computes all the pressure/tempertature control energy terms to get a conserved energy */
194
195 void NBaroT_trotter(t_grpopts *opts, real dt,
196                     double xi[], double vxi[], real *veta, t_extmass *MassQ);
197
198 void vrescale_tcoupl(t_inputrec *ir, gmx_ekindata_t *ekind, real dt,
199                      double therm_integral[],
200                      gmx_rng_t rng);
201 /* Compute temperature scaling. For V-rescale it is done in update. */
202
203 real vrescale_energy(t_grpopts *opts, double therm_integral[]);
204 /* Returns the V-rescale contribution to the conserved energy */
205
206 void rescale_velocities(gmx_ekindata_t *ekind, t_mdatoms *mdatoms,
207                         int start, int end, rvec v[]);
208 /* Rescale the velocities with the scaling factor in ekind */
209
210 void update_annealing_target_temp(t_grpopts *opts, real t);
211 /* Set reference temp for simulated annealing at time t*/
212
213 real calc_temp(real ekin, real nrdf);
214 /* Calculate the temperature */
215
216 real calc_pres(int ePBC, int nwall, matrix box, tensor ekin, tensor vir,
217                tensor pres);
218 /* Calculate the pressure tensor, returns the scalar pressure.
219  * The unit of pressure is bar.
220  */
221
222 void parrinellorahman_pcoupl(FILE *fplog, gmx_int64_t step,
223                              t_inputrec *ir, real dt, tensor pres,
224                              tensor box, tensor box_rel, tensor boxv,
225                              tensor M, matrix mu,
226                              gmx_bool bFirstStep);
227
228 void berendsen_pcoupl(FILE *fplog, gmx_int64_t step,
229                       t_inputrec *ir, real dt, tensor pres, matrix box,
230                       matrix mu);
231
232
233 void berendsen_pscale(t_inputrec *ir, matrix mu,
234                       matrix box, matrix box_rel,
235                       int start, int nr_atoms,
236                       rvec x[], unsigned short cFREEZE[],
237                       t_nrnb *nrnb);
238
239 void correct_ekin(FILE *log, int start, int end, rvec v[],
240                   rvec vcm, real mass[], real tmass, tensor ekin);
241 /* Correct ekin for vcm */
242
243
244 #ifdef __cplusplus
245 }
246 #endif
247
248 #endif  /* _update_h */