Merge branch release-2016
[alexxy/gromacs.git] / src / gromacs / tables / forcetable.cpp
index 55dbfc4b83aa4aa3f22f5c602719677119caec47..cfd20340b9e391bdabf9fdc4e7d3d32a19a4a94c 100644 (file)
@@ -211,7 +211,7 @@ void table_spline3_fill_ewald_lr(real                                 *table_f,
             vi = v_inrange - dc*(i - i_inrange)*dx;
         }
 
-        if (table_v != NULL)
+        if (table_v != nullptr)
         {
             table_v[i] = vi;
         }
@@ -281,7 +281,7 @@ void table_spline3_fill_ewald_lr(real                                 *table_f,
     /* Currently the last value only contains half the force: double it */
     table_f[0] *= 2;
 
-    if (table_v != NULL && table_fdv0 != NULL)
+    if (table_v != nullptr && table_fdv0 != nullptr)
     {
         /* Copy to FDV0 table too. Allocation occurs in forcerec.c,
          * init_ewald_f_table().
@@ -382,37 +382,6 @@ real ewald_spline3_table_scale(const interaction_const_t *ic)
     return sc;
 }
 
-/* Calculate the potential and force for an r value
- * in exactly the same way it is done in the inner loop.
- * VFtab is a pointer to the table data, offset is
- * the point where we should begin and stride is
- * 4 if we have a buckingham table, 3 otherwise.
- * If you want to evaluate table no N, set offset to 4*N.
- *
- * We use normal precision here, since that is what we
- * will use in the inner loops.
- */
-static void evaluate_table(real VFtab[], int offset, int stride,
-                           real tabscale, real r, real *y, real *yp)
-{
-    int  n;
-    real rt, eps, eps2;
-    real Y, F, Geps, Heps2, Fp;
-
-    rt       =  r*tabscale;
-    n        =  (int)rt;
-    eps      =  rt - n;
-    eps2     =  eps*eps;
-    n        =  offset+stride*n;
-    Y        =  VFtab[n];
-    F        =  VFtab[n+1];
-    Geps     =  eps*VFtab[n+2];
-    Heps2    =  eps2*VFtab[n+3];
-    Fp       =  F+Geps+Heps2;
-    *y       =  Y+eps*Fp;
-    *yp      =  (Fp+Geps+2.0*Heps2)*tabscale;
-}
-
 static void copy2table(int n, int offset, int stride,
                        double x[], double Vtab[], double Ftab[], real scalefactor,
                        real dest[])
@@ -609,7 +578,7 @@ static void read_tables(FILE *fp, const char *fn,
 {
     char    *libfn;
     char     buf[STRLEN];
-    double **yy = NULL, start, end, dx0, dx1, ssd, vm, vp, f, numf;
+    double **yy = nullptr, start, end, dx0, dx1, ssd, vm, vp, f, numf;
     int      k, i, nx, nx0 = 0, ny, nny, ns;
     gmx_bool bAllZero, bZeroV, bZeroF;
     double   tabscale;
@@ -790,7 +759,7 @@ static void done_tabledata(t_tabledata *td)
     sfree(td->f);
 }
 
-static void fill_table(t_tabledata *td, int tp, const t_forcerec *fr,
+static void fill_table(t_tabledata *td, int tp, const interaction_const_t *ic,
                        gmx_bool b14only)
 {
     /* Fill the table according to the formulas in the manual.
@@ -814,8 +783,8 @@ static void fill_table(t_tabledata *td, int tp, const t_forcerec *fr,
     double   ksw, swi, swi1;
     /* Temporary parameters */
     gmx_bool bPotentialSwitch, bForceSwitch, bPotentialShift;
-    double   ewc   = fr->ewaldcoeff_q;
-    double   ewclj = fr->ewaldcoeff_lj;
+    double   ewc   = ic->ewaldcoeff_q;
+    double   ewclj = ic->ewaldcoeff_lj;
     double   Vcut  = 0;
 
     if (b14only)
@@ -829,27 +798,27 @@ static void fill_table(t_tabledata *td, int tp, const t_forcerec *fr,
         bPotentialSwitch = ((tp == etabLJ6Switch) || (tp == etabLJ12Switch) ||
                             (tp == etabCOULSwitch) ||
                             (tp == etabEwaldSwitch) || (tp == etabEwaldUserSwitch) ||
-                            (tprops[tp].bCoulomb && (fr->coulomb_modifier == eintmodPOTSWITCH)) ||
-                            (!tprops[tp].bCoulomb && (fr->vdw_modifier == eintmodPOTSWITCH)));
+                            (tprops[tp].bCoulomb && (ic->coulomb_modifier == eintmodPOTSWITCH)) ||
+                            (!tprops[tp].bCoulomb && (ic->vdw_modifier == eintmodPOTSWITCH)));
         bForceSwitch  = ((tp == etabLJ6Shift) || (tp == etabLJ12Shift) ||
                          (tp == etabShift) ||
-                         (tprops[tp].bCoulomb && (fr->coulomb_modifier == eintmodFORCESWITCH)) ||
-                         (!tprops[tp].bCoulomb && (fr->vdw_modifier == eintmodFORCESWITCH)));
-        bPotentialShift = ((tprops[tp].bCoulomb && (fr->coulomb_modifier == eintmodPOTSHIFT)) ||
-                           (!tprops[tp].bCoulomb && (fr->vdw_modifier == eintmodPOTSHIFT)));
+                         (tprops[tp].bCoulomb && (ic->coulomb_modifier == eintmodFORCESWITCH)) ||
+                         (!tprops[tp].bCoulomb && (ic->vdw_modifier == eintmodFORCESWITCH)));
+        bPotentialShift = ((tprops[tp].bCoulomb && (ic->coulomb_modifier == eintmodPOTSHIFT)) ||
+                           (!tprops[tp].bCoulomb && (ic->vdw_modifier == eintmodPOTSHIFT)));
     }
 
-    reppow = fr->reppow;
+    reppow = ic->reppow;
 
     if (tprops[tp].bCoulomb)
     {
-        r1 = fr->rcoulomb_switch;
-        rc = fr->rcoulomb;
+        r1 = ic->rcoulomb_switch;
+        rc = ic->rcoulomb;
     }
     else
     {
-        r1 = fr->rvdw_switch;
-        rc = fr->rvdw;
+        r1 = ic->rvdw_switch;
+        rc = ic->rvdw;
     }
     if (bPotentialSwitch)
     {
@@ -1080,8 +1049,8 @@ static void fill_table(t_tabledata *td, int tp, const t_forcerec *fr,
                 break;
             case etabRF:
             case etabRF_ZERO:
-                Vtab  = 1.0/r      +   fr->k_rf*r2 - fr->c_rf;
-                Ftab  = 1.0/r2     - 2*fr->k_rf*r;
+                Vtab  = 1.0/r      +   ic->k_rf*r2 - ic->c_rf;
+                Ftab  = 1.0/r2     - 2*ic->k_rf*r;
                 if (tp == etabRF_ZERO && r >= rc)
                 {
                     Vtab = 0;
@@ -1180,7 +1149,7 @@ static void fill_table(t_tabledata *td, int tp, const t_forcerec *fr,
     }
 }
 
-static void set_table_type(int tabsel[], const t_forcerec *fr, gmx_bool b14only)
+static void set_table_type(int tabsel[], const interaction_const_t *ic, gmx_bool b14only)
 {
     int eltype, vdwtype;
 
@@ -1191,7 +1160,7 @@ static void set_table_type(int tabsel[], const t_forcerec *fr, gmx_bool b14only)
 
     if (b14only)
     {
-        switch (fr->eeltype)
+        switch (ic->eeltype)
         {
             case eelUSER:
             case eelPMEUSER:
@@ -1204,7 +1173,7 @@ static void set_table_type(int tabsel[], const t_forcerec *fr, gmx_bool b14only)
     }
     else
     {
-        eltype = fr->eeltype;
+        eltype = ic->eeltype;
     }
 
     switch (eltype)
@@ -1216,7 +1185,7 @@ static void set_table_type(int tabsel[], const t_forcerec *fr, gmx_bool b14only)
             tabsel[etiCOUL] = etabShift;
             break;
         case eelSHIFT:
-            if (fr->rcoulomb > fr->rcoulomb_switch)
+            if (ic->rcoulomb > ic->rcoulomb_switch)
             {
                 tabsel[etiCOUL] = etabShift;
             }
@@ -1258,20 +1227,20 @@ static void set_table_type(int tabsel[], const t_forcerec *fr, gmx_bool b14only)
     }
 
     /* Van der Waals time */
-    if (fr->bBHAM && !b14only)
+    if (ic->useBuckingham && !b14only)
     {
         tabsel[etiLJ6]  = etabLJ6;
         tabsel[etiLJ12] = etabEXPMIN;
     }
     else
     {
-        if (b14only && fr->vdwtype != evdwUSER)
+        if (b14only && ic->vdwtype != evdwUSER)
         {
             vdwtype = evdwCUT;
         }
         else
         {
-            vdwtype = fr->vdwtype;
+            vdwtype = ic->vdwtype;
         }
 
         switch (vdwtype)
@@ -1305,10 +1274,10 @@ static void set_table_type(int tabsel[], const t_forcerec *fr, gmx_bool b14only)
                           __FILE__, __LINE__);
         }
 
-        if (!b14only && fr->vdw_modifier != eintmodNONE)
+        if (!b14only && ic->vdw_modifier != eintmodNONE)
         {
-            if (fr->vdw_modifier != eintmodPOTSHIFT &&
-                fr->vdwtype != evdwCUT)
+            if (ic->vdw_modifier != eintmodPOTSHIFT &&
+                ic->vdwtype != evdwCUT)
             {
                 gmx_incons("Potential modifiers other than potential-shift are only implemented for LJ cut-off");
             }
@@ -1316,9 +1285,9 @@ static void set_table_type(int tabsel[], const t_forcerec *fr, gmx_bool b14only)
             /* LJ-PME and other (shift-only) modifiers are handled by applying the modifiers
              * to the original interaction forms when we fill the table, so we only check cutoffs here.
              */
-            if (fr->vdwtype == evdwCUT)
+            if (ic->vdwtype == evdwCUT)
             {
-                switch (fr->vdw_modifier)
+                switch (ic->vdw_modifier)
                 {
                     case eintmodNONE:
                     case eintmodPOTSHIFT:
@@ -1342,7 +1311,7 @@ static void set_table_type(int tabsel[], const t_forcerec *fr, gmx_bool b14only)
 }
 
 t_forcetable *make_tables(FILE *out,
-                          const t_forcerec *fr,
+                          const interaction_const_t *ic,
                           const char *fn,
                           real rtab, int flags)
 {
@@ -1364,7 +1333,7 @@ t_forcetable *make_tables(FILE *out,
     }
     else
     {
-        set_table_type(tabsel, fr, b14only);
+        set_table_type(tabsel, ic, b14only);
     }
     snew(td, etiNR);
     table->r         = rtab;
@@ -1431,13 +1400,15 @@ t_forcetable *make_tables(FILE *out,
         if (tabsel[k] != etabUSER)
         {
             real scale = table->scale;
-            if (fr->bBHAM && (fr->bham_b_max != 0) && tabsel[k] == etabEXPMIN)
+            if (ic->useBuckingham &&
+                (ic->buckinghamBMax != 0) &&
+                tabsel[k] == etabEXPMIN)
             {
-                scale /= fr->bham_b_max;
+                scale /= ic->buckinghamBMax;
             }
             init_table(table->n, nx0, scale, &(td[k]), !useUserTable);
 
-            fill_table(&(td[k]), tabsel[k], fr, b14only);
+            fill_table(&(td[k]), tabsel[k], ic, b14only);
             if (out)
             {
                 fprintf(out, "Generated table with %d data points for %s%s.\n"
@@ -1570,13 +1541,14 @@ bondedtable_t make_bonded_table(FILE *fplog, const char *fn, int angle)
     return tab;
 }
 
-t_forcetable *makeDispersionCorrectionTable(FILE *fp,
-                                            t_forcerec *fr, real rtab,
-                                            const char *tabfn)
+t_forcetable *makeDispersionCorrectionTable(FILE                      *fp,
+                                            const interaction_const_t *ic,
+                                            real                       rtab,
+                                            const char                *tabfn)
 {
-    t_forcetable *dispersionCorrectionTable = NULL;
+    t_forcetable *dispersionCorrectionTable = nullptr;
 
-    if (tabfn == NULL)
+    if (tabfn == nullptr)
     {
         if (debug)
         {
@@ -1585,7 +1557,7 @@ t_forcetable *makeDispersionCorrectionTable(FILE *fp,
         return dispersionCorrectionTable;
     }
 
-    t_forcetable *fullTable = make_tables(fp, fr, tabfn, rtab, 0);
+    t_forcetable *fullTable = make_tables(fp, ic, tabfn, rtab, 0);
     /* Copy the contents of the table to one that has just dispersion
      * and repulsion, to improve cache performance. We want the table
      * data to be aligned to 32-byte boundaries. The pointers could be