Eliminated t_ifunc from t_interaction_function
authorMark Abraham <mark.j.abraham@gmail.com>
Mon, 15 Oct 2018 16:27:12 +0000 (18:27 +0200)
committerMark Abraham <mark.j.abraham@gmail.com>
Tue, 16 Oct 2018 08:41:50 +0000 (10:41 +0200)
Declared an equivalent function type within the listed-forces module,
because it is local there.

This eliminates the inappropriate dependency on listed-forces by the
topology module, and also the recently discovered inappropriate
transitive dependency on gmxlib by topology.

Change-Id: I0f818767711cdf3fac88c06e01fac7564e9ccc65

docs/doxygen/cycle-suppressions.txt
src/gromacs/gmxana/gmx_disre.cpp
src/gromacs/listed-forces/bonded.h
src/gromacs/listed-forces/disre.h
src/gromacs/listed-forces/listed-forces.cpp
src/gromacs/listed-forces/listed-forces.h
src/gromacs/listed-forces/orires.h
src/gromacs/listed-forces/tests/bonded.cpp
src/gromacs/topology/ifunc.cpp
src/gromacs/topology/ifunc.h

index 33357f9b3b2ce02b3174744905be0fca8b751357..0f7e243b6bd3ed92a52b292cecf54be492b5ee00 100644 (file)
@@ -15,5 +15,4 @@ mdlib -> pulling
 mdlib -> awh
 simd -> hardware
 gpu_utils -> hardware
-topology -> listed-forces
 listed-forces -> mdlib
