Merge branch 'release-4-6' into release-5-0
[alexxy/gromacs.git] / src / gromacs / legacyheaders / pme.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 _pme_h
39 #define _pme_h
40
41 #include <stdio.h>
42 #include "typedefs.h"
43 #include "../math/gmxcomplex.h"
44 #include "../timing/walltime_accounting.h"
45 #include "../legacyheaders/network.h"
46
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50
51 typedef real *splinevec[DIM];
52
53 enum {
54     GMX_SUM_GRID_FORWARD, GMX_SUM_GRID_BACKWARD
55 };
56
57 int gmx_pme_init(gmx_pme_t *pmedata, t_commrec *cr,
58                  int nnodes_major, int nnodes_minor,
59                  t_inputrec *ir, int homenr,
60                  gmx_bool bFreeEnergy_q, gmx_bool bFreeEnergy_lj,
61                  gmx_bool bReproducible, int nthread);
62 /* Initialize the pme data structures resepectively.
63  * Return value 0 indicates all well, non zero is an error code.
64  */
65
66 int gmx_pme_reinit(gmx_pme_t *         pmedata,
67                    t_commrec *         cr,
68                    gmx_pme_t           pme_src,
69                    const t_inputrec *  ir,
70                    ivec                grid_size);
71 /* As gmx_pme_init, but takes most settings, except the grid, from pme_src */
72
73 int gmx_pme_destroy(FILE *log, gmx_pme_t *pmedata);
74 /* Destroy the pme data structures resepectively.
75  * Return value 0 indicates all well, non zero is an error code.
76  */
77
78 #define GMX_PME_SPREAD        (1<<0)
79 #define GMX_PME_SOLVE         (1<<1)
80 #define GMX_PME_CALC_F        (1<<2)
81 #define GMX_PME_CALC_ENER_VIR (1<<3)
82 /* This forces the grid to be backtransformed even without GMX_PME_CALC_F */
83 #define GMX_PME_CALC_POT      (1<<4)
84
85 /* These values label bits used for sending messages to PME nodes using the
86  * routines in pme_pp.c and shouldn't conflict with the flags used there
87  */
88 #define GMX_PME_DO_COULOMB    (1<<13)
89 #define GMX_PME_DO_LJ         (1<<14)
90
91 #define GMX_PME_DO_ALL_F  (GMX_PME_SPREAD | GMX_PME_SOLVE | GMX_PME_CALC_F)
92
93 int gmx_pme_do(gmx_pme_t pme,
94                int start,       int homenr,
95                rvec x[],        rvec f[],
96                real chargeA[],  real chargeB[],
97                real c6A[],      real c6B[],
98                real sigmaA[],   real sigmaB[],
99                matrix box,      t_commrec *cr,
100                int  maxshift_x, int maxshift_y,
101                t_nrnb *nrnb,    gmx_wallcycle_t wcycle,
102                matrix vir_q,    real ewaldcoeff_q,
103                matrix vir_lj,   real ewaldcoeff_lj,
104                real *energy_q,  real *energy_lj,
105                real lambda_q, real lambda_lj,
106                real *dvdlambda_q, real *dvdlambda_lj,
107                int flags);
108 /* Do a PME calculation for the long range electrostatics and/or LJ.
109  * flags, defined above, determine which parts of the calculation are performed.
110  * Return value 0 indicates all well, non zero is an error code.
111  */
112
113 int gmx_pmeonly(gmx_pme_t pme,
114                 t_commrec *cr,     t_nrnb *mynrnb,
115                 gmx_wallcycle_t wcycle,
116                 gmx_walltime_accounting_t walltime_accounting,
117                 real ewaldcoeff_q, real ewaldcoeff_lj,
118                 t_inputrec *ir);
119 /* Called on the nodes that do PME exclusively (as slaves)
120  */
121
122 void gmx_pme_calc_energy(gmx_pme_t pme, int n, rvec *x, real *q, real *V);
123 /* Calculate the PME grid energy V for n charges with a potential
124  * in the pme struct determined before with a call to gmx_pme_do
125  * with at least GMX_PME_SPREAD and GMX_PME_SOLVE specified.
126  * Note that the charges are not spread on the grid in the pme struct.
127  * Currently does not work in parallel or with free energy.
128  */
129
130 /* The following three routines are for PME/PP node splitting in pme_pp.c */
131
132 /* Abstract type for PME <-> PP communication */
133 typedef struct gmx_pme_pp *gmx_pme_pp_t;
134
135 void gmx_pme_check_restrictions(int pme_order,
136                                 int nkx, int nky, int nkz,
137                                 int nnodes_major,
138                                 int nnodes_minor,
139                                 gmx_bool bUseThreads,
140                                 gmx_bool bFatal,
141                                 gmx_bool *bValidSettings);
142 /* Check restrictions on pme_order and the PME grid nkx,nky,nkz.
143  * With bFatal=TRUE, a fatal error is generated on violation,
144  * bValidSettings=NULL can be passed.
145  * With bFatal=FALSE, *bValidSettings reports the validity of the settings.
146  * bUseThreads tells if any MPI rank doing PME uses more than 1 threads.
147  * If at calling you bUseThreads is unknown, pass TRUE for conservative
148  * checking.
149  */
150
151 gmx_pme_pp_t gmx_pme_pp_init(t_commrec *cr);
152 /* Initialize the PME-only side of the PME <-> PP communication */
153
154 void gmx_pme_send_parameters(t_commrec *cr,
155                              gmx_bool bFreeEnergy_q, gmx_bool bFreeEnergy_lj,
156                              real *chargeA, real *chargeB,
157                              real *sqrt_c6A, real *sqrt_c6B,
158                              real *sigmaA, real *sigmaB,
159                              int maxshift_x, int maxshift_y);
160 /* Send the charges and maxshift to out PME-only node. */
161
162 void gmx_pme_send_coordinates(t_commrec *cr, matrix box, rvec *x,
163                               gmx_bool bFreeEnergy_q, gmx_bool bFreeEnergy_lj,
164                               real lambda_q, real lambda_lj,
165                               gmx_bool bEnerVir, int pme_flags,
166                               gmx_int64_t step);
167 /* Send the coordinates to our PME-only node and request a PME calculation */
168
169 void gmx_pme_send_finish(t_commrec *cr);
170 /* Tell our PME-only node to finish */
171
172 void gmx_pme_send_switchgrid(t_commrec *cr, ivec grid_size, real ewaldcoeff_q, real ewaldcoeff_lj);
173 /* Tell our PME-only node to switch to a new grid size */
174
175 void gmx_pme_send_resetcounters(t_commrec *cr, gmx_int64_t step);
176 /* Tell our PME-only node to reset all cycle and flop counters */
177
178 void gmx_pme_receive_f(t_commrec *cr,
179                        rvec f[], matrix vir_q, real *energy_q,
180                        matrix vir_lj, real *energy_lj,
181                        real *dvdlambda_q, real *dvdlambda_lj,
182                        float *pme_cycles);
183 /* PP nodes receive the long range forces from the PME nodes */
184
185 /* Return values for gmx_pme_recv_q_x */
186 enum {
187     pmerecvqxX,            /* calculate PME mesh interactions for new x    */
188     pmerecvqxFINISH,       /* the simulation should finish, we should quit */
189     pmerecvqxSWITCHGRID,   /* change the PME grid size                     */
190     pmerecvqxRESETCOUNTERS /* reset the cycle and flop counters            */
191 };
192
193 int gmx_pme_recv_coeffs_coords(gmx_pme_pp_t pme_pp,
194                                int *natoms,
195                                real **chargeA, real **chargeB,
196                                real **sqrt_c6A, real **sqrt_c6B,
197                                real **sigmaA, real **sigmaB,
198                                matrix box, rvec **x, rvec **f,
199                                int *maxshift_x, int *maxshift_y,
200                                gmx_bool *bFreeEnergy_q, gmx_bool *bFreeEnergy_lj,
201                                real *lambda_q, real *lambda_lj,
202                                gmx_bool *bEnerVir, int *pme_flags,
203                                gmx_int64_t *step,
204                                ivec grid_size, real *ewaldcoeff_q, real *ewaldcoeff_lj);
205 ;
206 /* With return value:
207  * pmerecvqxX:             all parameters set, chargeA and chargeB can be NULL
208  * pmerecvqxFINISH:        no parameters set
209  * pmerecvqxSWITCHGRID:    only grid_size and *ewaldcoeff are set
210  * pmerecvqxRESETCOUNTERS: *step is set
211  */
212
213 void gmx_pme_send_force_vir_ener(gmx_pme_pp_t pme_pp,
214                                  rvec *f, matrix vir_q, real energy_q,
215                                  matrix vir_lj, real energy_lj,
216                                  real dvdlambda_q, real dvdlambda_lj,
217                                  float cycles);
218 /* Send the PME mesh force, virial and energy to the PP-only nodes */
219
220 #ifdef __cplusplus
221 }
222 #endif
223
224 #endif