2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
42 #include "gromacs/legacyheaders/typedefs.h"
43 #include "gromacs/legacyheaders/force.h"
44 #include "gromacs/legacyheaders/gmx_omp_nthreads.h"
46 #include "gromacs/math/vec.h"
47 #include "gromacs/pbcutil/ishift.h"
48 #include "gromacs/utility/smalloc.h"
50 #include "nbnxn_kernel_ref.h"
51 #include "../nbnxn_consts.h"
52 #include "nbnxn_kernel_common.h"
53 #include "gromacs/mdlib/nb_verlet.h"
55 /*! \brief Typedefs for declaring lookup tables of kernel functions.
58 typedef void (*p_nbk_func_noener)(const nbnxn_pairlist_t *nbl,
59 const nbnxn_atomdata_t *nbat,
60 const interaction_const_t *ic,
65 typedef void (*p_nbk_func_ener)(const nbnxn_pairlist_t *nbl,
66 const nbnxn_atomdata_t *nbat,
67 const interaction_const_t *ic,
74 /* Analytical reaction-field kernels */
77 #include "nbnxn_kernel_ref_includes.h"
79 #define LJ_FORCE_SWITCH
80 #include "nbnxn_kernel_ref_includes.h"
81 #undef LJ_FORCE_SWITCH
83 #include "nbnxn_kernel_ref_includes.h"
87 #define LJ_EWALD_COMB_GEOM
88 #include "nbnxn_kernel_ref_includes.h"
89 #undef LJ_EWALD_COMB_GEOM
90 #define LJ_EWALD_COMB_LB
91 #include "nbnxn_kernel_ref_includes.h"
92 #undef LJ_EWALD_COMB_LB
98 /* Tabulated exclusion interaction electrostatics kernels */
101 #include "nbnxn_kernel_ref_includes.h"
103 #define LJ_FORCE_SWITCH
104 #include "nbnxn_kernel_ref_includes.h"
105 #undef LJ_FORCE_SWITCH
106 #define LJ_POT_SWITCH
107 #include "nbnxn_kernel_ref_includes.h"
111 #define LJ_EWALD_COMB_GEOM
112 #include "nbnxn_kernel_ref_includes.h"
113 #undef LJ_EWALD_COMB_GEOM
114 #define LJ_EWALD_COMB_LB
115 #include "nbnxn_kernel_ref_includes.h"
116 #undef LJ_EWALD_COMB_LB
119 /* Twin-range cut-off kernels */
120 #define VDW_CUTOFF_CHECK
122 #include "nbnxn_kernel_ref_includes.h"
124 #define LJ_FORCE_SWITCH
125 #include "nbnxn_kernel_ref_includes.h"
126 #undef LJ_FORCE_SWITCH
127 #define LJ_POT_SWITCH
128 #include "nbnxn_kernel_ref_includes.h"
132 #define LJ_EWALD_COMB_GEOM
133 #include "nbnxn_kernel_ref_includes.h"
134 #undef LJ_EWALD_COMB_GEOM
135 #define LJ_EWALD_COMB_LB
136 #include "nbnxn_kernel_ref_includes.h"
137 #undef LJ_EWALD_COMB_LB
140 #undef VDW_CUTOFF_CHECK
145 coultRF, coultTAB, coultTAB_TWIN, coultNR
149 vdwtCUT, vdwtFSWITCH, vdwtPSWITCH, vdwtEWALDGEOM, vdwtEWALDLB, vdwtNR
152 p_nbk_func_noener p_nbk_c_noener[coultNR][vdwtNR] =
154 { nbnxn_kernel_ElecRF_VdwLJ_F_ref, nbnxn_kernel_ElecRF_VdwLJFsw_F_ref, nbnxn_kernel_ElecRF_VdwLJPsw_F_ref, nbnxn_kernel_ElecRF_VdwLJEwCombGeom_F_ref, nbnxn_kernel_ElecRF_VdwLJEwCombLB_F_ref },
155 { nbnxn_kernel_ElecQSTab_VdwLJ_F_ref, nbnxn_kernel_ElecQSTab_VdwLJFsw_F_ref, nbnxn_kernel_ElecQSTab_VdwLJPsw_F_ref, nbnxn_kernel_ElecQSTab_VdwLJEwCombGeom_F_ref, nbnxn_kernel_ElecQSTab_VdwLJEwCombLB_F_ref },
156 { nbnxn_kernel_ElecQSTabTwinCut_VdwLJ_F_ref, nbnxn_kernel_ElecQSTabTwinCut_VdwLJFsw_F_ref, nbnxn_kernel_ElecQSTabTwinCut_VdwLJPsw_F_ref, nbnxn_kernel_ElecQSTabTwinCut_VdwLJEwCombGeom_F_ref, nbnxn_kernel_ElecQSTabTwinCut_VdwLJEwCombLB_F_ref }
159 p_nbk_func_ener p_nbk_c_ener[coultNR][vdwtNR] =
161 { nbnxn_kernel_ElecRF_VdwLJ_VF_ref, nbnxn_kernel_ElecRF_VdwLJFsw_VF_ref, nbnxn_kernel_ElecRF_VdwLJPsw_VF_ref, nbnxn_kernel_ElecRF_VdwLJEwCombGeom_VF_ref, nbnxn_kernel_ElecRF_VdwLJEwCombLB_VF_ref },
162 { nbnxn_kernel_ElecQSTab_VdwLJ_VF_ref, nbnxn_kernel_ElecQSTab_VdwLJFsw_VF_ref, nbnxn_kernel_ElecQSTab_VdwLJPsw_VF_ref, nbnxn_kernel_ElecQSTab_VdwLJEwCombGeom_VF_ref, nbnxn_kernel_ElecQSTab_VdwLJEwCombLB_VF_ref },
163 { nbnxn_kernel_ElecQSTabTwinCut_VdwLJ_VF_ref, nbnxn_kernel_ElecQSTabTwinCut_VdwLJFsw_VF_ref, nbnxn_kernel_ElecQSTabTwinCut_VdwLJPsw_VF_ref, nbnxn_kernel_ElecQSTabTwinCut_VdwLJEwCombGeom_VF_ref, nbnxn_kernel_ElecQSTabTwinCut_VdwLJEwCombLB_VF_ref }
166 p_nbk_func_ener p_nbk_c_energrp[coultNR][vdwtNR] =
168 { nbnxn_kernel_ElecRF_VdwLJ_VgrpF_ref, nbnxn_kernel_ElecRF_VdwLJFsw_VgrpF_ref, nbnxn_kernel_ElecRF_VdwLJPsw_VgrpF_ref, nbnxn_kernel_ElecRF_VdwLJEwCombGeom_VgrpF_ref, nbnxn_kernel_ElecRF_VdwLJEwCombLB_VgrpF_ref },
169 { nbnxn_kernel_ElecQSTab_VdwLJ_VgrpF_ref, nbnxn_kernel_ElecQSTab_VdwLJFsw_VgrpF_ref, nbnxn_kernel_ElecQSTab_VdwLJPsw_VgrpF_ref, nbnxn_kernel_ElecQSTab_VdwLJEwCombGeom_VgrpF_ref, nbnxn_kernel_ElecQSTab_VdwLJEwCombLB_VgrpF_ref },
170 { nbnxn_kernel_ElecQSTabTwinCut_VdwLJ_VgrpF_ref, nbnxn_kernel_ElecQSTabTwinCut_VdwLJFsw_VgrpF_ref, nbnxn_kernel_ElecQSTabTwinCut_VdwLJPsw_VgrpF_ref, nbnxn_kernel_ElecQSTabTwinCut_VdwLJEwCombGeom_VgrpF_ref, nbnxn_kernel_ElecQSTabTwinCut_VdwLJEwCombLB_VgrpF_ref }
174 nbnxn_kernel_ref(const nbnxn_pairlist_set_t *nbl_list,
175 const nbnxn_atomdata_t *nbat,
176 const interaction_const_t *ic,
185 nbnxn_pairlist_t **nbl;
190 nnbl = nbl_list->nnbl;
193 if (EEL_RF(ic->eeltype) || ic->eeltype == eelCUT)
199 if (ic->rcoulomb == ic->rvdw)
205 coult = coultTAB_TWIN;
209 if (ic->vdwtype == evdwCUT)
211 switch (ic->vdw_modifier)
213 case eintmodPOTSHIFT:
217 case eintmodFORCESWITCH:
220 case eintmodPOTSWITCH:
224 gmx_incons("Unsupported VdW modifier");
228 else if (ic->vdwtype == evdwPME)
230 if (ic->ljpme_comb_rule == ljcrGEOM)
232 assert(nbat->comb_rule == ljcrGEOM);
233 vdwt = vdwtEWALDGEOM;
237 assert(nbat->comb_rule == ljcrLB);
243 gmx_incons("Unsupported vdwtype in nbnxn reference kernel");
246 #pragma omp parallel for schedule(static) num_threads(gmx_omp_nthreads_get(emntNonbonded))
247 for (nb = 0; nb < nnbl; nb++)
249 nbnxn_atomdata_output_t *out;
252 out = &nbat->out[nb];
254 if (clearF == enbvClearFYes)
256 clear_f(nbat, nb, out->f);
259 if ((force_flags & GMX_FORCE_VIRIAL) && nnbl == 1)
265 fshift_p = out->fshift;
267 if (clearF == enbvClearFYes)
269 clear_fshift(fshift_p);
273 if (!(force_flags & GMX_FORCE_ENERGY))
275 /* Don't calculate energies */
276 p_nbk_c_noener[coult][vdwt](nbl[nb], nbat,
282 else if (out->nV == 1)
284 /* No energy groups */
288 p_nbk_c_ener[coult][vdwt](nbl[nb], nbat,
298 /* Calculate energy group contributions */
301 for (i = 0; i < out->nV; i++)
305 for (i = 0; i < out->nV; i++)
310 p_nbk_c_energrp[coult][vdwt](nbl[nb], nbat,
320 if (force_flags & GMX_FORCE_ENERGY)
322 reduce_energies_over_lists(nbat, nnbl, Vvdw, Vc);