From 5db7b9d7356c00316c0ce115c632cd3c0712eea7 Mon Sep 17 00:00:00 2001 From: Paul Bauer Date: Tue, 2 Apr 2019 12:36:58 +0200 Subject: [PATCH] Replace t_grps with std::vector Refs #2833 Change-Id: Ia1f156fec4c6c24f4c29a792e384668d835416f0 --- src/gromacs/fileio/enxio.cpp | 2 +- src/gromacs/fileio/tngio.cpp | 2 +- src/gromacs/fileio/tpxio.cpp | 13 ++-- src/gromacs/gmxpreprocess/readir.cpp | 90 ++++++++++++------------ src/gromacs/mdlib/broadcaststructs.cpp | 8 +-- src/gromacs/mdlib/energyoutput.cpp | 32 ++++----- src/gromacs/mdlib/forcerec.cpp | 12 ++-- src/gromacs/mdlib/mdatoms.cpp | 4 +- src/gromacs/mdlib/membed.cpp | 14 ++-- src/gromacs/mdlib/tests/energyoutput.cpp | 48 ++++++------- src/gromacs/mdlib/vcm.cpp | 4 +- src/gromacs/mdlib/wall.cpp | 3 +- src/gromacs/mdrun/runner.cpp | 2 +- src/gromacs/mdrun/tpi.cpp | 6 +- src/gromacs/tools/dump.cpp | 8 +-- src/gromacs/topology/atoms.h | 9 ++- src/gromacs/topology/topology.cpp | 46 ++++-------- src/gromacs/topology/topology.h | 8 +-- 18 files changed, 138 insertions(+), 173 deletions(-) diff --git a/src/gromacs/fileio/enxio.cpp b/src/gromacs/fileio/enxio.cpp index 35be6cb9e0..f0d22ae4a9 100644 --- a/src/gromacs/fileio/enxio.cpp +++ b/src/gromacs/fileio/enxio.cpp @@ -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++) { diff --git a/src/gromacs/fileio/tngio.cpp b/src/gromacs/fileio/tngio.cpp index c6e2917697..862bb2c1b0 100644 --- a/src/gromacs/fileio/tngio.cpp +++ b/src/gromacs/fileio/tngio.cpp @@ -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); diff --git a/src/gromacs/fileio/tpxio.cpp b/src/gromacs/fileio/tpxio.cpp index 5e7c77c73b..7659e730ed 100644 --- a/src/gromacs/fileio/tpxio.cpp +++ b/src/gromacs/fileio/tpxio.cpp @@ -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 grps, - gmx_bool bRead) +static void do_grps(t_fileio *fio, + gmx::ArrayRef 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); } } diff --git a/src/gromacs/gmxpreprocess/readir.cpp b/src/gromacs/gmxpreprocess/readir.cpp index 7774199656..60401e169f 100644 --- a/src/gromacs/gmxpreprocess/readir.cpp +++ b/src/gromacs/gmxpreprocess/readir.cpp @@ -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]; } diff --git a/src/gromacs/mdlib/broadcaststructs.cpp b/src/gromacs/mdlib/broadcaststructs.cpp index ef7dd2ee50..94c80855d2 100644 --- a/src/gromacs/mdlib/broadcaststructs.cpp +++ b/src/gromacs/mdlib/broadcaststructs.cpp @@ -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 grps) +static void bc_grps(const t_commrec *cr, gmx::ArrayRef 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); } } diff --git a/src/gromacs/mdlib/energyoutput.cpp b/src/gromacs/mdlib/energyoutput.cpp index 9418e4170d..2f03c787c9 100644 --- a/src/gromacs/mdlib/energyoutput.cpp +++ b/src/gromacs/mdlib/energyoutput.cpp @@ -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); } diff --git a/src/gromacs/mdlib/forcerec.cpp b/src/gromacs/mdlib/forcerec.cpp index d66280e64d..3c625533fb 100644 --- a/src/gromacs/mdlib/forcerec.cpp +++ b/src/gromacs/mdlib/forcerec.cpp @@ -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 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); diff --git a/src/gromacs/mdlib/mdatoms.cpp b/src/gromacs/mdlib/mdatoms.cpp index 84d73f4fd3..3ff5a699ae 100644 --- a/src/gromacs/mdlib/mdatoms.cpp +++ b/src/gromacs/mdlib/mdatoms.cpp @@ -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; } diff --git a/src/gromacs/mdlib/membed.cpp b/src/gromacs/mdlib/membed.cpp index b2999ca05f..c3ccdafec3 100644 --- a/src/gromacs/mdlib/membed.cpp +++ b/src/gromacs/mdlib/membed.cpp @@ -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); } } } diff --git a/src/gromacs/mdlib/tests/energyoutput.cpp b/src/gromacs/mdlib/tests/energyoutput.cpp index cff50232c0..05b941eb83 100644 --- a/src/gromacs/mdlib/tests/energyoutput.cpp +++ b/src/gromacs/mdlib/tests/energyoutput.cpp @@ -323,42 +323,36 @@ class EnergyOutputTest : public ::testing::TestWithParam(mtop_.groups.groups[SimulationAtomGroupType::EnergyOutput].nr, 0); + enerdata_ = std::make_unique(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::TestWithParamnr+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]]; } diff --git a/src/gromacs/mdlib/wall.cpp b/src/gromacs/mdlib/wall.cpp index 3f086e6898..b10b14b69b 100644 --- a/src/gromacs/mdlib/wall.cpp +++ b/src/gromacs/mdlib/wall.cpp @@ -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 nm_ind = groups->groups[SimulationAtomGroupType::EnergyOutput]; if (fplog) { diff --git a/src/gromacs/mdrun/runner.cpp b/src/gromacs/mdrun/runner.cpp index 54e60c4abc..5fc025198c 100644 --- a/src/gromacs/mdrun/runner.cpp +++ b/src/gromacs/mdrun/runner.cpp @@ -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, diff --git a/src/gromacs/mdrun/tpi.cpp b/src/gromacs/mdrun/tpi.cpp index 3a601fd3c6..1f50b1e063 100644 --- a/src/gromacs/mdrun/tpi.cpp +++ b/src/gromacs/mdrun/tpi.cpp @@ -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. ", - *(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. ", - *(groups->groupNames[groups->groups[SimulationAtomGroupType::EnergyOutput].nm_ind[i]])); + *(groups->groupNames[groups->groups[SimulationAtomGroupType::EnergyOutput][i]])); leg[e++] = gmx_strdup(str); } if (bRFExcl) diff --git a/src/gromacs/tools/dump.cpp b/src/gromacs/tools/dump.cpp index 28e82c5062..f39a07cea5 100644 --- a/src/gromacs/tools/dump.cpp +++ b/src/gromacs/tools/dump.cpp @@ -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); } diff --git a/src/gromacs/topology/atoms.h b/src/gromacs/topology/atoms.h index 09ac28df05..f9594b6aae 100644 --- a/src/gromacs/topology/atoms.h +++ b/src/gromacs/topology/atoms.h @@ -39,6 +39,8 @@ #include +#include + #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; typedef struct t_atoms { diff --git a/src/gromacs/topology/topology.cpp b/src/gromacs/topology/topology.cpp index ffbc051011..d43ae865b6 100644 --- a/src/gromacs/topology/topology.cpp +++ b/src/gromacs/topology/topology.cpp @@ -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 grps, - char ***grpname) +static void pr_grps(FILE *fp, + const char *title, + gmx::ArrayRef 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(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(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(group), g0.numberOfGroupNumbers(group), g1.numberOfGroupNumbers(group)); diff --git a/src/gromacs/topology/topology.h b/src/gromacs/topology/topology.h index 31bc288694..e4159ed6ea 100644 --- a/src/gromacs/topology/topology.h +++ b/src/gromacs/topology/topology.h @@ -117,14 +117,10 @@ struct MoleculeBlockIndices */ struct SimulationGroups { - SimulationGroups(); - - ~SimulationGroups(); - //! Groups of particles - gmx::EnumerationArray groups; + gmx::EnumerationArray groups; //! Names of groups, stored as pointer to the entries in the symbol table. - std::vector groupNames; + std::vector groupNames; //! Group numbers for the different SimulationAtomGroupType groups. gmx::EnumerationArray < SimulationAtomGroupType, std::vector < unsigned char>> groupNumbers; -- 2.22.0