Merge branch release-2018
[alexxy/gromacs.git] / src / gromacs / mdlib / calc_verletbuf.cpp
index c1a6fcdcce9202be31a91b5056841bb4adbf7cb8..f0a48401fc798d746bae2b7a19b8916f42663746 100644 (file)
 
 #include "calc_verletbuf.h"
 
-#include <assert.h>
-#include <stdlib.h>
-
+#include <cassert>
 #include <cmath>
+#include <cstdlib>
 
 #include <algorithm>
 
@@ -56,6 +55,7 @@
 #include "gromacs/topology/topology.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/smalloc.h"
+#include "gromacs/utility/strconvert.h"
 
 /* The code in this file estimates a pairlist buffer length
  * given a target energy drift per atom per picosecond.
@@ -286,7 +286,6 @@ static void get_vsite_masses(const gmx_moltype_t  *moltype,
                             break;
                         case F_VSITEN:
                             gmx_incons("Invalid vsite type");
-                            break;
                         default:
                             /* Use the mass of the lightest constructing atom.
                              * This is an approximation.
@@ -356,8 +355,7 @@ static void get_verlet_buffer_atomtypes(const gmx_mtop_t      *mtop,
 {
     verletbuf_atomtype_t          *att;
     int                            natt;
-    int                            mb, nmol, ft, i, a1, a2, a3, a;
-    const t_atoms                 *atoms;
+    int                            ft, i, a1, a2, a3, a;
     const t_ilist                 *il;
     const t_iparams               *ip;
     atom_nonbonded_kinetic_prop_t *prop;
@@ -372,11 +370,11 @@ static void get_verlet_buffer_atomtypes(const gmx_mtop_t      *mtop,
         *n_nonlin_vsite = 0;
     }
 
-    for (mb = 0; mb < mtop->nmolblock; mb++)
+    for (const gmx_molblock_t &molblock : mtop->molblock)
     {
-        nmol = mtop->molblock[mb].nmol;
-
-        atoms = &mtop->moltype[mtop->molblock[mb].type].atoms;
+        int                  nmol    = molblock.nmol;
+        const gmx_moltype_t &moltype = mtop->moltype[molblock.type];
+        const t_atoms       *atoms   = &moltype.atoms;
 
         /* Check for constraints, as they affect the kinetic energy.
          * For virtual sites we need the masses and geometry of
@@ -387,7 +385,7 @@ static void get_verlet_buffer_atomtypes(const gmx_mtop_t      *mtop,
 
         for (ft = F_CONSTR; ft <= F_CONSTRNC; ft++)
         {
-            il = &mtop->moltype[mtop->molblock[mb].type].ilist[ft];
+            il = &moltype.ilist[ft];
 
             for (i = 0; i < il->nr; i += 1+NRAL(ft))
             {
@@ -409,7 +407,7 @@ static void get_verlet_buffer_atomtypes(const gmx_mtop_t      *mtop,
             }
         }
 
-        il = &mtop->moltype[mtop->molblock[mb].type].ilist[F_SETTLE];
+        il = &moltype.ilist[F_SETTLE];
 
         for (i = 0; i < il->nr; i += 1+NRAL(F_SETTLE))
         {
@@ -431,7 +429,7 @@ static void get_verlet_buffer_atomtypes(const gmx_mtop_t      *mtop,
             prop[a3].con_len  = ip->settle.doh;
         }
 
-        get_vsite_masses(&mtop->moltype[mtop->molblock[mb].type],
+        get_vsite_masses(&moltype,
                          &mtop->ffparams,
                          setMassesToOne,
                          vsite_m,
@@ -473,9 +471,9 @@ static void get_verlet_buffer_atomtypes(const gmx_mtop_t      *mtop,
     {
         for (a = 0; a < natt; a++)
         {
-            fprintf(debug, "type %d: m %5.2f t %d q %6.3f con %d con_m %5.3f con_l %5.3f n %d\n",
+            fprintf(debug, "type %d: m %5.2f t %d q %6.3f con %s con_m %5.3f con_l %5.3f n %d\n",
                     a, att[a].prop.mass, att[a].prop.type, att[a].prop.q,
-                    att[a].prop.bConstr, att[a].prop.con_mass, att[a].prop.con_len,
+                    gmx::boolToString(att[a].prop.bConstr), att[a].prop.con_mass, att[a].prop.con_len,
                     att[a].n);
         }
     }
@@ -736,11 +734,11 @@ static real energyDrift(const verletbuf_atomtype_t *att, int natt,
             /* Multiply by the number of atom pairs */
             if (j == i)
             {
-                pot *= (double)att[i].n*(att[i].n - 1)/2;
+                pot *= static_cast<double>(att[i].n)*(att[i].n - 1)/2;
             }
             else
             {
-                pot *= (double)att[i].n*att[j].n;
+                pot *= static_cast<double>(att[i].n)*att[j].n;
             }
             /* We need the line density to get the energy drift of the system.
              * The effective average r^2 is close to (rlist+sigma)^2.
@@ -800,7 +798,6 @@ static real surface_frac(int cluster_size, real particle_distance, real rlist)
             break;
         default:
             gmx_incons("surface_frac called with unsupported cluster_size");
-            area_rel = 1.0;
     }
 
     return area_rel/cluster_size;
@@ -990,7 +987,7 @@ void calc_verlet_buffer_size(const gmx_mtop_t *mtop, real boxvol,
      */
     const bool setMassesToOne = (ir->eI == eiBD && ir->bd_fric > 0);
     get_verlet_buffer_atomtypes(mtop, setMassesToOne, &att, &natt, n_nonlin_vsite);
-    assert(att != NULL && natt >= 0);
+    assert(att != nullptr && natt >= 0);
 
     if (debug)
     {
@@ -1124,7 +1121,7 @@ void calc_verlet_buffer_size(const gmx_mtop_t *mtop, real boxvol,
     /* Search using bisection */
     ib0 = -1;
     /* The drift will be neglible at 5 times the max sigma */
-    ib1 = (int)(5*maxSigma(kT_fac, natt, att)/resolution) + 1;
+    ib1 = static_cast<int>(5*maxSigma(kT_fac, natt, att)/resolution) + 1;
     while (ib1 - ib0 > 1)
     {
         ib = (ib0 + ib1)/2;
@@ -1219,7 +1216,7 @@ real minCellSizeForAtomDisplacement(const gmx_mtop_t &mtop,
     /* Search using bisection, avoid 0 and start at 1 */
     int  ib0      = 0;
     /* The chance will be neglible at 10 times the max sigma */
-    int  ib1      = (int)(10*maxSigma(kT_fac, natt, att)/resolution) + 1;
+    int  ib1      = int(10*maxSigma(kT_fac, natt, att)/resolution) + 1;
     real cellSize = 0;
     while (ib1 - ib0 > 1)
     {