index 9934e3d986c07001da28bbe1ea7da41599117257..52973b9c4138553c8ec36b9e5a30b1cc286ae43b 100644 (file)
@@ -209,9 +209,9 @@ static void check_viol(FILE *log,
         dr[clust_id].aver_6[ndr] += fcd->disres.Rt_6[label];
 
         snew(fshift, SHIFTS);
-        interaction_function[F_DISRES].ifunc(n, &forceatoms[i], forceparams,
-                                             x, f, fshift,
-                                             pbc, g, lam, &dvdl, nullptr, fcd, nullptr);
+        ta_disres(n, &forceatoms[i], forceparams,
+                  x, f, fshift,
+                  pbc, g, lam, &dvdl, nullptr, fcd, nullptr);
         sfree(fshift);
         viol = fcd->disres.sumviol;
 
index 840c779c840c8af69c5f1f968e84b04f8e90a216..bf7412e80f49e84a42009c760c25136c41665a3e 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016,2017, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -102,13 +102,216 @@ real
  *  Bonded force functions
  *
  *************************************************************************/
-t_ifunc bonds, g96bonds, morse_bonds, cubic_bonds, FENE_bonds, restraint_bonds;
-t_ifunc angles, g96angles, cross_bond_bond, cross_bond_angle, urey_bradley, quartic_angles, linear_angles;
-t_ifunc restrangles;
-t_ifunc pdihs, idihs, rbdihs;
-t_ifunc restrdihs, cbtdihs;
-t_ifunc tab_bonds, tab_angles, tab_dihs;
-t_ifunc polarize, anharm_polarize, water_pol, thole_pol, angres, angresz, dihres, unimplemented;
+real bonds(int nfa, const t_iatom forceatoms[], const t_iparams ip[],
+           const rvec x[], rvec4 f[], rvec fshift[],
+           const t_pbc *pbc, const t_graph *g,
+           real lambda, real *dvdlambda,
+           const t_mdatoms *md, t_fcdata *fcd,
+           int *global_atom_index);
+
+real g96bonds(int nfa, const t_iatom forceatoms[], const t_iparams ip[],
+              const rvec x[], rvec4 f[], rvec fshift[],
+              const t_pbc *pbc, const t_graph *g,
+              real lambda, real *dvdlambda,
+              const t_mdatoms *md, t_fcdata *fcd,
+              int *global_atom_index);
+
+real morse_bonds(int nfa, const t_iatom forceatoms[], const t_iparams ip[],
+                 const rvec x[], rvec4 f[], rvec fshift[],
+                 const t_pbc *pbc, const t_graph *g,
+                 real lambda, real *dvdlambda,
+                 const t_mdatoms *md, t_fcdata *fcd,
+                 int *global_atom_index);
+
+real cubic_bonds(int nfa, const t_iatom forceatoms[], const t_iparams ip[],
+                 const rvec x[], rvec4 f[], rvec fshift[],
+                 const t_pbc *pbc, const t_graph *g,
+                 real lambda, real *dvdlambda,
+                 const t_mdatoms *md, t_fcdata *fcd,
+                 int *global_atom_index);
+
+real FENE_bonds(int nfa, const t_iatom forceatoms[], const t_iparams ip[],
+                const rvec x[], rvec4 f[], rvec fshift[],
+                const t_pbc *pbc, const t_graph *g,
+                real lambda, real *dvdlambda,
+                const t_mdatoms *md, t_fcdata *fcd,
+                int *global_atom_index);
+
+real restraint_bonds(int nfa, const t_iatom forceatoms[], const t_iparams ip[],
+                     const rvec x[], rvec4 f[], rvec fshift[],
+                     const t_pbc *pbc, const t_graph *g,
+                     real lambda, real *dvdlambda,
+                     const t_mdatoms *md, t_fcdata *fcd,
+                     int *global_atom_index);
+
+real angles(int nfa, const t_iatom forceatoms[], const t_iparams ip[],
+            const rvec x[], rvec4 f[], rvec fshift[],
+            const t_pbc *pbc, const t_graph *g,
+            real lambda, real *dvdlambda,
+            const t_mdatoms *md, t_fcdata *fcd,
+            int *global_atom_index);
+
+real g96angles(int nfa, const t_iatom forceatoms[], const t_iparams ip[],
+               const rvec x[], rvec4 f[], rvec fshift[],
+               const t_pbc *pbc, const t_graph *g,
+               real lambda, real *dvdlambda,
+               const t_mdatoms *md, t_fcdata *fcd,
+               int *global_atom_index);
+
+real cross_bond_bond(int nfa, const t_iatom forceatoms[], const t_iparams ip[],
+                     const rvec x[], rvec4 f[], rvec fshift[],
+                     const t_pbc *pbc, const t_graph *g,
+                     real lambda, real *dvdlambda,
+                     const t_mdatoms *md, t_fcdata *fcd,
+                     int *global_atom_index);
+
+real cross_bond_angle(int nfa, const t_iatom forceatoms[], const t_iparams ip[],
+                      const rvec x[], rvec4 f[], rvec fshift[],
+                      const t_pbc *pbc, const t_graph *g,
+                      real lambda, real *dvdlambda,
+                      const t_mdatoms *md, t_fcdata *fcd,
+                      int *global_atom_index);
+
+real urey_bradley(int nfa, const t_iatom forceatoms[], const t_iparams ip[],
+                  const rvec x[], rvec4 f[], rvec fshift[],
+                  const t_pbc *pbc, const t_graph *g,
+                  real lambda, real *dvdlambda,
+                  const t_mdatoms *md, t_fcdata *fcd,
+                  int *global_atom_index);
+
+real quartic_angles(int nfa, const t_iatom forceatoms[], const t_iparams ip[],
+                    const rvec x[], rvec4 f[], rvec fshift[],
+                    const t_pbc *pbc, const t_graph *g,
+                    real lambda, real *dvdlambda,
+                    const t_mdatoms *md, t_fcdata *fcd,
+                    int *global_atom_index);
+
+real linear_angles(int nfa, const t_iatom forceatoms[], const t_iparams ip[],
+                   const rvec x[], rvec4 f[], rvec fshift[],
+                   const t_pbc *pbc, const t_graph *g,
+                   real lambda, real *dvdlambda,
+                   const t_mdatoms *md, t_fcdata *fcd,
+                   int *global_atom_index);
+
+real restrangles(int nfa, const t_iatom forceatoms[], const t_iparams ip[],
+                 const rvec x[], rvec4 f[], rvec fshift[],
+                 const t_pbc *pbc, const t_graph *g,
+                 real lambda, real *dvdlambda,
+                 const t_mdatoms *md, t_fcdata *fcd,
+                 int *global_atom_index);
+
+real pdihs(int nfa, const t_iatom forceatoms[], const t_iparams ip[],
+           const rvec x[], rvec4 f[], rvec fshift[],
+           const t_pbc *pbc, const t_graph *g,
+           real lambda, real *dvdlambda,
+           const t_mdatoms *md, t_fcdata *fcd,
+           int *global_atom_index);
+
+real idihs(int nfa, const t_iatom forceatoms[], const t_iparams ip[],
+           const rvec x[], rvec4 f[], rvec fshift[],
+           const t_pbc *pbc, const t_graph *g,
+           real lambda, real *dvdlambda,
+           const t_mdatoms *md, t_fcdata *fcd,
+           int *global_atom_index);
+
+real rbdihs(int nfa, const t_iatom forceatoms[], const t_iparams ip[],
+            const rvec x[], rvec4 f[], rvec fshift[],
+            const t_pbc *pbc, const t_graph *g,
+            real lambda, real *dvdlambda,
+            const t_mdatoms *md, t_fcdata *fcd,
+            int *global_atom_index);
+
+real restrdihs(int nfa, const t_iatom forceatoms[], const t_iparams ip[],
+               const rvec x[], rvec4 f[], rvec fshift[],
+               const t_pbc *pbc, const t_graph *g,
+               real lambda, real *dvdlambda,
+               const t_mdatoms *md, t_fcdata *fcd,
+               int *global_atom_index);
+
+real cbtdihs(int nfa, const t_iatom forceatoms[], const t_iparams ip[],
+             const rvec x[], rvec4 f[], rvec fshift[],
+             const t_pbc *pbc, const t_graph *g,
+             real lambda, real *dvdlambda,
+             const t_mdatoms *md, t_fcdata *fcd,
+             int *global_atom_index);
+
+real tab_bonds(int nfa, const t_iatom forceatoms[], const t_iparams ip[],
+               const rvec x[], rvec4 f[], rvec fshift[],
+               const t_pbc *pbc, const t_graph *g,
+               real lambda, real *dvdlambda,
+               const t_mdatoms *md, t_fcdata *fcd,
+               int *global_atom_index);
+
+real tab_angles(int nfa, const t_iatom forceatoms[], const t_iparams ip[],
+                const rvec x[], rvec4 f[], rvec fshift[],
+                const t_pbc *pbc, const t_graph *g,
+                real lambda, real *dvdlambda,
+                const t_mdatoms *md, t_fcdata *fcd,
+                int *global_atom_index);
+
+real tab_dihs(int nfa, const t_iatom forceatoms[], const t_iparams ip[],
+              const rvec x[], rvec4 f[], rvec fshift[],
+              const t_pbc *pbc, const t_graph *g,
+              real lambda, real *dvdlambda,
+              const t_mdatoms *md, t_fcdata *fcd,
+              int *global_atom_index);
+
+real polarize(int nfa, const t_iatom forceatoms[], const t_iparams ip[],
+              const rvec x[], rvec4 f[], rvec fshift[],
+              const t_pbc *pbc, const t_graph *g,
+              real lambda, real *dvdlambda,
+              const t_mdatoms *md, t_fcdata *fcd,
+              int *global_atom_index);
+
+real anharm_polarize(int nfa, const t_iatom forceatoms[], const t_iparams ip[],
+                     const rvec x[], rvec4 f[], rvec fshift[],
+                     const t_pbc *pbc, const t_graph *g,
+                     real lambda, real *dvdlambda,
+                     const t_mdatoms *md, t_fcdata *fcd,
+                     int *global_atom_index);
+
+real water_pol(int nfa, const t_iatom forceatoms[], const t_iparams ip[],
+               const rvec x[], rvec4 f[], rvec fshift[],
+               const t_pbc *pbc, const t_graph *g,
+               real lambda, real *dvdlambda,
+               const t_mdatoms *md, t_fcdata *fcd,
+               int *global_atom_index);
+
+real thole_pol(int nfa, const t_iatom forceatoms[], const t_iparams ip[],
+               const rvec x[], rvec4 f[], rvec fshift[],
+               const t_pbc *pbc, const t_graph *g,
+               real lambda, real *dvdlambda,
+               const t_mdatoms *md, t_fcdata *fcd,
+               int *global_atom_index);
+
+real angres(int nfa, const t_iatom forceatoms[], const t_iparams ip[],
+            const rvec x[], rvec4 f[], rvec fshift[],
+            const t_pbc *pbc, const t_graph *g,
+            real lambda, real *dvdlambda,
+            const t_mdatoms *md, t_fcdata *fcd,
+            int *global_atom_index);
+
+real angresz(int nfa, const t_iatom forceatoms[], const t_iparams ip[],
+             const rvec x[], rvec4 f[], rvec fshift[],
+             const t_pbc *pbc, const t_graph *g,
+             real lambda, real *dvdlambda,
+             const t_mdatoms *md, t_fcdata *fcd,
+             int *global_atom_index);
+
+real dihres(int nfa, const t_iatom forceatoms[], const t_iparams ip[],
+            const rvec x[], rvec4 f[], rvec fshift[],
+            const t_pbc *pbc, const t_graph *g,
+            real lambda, real *dvdlambda,
+            const t_mdatoms *md, t_fcdata *fcd,
+            int *global_atom_index);
+
+real unimplemented(int nfa, const t_iatom forceatoms[], const t_iparams ip[],
+                   const rvec x[], rvec4 f[], rvec fshift[],
+                   const t_pbc *pbc, const t_graph *g,
+                   real lambda, real *dvdlambda,
+                   const t_mdatoms *md, t_fcdata *fcd,
+                   int *global_atom_index);
+
 
 /* As pdihs(), but without calculating energies and shift forces */
 void
index d2d82a06e65fea800af7587b1d72fe11f65b11df..211700d984939d0675ee85049c0087f88d5447d1 100644 (file)
@@ -83,7 +83,12 @@ void calc_disres_R_6(const t_commrec *cr,
                      t_fcdata *fcd, history_t *hist);
 
 //! Calculates the distance restraint forces, return the potential.
-t_ifunc ta_disres;
+real ta_disres(int nfa, const t_iatom forceatoms[], const t_iparams ip[],
+               const rvec x[], rvec4 f[], rvec fshift[],
+               const t_pbc *pbc, const t_graph *g,
+               real lambda, real *dvdlambda,
+               const t_mdatoms *md, t_fcdata *fcd,
+               int *global_atom_index);
 
 //! Copies the new time averages that have been calculated in calc_disres_R_6.
 void update_disres_history(const t_fcdata *fcd, history_t *hist);
index 06572bd4b9cab24784da2a889dc86760d47004fb..56524b8d0856b4f3877ec0cbb64cc87d49934d3a 100644 (file)
@@ -48,6 +48,7 @@
 #include <cassert>
 
 #include <algorithm>
+#include <array>
 
 #include "gromacs/gmxlib/network.h"
 #include "gromacs/gmxlib/nrnb.h"
 
 #include "listed-internal.h"
 
+struct BondedInteractions
+{
+    BondedFunction function;
+    int            nrnbIndex;
+};
+
+/*! \brief Lookup table of bonded interaction functions
+ *
+ * This must have as many entries as interaction_function in ifunc.cpp */
+static std::array<BondedInteractions, F_NRE> s_bondedInteractionFunctions
+    = {
+    BondedInteractions {bonds, eNR_BONDS },                       // F_BONDS
+    BondedInteractions {g96bonds, eNR_BONDS },                    // F_G96BONDS
+    BondedInteractions {morse_bonds, eNR_MORSE },                 // F_MORSE
+    BondedInteractions {cubic_bonds, eNR_CUBICBONDS },            // F_CUBICBONDS
+    BondedInteractions {unimplemented, -1 },                      // F_CONNBONDS
+    BondedInteractions {bonds, eNR_BONDS },                       // F_HARMONIC
+    BondedInteractions {FENE_bonds, eNR_FENEBONDS },              // F_FENEBONDS
+    BondedInteractions {tab_bonds, eNR_TABBONDS },                // F_TABBONDS
+    BondedInteractions {tab_bonds, eNR_TABBONDS },                // F_TABBONDSNC
+    BondedInteractions {restraint_bonds, eNR_RESTRBONDS },        // F_RESTRBONDS
+    BondedInteractions {angles, eNR_ANGLES },                     // F_ANGLES
+    BondedInteractions {g96angles, eNR_ANGLES },                  // F_G96ANGLES
+    BondedInteractions {restrangles, eNR_ANGLES },                // F_RESTRANGLES
+    BondedInteractions {linear_angles, eNR_ANGLES },              // F_LINEAR_ANGLES
+    BondedInteractions {cross_bond_bond, eNR_CROSS_BOND_BOND },   // F_CROSS_BOND_BONDS
+    BondedInteractions {cross_bond_angle, eNR_CROSS_BOND_ANGLE }, // F_CROSS_BOND_ANGLES
+    BondedInteractions {urey_bradley, eNR_UREY_BRADLEY },         // F_UREY_BRADLEY
+    BondedInteractions {quartic_angles, eNR_QANGLES },            // F_QUARTIC_ANGLES
+    BondedInteractions {tab_angles, eNR_TABANGLES },              // F_TABANGLES
+    BondedInteractions {pdihs, eNR_PROPER },                      // F_PDIHS
+    BondedInteractions {rbdihs, eNR_RB },                         // F_RBDIHS
+    BondedInteractions {restrdihs, eNR_PROPER },                  // F_RESTRDIHS
+    BondedInteractions {cbtdihs, eNR_RB },                        // F_CBTDIHS
+    BondedInteractions {rbdihs, eNR_FOURDIH },                    // F_FOURDIHS
+    BondedInteractions {idihs, eNR_IMPROPER },                    // F_IDIHS
+    BondedInteractions {pdihs, eNR_IMPROPER },                    // F_PIDIHS
+    BondedInteractions {tab_dihs, eNR_TABDIHS },                  // F_TABDIHS
+    BondedInteractions {unimplemented, eNR_CMAP },                // F_CMAP
+    BondedInteractions {unimplemented, -1 },                      // F_GB12_NOLONGERUSED
+    BondedInteractions {unimplemented, -1 },                      // F_GB13_NOLONGERUSED
+    BondedInteractions {unimplemented, -1 },                      // F_GB14_NOLONGERUSED
+    BondedInteractions {unimplemented, -1 },                      // F_GBPOL_NOLONGERUSED
+    BondedInteractions {unimplemented, -1 },                      // F_NPSOLVATION_NOLONGERUSED
+    BondedInteractions {unimplemented, eNR_NB14 },                // F_LJ14
+    BondedInteractions {unimplemented, -1 },                      // F_COUL14
+    BondedInteractions {unimplemented, eNR_NB14 },                // F_LJC14_Q
+    BondedInteractions {unimplemented, eNR_NB14 },                // F_LJC_PAIRS_NB
+    BondedInteractions {unimplemented, -1 },                      // F_LJ
+    BondedInteractions {unimplemented, -1 },                      // F_BHAM
+    BondedInteractions {unimplemented, -1 },                      // F_LJ_LR_NOLONGERUSED
+    BondedInteractions {unimplemented, -1 },                      // F_BHAM_LR_NOLONGERUSED
+    BondedInteractions {unimplemented, -1 },                      // F_DISPCORR
+    BondedInteractions {unimplemented, -1 },                      // F_COUL_SR
+    BondedInteractions {unimplemented, -1 },                      // F_COUL_LR_NOLONGERUSED
+    BondedInteractions {unimplemented, -1 },                      // F_RF_EXCL
+    BondedInteractions {unimplemented, -1 },                      // F_COUL_RECIP
+    BondedInteractions {unimplemented, -1 },                      // F_LJ_RECIP
+    BondedInteractions {unimplemented, -1 },                      // F_DPD
+    BondedInteractions {polarize, eNR_POLARIZE },                 // F_POLARIZATION
+    BondedInteractions {water_pol, eNR_WPOL },                    // F_WATER_POL
+    BondedInteractions {thole_pol, eNR_THOLE },                   // F_THOLE_POL
+    BondedInteractions {anharm_polarize, eNR_ANHARM_POL },        // F_ANHARM_POL
+    BondedInteractions {unimplemented, -1 },                      // F_POSRES
+    BondedInteractions {unimplemented, -1 },                      // F_FBPOSRES
+    BondedInteractions {ta_disres, eNR_DISRES },                  // F_DISRES
+    BondedInteractions {unimplemented, -1 },                      // F_DISRESVIOL
+    BondedInteractions {orires, eNR_ORIRES },                     // F_ORIRES
+    BondedInteractions {unimplemented, -1 },                      // F_ORIRESDEV
+    BondedInteractions {angres, eNR_ANGRES },                     // F_ANGRES
+    BondedInteractions {angresz, eNR_ANGRESZ },                   // F_ANGRESZ
+    BondedInteractions {dihres, eNR_DIHRES },                     // F_DIHRES
+    BondedInteractions {unimplemented, -1 },                      // F_DIHRESVIOL
+    BondedInteractions {unimplemented, -1 },                      // F_CONSTR
+    BondedInteractions {unimplemented, -1 },                      // F_CONSTRNC
+    BondedInteractions {unimplemented, -1 },                      // F_SETTLE
+    BondedInteractions {unimplemented, -1 },                      // F_VSITE2
+    BondedInteractions {unimplemented, -1 },                      // F_VSITE3
+    BondedInteractions {unimplemented, -1 },                      // F_VSITE3FD
+    BondedInteractions {unimplemented, -1 },                      // F_VSITE3FAD
+    BondedInteractions {unimplemented, -1 },                      // F_VSITE3OUT
+    BondedInteractions {unimplemented, -1 },                      // F_VSITE4FD
+    BondedInteractions {unimplemented, -1 },                      // F_VSITE4FDN
+    BondedInteractions {unimplemented, -1 },                      // F_VSITEN
+    BondedInteractions {unimplemented, -1 },                      // F_COM_PULL
+    BondedInteractions {unimplemented, -1 },                      // F_EQM
+    BondedInteractions {unimplemented, -1 },                      // F_EPOT
+    BondedInteractions {unimplemented, -1 },                      // F_EKIN
+    BondedInteractions {unimplemented, -1 },                      // F_ETOT
+    BondedInteractions {unimplemented, -1 },                      // F_ECONSERVED
+    BondedInteractions {unimplemented, -1 },                      // F_TEMP
+    BondedInteractions {unimplemented, -1 },                      // F_VTEMP_NOLONGERUSED
+    BondedInteractions {unimplemented, -1 },                      // F_PDISPCORR
+    BondedInteractions {unimplemented, -1 },                      // F_PRES
+    BondedInteractions {unimplemented, -1 },                      // F_DVDL_CONSTR
+    BondedInteractions {unimplemented, -1 },                      // F_DVDL
+    BondedInteractions {unimplemented, -1 },                      // F_DKDL
+    BondedInteractions {unimplemented, -1 },                      // F_DVDL_COUL
+    BondedInteractions {unimplemented, -1 },                      // F_DVDL_VDW
+    BondedInteractions {unimplemented, -1 },                      // F_DVDL_BONDED
+    BondedInteractions {unimplemented, -1 },                      // F_DVDL_RESTRAINT
+    BondedInteractions {unimplemented, -1 },                      // F_DVDL_TEMPERATURE
+    };
+
+BondedFunction bondedFunction(int ftype)
+{
+    return s_bondedInteractionFunctions[ftype].function;
+}
+
+//! Getter for finding the flop count for an \c ftype interaction.
+static int nrnbIndex(int ftype)
+{
+    return s_bondedInteractionFunctions[ftype].nrnbIndex;
+}
+
 namespace
 {
 
@@ -375,11 +491,11 @@ calc_one_bond(int thread,
 #endif
         else
         {
-            v = interaction_function[ftype].ifunc(nbn, iatoms+nb0,
-                                                  idef->iparams,
-                                                  x, f, fshift,
-                                                  pbc, g, lambda[efptFTYPE], &(dvdl[efptFTYPE]),
-                                                  md, fcd, global_atom_index);
+            v = bondedFunction(ftype)(nbn, iatoms+nb0,
+                                      idef->iparams,
+                                      x, f, fshift,
+                                      pbc, g, lambda[efptFTYPE], &(dvdl[efptFTYPE]),
+                                      md, fcd, global_atom_index);
         }
     }
     else
@@ -395,7 +511,7 @@ calc_one_bond(int thread,
 
     if (thread == 0)
     {
-        inc_nrnb(nrnb, interaction_function[ftype].nrnb_ind, nbonds);
+        inc_nrnb(nrnb, nrnbIndex(ftype), nbonds);
     }
 
     return v;
index 6fd13ac0deb0185e0a8b931a7fe616eeff7bb647..a8910f545f169cd0cb0452806f69326621fdeeb8 100644 (file)
@@ -67,6 +67,7 @@
 #define GMX_LISTED_FORCES_LISTED_FORCES_H
 
 #include "gromacs/math/vectypes.h"
+#include "gromacs/topology/ifunc.h"
 #include "gromacs/utility/basedefinitions.h"
 
 struct gmx_enerdata_t;
@@ -88,6 +89,18 @@ namespace gmx
 class ForceWithVirial;
 }
 
+//! Type of CPU function to compute a bonded interaction.
+using BondedFunction = real(*)(int nbonds, const t_iatom iatoms[],
+                               const t_iparams iparams[],
+                               const rvec x[], rvec4 f[], rvec fshift[],
+                               const t_pbc *pbc, const t_graph *g,
+                               real lambda, real *dvdlambda,
+                               const t_mdatoms *md, t_fcdata *fcd,
+                               int *ddgatindex);
+
+//! Getter for finding a callable CPU function to compute an \c ftype interaction.
+BondedFunction bondedFunction(int ftype);
+
 /*! \brief Return whether this is an interaction that actually
  * calculates a potential and works on multiple atoms (not e.g. a
  * connection or a position restraint).
index 75d29c3800704e33f8a944b35ceb12d41547cbd9..d7066e1380c47c30641f36ff17a79e07d12a3916 100644 (file)
@@ -96,7 +96,12 @@ void diagonalize_orires_tensors(t_oriresdata *od);
 void print_orires_log(FILE *log, t_oriresdata *od);
 
 //! Calculates the orientation restraint forces.
-t_ifunc orires;
+real orires(int nfa, const t_iatom forceatoms[], const t_iparams ip[],
+            const rvec x[], rvec4 f[], rvec fshift[],
+            const t_pbc *pbc, const t_graph *g,
+            real lambda, real *dvdlambda,
+            const t_mdatoms *md, t_fcdata *fcd,
+            int *global_atom_index);
 
 //! Copies the new time averages that have been calculated in calc_orires_dev.
 void update_orires_history(const t_fcdata *fcd, history_t *hist);
index 973d01bd5648a1eccafacc2bea5bb6f46b4079ce..a70831448465f2768c8f0cf7ad59979e630129c8 100644 (file)
@@ -49,6 +49,7 @@
 
 #include <gtest/gtest.h>
 
+#include "gromacs/listed-forces/listed-forces.h"
 #include "gromacs/math/units.h"
 #include "gromacs/pbcutil/ishift.h"
 #include "gromacs/pbcutil/pbc.h"
@@ -141,16 +142,16 @@ class BondedTest : public ::testing::Test
             t_pbc pbc;
             set_pbc(&pbc, epbc, box);
             int   ddgatindex = 0;
-            real  energy     = interaction_function[ftype].ifunc(iatoms.size(),
-                                                                 iatoms.data(),
-                                                                 iparams,
-                                                                 x, f, fshift,
-                                                                 &pbc,
-                                                                 /* const struct t_graph *g */ nullptr,
-                                                                 lambda, &dvdlambda,
-                                                                 /* const struct t_mdatoms *md */ nullptr,
-                                                                 /* struct t_fcdata *fcd */ nullptr,
-                                                                 &ddgatindex);
+            real  energy     = bondedFunction(ftype)(iatoms.size(),
+                                                     iatoms.data(),
+                                                     iparams,
+                                                     x, f, fshift,
+                                                     &pbc,
+                                                     /* const struct t_graph *g */ nullptr,
+                                                     lambda, &dvdlambda,
+                                                     /* const struct t_mdatoms *md */ nullptr,
+                                                     /* struct t_fcdata *fcd */ nullptr,
+                                                     &ddgatindex);
             checker_.checkReal(energy, interaction_function[ftype].longname);
         }
 
