Change gmx_localtop_t to C++
authorPaul Bauer <paul.bauer.q@gmail.com>
Thu, 13 Sep 2018 12:19:40 +0000 (14:19 +0200)
committerMark Abraham <mark.j.abraham@gmail.com>
Fri, 4 Jan 2019 16:30:36 +0000 (17:30 +0100)
Changes the localtop topology structure to C++.

Cases where the object could be allocated on the stack have
been changed in that way. In other places, unique_ptr is now
used for the allocation.

Changed callers that returned a pointer to a new gmx_localtop_t
to instead take a pointer to the datastructure that will be
populated.

gmx_localtop_t is by default managing its own memory, but can be changed
to not do this. This is needed for the domain decomposition as it is not
expected to free memory owned by mtop there.

This is part of the larger aim of modernizing the topology
datastructures to C++.

Changed const pointers to const references where encountered during the
change.

Change-Id: I619533f5dc332332f1652afb24266bc2dae67d4c

21 files changed:
src/gromacs/domdec/domdec.h
src/gromacs/domdec/domdec_topology.cpp
src/gromacs/domdec/partition.cpp
src/gromacs/domdec/partition.h
src/gromacs/gmxana/gmx_disre.cpp
src/gromacs/gmxana/gmx_nmr.cpp
src/gromacs/mdlib/mdsetup.cpp
src/gromacs/mdlib/mdsetup.h
src/gromacs/mdrun/md.cpp
src/gromacs/mdrun/mimic.cpp
src/gromacs/mdrun/minimize.cpp
src/gromacs/mdrun/rerun.cpp
src/gromacs/mdrun/tpi.cpp
src/gromacs/tools/check.cpp
src/gromacs/topology/block.cpp
src/gromacs/topology/block.h
src/gromacs/topology/mtop_util.cpp
src/gromacs/topology/mtop_util.h
src/gromacs/topology/topology.cpp
src/gromacs/topology/topology.h
src/gromacs/trajectoryanalysis/topologyinformation.cpp

