Replace t_grps with std::vector
authorPaul Bauer <paul.bauer.q@gmail.com>
Tue, 2 Apr 2019 10:36:58 +0000 (12:36 +0200)
committerPaul Bauer <paul.bauer.q@gmail.com>
Fri, 3 May 2019 08:59:30 +0000 (10:59 +0200)
Refs #2833

Change-Id: Ia1f156fec4c6c24f4c29a792e384668d835416f0

18 files changed:
src/gromacs/fileio/enxio.cpp
src/gromacs/fileio/tngio.cpp
src/gromacs/fileio/tpxio.cpp
src/gromacs/gmxpreprocess/readir.cpp
src/gromacs/mdlib/broadcaststructs.cpp
src/gromacs/mdlib/energyoutput.cpp
src/gromacs/mdlib/forcerec.cpp
src/gromacs/mdlib/mdatoms.cpp
src/gromacs/mdlib/membed.cpp
src/gromacs/mdlib/tests/energyoutput.cpp
src/gromacs/mdlib/vcm.cpp
src/gromacs/mdlib/wall.cpp
src/gromacs/mdrun/runner.cpp
src/gromacs/mdrun/tpi.cpp
src/gromacs/tools/dump.cpp
src/gromacs/topology/atoms.h
src/gromacs/topology/topology.cpp
src/gromacs/topology/topology.h

