enable GPU sharing among tMPI ranks
[alexxy/gromacs.git] / include / force.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  * check out http://www.gromacs.org for more information.
7  * Copyright (c) 2012,2013, by the GROMACS development team, led by
8  * David van der Spoel, Berk Hess, Erik Lindahl, and including many
9  * others, as listed in the AUTHORS file in the top-level source
10  * directory and at http://www.gromacs.org.
11  *
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.
16  *
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.
21  *
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.
26  *
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.
34  *
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.
37  */
38
39 #ifndef _force_h
40 #define _force_h
41
42 #include "visibility.h"
43 #include "typedefs.h"
44 #include "types/force_flags.h"
45 #include "pbc.h"
46 #include "network.h"
47 #include "tgroup.h"
48 #include "vsite.h"
49 #include "genborn.h"
50
51
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55
56 static const char *sepdvdlformat = "  %-30s V %12.5e  dVdl %12.5e\n";
57
58 void calc_vir(FILE *fplog, int nxf, rvec x[], rvec f[], tensor vir,
59               gmx_bool bScrewPBC, matrix box);
60 /* Calculate virial for nxf atoms, and add it to vir */
61
62 void f_calc_vir(FILE *fplog, int i0, int i1, rvec x[], rvec f[], tensor vir,
63                 t_graph *g, rvec shift_vec[]);
64 /* Calculate virial taking periodicity into account */
65
66 real RF_excl_correction(FILE *fplog,
67                         const t_forcerec *fr, t_graph *g,
68                         const t_mdatoms *mdatoms, const t_blocka *excl,
69                         rvec x[], rvec f[], rvec *fshift, const t_pbc *pbc,
70                         real lambda, real *dvdlambda);
71 /* Calculate the reaction-field energy correction for this node:
72  * epsfac q_i q_j (k_rf r_ij^2 - c_rf)
73  * and force correction for all excluded pairs, including self pairs.
74  */
75
76 void calc_rffac(FILE *fplog, int eel, real eps_r, real eps_rf,
77                 real Rc, real Temp,
78                 real zsq, matrix box,
79                 real *kappa, real *krf, real *crf);
80 /* Determine the reaction-field constants */
81
82 void init_generalized_rf(FILE *fplog,
83                          const gmx_mtop_t *mtop, const t_inputrec *ir,
84                          t_forcerec *fr);
85 /* Initialize the generalized reaction field parameters */
86
87
88 /* In wall.c */
89 void make_wall_tables(FILE *fplog, const output_env_t oenv,
90                       const t_inputrec *ir, const char *tabfn,
91                       const gmx_groups_t *groups,
92                       t_forcerec *fr);
93
94 real do_walls(t_inputrec *ir, t_forcerec *fr, matrix box, t_mdatoms *md,
95               rvec x[], rvec f[], real lambda, real Vlj[], t_nrnb *nrnb);
96
97 GMX_LIBMD_EXPORT
98 t_forcerec *mk_forcerec(void);
99
100 #define GMX_MAKETABLES_FORCEUSER  (1<<0)
101 #define GMX_MAKETABLES_14ONLY     (1<<1)
102
103 t_forcetable make_tables(FILE *fp, const output_env_t oenv,
104                          const t_forcerec *fr, gmx_bool bVerbose,
105                          const char *fn, real rtab, int flags);
106 /* Return tables for inner loops. When bVerbose the tables are printed
107  * to .xvg files
108  */
109
110 bondedtable_t make_bonded_table(FILE *fplog, char *fn, int angle);
111 /* Return a table for bonded interactions,
112  * angle should be: bonds 0, angles 1, dihedrals 2
113  */
114
115 /* Return a table for GB calculations */
116 t_forcetable make_gb_table(FILE *out, const output_env_t oenv,
117                            const t_forcerec *fr,
118                            const char *fn,
119                            real rtab);
120
121 /* Read a table for AdResS Thermo Force calculations */
122 extern t_forcetable make_atf_table(FILE *out, const output_env_t oenv,
123                                    const t_forcerec *fr,
124                                    const char *fn,
125                                    matrix box);
126
127 GMX_LIBMD_EXPORT
128 void pr_forcerec(FILE *fplog, t_forcerec *fr, t_commrec *cr);
129
130 void
131 forcerec_set_ranges(t_forcerec *fr,
132                     int ncg_home, int ncg_force,
133                     int natoms_force,
134                     int natoms_force_constr, int natoms_f_novirsum);
135 /* Set the number of cg's and atoms for the force calculation */
136
137 GMX_LIBMD_EXPORT
138 gmx_bool can_use_allvsall(const t_inputrec *ir, const gmx_mtop_t *mtop,
139                           gmx_bool bPrintNote, t_commrec *cr, FILE *fp);
140 /* Returns if we can use all-vs-all loops.
141  * If bPrintNote==TRUE, prints a note, if necessary, to stderr
142  * and fp (if !=NULL) on the master node.
143  */
144
145 GMX_LIBMD_EXPORT
146 gmx_bool uses_simple_tables(int                 cutoff_scheme,
147                             nonbonded_verlet_t *nbv,
148                             int                 group);
149 /* Returns whether simple tables (i.e. not for use with GPUs) are used
150  * with the type of kernel indicated.
151  */
152
153 GMX_LIBMD_EXPORT
154 void init_interaction_const_tables(FILE                *fp,
155                                    interaction_const_t *ic,
156                                    gmx_bool             bSimpleTable,
157                                    real                 rtab);
158 /* Initializes the tables in the interaction constant data structure.
159  * Setting verlet_kernel_type to -1 always initializes tables for
160  * use with group kernels.
161  */
162
163 GMX_LIBMD_EXPORT
164 void init_forcerec(FILE              *fplog,
165                    const output_env_t oenv,
166                    t_forcerec        *fr,
167                    t_fcdata          *fcd,
168                    const t_inputrec  *ir,
169                    const gmx_mtop_t  *mtop,
170                    const t_commrec   *cr,
171                    matrix             box,
172                    gmx_bool           bMolEpot,
173                    const char        *tabfn,
174                    const char        *tabafn,
175                    const char        *tabpfn,
176                    const char        *tabbfn,
177                    const char        *nbpu_opt,
178                    gmx_bool           bNoSolvOpt,
179                    real               print_force);
180 /* The Force rec struct must be created with mk_forcerec
181  * The gmx_booleans have the following meaning:
182  * bSetQ:    Copy the charges [ only necessary when they change ]
183  * bMolEpot: Use the free energy stuff per molecule
184  * print_force >= 0: print forces for atoms with force >= print_force
185  */
186
187 GMX_LIBMD_EXPORT
188 void forcerec_set_excl_load(t_forcerec *fr,
189                             const gmx_localtop_t *top, const t_commrec *cr);
190 /* Set the exclusion load for the local exclusions and possibly threads */
191
192 GMX_LIBMD_EXPORT
193 void init_enerdata(int ngener, int n_lambda, gmx_enerdata_t *enerd);
194 /* Intializes the energy storage struct */
195
196 void destroy_enerdata(gmx_enerdata_t *enerd);
197 /* Free all memory associated with enerd */
198
199 void reset_foreign_enerdata(gmx_enerdata_t *enerd);
200 /* Resets only the foreign energy data */
201
202 void reset_enerdata(t_grpopts *opts,
203                     t_forcerec *fr, gmx_bool bNS,
204                     gmx_enerdata_t *enerd,
205                     gmx_bool bMaster);
206 /* Resets the energy data, if bNS=TRUE also zeros the long-range part */
207
208 void sum_epot(t_grpopts *opts, gmx_grppairener_t *grpp, real *epot);
209 /* Locally sum the non-bonded potential energy terms */
210
211 GMX_LIBMD_EXPORT
212 void sum_dhdl(gmx_enerdata_t *enerd, real *lambda, t_lambda *fepvals);
213 /* Sum the free energy contributions */
214
215 void update_forcerec(FILE *fplog, t_forcerec *fr, matrix box);
216 /* Updates parameters in the forcerec that are time dependent */
217
218 /* Compute the average C6 and C12 params for LJ corrections */
219 void set_avcsixtwelve(FILE *fplog, t_forcerec *fr,
220                       const gmx_mtop_t *mtop);
221
222 GMX_LIBMD_EXPORT
223 extern void do_force(FILE *log, t_commrec *cr,
224                      t_inputrec *inputrec,
225                      gmx_large_int_t step, t_nrnb *nrnb, gmx_wallcycle_t wcycle,
226                      gmx_localtop_t *top,
227                      gmx_mtop_t *mtop,
228                      gmx_groups_t *groups,
229                      matrix box, rvec x[], history_t *hist,
230                      rvec f[],
231                      tensor vir_force,
232                      t_mdatoms *mdatoms,
233                      gmx_enerdata_t *enerd, t_fcdata *fcd,
234                      real *lambda, t_graph *graph,
235                      t_forcerec *fr,
236                      gmx_vsite_t *vsite, rvec mu_tot,
237                      double t, FILE *field, gmx_edsam_t ed,
238                      gmx_bool bBornRadii,
239                      int flags);
240
241 /* Communicate coordinates (if parallel).
242  * Do neighbor searching (if necessary).
243  * Calculate forces.
244  * Communicate forces (if parallel).
245  * Spread forces for vsites (if present).
246  *
247  * f is always required.
248  */
249
250 GMX_LIBMD_EXPORT
251 void ns(FILE              *fplog,
252         t_forcerec        *fr,
253         rvec               x[],
254         matrix             box,
255         gmx_groups_t      *groups,
256         t_grpopts         *opts,
257         gmx_localtop_t    *top,
258         t_mdatoms         *md,
259         t_commrec         *cr,
260         t_nrnb            *nrnb,
261         real              *lambda,
262         real              *dvdlambda,
263         gmx_grppairener_t *grppener,
264         gmx_bool           bFillGrid,
265         gmx_bool           bDoLongRangeNS);
266 /* Call the neighborsearcher */
267
268 extern void do_force_lowlevel(FILE         *fplog,
269                               gmx_large_int_t   step,
270                               t_forcerec   *fr,
271                               t_inputrec   *ir,
272                               t_idef       *idef,
273                               t_commrec    *cr,
274                               t_nrnb       *nrnb,
275                               gmx_wallcycle_t wcycle,
276                               t_mdatoms    *md,
277                               t_grpopts    *opts,
278                               rvec         x[],
279                               history_t    *hist,
280                               rvec         f_shortrange[],
281                               rvec         f_longrange[],
282                               gmx_enerdata_t *enerd,
283                               t_fcdata     *fcd,
284                               gmx_mtop_t     *mtop,
285                               gmx_localtop_t *top,
286                               gmx_genborn_t *born,
287                               t_atomtypes  *atype,
288                               gmx_bool         bBornRadii,
289                               matrix       box,
290                               t_lambda     *fepvals,
291                               real         *lambda,
292                               t_graph      *graph,
293                               t_blocka     *excl,
294                               rvec         mu_tot[2],
295                               int          flags,
296                               float        *cycles_pme);
297 /* Call all the force routines */
298
299 #ifdef __cplusplus
300 }
301 #endif
302
303 #endif  /* _force_h */