Converted pulling code to C++.
authorRossen Apostolov <rossen@kth.se>
Wed, 3 Sep 2014 13:54:35 +0000 (15:54 +0200)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Wed, 27 May 2015 03:21:53 +0000 (05:21 +0200)
Removed unused variables and changed some pointers to const char.
Added some static_cast to make explicit the old casting behaviour.

Added a missing default clause in pull code

Change-Id: I14708cf15799c564b77e466d73a9e8bc4488d192

src/gromacs/pulling/CMakeLists.txt
src/gromacs/pulling/pull.cpp [moved from src/gromacs/pulling/pull.c with 99% similarity]
src/gromacs/pulling/pull_rotation.cpp [moved from src/gromacs/pulling/pull_rotation.c with 99% similarity]
src/gromacs/pulling/pullutil.cpp [moved from src/gromacs/pulling/pullutil.c with 99% similarity]

index 9c9f21883ddce244fa6f63a946db91065c3b6d6c..afac1ee686464304b9344a228653d59764c6544b 100644 (file)
@@ -1,7 +1,7 @@
 #
 # This file is part of the GROMACS molecular simulation package.
 #
-# Copyright (c) 2014, by the GROMACS development team, led by
+# Copyright (c) 2014,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.
@@ -32,7 +32,7 @@
 # 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 PULLING_SOURCES *.cpp *.c)
+file(GLOB PULLING_SOURCES *.cpp)
 set(LIBGROMACS_SOURCES ${LIBGROMACS_SOURCES} ${PULLING_SOURCES} PARENT_SCOPE)
 
 if (BUILD_TESTING)
similarity index 99%
rename from src/gromacs/pulling/pull.c
rename to src/gromacs/pulling/pull.cpp
index a252388ef5ad0b9c4238e1050494e1bdc00fb5f2..a1960ea9d7d04db8644bdc4f31aa99e8718b10dd 100644 (file)
@@ -43,6 +43,8 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include <algorithm>
+
 #include "gromacs/fileio/filenm.h"
 #include "gromacs/fileio/gmxfio.h"
 #include "gromacs/fileio/xvgr.h"
@@ -431,7 +433,7 @@ static double max_pull_distance2(const t_pull_coord *pcrd, const t_pbc *pbc)
     {
         if (pcrd->dim[m] != 0)
         {
-            max_d2 = min(max_d2, norm2(pbc->box[m]));
+            max_d2 = std::min(max_d2, static_cast<double>(norm2(pbc->box[m])));
         }
     }
 
