More const ref in shellfc
authorejjordan <ejjordan@kth.se>
Mon, 22 Mar 2021 09:30:50 +0000 (10:30 +0100)
committerAndrey Alekseenko <al42and@gmail.com>
Tue, 23 Mar 2021 08:19:44 +0000 (08:19 +0000)
Pass a const ref to t_mdatoms in shellfc functions. Part of work
to make refactoring t_mdatoms easier.

src/gromacs/domdec/mdsetup.cpp
src/gromacs/domdec/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/shellfc.cpp
src/gromacs/mdrun/shellfc.h
src/gromacs/modularsimulator/forceelement.cpp

index c2fd29ccb368d7973f197206b4b44e86d4969954..ccf793b0bd7088f25841b0422862ae151c61c746 100644 (file)
@@ -128,7 +128,7 @@ void mdAlgorithmsSetupAtomData(const t_commrec*     cr,
      */
     if (!usingDomDec && shellfc)
     {
-        make_local_shells(cr, mdatoms, shellfc);
+        make_local_shells(cr, *mdatoms, shellfc);
     }
 
     for (auto& listedForces : fr->listedForces)
index 007c410660f8d73b1d67684cdc377375b4e0f321..0023b797c93983fbee2d2eb564b07f3f287587d7 100644 (file)
@@ -67,7 +67,7 @@ class VirtualSitesHandler;
  * \param[in]     md        The MD atom data
  * \param[in,out] shfc      The shell/flexible-constraint data
  */
-void make_local_shells(const t_commrec* cr, const t_mdatoms* md, gmx_shellfc_t* shfc);
+void make_local_shells(const t_commrec* cr, const t_mdatoms& md, gmx_shellfc_t* shfc);
 
 /*! \brief Sets atom data for several MD algorithms
  *
index d577f3b08d513ca64bf1ca86afcbdcece6a6b437..77d3641a6db22983f2f0021d84de954a329f1b15 100644 (file)
@@ -1145,7 +1145,7 @@ void gmx::LegacySimulator::do_md()
                                 &state->hist,
                                 &f.view(),
                                 force_vir,
-                                mdatoms,
+                                *mdatoms,
                                 nrnb,
                                 wcycle,
                                 shellfc,
index f64a8c3e5dfc89f9436cf753048410ed44bf4a11..78239e1b0782073a06d18e2b1324de397f7536ac 100644 (file)
@@ -544,7 +544,7 @@ void gmx::LegacySimulator::do_mimic()
                                 &state->hist,
                                 &f.view(),
                                 force_vir,
-                                mdatoms,
+                                *mdatoms,
                                 nrnb,
                                 wcycle,
                                 shellfc,
index 33b067bde18f2a084cdd8dcccfc46d584f7b57ef..7c59a560058da0cd06e7bfce55eaadbdb59eae46 100644 (file)
@@ -3222,7 +3222,7 @@ void LegacySimulator::do_nm()
                                         &state_work.s.hist,
                                         &state_work.f.view(),
                                         vir,
-                                        mdatoms,
+                                        *mdatoms,
                                         nrnb,
                                         wcycle,
                                         shellfc,
index 8b11f9630e8464228e297c9bfa2fb78b0d151367..6ae83c4b3f7a9ea1fec5c05951dad2f3d6aa6a2a 100644 (file)
@@ -654,7 +654,7 @@ void gmx::LegacySimulator::do_rerun()
                                 &state->hist,
                                 &f.view(),
                                 force_vir,
-                                mdatoms,
+                                *mdatoms,
                                 nrnb,
                                 wcycle,
                                 shellfc,
index 73c14ac3b5453c08d824dd5b0b2a1f83a69e2505..0b630b6a5292a234de64df43505c9933df9ca8dd 100644 (file)
@@ -62,7 +62,6 @@
 #include "gromacs/mdlib/force.h"
 #include "gromacs/mdlib/force_flags.h"
 #include "gromacs/mdlib/gmx_omp_nthreads.h"
-#include "gromacs/mdlib/mdatoms.h"
 #include "gromacs/mdlib/vsite.h"
 #include "gromacs/mdtypes/commrec.h"
 #include "gromacs/mdtypes/enerdata.h"
@@ -536,7 +535,7 @@ gmx_shellfc_t* init_shell_flexcon(FILE*             fplog,
     return shfc;
 }
 
-void gmx::make_local_shells(const t_commrec* cr, const t_mdatoms* md, gmx_shellfc_t* shfc)
+void gmx::make_local_shells(const t_commrec* cr, const t_mdatoms& md, gmx_shellfc_t* shfc)
 {
     int           a0, a1;
     gmx_domdec_t* dd = nullptr;
@@ -559,9 +558,10 @@ void gmx::make_local_shells(const t_commrec* cr, const t_mdatoms* md, gmx_shellf
 
     std::vector<t_shell>& shells = shfc->shells;
     shells.clear();
+    auto ptype = md.ptype;
     for (int i = a0; i < a1; i++)
     {
-        if (md->ptype[i] == ParticleType::Shell)
+        if (ptype[i] == ParticleType::Shell)
         {
             if (dd)
             {
@@ -819,7 +819,7 @@ static void init_adir(gmx_shellfc_t*            shfc,
                       const t_commrec*          cr,
                       int                       dd_ac1,
                       int64_t                   step,
-                      const t_mdatoms*          md,
+                      const t_mdatoms&          md,
                       int                       end,
                       ArrayRefWithPadding<RVec> xOld,
                       ArrayRef<RVec>            x_init,
@@ -848,14 +848,14 @@ static void init_adir(gmx_shellfc_t*            shfc,
     rvec* x_old = as_rvec_array(xOld.paddedArrayRef().data());
     rvec* x     = as_rvec_array(xCurrent.paddedArrayRef().data());
 
-    const ParticleType* ptype = md->ptype;
-
-    dt = ir->delta_t;
+    auto ptype   = md.ptype;
+    auto invmass = gmx::arrayRefFromArray(md.invmass, md.nr);
+    dt           = ir->delta_t;
 
     /* Does NOT work with freeze groups (yet) */
     for (n = 0; n < end; n++)
     {
-        w_dt = md->invmass[n] * dt;
+        w_dt = invmass[n] * dt;
 
         for (d = 0; d < DIM; d++)
         {
@@ -910,7 +910,7 @@ static void init_adir(gmx_shellfc_t*            shfc,
         for (d = 0; d < DIM; d++)
         {
             xnew[n][d] = -(2 * x[n][d] - xnold[n][d] - xnew[n][d]) / gmx::square(dt)
-                         - f[n][d] * md->invmass[n];
+                         - f[n][d] * invmass[n];
         }
         clear_rvec(acc_dir[n]);
     }
@@ -955,7 +955,7 @@ void relax_shell_flexcon(FILE*                         fplog,
                          const history_t*              hist,
                          gmx::ForceBuffersView*        f,
                          tensor                        force_vir,
-                         const t_mdatoms*              md,
+                         const t_mdatoms&              md,
                          t_nrnb*                       nrnb,
                          gmx_wallcycle_t               wcycle,
                          gmx_shellfc_t*                shfc,
@@ -971,7 +971,7 @@ void relax_shell_flexcon(FILE*                         fplog,
     real dum = 0;
     char sbuf[22];
     int  nat, dd_ac0, dd_ac1 = 0, i;
-    int  homenr = md->homenr, end = homenr;
+    int  homenr = md.homenr, end = homenr;
     int  d, Min = 0, count = 0;
 #define Try (1 - Min) /* At start Try = 1 */
 
@@ -1024,8 +1024,7 @@ void relax_shell_flexcon(FILE*                         fplog,
          * before do_force is called, which normally puts all
          * charge groups in the box.
          */
-        put_atoms_in_box_omp(
-                fr->pbcType, box, x.subArray(0, md->homenr), gmx_omp_nthreads_get(emntDefault));
+        put_atoms_in_box_omp(fr->pbcType, box, x.subArray(0, md.homenr), gmx_omp_nthreads_get(emntDefault));
     }
 
     if (nflexcon)
@@ -1042,13 +1041,13 @@ void relax_shell_flexcon(FILE*                         fplog,
         }
     }
 
+    auto massT = gmx::arrayRefFromArray(md.massT, md.nr);
     /* Do a prediction of the shell positions, when appropriate.
      * Without velocities (EM, NM, BD) we only do initial prediction.
      */
     if (shfc->predictShells && !bCont && (EI_STATE_VELOCITY(inputrec->eI) || bInit))
     {
-        predict_shells(
-                fplog, x, v, inputrec->delta_t, shells, gmx::arrayRefFromArray(md->massT, md->homenr), bInit);
+        predict_shells(fplog, x, v, inputrec->delta_t, shells, massT, bInit);
     }
 
     /* Calculate the forces first time around */
@@ -1075,7 +1074,7 @@ void relax_shell_flexcon(FILE*                         fplog,
              hist,
              &forceViewInit,
              force_vir,
-             md,
+             &md,
              enerd,
              lambda,
              fr,
@@ -1109,7 +1108,7 @@ void relax_shell_flexcon(FILE*                         fplog,
 
         for (i = 0; i < end; i++)
         {
-            sf_dir += md->massT[i] * norm2(shfc->acc_dir[i]);
+            sf_dir += massT[i] * norm2(shfc->acc_dir[i]);
         }
     }
     accumulatePotentialEnergies(enerd, lambda, inputrec->fepvals.get());
@@ -1124,7 +1123,7 @@ void relax_shell_flexcon(FILE*                         fplog,
 
     if (gmx_debug_at)
     {
-        pr_rvecs(debug, 0, "force0", as_rvec_array(force[Min].data()), md->nr);
+        pr_rvecs(debug, 0, "force0", as_rvec_array(force[Min].data()), md.nr);
     }
 
     if (!shells.empty() || nflexcon > 0)
@@ -1215,7 +1214,7 @@ void relax_shell_flexcon(FILE*                         fplog,
                  hist,
                  &forceViewTry,
                  force_vir,
-                 md,
+                 &md,
                  enerd,
                  lambda,
                  fr,
@@ -1255,7 +1254,7 @@ void relax_shell_flexcon(FILE*                         fplog,
             ArrayRef<const RVec> acc_dir = shfc->acc_dir;
             for (i = 0; i < end; i++)
             {
-                sf_dir += md->massT[i] * norm2(acc_dir[i]);
+                sf_dir += massT[i] * norm2(acc_dir[i]);
             }
         }
 
index 76722cd33f85b086b6ee0827fa3604af4e5dc6b8..6d3120fd98c7f58c9a43a13d9dc5875352958726 100644 (file)
@@ -114,7 +114,7 @@ void relax_shell_flexcon(FILE*                               log,
                          const history_t*                    hist,
                          gmx::ForceBuffersView*              f,
                          tensor                              force_vir,
-                         const t_mdatoms*                    md,
+                         const t_mdatoms&                    md,
                          t_nrnb*                             nrnb,
                          gmx_wallcycle_t                     wcycle,
                          gmx_shellfc_t*                      shfc,
@@ -136,6 +136,6 @@ void done_shellfc(FILE* fplog, gmx_shellfc_t* shellfc, int64_t numSteps);
  * \param[in]  mtop  Molecular topology.
  * \returns Array holding the number of particles of a type
  */
-gmx::EnumerationArray<ParticleType, int> countPtypes(FILE* fplog, const gmx_mtop_t* mtop);
+gmx::EnumerationArray<ParticleType, int> countPtypes(FILE* fplog, const gmx_mtop_t& mtop);
 
 #endif
index 48fa24754d18f97871a9de6f0335f1e1abbabf6c..77565e161c3f83475c1e4854d3f87b72ba43f5fd 100644 (file)
@@ -130,7 +130,7 @@ ForceElement::ForceElement(StatePropagatorData*        statePropagatorData,
     {
         // This was done in mdAlgorithmsSetupAtomData(), but shellfc
         // won't be available outside this element.
-        make_local_shells(cr, mdAtoms->mdatoms(), shellfc_);
+        make_local_shells(cr, *mdAtoms->mdatoms(), shellfc_);
     }
 }
 
@@ -216,7 +216,7 @@ void ForceElement::run(Step step, Time time, unsigned int flags)
                             hist,
                             &forces,
                             force_vir,
-                            mdAtoms_->mdatoms(),
+                            *mdAtoms_->mdatoms(),
                             nrnb_,
                             wcycle_,
                             shellfc_,