index 35be6cb9e034e6866039798c5f95b88bdb83e7a3..f0d22ae4a9c922ec149020280014d1a2a8f2e0cf 100644 (file)
@@ -1208,7 +1208,7 @@ void get_enx_state(const char *fn, real t, const SimulationGroups &groups, t_inp
 
         for (i = 0; i < state->ngtc; i++)
         {
-            ni   = groups.groups[SimulationAtomGroupType::TemperatureCoupling].nm_ind[i];
+            ni   = groups.groups[SimulationAtomGroupType::TemperatureCoupling][i];
             bufi = *(groups.groupNames[ni]);
             for (j = 0; (j < state->nhchainlength); j++)
             {
index c6e29176971e59f38c17deba3071d2cf1e0ba45c..862bb2c1b025c4e0dd4eee892e13f1dac41eee9e 100644 (file)
@@ -643,7 +643,7 @@ static void add_selection_groups(gmx_tng_trajectory_t  gmx_tng,
 
     /* The name of the TNG molecule containing the selection group is the
      * same as the name of the selection group. */
-    nameIndex = *mtop->groups.groups[SimulationAtomGroupType::CompressedPositionOutput].nm_ind;
+    nameIndex = mtop->groups.groups[SimulationAtomGroupType::CompressedPositionOutput][0];
     groupName = *mtop->groups.groupNames[nameIndex];
 
     tng_molecule_alloc(tng, &mol);
index 5e7c77c73bc81322f8180cc79e1878ca9eec7e9e..7659e730ede0b78905b680f658dc74aa40302249 100644 (file)
@@ -2190,18 +2190,19 @@ static void do_atom(t_fileio *fio, t_atom *atom, gmx_bool bRead)
     }
 }
 
-static void do_grps(t_fileio             *fio,
-                    gmx::ArrayRef<t_grps> grps,
-                    gmx_bool              bRead)
+static void do_grps(t_fileio                       *fio,
+                    gmx::ArrayRef<AtomGroupIndices> grps,
+                    gmx_bool                        bRead)
 {
     for (auto &group : grps)
     {
-        gmx_fio_do_int(fio, group.nr);
+        int size = group.size();
+        gmx_fio_do_int(fio, size);
         if (bRead)
         {
-            snew(group.nm_ind, group.nr);
+            group.resize(size);
         }
-        gmx_fio_ndo_int(fio, group.nm_ind, group.nr);
+        gmx_fio_ndo_int(fio, group.data(), size);
     }
 }
 
index 7774199656458608576e3a47a98bd00d7b191666..60401e169f2d6b122280f61fb956ad97b571e828 100644 (file)
@@ -1672,15 +1672,14 @@ static void add_wall_energrps(SimulationGroups *groups, int nwall, t_symtab *sym
 {
     if (nwall > 0)
     {
-        t_grps *grps = &(groups->groups[SimulationAtomGroupType::EnergyOutput]);
-        srenew(grps->nm_ind, grps->nr+nwall);
+        AtomGroupIndices *grps = &(groups->groups[SimulationAtomGroupType::EnergyOutput]);
         for (int i = 0; i < nwall; i++)
         {
             groups->groupNames.emplace_back(
                     put_symtab(
                             symtab,
                             gmx::formatString("wall%d", i).c_str()));
-            grps->nm_ind[grps->nr++] = groups->groupNames.size() - 1;
+            grps->emplace_back(groups->groupNames.size() - 1);
         }
     }
 }
@@ -2626,12 +2625,12 @@ static bool do_numbering(int natoms, SimulationGroups *groups,
                          int grptp, bool bVerbose,
                          warninp_t wi)
 {
-    unsigned short *cbuf;
-    t_grps         *grps = &(groups->groups[gtype]);
-    int             j, gid, aj, ognr, ntot = 0;
-    const char     *title;
-    bool            bRest;
-    char            warn_buf[STRLEN];
+    unsigned short           *cbuf;
+    AtomGroupIndices         *grps = &(groups->groups[gtype]);
+    int                       j, gid, aj, ognr, ntot = 0;
+    const char               *title;
+    bool                      bRest;
+    char                      warn_buf[STRLEN];
 
     title = shortName(gtype);
 
@@ -2642,14 +2641,13 @@ static bool do_numbering(int natoms, SimulationGroups *groups,
         cbuf[i] = NOGID;
     }
 
-    snew(grps->nm_ind, groupsFromMdpFile.size()+1); /* +1 for possible rest group */
     for (int i = 0; i != groupsFromMdpFile.ssize(); ++i)
     {
         /* Lookup the group name in the block structure */
         gid = search_string(groupsFromMdpFile[i].c_str(), block->nr, gnames);
         if ((grptp != egrptpONE) || (i == 0))
         {
-            grps->nm_ind[grps->nr++] = gid;
+            grps->emplace_back(gid);
         }
 
         /* Now go over the atoms in the group */
@@ -2706,7 +2704,7 @@ static bool do_numbering(int natoms, SimulationGroups *groups,
         {
             if (cbuf[j] == NOGID)
             {
-                cbuf[j] = grps->nr;
+                cbuf[j] = grps->size();
                 bRest   = TRUE;
             }
         }
@@ -2719,21 +2717,21 @@ static bool do_numbering(int natoms, SimulationGroups *groups,
                         title, natoms-ntot);
             }
             /* Add group name "rest" */
-            grps->nm_ind[grps->nr] = restnm;
+            grps->emplace_back(restnm);
 
             /* Assign the rest name to all atoms not currently assigned to a group */
             for (j = 0; (j < natoms); j++)
             {
                 if (cbuf[j] == NOGID)
                 {
-                    cbuf[j] = grps->nr;
+                    // group size was not updated before this here, so need to use -1.
+                    cbuf[j] = grps->size() - 1;
                 }
             }
-            grps->nr++;
         }
     }
 
-    if (grps->nr == 1 && (ntot == 0 || ntot == natoms))
+    if (grps->size() == 1 && (ntot == 0 || ntot == natoms))
     {
         /* All atoms are part of one (or no) group, no index required */
         groups->groupNumbers[gtype].clear();
@@ -2777,17 +2775,17 @@ static void calc_nrdf(const gmx_mtop_t *mtop, t_inputrec *ir, char **gnames)
     /* We need to sum degrees of freedom into doubles,
      * since floats give too low nrdf's above 3 million atoms.
      */
-    snew(nrdf_tc, groups.groups[SimulationAtomGroupType::TemperatureCoupling].nr+1);
-    snew(nrdf_vcm, groups.groups[SimulationAtomGroupType::MassCenterVelocityRemoval].nr+1);
-    snew(dof_vcm, groups.groups[SimulationAtomGroupType::MassCenterVelocityRemoval].nr+1);
-    snew(na_vcm, groups.groups[SimulationAtomGroupType::MassCenterVelocityRemoval].nr+1);
-    snew(nrdf_vcm_sub, groups.groups[SimulationAtomGroupType::MassCenterVelocityRemoval].nr+1);
+    snew(nrdf_tc, groups.groups[SimulationAtomGroupType::TemperatureCoupling].size()+1);
+    snew(nrdf_vcm, groups.groups[SimulationAtomGroupType::MassCenterVelocityRemoval].size()+1);
+    snew(dof_vcm, groups.groups[SimulationAtomGroupType::MassCenterVelocityRemoval].size()+1);
+    snew(na_vcm, groups.groups[SimulationAtomGroupType::MassCenterVelocityRemoval].size()+1);
+    snew(nrdf_vcm_sub, groups.groups[SimulationAtomGroupType::MassCenterVelocityRemoval].size()+1);
 
-    for (int i = 0; i < groups.groups[SimulationAtomGroupType::TemperatureCoupling].nr; i++)
+    for (int i = 0; i < gmx::ssize(groups.groups[SimulationAtomGroupType::TemperatureCoupling]); i++)
     {
         nrdf_tc[i] = 0;
     }
-    for (int i = 0; i < groups.groups[SimulationAtomGroupType::MassCenterVelocityRemoval].nr+1; i++)
+    for (int i = 0; i < gmx::ssize(groups.groups[SimulationAtomGroupType::MassCenterVelocityRemoval])+1; i++)
     {
         nrdf_vcm[i]     = 0;
         clear_ivec(dof_vcm[i]);
@@ -2923,7 +2921,7 @@ static void calc_nrdf(const gmx_mtop_t *mtop, t_inputrec *ir, char **gnames)
                     nrdf_vcm[getGroupType(groups, SimulationAtomGroupType::MassCenterVelocityRemoval, ai)] -= 0.5*imin;
                     if (nrdf_tc[getGroupType(groups, SimulationAtomGroupType::TemperatureCoupling, ai)] < 0)
                     {
-                        gmx_fatal(FARGS, "Center of mass pulling constraints caused the number of degrees of freedom for temperature coupling group %s to be negative", gnames[groups.groups[SimulationAtomGroupType::TemperatureCoupling].nm_ind[getGroupType(groups, SimulationAtomGroupType::TemperatureCoupling, ai)]]);
+                        gmx_fatal(FARGS, "Center of mass pulling constraints caused the number of degrees of freedom for temperature coupling group %s to be negative", gnames[groups.groups[SimulationAtomGroupType::TemperatureCoupling][getGroupType(groups, SimulationAtomGroupType::TemperatureCoupling, ai)]]);
                     }
                 }
                 else
@@ -2946,7 +2944,7 @@ static void calc_nrdf(const gmx_mtop_t *mtop, t_inputrec *ir, char **gnames)
          * the number of degrees of freedom in each vcm group when COM
          * translation is removed and 6 when rotation is removed as well.
          */
-        for (int j = 0; j < groups.groups[SimulationAtomGroupType::MassCenterVelocityRemoval].nr+1; j++)
+        for (int j = 0; j < gmx::ssize(groups.groups[SimulationAtomGroupType::MassCenterVelocityRemoval])+1; j++)
         {
             switch (ir->comm_mode)
             {
@@ -2969,10 +2967,10 @@ static void calc_nrdf(const gmx_mtop_t *mtop, t_inputrec *ir, char **gnames)
             }
         }
 
-        for (int i = 0; i < groups.groups[SimulationAtomGroupType::TemperatureCoupling].nr; i++)
+        for (int i = 0; i < gmx::ssize(groups.groups[SimulationAtomGroupType::TemperatureCoupling]); i++)
         {
             /* Count the number of atoms of TC group i for every VCM group */
-            for (int j = 0; j < groups.groups[SimulationAtomGroupType::MassCenterVelocityRemoval].nr+1; j++)
+            for (int j = 0; j < gmx::ssize(groups.groups[SimulationAtomGroupType::MassCenterVelocityRemoval])+1; j++)
             {
                 na_vcm[j] = 0;
             }
@@ -2990,7 +2988,7 @@ static void calc_nrdf(const gmx_mtop_t *mtop, t_inputrec *ir, char **gnames)
              */
             nrdf_uc    = nrdf_tc[i];
             nrdf_tc[i] = 0;
-            for (int j = 0; j < groups.groups[SimulationAtomGroupType::MassCenterVelocityRemoval].nr+1; j++)
+            for (int j = 0; j < gmx::ssize(groups.groups[SimulationAtomGroupType::MassCenterVelocityRemoval])+1; j++)
             {
                 if (nrdf_vcm[j] > nrdf_vcm_sub[j])
                 {
@@ -3000,7 +2998,7 @@ static void calc_nrdf(const gmx_mtop_t *mtop, t_inputrec *ir, char **gnames)
             }
         }
     }
-    for (int i = 0; (i < groups.groups[SimulationAtomGroupType::TemperatureCoupling].nr); i++)
+    for (int i = 0; (i < gmx::ssize(groups.groups[SimulationAtomGroupType::TemperatureCoupling])); i++)
     {
         opts->nrdf[i] = nrdf_tc[i];
         if (opts->nrdf[i] < 0)
@@ -3009,7 +3007,7 @@ static void calc_nrdf(const gmx_mtop_t *mtop, t_inputrec *ir, char **gnames)
         }
         fprintf(stderr,
                 "Number of degrees of freedom in T-Coupling group %s is %.2f\n",
-                gnames[groups.groups[SimulationAtomGroupType::TemperatureCoupling].nm_ind[i]], opts->nrdf[i]);
+                gnames[groups.groups[SimulationAtomGroupType::TemperatureCoupling][i]], opts->nrdf[i]);
     }
 
     sfree(nrdf2);
@@ -3036,14 +3034,14 @@ static bool do_egp_flag(t_inputrec *ir, SimulationGroups *groups,
     {
         gmx_fatal(FARGS, "The number of groups for %s is odd", option);
     }
-    nr   = groups->groups[SimulationAtomGroupType::EnergyOutput].nr;
+    nr   = groups->groups[SimulationAtomGroupType::EnergyOutput].size();
     bSet = FALSE;
     for (size_t i = 0; i < names.size() / 2; i++)
     {
         // TODO this needs to be replaced by a solution using std::find_if
         j = 0;
         while ((j < nr) &&
-               gmx_strcasecmp(names[2*i].c_str(), *(groups->groupNames[groups->groups[SimulationAtomGroupType::EnergyOutput].nm_ind[j]])))
+               gmx_strcasecmp(names[2*i].c_str(), *(groups->groupNames[groups->groups[SimulationAtomGroupType::EnergyOutput][j]])))
         {
             j++;
         }
@@ -3054,7 +3052,7 @@ static bool do_egp_flag(t_inputrec *ir, SimulationGroups *groups,
         }
         k = 0;
         while ((k < nr) &&
-               gmx_strcasecmp(names[2*i+1].c_str(), *(groups->groupNames[groups->groups[SimulationAtomGroupType::EnergyOutput].nm_ind[k]])))
+               gmx_strcasecmp(names[2*i+1].c_str(), *(groups->groupNames[groups->groups[SimulationAtomGroupType::EnergyOutput][k]])))
         {
             k++;
         }
@@ -3205,7 +3203,7 @@ void do_index(const char* mdparin, const char *ndx,
     do_numbering(natoms, groups, temperatureCouplingGroupNames, defaultIndexGroups, gnames,
                  SimulationAtomGroupType::TemperatureCoupling,
                  restnm, useReferenceTemperature ? egrptpALL : egrptpALL_GENREST, bVerbose, wi);
-    nr            = groups->groups[SimulationAtomGroupType::TemperatureCoupling].nr;
+    nr            = groups->groups[SimulationAtomGroupType::TemperatureCoupling].size();
     ir->opts.ngtc = nr;
     snew(ir->opts.nrdf, nr);
     snew(ir->opts.tau_t, nr);
@@ -3431,7 +3429,7 @@ void do_index(const char* mdparin, const char *ndx,
                 {
                     if (ir->opts.annealing[i] != eannNO)
                     {
-                        j = groups->groups[SimulationAtomGroupType::TemperatureCoupling].nm_ind[i];
+                        j = groups->groups[SimulationAtomGroupType::TemperatureCoupling][i];
                         fprintf(stderr, "Simulated annealing for group %s: %s, %d timepoints\n",
                                 *(groups->groupNames[j]), eann_names[ir->opts.annealing[i]],
                                 ir->opts.anneal_npoints[i]);
@@ -3495,7 +3493,7 @@ void do_index(const char* mdparin, const char *ndx,
     do_numbering(natoms, groups, accelerationGroupNames, defaultIndexGroups, gnames,
                  SimulationAtomGroupType::Acceleration,
                  restnm, egrptpALL_GENREST, bVerbose, wi);
-    nr = groups->groups[SimulationAtomGroupType::Acceleration].nr;
+    nr = groups->groups[SimulationAtomGroupType::Acceleration].size();
     snew(ir->opts.acc, nr);
     ir->opts.ngacc = nr;
 
@@ -3511,7 +3509,7 @@ void do_index(const char* mdparin, const char *ndx,
     do_numbering(natoms, groups, freezeGroupNames, defaultIndexGroups, gnames,
                  SimulationAtomGroupType::Freeze,
                  restnm, egrptpALL_GENREST, bVerbose, wi);
-    nr             = groups->groups[SimulationAtomGroupType::Freeze].nr;
+    nr             = groups->groups[SimulationAtomGroupType::Freeze].size();
     ir->opts.ngfrz = nr;
     snew(ir->opts.nFreeze, nr);
     for (i = k = 0; (size_t(i) < freezeGroupNames.size()); i++)
@@ -3543,7 +3541,7 @@ void do_index(const char* mdparin, const char *ndx,
                  SimulationAtomGroupType::EnergyOutput,
                  restnm, egrptpALL_GENREST, bVerbose, wi);
     add_wall_energrps(groups, ir->nwall, symtab);
-    ir->opts.ngener = groups->groups[SimulationAtomGroupType::EnergyOutput].nr;
+    ir->opts.ngener = groups->groups[SimulationAtomGroupType::EnergyOutput].size();
     auto vcmGroupNames = gmx::splitString(is->vcm);
     bRest           =
         do_numbering(natoms, groups, vcmGroupNames, defaultIndexGroups, gnames,
@@ -3658,16 +3656,16 @@ void do_index(const char* mdparin, const char *ndx,
     {
         for (auto group : gmx::keysOf(groups->groups))
         {
-            fprintf(stderr, "%-16s has %d element(s):", shortName(group), groups->groups[group].nr);
-            for (int j = 0; (j < groups->groups[group].nr); j++)
+            fprintf(stderr, "%-16s has %zu element(s):", shortName(group), groups->groups[group].size());
+            for (const auto &entry : groups->groups[group])
             {
-                fprintf(stderr, " %s", *(groups->groupNames[groups->groups[group].nm_ind[j]]));
+                fprintf(stderr, " %s", *(groups->groupNames[entry]));
             }
             fprintf(stderr, "\n");
         }
     }
 
-    nr = groups->groups[SimulationAtomGroupType::EnergyOutput].nr;
+    nr = groups->groups[SimulationAtomGroupType::EnergyOutput].size();
     snew(ir->opts.egp_flags, nr*nr);
 
     bExcl = do_egp_flag(ir, groups, "energygrp-excl", is->egpexcl, EGP_EXCL);
@@ -4142,7 +4140,7 @@ void triple_check(const char *mdparin, t_inputrec *ir, gmx_mtop_t *sys,
     }
 
     bAcc = FALSE;
-    for (int i = 0; (i < sys->groups.groups[SimulationAtomGroupType::Acceleration].nr); i++)
+    for (int i = 0; (i < gmx::ssize(sys->groups.groups[SimulationAtomGroupType::Acceleration])); i++)
     {
         for (m = 0; (m < DIM); m++)
         {
@@ -4155,7 +4153,7 @@ void triple_check(const char *mdparin, t_inputrec *ir, gmx_mtop_t *sys,
     if (bAcc)
     {
         clear_rvec(acc);
-        snew(mgrp, sys->groups.groups[SimulationAtomGroupType::Acceleration].nr);
+        snew(mgrp, sys->groups.groups[SimulationAtomGroupType::Acceleration].size());
         for (const AtomProxy atomP : AtomRange(*sys))
         {
             const t_atom &local = atomP.atom();
@@ -4163,7 +4161,7 @@ void triple_check(const char *mdparin, t_inputrec *ir, gmx_mtop_t *sys,
             mgrp[getGroupType(sys->groups, SimulationAtomGroupType::Acceleration, i)] += local.m;
         }
         mt = 0.0;
-        for (i = 0; (i < sys->groups.groups[SimulationAtomGroupType::Acceleration].nr); i++)
+        for (i = 0; (i < gmx::ssize(sys->groups.groups[SimulationAtomGroupType::Acceleration])); i++)
         {
             for (m = 0; (m < DIM); m++)
             {
@@ -4182,7 +4180,7 @@ void triple_check(const char *mdparin, t_inputrec *ir, gmx_mtop_t *sys,
                 if (ir->nstcomm != 0 && m < ndof_com(ir))
                 {
                     acc[m] /= mt;
-                    for (i = 0; (i < sys->groups.groups[SimulationAtomGroupType::Acceleration].nr); i++)
+                    for (i = 0; (i < gmx::ssize(sys->groups.groups[SimulationAtomGroupType::Acceleration])); i++)
                     {
                         ir->opts.acc[i][m] -= acc[m];
                     }
index ef7dd2ee503fd67da3614e00d2dfdf0bf47964db..94c80855d29d5470dbef4671614a582c3b09cf40 100644 (file)
@@ -222,13 +222,13 @@ static void bc_blocka(const t_commrec *cr, t_blocka *block)
     }
 }
 
-static void bc_grps(const t_commrec *cr, gmx::ArrayRef<t_grps> grps)
+static void bc_grps(const t_commrec *cr, gmx::ArrayRef<AtomGroupIndices> grps)
 {
     for (auto &group : grps)
     {
-        block_bc(cr, group.nr);
-        snew_bc(cr, group.nm_ind, group.nr);
-        nblock_bc(cr, group.nr, group.nm_ind);
+        int size = group.size();
+        block_bc(cr, size);
+        nblock_abc(cr, size, &group);
     }
 }
 
index 9418e4170d5cfe2fc19359e936be3d4f49f59610..2f03c787c971b42451b4e267bc9e0cf75652f5e0 100644 (file)
@@ -450,7 +450,7 @@ t_mdebin *init_mdebin(ener_file_t       fp_ene,
             md->nEc++;
         }
     }
-    n       = groups->groups[SimulationAtomGroupType::EnergyOutput].nr;
+    n       = groups->groups[SimulationAtomGroupType::EnergyOutput].size();
     md->nEg = n;
     md->nE  = (n*(n+1))/2;
 
@@ -463,12 +463,12 @@ t_mdebin *init_mdebin(ener_file_t       fp_ene,
         {
             snew(gnm[k], STRLEN);
         }
-        for (i = 0; (i < groups->groups[SimulationAtomGroupType::EnergyOutput].nr); i++)
+        for (i = 0; (i < gmx::ssize(groups->groups[SimulationAtomGroupType::EnergyOutput])); i++)
         {
-            ni = groups->groups[SimulationAtomGroupType::EnergyOutput].nm_ind[i];
-            for (j = i; (j < groups->groups[SimulationAtomGroupType::EnergyOutput].nr); j++)
+            ni = groups->groups[SimulationAtomGroupType::EnergyOutput][i];
+            for (j = i; (j < gmx::ssize(groups->groups[SimulationAtomGroupType::EnergyOutput])); j++)
             {
-                nj = groups->groups[SimulationAtomGroupType::EnergyOutput].nm_ind[j];
+                nj = groups->groups[SimulationAtomGroupType::EnergyOutput][j];
                 for (k = kk = 0; (k < egNR); k++)
                 {
                     if (md->bEInd[k])
@@ -495,7 +495,7 @@ t_mdebin *init_mdebin(ener_file_t       fp_ene,
         }
     }
 
-    md->nTC  = isRerun ? 0 : groups->groups[SimulationAtomGroupType::TemperatureCoupling].nr;
+    md->nTC  = isRerun ? 0 : groups->groups[SimulationAtomGroupType::TemperatureCoupling].size();
     md->nNHC = ir->opts.nhchainlength; /* shorthand for number of NH chains */
     if (md->bMTTK)
     {
@@ -535,7 +535,7 @@ t_mdebin *init_mdebin(ener_file_t       fp_ene,
 
     for (i = 0; (i < md->nTC); i++)
     {
-        ni = groups->groups[SimulationAtomGroupType::TemperatureCoupling].nm_ind[i];
+        ni = groups->groups[SimulationAtomGroupType::TemperatureCoupling][i];
         sprintf(buf, "T-%s", *(groups->groupNames[ni]));
         grpnms[i] = gmx_strdup(buf);
     }
@@ -555,7 +555,7 @@ t_mdebin *init_mdebin(ener_file_t       fp_ene,
             {
                 for (i = 0; (i < md->nTC); i++)
                 {
-                    ni   = groups->groups[SimulationAtomGroupType::TemperatureCoupling].nm_ind[i];
+                    ni   = groups->groups[SimulationAtomGroupType::TemperatureCoupling][i];
                     bufi = *(groups->groupNames[ni]);
                     for (j = 0; (j < md->nNHC); j++)
                     {
@@ -590,7 +590,7 @@ t_mdebin *init_mdebin(ener_file_t       fp_ene,
             {
                 for (i = 0; (i < md->nTC); i++)
                 {
-                    ni   = groups->groups[SimulationAtomGroupType::TemperatureCoupling].nm_ind[i];
+                    ni   = groups->groups[SimulationAtomGroupType::TemperatureCoupling][i];
                     bufi = *(groups->groupNames[ni]);
                     sprintf(buf, "Xi-%s", bufi);
                     grpnms[2*i] = gmx_strdup(buf);
@@ -608,7 +608,7 @@ t_mdebin *init_mdebin(ener_file_t       fp_ene,
     {
         for (i = 0; (i < md->nTC); i++)
         {
-            ni = groups->groups[SimulationAtomGroupType::TemperatureCoupling].nm_ind[i];
+            ni = groups->groups[SimulationAtomGroupType::TemperatureCoupling][i];
             sprintf(buf, "Lamb-%s", *(groups->groupNames[ni]));
             grpnms[i] = gmx_strdup(buf);
         }
@@ -622,14 +622,14 @@ t_mdebin *init_mdebin(ener_file_t       fp_ene,
     }
     sfree(grpnms);
 
-    md->nU = groups->groups[SimulationAtomGroupType::Acceleration].nr;
+    md->nU = groups->groups[SimulationAtomGroupType::Acceleration].size();
     snew(md->tmp_v, md->nU);
     if (md->nU > 1)
     {
         snew(grpnms, 3*md->nU);
         for (i = 0; (i < md->nU); i++)
         {
-            ni = groups->groups[SimulationAtomGroupType::Acceleration].nm_ind[i];
+            ni = groups->groups[SimulationAtomGroupType::Acceleration][i];
             sprintf(buf, "Ux-%s", *(groups->groupNames[ni]));
             grpnms[3*i+XX] = gmx_strdup(buf);
             sprintf(buf, "Uy-%s", *(groups->groupNames[ni]));
@@ -1505,7 +1505,7 @@ void print_ebin(ener_file_t fp_ene, gmx_bool bEne, gmx_bool bDR, gmx_bool bOR,
                 if (opts->annealing[i] != eannNO)
                 {
                     fprintf(log, "Current ref_t for group %s: %8.1f\n",
-                            *(groups->groupNames[groups->groups[SimulationAtomGroupType::TemperatureCoupling].nm_ind[i]]),
+                            *(groups->groupNames[groups->groups[SimulationAtomGroupType::TemperatureCoupling][i]]),
                             opts->ref_t[i]);
                 }
             }
@@ -1559,10 +1559,10 @@ void print_ebin(ener_file_t fp_ene, gmx_bool bEne, gmx_bool bDR, gmx_bool bOR,
                     n = 0;
                     for (i = 0; (i < md->nEg); i++)
                     {
-                        ni = groups->groups[SimulationAtomGroupType::EnergyOutput].nm_ind[i];
+                        ni = groups->groups[SimulationAtomGroupType::EnergyOutput][i];
                         for (j = i; (j < md->nEg); j++)
                         {
-                            nj = groups->groups[SimulationAtomGroupType::EnergyOutput].nm_ind[j];
+                            nj = groups->groups[SimulationAtomGroupType::EnergyOutput][j];
                             sprintf(buf, "%s-%s", *(groups->groupNames[ni]),
                                     *(groups->groupNames[nj]));
                             md->print_grpnms[n++] = gmx_strdup(buf);
@@ -1598,7 +1598,7 @@ void print_ebin(ener_file_t fp_ene, gmx_bool bEne, gmx_bool bDR, gmx_bool bOR,
                         "Group", "Ux", "Uy", "Uz");
                 for (i = 0; (i < md->nU); i++)
                 {
-                    ni = groups->groups[SimulationAtomGroupType::Acceleration].nm_ind[i];
+                    ni = groups->groups[SimulationAtomGroupType::Acceleration][i];
                     fprintf(log, "%15s", *groups->groupNames[ni]);
                     pr_ebin(log, md->ebin, md->iu+3*i, 3, 3, mode, FALSE);
                 }
index d66280e64db08698502d1192bab4d2f55df24202..3c625533fb1b9f3cf6b72fe12a16afae76ca2007 100644 (file)
@@ -202,8 +202,8 @@ check_solvent_cg(const gmx_moltype_t    *molt,
                  int                     cg0,
                  int                     nmol,
                  const unsigned char    *qm_grpnr,
-                 const t_grps           *qm_grps,
-                 t_forcerec   *          fr,
+                 const AtomGroupIndices *qm_grps,
+                 t_forcerec             *fr,
                  int                    *n_solvent_parameters,
                  solvent_parameters_t  **solvent_parameters_p,
                  int                     cginfo,
@@ -276,7 +276,7 @@ check_solvent_cg(const gmx_moltype_t    *molt,
     {
         for (j = j0; j < j1 && !qm; j++)
         {
-            qm = (qm_grpnr[j] < qm_grps->nr - 1);
+            qm = (qm_grpnr[j] < qm_grps->size() - 1);
         }
     }
     /* Cannot use solvent optimization with QM */
@@ -1624,7 +1624,7 @@ void init_forcerec(FILE                             *fp,
     gmx_bool       bGenericKernelOnly;
     gmx_bool       needGroupSchemeTables, bSomeNormalNbListsAreInUse;
     gmx_bool       bFEP_NonBonded;
-    int           *nm_ind, egp_flags;
+    int            egp_flags;
 
 
     /* By default we turn SIMD kernels on, but it might be turned off further down... */
@@ -2173,7 +2173,7 @@ void init_forcerec(FILE                             *fp,
         if (negptable > 0)
         {
             /* Read the special tables for certain energy group pairs */
-            nm_ind = mtop->groups.groups[SimulationAtomGroupType::EnergyOutput].nm_ind;
+            gmx::ArrayRef<const int> nm_ind = mtop->groups.groups[SimulationAtomGroupType::EnergyOutput];
             for (egi = 0; egi < negp_pp; egi++)
             {
                 for (egj = egi; egj < negp_pp; egj++)
@@ -2277,7 +2277,7 @@ void init_forcerec(FILE                             *fp,
 
     /* Initialize the thread working data for bonded interactions */
     fr->bondedThreading =
-        init_bonded_threading(fp, mtop->groups.groups[SimulationAtomGroupType::EnergyOutput].nr);
+        init_bonded_threading(fp, mtop->groups.groups[SimulationAtomGroupType::EnergyOutput].size());
 
     fr->nthread_ewc = gmx_omp_nthreads_get(emntBonded);
     snew(fr->ewc_t, fr->nthread_ewc);
index 84d73f4fd386c4afe3457cee02730aa0156b7953..3ff5a699ae8a416a4d99af0dbe034e8db2470a37 100644 (file)
@@ -124,7 +124,7 @@ makeMDAtoms(FILE *fp, const gmx_mtop_t &mtop, const t_inputrec &ir,
     snew(md, 1);
     mdAtoms->mdatoms_.reset(md);
 
-    md->nenergrp = mtop.groups.groups[SimulationAtomGroupType::EnergyOutput].nr;
+    md->nenergrp = mtop.groups.groups[SimulationAtomGroupType::EnergyOutput].size();
     md->bVCMgrps = FALSE;
     for (int i = 0; i < mtop.natoms; i++)
     {
@@ -493,7 +493,7 @@ void atoms2md(const gmx_mtop_t *mtop, const t_inputrec *ir,
             if (ir->bQMMM)
             {
                 if (groups.groupNumbers[SimulationAtomGroupType::QuantumMechanics].empty() ||
-                    groups.groupNumbers[SimulationAtomGroupType::QuantumMechanics][ag] < groups.groups[SimulationAtomGroupType::QuantumMechanics].nr-1)
+                    groups.groupNumbers[SimulationAtomGroupType::QuantumMechanics][ag] < groups.groups[SimulationAtomGroupType::QuantumMechanics].size()-1)
                 {
                     md->bQM[i]      = TRUE;
                 }
index b2999ca05f02799871241ed4590a96e13050cce0..c3ccdafec3ec2dcc715884efdad874f00dc85b09 100644 (file)
@@ -267,7 +267,7 @@ static int init_ins_at(t_block *ins_at, t_block *rest_at, t_state *state, pos_in
     for (i = 0; i < state->natoms; i++)
     {
         gid = groups->groupNumbers[SimulationAtomGroupType::Freeze][i];
-        if (groups->groups[SimulationAtomGroupType::Freeze].nm_ind[gid] == ins_grp_id)
+        if (groups->groups[SimulationAtomGroupType::Freeze][gid] == ins_grp_id)
         {
             xmin = std::min(xmin, x[i][XX]);
             xmax = std::max(xmax, x[i][XX]);
@@ -1127,7 +1127,7 @@ gmx_membed_t *init_membed(FILE *fplog, int nfile, const t_filenm fnm[], gmx_mtop
 
         for (i = 0; i < inputrec->opts.ngfrz; i++)
         {
-            tmp_id = mtop->groups.groups[SimulationAtomGroupType::Freeze].nm_ind[i];
+            tmp_id = mtop->groups.groups[SimulationAtomGroupType::Freeze][i];
             if (ins_grp_id == tmp_id)
             {
                 fr_id = tmp_id;
@@ -1148,7 +1148,7 @@ gmx_membed_t *init_membed(FILE *fplog, int nfile, const t_filenm fnm[], gmx_mtop
             }
         }
 
-        ng = groups->groups[SimulationAtomGroupType::EnergyOutput].nr;
+        ng = groups->groups[SimulationAtomGroupType::EnergyOutput].size();
         if (ng == 1)
         {
             gmx_input("No energy groups defined. This is necessary for energy exclusion in the freeze group");
@@ -1161,12 +1161,12 @@ gmx_membed_t *init_membed(FILE *fplog, int nfile, const t_filenm fnm[], gmx_mtop
                 if (inputrec->opts.egp_flags[ng*i+j] == EGP_EXCL)
                 {
                     bExcl = TRUE;
-                    if ( (groups->groups[SimulationAtomGroupType::EnergyOutput].nm_ind[i] != ins_grp_id) ||
-                         (groups->groups[SimulationAtomGroupType::EnergyOutput].nm_ind[j] != ins_grp_id) )
+                    if ( (groups->groups[SimulationAtomGroupType::EnergyOutput][i] != ins_grp_id) ||
+                         (groups->groups[SimulationAtomGroupType::EnergyOutput][j] != ins_grp_id) )
                     {
                         gmx_fatal(FARGS, "Energy exclusions \"%s\" and  \"%s\" do not match the group "
-                                  "to embed \"%s\"", *groups->groupNames[groups->groups[SimulationAtomGroupType::EnergyOutput].nm_ind[i]],
-                                  *groups->groupNames[groups->groups[SimulationAtomGroupType::EnergyOutput].nm_ind[j]], ins);
+                                  "to embed \"%s\"", *groups->groupNames[groups->groups[SimulationAtomGroupType::EnergyOutput][i]],
+                                  *groups->groupNames[groups->groups[SimulationAtomGroupType::EnergyOutput][j]], ins);
                     }
                 }
             }
index cff50232c03c6443a8b53ec543ee8d8e56bc2431..05b941eb833c4fbc73dafe2b07a71f0c90cb0d3a 100644 (file)
@@ -323,42 +323,36 @@ class EnergyOutputTest : public ::testing::TestWithParam<EnergyOutputTestParamet
                 mtop_.groups.groupNames.emplace_back(&handle);
             }
 
-            mtop_.groups.groups[SimulationAtomGroupType::EnergyOutput].nr = 3;
-            snew(mtop_.groups.groups[SimulationAtomGroupType::EnergyOutput].nm_ind,
-                 mtop_.groups.groups[SimulationAtomGroupType::EnergyOutput].nr);
-            mtop_.groups.groups[SimulationAtomGroupType::EnergyOutput].nm_ind[0] = 0;
-            mtop_.groups.groups[SimulationAtomGroupType::EnergyOutput].nm_ind[1] = 1;
-            mtop_.groups.groups[SimulationAtomGroupType::EnergyOutput].nm_ind[2] = 2;
-
-            mtop_.groups.groups[SimulationAtomGroupType::TemperatureCoupling].nr = 3;
-            snew(mtop_.groups.groups[SimulationAtomGroupType::TemperatureCoupling].nm_ind,
-                 mtop_.groups.groups[SimulationAtomGroupType::TemperatureCoupling].nr);
-            mtop_.groups.groups[SimulationAtomGroupType::TemperatureCoupling].nm_ind[0] = 0;
-            mtop_.groups.groups[SimulationAtomGroupType::TemperatureCoupling].nm_ind[1] = 1;
-            mtop_.groups.groups[SimulationAtomGroupType::TemperatureCoupling].nm_ind[2] = 2;
-
-            mtop_.groups.groups[SimulationAtomGroupType::Acceleration].nr = 2;
-            snew(mtop_.groups.groups[SimulationAtomGroupType::Acceleration].nm_ind,
-                 mtop_.groups.groups[SimulationAtomGroupType::Acceleration].nr);
-            mtop_.groups.groups[SimulationAtomGroupType::Acceleration].nm_ind[0] = 0;
-            mtop_.groups.groups[SimulationAtomGroupType::Acceleration].nm_ind[1] = 2;
+            mtop_.groups.groups[SimulationAtomGroupType::EnergyOutput].resize(3);
+            mtop_.groups.groups[SimulationAtomGroupType::EnergyOutput][0] = 0;
+            mtop_.groups.groups[SimulationAtomGroupType::EnergyOutput][1] = 1;
+            mtop_.groups.groups[SimulationAtomGroupType::EnergyOutput][2] = 2;
+
+            mtop_.groups.groups[SimulationAtomGroupType::TemperatureCoupling].resize(3);
+            mtop_.groups.groups[SimulationAtomGroupType::TemperatureCoupling][0] = 0;
+            mtop_.groups.groups[SimulationAtomGroupType::TemperatureCoupling][1] = 1;
+            mtop_.groups.groups[SimulationAtomGroupType::TemperatureCoupling][2] = 2;
+
+            mtop_.groups.groups[SimulationAtomGroupType::Acceleration].resize(2);
+            mtop_.groups.groups[SimulationAtomGroupType::Acceleration][0] = 0;
+            mtop_.groups.groups[SimulationAtomGroupType::Acceleration][1] = 2;
 
             // Nose-Hoover chains
             inputrec_.bPrintNHChains     = true;
             inputrec_.opts.nhchainlength = 2;
-            state_.nosehoover_xi.resize(mtop_.groups.groups[SimulationAtomGroupType::TemperatureCoupling].nr*inputrec_.opts.nhchainlength);
-            state_.nosehoover_vxi.resize(mtop_.groups.groups[SimulationAtomGroupType::TemperatureCoupling].nr*inputrec_.opts.nhchainlength);
+            state_.nosehoover_xi.resize(mtop_.groups.groups[SimulationAtomGroupType::TemperatureCoupling].size()*inputrec_.opts.nhchainlength);
+            state_.nosehoover_vxi.resize(mtop_.groups.groups[SimulationAtomGroupType::TemperatureCoupling].size()*inputrec_.opts.nhchainlength);
 
             // This will be needed only with MTTK barostat
             state_.nhpres_xi.resize(1*inputrec_.opts.nhchainlength);
             state_.nhpres_vxi.resize(1*inputrec_.opts.nhchainlength);
 
             // Group pairs
-            enerdata_ = std::make_unique<gmx_enerdata_t>(mtop_.groups.groups[SimulationAtomGroupType::EnergyOutput].nr, 0);
+            enerdata_ = std::make_unique<gmx_enerdata_t>(mtop_.groups.groups[SimulationAtomGroupType::EnergyOutput].size(), 0);
 
             // Kinetic energy and related data
-            ekindata_.tcstat.resize(mtop_.groups.groups[SimulationAtomGroupType::TemperatureCoupling].nr);
-            ekindata_.grpstat.resize(mtop_.groups.groups[SimulationAtomGroupType::Acceleration].nr);
+            ekindata_.tcstat.resize(mtop_.groups.groups[SimulationAtomGroupType::TemperatureCoupling].size());
+            ekindata_.grpstat.resize(mtop_.groups.groups[SimulationAtomGroupType::Acceleration].size());
 
             // This is needed so that the ebin space will be allocated
             inputrec_.cos_accel = 1.0;
@@ -449,12 +443,12 @@ class EnergyOutputTest : public ::testing::TestWithParam<EnergyOutputTestParamet
             }
 
             // Kinetic energy and related data
-            for (int i = 0; i < mtop_.groups.groups[SimulationAtomGroupType::TemperatureCoupling].nr; i++)
+            for (int i = 0; i < gmx::ssize(mtop_.groups.groups[SimulationAtomGroupType::TemperatureCoupling]); i++)
             {
                 ekindata_.tcstat[i].T      = (*testValue += 0.1);
                 ekindata_.tcstat[i].lambda = (*testValue += 0.1);
             }
-            for (int i = 0; i < mtop_.groups.groups[SimulationAtomGroupType::Acceleration].nr; i++)
+            for (int i = 0; i < gmx::ssize(mtop_.groups.groups[SimulationAtomGroupType::Acceleration]); i++)
             {
                 ekindata_.grpstat[i].u[XX] = (*testValue += 0.1);
                 ekindata_.grpstat[i].u[YY] = (*testValue += 0.1);
@@ -548,7 +542,7 @@ class EnergyOutputTest : public ::testing::TestWithParam<EnergyOutputTestParamet
                 inputrec_.opts.ref_t[i] = (*testValue += 0.1);
             }
 
-            for (int k = 0; k < mtop_.groups.groups[SimulationAtomGroupType::TemperatureCoupling].nr*inputrec_.opts.nhchainlength; k++)
+            for (int k = 0; k < gmx::ssize(mtop_.groups.groups[SimulationAtomGroupType::TemperatureCoupling])*inputrec_.opts.nhchainlength; k++)
             {
                 state_.nosehoover_xi[k]  = (*testValue += 0.1);
                 state_.nosehoover_vxi[k] = (*testValue += 0.1);
index c21afd2ec5f5d8c3d7e02f7c65700354b45a69b0..1388d1ebb457c43d5559ad96ac079de01383904f 100644 (file)
@@ -68,7 +68,7 @@ t_vcm::t_vcm(const SimulationGroups &groups, const t_inputrec &ir)
 
     if (mode != ecmNO)
     {
-        nr = groups.groups[SimulationAtomGroupType::MassCenterVelocityRemoval].nr;
+        nr = groups.groups[SimulationAtomGroupType::MassCenterVelocityRemoval].size();
         /* Allocate one extra for a possible rest group */
         size = nr + 1;
         /* We need vcm->nr+1 elements per thread, but to avoid cache
@@ -93,7 +93,7 @@ t_vcm::t_vcm(const SimulationGroups &groups, const t_inputrec &ir)
         for (int g = 0; (g < nr); g++)
         {
             group_ndf[g]  = ir.opts.nrdf[g];
-            group_name[g] = *groups.groupNames[groups.groups[SimulationAtomGroupType::MassCenterVelocityRemoval].nm_ind[g]];
+            group_name[g] = *groups.groupNames[groups.groups[SimulationAtomGroupType::MassCenterVelocityRemoval][g]];
 
         }
 
index 3f086e6898a9367e5b7e32bedeb04b655294d79a..b10b14b69b048965e2e377dfdebead44eccedc2c 100644 (file)
@@ -64,11 +64,10 @@ void make_wall_tables(FILE *fplog,
                       t_forcerec *fr)
 {
     int           negp_pp;
-    int          *nm_ind;
     char          buf[STRLEN];
 
     negp_pp = ir->opts.ngener - ir->nwall;
-    nm_ind  = groups->groups[SimulationAtomGroupType::EnergyOutput].nm_ind;
+    gmx::ArrayRef<const int> nm_ind  = groups->groups[SimulationAtomGroupType::EnergyOutput];
 
     if (fplog)
     {
index 54e60c4abc7234045c39504555ac2b3d5c239cae..5fc025198c2e9853544717910bc62e0d1205191c 100644 (file)
@@ -1500,7 +1500,7 @@ int Mdrunner::mdrunner()
                                                    cr, ms, nrnb, wcycle, fr->bMolPBC);
 
         /* Energy terms and groups */
-        gmx_enerdata_t enerd(mtop.groups.groups[SimulationAtomGroupType::EnergyOutput].nr, inputrec->fepvals->n_lambda);
+        gmx_enerdata_t enerd(mtop.groups.groups[SimulationAtomGroupType::EnergyOutput].size(), inputrec->fepvals->n_lambda);
 
         /* Set up interactive MD (IMD) */
         auto imdSession = makeImdSession(inputrec, cr, wcycle, &enerd, ms, &mtop, mdlog,
index 3a601fd3c600462f3f5184554e10df10fd6fe466..1f50b1e063ebc2a2fa5d725da972662fff27cf93 100644 (file)
@@ -348,7 +348,7 @@ Integrator::do_tpi()
         }
     }
 
-    ngid   = groups->groups[SimulationAtomGroupType::EnergyOutput].nr;
+    ngid   = groups->groups[SimulationAtomGroupType::EnergyOutput].size();
     // TODO: Figure out which energy group to use
 #if 0
     gid_tp = GET_CGINFO_GID(fr->cginfo[cg_tp]);
@@ -400,7 +400,7 @@ Integrator::do_tpi()
         for (i = 0; i < ngid; i++)
         {
             sprintf(str, "f. <U\\sVdW %s\\Ne\\S-\\betaU\\N>",
-                    *(groups->groupNames[groups->groups[SimulationAtomGroupType::EnergyOutput].nm_ind[i]]));
+                    *(groups->groupNames[groups->groups[SimulationAtomGroupType::EnergyOutput][i]]));
             leg[e++] = gmx_strdup(str);
         }
         if (bDispCorr)
@@ -413,7 +413,7 @@ Integrator::do_tpi()
             for (i = 0; i < ngid; i++)
             {
                 sprintf(str, "f. <U\\sCoul %s\\Ne\\S-\\betaU\\N>",
-                        *(groups->groupNames[groups->groups[SimulationAtomGroupType::EnergyOutput].nm_ind[i]]));
+                        *(groups->groupNames[groups->groups[SimulationAtomGroupType::EnergyOutput][i]]));
                 leg[e++] = gmx_strdup(str);
             }
             if (bRFExcl)
index 28e82c5062e2819dbbe68c585d6edb5e0e864d8f..f39a07cea5e49153441dbdc30e898a29117338b9 100644 (file)
@@ -163,7 +163,7 @@ void list_tpr(const char *fn,
         gmx::EnumerationArray < SimulationAtomGroupType, std::vector < int>> gcount;
         for (auto group : keysOf(gcount))
         {
-            gcount[group].resize(groups.groups[group].nr);
+            gcount[group].resize(groups.groups[group].size());
         }
 
         for (int i = 0; (i < mtop.natoms); i++)
@@ -178,10 +178,10 @@ void list_tpr(const char *fn,
         {
             atot = 0;
             printf("%-12s: ", shortName(group));
-            for (int j = 0; (j < groups.groups[group].nr); j++)
+            for (const auto &entry : gcount[group])
             {
-                printf("  %5d", gcount[group][j]);
-                atot += gcount[group][j];
+                printf("  %5d", entry);
+                atot += entry;
             }
             printf("  (total %d atoms)\n", atot);
         }
index 09ac28df056427488ac7d336cb174a156d749911..f9594b6aae422bb5ad8a5b8d8065c78b7a0758b6 100644 (file)
@@ -39,6 +39,8 @@
 
 #include <stdio.h>
 
+#include <vector>
+
 #include "gromacs/utility/basedefinitions.h"
 #include "gromacs/utility/real.h"
 #include "gromacs/utility/unique_cptr.h"
@@ -96,11 +98,8 @@ typedef struct t_pdbinfo
     int      uij[6];            /* Anisotropic B-factor                 */
 } t_pdbinfo;
 
-typedef struct t_grps
-{
-    int   nr;                   /* Number of different groups           */
-    int  *nm_ind;               /* Index in the group names             */
-} t_grps;
+//! Contains indices into group names for different groups.
+using AtomGroupIndices = std::vector<int>;
 
 typedef struct t_atoms
 {
index ffbc05101197fe8eba61e5851f7c4c603f60d6f8..d43ae865b6597eaa1cadfb1d3d7d19cf7d2b8eb3 100644 (file)
@@ -74,16 +74,6 @@ const char *shortName(SimulationAtomGroupType type)
     return c_simulationAtomGroupTypeShortNames[type];
 }
 
-SimulationGroups::SimulationGroups()
-{
-    for (auto group : keysOf(groups))
-    {
-        groups[group].nr     = 0;
-        groups[group].nm_ind = nullptr;
-    }
-
-}
-
 void init_top(t_topology *top)
 {
     top->name = nullptr;
@@ -112,18 +102,6 @@ gmx_moltype_t::~gmx_moltype_t()
     done_blocka(&excls);
 }
 
-SimulationGroups::~SimulationGroups()
-{
-    for (auto group : keysOf(groups))
-    {
-        if (nullptr != groups[group].nm_ind)
-        {
-            sfree(groups[group].nm_ind);
-            groups[group].nm_ind = nullptr;
-        }
-    }
-}
-
 gmx_mtop_t::gmx_mtop_t()
 {
     init_atomtypes(&atomtypes);
@@ -245,18 +223,18 @@ bool gmx_mtop_has_pdbinfo(const gmx_mtop_t *mtop)
     return mtop->moltype.empty() || mtop->moltype[0].atoms.havePdbInfo;
 }
 
-static void pr_grps(FILE                       *fp,
-                    const char                 *title,
-                    gmx::ArrayRef<const t_grps> grps,
-                    char                     ***grpname)
+static void pr_grps(FILE                                 *fp,
+                    const char                           *title,
+                    gmx::ArrayRef<const AtomGroupIndices> grps,
+                    char                               ***grpname)
 {
     int index = 0;
     for (const auto &group : grps)
     {
-        fprintf(fp, "%s[%-12s] nr=%d, name=[", title, c_simulationAtomGroupTypeShortNames[index], group.nr);
-        for (int j = 0; (j < group.nr); j++)
+        fprintf(fp, "%s[%-12s] nr=%zu, name=[", title, c_simulationAtomGroupTypeShortNames[index], group.size());
+        for (const auto &entry : group)
         {
-            fprintf(fp, " %s", *(grpname[group.nm_ind[j]]));
+            fprintf(fp, " %s", *(grpname[entry]));
         }
         fprintf(fp, "]\n");
         index++;
@@ -678,15 +656,15 @@ void compareAtomGroups(FILE *fp, const SimulationGroups &g0, const SimulationGro
     for (auto group : keysOf(g0.groups))
     {
         std::string buf = gmx::formatString("grps[%d].nr", static_cast<int>(group));
-        cmp_int(fp, buf.c_str(), -1, g0.groups[group].nr, g1.groups[group].nr);
-        if (g0.groups[group].nr == g1.groups[group].nr)
+        cmp_int(fp, buf.c_str(), -1, g0.groups[group].size(), g1.groups[group].size());
+        if (g0.groups[group].size() == g1.groups[group].size())
         {
-            for (int j = 0; j < g0.groups[group].nr; j++)
+            for (int j = 0; j < gmx::ssize(g0.groups[group]); j++)
             {
                 buf = gmx::formatString("grps[%d].name[%d]", static_cast<int>(group), j);
                 cmp_str(fp, buf.c_str(), -1,
-                        *g0.groupNames[g0.groups[group].nm_ind[j]],
-                        *g1.groupNames[g1.groups[group].nm_ind[j]]);
+                        *g0.groupNames[g0.groups[group][j]],
+                        *g1.groupNames[g1.groups[group][j]]);
             }
         }
         cmp_int(fp, "ngrpnr", static_cast<int>(group), g0.numberOfGroupNumbers(group), g1.numberOfGroupNumbers(group));
index 31bc288694fb05f51a1bafde0aa22fd146b15247..e4159ed6ea17c05b8225bcd80eada97bd7722527 100644 (file)
@@ -117,14 +117,10 @@ struct MoleculeBlockIndices
  */
 struct SimulationGroups
 {
-    SimulationGroups();
-
-    ~SimulationGroups();
-
     //! Groups of particles
-    gmx::EnumerationArray<SimulationAtomGroupType, t_grps>                     groups;
+    gmx::EnumerationArray<SimulationAtomGroupType, AtomGroupIndices>                     groups;
     //! Names of groups, stored as pointer to the entries in the symbol table.
-    std::vector<char **>                                                       groupNames;
+    std::vector<char **>                                                                 groupNames;
     //! Group numbers for the different SimulationAtomGroupType groups.
     gmx::EnumerationArray < SimulationAtomGroupType, std::vector < unsigned char>> groupNumbers;