Move ownership of kinetic energy object to ISimulator
authorPascal Merz <pascal.merz@me.com>
Tue, 25 Jun 2019 07:07:10 +0000 (01:07 -0600)
committerMark Abraham <mark.j.abraham@gmail.com>
Mon, 5 Aug 2019 20:44:38 +0000 (22:44 +0200)
Treating the kinetic energy object (ekind) equivalently to the
energy object (enerd) makes subsequent changes easier. It also
removes some code duplication between do_md, do_rerun and
do_mimic. There are some algorithms that never use the kinetic
energy (e.g. minimization), but this is true for other members
of ISimulator as well.

Change-Id: I995d14652dae25bcbcaa0a75437382a053e76f74

src/gromacs/mdlib/tgroup.cpp
src/gromacs/mdlib/tgroup.h
src/gromacs/mdrun/isimulator.h
src/gromacs/mdrun/md.cpp
src/gromacs/mdrun/mimic.cpp
src/gromacs/mdrun/rerun.cpp
src/gromacs/mdrun/runner.cpp

index b3a5c80e943f39056b8e12897dbc07e80a32f2ad..d70d7ad3d5408cbb080e4e0551047932f681cedb 100644 (file)
@@ -79,7 +79,7 @@ static void init_grpstat(const gmx_mtop_t *mtop, int ngacc, t_grp_acc gstat[])
 }
 
 void init_ekindata(FILE gmx_unused *log, const gmx_mtop_t *mtop, const t_grpopts *opts,
-                   gmx_ekindata_t *ekind)
+                   gmx_ekindata_t *ekind, real cos_accel)
 {
     int i;
     int nthread, thread;
@@ -135,6 +135,8 @@ void init_ekindata(FILE gmx_unused *log, const gmx_mtop_t *mtop, const t_grpopts
     ekind->ngacc = opts->ngacc;
     ekind->grpstat.resize(opts->ngacc);
     init_grpstat(mtop, opts->ngacc, ekind->grpstat.data());
+
+    ekind->cosacc.cos_accel = cos_accel;
 }
 
 void accumulate_u(const t_commrec *cr, const t_grpopts *opts, gmx_ekindata_t *ekind)
index 3530fe6f813dc8149b78c93af975a263e829cba5..274b077914ff7e4e9394b1cfd888480206ea358f 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,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,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.
@@ -51,7 +51,8 @@ struct t_mdatoms;
 
 void init_ekindata(FILE *log, const gmx_mtop_t *mtop,
                    const t_grpopts *opts,
-                   gmx_ekindata_t *ekind);
+                   gmx_ekindata_t *ekind,
+                   real cos_accel);
 /* Allocate memory and set the grpnr array. */
 
 void done_ekindata(gmx_ekindata_t *ekind);
index 2a8110b1da7d4db680351d968de248b642a69f04..9fbb343514b4571905283f7803cf4955148c39e4 100644 (file)
@@ -44,6 +44,7 @@
 #include "gromacs/mdlib/stophandler.h"
 
 class energyhistory_t;
+struct gmx_ekindata_t;
 struct gmx_enerdata_t;
 struct gmx_enfrot;
 struct gmx_mtop_t;
@@ -125,6 +126,7 @@ class ISimulator
             gmx_wallcycle                      *wcycle,
             t_forcerec                         *fr,
             gmx_enerdata_t                     *enerd,
+            gmx_ekindata_t                     *ekind,
             PpForceWorkload                    *ppForceWorkload,
             const ReplicaExchangeParameters    &replExParams,
             gmx_membed_t                       *membed,
@@ -158,6 +160,7 @@ class ISimulator
             wcycle(wcycle),
             fr(fr),
             enerd(enerd),
+            ekind(ekind),
             ppForceWorkload(ppForceWorkload),
             replExParams(replExParams),
             membed(membed),
@@ -221,6 +224,8 @@ class ISimulator
         t_forcerec                         *fr;
         //! Data for energy output.
         gmx_enerdata_t                     *enerd;
+        //! Kinetic energy data.
+        gmx_ekindata_t                     *ekind;
         //! Schedule of force-calculation work each step for this task.
         PpForceWorkload                    *ppForceWorkload;
         //! Parameters for replica exchange algorihtms.
