Increase const correctness of t_mdatoms use in md.cpp
authorejjordan <ejjordan@kth.se>
Thu, 22 Apr 2021 12:22:07 +0000 (14:22 +0200)
committerArtem Zhmurov <zhmurov@gmail.com>
Tue, 27 Apr 2021 05:04:36 +0000 (05:04 +0000)
Previously two instances of t_mdatoms were made in do_md, once const
and one not. This replaces all instances where the non-const was not
used but could be with const usage. Also, non-const usage is now done
by calling MDAtoms->mdatoms() to indicate non-const usage more clearly.

src/gromacs/mdrun/md.cpp

index 425eda0de852359d92ff7fe84cc179def23a5793..ea5494534c9d0739200115c71420be08a644f726 100644 (file)
@@ -363,8 +363,6 @@ void gmx::LegacySimulator::do_md()
 
     gmx_localtop_t top(top_global.ffparams);
 
-    auto mdatoms = mdAtoms->mdatoms();
-
     ForceBuffers     f(fr->useMts,
                    ((useGpuForNonbonded && useGpuForBufferOps) || useGpuForUpdate)
                            ? PinningPolicy::PinnedIfSupported
@@ -447,7 +445,7 @@ void gmx::LegacySimulator::do_md()
                         || ir->epc == PressureCoupling::Berendsen || ir->epc == PressureCoupling::CRescale,
                 "Only Parrinello-Rahman, Berendsen, and C-rescale pressure coupling are supported "
                 "with the GPU update.\n");
