Move tables.c to new module and C++
authorMark Abraham <mark.j.abraham@gmail.com>
Thu, 24 Sep 2015 11:56:04 +0000 (13:56 +0200)
committerDavid van der Spoel <davidvanderspoel@gmail.com>
Tue, 29 Sep 2015 09:28:16 +0000 (11:28 +0200)
There is a question mark over icc+Phi for some of this code when
compiled as C++.

Change-Id: I33a07307ac5eac69958a7acd9e05e8b5a4f93c01

src/gromacs/CMakeLists.txt
src/gromacs/ewald/pme-load-balancing.cpp
src/gromacs/gmxlib/nonbonded/nonbonded.c
src/gromacs/legacyheaders/force.h
src/gromacs/listed-forces/pairs.cpp
src/gromacs/mdlib/forcerec.cpp
src/gromacs/mdlib/wall.cpp
src/gromacs/tables/CMakeLists.txt [new file with mode: 0644]
src/gromacs/tables/forcetable.cpp [moved from src/gromacs/mdlib/tables.c with 95% similarity]
src/gromacs/tables/forcetable.h [moved from src/gromacs/legacyheaders/tables.h with 73% similarity]

index 26d7111383d96c659540fb93926fc9026e74ec4f..443f3effbddcae51f6888176543623dcda434e24 100644 (file)
@@ -103,6 +103,7 @@ add_subdirectory(random)
 add_subdirectory(onlinehelp)
 add_subdirectory(options)
 add_subdirectory(pbcutil)
+add_subdirectory(tables)
 add_subdirectory(timing)
 add_subdirectory(topology)
 add_subdirectory(utility)
index 88cccde7644a1270b0b9bccc2decacc9cf6ff968..0cae0f2b37c32a662b4f8de4f4332e56338ed293 100644 (file)
@@ -57,7 +57,6 @@
 #include "gromacs/domdec/domdec_network.h"
 #include "gromacs/gmxlib/calcgrid.h"
 #include "gromacs/gmxlib/md_logging.h"
-#include "gromacs/legacyheaders/force.h"
 #include "gromacs/legacyheaders/network.h"
 #include "gromacs/legacyheaders/sim_util.h"
 #include "gromacs/legacyheaders/types/commrec.h"
index bafe83f5b3ca7a536658135e0dcf208e1cd7f390..d0f3e099b73f76d1469f14dca8ec732b968e04fc 100644 (file)
@@ -55,7 +55,6 @@
 #include "gromacs/legacyheaders/names.h"
 #include "gromacs/legacyheaders/nrnb.h"
 #include "gromacs/legacyheaders/ns.h"
-#include "gromacs/legacyheaders/tables.h"
 #include "gromacs/legacyheaders/txtdump.h"
 #include "gromacs/legacyheaders/types/forcerec.h"
 #include "gromacs/legacyheaders/types/mdatom.h"
@@ -67,6 +66,7 @@
 #include "gromacs/pbcutil/ishift.h"
 #include "gromacs/pbcutil/mshift.h"
 #include "gromacs/pbcutil/pbc.h"
+#include "gromacs/tables/forcetable.h"
 #include "gromacs/utility/arraysize.h"
 #include "gromacs/utility/basedefinitions.h"
 #include "gromacs/utility/cstringutil.h"