index f042b5ceafb0a10300ee7f1822e0c638447ed86c..172f2e5007b5f90483fb7d3e2e04fe169449b98f 100644 (file)
 
 #include "ifunc.h"
 
-#include "gromacs/listed-forces/bonded.h"
-#include "gromacs/listed-forces/disre.h"
-#include "gromacs/listed-forces/orires.h"
+#define  def_bonded(str, lstr, nra, nrpa, nrpb) \
+    {str, lstr, (nra), (nrpa), (nrpb), IF_BOND}
 
-#define  def_bonded(str, lstr, nra, nrpa, nrpb, ind, func) \
-    {str, lstr, (nra), (nrpa), (nrpb), IF_BOND,                        (ind), (func)}
+#define  def_bondedz(str, lstr, nra, nrpa, nrpb) \
+    {str, lstr, (nra), (nrpa), (nrpb), IF_BOND | IF_LIMZERO}
 
-#define  def_bondedz(str, lstr, nra, nrpa, nrpb, ind, func) \
-    {str, lstr, (nra), (nrpa), (nrpb), IF_BOND | IF_LIMZERO,           (ind), (func)}
+#define  def_bondedt(str, lstr, nra, nrpa, nrpb) \
+    {str, lstr, (nra), (nrpa), (nrpb), IF_BOND | IF_TABULATED}
 