index 61044f8c17067fc0e726dfc7ef06f9239bb58d6c..56208a19308fc65ce607a112c4053d0711066a08 100644 (file)
@@ -1,7 +1,8 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2005,2006,2007,2008,2009,2010,2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2005 - 2014, The GROMACS development team.
+ * Copyright (c) 2015,2016,2017,2018,2019, 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.
@@ -323,20 +324,29 @@ void dd_make_reverse_top(FILE *fplog,
 void dd_make_local_cgs(struct gmx_domdec_t *dd, t_block *lcgs);
 
 /*! \brief Generate the local topology and virtual site data */
-void dd_make_local_top(struct gmx_domdec_t *dd, struct gmx_domdec_zones_t *zones,
-                       int npbcdim, matrix box,
-                       rvec cellsize_min, const ivec npulse,
-                       t_forcerec *fr,
-                       rvec *cgcm_or_x,
-                       gmx_vsite_t *vsite,
-                       const gmx_mtop_t *top, gmx_localtop_t *ltop);
+void dd_make_local_top(struct gmx_domdec_t       *dd,
+                       struct gmx_domdec_zones_t *zones,
+                       int                        npbcdim,
+                       matrix                     box,
+                       rvec                       cellsize_min,
+                       const ivec                 npulse,
+                       t_forcerec                *fr,
+                       rvec                      *cgcm_or_x,
+                       gmx_vsite_t               *vsite,
+                       const gmx_mtop_t          &top,
+                       gmx_localtop_t            *ltop);
 
 /*! \brief Sort ltop->ilist when we are doing free energy. */
 void dd_sort_local_top(gmx_domdec_t *dd, const t_mdatoms *mdatoms,
                        gmx_localtop_t *ltop);
 
-/*! \brief Construct local topology */
-gmx_localtop_t *dd_init_local_top(const gmx_mtop_t *top_global);
+/*! \brief Initialize local topology
+ *
+ * \param[in] top_global Reference to global topology.
+ * \param[in,out] top Pointer to new local topology
+ */
+void dd_init_local_top(const gmx_mtop_t &top_global,
+                       gmx_localtop_t   *top);
 
 /*! \brief Construct local state */
 void dd_init_local_state(struct gmx_domdec_t *dd,
index 1079f366967a7b00ca877e80bb92c4fd14e07f4e..663af6796dacf0e552dd9760e09378a24a38d282 100644 (file)
@@ -1,7 +1,8 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2006 - 2014, The GROMACS development team.
+ * Copyright (c) 2015,2016,2017,2018,2019, 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.
@@ -2069,7 +2070,7 @@ void dd_make_local_top(gmx_domdec_t *dd, gmx_domdec_zones_t *zones,
                        t_forcerec *fr,
                        rvec *cgcm_or_x,
                        gmx_vsite_t *vsite,
-                       const gmx_mtop_t *mtop, gmx_localtop_t *ltop)
+                       const gmx_mtop_t &mtop, gmx_localtop_t *ltop)
 {
     gmx_bool bRCheckMB, bRCheck2B;
     real     rc = -1;
@@ -2139,7 +2140,7 @@ void dd_make_local_top(gmx_domdec_t *dd, gmx_domdec_zones_t *zones,
     }
 
     dd->nbonded_local =
-        make_local_bondeds_excls(dd, zones, mtop, fr->cginfo,
+        make_local_bondeds_excls(dd, zones, &mtop, fr->cginfo,
                                  bRCheckMB, rcheck, bRCheck2B, rc,
                                  dd->localAtomGroupFromAtom.data(),
                                  pbc_null, cgcm_or_x,
@@ -2156,7 +2157,7 @@ void dd_make_local_top(gmx_domdec_t *dd, gmx_domdec_zones_t *zones,
         dd->nbonded_local += nexcl;
     }
 
-    ltop->atomtypes  = mtop->atomtypes;
+    ltop->atomtypes  = mtop.atomtypes;
 }
 
 void dd_sort_local_top(gmx_domdec_t *dd, const t_mdatoms *mdatoms,
@@ -2172,24 +2173,20 @@ void dd_sort_local_top(gmx_domdec_t *dd, const t_mdatoms *mdatoms,
     }
 }
 
-gmx_localtop_t *dd_init_local_top(const gmx_mtop_t *top_global)
+void dd_init_local_top(const gmx_mtop_t &top_global,
+                       gmx_localtop_t   *top)
 {
-    gmx_localtop_t *top;
-
-    snew(top, 1);
-
     /* TODO: Get rid of the const casts below, e.g. by using a reference */
-    top->idef.ntypes     = top_global->ffparams.numTypes();
-    top->idef.atnr       = top_global->ffparams.atnr;
-    top->idef.functype   = const_cast<t_functype *>(top_global->ffparams.functype.data());
-    top->idef.iparams    = const_cast<t_iparams *>(top_global->ffparams.iparams.data());
-    top->idef.fudgeQQ    = top_global->ffparams.fudgeQQ;
+    top->idef.ntypes     = top_global.ffparams.numTypes();
+    top->idef.atnr       = top_global.ffparams.atnr;
+    top->idef.functype   = const_cast<t_functype *>(top_global.ffparams.functype.data());
+    top->idef.iparams    = const_cast<t_iparams *>(top_global.ffparams.iparams.data());
+    top->idef.fudgeQQ    = top_global.ffparams.fudgeQQ;
     top->idef.cmap_grid  = new gmx_cmap_t;
-    *top->idef.cmap_grid = top_global->ffparams.cmap_grid;
-
-    top->idef.ilsort     = ilsortUNKNOWN;
+    *top->idef.cmap_grid = top_global.ffparams.cmap_grid;
 
-    return top;
+    top->idef.ilsort    = ilsortUNKNOWN;
+    top->useInDomainDecomp_ = true;
 }
 
 void dd_init_local_state(gmx_domdec_t *dd,
index 252477f65136b4ec001e725fdd153d2560276723..df96239fa8932f72dc35cfec4fa954fa77356071 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2018, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019, 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.
@@ -3002,7 +3002,7 @@ void dd_partition_system(FILE                    *fplog,
                          gmx_bool                 bMasterState,
                          int                      nstglobalcomm,
                          t_state                 *state_global,
-                         const gmx_mtop_t        *top_global,
+                         const gmx_mtop_t        &top_global,
                          const t_inputrec        *ir,
                          t_state                 *state_local,
                          PaddedVector<gmx::RVec> *f,
@@ -3243,7 +3243,7 @@ void dd_partition_system(FILE                    *fplog,
                   true, xGlobal,
                   &ddbox);
 
-        distributeState(mdlog, dd, *top_global, state_global, ddbox, state_local, f);
+        distributeState(mdlog, dd, top_global, state_global, ddbox, state_local, f);
 
         dd_make_local_cgs(dd, &top_local->cgs);
 
@@ -3536,7 +3536,7 @@ void dd_partition_system(FILE                    *fplog,
                 if (dd->splitConstraints || dd->splitSettles)
                 {
                     /* Only for inter-cg constraints we need special code */
-                    n = dd_make_local_constraints(dd, n, top_global, fr->cginfo,
+                    n = dd_make_local_constraints(dd, n, &top_global, fr->cginfo,
                                                   constr, ir->nProjOrder,
                                                   top_local->idef.il);
                 }
@@ -3640,7 +3640,7 @@ void dd_partition_system(FILE                    *fplog,
     if (comm->nstDDDump > 0 && step % comm->nstDDDump == 0)
     {
         dd_move_x(dd, state_local->box, state_local->x, nullWallcycle);
-        write_dd_pdb("dd_dump", step, "dump", top_global, cr,
+        write_dd_pdb("dd_dump", step, "dump", &top_global, cr,
                      -1, state_local->x.rvec_array(), state_local->box);
     }
 
@@ -3662,7 +3662,7 @@ void dd_partition_system(FILE                    *fplog,
     if (comm->DD_debug > 0)
     {
         /* Set the env var GMX_DD_DEBUG if you suspect corrupted indices */
-        check_index_consistency(dd, top_global->natoms, ncg_mtop(top_global),
+        check_index_consistency(dd, top_global.natoms, ncg_mtop(&top_global),
                                 "after partitioning");
     }
 
index be4885414ee72a79aa3622ca74efb932b7fd8605..2bdeacbc3085e8d5b101885cc6ed6e1f54b1fbb8 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2018, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019, 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.
@@ -93,7 +93,7 @@ void dd_partition_system(FILE                    *fplog,
                          gmx_bool                 bMasterState,
                          int                      nstglobalcomm,
                          t_state                 *state_global,
-                         const gmx_mtop_t        *top_global,
+                         const gmx_mtop_t        &top_global,
                          const t_inputrec        *ir,
                          t_state                 *state_local,
                          PaddedVector<gmx::RVec> *f,
index 52973b9c4138553c8ec36b9e5a30b1cc286ae43b..96a6cfd6221d33af188a60f9029723893b197276 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, 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.
@@ -70,6 +70,7 @@
 #include "gromacs/topology/index.h"
 #include "gromacs/topology/mtop_util.h"
 #include "gromacs/topology/topology.h"
+#include "gromacs/trajectoryanalysis/topologyinformation.h"
 #include "gromacs/utility/arraysize.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/futil.h"
@@ -658,15 +659,11 @@ int gmx_disre(int argc, char *argv[])
     };
 
     FILE             *out = nullptr, *aver = nullptr, *numv = nullptr, *maxxv = nullptr, *xvg = nullptr;
-    t_tpxheader       header;
-    gmx_mtop_t        mtop;
-    rvec             *xtop;
-    gmx_localtop_t   *top;
-    t_atoms          *atoms = nullptr;
+    gmx_localtop_t    top;
     t_fcdata          fcd;
     t_nrnb            nrnb;
     t_graph          *g;
-    int               ntopatoms, natoms, i, j, kkk;
+    int               i, j, kkk;
     t_trxstatus      *status;
     real              t;
     rvec             *x, *xav = nullptr;
@@ -718,9 +715,10 @@ int gmx_disre(int argc, char *argv[])
     t_inputrec      irInstance;
     t_inputrec     *ir = &irInstance;
 
-    read_tpxheader(ftp2fn(efTPR, NFILE, fnm), &header, FALSE);
-    snew(xtop, header.natoms);
-    read_tpx(ftp2fn(efTPR, NFILE, fnm), ir, box, &ntopatoms, xtop, nullptr, &mtop);
+    gmx::TopologyInformation topInfo;
+    topInfo.fillFromInputFile(ftp2fn(efTPR, NFILE, fnm));
+    int ntopatoms = topInfo.mtop()->natoms;
+    AtomsDataPtr atoms;
     bPDB = opt2bSet("-q", NFILE, fnm);
     if (bPDB)
     {
@@ -733,8 +731,7 @@ int gmx_disre(int argc, char *argv[])
             ind_fit[kkk] = kkk;
         }
 
-        snew(atoms, 1);
-        *atoms = gmx_mtop_global_atoms(&mtop);
+        atoms = topInfo.copyAtoms();
 
         if (atoms->pdbinfo == nullptr)
         {
@@ -743,7 +740,7 @@ int gmx_disre(int argc, char *argv[])
         atoms->havePdbInfo = TRUE;
     }
 
-    top = gmx_mtop_generate_local_top(&mtop, ir->efep != efepNO);
+    gmx_mtop_generate_local_top(*topInfo.mtop(), &top, ir->efep != efepNO);
 
     g        = nullptr;
     pbc_null = nullptr;
@@ -755,7 +752,7 @@ int gmx_disre(int argc, char *argv[])
         }
         else
         {
-            g = mk_graph(fplog, &top->idef, 0, mtop.natoms, FALSE, FALSE);
+            g = mk_graph(fplog, &top.idef, 0, ntopatoms, FALSE, FALSE);
         }
     }
 
@@ -782,9 +779,9 @@ int gmx_disre(int argc, char *argv[])
     }
 
     ir->dr_tau = 0.0;
-    init_disres(fplog, &mtop, ir, nullptr, nullptr, &fcd, nullptr, FALSE);
+    init_disres(fplog, topInfo.mtop(), ir, nullptr, nullptr, &fcd, nullptr, FALSE);
 
-    natoms = read_first_x(oenv, &status, ftp2fn(efTRX, NFILE, fnm), &t, &x, box);
+    int natoms = read_first_x(oenv, &status, ftp2fn(efTRX, NFILE, fnm), &t, &x, box);
     snew(f, 5*natoms);
 
     init_dr_res(&dr, fcd.disres.nres);
@@ -809,13 +806,13 @@ int gmx_disre(int argc, char *argv[])
                          "Largest Violation", "Time (ps)", "nm", oenv);
     }
 
-    auto mdAtoms = gmx::makeMDAtoms(fplog, mtop, *ir, false);
-    atoms2md(&mtop, ir, -1, nullptr, mtop.natoms, mdAtoms.get());
+    auto mdAtoms = gmx::makeMDAtoms(fplog, *topInfo.mtop(), *ir, false);
+    atoms2md(topInfo.mtop(), ir, -1, nullptr, ntopatoms, mdAtoms.get());
     update_mdatoms(mdAtoms->mdatoms(), ir->fepvals->init_lambda);
     init_nrnb(&nrnb);
     if (ir->ePBC != epbcNONE)
     {
-        gpbc = gmx_rmpbc_init(&top->idef, ir->ePBC, natoms);
+        gpbc = gmx_rmpbc_init(&top.idef, ir->ePBC, natoms);
     }
 
     j = 0;
@@ -841,14 +838,14 @@ int gmx_disre(int argc, char *argv[])
             }
             my_clust = clust->inv_clust[j];
             range_check(my_clust, 0, clust->clust->nr);
-            check_viol(fplog, &(top->idef.il[F_DISRES]),
-                       top->idef.iparams,
+            check_viol(fplog, &(top.idef.il[F_DISRES]),
+                       top.idef.iparams,
                        x, f, pbc_null, g, dr_clust, my_clust, isize, index, vvindex, &fcd);
         }
         else
         {
-            check_viol(fplog, &(top->idef.il[F_DISRES]),
-                       top->idef.iparams,
+            check_viol(fplog, &(top.idef.il[F_DISRES]),
+                       top.idef.iparams,
                        x, f, pbc_null, g, &dr, 0, isize, index, vvindex, &fcd);
         }
         if (bPDB)
@@ -893,23 +890,23 @@ int gmx_disre(int argc, char *argv[])
 
     if (clust)
     {
-        dump_clust_stats(fplog, fcd.disres.nres, &(top->idef.il[F_DISRES]),
-                         top->idef.iparams, clust->clust, dr_clust,
+        dump_clust_stats(fplog, fcd.disres.nres, &(top.idef.il[F_DISRES]),
+                         top.idef.iparams, clust->clust, dr_clust,
                          clust->grpname, isize, index);
     }
     else
     {
-        dump_stats(fplog, j, fcd.disres.nres, &(top->idef.il[F_DISRES]),
-                   top->idef.iparams, &dr, isize, index,
-                   bPDB ? atoms : nullptr);
+        dump_stats(fplog, j, fcd.disres.nres, &(top.idef.il[F_DISRES]),
+                   top.idef.iparams, &dr, isize, index,
+                   bPDB ? atoms.get() : nullptr);
         if (bPDB)
         {
             write_sto_conf(opt2fn("-q", NFILE, fnm),
                            "Coloured by average violation in Angstrom",
-                           atoms, xav, nullptr, ir->ePBC, box);
+                           atoms.get(), xav, nullptr, ir->ePBC, box);
         }
         dump_disre_matrix(opt2fn_null("-x", NFILE, fnm), &dr, fcd.disres.nres,
-                          j, &top->idef, &mtop, max_dr, nlevels, bThird);
+                          j, &top.idef, topInfo.mtop(), max_dr, nlevels, bThird);
         xvgrclose(out);
         xvgrclose(aver);
         xvgrclose(numv);
index b8f15180e4bf6415862817ff1b8209b509e2bc4a..e76c92756c84db55fc00b2fcb221677ad064e9a8 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, 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.
@@ -62,6 +62,7 @@
 #include "gromacs/topology/mtop_lookup.h"
 #include "gromacs/topology/mtop_util.h"
 #include "gromacs/topology/topology.h"
+#include "gromacs/trajectoryanalysis/topologyinformation.h"
 #include "gromacs/utility/arraysize.h"
 #include "gromacs/utility/cstringutil.h"
 #include "gromacs/utility/fatalerror.h"
@@ -198,25 +199,17 @@ static void get_orires_parms(const char *topnm, t_inputrec *ir,
     done_top_mtop(&top, &mtop);
 }
 
-static int get_bounds(const char *topnm,
-                      real **bounds, int **index, int **dr_pair, int *npairs,
-                      gmx_mtop_t *mtop, gmx_localtop_t **ltop, t_inputrec *ir)
+static int get_bounds(real **bounds, int **index, int **dr_pair, int *npairs,
+                      gmx_localtop_t *top)
 {
-    gmx_localtop_t *top;
     t_functype     *functype;
     t_iparams      *ip;
-    int             natoms, i, j, k, type, ftype, natom;
+    int             i, j, k, type, ftype, natom;
     t_ilist        *disres;
     t_iatom        *iatom;
     real           *b;
     int            *ind, *pair;
     int             nb, label1;
-    matrix          box;
-
-    read_tpx(topnm, ir, box, &natoms, nullptr, nullptr, mtop);
-    snew(*ltop, 1);
-    top   = gmx_mtop_generate_local_top(mtop, ir->efep != efepNO);
-    *ltop = top;
 
     functype = top->idef.functype;
     ip       = top->idef.iparams;
@@ -423,32 +416,31 @@ int gmx_nmr(int argc, char *argv[])
     };
 
     FILE              /* *out     = NULL,*/ *out_disre = nullptr, *fp_pairs = nullptr, *fort = nullptr, *fodt = nullptr, *foten = nullptr;
-    ener_file_t        fp;
-    int                timecheck = 0;
-    gmx_mtop_t         mtop;
-    gmx_localtop_t    *top = nullptr;
-    gmx_enxnm_t       *enm = nullptr;
-    t_enxframe         fr;
-    int                nre, teller, teller_disre;
-    int                nor     = 0, nex = 0, norfr = 0, enx_i = 0;
-    real              *bounds  = nullptr, *violaver = nullptr, *oobs = nullptr, *orient = nullptr, *odrms = nullptr;
-    int               *index   = nullptr, *pair = nullptr, norsel = 0, *orsel = nullptr, *or_label = nullptr;
-    int                nbounds = 0, npairs;
-    gmx_bool           bDisRe, bDRAll, bORA, bORT, bODA, bODR, bODT, bORIRE, bOTEN;
-    gmx_bool           bCont;
-    double             sumaver, sumt;
-    int               *set     = nullptr, i, j, k, nset, sss;
-    char             **pairleg, **odtleg, **otenleg;
-    char             **leg = nullptr;
-    const char        *anm_j, *anm_k, *resnm_j, *resnm_k;
-    int                resnr_j, resnr_k;
-    const char        *orinst_sub = "@ subtitle \"instantaneous\"\n";
-    char               buf[256];
-    gmx_output_env_t  *oenv;
-    t_enxblock        *blk_disre = nullptr;
-    int                ndisre    = 0;
-
-    t_filenm           fnm[] = {
+    ener_file_t       fp;
+    int               timecheck = 0;
+    gmx_localtop_t    top;
+    gmx_enxnm_t      *enm = nullptr;
+    t_enxframe        fr;
+    int               nre, teller, teller_disre;
+    int               nor     = 0, nex = 0, norfr = 0, enx_i = 0;
+    real             *bounds  = nullptr, *violaver = nullptr, *oobs = nullptr, *orient = nullptr, *odrms = nullptr;
+    int              *index   = nullptr, *pair = nullptr, norsel = 0, *orsel = nullptr, *or_label = nullptr;
+    int               nbounds = 0, npairs;
+    gmx_bool          bDisRe, bDRAll, bORA, bORT, bODA, bODR, bODT, bORIRE, bOTEN;
+    gmx_bool          bCont;
+    double            sumaver, sumt;
+    int              *set     = nullptr, i, j, k, nset, sss;
+    char            **pairleg, **odtleg, **otenleg;
+    char            **leg = nullptr;
+    const char       *anm_j, *anm_k, *resnm_j, *resnm_k;
+    int               resnr_j, resnr_k;
+    const char       *orinst_sub = "@ subtitle \"instantaneous\"\n";
+    char              buf[256];
+    gmx_output_env_t *oenv;
+    t_enxblock       *blk_disre = nullptr;
+    int               ndisre    = 0;
+
+    t_filenm                                 fnm[] = {
         { efEDR, "-f",    nullptr,      ffREAD  },
         { efEDR, "-f2",   nullptr,      ffOPTRD },
         { efTPR, "-s",    nullptr,      ffOPTRD },
@@ -463,7 +455,7 @@ int gmx_nmr(int argc, char *argv[])
         { efXVG, "-oten", "oriten",  ffOPTWR }
     };
 #define NFILE asize(fnm)
-    int                npargs;
+    int                                      npargs;
 
     npargs = asize(pa);
     if (!parse_common_args(&argc, argv,
@@ -496,7 +488,7 @@ int gmx_nmr(int argc, char *argv[])
     t_inputrec  irInstance;
     t_inputrec *ir = &irInstance;
     init_enxframe(&fr);
-
+    gmx::TopologyInformation topInfo;
     if (!bDisRe)
     {
         if (bORIRE || bOTEN)
@@ -637,8 +629,12 @@ int gmx_nmr(int argc, char *argv[])
     }
     else
     {
-        nbounds = get_bounds(ftp2fn(efTPR, NFILE, fnm), &bounds, &index, &pair, &npairs,
-                             &mtop, &top, ir);
+        {
+            topInfo.fillFromInputFile(ftp2fn(efTPR, NFILE, fnm));
+            gmx_mtop_generate_local_top(*topInfo.mtop(), &top, ir->efep != efepNO);
+        }
+        nbounds = get_bounds(&bounds, &index, &pair, &npairs,
+                             &top);
         snew(violaver, npairs);
         out_disre = xvgropen(opt2fn("-o", NFILE, fnm), "Sum of Violations",
                              "Time (ps)", "nm", oenv);
@@ -685,8 +681,8 @@ int gmx_nmr(int argc, char *argv[])
                 t_iatom   *fa;
                 t_iparams *ip;
 
-                fa = top->idef.il[F_DISRES].iatoms;
-                ip = top->idef.iparams;
+                fa = top.idef.il[F_DISRES].iatoms;
+                ip = top.idef.iparams;
                 if (blk_disre->nsub != 2 ||
                     (blk_disre->sub[0].nr != blk_disre->sub[1].nr) )
                 {
@@ -694,10 +690,10 @@ int gmx_nmr(int argc, char *argv[])
                 }
 
                 ndisre = blk_disre->sub[0].nr;
-                if (ndisre != top->idef.il[F_DISRES].nr/3)
+                if (ndisre != top.idef.il[F_DISRES].nr/3)
                 {
                     gmx_fatal(FARGS, "Number of disre pairs in the energy file (%d) does not match the number in the run input file (%d)\n",
-                              ndisre, top->idef.il[F_DISRES].nr/3);
+                              ndisre, top.idef.il[F_DISRES].nr/3);
                 }
                 snew(pairleg, ndisre);
                 int molb = 0;
@@ -706,8 +702,8 @@ int gmx_nmr(int argc, char *argv[])
                     snew(pairleg[i], 30);
                     j = fa[3*i+1];
                     k = fa[3*i+2];
-                    mtopGetAtomAndResidueName(&mtop, j, &molb, &anm_j, &resnr_j, &resnm_j, nullptr);
-                    mtopGetAtomAndResidueName(&mtop, k, &molb, &anm_k, &resnr_k, &resnm_k, nullptr);
+                    mtopGetAtomAndResidueName(topInfo.mtop(), j, &molb, &anm_j, &resnr_j, &resnm_j, nullptr);
+                    mtopGetAtomAndResidueName(topInfo.mtop(), k, &molb, &anm_k, &resnr_k, &resnm_k, nullptr);
                     sprintf(pairleg[i], "%d %s %d %s (%d)",
                             resnr_j, anm_j, resnr_k, anm_k,
                             ip[fa[3*i]].disres.label);
index 3f9e5a2246ed6cd13214caf8a4e12b2faed67284..62558c8552c112e101a3a318939c062a2d00212d 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2016,2017,2018,2019, 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.
  * The final solution should be an MD algorithm base class with methods
  * for initialization and atom-data setup.
  */
-
-void mdAlgorithmsSetupAtomData(const t_commrec   *cr,
-                               const t_inputrec  *ir,
-                               const gmx_mtop_t  *top_global,
-                               gmx_localtop_t    *top,
-                               t_forcerec        *fr,
-                               t_graph          **graph,
-                               gmx::MDAtoms      *mdAtoms,
-                               gmx::Constraints  *constr,
-                               gmx_vsite_t       *vsite,
-                               gmx_shellfc_t     *shellfc)
+void mdAlgorithmsSetupAtomData(const t_commrec  *cr,
+                               const t_inputrec *ir,
+                               const gmx_mtop_t &top_global,
+                               gmx_localtop_t   *top,
+                               t_forcerec       *fr,
+                               t_graph         **graph,
+                               gmx::MDAtoms     *mdAtoms,
+                               gmx::Constraints *constr,
+                               gmx_vsite_t      *vsite,
+                               gmx_shellfc_t    *shellfc)
 {
     bool  usingDomDec = DOMAINDECOMP(cr);
 
@@ -86,9 +85,9 @@ void mdAlgorithmsSetupAtomData(const t_commrec   *cr,
     {
         numAtomIndex = -1;
         atomIndex    = nullptr;
-        numHomeAtoms = top_global->natoms;
+        numHomeAtoms = top_global.natoms;
     }
-    atoms2md(top_global, ir, numAtomIndex, atomIndex, numHomeAtoms, mdAtoms);
+    atoms2md(&top_global, ir, numAtomIndex, atomIndex, numHomeAtoms, mdAtoms);
 
     auto mdatoms = mdAtoms->mdatoms();
     if (usingDomDec)
@@ -97,14 +96,7 @@ void mdAlgorithmsSetupAtomData(const t_commrec   *cr,
     }
     else
     {
-        /* Currently gmx_generate_local_top allocates and returns a pointer.
-         * We should implement a more elegant solution.
-         */
-        gmx_localtop_t *tmpTop;
-
-        tmpTop = gmx_mtop_generate_local_top(top_global, ir->efep != efepNO);
-        *top   = *tmpTop;
-        sfree(tmpTop);
+        gmx_mtop_generate_local_top(top_global, top, ir->efep != efepNO);
     }
 
     if (vsite)
@@ -127,7 +119,7 @@ void mdAlgorithmsSetupAtomData(const t_commrec   *cr,
     {
         GMX_ASSERT(graph != nullptr, "We use a graph with PBC (no periodic mols) and without DD");
 
-        *graph = mk_graph(nullptr, &(top->idef), 0, top_global->natoms, FALSE, FALSE);
+        *graph = mk_graph(nullptr, &(top->idef), 0, top_global.natoms, FALSE, FALSE);
     }
     else if (graph != nullptr)
     {
index 84f3e5ab1fe08ff4b66ffe820cc706534ee47324..195905169156caa8f7ba249973146aadca593205 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2016,2017,2018,2019, 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.
@@ -69,15 +69,15 @@ class MDAtoms;
  * \param[in,out] vsite      The virtual site data, can be NULL
  * \param[in,out] shellfc    The shell/flexible-constraint data, can be NULL
  */
-void mdAlgorithmsSetupAtomData(const t_commrec   *cr,
-                               const t_inputrec  *ir,
-                               const gmx_mtop_t  *top_global,
-                               gmx_localtop_t    *top,
-                               t_forcerec        *fr,
-                               t_graph          **graph,
-                               gmx::MDAtoms      *mdAtoms,
-                               gmx::Constraints  *constr,
-                               gmx_vsite_t       *vsite,
-                               gmx_shellfc_t     *shellfc);
+void mdAlgorithmsSetupAtomData(const t_commrec                 *cr,
+                               const t_inputrec                *ir,
+                               const gmx_mtop_t                &top_global,
+                               gmx_localtop_t                  *top,
+                               t_forcerec                      *fr,
+                               t_graph                        **graph,
+                               gmx::MDAtoms                    *mdAtoms,
+                               gmx::Constraints                *constr,
+                               gmx_vsite_t                     *vsite,
+                               gmx_shellfc_t                   *shellfc);
 
 #endif
index 1d8eef6d6068eaa2f26a8795bd9127e4b8422b88..34c5e0b08b4bcbb0d09608032fd3198d895937a3 100644 (file)
@@ -169,7 +169,7 @@ void gmx::Integrator::do_md()
     t_vcm                  *vcm;
     matrix                  parrinellorahmanMu, M;
     gmx_repl_ex_t           repl_ex = nullptr;
-    gmx_localtop_t         *top;
+    gmx_localtop_t          top;
     t_mdebin               *mdebin   = nullptr;
     gmx_enerdata_t         *enerd;
     PaddedVector<gmx::RVec> f {};
@@ -297,7 +297,7 @@ void gmx::Integrator::do_md()
 
     if (DOMAINDECOMP(cr))
     {
-        top = dd_init_local_top(top_global);
+        dd_init_local_top(*top_global, &top);
 
         stateInstance = compat::make_unique<t_state>();
         state         = stateInstance.get();
@@ -305,8 +305,8 @@ void gmx::Integrator::do_md()
 
         /* Distribute the charge groups over the nodes from the master node */
         dd_partition_system(fplog, mdlog, ir->init_step, cr, TRUE, 1,
-                            state_global, top_global, ir,
-                            state, &f, mdAtoms, top, fr,
+                            state_global, *top_global, ir,
+                            state, &f, mdAtoms, &top, fr,
                             vsite, constr,
                             nrnb, nullptr, FALSE);
         shouldCheckNumberOfBondedInteractions = true;
@@ -319,8 +319,8 @@ void gmx::Integrator::do_md()
         /* Copy the pointer to the global state */
         state = state_global;
 
-        snew(top, 1);
-        mdAlgorithmsSetupAtomData(cr, ir, top_global, top, fr,
+        /* Generate and initialize new topology */
+        mdAlgorithmsSetupAtomData(cr, ir, *top_global, &top, fr,
                                   &graph, mdAtoms, constr, vsite, shellfc);
 
         update_realloc(upd, state->natoms);
@@ -449,7 +449,7 @@ void gmx::Integrator::do_md()
         {
             /* Construct the virtual sites for the initial configuration */
             construct_vsites(vsite, state->x.rvec_array(), ir->delta_t, nullptr,
-                             top->idef.iparams, top->idef.il,
+                             top.idef.iparams, top.idef.il,
                              fr->ePBC, fr->bMolPBC, cr, state->box);
         }
     }
@@ -506,7 +506,7 @@ void gmx::Integrator::do_md()
                         | (shouldCheckNumberOfBondedInteractions ? CGLO_CHECK_NUMBER_OF_BONDED_INTERACTIONS : 0));
     }
     checkNumberOfBondedInteractions(mdlog, cr, totalNumberOfBondedInteractions,
-                                    top_global, top, state,
+                                    top_global, &top, state,
                                     &shouldCheckNumberOfBondedInteractions);
     if (ir->eI == eiVVAK)
     {
@@ -761,8 +761,8 @@ void gmx::Integrator::do_md()
                 /* Repartition the domain decomposition */
                 dd_partition_system(fplog, mdlog, step, cr,
                                     bMasterState, nstglobalcomm,
-                                    state_global, top_global, ir,
-                                    state, &f, mdAtoms, top, fr,
+                                    state_global, *top_global, ir,
+                                    state, &f, mdAtoms, &top, fr,
                                     vsite, constr,
                                     nrnb, wcycle,
                                     do_verbose && !bPMETunePrinting);
@@ -793,7 +793,7 @@ void gmx::Integrator::do_md()
                             &totalNumberOfBondedInteractions, &bSumEkinhOld,
                             CGLO_GSTAT | CGLO_TEMPERATURE | CGLO_CHECK_NUMBER_OF_BONDED_INTERACTIONS);
             checkNumberOfBondedInteractions(mdlog, cr, totalNumberOfBondedInteractions,
-                                            top_global, top, state,
+                                            top_global, &top, state,
                                             &shouldCheckNumberOfBondedInteractions);
         }
         clear_mat(force_vir);
@@ -843,7 +843,7 @@ void gmx::Integrator::do_md()
             /* Now is the time to relax the shells */
             relax_shell_flexcon(fplog, cr, ms, mdrunOptions.verbose,
                                 enforcedRotation, step,
-                                ir, bNS, force_flags, top,
+                                ir, bNS, force_flags, &top,
                                 constr, enerd, fcd,
                                 state, f.arrayRefWithPadding(), force_vir, mdatoms,
                                 nrnb, wcycle, graph, groups,
@@ -872,7 +872,7 @@ void gmx::Integrator::do_md()
              * Check comments in sim_util.c
              */
             do_force(fplog, cr, ms, ir, awh.get(), enforcedRotation,
-                     step, nrnb, wcycle, top, groups,
+                     step, nrnb, wcycle, &top, groups,
                      state->box, state->x.arrayRefWithPadding(), &state->hist,
                      f.arrayRefWithPadding(), force_vir, mdatoms, enerd, fcd,
                      state->lambda, graph,
@@ -956,7 +956,7 @@ void gmx::Integrator::do_md()
                    b) If we are using EkinAveEkin for the kinetic energy for the temperature control, we still feed in
                    EkinAveVel because it's needed for the pressure */
                 checkNumberOfBondedInteractions(mdlog, cr, totalNumberOfBondedInteractions,
-                                                top_global, top, state,
+                                                top_global, &top, state,
                                                 &shouldCheckNumberOfBondedInteractions);
                 wallcycle_start(wcycle, ewcUPDATE);
             }
@@ -1226,7 +1226,7 @@ void gmx::Integrator::do_md()
                 shift_self(graph, state->box, state->x.rvec_array());
             }
             construct_vsites(vsite, state->x.rvec_array(), ir->delta_t, state->v.rvec_array(),
-                             top->idef.iparams, top->idef.il,
+                             top.idef.iparams, top.idef.il,
                              fr->ePBC, fr->bMolPBC, cr, state->box);
 
             if (graph != nullptr)
@@ -1272,7 +1272,7 @@ void gmx::Integrator::do_md()
                                 | (shouldCheckNumberOfBondedInteractions ? CGLO_CHECK_NUMBER_OF_BONDED_INTERACTIONS : 0)
                                 );
                 checkNumberOfBondedInteractions(mdlog, cr, totalNumberOfBondedInteractions,
-                                                top_global, top, state,
+                                                top_global, &top, state,
                                                 &shouldCheckNumberOfBondedInteractions);
             }
         }
@@ -1424,8 +1424,8 @@ void gmx::Integrator::do_md()
         if ( (bExchanged || bNeedRepartition) && DOMAINDECOMP(cr) )
         {
             dd_partition_system(fplog, mdlog, step, cr, TRUE, 1,
-                                state_global, top_global, ir,
-                                state, &f, mdAtoms, top, fr,
+                                state_global, *top_global, ir,
+                                state, &f, mdAtoms, &top, fr,
                                 vsite, constr,
                                 nrnb, wcycle, FALSE);
             shouldCheckNumberOfBondedInteractions = true;
@@ -1527,13 +1527,6 @@ void gmx::Integrator::do_md()
     destroy_enerdata(enerd);
 
     sfree(enerd);
-
     global_stat_destroy(gstat);
 
-    /* Clean up topology. top->atomtypes has an allocated pointer if no domain decomposition*/
-    if (!DOMAINDECOMP(cr))
-    {
-        done_localtop(top);
-    }
-    sfree(top);
 }
index ad10a7bbc048d99d68e11195a31348c7e212f1ff..dd40607099f1eabaacd0b42b29102bb603763ccb 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2018, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019, 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.
@@ -150,7 +150,7 @@ void gmx::Integrator::do_mimic()
     int                      force_flags;
     tensor                   force_vir, shake_vir, total_vir, pres;
     rvec                     mu_tot;
-    gmx_localtop_t          *top;
+    gmx_localtop_t           top;
     t_mdebin                *mdebin   = nullptr;
     gmx_enerdata_t          *enerd;
     PaddedVector<gmx::RVec>  f {};
@@ -268,7 +268,7 @@ void gmx::Integrator::do_mimic()
 
     if (DOMAINDECOMP(cr))
     {
-        top = dd_init_local_top(top_global);
+        dd_init_local_top(*top_global, &top);
 
         stateInstance = compat::make_unique<t_state>();
         state         = stateInstance.get();
@@ -276,8 +276,8 @@ void gmx::Integrator::do_mimic()
 
         /* Distribute the charge groups over the nodes from the master node */
         dd_partition_system(fplog, mdlog, ir->init_step, cr, TRUE, 1,
-                            state_global, top_global, ir,
-                            state, &f, mdAtoms, top, fr,
+                            state_global, *top_global, ir,
+                            state, &f, mdAtoms, &top, fr,
                             vsite, constr,
                             nrnb, nullptr, FALSE);
         shouldCheckNumberOfBondedInteractions = true;
@@ -293,8 +293,7 @@ void gmx::Integrator::do_mimic()
         /* Copy the pointer to the global state */
         state = state_global;
 
-        snew(top, 1);
-        mdAlgorithmsSetupAtomData(cr, ir, top_global, top, fr,
+        mdAlgorithmsSetupAtomData(cr, ir, *top_global, &top, fr,
                                   &graph, mdAtoms, constr, vsite, shellfc);
     }
 
@@ -324,7 +323,7 @@ void gmx::Integrator::do_mimic()
                         &totalNumberOfBondedInteractions, &bSumEkinhOld, cglo_flags);
     }
     checkNumberOfBondedInteractions(mdlog, cr, totalNumberOfBondedInteractions,
-                                    top_global, top, state,
+                                    top_global, &top, state,
                                     &shouldCheckNumberOfBondedInteractions);
 
     if (MASTER(cr))
@@ -415,8 +414,8 @@ void gmx::Integrator::do_mimic()
             const bool bMasterState = true;
             dd_partition_system(fplog, mdlog, step, cr,
                                 bMasterState, nstglobalcomm,
-                                state_global, top_global, ir,
-                                state, &f, mdAtoms, top, fr,
+                                state_global, *top_global, ir,
+                                state, &f, mdAtoms, &top, fr,
                                 vsite, constr,
                                 nrnb, wcycle,
                                 mdrunOptions.verbose);
@@ -445,7 +444,7 @@ void gmx::Integrator::do_mimic()
             /* Now is the time to relax the shells */
             relax_shell_flexcon(fplog, cr, ms, mdrunOptions.verbose,
                                 enforcedRotation, step,
-                                ir, bNS, force_flags, top,
+                                ir, bNS, force_flags, &top,
                                 constr, enerd, fcd,
                                 state, f.arrayRefWithPadding(), force_vir, mdatoms,
                                 nrnb, wcycle, graph, groups,
@@ -463,7 +462,7 @@ void gmx::Integrator::do_mimic()
             Awh       *awh = nullptr;
             gmx_edsam *ed  = nullptr;
             do_force(fplog, cr, ms, ir, awh, enforcedRotation,
-                     step, nrnb, wcycle, top, groups,
+                     step, nrnb, wcycle, &top, groups,
                      state->box, state->x.arrayRefWithPadding(), &state->hist,
                      f.arrayRefWithPadding(), force_vir, mdatoms, enerd, fcd,
                      state->lambda, graph,
@@ -504,7 +503,7 @@ void gmx::Integrator::do_mimic()
                 shift_self(graph, state->box, as_rvec_array(state->x.data()));
             }
             construct_vsites(vsite, as_rvec_array(state->x.data()), ir->delta_t, as_rvec_array(state->v.data()),
-                             top->idef.iparams, top->idef.il,
+                             top.idef.iparams, top.idef.il,
                              fr->ePBC, fr->bMolPBC, cr, state->box);
 
             if (graph != nullptr)
@@ -530,7 +529,7 @@ void gmx::Integrator::do_mimic()
                             | (shouldCheckNumberOfBondedInteractions ? CGLO_CHECK_NUMBER_OF_BONDED_INTERACTIONS : 0)
                             );
             checkNumberOfBondedInteractions(mdlog, cr, totalNumberOfBondedInteractions,
-                                            top_global, top, state,
+                                            top_global, &top, state,
                                             &shouldCheckNumberOfBondedInteractions);
         }
 
@@ -654,5 +653,4 @@ void gmx::Integrator::do_mimic()
 
     destroy_enerdata(enerd);
     sfree(enerd);
-    sfree(top);
 }
index eb8e910468fd99643d8d9f5aa061caa7a10c13ab..80a75fbb7ce35c70b0c469d329a4a28b131e43d9 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, 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.
@@ -353,7 +353,7 @@ static void init_em(FILE *fplog,
                     t_inputrec *ir,
                     const MdrunOptions &mdrunOptions,
                     t_state *state_global, gmx_mtop_t *top_global,
-                    em_state_t *ems, gmx_localtop_t **top,
+                    em_state_t *ems, gmx_localtop_t *top,
                     t_nrnb *nrnb, rvec mu_tot,
                     t_forcerec *fr, gmx_enerdata_t **enerd,
                     t_graph **graph, gmx::MDAtoms *mdAtoms, gmx_global_stat_t *gstat,
@@ -410,14 +410,15 @@ static void init_em(FILE *fplog,
     auto mdatoms = mdAtoms->mdatoms();
     if (DOMAINDECOMP(cr))
     {
-        *top = dd_init_local_top(top_global);
+        top->useInDomainDecomp_ = true;
+        dd_init_local_top(*top_global, top);
 
         dd_init_local_state(cr->dd, state_global, &ems->s);
 
         /* Distribute the charge groups over the nodes from the master node */
         dd_partition_system(fplog, mdlog, ir->init_step, cr, TRUE, 1,
-                            state_global, top_global, ir,
-                            &ems->s, &ems->f, mdAtoms, *top,
+                            state_global, *top_global, ir,
+                            &ems->s, &ems->f, mdAtoms, top,
                             fr, vsite, constr,
                             nrnb, nullptr, FALSE);
         dd_store_state(cr->dd, &ems->s);
@@ -432,14 +433,13 @@ static void init_em(FILE *fplog,
         state_change_natoms(&ems->s, ems->s.natoms);
         ems->f.resizeWithPadding(ems->s.natoms);
 
-        snew(*top, 1);
-        mdAlgorithmsSetupAtomData(cr, ir, top_global, *top, fr,
+        mdAlgorithmsSetupAtomData(cr, ir, *top_global, top, fr,
                                   graph, mdAtoms,
                                   constr, vsite, shellfc ? *shellfc : nullptr);
 
         if (vsite)
         {
-            set_vsite_top(vsite, *top, mdatoms);
+            set_vsite_top(vsite, top, mdatoms);
         }
     }
 
@@ -736,7 +736,7 @@ static void em_dd_partition_system(FILE *fplog,
 {
     /* Repartition the domain decomposition */
     dd_partition_system(fplog, mdlog, step, cr, FALSE, 1,
-                        nullptr, top_global, ir,
+                        nullptr, *top_global, ir,
                         &ems->s, &ems->f,
                         mdAtoms, top, fr, vsite, constr,
                         nrnb, wcycle, FALSE);
@@ -1078,26 +1078,26 @@ namespace gmx
 void
 Integrator::do_cg()
 {
-    const char       *CG = "Polak-Ribiere Conjugate Gradients";
+    const char        *CG = "Polak-Ribiere Conjugate Gradients";
 
-    gmx_localtop_t   *top;
-    gmx_enerdata_t   *enerd;
-    gmx_global_stat_t gstat;
-    t_graph          *graph;
-    double            tmp, minstep;
-    real              stepsize;
-    real              a, b, c, beta = 0.0;
-    real              epot_repl = 0;
-    real              pnorm;
-    t_mdebin         *mdebin;
-    gmx_bool          converged, foundlower;
-    rvec              mu_tot;
-    gmx_bool          do_log = FALSE, do_ene = FALSE, do_x, do_f;
-    tensor            vir, pres;
-    int               number_steps, neval = 0, nstcg = inputrec->nstcgsteep;
-    gmx_mdoutf_t      outf;
-    int               m, step, nminstep;
-    auto              mdatoms = mdAtoms->mdatoms();
+    gmx_localtop_t     top;
+    gmx_enerdata_t    *enerd;
+    gmx_global_stat_t  gstat;
+    t_graph           *graph;
+    double             tmp, minstep;
+    real               stepsize;
+    real               a, b, c, beta = 0.0;
+    real               epot_repl = 0;
+    real               pnorm;
+    t_mdebin          *mdebin;
+    gmx_bool           converged, foundlower;
+    rvec               mu_tot;
+    gmx_bool           do_log = FALSE, do_ene = FALSE, do_x, do_f;
+    tensor             vir, pres;
+    int                number_steps, neval = 0, nstcg = inputrec->nstcgsteep;
+    gmx_mdoutf_t       outf;
+    int                m, step, nminstep;
+    auto               mdatoms = mdAtoms->mdatoms();
 
     GMX_LOG(mdlog.info).asParagraph().
         appendText("Note that activating conjugate gradient energy minimization via the "
@@ -1153,7 +1153,7 @@ Integrator::do_cg()
 
     EnergyEvaluator energyEvaluator {
         fplog, mdlog, cr, ms,
-        top_global, top,
+        top_global, &top,
         inputrec, nrnb, wcycle, gstat,
         vsite, constr, fcd, graph,
         mdAtoms, fr, ppForceWorkload, enerd
@@ -1326,7 +1326,7 @@ Integrator::do_cg()
         if (DOMAINDECOMP(cr) && s_min->s.ddp_count < cr->dd->ddp_count)
         {
             em_dd_partition_system(fplog, mdlog, step, cr, top_global, inputrec,
-                                   s_min, top, mdAtoms, fr, vsite, constr,
+                                   s_min, &top, mdAtoms, fr, vsite, constr,
                                    nrnb, wcycle);
         }
 
@@ -1431,7 +1431,7 @@ Integrator::do_cg()
                 {
                     /* Reload the old state */
                     em_dd_partition_system(fplog, mdlog, -1, cr, top_global, inputrec,
-                                           s_min, top, mdAtoms, fr, vsite, constr,
+                                           s_min, &top, mdAtoms, fr, vsite, constr,
                                            nrnb, wcycle);
                 }
 
@@ -1708,7 +1708,7 @@ Integrator::do_lbfgs()
 {
     static const char *LBFGS = "Low-Memory BFGS Minimizer";
     em_state_t         ems;
-    gmx_localtop_t    *top;
+    gmx_localtop_t     top;
     gmx_enerdata_t    *enerd;
     gmx_global_stat_t  gstat;
     t_graph           *graph;
@@ -1823,7 +1823,7 @@ Integrator::do_lbfgs()
     if (vsite)
     {
         construct_vsites(vsite, state_global->x.rvec_array(), 1, nullptr,
-                         top->idef.iparams, top->idef.il,
+                         top.idef.iparams, top.idef.il,
                          fr->ePBC, fr->bMolPBC, cr, state_global->box);
     }
 
@@ -1834,7 +1834,7 @@ Integrator::do_lbfgs()
     neval++;
     EnergyEvaluator energyEvaluator {
         fplog, mdlog, cr, ms,
-        top_global, top,
+        top_global, &top,
         inputrec, nrnb, wcycle, gstat,
         vsite, constr, fcd, graph,
         mdAtoms, fr, ppForceWorkload, enerd
@@ -2433,8 +2433,8 @@ Integrator::do_lbfgs()
 void
 Integrator::do_steep()
 {
-    const char       *SD = "Steepest Descents";
-    gmx_localtop_t   *top;
+    const char       *SD  = "Steepest Descents";
+    gmx_localtop_t    top;
     gmx_enerdata_t   *enerd;
     gmx_global_stat_t gstat;
     t_graph          *graph;
@@ -2491,7 +2491,7 @@ Integrator::do_steep()
     }
     EnergyEvaluator energyEvaluator {
         fplog, mdlog, cr, ms,
-        top_global, top,
+        top_global, &top,
         inputrec, nrnb, wcycle, gstat,
         vsite, constr, fcd, graph,
         mdAtoms, fr, ppForceWorkload, enerd
@@ -2608,7 +2608,7 @@ Integrator::do_steep()
             {
                 /* Reload the old state */
                 em_dd_partition_system(fplog, mdlog, count, cr, top_global, inputrec,
-                                       s_min, top, mdAtoms, fr, vsite, constr,
+                                       s_min, &top, mdAtoms, fr, vsite, constr,
                                        nrnb, wcycle);
             }
         }
@@ -2679,7 +2679,7 @@ Integrator::do_nm()
     const char          *NM = "Normal Mode Analysis";
     gmx_mdoutf_t         outf;
     int                  nnodes, node;
-    gmx_localtop_t      *top;
+    gmx_localtop_t       top;
     gmx_enerdata_t      *enerd;
     gmx_global_stat_t    gstat;
     t_graph             *graph;
@@ -2794,7 +2794,7 @@ Integrator::do_nm()
     cr->nnodes = 1;
     EnergyEvaluator energyEvaluator {
         fplog, mdlog, cr, ms,
-        top_global, top,
+        top_global, &top,
         inputrec, nrnb, wcycle, gstat,
         vsite, constr, fcd, graph,
         mdAtoms, fr, ppForceWorkload, enerd
@@ -2864,7 +2864,7 @@ Integrator::do_nm()
                                         inputrec,
                                         bNS,
                                         force_flags,
-                                        top,
+                                        &top,
                                         constr,
                                         enerd,
                                         fcd,
index 4a29fc9b97cb8d2eecbed5109e3ee6c5fb1dfc07..ae2e3fd2ecf35b4fa912c037d42721d62efb3c81 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2018, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019, 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.
@@ -205,7 +205,7 @@ void gmx::Integrator::do_rerun()
     t_trxstatus            *status;
     rvec                    mu_tot;
     t_trxframe              rerun_fr;
-    gmx_localtop_t         *top;
+    gmx_localtop_t          top;
     t_mdebin               *mdebin   = nullptr;
     gmx_enerdata_t         *enerd;
     PaddedVector<gmx::RVec> f {};
@@ -334,7 +334,7 @@ void gmx::Integrator::do_rerun()
 
     if (DOMAINDECOMP(cr))
     {
-        top = dd_init_local_top(top_global);
+        dd_init_local_top(*top_global, &top);
 
         stateInstance = compat::make_unique<t_state>();
         state         = stateInstance.get();
@@ -342,8 +342,8 @@ void gmx::Integrator::do_rerun()
 
         /* Distribute the charge groups over the nodes from the master node */
         dd_partition_system(fplog, mdlog, ir->init_step, cr, TRUE, 1,
-                            state_global, top_global, ir,
-                            state, &f, mdAtoms, top, fr,
+                            state_global, *top_global, ir,
+                            state, &f, mdAtoms, &top, fr,
                             vsite, constr,
                             nrnb, nullptr, FALSE);
         shouldCheckNumberOfBondedInteractions = true;
@@ -358,8 +358,7 @@ void gmx::Integrator::do_rerun()
         /* Copy the pointer to the global state */
         state = state_global;
 
-        snew(top, 1);
-        mdAlgorithmsSetupAtomData(cr, ir, top_global, top, fr,
+        mdAlgorithmsSetupAtomData(cr, ir, *top_global, &top, fr,
                                   &graph, mdAtoms, constr, vsite, shellfc);
     }
 
@@ -388,7 +387,7 @@ void gmx::Integrator::do_rerun()
                         &totalNumberOfBondedInteractions, &bSumEkinhOld, cglo_flags);
     }
     checkNumberOfBondedInteractions(mdlog, cr, totalNumberOfBondedInteractions,
-                                    top_global, top, state,
+                                    top_global, &top, state,
                                     &shouldCheckNumberOfBondedInteractions);
 
     if (MASTER(cr))
@@ -514,7 +513,7 @@ void gmx::Integrator::do_rerun()
                 gmx_fatal(FARGS, "Vsite recalculation with -rerun is not implemented with domain decomposition, "
                           "use a single rank");
             }
-            prepareRerunState(rerun_fr, state_global, constructVsites, vsite, top->idef, ir->delta_t, *fr, graph);
+            prepareRerunState(rerun_fr, state_global, constructVsites, vsite, top.idef, ir->delta_t, *fr, graph);
         }
 
         isLastStep = isLastStep || stopHandler->stoppingAfterCurrentStep(bNS);
@@ -525,8 +524,8 @@ void gmx::Integrator::do_rerun()
             const bool bMasterState = true;
             dd_partition_system(fplog, mdlog, step, cr,
                                 bMasterState, nstglobalcomm,
-                                state_global, top_global, ir,
-                                state, &f, mdAtoms, top, fr,
+                                state_global, *top_global, ir,
+                                state, &f, mdAtoms, &top, fr,
                                 vsite, constr,
                                 nrnb, wcycle,
                                 mdrunOptions.verbose);
@@ -555,7 +554,7 @@ void gmx::Integrator::do_rerun()
             /* Now is the time to relax the shells */
             relax_shell_flexcon(fplog, cr, ms, mdrunOptions.verbose,
                                 enforcedRotation, step,
-                                ir, bNS, force_flags, top,
+                                ir, bNS, force_flags, &top,
                                 constr, enerd, fcd,
                                 state, f.arrayRefWithPadding(), force_vir, mdatoms,
                                 nrnb, wcycle, graph, groups,
@@ -573,7 +572,7 @@ void gmx::Integrator::do_rerun()
             Awh       *awh = nullptr;
             gmx_edsam *ed  = nullptr;
             do_force(fplog, cr, ms, ir, awh, enforcedRotation,
-                     step, nrnb, wcycle, top, groups,
+                     step, nrnb, wcycle, &top, groups,
                      state->box, state->x.arrayRefWithPadding(), &state->hist,
                      f.arrayRefWithPadding(), force_vir, mdatoms, enerd, fcd,
                      state->lambda, graph,
@@ -614,7 +613,7 @@ void gmx::Integrator::do_rerun()
                 shift_self(graph, state->box, as_rvec_array(state->x.data()));
             }
             construct_vsites(vsite, as_rvec_array(state->x.data()), ir->delta_t, as_rvec_array(state->v.data()),
-                             top->idef.iparams, top->idef.il,
+                             top.idef.iparams, top.idef.il,
                              fr->ePBC, fr->bMolPBC, cr, state->box);
 
             if (graph != nullptr)
@@ -640,7 +639,7 @@ void gmx::Integrator::do_rerun()
                             | (shouldCheckNumberOfBondedInteractions ? CGLO_CHECK_NUMBER_OF_BONDED_INTERACTIONS : 0)
                             );
             checkNumberOfBondedInteractions(mdlog, cr, totalNumberOfBondedInteractions,
-                                            top_global, top, state,
+                                            top_global, &top, state,
                                             &shouldCheckNumberOfBondedInteractions);
         }
 
@@ -769,5 +768,4 @@ void gmx::Integrator::do_rerun()
 
     destroy_enerdata(enerd);
     sfree(enerd);
-    sfree(top);
 }
index a6aa1ec01ba733fb7634d61e17da6fde586ee0c2..5aaf23de06a4b5987bb051f17b287fcc0909fa34 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, 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.
@@ -134,7 +134,7 @@ namespace gmx
 void
 Integrator::do_tpi()
 {
-    gmx_localtop_t         *top;
+    gmx_localtop_t          top;
     gmx_groups_t           *groups;
     gmx_enerdata_t         *enerd;
     PaddedVector<gmx::RVec> f {};
@@ -185,7 +185,7 @@ Integrator::do_tpi()
 
     nnodes = cr->nnodes;
 
-    top = gmx_mtop_generate_local_top(top_global, inputrec->efep != efepNO);
+    gmx_mtop_generate_local_top(*top_global, &top, inputrec->efep != efepNO);
 
     groups = &top_global->groups;
 
@@ -274,9 +274,9 @@ Integrator::do_tpi()
     print_start(fplog, cr, walltime_accounting, "Test Particle Insertion");
 
     /* The last charge group is the group to be inserted */
-    cg_tp = top->cgs.nr - 1;
-    a_tp0 = top->cgs.index[cg_tp];
-    a_tp1 = top->cgs.index[cg_tp+1];
+    cg_tp = top.cgs.nr - 1;
+    a_tp0 = top.cgs.index[cg_tp];
+    a_tp1 = top.cgs.index[cg_tp+1];
     if (debug)
     {
         fprintf(debug, "TPI cg %d, atoms %d-%d\n", cg_tp, a_tp0, a_tp1);
@@ -299,7 +299,7 @@ Integrator::do_tpi()
     }
     bRFExcl = (bCharge && EEL_RF(fr->ic->eeltype));
 
-    calc_cgcm(fplog, cg_tp, cg_tp+1, &(top->cgs), state_global->x.rvec_array(), fr->cg_cm);
+    calc_cgcm(fplog, cg_tp, cg_tp+1, &(top.cgs), state_global->x.rvec_array(), fr->cg_cm);
     if (bCavity)
     {
         if (norm(fr->cg_cm[cg_tp]) > 0.5*inputrec->rlist && fplog)
@@ -627,7 +627,7 @@ Integrator::do_tpi()
             clear_mat(pres);
 
             /* Set the charge group center of mass of the test particle */
-            copy_rvec(x_init, fr->cg_cm[top->cgs.nr-1]);
+            copy_rvec(x_init, fr->cg_cm[top.cgs.nr-1]);
 
             /* Calc energy (no forces) on new positions.
              * Since we only need the intermolecular energy
@@ -645,7 +645,7 @@ Integrator::do_tpi()
             std::fenv_t floatingPointEnvironment;
             std::feholdexcept(&floatingPointEnvironment);
             do_force(fplog, cr, ms, inputrec, nullptr, nullptr,
-                     step, nrnb, wcycle, top, &top_global->groups,
+                     step, nrnb, wcycle, &top, &top_global->groups,
                      state_global->box, state_global->x.arrayRefWithPadding(), &state_global->hist,
                      f.arrayRefWithPadding(), force_vir, mdatoms, enerd, fcd,
                      state_global->lambda,
index 47ff776549039294f7df7f87ccc08ddaa462a6cf..51e1585447987ee5a33f7b9248be187018e59829 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2013, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, 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.
@@ -308,22 +308,22 @@ static void chk_bonds(t_idef *idef, int ePBC, rvec *x, matrix box, real tol)
 
 static void chk_trj(const gmx_output_env_t *oenv, const char *fn, const char *tpr, real tol)
 {
-    t_trxframe       fr;
-    t_count          count;
-    t_fr_time        first, last;
-    int              j = -1, new_natoms, natoms;
-    real             old_t1, old_t2;
-    gmx_bool         bShowTimestep = TRUE, newline = FALSE;
-    t_trxstatus     *status;
-    gmx_mtop_t       mtop;
-    gmx_localtop_t  *top = nullptr;
-    t_state          state;
-    t_inputrec       ir;
+    t_trxframe     fr;
+    t_count        count;
+    t_fr_time      first, last;
+    int            j = -1, new_natoms, natoms;
+    real           old_t1, old_t2;
+    gmx_bool       bShowTimestep = TRUE, newline = FALSE;
+    t_trxstatus   *status;
+    gmx_mtop_t     mtop;
+    gmx_localtop_t top;
+    t_state        state;
+    t_inputrec     ir;
 
     if (tpr)
     {
         read_tpx_state(tpr, &ir, &state, &mtop);
-        top = gmx_mtop_generate_local_top(&mtop, ir.efep != efepNO);
+        gmx_mtop_generate_local_top(mtop, &top, ir.efep != efepNO);
     }
     new_natoms = -1;
     natoms     = -1;
@@ -390,7 +390,7 @@ static void chk_trj(const gmx_output_env_t *oenv, const char *fn, const char *tp
         natoms = new_natoms;
         if (tpr)
         {
-            chk_bonds(&top->idef, ir.ePBC, fr.x, fr.box, tol);
+            chk_bonds(&top.idef, ir.ePBC, fr.x, fr.box, tol);
         }
         if (fr.bX)
         {
index b3714531547e501dc17a54da73a0c7eb9be2b857..4416300d60331d0680a9b6ea1da9807931f1124e 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2017,2018,2019, 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.
@@ -72,6 +72,13 @@ void init_block(t_block *block)
     block->index[0]     = 0;
 }
 
+void init_block_null(t_block *block)
+{
+    block->nr           = 0;
+    block->nalloc_index = 0;
+    block->index        = nullptr;
+}
+
 void init_blocka(t_blocka *block)
 {
     block->nr           = 0;
@@ -83,6 +90,16 @@ void init_blocka(t_blocka *block)
     block->a            = nullptr;
 }
 
+void init_blocka_null(t_blocka *block)
+{
+    block->nr           = 0;
+    block->nra          = 0;
+    block->nalloc_index = 0;
+    block->index        = nullptr;
+    block->nalloc_a     = 0;
+    block->a            = nullptr;
+}
+
 t_blocka *new_blocka()
 {
     t_blocka *block;
index b8a47faf002f471948c229c0a100ce3575286a14..68a99a6b807ed36fc44f44795907d0e629046065 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2010,2014,2015,2018, by the GROMACS development team, led by
+ * Copyright (c) 2010,2014,2015,2018,2019, 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.
@@ -215,8 +215,56 @@ struct t_blocka
     int nalloc_a;               /* The allocation size for a            */
 };
 
+/*! \brief
+ * Fully initialize t_block datastructure.
+ *
+ * Initializes a \p block and sets up the first index to zero.
+ *
+ * \param[in,out] block datastructure to initialize.
+ */
 void init_block(t_block *block);
+
+/*! \brief
+ * Fully initialize t_blocka datastructure.
+ *
+ * Initializes a \p block and sets up the first index to zero.
+ * The atom number array is initialized to nullptr.
+ *
+ * \param[in,out] block datastructure to initialize.
+ */
 void init_blocka(t_blocka *block);
+
+/* TODO
+ * In general all t_block datastructures should be avoided
+ * in favour of RangePartitioning. This here is a simple cludge
+ * to use more modern initialization while we move to the use
+ * of RangePartitioning.
+ */
+
+/*! \brief
+ * Minimal initialization of t_block datastructure.
+ *
+ * Performs the equivalent to a snew on a t_block, setting all
+ * values to zero or nullptr. Needed for some cases where the topology
+ * handling expects a block to be valid initialized (e.g. during domain
+ * decomposition) but without the first block set to zero.
+ *
+ * \param[in,out] block datastructure to initialize.
+ */
+void init_block_null(t_block *block);
+
+/*! \brief
+ * Minimal initialization of t_blocka datastructure.
+ *
+ * Performs the equivalent to a snew on a t_blocka, setting all
+ * values to zero or nullptr. Needed for some cases where the topology
+ * handling expects a block to be valid initialized (e.g. during domain
+ * decomposition) but without the first block set to zero.
+ *
+ * \param[in,out] block datastructure to initialize.
+ */
+void init_blocka_null(t_blocka *block);
+
 t_blocka *new_blocka();
 /* allocate new block */
 
index aff5c43eac33ed90b9b6f57b47dbdbe8ce0a66e9..67881f5844af177e2e8105cb14f8d3083b3b6c13 100644 (file)
@@ -1,7 +1,8 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2008,2009,2010,2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2008,2009,2010,
+ * Copyright (c) 2012,2013,2014,2015,2016,2017,2018,2019, 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.
@@ -1128,17 +1129,12 @@ static void gen_local_top(const gmx_mtop_t  &mtop,
     }
 }
 
-gmx_localtop_t *
-gmx_mtop_generate_local_top(const gmx_mtop_t *mtop,
+void
+gmx_mtop_generate_local_top(const gmx_mtop_t &mtop,
+                            gmx_localtop_t   *top,
                             bool              freeEnergyInteractionsAtEnd)
 {
-    gmx_localtop_t *top;
-
-    snew(top, 1);
-
-    gen_local_top(*mtop, freeEnergyInteractionsAtEnd, true, top);
-
-    return top;
+    gen_local_top(mtop, freeEnergyInteractionsAtEnd, true, top);
 }
 
 /*! \brief Fills an array with molecule begin/end atom indices
index 3e9c8079934fa8821360065004242c187df4f725..964cd2a550a70d575e59d7c659a7bf1afe909dd9 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2012,2013,2014,2015,2016,2018, by the GROMACS development team, led by
+ * Copyright (c) 2012,2013,2014,2015,2016,2018,2019, 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.
@@ -217,12 +217,20 @@ t_atoms
 gmx_mtop_global_atoms(const gmx_mtop_t *mtop);
 
 
-/* Generate a 'local' topology for the whole system.
+/*! \brief
+ * Populate a 'local' topology for the whole system.
+ *
  * When freeEnergyInteractionsAtEnd == true, the free energy interactions will
  * be sorted to the end.
+ *
+ * \param[in]     mtop                        The global topology used to populate the local one.
+ * \param[in,out] top                         New local topology populated from global \p mtop.
+ * \param[in]     freeEnergyInteractionsAtEnd If free energy interactions will be sorted.
  */
-gmx_localtop_t *
-gmx_mtop_generate_local_top(const gmx_mtop_t *mtop, bool freeEnergyInteractionsAtEnd);
+void
+gmx_mtop_generate_local_top(const gmx_mtop_t &mtop,
+                            gmx_localtop_t   *top,
+                            bool              freeEnergyInteractionsAtEnd);
 
 
 /*!\brief Creates and returns a struct with begin/end atom indices of all molecules
index 9e2caf22daa9e6a5f49b932ca3853c617c343798..eeacafe16329e1fb4c386300589b9d58681579e1 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, 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.
@@ -172,30 +172,23 @@ void done_top_mtop(t_topology *top, gmx_mtop_t *mtop)
     }
 }
 
-void init_localtop(gmx_localtop_t *top)
+gmx_localtop_t::gmx_localtop_t()
 {
-    init_block(&top->cgs);
-    init_blocka(&top->excls);
-    init_idef(&top->idef);
-    init_atomtypes(&top->atomtypes);
+    init_block_null(&cgs);
+    init_blocka_null(&excls);
+    init_idef(&idef);
+    init_atomtypes(&atomtypes);
 }
 
-void done_localtop(gmx_localtop_t *top)
+gmx_localtop_t::~gmx_localtop_t()
 {
-    if (top == nullptr)
+    if (!useInDomainDecomp_)
     {
-        return;
+        done_idef(&idef);
+        done_block(&cgs);
+        done_blocka(&excls);
+        done_atomtypes(&atomtypes);
     }
-    done_idef(&top->idef);
-    done_block(&top->cgs);
-    done_blocka(&top->excls);
-    done_atomtypes(&top->atomtypes);
-}
-
-void done_and_sfree_localtop(gmx_localtop_t *top)
-{
-    done_localtop(top);
-    sfree(top);
 }
 
 bool gmx_mtop_has_masses(const gmx_mtop_t *mtop)
index 8d46a12e9d80b107b8e5f95d96454343333aadb3..1bc48ec4fd4e8f7993c211a8db1b7915eed749a8 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2011,2014,2015,2016,2018, by the GROMACS development team, led by
+ * Copyright (c) 2011,2014,2015,2016,2018,2019, 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,14 +171,29 @@ struct gmx_mtop_t //NOLINT(clang-analyzer-optin.performance.Padding)
     std::vector<MoleculeBlockIndices> moleculeBlockIndices;
 };
 
-/* The mdrun node-local topology struct, completely written out */
-typedef struct gmx_localtop_t
+/* \brief
+ * The fully written out topology for a domain over its lifetime
+ *
+ * Also used in some analysis code.
+ */
+struct gmx_localtop_t
 {
-    t_idef        idef;         /* The interaction function definition  */
-    t_atomtypes   atomtypes;    /* Atomtype properties                  */
-    t_block       cgs;          /* The charge groups                    */
-    t_blocka      excls;        /* The exclusions                       */
-} gmx_localtop_t;
+    //! Constructor used for normal operation, manages own resources.
+    gmx_localtop_t();
+
+    ~gmx_localtop_t();
+
+    //! The interaction function definition
+    t_idef        idef;
+    //! Atomtype properties
+    t_atomtypes   atomtypes;
+    //! The charge groups
+    t_block       cgs;
+    //! The exclusions
+    t_blocka      excls;
+    //! Flag for domain decomposition so we don't free already freed memory.
+    bool          useInDomainDecomp_ = false;
+};
 
 /* The old topology struct, completely written out, used in analysis tools */
 typedef struct t_topology
@@ -200,19 +215,6 @@ void done_top(t_topology *top);
 // Frees both t_topology and gmx_mtop_t when the former has been created from
 // the latter.
 void done_top_mtop(t_topology *top, gmx_mtop_t *mtop);
-/*! \brief
- * Properly initialize local topology.
- *
- * \param[in] top Pointer to topology to initialize.
- */
-void init_localtop(gmx_localtop_t *top);
-/*! \brief
- * Properly clear up local topology,
- *
- * \param[in] top Pointer to topology to clear up.
- */
-void done_localtop(gmx_localtop_t *top);
-void done_and_sfree_localtop(gmx_localtop_t *top);
 
 bool gmx_mtop_has_masses(const gmx_mtop_t *mtop);
 bool gmx_mtop_has_charges(const gmx_mtop_t *mtop);
@@ -238,8 +240,8 @@ void cmp_top(FILE *fp, const t_topology *t1, const t_topology *t2, real ftol, re
 void compareAtomGroups(FILE *fp, const gmx_groups_t &g0, const gmx_groups_t &g1,
                        int natoms0, int natoms1);
 
-//! Deleter for gmx_localtop_t, needed until it has a proper destructor.
-using ExpandedTopologyPtr = gmx::unique_cptr<gmx_localtop_t, done_and_sfree_localtop>;
+//! Typedef for gmx_localtop in analysis tools.
+using ExpandedTopologyPtr = std::unique_ptr<gmx_localtop_t>;
 
 void copy_moltype(const gmx_moltype_t *src, gmx_moltype_t *dst);
 
index 917e7c1741aac9a889d896dbfd32cd62a18c8954..f7a292e649ae45c2871808fdff958a54eee87f49 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2018, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019, 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.
@@ -107,7 +107,8 @@ const gmx_localtop_t *TopologyInformation::expandedTopology() const
     // Do lazy initialization
     if (expandedTopology_ == nullptr && hasTopology())
     {
-        expandedTopology_.reset(gmx_mtop_generate_local_top(mtop_.get(), false));
+        expandedTopology_ = gmx::compat::make_unique<gmx_localtop_t>();
+        gmx_mtop_generate_local_top(*mtop_, expandedTopology_.get(), false);
     }
 
     return expandedTopology_.get();