@@ -447,13 +449,12 @@ static void low_get_pull_coord_dr(const t_pull *pull,
                                   dvec xg, dvec xref, double max_dist2,
                                   dvec dr)
 {
-    const t_pull_group *pgrp0, *pgrp1;
+    const t_pull_group *pgrp0;
     int                 m;
     dvec                xrefr, dref = {0, 0, 0};
     double              dr2;
 
     pgrp0 = &pull->group[pcrd->group[0]];
-    pgrp1 = &pull->group[pcrd->group[1]];
 
     /* Only the first group can be an absolute reference, in that case nat=0 */
     if (pgrp0->nat == 0)
@@ -522,7 +523,6 @@ static void get_pull_coord_dr(t_pull      *pull,
         const t_pull_group *pgrp2, *pgrp3;
         dvec                vec;
         int                 m;
-        double              invlen;
 
         pgrp2 = &pull->group[pcrd->group[2]];
         pgrp3 = &pull->group[pcrd->group[3]];
@@ -692,7 +692,6 @@ static void do_constraint(t_pull *pull, t_pbc *pbc,
     gmx_bool      bConverged_all, bConverged = FALSE;
     int           niter = 0, g, c, ii, j, m, max_iter = 100;
     double        a;
-    dvec          f;       /* the pull force */
     dvec          tmp, tmp3;
     t_pull_group *pgrp0, *pgrp1;
     t_pull_coord *pcrd;
@@ -853,6 +852,11 @@ static void do_constraint(t_pull *pull, t_pbc *pbc,
                     dsvmul( lambda*rm*pgrp0->invtm, vec, dr0);
                     dr_tot[c] += -lambda;
                     break;
+                default:
+                    gmx_incons("Invalid enumeration value for eGeom");
+                    /* Keep static analyzer happy */
+                    clear_dvec(dr0);
+                    clear_dvec(dr1);
             }
 
             /* DEBUG */
similarity index 99%
rename from src/gromacs/pulling/pull_rotation.c
rename to src/gromacs/pulling/pull_rotation.cpp
index 5b7358a761d8f770dd0c611431a1b05818175c0f..187fef017fe8490b57f09ff2f290630e7fff1b8c 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2008, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,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.
@@ -44,6 +44,8 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include <algorithm>
+
 #include "gromacs/domdec/domdec.h"
 #include "gromacs/fileio/gmxfio.h"
 #include "gromacs/fileio/trnio.h"
@@ -67,7 +69,7 @@
 #include "gromacs/utility/qsort_threadsafe.h"
 #include "gromacs/utility/smalloc.h"
 
-static char *RotStr = {"Enforced rotation:"};
+static char const *RotStr = {"Enforced rotation:"};
 
 /* Set the minimum weight for the determination of the slab centers */
 #define WEIGHT_MIN (10*GMX_FLOAT_MIN)
@@ -594,16 +596,11 @@ static real get_slab_weight(int j, t_rotgrp *rotg, rvec xc[], real mc[], rvec *x
     real            gaussian;         /* A single gaussian weight                     */
     real            wgauss;           /* gaussian times current mass                  */
     real            slabweight = 0.0; /* The sum of weights in the slab               */
-    int             i, islab;
-    gmx_enfrotgrp_t erg;              /* Pointer to enforced rotation group data      */
+    int             i;
 
 
-    erg = rotg->enfrotgrp;
     clear_rvec(*x_weighted_sum);
 
-    /* Slab index */
-    islab = j - erg->slab_first;
-
     /* Loop over all atoms in the rotation group */
     for (i = 0; i < rotg->nat; i++)
     {
@@ -633,6 +630,7 @@ static void get_slab_centers(
                                   init_rot_group we need to store
                                   the reference slab centers                   */
 {
+    /* Slab index */
     int             j, islab;
     gmx_enfrotgrp_t erg;      /* Pointer to enforced rotation group data */
 
@@ -754,14 +752,14 @@ static gmx_inline real torque(
 
 
 /* Right-aligned output of value with standard width */
-static void print_aligned(FILE *fp, char *str)
+static void print_aligned(FILE *fp, char const *str)
 {
     fprintf(fp, "%12s", str);
 }
 
 
 /* Right-aligned output of value with standard short width */
-static void print_aligned_short(FILE *fp, char *str)
+static void print_aligned_short(FILE *fp, char const *str)
 {
     fprintf(fp, "%6s", str);
 }
@@ -937,7 +935,6 @@ static FILE *open_rot_out(const char *fn, t_rot *rot, const output_env_t oenv)
 
         for (g = 0; g < rot->ngrp; g++)
         {
-            rotg = &rot->grp[g];
             sprintf(buf, "theta_ref%d", g);
             add_to_string_aligned(&LegendStr, buf);
 
@@ -2469,7 +2466,7 @@ static gmx_inline int get_first_slab(
         rvec      firstatom) /* First atom after sorting along the rotation vector v */
 {
     /* Find the first slab for the first atom */
-    return ceil((iprod(firstatom, rotg->vec) - max_beta)/rotg->slab_dist);
+    return static_cast<int>(ceil(static_cast<double>((iprod(firstatom, rotg->vec) - max_beta)/rotg->slab_dist)));
 }
 
 
@@ -2479,7 +2476,7 @@ static gmx_inline int get_last_slab(
         rvec      lastatom) /* Last atom along v */
 {
     /* Find the last slab for the last atom */
-    return floor((iprod(lastatom, rotg->vec) + max_beta)/rotg->slab_dist);
+    return static_cast<int>(floor(static_cast<double>((iprod(lastatom, rotg->vec) + max_beta)/rotg->slab_dist)));
 }
 
 
@@ -3009,7 +3006,7 @@ static void radial_motion2_precalc_inner_sum(t_rotgrp  *rotg, rvec innersumvec)
     gmx_enfrotgrp_t erg;       /* Pointer to enforced rotation group data */
     rvec            xi_xc;     /* xj - xc */
     rvec            tmpvec, tmpvec2;
-    real            fac, fac2;
+    real            fac;
     rvec            ri, si;
     real            siri;
     rvec            v_xi_xc;   /* v x (xj - u) */
@@ -3047,10 +3044,7 @@ static void radial_motion2_precalc_inner_sum(t_rotgrp  *rotg, rvec innersumvec)
 
         svmul(psii, v_xi_xc, si);         /*  si = psii * (v x (xi-xc) )     */
 
-        fac  = iprod(v_xi_xc, ri);        /* fac = (v x (xi-xc)).ri */
-        fac2 = fac*fac;
-
-        siri = iprod(si, ri);                       /* siri = si.ri           */
+        siri = iprod(si, ri);             /* siri = si.ri           */
 
         svmul(psiistar/psii, ri, tmpvec);
         svmul(psiistar*psiistar/(psii*psii*psii) * siri, si, tmpvec2);
@@ -3232,7 +3226,6 @@ static void get_firstlast_atom_ref(
         int       *firstindex,
         int       *lastindex)
 {
-    gmx_enfrotgrp_t erg;              /* Pointer to enforced rotation group data */
     int             i;
     real            xcproj;           /* The projection of a reference position on the
                                          rotation vector */
@@ -3240,8 +3233,6 @@ static void get_firstlast_atom_ref(
 
 
 
-    erg = rotg->enfrotgrp;
-
     /* Start with some value */
     minproj = iprod(rotg->x_ref[0], rotg->vec);
     maxproj = minproj;
@@ -3756,7 +3747,7 @@ extern void init_rot(FILE *fplog, t_inputrec *ir, int nfile, const t_filenm fnm[
             snew(rotg->enfrotgrp, 1);
             erg  = rotg->enfrotgrp;
 
-            nat_max = max(nat_max, rotg->nat);
+            nat_max = std::max(nat_max, rotg->nat);
 
             if (PAR(cr))
             {
@@ -3913,7 +3904,7 @@ extern void do_rotation(
     t_rot          *rot;
     t_rotgrp       *rotg;
     gmx_bool        outstep_slab, outstep_rot;
-    gmx_bool        bFlex, bColl;
+    gmx_bool        bColl;
     gmx_enfrot_t    er;         /* Pointer to the enforced rotation buffer variables */
     gmx_enfrotgrp_t erg;        /* Pointer to enforced rotation group data           */
     rvec            transvec;
@@ -3950,8 +3941,6 @@ extern void do_rotation(
         rotg = &rot->grp[g];
         erg  = rotg->enfrotgrp;
 
-        /* Do we have a flexible axis? */
-        bFlex = ISFLEX(rotg);
         /* Do we use a collective (global) set of coordinates? */
         bColl = ISCOLL(rotg);
 
@@ -4011,9 +4000,6 @@ extern void do_rotation(
         rotg = &rot->grp[g];
         erg  = rotg->enfrotgrp;
 
-        bFlex = ISFLEX(rotg);
-        bColl = ISCOLL(rotg);
-
         if (outstep_rot && MASTER(cr))
         {
             fprintf(er->out_rot, "%12.4f", erg->degangle);
similarity index 99%
rename from src/gromacs/pulling/pullutil.c
rename to src/gromacs/pulling/pullutil.cpp
index abfcda8ae6f39cf86f3d0172e7c4418db7dc14f5..852acc9521ed43646e46570cd21832c20e205870 100644 (file)
@@ -80,7 +80,7 @@ static void pull_set_pbcatoms(t_commrec *cr, t_pull *pull,
                               rvec *x,
                               rvec *x_pbc)
 {
-    int g, n, m;
+    int g, n;
 
     n = 0;
     for (g = 0; g < pull->ngroup; g++)
@@ -264,7 +264,7 @@ static void make_cyl_refgrps(t_commrec *cr, t_pull *pull, t_mdatoms *md,
 
         if (pcrd->eGeom == epullgCYL)
         {
-            double wmass, wwmass, inp, dist;
+            double wmass, wwmass, dist;
 
             pdyna = &pull->dyna[c];
             pgrp  = &pull->group[pcrd->group[1]];