-#define  def_bondedt(str, lstr, nra, nrpa, nrpb, ind, func) \
-    {str, lstr, (nra), (nrpa), (nrpb), IF_BOND | IF_TABULATED,         (ind), (func)}
+#define  def_bondedtz(str, lstr, nra, nrpa, nrpb) \
+    {str, lstr, (nra), (nrpa), (nrpb), IF_BOND | IF_TABULATED | IF_LIMZERO}
 
-#define  def_bondedtz(str, lstr, nra, nrpa, nrpb, ind, func) \
-    {str, lstr, (nra), (nrpa), (nrpb), IF_BOND | IF_TABULATED | IF_LIMZERO, (ind), (func)}
+#define   def_angle(str, lstr, nra, nrpa, nrpb) \
+    {str, lstr, (nra), (nrpa), (nrpb), IF_BOND | IF_ATYPE}
 
-#define   def_angle(str, lstr, nra, nrpa, nrpb, ind, func) \
-    {str, lstr, (nra), (nrpa), (nrpb), IF_BOND | IF_ATYPE, (ind), (func)}
+#define    def_bond(str, lstr, nra, nrpa, nrpb) \
+    {str, lstr, (nra), (nrpa), (nrpb), IF_BOND | IF_CHEMBOND | IF_BTYPE}
 