index 167ad8a2fb44042350c0d0989def268467c99cd8..fb3bd42d4a5af6c9fe3ed26767a315dd9e631722 100644 (file)
@@ -260,13 +260,6 @@ void gmx::LegacySimulator::do_md()
                                          StartingBehavior::NewSimulation);
     gmx::EnergyOutput energyOutput(mdoutf_get_fp_ene(outf), top_global, ir, pull_work, mdoutf_get_fp_dhdl(outf), false);
 
-    /* Kinetic energy data */
-    std::unique_ptr<gmx_ekindata_t> eKinData = std::make_unique<gmx_ekindata_t>();
-    gmx_ekindata_t                 *ekind    = eKinData.get();
-    init_ekindata(fplog, top_global, &(ir->opts), ekind);
-    /* Copy the cos acceleration to the groups struct */
-    ekind->cosacc.cos_accel = ir->cos_accel;
-
     gstat = global_stat_init(ir);
 
     /* Check for polarizable models and flexible constraints */
index bfd709a0225e65e22dd3d5d3cc46c625b38cc931..703e1e792464fbf9e3dc1e130c398496318094bc 100644 (file)
@@ -230,13 +230,6 @@ void gmx::LegacySimulator::do_mimic()
                                           StartingBehavior::NewSimulation);
     gmx::EnergyOutput  energyOutput(mdoutf_get_fp_ene(outf), top_global, ir, pull_work, mdoutf_get_fp_dhdl(outf), true);
 
-    /* Kinetic energy data */
-    std::unique_ptr<gmx_ekindata_t> eKinData = std::make_unique<gmx_ekindata_t>();
-    gmx_ekindata_t                 *ekind    = eKinData.get();
-    init_ekindata(fplog, top_global, &(ir->opts), ekind);
-    /* Copy the cos acceleration to the groups struct */
-    ekind->cosacc.cos_accel = ir->cos_accel;
-
     gstat = global_stat_init(ir);
 
     /* Check for polarizable models and flexible constraints */
index eb31c8a309b7d30feded2214336c39c4462e6fbb..d3937bf09b82f96f19e53ddb91ded81bf94fc54b 100644 (file)
@@ -302,13 +302,6 @@ void gmx::LegacySimulator::do_rerun()
                                          StartingBehavior::NewSimulation);
     gmx::EnergyOutput energyOutput(mdoutf_get_fp_ene(outf), top_global, ir, pull_work, mdoutf_get_fp_dhdl(outf), true);
 
-    /* Kinetic energy data */
-    std::unique_ptr<gmx_ekindata_t> eKinData = std::make_unique<gmx_ekindata_t>();
-    gmx_ekindata_t                 *ekind    = eKinData.get();
-    init_ekindata(fplog, top_global, &(ir->opts), ekind);
-    /* Copy the cos acceleration to the groups struct */
-    ekind->cosacc.cos_accel = ir->cos_accel;
-
     gstat = global_stat_init(ir);
 
     /* Check for polarizable models and flexible constraints */
index 7f0c26fd7fdad261db9a2b4815f5b0c4972ec438..deef8f5b9e72b132f9ebcdc49315cfffb039b177 100644 (file)
 #include "gromacs/mdtypes/commrec.h"
 #include "gromacs/mdtypes/enerdata.h"
 #include "gromacs/mdtypes/fcdata.h"
+#include "gromacs/mdtypes/group.h"
 #include "gromacs/mdtypes/inputrec.h"
 #include "gromacs/mdtypes/md_enums.h"
 #include "gromacs/mdtypes/mdrunoptions.h"
@@ -1467,6 +1468,10 @@ int Mdrunner::mdrunner()
         /* Energy terms and groups */
         gmx_enerdata_t enerd(mtop.groups.groups[SimulationAtomGroupType::EnergyOutput].size(), inputrec->fepvals->n_lambda);
 
+        /* Kinetic energy data */
+        gmx_ekindata_t ekind;
+        init_ekindata(fplog, &mtop, &(inputrec->opts), &ekind, inputrec->cos_accel);
+
         /* Set up interactive MD (IMD) */
         auto imdSession = makeImdSession(inputrec, cr, wcycle, &enerd, ms, &mtop, mdlog,
                                          MASTER(cr) ? globalState->x.rvec_array() : nullptr,
@@ -1510,6 +1515,7 @@ int Mdrunner::mdrunner()
                     &observablesHistory,
                     mdAtoms.get(), &nrnb, wcycle, fr,
                     &enerd,
+                    &ekind,
                     &ppForceWorkload,
                     replExParams,
                     membed,