-        GMX_RELEASE_ASSERT(!mdatoms->haveVsites,
+        GMX_RELEASE_ASSERT(!md->haveVsites,
                            "Virtual sites are not supported with the GPU update.\n");
         GMX_RELEASE_ASSERT(ed == nullptr,
                            "Essential dynamics is not supported with the GPU update.\n");
@@ -504,7 +502,7 @@ void gmx::LegacySimulator::do_md()
     // the global state to file and potentially for replica exchange.
     // (Global topology should persist.)
 
-    update_mdatoms(mdatoms, state->lambda[FreeEnergyPerturbationCouplingType::Mass]);
+    update_mdatoms(mdAtoms->mdatoms(), state->lambda[FreeEnergyPerturbationCouplingType::Mass]);
 
     if (ir->bExpanded)
     {
@@ -524,7 +522,7 @@ void gmx::LegacySimulator::do_md()
 
     preparePrevStepPullCom(ir,
                            pull_work,
-                           gmx::arrayRefFromArray(mdatoms->massT, mdatoms->nr),
+                           gmx::arrayRefFromArray(md->massT, md->nr),
                            state,
                            state_global,
                            cr,
@@ -563,17 +561,17 @@ void gmx::LegacySimulator::do_md()
         {
             auto v = makeArrayRef(state->v);
             /* Set the velocities of vsites, shells and frozen atoms to zero */
-            for (i = 0; i < mdatoms->homenr; i++)
+            for (i = 0; i < md->homenr; i++)
             {
-                if (mdatoms->ptype[i] == ParticleType::Shell)
+                if (md->ptype[i] == ParticleType::Shell)
                 {
                     clear_rvec(v[i]);
                 }
-                else if (mdatoms->cFREEZE)
+                else if (md->cFREEZE)
                 {
                     for (m = 0; m < DIM; m++)
                     {
-                        if (ir->opts.nFreeze[mdatoms->cFREEZE[i]][m])
+                        if (ir->opts.nFreeze[md->cFREEZE[i]][m])
                         {
                             v[i][m] = 0;
                         }
@@ -588,8 +586,8 @@ void gmx::LegacySimulator::do_md()
             do_constrain_first(fplog,
                                constr,
                                ir,
-                               mdatoms->nr,
-                               mdatoms->homenr,
+                               md->nr,
+                               md->homenr,
                                state->x.arrayRefWithPadding(),
                                state->v.arrayRefWithPadding(),
                                state->box,
@@ -676,7 +674,7 @@ void gmx::LegacySimulator::do_md()
                         makeConstArrayRef(state->x),
                         makeConstArrayRef(state->v),
                         state->box,
-                        mdatoms,
+                        md,
                         nrnb,
                         &vcm,
                         nullptr,
@@ -698,8 +696,8 @@ void gmx::LegacySimulator::do_md()
             auto x = (vcm.mode == ComRemovalAlgorithm::LinearAccelerationCorrection)
                              ? ArrayRef<RVec>()
                              : makeArrayRef(state->x);
-            process_and_stopcm_grp(fplog, &vcm, *mdatoms, x, makeArrayRef(state->v));
-            inc_nrnb(nrnb, eNR_STOPCM, mdatoms->homenr);
+            process_and_stopcm_grp(fplog, &vcm, *md, x, makeArrayRef(state->v));
+            inc_nrnb(nrnb, eNR_STOPCM, md->homenr);
         }
     }
     if (DOMAINDECOMP(cr))
@@ -723,7 +721,7 @@ void gmx::LegacySimulator::do_md()
                         makeConstArrayRef(state->x),
                         makeConstArrayRef(state->v),
                         state->box,
-                        mdatoms,
+                        md,
                         nrnb,
                         &vcm,
                         nullptr,
@@ -1050,7 +1048,7 @@ void gmx::LegacySimulator::do_md()
 
         if (ir->efep != FreeEnergyPerturbationType::No)
         {
-            update_mdatoms(mdatoms, state->lambda[FreeEnergyPerturbationCouplingType::Mass]);
+            update_mdatoms(mdAtoms->mdatoms(), state->lambda[FreeEnergyPerturbationCouplingType::Mass]);
         }
 
         if (bExchanged)
@@ -1071,7 +1069,7 @@ void gmx::LegacySimulator::do_md()
                             makeConstArrayRef(state->x),
                             makeConstArrayRef(state->v),
                             state->box,
-                            mdatoms,
+                            md,
                             nrnb,
                             &vcm,
                             wcycle,
@@ -1158,7 +1156,7 @@ void gmx::LegacySimulator::do_md()
                                 &state->hist,
                                 &f.view(),
                                 force_vir,
-                                *mdatoms,
+                                *md,
                                 nrnb,
                                 wcycle,
                                 shellfc,
@@ -1206,7 +1204,7 @@ void gmx::LegacySimulator::do_md()
                      &state->hist,
                      &f.view(),
                      force_vir,
-                     mdatoms,
+                     md,
                      enerd,
                      state->lambda,
                      fr,
@@ -1234,7 +1232,7 @@ void gmx::LegacySimulator::do_md()
                                  fr,
                                  cr,
                                  state,
-                                 mdatoms,
+                                 mdAtoms->mdatoms(),
                                  fcdata,
                                  &MassQ,
                                  &vcm,
@@ -1298,7 +1296,7 @@ void gmx::LegacySimulator::do_md()
                                               state->dfhist,
                                               step,
                                               state->v.rvec_array(),
-                                              mdatoms);
+                                              md);
             /* history is maintained in state->dfhist, but state_global is what is sent to trajectory and log output */
             if (MASTER(cr))
             {
@@ -1396,7 +1394,7 @@ void gmx::LegacySimulator::do_md()
         if (ETC_ANDERSEN(ir->etc)) /* keep this outside of update_tcouple because of the extra info required to pass */
         {
             gmx_bool bIfRandomize;
-            bIfRandomize = update_randomize_velocities(ir, step, cr, mdatoms, state->v, &upd, constr);
+            bIfRandomize = update_randomize_velocities(ir, step, cr, md, state->v, &upd, constr);
             /* if we have constraints, we have to remove the kinetic energy parallel to the bonds */
             if (constr && bIfRandomize)
             {
@@ -1419,7 +1417,7 @@ void gmx::LegacySimulator::do_md()
         /* UPDATE PRESSURE VARIABLES IN TROTTER FORMULATION WITH CONSTRAINTS */
         if (bTrotter)
         {
-            trotter_update(ir, step, ekind, enerd, state, total_vir, mdatoms, &MassQ, trotter_seq, ettTSEQ3);
+            trotter_update(ir, step, ekind, enerd, state, total_vir, md, &MassQ, trotter_seq, ettTSEQ3);
             /* We can only do Berendsen coupling after we have summed
              * the kinetic energy or virial. Since the happens
              * in global_state after update, we should only do it at
@@ -1428,7 +1426,7 @@ void gmx::LegacySimulator::do_md()
         }
         else
         {
-            update_tcouple(step, ir, state, ekind, &MassQ, mdatoms);
+            update_tcouple(step, ir, state, ekind, &MassQ, md);
             update_pcouple_before_coordinates(fplog, step, ir, state, pressureCouplingMu, M, bInitStep);
         }
 
@@ -1454,7 +1452,7 @@ void gmx::LegacySimulator::do_md()
                                   fr,
                                   cr,
                                   state,
-                                  mdatoms,
+                                  mdAtoms->mdatoms(),
                                   fcdata,
                                   &MassQ,
                                   &vcm,
@@ -1493,7 +1491,7 @@ void gmx::LegacySimulator::do_md()
                                     stateGpu->getVelocities(),
                                     stateGpu->getForces(),
                                     top.idef,
-                                    *mdatoms);
+                                    *md);
 
                     // Copy data to the GPU after buffers might have being reinitialized
                     stateGpu->copyVelocitiesToGpu(state->v, AtomLocality::Local);
@@ -1550,15 +1548,14 @@ void gmx::LegacySimulator::do_md()
                  */
                 if (fr->useMts && bCalcVir && constr != nullptr)
                 {
-                    upd.update_for_constraint_virial(
-                            *ir,
-                            mdatoms->homenr,
-                            mdatoms->havePartiallyFrozenAtoms,
-                            gmx::arrayRefFromArray(mdatoms->invmass, mdatoms->nr),
-                            gmx::arrayRefFromArray(mdatoms->invMassPerDim, mdatoms->nr),
-                            *state,
-                            f.view().forceWithPadding(),
-                            *ekind);
+                    upd.update_for_constraint_virial(*ir,
+                                                     md->homenr,
+                                                     md->havePartiallyFrozenAtoms,
+                                                     gmx::arrayRefFromArray(md->invmass, md->nr),
+                                                     gmx::arrayRefFromArray(md->invMassPerDim, md->nr),
+                                                     *state,
+                                                     f.view().forceWithPadding(),
+                                                     *ekind);
 
                     constrain_coordinates(constr,
                                           do_log,
@@ -1577,8 +1574,8 @@ void gmx::LegacySimulator::do_md()
                                 : f.view().forceWithPadding();
                 upd.update_coords(*ir,
                                   step,
-                                  mdatoms->homenr,
-                                  mdatoms->havePartiallyFrozenAtoms,
+                                  md->homenr,
+                                  md->havePartiallyFrozenAtoms,
                                   gmx::arrayRefFromArray(md->ptype, md->nr),
                                   gmx::arrayRefFromArray(md->invmass, md->nr),
                                   gmx::arrayRefFromArray(md->invMassPerDim, md->nr),
@@ -1606,7 +1603,7 @@ void gmx::LegacySimulator::do_md()
                 upd.update_sd_second_half(*ir,
                                           step,
                                           &dvdl_constr,
-                                          mdatoms->homenr,
+                                          md->homenr,
                                           gmx::arrayRefFromArray(md->ptype, md->nr),
                                           gmx::arrayRefFromArray(md->invmass, md->nr),
                                           state,
@@ -1617,7 +1614,7 @@ void gmx::LegacySimulator::do_md()
                                           do_log,
                                           do_ene);
                 upd.finish_update(
-                        *ir, mdatoms->havePartiallyFrozenAtoms, mdatoms->homenr, state, wcycle, constr != nullptr);
+                        *ir, md->havePartiallyFrozenAtoms, md->homenr, state, wcycle, constr != nullptr);
             }
 
             if (ir->bPull && ir->pull->bSetPbcRefToPrevStepCOM)
@@ -1665,7 +1662,7 @@ void gmx::LegacySimulator::do_md()
                         makeConstArrayRef(state->x),
                         makeConstArrayRef(state->v),
                         state->box,
-                        mdatoms,
+                        md,
                         nrnb,
                         &vcm,
                         wcycle,
@@ -1694,8 +1691,8 @@ void gmx::LegacySimulator::do_md()
                 if (!EI_VV(ir->eI) && bStopCM)
                 {
                     process_and_stopcm_grp(
-                            fplog, &vcm, *mdatoms, makeArrayRef(state->x), makeArrayRef(state->v));
-                    inc_nrnb(nrnb, eNR_STOPCM, mdatoms->homenr);
+                            fplog, &vcm, *md, makeArrayRef(state->x), makeArrayRef(state->v));
+                    inc_nrnb(nrnb, eNR_STOPCM, md->homenr);
 
                     // TODO: The special case of removing CM motion should be dealt more gracefully
                     if (useGpuForUpdate)
@@ -1730,7 +1727,7 @@ void gmx::LegacySimulator::do_md()
         }
 
         update_pcouple_after_coordinates(
-                fplog, step, ir, mdatoms, pres, force_vir, shake_vir, pressureCouplingMu, state, nrnb, upd.deform(), !useGpuForUpdate);
+                fplog, step, ir, md, pres, force_vir, shake_vir, pressureCouplingMu, state, nrnb, upd.deform(), !useGpuForUpdate);
 
         const bool doBerendsenPressureCoupling = (inputrec->epc == PressureCoupling::Berendsen
                                                   && do_per_step(step, inputrec->nstpcouple));
@@ -1806,7 +1803,7 @@ void gmx::LegacySimulator::do_md()
                 energyOutput.addDataAtEnergyStep(bDoDHDL,
                                                  bCalcEnerStep,
                                                  t,
-                                                 mdatoms->tmass,
+                                                 md->tmass,
                                                  enerd,
                                                  ir->fepvals.get(),
                                                  ir->expandedvals.get(),