-#define    def_bond(str, lstr, nra, nrpa, nrpb, ind, func) \
-    {str, lstr, (nra), (nrpa), (nrpb), IF_BOND | IF_CHEMBOND | IF_BTYPE, (ind), (func)}
+#define    def_bondt(str, lstr, nra, nrpa, nrpb) \
+    {str, lstr, (nra), (nrpa), (nrpb), IF_BOND | IF_CHEMBOND | IF_TABULATED}
 
-#define    def_bondt(str, lstr, nra, nrpa, nrpb, ind, func) \
-    {str, lstr, (nra), (nrpa), (nrpb), IF_BOND | IF_CHEMBOND | IF_TABULATED, (ind), (func)}
-
-#define  def_bondnb(str, lstr, nra, nrpa, nrpb, ind, func) \
-    {str, lstr, (nra), (nrpa), (nrpb), IF_BOND | IF_CHEMBOND, (ind), (func)}
+#define  def_bondnb(str, lstr, nra, nrpa, nrpb) \
+    {str, lstr, (nra), (nrpa), (nrpb), IF_BOND | IF_CHEMBOND}
 
 #define   def_vsite(str, lstr, nra, nrpa) \
-    {str, lstr, (nra), (nrpa),     0, IF_VSITE,                  -1, unimplemented}
+    {str, lstr, (nra), (nrpa),     0, IF_VSITE}
 
 #define     def_shk(str, lstr, nra, nrpa, nrpb) \