index d3c094cc11e6ce421e63bbfcbfc2b107030f6d8e..0a1851d3be3271334c9c45db38c6bb1562454901 100644 (file)
@@ -96,28 +96,6 @@ real do_walls(t_inputrec *ir, t_forcerec *fr, matrix box, t_mdatoms *md,
 #define GMX_MAKETABLES_FORCEUSER  (1<<0)
 #define GMX_MAKETABLES_14ONLY     (1<<1)
 
-t_forcetable make_tables(FILE *fp, const output_env_t oenv,
-                         const t_forcerec *fr, gmx_bool bVerbose,
-                         const char *fn, real rtab, int flags);
-/* Return tables for inner loops. When bVerbose the tables are printed
- * to .xvg files
- */
-
-bondedtable_t make_bonded_table(FILE *fplog, char *fn, int angle);
-/* Fill a table for bonded interactions,
- * angle should be: bonds 0, angles 1, dihedrals 2
- */
-
-/* Return a table for GB calculations */
-t_forcetable make_gb_table(const output_env_t oenv,
-                           const t_forcerec  *fr);
-
-/* Read a table for AdResS Thermo Force calculations */
-t_forcetable make_atf_table(FILE *out, const output_env_t oenv,
-                            const t_forcerec *fr,
-                            const char *fn,
-                            matrix box);
-
 gmx_bool can_use_allvsall(const t_inputrec *ir,
                           gmx_bool bPrintNote, struct t_commrec *cr, FILE *fp);
 /* Returns if we can use all-vs-all loops.
index f0d3b520a234ef39db01c09b916cd43f025ad023..1e1a54d99e53485a677dd9471637f587e066b411 100644 (file)
 
 #include <cmath>
 
-#include "gromacs/legacyheaders/tables.h"
 #include "gromacs/legacyheaders/types/group.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/pbcutil/ishift.h"
 #include "gromacs/pbcutil/mshift.h"
 #include "gromacs/pbcutil/pbc.h"
+#include "gromacs/tables/forcetable.h"
 #include "gromacs/utility/basedefinitions.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/gmxassert.h"
index a088b6aa86f753f6435d725e3445d4ee7018f2f2..799e5c6eb9be0e9918f2b52a77dd56e465fde49c 100644 (file)
@@ -61,7 +61,6 @@
 #include "gromacs/legacyheaders/network.h"
 #include "gromacs/legacyheaders/nonbonded.h"
 #include "gromacs/legacyheaders/ns.h"
-#include "gromacs/legacyheaders/tables.h"
 #include "gromacs/legacyheaders/txtdump.h"
 #include "gromacs/legacyheaders/typedefs.h"
 #include "gromacs/legacyheaders/types/commrec.h"
@@ -84,6 +83,7 @@
 #include "gromacs/pbcutil/ishift.h"
 #include "gromacs/pbcutil/pbc.h"
 #include "gromacs/simd/simd.h"
+#include "gromacs/tables/forcetable.h"
 #include "gromacs/topology/mtop_util.h"
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
index c8bd484079015bf2f17cac0eb54e2814bc568ffa..f37b5053291cf327654347c9728a10f47a72a86a 100644 (file)
@@ -47,6 +47,7 @@
 #include "gromacs/legacyheaders/typedefs.h"
 #include "gromacs/math/utilities.h"
 #include "gromacs/math/vec.h"
+#include "gromacs/tables/forcetable.h"
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/smalloc.h"
diff --git a/src/gromacs/tables/CMakeLists.txt b/src/gromacs/tables/CMakeLists.txt
new file mode 100644 (file)
index 0000000..6b4ed58
--- /dev/null
@@ -0,0 +1,40 @@
+#
+# This file is part of the GROMACS molecular simulation package.
+#
+# Copyright (c) 2015, 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.
+#
+# GROMACS is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public License
+# as published by the Free Software Foundation; either version 2.1
+# of the License, or (at your option) any later version.
+#
+# GROMACS is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with GROMACS; if not, see
+# http://www.gnu.org/licenses, or write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+#
+# If you want to redistribute modifications to GROMACS, please
+# consider that scientific software is very special. Version
+# control is crucial - bugs must be traceable. We will be happy to
+# consider code for inclusion in the official distribution, but
+# derived work must not be called official GROMACS. Details are found
+# in the README & COPYING files - if they are missing, get the
+# official version at http://www.gromacs.org.
+#
+# To help us fund GROMACS development, we humbly ask that you cite
+# the research papers on the package. Check out http://www.gromacs.org.
+
+file(GLOB TABLE_SOURCES *.cpp)
+set(LIBGROMACS_SOURCES ${LIBGROMACS_SOURCES} ${TABLE_SOURCES} PARENT_SCOPE)
+
+if (BUILD_TESTING)
+#    add_subdirectory(tests)
+endif()
similarity index 95%
rename from src/gromacs/mdlib/tables.c
rename to src/gromacs/tables/forcetable.cpp
index 91cd7107fd48ffc08f540dcf2318f29256a1b959..0fe35d91faac41913954da29d04c4a14ecdbbafe 100644 (file)
  */
 #include "gmxpre.h"
 
-#include "gromacs/legacyheaders/tables.h"
+#include "forcetable.h"
 
-#include <math.h>
+#include <cmath>
+
+#include <algorithm>
 
 #include "gromacs/fileio/xvgr.h"
 #include "gromacs/legacyheaders/force.h"
-#include "gromacs/legacyheaders/macros.h"
 #include "gromacs/legacyheaders/names.h"
 #include "gromacs/legacyheaders/network.h"
 #include "gromacs/legacyheaders/typedefs.h"
@@ -321,10 +322,10 @@ static double spline3_table_scale(double third_deriv_max,
     sc_deriv  = sqrt(third_deriv_max/(6*4*deriv_tol*x_scale))*x_scale;
 
     /* Don't try to be more accurate on energy than the precision */
-    func_tol  = max(func_tol, GMX_REAL_EPS);
+    func_tol  = std::max(func_tol, static_cast<double>(GMX_REAL_EPS));
     sc_func   = pow(third_deriv_max/(6*12*sqrt(3)*func_tol), 1.0/3.0)*x_scale;
 
-    return max(sc_deriv, sc_func);
+    return std::max(sc_deriv, sc_func);
 }
 
 /* The scale (1/spacing) for third order spline interpolation
@@ -361,7 +362,7 @@ real ewald_spline3_table_scale(const interaction_const_t *ic)
             fprintf(debug, "Ewald Coulomb quadratic spline table spacing: %f 1/nm\n", 1/sc_q);
         }
 
-        sc    = max(sc, sc_q);
+        sc    = std::max(sc, sc_q);
     }
 
     if (EVDW_PME(ic->vdwtype))
@@ -381,7 +382,7 @@ real ewald_spline3_table_scale(const interaction_const_t *ic)
             fprintf(debug, "Ewald LJ quadratic spline table spacing: %f 1/nm\n", 1/sc_lj);
         }
 
-        sc = max(sc, sc_lj);
+        sc = std::max(sc, sc_lj);
     }
 
     return sc;
@@ -495,7 +496,6 @@ static void spline_forces(int nx, double h, double v[], gmx_bool bS3, gmx_bool b
     /* To make life easy we initially set the spacing to 1
      * and correct for this at the end.
      */
-    beta = 2;
     if (bS3)
     {
         /* Fit V''' at the start */
@@ -789,8 +789,6 @@ static void read_tables(FILE *fp, const char *fn,
 
 static void done_tabledata(t_tabledata *td)
 {
-    int i;
-
     if (!td)
     {
         return;
@@ -919,7 +917,7 @@ static void fill_table(t_tabledata *td, int tp, const t_forcerec *fr,
         }
         else
         {
-            rc12 = pow(rc, -reppow);
+            rc12 = std::pow(rc, -reppow);
         }
 
         switch (tp)
@@ -971,7 +969,7 @@ static void fill_table(t_tabledata *td, int tp, const t_forcerec *fr,
         }
         else
         {
-            r12 = pow(r, -reppow);
+            r12 = std::pow(r, -reppow);
         }
         Vtab  = 0.0;
         Ftab  = 0.0;
@@ -1368,7 +1366,7 @@ static void set_table_type(int tabsel[], const t_forcerec *fr, gmx_bool b14only)
     }
 }
 
-t_forcetable make_tables(FILE *out, const output_env_t oenv,
+t_forcetable make_tables(FILE *out, const struct gmx_output_env_t *oenv,
                          const t_forcerec *fr,
                          gmx_bool bVerbose, const char *fn,
                          real rtab, int flags)
@@ -1379,7 +1377,7 @@ t_forcetable make_tables(FILE *out, const output_env_t oenv,
     t_tabledata    *td;
     gmx_bool        b14only, bReadTab, bGenTab;
     real            x0, y0, yp;
-    int             i, j, k, nx, nx0, tabsel[etiNR];
+    int             k, nx, nx0, tabsel[etiNR];
     real            scalefactor;
 
     t_forcetable    table;
@@ -1413,7 +1411,7 @@ t_forcetable make_tables(FILE *out, const output_env_t oenv,
     /* Check whether we have to read or generate */
     bReadTab = FALSE;
     bGenTab  = FALSE;
-    for (i = 0; (i < etiNR); i++)
+    for (unsigned int i = 0; (i < etiNR); i++)
     {
         if (ETAB_USER(tabsel[i]))
         {
@@ -1454,7 +1452,7 @@ t_forcetable make_tables(FILE *out, const output_env_t oenv,
 #else
             table.scale = 500.0;
 #endif
-            nx = table.n = rtab*table.scale;
+            nx = table.n = static_cast<int>(rtab*table.scale);
         }
     }
     if (fr->bBHAM)
@@ -1525,7 +1523,7 @@ t_forcetable make_tables(FILE *out, const output_env_t oenv,
                 fp = xvgropen(fns[k], fns[k], "r", "V", oenv);
             }
             /* plot the output 5 times denser than the table data */
-            for (i = 5*((nx0+1)/2); i < 5*table.n; i++)
+            for (int i = 5*((nx0+1)/2); i < 5*table.n; i++)
             {
                 x0 = i*table.r/(5*(table.n-1));
                 evaluate_table(table.data, k*table.formatsize, table.stride, table.scale, x0, &y0, &yp);
@@ -1540,33 +1538,19 @@ t_forcetable make_tables(FILE *out, const output_env_t oenv,
     return table;
 }
 
-t_forcetable make_gb_table(const output_env_t oenv,
-                           const t_forcerec  *fr)
+t_forcetable make_gb_table(const struct gmx_output_env_t *oenv,
+                           const t_forcerec              *fr)
 {
     const char     *fns[3]   = { "gbctab.xvg", "gbdtab.xvg", "gbrtab.xvg" };
-    const char     *fns14[3] = { "gbctab14.xvg", "gbdtab14.xvg", "gbrtab14.xvg" };
     FILE           *fp;
     t_tabledata    *td;
-    gmx_bool        bReadTab, bGenTab;
+    gmx_bool        bReadTab;
     real            x0, y0, yp;
-    int             i, j, k, nx, nx0, tabsel[etiNR];
+    int             i, nx, nx0;
     double          r, r2, Vtab, Ftab, expterm;
 
     t_forcetable    table;
 
-    double          abs_error_r, abs_error_r2;
-    double          rel_error_r, rel_error_r2;
-    double          rel_error_r_old = 0, rel_error_r2_old = 0;
-    double          x0_r_error, x0_r2_error;
-
-
-    /* Only set a Coulomb table for GB */
-    /*
-       tabsel[0]=etabGB;
-       tabsel[1]=-1;
-       tabsel[2]=-1;
-     */
-
     /* Set the table dimensions for GB, not really necessary to
      * use etiNR (since we only have one table, but ...)
      */
@@ -1576,19 +1560,18 @@ t_forcetable make_gb_table(const output_env_t oenv,
     table.r             = fr->gbtabr;
     table.scale         = fr->gbtabscale;
     table.scale_exp     = 0;
-    table.n             = table.scale*table.r;
+    table.n             = static_cast<int>(table.scale*table.r);
     table.formatsize    = 4;
     table.ninteractions = 1;
     table.stride        = table.formatsize*table.ninteractions;
     nx0                 = 0;
-    nx                  = table.scale*table.r;
+    nx                  = table.n;
 
     /* Check whether we have to read or generate
      * We will always generate a table, so remove the read code
      * (Compare with original make_table function
      */
     bReadTab = FALSE;
-    bGenTab  = TRUE;
 
     /* Each table type (e.g. coul,lj6,lj12) requires four numbers per
      * datapoint. For performance reasons we want the table data to be
@@ -1642,44 +1625,6 @@ t_forcetable make_gb_table(const output_env_t oenv,
         xvgrclose(fp);
     }
 
-    /*
-       for(i=100*nx0;i<99.81*table.n;i++)
-       {
-       r = i*table.r/(100*table.n);
-       r2      = r*r;
-       expterm = exp(-0.25*r2);
-
-       Vtab = 1/sqrt(r2+expterm);
-       Ftab = (r-0.25*r*expterm)/((r2+expterm)*sqrt(r2+expterm));
-
-
-       evaluate_table(table.data,0,4,table.scale,r,&y0,&yp);
-       printf("gb: i=%d, x0=%g, y0=%15.15f, Vtab=%15.15f, yp=%15.15f, Ftab=%15.15f\n",i,r, y0, Vtab, yp, Ftab);
-
-       abs_error_r=fabs(y0-Vtab);
-       abs_error_r2=fabs(yp-(-1)*Ftab);
-
-       rel_error_r=abs_error_r/y0;
-       rel_error_r2=fabs(abs_error_r2/yp);
-
-
-       if(rel_error_r>rel_error_r_old)
-       {
-       rel_error_r_old=rel_error_r;
-       x0_r_error=x0;
-       }
-
-       if(rel_error_r2>rel_error_r2_old)
-       {
-       rel_error_r2_old=rel_error_r2;
-       x0_r2_error=x0;
-       }
-       }
-
-       printf("gb: MAX REL ERROR IN R=%15.15f, MAX REL ERROR IN R2=%15.15f\n",rel_error_r_old, rel_error_r2_old);
-       printf("gb: XO_R=%g, X0_R2=%g\n",x0_r_error, x0_r2_error);
-
-       exit(1); */
     done_tabledata(&(td[0]));
     sfree(td);
 
@@ -1688,7 +1633,7 @@ t_forcetable make_gb_table(const output_env_t oenv,
 
 }
 
-t_forcetable make_atf_table(FILE *out, const output_env_t oenv,
+t_forcetable make_atf_table(FILE *out, const struct gmx_output_env_t *oenv,
                             const t_forcerec *fr,
                             const char *fn,
                             matrix box)
@@ -1726,8 +1671,6 @@ t_forcetable make_atf_table(FILE *out, const output_env_t oenv,
     table.scale     = 0;
     table.n         = 0;
     table.scale_exp = 0;
-    nx0             = 10;
-    nx              = 0;
 
     read_tables(out, fn, 1, 0, td);
     rtab      = td[0].x[td[0].nx-1];
@@ -1794,19 +1737,10 @@ t_forcetable make_atf_table(FILE *out, const output_env_t oenv,
 bondedtable_t make_bonded_table(FILE *fplog, char *fn, int angle)
 {
     t_tabledata   td;
-    double        start;
     int           i;
     bondedtable_t tab;
     int           stride = 4;
 
-    if (angle < 2)
-    {
-        start = 0;
-    }
-    else
-    {
-        start = -180.0;
-    }
     read_tables(fplog, fn, 1, angle, &td);
     if (angle > 0)
     {
similarity index 73%
rename from src/gromacs/legacyheaders/tables.h
rename to src/gromacs/tables/forcetable.h
index 75db9e2f4e4d8875dae7ac67f6a07e7cc1615292..6fa8ed1a9fe794037dd73e009a95d17bf161cdda 100644 (file)
  * To help us fund GROMACS development, we humbly ask that you cite
  * the research papers on the package. Check out http://www.gromacs.org.
  */
+#ifndef GMX_TABLES_FORCETABLE_H
+#define GMX_TABLES_FORCETABLE_H
 
-#ifndef _tables_h
-#define _tables_h
+#include "gromacs/legacyheaders/types/fcdata.h"
+#include "gromacs/legacyheaders/types/forcerec.h"
 #include "gromacs/legacyheaders/types/interaction_const.h"
 #include "gromacs/legacyheaders/types/simple.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-#if 0
-}
-#endif
+struct gmx_output_env_t;
 
 /* Index in the tables that says which function to use */
 enum {
@@ -79,8 +76,27 @@ double v_q_ewald_lr(double beta, double r);
 double v_lj_ewald_lr(double beta, double r);
 /* Return the real space grid contribution for LJ-Ewald*/
 
-#ifdef __cplusplus
-}
-#endif
+t_forcetable make_tables(FILE *fp, const struct gmx_output_env_t *oenv,
+                         const t_forcerec *fr, gmx_bool bVerbose,
+                         const char *fn, real rtab, int flags);
+/* Return tables for inner loops. When bVerbose the tables are printed
+ * to .xvg files
+ */
+
+bondedtable_t make_bonded_table(FILE *fplog, char *fn, int angle);
+/* Return a table for bonded interactions,
+ * angle should be: bonds 0, angles 1, dihedrals 2
+ */
+
+/* Return a table for GB calculations */
+t_forcetable make_gb_table(const struct gmx_output_env_t *oenv,
+                           const t_forcerec              *fr);
+
+/* Read a table for AdResS Thermo Force calculations */
+t_forcetable make_atf_table(FILE                          *out,
+                            const struct gmx_output_env_t *oenv,
+                            const t_forcerec              *fr,
+                            const char                    *fn,
+                            matrix                         box);
 
-#endif  /* _tables\_h */
+#endif  /* GMX_TABLES_FORCETABLE_H */