Convert gmx_mtop_t to C++
[alexxy/gromacs.git] / src / gromacs / mdlib / perf_est.cpp
index 6888f3b0bc8876bf1f59823f2a53a3d4bb0dec92..d638869306c8a4571f9fa669154c4682423c668f 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) 2012,2014,2015,2016,2017, by the GROMACS development team, led by
+ * Copyright (c) 2012,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.
@@ -171,8 +171,7 @@ void count_bonded_distances(const gmx_mtop_t *mtop, const t_inputrec *ir,
 {
     gmx_bool       bExcl;
     double         nonsimd_step_frac;
-    int            mb, nmol, ftype;
-    gmx_moltype_t *molt;
+    int            ftype;
     double         ndtot_c, ndtot_simd;
 #if GMX_SIMD_HAVE_REAL
     gmx_bool       bSimdBondeds = TRUE;
@@ -211,10 +210,9 @@ void count_bonded_distances(const gmx_mtop_t *mtop, const t_inputrec *ir,
      */
     ndtot_c    = 0;
     ndtot_simd = 0;
-    for (mb = 0; mb < mtop->nmolblock; mb++)
+    for (const gmx_molblock_t &molb : mtop->molblock)
     {
-        molt = &mtop->moltype[mtop->molblock[mb].type];
-        nmol = mtop->molblock[mb].nmol;
+        const gmx_moltype_t *molt = &mtop->moltype[molb.type];
         for (ftype = 0; ftype < F_NRE; ftype++)
         {
             int nbonds;
@@ -248,14 +246,14 @@ void count_bonded_distances(const gmx_mtop_t *mtop, const t_inputrec *ir,
                         nd_c    = NRAL(ftype) - 1;
                         break;
                 }
-                nbonds      = nmol*molt->ilist[ftype].nr/(1 + NRAL(ftype));
+                nbonds      = molb.nmol*molt->ilist[ftype].nr/(1 + NRAL(ftype));
                 ndtot_c    += nbonds*nd_c;
                 ndtot_simd += nbonds*nd_simd;
             }
         }
         if (bExcl)
         {
-            ndtot_c += nmol*(molt->excls.nra - molt->atoms.nr)/2;
+            ndtot_c += molb.nmol*(molt->excls.nra - molt->atoms.nr)/2;
         }
     }
 
@@ -280,13 +278,11 @@ static void pp_group_load(const gmx_mtop_t *mtop, const t_inputrec *ir,
                           double *cost_pp,
                           gmx_bool *bChargePerturbed, gmx_bool *bTypePerturbed)
 {
-    t_atom        *atom;
-    int            mb, nmol, atnr, cg, a, a0, ncqlj, ncq, nclj;
+    int            atnr, cg, a0, ncqlj, ncq, nclj;
     gmx_bool       bBHAM, bLJcut, bWater, bQ, bLJ;
     int            nw, nqlj, nq, nlj;
     double         fq, fqlj, flj, fqljw, fqw;
     t_iparams     *iparams;
-    gmx_moltype_t *molt;
 
     bBHAM = (mtop->ffparams.functype[0] == F_BHAM);
 
@@ -314,12 +310,11 @@ static void pp_group_load(const gmx_mtop_t *mtop, const t_inputrec *ir,
     nlj               = 0;
     *bChargePerturbed = FALSE;
     *bTypePerturbed   = FALSE;
-    for (mb = 0; mb < mtop->nmolblock; mb++)
+    for (const gmx_molblock_t &molb : mtop->molblock)
     {
-        molt = &mtop->moltype[mtop->molblock[mb].type];
-        atom = molt->atoms.atom;
-        nmol = mtop->molblock[mb].nmol;
-        a    = 0;
+        const gmx_moltype_t *molt = &mtop->moltype[molb.type];
+        const t_atom        *atom = molt->atoms.atom;
+        int                  a    = 0;
         for (cg = 0; cg < molt->cgs.nr; cg++)
         {
             bWater = !bBHAM;
@@ -367,13 +362,13 @@ static void pp_group_load(const gmx_mtop_t *mtop, const t_inputrec *ir,
             }
             if (bWater)
             {
-                nw   += nmol;
+                nw   += molb.nmol;
             }
             else
             {
-                nqlj += nmol*ncqlj;
-                nq   += nmol*ncq;
-                nlj  += nmol*nclj;
+                nqlj += molb.nmol*ncqlj;
+                nq   += molb.nmol*ncq;
+                nlj  += molb.nmol*nclj;
             }
         }
     }
@@ -407,11 +402,9 @@ static void pp_verlet_load(const gmx_mtop_t *mtop, const t_inputrec *ir,
                            double *cost_pp,
                            gmx_bool *bChargePerturbed, gmx_bool *bTypePerturbed)
 {
-    t_atom        *atom;
-    int            mb, nmol, atnr, a, nqlj, nq, nlj;
+    int            atnr, a, nqlj, nq, nlj;
     gmx_bool       bQRF;
     t_iparams     *iparams;
-    gmx_moltype_t *molt;
     real           r_eff;
     double         c_qlj, c_q, c_lj;
     double         nppa;
@@ -433,11 +426,10 @@ static void pp_verlet_load(const gmx_mtop_t *mtop, const t_inputrec *ir,
     nq                = 0;
     *bChargePerturbed = FALSE;
     *bTypePerturbed   = FALSE;
-    for (mb = 0; mb < mtop->nmolblock; mb++)
+    for (const gmx_molblock_t &molb : mtop->molblock)
     {
-        molt = &mtop->moltype[mtop->molblock[mb].type];
-        atom = molt->atoms.atom;
-        nmol = mtop->molblock[mb].nmol;
+        const gmx_moltype_t *molt = &mtop->moltype[molb.type];
+        const t_atom        *atom = molt->atoms.atom;
         for (a = 0; a < molt->atoms.nr; a++)
         {
             if (atom[a].q != 0 || atom[a].qB != 0)
@@ -445,11 +437,11 @@ static void pp_verlet_load(const gmx_mtop_t *mtop, const t_inputrec *ir,
                 if (iparams[(atnr+1)*atom[a].type].lj.c6  != 0 ||
                     iparams[(atnr+1)*atom[a].type].lj.c12 != 0)
                 {
-                    nqlj += nmol;
+                    nqlj += molb.nmol;
                 }
                 else
                 {
-                    nq += nmol;
+                    nq += molb.nmol;
                 }
             }
             if (atom[a].q != atom[a].qB)