-    {str, lstr, (nra), (nrpa), (nrpb), IF_CONSTRAINT,             -1, unimplemented}
+    {str, lstr, (nra), (nrpa), (nrpb), IF_CONSTRAINT}
 
 #define   def_shkcb(str, lstr, nra, nrpa, nrpb) \
-    {str, lstr, (nra), (nrpa), (nrpb), IF_CONSTRAINT | IF_CHEMBOND, -1, unimplemented}
+    {str, lstr, (nra), (nrpa), (nrpb), IF_CONSTRAINT | IF_CHEMBOND}
 
 #define      def_nb(str, lstr, nra, nrp) \
-    {str, lstr, (nra), (nrp),     0, IF_NULL,                    -1, unimplemented}
+    {str, lstr, (nra), (nrp),     0, IF_NULL}
 
 #define    def_nofc(str, lstr) \
-    {str, lstr,    0,     0,     0, IF_NULL,                    -1, unimplemented}
+    {str, lstr,    0,     0,     0, IF_NULL}
 
 /* this MUST correspond to the enum in src/gromacs/topology/idef.h */
 const t_interaction_function interaction_function[F_NRE] =
 {
-    def_bond    ("BONDS",    "Bond",            2, 2, 2,  eNR_BONDS,  bonds         ),
-    def_bond    ("G96BONDS", "G96Bond",         2, 2, 2,  eNR_BONDS,  g96bonds      ),
-    def_bond    ("MORSE",    "Morse",           2, 3, 3,  eNR_MORSE,  morse_bonds   ),
-    def_bond    ("CUBICBONDS", "Cubic Bonds",    2, 3, 0,  eNR_CUBICBONDS, cubic_bonds),
-    def_bondnb  ("CONNBONDS", "Connect Bonds",   2, 0, 0,  0,      unimplemented     ),
-    def_bonded  ("HARMONIC", "Harmonic Pot.",   2, 2, 2,  eNR_BONDS,  bonds         ),
-    def_bondnb  ("FENEBONDS", "FENE Bonds",     2, 2, 0,  eNR_FENEBONDS, FENE_bonds ),
-    def_bondt   ("TABBONDS", "Tab. Bonds",      2, 2, 2,  eNR_TABBONDS, tab_bonds   ),
-    def_bondedtz("TABBONDSNC", "Tab. Bonds NC", 2, 2, 2,  eNR_TABBONDS, tab_bonds   ),
-    def_bonded  ("RESTRAINTPOT", "Restraint Pot.", 2, 4, 4,  eNR_RESTRBONDS,  restraint_bonds ),
-    def_angle   ("ANGLES",   "Angle",           3, 2, 2,  eNR_ANGLES, angles        ),
-    def_angle   ("G96ANGLES", "G96Angle",        3, 2, 2,  eNR_ANGLES, g96angles     ),
-    def_angle   ("RESTRANGLES", "Restricted Angles", 3, 2, 2,  eNR_ANGLES, restrangles),
-    def_angle   ("LINEAR_ANGLES", "Lin. Angle", 3, 2, 2,  eNR_LINEAR_ANGLES, linear_angles ),
-    def_bonded  ("CROSS_BOND_BOND", "Bond-Cross", 3, 3, 0, eNR_CROSS_BOND_BOND, cross_bond_bond ),
-    def_bonded  ("CROSS_BOND_ANGLE", "BA-Cross",   3, 4, 0, eNR_CROSS_BOND_ANGLE, cross_bond_angle ),
-    def_angle   ("UREY_BRADLEY", "U-B",          3, 4, 4,  eNR_UREY_BRADLEY, urey_bradley ),
-    def_angle   ("QANGLES", "Quartic Angles",    3, 6, 0,  eNR_QANGLES, quartic_angles ),
-    def_bondedt ("TABANGLES", "Tab. Angles",    3, 2, 2,  eNR_TABANGLES, tab_angles ),
-    def_bonded  ("PDIHS",    "Proper Dih.",     4, 3, 3,  eNR_PROPER, pdihs         ),
-    def_bonded  ("RBDIHS",   "Ryckaert-Bell.",  4, 6, 6,  eNR_RB, rbdihs            ),
-    def_bonded  ("RESTRDIHS",  "Restricted Dih.",     4, 2, 2,  eNR_PROPER,  restrdihs),
-    def_bonded  ("CBTDIHS",   "CBT Dih.",  4, 6, 6,  eNR_RB, cbtdihs            ),
-    def_bonded  ("FOURDIHS", "Fourier Dih.",    4, 4, 4,  eNR_FOURDIH, rbdihs       ),
-    def_bonded  ("IDIHS",    "Improper Dih.",   4, 2, 2,  eNR_IMPROPER, idihs        ),
-    def_bonded  ("PIDIHS",   "Improper Dih.",   4, 3, 3,  eNR_IMPROPER, pdihs       ),
-    def_bondedt ("TABDIHS", "Tab. Dih.",        4, 2, 2,  eNR_TABDIHS, tab_dihs     ),
-    def_bonded  ("CMAP",  "CMAP Dih.",          5, -1, -1,  eNR_CMAP,   unimplemented ),
+    def_bond    ("BONDS",    "Bond",            2, 2, 2),
+    def_bond    ("G96BONDS", "G96Bond",         2, 2, 2),
+    def_bond    ("MORSE",    "Morse",           2, 3, 3),
+    def_bond    ("CUBICBONDS", "Cubic Bonds",    2, 3, 0),
+    def_bondnb  ("CONNBONDS", "Connect Bonds",   2, 0, 0),
+    def_bonded  ("HARMONIC", "Harmonic Pot.",   2, 2, 2),
+    def_bondnb  ("FENEBONDS", "FENE Bonds",     2, 2, 0),
+    def_bondt   ("TABBONDS", "Tab. Bonds",      2, 2, 2),
+    def_bondedtz("TABBONDSNC", "Tab. Bonds NC", 2, 2, 2),
+    def_bonded  ("RESTRAINTPOT", "Restraint Pot.", 2, 4, 4),
+    def_angle   ("ANGLES",   "Angle",           3, 2, 2),
+    def_angle   ("G96ANGLES", "G96Angle",        3, 2, 2),
+    def_angle   ("RESTRANGLES", "Restricted Angles", 3, 2, 2),
+    def_angle   ("LINEAR_ANGLES", "Lin. Angle", 3, 2, 2),
+    def_bonded  ("CROSS_BOND_BOND", "Bond-Cross", 3, 3, 0),
+    def_bonded  ("CROSS_BOND_ANGLE", "BA-Cross",   3, 4, 0),
+    def_angle   ("UREY_BRADLEY", "U-B",          3, 4, 4),
+    def_angle   ("QANGLES", "Quartic Angles",    3, 6, 0),
+    def_bondedt ("TABANGLES", "Tab. Angles",    3, 2, 2),
+    def_bonded  ("PDIHS",    "Proper Dih.",     4, 3, 3),
+    def_bonded  ("RBDIHS",   "Ryckaert-Bell.",  4, 6, 6),
+    def_bonded  ("RESTRDIHS",  "Restricted Dih.",     4, 2, 2),
+    def_bonded  ("CBTDIHS",   "CBT Dih.",  4, 6, 6),
+    def_bonded  ("FOURDIHS", "Fourier Dih.",    4, 4, 4),
+    def_bonded  ("IDIHS",    "Improper Dih.",   4, 2, 2),
+    def_bonded  ("PIDIHS",   "Improper Dih.",   4, 3, 3),
+    def_bondedt ("TABDIHS", "Tab. Dih.",        4, 2, 2),
+    def_bonded  ("CMAP",  "CMAP Dih.",          5, -1, -1),
     def_nofc    ("GB12",     "GB 1-2 Pol. (unused)" ),
     def_nofc    ("GB13",     "GB 1-3 Pol. (unused)" ),
     def_nofc    ("GB14",     "GB 1-4 Pol. (unused)" ),
     def_nofc    ("GBPOL",    "GB Polarization (unused)" ),
     def_nofc    ("NPSOLVATION", "Nonpolar Sol. (unused)" ),
-    def_bondedz ("LJ14",     "LJ-14",           2, 2, 2,  eNR_NB14,   unimplemented ),
+    def_bondedz ("LJ14",     "LJ-14",           2, 2, 2),
     def_nofc    ("COUL14",   "Coulomb-14"                                           ),
-    def_bondedz ("LJC14_Q",  "LJC-14 q",        2, 5, 0,  eNR_NB14,   unimplemented ),
-    def_bondedz ("LJC_NB",   "LJC Pairs NB",    2, 4, 0,  eNR_NB14,   unimplemented ),
+    def_bondedz ("LJC14_Q",  "LJC-14 q",        2, 5, 0),
+    def_bondedz ("LJC_NB",   "LJC Pairs NB",    2, 4, 0),
     def_nb      ("LJ_SR",    "LJ (SR)",         2, 2                                ),
     def_nb      ("BHAM",     "Buck.ham (SR)",   2, 3                                ),
     def_nofc    ("LJ_LR",    "LJ (unused)"                                          ),
@@ -133,19 +129,19 @@ const t_interaction_function interaction_function[F_NRE] =
     def_nofc    ("COUL_RECIP", "Coul. recip."                                       ),
     def_nofc    ("LJ_RECIP", "LJ recip."                                            ),
     def_nofc    ("DPD",      "DPD"                                                  ),
-    def_bondnb  ("POLARIZATION", "Polarization", 2, 1, 0,  eNR_POLARIZE, polarize      ),
-    def_bonded  ("WATERPOL", "Water Pol.",      5, 6, 0,  eNR_WPOL,   water_pol     ),
-    def_bonded  ("THOLE",    "Thole Pol.",      4, 3, 0,  eNR_THOLE,  thole_pol     ),
-    def_bondnb  ("ANHARM_POL", "Anharm. Pol.", 2, 3, 0, eNR_ANHARM_POL, anharm_polarize      ),
-    def_bonded  ("POSRES",   "Position Rest.",  1, 3, 3,  eNR_POSRES, unimplemented ),
-    def_bonded  ("FBPOSRES", "Flat-bottom posres", 1, 3, 0, eNR_FBPOSRES, unimplemented ),
-    def_bonded  ("DISRES",   "Dis. Rest.",      2, 6, 0,  eNR_DISRES, ta_disres     ),
+    def_bondnb  ("POLARIZATION", "Polarization", 2, 1, 0),
+    def_bonded  ("WATERPOL", "Water Pol.",      5, 6, 0),
+    def_bonded  ("THOLE",    "Thole Pol.",      4, 3, 0),
+    def_bondnb  ("ANHARM_POL", "Anharm. Pol.", 2, 3, 0),
+    def_bonded  ("POSRES",   "Position Rest.",  1, 3, 3),
+    def_bonded  ("FBPOSRES", "Flat-bottom posres", 1, 3, 0),
+    def_bonded  ("DISRES",   "Dis. Rest.",      2, 6, 0),
     def_nofc    ("DISRESVIOL",   "D.R.Viol. (nm)"                                       ),
-    def_bonded  ("ORIRES",   "Orient. Rest.",   2, 6, 0,  eNR_ORIRES, orires        ),
+    def_bonded  ("ORIRES",   "Orient. Rest.",   2, 6, 0),
     def_nofc    ("ORDEV",    "Ori. R. RMSD"                                         ),
-    def_bonded  ("ANGRES",   "Angle Rest.",     4, 3, 3,  eNR_ANGRES, angres        ),
-    def_bonded  ("ANGRESZ",  "Angle Rest. Z",   2, 3, 3,  eNR_ANGRESZ, angresz       ),
-    def_bonded  ("DIHRES",   "Dih. Rest.",      4, 3, 3,  eNR_DIHRES, dihres        ),
+    def_bonded  ("ANGRES",   "Angle Rest.",     4, 3, 3),
+    def_bonded  ("ANGRESZ",  "Angle Rest. Z",   2, 3, 3),
+    def_bonded  ("DIHRES",   "Dih. Rest.",      4, 3, 3),
     def_nofc    ("DIHRESVIOL",  "Dih. Rest. Viol."                                     ), /* obsolete */
     def_shkcb   ("CONSTR",   "Constraint",      2, 1, 1                             ),
     def_shk     ("CONSTRNC", "Constr. No Conn.", 2, 1, 1                             ),
index 69a0a6db9d95c12473b6dbed73e7b0543bf0488f..b57e7368672c2634c89fddd3135256ca41348609 100644 (file)
@@ -53,14 +53,6 @@ typedef int t_iatom;
  */
 typedef real rvec4[4];
 
-typedef real t_ifunc (int nbonds, const t_iatom iatoms[],
-                      const t_iparams iparams[],
-                      const rvec x[], rvec4 f[], rvec fshift[],
-                      const struct t_pbc *pbc, const struct t_graph *g,
-                      real lambda, real *dvdlambda,
-                      const struct t_mdatoms *md, struct t_fcdata *fcd,
-                      int *ddgatindex);
-
 /*
  * The function type t_ifunc() calculates one interaction, using iatoms[]
  * and iparams. Within the function the number of atoms to be used is
@@ -106,8 +98,6 @@ struct t_interaction_function // NOLINT (clang-analyzer-optin.performance.Paddin
                               /* iparams struct! (see idef.h)                 */
     /* A and B are for normal and free energy components respectively.    */
     unsigned int    flags;    /* Flags (see above)                            */
-    int             nrnb_ind; /* index for nrnb (-1 if unknown)               */
-    t_ifunc        *ifunc;    /* the function it self                          */
 };
 
 #define NRFPA(ftype) (interaction_function[(ftype)].nrfpA)