Use ArrayRef in compute_globals
authorPascal Merz <pascal.merz@me.com>
Fri, 24 Jan 2020 23:10:22 +0000 (23:10 +0000)
committerPaul Bauer <paul.bauer.q@gmail.com>
Mon, 24 Feb 2020 09:45:16 +0000 (10:45 +0100)
This refactors compute_globals to use ArrayRef instead of rvec
pointers.

Change-Id: I0e16b7bcee0583326180c6c93a7feddbb7213bfe

14 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/mdlib/md_support.cpp
src/gromacs/mdlib/md_support.h
src/gromacs/mdlib/update.cpp
src/gromacs/mdlib/update.h
src/gromacs/mdlib/vcm.cpp
src/gromacs/mdlib/vcm.h
src/gromacs/mdrun/md.cpp
src/gromacs/mdrun/mimic.cpp
src/gromacs/mdrun/rerun.cpp
src/gromacs/modularsimulator/computeglobalselement.cpp

index 1f3fad44051cf9d9622bf60106e939720cb99346..39f8bd0b89922711e8d316e1ed18ecdead35f56a 100644 (file)
@@ -261,13 +261,13 @@ gmx::ArrayRef<const int> dd_constraints_nlocalatoms(const gmx_domdec_t* dd);
 /* In domdec_top.c */
 
 /*! \brief Print error output when interactions are missing */
-[[noreturn]] void dd_print_missing_interactions(const gmx::MDLogger&  mdlog,
-                                                t_commrec*            cr,
-                                                int                   local_count,
-                                                const gmx_mtop_t*     top_global,
-                                                const gmx_localtop_t* top_local,
-                                                const rvec*           x,
-                                                const matrix          box);
+[[noreturn]] void dd_print_missing_interactions(const gmx::MDLogger&           mdlog,
+                                                t_commrec*                     cr,
+                                                int                            local_count,
+                                                const gmx_mtop_t*              top_global,
+                                                const gmx_localtop_t*          top_local,
+                                                gmx::ArrayRef<const gmx::RVec> x,
+                                                const matrix                   box);
 
 /*! \brief Generate and store the reverse topology */
 void dd_make_reverse_top(FILE*              fplog,
index c34831c515c60951906bb1177e9d0c994f59fb69..e627bd2262e26bf1a6979702bc1a77c308255396 100644 (file)
@@ -329,13 +329,13 @@ static void print_missing_interactions_atoms(const gmx::MDLogger& mdlog,
     }
 }
 
-void dd_print_missing_interactions(const gmx::MDLogger&  mdlog,
-                                   t_commrec*            cr,
-                                   int                   local_count,
-                                   const gmx_mtop_t*     top_global,
-                                   const gmx_localtop_t* top_local,
-                                   const rvec*           x,
-                                   const matrix          box)
+void dd_print_missing_interactions(const gmx::MDLogger&           mdlog,
+                                   t_commrec*                     cr,
+                                   int                            local_count,
+                                   const gmx_mtop_t*              top_global,
+                                   const gmx_localtop_t*          top_local,
+                                   gmx::ArrayRef<const gmx::RVec> x,
+                                   const matrix                   box)
 {
     int           ndiff_tot, cl[F_NRE], n, ndiff, rest_global, rest_local;
     int           ftype, nral;
@@ -399,7 +399,7 @@ void dd_print_missing_interactions(const gmx::MDLogger&  mdlog,
     }
 
     print_missing_interactions_atoms(mdlog, cr, top_global, &top_local->idef);
-    write_dd_pdb("dd_dump_err", 0, "dump", top_global, cr, -1, x, box);
+    write_dd_pdb("dd_dump_err", 0, "dump", top_global, cr, -1, as_rvec_array(x.data()), box);
 
     std::string errorMessage;
 
index 0d034175bdb6f108c28dee519435ebf16805ddbf..e83408dfeac1db4c3f48d27d61b22dc8d23b4a68 100644 (file)
@@ -3227,14 +3227,14 @@ void dd_partition_system(FILE*                        fplog,
 }
 
 /*! \brief Check whether bonded interactions are missing, if appropriate */
-void checkNumberOfBondedInteractions(const gmx::MDLogger&  mdlog,
-                                     t_commrec*            cr,
-                                     int                   totalNumberOfBondedInteractions,
-                                     const gmx_mtop_t*     top_global,
-                                     const gmx_localtop_t* top_local,
-                                     const rvec*           x,
-                                     const matrix          box,
-                                     bool*                 shouldCheckNumberOfBondedInteractions)
+void checkNumberOfBondedInteractions(const gmx::MDLogger&           mdlog,
+                                     t_commrec*                     cr,
+                                     int                            totalNumberOfBondedInteractions,
+                                     const gmx_mtop_t*              top_global,
+                                     const gmx_localtop_t*          top_local,
+                                     gmx::ArrayRef<const gmx::RVec> x,
+                                     const matrix                   box,
+                                     bool* shouldCheckNumberOfBondedInteractions)
 {
     if (*shouldCheckNumberOfBondedInteractions)
     {
index fc07a745b195cb5d80062d9f90da75b37cfdbc43..721893a3711ed2da16a7d2cdd46838ab6705f512 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2018,2019, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019,2020, 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.
@@ -139,13 +139,13 @@ void dd_partition_system(FILE*                             fplog,
  * \param[in]    box                                    Box matrix for the error message
  * \param[in,out] shouldCheckNumberOfBondedInteractions Whether we should do the check. Always set to false.
  */
-void checkNumberOfBondedInteractions(const gmx::MDLogger&  mdlog,
-                                     t_commrec*            cr,
-                                     int                   totalNumberOfBondedInteractions,
-                                     const gmx_mtop_t*     top_global,
-                                     const gmx_localtop_t* top_local,
-                                     const rvec*           x,
-                                     const matrix          box,
-                                     bool*                 shouldCheckNumberOfBondedInteractions);
+void checkNumberOfBondedInteractions(const gmx::MDLogger&           mdlog,
+                                     t_commrec*                     cr,
+                                     int                            totalNumberOfBondedInteractions,
+                                     const gmx_mtop_t*              top_global,
+                                     const gmx_localtop_t*          top_local,
+                                     gmx::ArrayRef<const gmx::RVec> x,
+                                     const matrix                   box,
+                                     bool* shouldCheckNumberOfBondedInteractions);
 
 #endif
index bc3536d247fa4ff4e3a259aa946ceb589dc690db..fb3a048e72466a8034d0eeed3aeb2ece39bf24ab 100644 (file)
@@ -154,30 +154,30 @@ int multisim_min(const gmx_multisim_t* ms, int nmin, int n)
 
 /* TODO Specialize this routine into init-time and loop-time versions?
    e.g. bReadEkin is only true when restoring from checkpoint */
-void compute_globals(gmx_global_stat*          gstat,
-                     t_commrec*                cr,
-                     const t_inputrec*         ir,
-                     t_forcerec*               fr,
-                     gmx_ekindata_t*           ekind,
-                     const rvec*               x,
-                     const rvec*               v,
-                     const matrix              box,
-                     real                      vdwLambda,
-                     const t_mdatoms*          mdatoms,
-                     t_nrnb*                   nrnb,
-                     t_vcm*                    vcm,
-                     gmx_wallcycle_t           wcycle,
-                     gmx_enerdata_t*           enerd,
-                     tensor                    force_vir,
-                     tensor                    shake_vir,
-                     tensor                    total_vir,
-                     tensor                    pres,
-                     gmx::Constraints*         constr,
-                     gmx::SimulationSignaller* signalCoordinator,
-                     const matrix              lastbox,
-                     int*                      totalNumberOfBondedInteractions,
-                     gmx_bool*                 bSumEkinhOld,
-                     const int                 flags)
+void compute_globals(gmx_global_stat*               gstat,
+                     t_commrec*                     cr,
+                     const t_inputrec*              ir,
+                     t_forcerec*                    fr,
+                     gmx_ekindata_t*                ekind,
+                     gmx::ArrayRef<const gmx::RVec> x,
+                     gmx::ArrayRef<const gmx::RVec> v,
+                     const matrix                   box,
+                     real                           vdwLambda,
+                     const t_mdatoms*               mdatoms,
+                     t_nrnb*                        nrnb,
+                     t_vcm*                         vcm,
+                     gmx_wallcycle_t                wcycle,
+                     gmx_enerdata_t*                enerd,
+                     tensor                         force_vir,
+                     tensor                         shake_vir,
+                     tensor                         total_vir,
+                     tensor                         pres,
+                     gmx::Constraints*              constr,
+                     gmx::SimulationSignaller*      signalCoordinator,
+                     const matrix                   lastbox,
+                     int*                           totalNumberOfBondedInteractions,
+                     gmx_bool*                      bSumEkinhOld,
+                     const int                      flags)
 {
     gmx_bool bEner, bPres, bTemp;
     gmx_bool bStopCM, bGStat, bReadEkin, bEkinAveVel, bScaleEkin, bConstrain;
index 01cb5c7e8e811a4cfb611b9edf6f31ab385df980..e13fa1f4838da0caa0415f1c194545b1785f78a3 100644 (file)
@@ -131,29 +131,29 @@ int multisim_min(const gmx_multisim_t* ms, int nmin, int n);
  * and for COM removal with rotational and acceleration correction modes.
  * Velocities v are needed for kinetic energy calculation and for COM removal.
  */
-void compute_globals(gmx_global_stat*          gstat,
-                     t_commrec*                cr,
-                     const t_inputrec*         ir,
-                     t_forcerec*               fr,
-                     gmx_ekindata_t*           ekind,
-                     const rvec*               x,
-                     const rvec*               v,
-                     const matrix              box,
-                     real                      vdwLambda,
-                     const t_mdatoms*          mdatoms,
-                     t_nrnb*                   nrnb,
-                     t_vcm*                    vcm,
-                     gmx_wallcycle_t           wcycle,
-                     gmx_enerdata_t*           enerd,
-                     tensor                    force_vir,
-                     tensor                    shake_vir,
-                     tensor                    total_vir,
-                     tensor                    pres,
-                     gmx::Constraints*         constr,
-                     gmx::SimulationSignaller* signalCoordinator,
-                     const matrix              lastbox,
-                     int*                      totalNumberOfBondedInteractions,
-                     gmx_bool*                 bSumEkinhOld,
-                     int                       flags);
+void compute_globals(gmx_global_stat*               gstat,
+                     t_commrec*                     cr,
+                     const t_inputrec*              ir,
+                     t_forcerec*                    fr,
+                     gmx_ekindata_t*                ekind,
+                     gmx::ArrayRef<const gmx::RVec> x,
+                     gmx::ArrayRef<const gmx::RVec> v,
+                     const matrix                   box,
+                     real                           vdwLambda,
+                     const t_mdatoms*               mdatoms,
+                     t_nrnb*                        nrnb,
+                     t_vcm*                         vcm,
+                     gmx_wallcycle_t                wcycle,
+                     gmx_enerdata_t*                enerd,
+                     tensor                         force_vir,
+                     tensor                         shake_vir,
+                     tensor                         total_vir,
+                     tensor                         pres,
+                     gmx::Constraints*              constr,
+                     gmx::SimulationSignaller*      signalCoordinator,
+                     const matrix                   lastbox,
+                     int*                           totalNumberOfBondedInteractions,
+                     gmx_bool*                      bSumEkinhOld,
+                     int                            flags);
 
 #endif
index 2d00dd6aec066c006e0b6758aec42cf810cc9fbf..06a51f9fb271f87beeb4e21b889a9aba2b3a5f40 100644 (file)
@@ -1043,12 +1043,12 @@ static void do_update_bd(int                  start,
     }
 }
 
-static void calc_ke_part_normal(const rvec       v[],
-                                const t_grpopts* opts,
-                                const t_mdatoms* md,
-                                gmx_ekindata_t*  ekind,
-                                t_nrnb*          nrnb,
-                                gmx_bool         bEkinAveVel)
+static void calc_ke_part_normal(ArrayRef<const RVec> v,
+                                const t_grpopts*     opts,
+                                const t_mdatoms*     md,
+                                gmx_ekindata_t*      ekind,
+                                t_nrnb*              nrnb,
+                                gmx_bool             bEkinAveVel)
 {
     int                         g;
     gmx::ArrayRef<t_grp_tcstat> tcstat  = ekind->tcstat;
@@ -1159,14 +1159,14 @@ static void calc_ke_part_normal(const rvec       v[],
     inc_nrnb(nrnb, eNR_EKIN, md->homenr);
 }
 
-static void calc_ke_part_visc(const matrix     box,
-                              const rvec       x[],
-                              const rvec       v[],
-                              const t_grpopts* opts,
-                              const t_mdatoms* md,
-                              gmx_ekindata_t*  ekind,
-                              t_nrnb*          nrnb,
-                              gmx_bool         bEkinAveVel)
+static void calc_ke_part_visc(const matrix         box,
+                              ArrayRef<const RVec> x,
+                              ArrayRef<const RVec> v,
+                              const t_grpopts*     opts,
+                              const t_mdatoms*     md,
+                              gmx_ekindata_t*      ekind,
+                              t_nrnb*              nrnb,
+                              gmx_bool             bEkinAveVel)
 {
     int                         start = 0, homenr = md->homenr;
     int                         g, d, n, m, gt = 0;
@@ -1236,14 +1236,14 @@ static void calc_ke_part_visc(const matrix     box,
     inc_nrnb(nrnb, eNR_EKIN, homenr);
 }
 
-void calc_ke_part(const rvec*      x,
-                  const rvec*      v,
-                  const matrix     box,
-                  const t_grpopts* opts,
-                  const t_mdatoms* md,
-                  gmx_ekindata_t*  ekind,
-                  t_nrnb*          nrnb,
-                  gmx_bool         bEkinAveVel)
+void calc_ke_part(ArrayRef<const RVec> x,
+                  ArrayRef<const RVec> v,
+                  const matrix         box,
+                  const t_grpopts*     opts,
+                  const t_mdatoms*     md,
+                  gmx_ekindata_t*      ekind,
+                  t_nrnb*              nrnb,
+                  gmx_bool             bEkinAveVel)
 {
     if (ekind->cosacc.cos_accel == 0)
     {
index 5b9607b2aa37a18122fc5bac6b122c960287ea2e..acd097e3b762deaff89d29986f318e69c25328ba 100644 (file)
@@ -205,14 +205,14 @@ void finish_update(const t_inputrec*       inputrec,
 
 /* Return TRUE if OK, FALSE in case of Shake Error */
 
-void calc_ke_part(const rvec*      x,
-                  const rvec*      v,
-                  const matrix     box,
-                  const t_grpopts* opts,
-                  const t_mdatoms* md,
-                  gmx_ekindata_t*  ekind,
-                  t_nrnb*          nrnb,
-                  gmx_bool         bEkinAveVel);
+void calc_ke_part(gmx::ArrayRef<const gmx::RVec> x,
+                  gmx::ArrayRef<const gmx::RVec> v,
+                  const matrix                   box,
+                  const t_grpopts*               opts,
+                  const t_mdatoms*               md,
+                  gmx_ekindata_t*                ekind,
+                  t_nrnb*                        nrnb,
+                  gmx_bool                       bEkinAveVel);
 /*
  * Compute the partial kinetic energy for home particles;
  * will be accumulated in the calling routine.
index 89b923706bdd623b3c038e3e7a70aeefc4423da5..b34bbdef355bca1c2f4f9c12c44720be51a48847 100644 (file)
@@ -152,7 +152,10 @@ static void update_tensor(const rvec x, real m0, tensor I)
 }
 
 /* Center of mass code for groups */
-void calc_vcm_grp(const t_mdatoms& md, const rvec x[], const rvec v[], t_vcm* vcm)
+void calc_vcm_grp(const t_mdatoms&               md,
+                  gmx::ArrayRef<const gmx::RVec> x,
+                  gmx::ArrayRef<const gmx::RVec> v,
+                  t_vcm*                         vcm)
 {
     if (vcm->mode == ecmNO)
     {
@@ -253,7 +256,7 @@ void calc_vcm_grp(const t_mdatoms& md, const rvec x[], const rvec v[], t_vcm* vc
  * \param[in]     vcm       VCM data
  */
 template<int numDimensions>
-static void doStopComMotionLinear(const t_mdatoms& mdatoms, rvec* v, const t_vcm& vcm)
+static void doStopComMotionLinear(const t_mdatoms& mdatoms, gmx::ArrayRef<gmx::RVec> v, const t_vcm& vcm)
 {
     const int             homenr   = mdatoms.homenr;
     const unsigned short* group_id = mdatoms.cVCM;
@@ -313,11 +316,11 @@ static void doStopComMotionLinear(const t_mdatoms& mdatoms, rvec* v, const t_vcm
  * \param[in]     vcm       VCM data
  */
 template<int numDimensions>
-static void doStopComMotionAccelerationCorrection(int                   homenr,
-                                                  const unsigned short* group_id,
-                                                  rvec* gmx_restrict x,
-                                                  rvec* gmx_restrict v,
-                                                  const t_vcm&       vcm)
+static void doStopComMotionAccelerationCorrection(int                      homenr,
+                                                  const unsigned short*    group_id,
+                                                  gmx::ArrayRef<gmx::RVec> x,
+                                                  gmx::ArrayRef<gmx::RVec> v,
+                                                  const t_vcm&             vcm)
 {
     const real xCorrectionFactor = 0.5 * vcm.timeStep;
 
@@ -348,7 +351,10 @@ static void doStopComMotionAccelerationCorrection(int                   homenr,
     }
 }
 
-static void do_stopcm_grp(const t_mdatoms& mdatoms, rvec x[], rvec v[], const t_vcm& vcm)
+static void do_stopcm_grp(const t_mdatoms&         mdatoms,
+                          gmx::ArrayRef<gmx::RVec> x,
+                          gmx::ArrayRef<gmx::RVec> v,
+                          const t_vcm&             vcm)
 {
     if (vcm.mode == ecmNO)
     {
@@ -365,7 +371,7 @@ static void do_stopcm_grp(const t_mdatoms& mdatoms, rvec x[], rvec v[], const t_
         firstprivate(homenr)
         {
             if (vcm.mode == ecmLINEAR || vcm.mode == ecmANGULAR
-                || (vcm.mode == ecmLINEAR_ACCELERATION_CORRECTION && x == nullptr))
+                || (vcm.mode == ecmLINEAR_ACCELERATION_CORRECTION && x.empty()))
             {
                 /* Subtract linear momentum for v */
                 switch (vcm.ndim)
@@ -397,7 +403,7 @@ static void do_stopcm_grp(const t_mdatoms& mdatoms, rvec x[], rvec v[], const t_
             if (vcm.mode == ecmANGULAR)
             {
                 /* Subtract angular momentum */
-                GMX_ASSERT(x, "Need x to compute angular momentum correction");
+                GMX_ASSERT(!x.empty(), "Need x to compute angular momentum correction");
 
                 int g = 0;
 #pragma omp for schedule(static)
@@ -569,7 +575,11 @@ static void process_and_check_cm_grp(FILE* fp, t_vcm* vcm, real Temp_Max)
     }
 }
 
-void process_and_stopcm_grp(FILE* fplog, t_vcm* vcm, const t_mdatoms& mdatoms, rvec x[], rvec v[])
+void process_and_stopcm_grp(FILE*                    fplog,
+                            t_vcm*                   vcm,
+                            const t_mdatoms&         mdatoms,
+                            gmx::ArrayRef<gmx::RVec> x,
+                            gmx::ArrayRef<gmx::RVec> v)
 {
     if (vcm->mode != ecmNO)
     {
index acafb8d8ba791bab258552456f7e321221596fe3..b0c142474101f740f8fda554d70e1b6ee6382118 100644 (file)
@@ -50,6 +50,12 @@ struct SimulationGroups;
 struct t_inputrec;
 struct t_mdatoms;
 
+namespace gmx
+{
+template<typename T>
+class ArrayRef;
+}
+
 struct t_vcm_thread
 {
     //! Linear momentum
@@ -113,7 +119,10 @@ void reportComRemovalInfo(FILE* fp, const t_vcm& vcm);
 
 
 /* Do a per group center of mass things */
-void calc_vcm_grp(const t_mdatoms& md, const rvec x[], const rvec v[], t_vcm* vcm);
+void calc_vcm_grp(const t_mdatoms&               md,
+                  gmx::ArrayRef<const gmx::RVec> x,
+                  gmx::ArrayRef<const gmx::RVec> v,
+                  t_vcm*                         vcm);
 
 /* Set the COM velocity to zero and potentially correct the COM position.
  *
@@ -123,6 +132,10 @@ void calc_vcm_grp(const t_mdatoms& md, const rvec x[], const rvec v[], t_vcm* vc
  * and a pointer to the coordinates at normal MD steps.
  * When fplog != nullptr, a warning is printed to fplog with high COM velocity.
  */
-void process_and_stopcm_grp(FILE* fplog, t_vcm* vcm, const t_mdatoms& mdatoms, rvec x[], rvec v[]);
+void process_and_stopcm_grp(FILE*                    fplog,
+                            t_vcm*                   vcm,
+                            const t_mdatoms&         mdatoms,
+                            gmx::ArrayRef<gmx::RVec> x,
+                            gmx::ArrayRef<gmx::RVec> v);
 
 #endif
index 5314e3ac9c39e9423ce4689c63eba32cbf4153e8..0f3fc85c0707a9fd8b3cbefabef7d4c9f5fa6148 100644 (file)
@@ -540,10 +540,10 @@ void gmx::LegacySimulator::do_md()
             cglo_flags_iteration |= CGLO_STOPCM;
             cglo_flags_iteration &= ~CGLO_TEMPERATURE;
         }
-        compute_globals(gstat, cr, ir, fr, ekind, state->x.rvec_array(), state->v.rvec_array(),
-                        state->box, state->lambda[efptVDW], mdatoms, nrnb, &vcm, nullptr, enerd,
-                        force_vir, shake_vir, total_vir, pres, constr, &nullSignaller, state->box,
-                        &totalNumberOfBondedInteractions, &bSumEkinhOld,
+        compute_globals(gstat, cr, ir, fr, ekind, makeConstArrayRef(state->x),
+                        makeConstArrayRef(state->v), state->box, state->lambda[efptVDW], mdatoms,
+                        nrnb, &vcm, nullptr, enerd, force_vir, shake_vir, total_vir, pres, constr,
+                        &nullSignaller, state->box, &totalNumberOfBondedInteractions, &bSumEkinhOld,
                         cglo_flags_iteration
                                 | (shouldCheckNumberOfBondedInteractions ? CGLO_CHECK_NUMBER_OF_BONDED_INTERACTIONS
                                                                          : 0));
@@ -552,17 +552,14 @@ void gmx::LegacySimulator::do_md()
             /* At initialization, do not pass x with acceleration-correction mode
              * to avoid (incorrect) correction of the initial coordinates.
              */
-            rvec* xPtr = nullptr;
-            if (vcm.mode != ecmLINEAR_ACCELERATION_CORRECTION)
-            {
-                xPtr = state->x.rvec_array();
-            }
-            process_and_stopcm_grp(fplog, &vcm, *mdatoms, xPtr, state->v.rvec_array());
+            auto x = (vcm.mode == ecmLINEAR_ACCELERATION_CORRECTION) ? ArrayRef<RVec>()
+                                                                     : makeArrayRef(state->x);
+            process_and_stopcm_grp(fplog, &vcm, *mdatoms, x, makeArrayRef(state->v));
             inc_nrnb(nrnb, eNR_STOPCM, mdatoms->homenr);
         }
     }
     checkNumberOfBondedInteractions(mdlog, cr, totalNumberOfBondedInteractions, top_global, &top,
-                                    state->x.rvec_array(), state->box,
+                                    makeConstArrayRef(state->x), state->box,
                                     &shouldCheckNumberOfBondedInteractions);
     if (ir->eI == eiVVAK)
     {
@@ -572,10 +569,10 @@ void gmx::LegacySimulator::do_md()
            kinetic energy calculation.  This minimized excess variables, but
            perhaps loses some logic?*/
 
-        compute_globals(gstat, cr, ir, fr, ekind, state->x.rvec_array(), state->v.rvec_array(),
-                        state->box, state->lambda[efptVDW], mdatoms, nrnb, &vcm, nullptr, enerd,
-                        force_vir, shake_vir, total_vir, pres, constr, &nullSignaller, state->box,
-                        nullptr, &bSumEkinhOld, cglo_flags & ~CGLO_PRESSURE);
+        compute_globals(gstat, cr, ir, fr, ekind, makeConstArrayRef(state->x),
+                        makeConstArrayRef(state->v), state->box, state->lambda[efptVDW], mdatoms,
+                        nrnb, &vcm, nullptr, enerd, force_vir, shake_vir, total_vir, pres, constr,
+                        &nullSignaller, state->box, nullptr, &bSumEkinhOld, cglo_flags & ~CGLO_PRESSURE);
     }
 
     /* Calculate the initial half step temperature, and save the ekinh_old */
@@ -875,13 +872,13 @@ void gmx::LegacySimulator::do_md()
             /* We need the kinetic energy at minus the half step for determining
              * the full step kinetic energy and possibly for T-coupling.*/
             /* This may not be quite working correctly yet . . . . */
-            compute_globals(gstat, cr, ir, fr, ekind, state->x.rvec_array(), state->v.rvec_array(),
-                            state->box, state->lambda[efptVDW], mdatoms, nrnb, &vcm, wcycle, enerd,
-                            nullptr, nullptr, nullptr, nullptr, constr, &nullSignaller, state->box,
-                            &totalNumberOfBondedInteractions, &bSumEkinhOld,
+            compute_globals(gstat, cr, ir, fr, ekind, makeConstArrayRef(state->x),
+                            makeConstArrayRef(state->v), state->box, state->lambda[efptVDW], mdatoms,
+                            nrnb, &vcm, wcycle, enerd, nullptr, nullptr, nullptr, nullptr, constr,
+                            &nullSignaller, state->box, &totalNumberOfBondedInteractions, &bSumEkinhOld,
                             CGLO_GSTAT | CGLO_TEMPERATURE | CGLO_CHECK_NUMBER_OF_BONDED_INTERACTIONS);
             checkNumberOfBondedInteractions(mdlog, cr, totalNumberOfBondedInteractions, top_global,
-                                            &top, state->x.rvec_array(), state->box,
+                                            &top, makeConstArrayRef(state->x), state->box,
                                             &shouldCheckNumberOfBondedInteractions);
         }
         clear_mat(force_vir);
@@ -1013,16 +1010,17 @@ void gmx::LegacySimulator::do_md()
             if (bGStat || do_per_step(step - 1, nstglobalcomm))
             {
                 wallcycle_stop(wcycle, ewcUPDATE);
-                compute_globals(gstat, cr, ir, fr, ekind, state->x.rvec_array(), state->v.rvec_array(),
-                                state->box, state->lambda[efptVDW], mdatoms, nrnb, &vcm, wcycle,
-                                enerd, force_vir, shake_vir, total_vir, pres, constr, &nullSignaller,
-                                state->box, &totalNumberOfBondedInteractions, &bSumEkinhOld,
-                                (bGStat ? CGLO_GSTAT : 0) | (bCalcEner ? CGLO_ENERGY : 0)
-                                        | (bTemp ? CGLO_TEMPERATURE : 0) | (bPres ? CGLO_PRESSURE : 0)
-                                        | (bPres ? CGLO_CONSTRAINT : 0) | (bStopCM ? CGLO_STOPCM : 0)
-                                        | (shouldCheckNumberOfBondedInteractions ? CGLO_CHECK_NUMBER_OF_BONDED_INTERACTIONS
-                                                                                 : 0)
-                                        | CGLO_SCALEEKIN);
+                compute_globals(
+                        gstat, cr, ir, fr, ekind, makeConstArrayRef(state->x),
+                        makeConstArrayRef(state->v), state->box, state->lambda[efptVDW], mdatoms,
+                        nrnb, &vcm, wcycle, enerd, force_vir, shake_vir, total_vir, pres, constr,
+                        &nullSignaller, state->box, &totalNumberOfBondedInteractions, &bSumEkinhOld,
+                        (bGStat ? CGLO_GSTAT : 0) | (bCalcEner ? CGLO_ENERGY : 0)
+                                | (bTemp ? CGLO_TEMPERATURE : 0) | (bPres ? CGLO_PRESSURE : 0)
+                                | (bPres ? CGLO_CONSTRAINT : 0) | (bStopCM ? CGLO_STOPCM : 0)
+                                | (shouldCheckNumberOfBondedInteractions ? CGLO_CHECK_NUMBER_OF_BONDED_INTERACTIONS
+                                                                         : 0)
+                                | CGLO_SCALEEKIN);
                 /* explanation of above:
                    a) We compute Ekin at the full time step
                    if 1) we are using the AveVel Ekin, and it's not the
@@ -1031,12 +1029,12 @@ void gmx::LegacySimulator::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->x.rvec_array(), state->box,
-                                                &shouldCheckNumberOfBondedInteractions);
+                                                top_global, &top, makeConstArrayRef(state->x),
+                                                state->box, &shouldCheckNumberOfBondedInteractions);
                 if (bStopCM)
                 {
-                    process_and_stopcm_grp(fplog, &vcm, *mdatoms, state->x.rvec_array(),
-                                           state->v.rvec_array());
+                    process_and_stopcm_grp(fplog, &vcm, *mdatoms, makeArrayRef(state->x),
+                                           makeArrayRef(state->v));
                     inc_nrnb(nrnb, eNR_STOPCM, mdatoms->homenr);
                 }
                 wallcycle_start(wcycle, ewcUPDATE);
@@ -1074,8 +1072,8 @@ void gmx::LegacySimulator::do_md()
                     /* We need the kinetic energy at minus the half step for determining
                      * the full step kinetic energy and possibly for T-coupling.*/
                     /* This may not be quite working correctly yet . . . . */
-                    compute_globals(gstat, cr, ir, fr, ekind, state->x.rvec_array(),
-                                    state->v.rvec_array(), state->box, state->lambda[efptVDW],
+                    compute_globals(gstat, cr, ir, fr, ekind, makeConstArrayRef(state->x),
+                                    makeConstArrayRef(state->v), state->box, state->lambda[efptVDW],
                                     mdatoms, nrnb, &vcm, wcycle, enerd, nullptr, nullptr, nullptr,
                                     nullptr, constr, &nullSignaller, state->box, nullptr,
                                     &bSumEkinhOld, CGLO_GSTAT | CGLO_TEMPERATURE);
@@ -1324,10 +1322,11 @@ void gmx::LegacySimulator::do_md()
         {
             /* erase F_EKIN and F_TEMP here? */
             /* just compute the kinetic energy at the half step to perform a trotter step */
-            compute_globals(gstat, cr, ir, fr, ekind, state->x.rvec_array(), state->v.rvec_array(),
-                            state->box, state->lambda[efptVDW], mdatoms, nrnb, &vcm, wcycle, enerd,
-                            force_vir, shake_vir, total_vir, pres, constr, &nullSignaller, lastbox,
-                            nullptr, &bSumEkinhOld, (bGStat ? CGLO_GSTAT : 0) | CGLO_TEMPERATURE);
+            compute_globals(gstat, cr, ir, fr, ekind, makeConstArrayRef(state->x),
+                            makeConstArrayRef(state->v), state->box, state->lambda[efptVDW],
+                            mdatoms, nrnb, &vcm, wcycle, enerd, force_vir, shake_vir, total_vir,
+                            pres, constr, &nullSignaller, lastbox, nullptr, &bSumEkinhOld,
+                            (bGStat ? CGLO_GSTAT : 0) | CGLO_TEMPERATURE);
             wallcycle_start(wcycle, ewcUPDATE);
             trotter_update(ir, step, ekind, enerd, state, total_vir, mdatoms, &MassQ, trotter_seq, ettTSEQ4);
             /* now we know the scaling, we can compute the positions again */
@@ -1413,10 +1412,10 @@ void gmx::LegacySimulator::do_md()
                 SimulationSignaller signaller(&signals, cr, ms, doInterSimSignal, doIntraSimSignal);
 
                 compute_globals(
-                        gstat, cr, ir, fr, ekind, state->x.rvec_array(), state->v.rvec_array(),
-                        state->box, state->lambda[efptVDW], mdatoms, nrnb, &vcm, wcycle, enerd,
-                        force_vir, shake_vir, total_vir, pres, constr, &signaller, lastbox,
-                        &totalNumberOfBondedInteractions, &bSumEkinhOld,
+                        gstat, cr, ir, fr, ekind, makeConstArrayRef(state->x),
+                        makeConstArrayRef(state->v), state->box, state->lambda[efptVDW], mdatoms,
+                        nrnb, &vcm, wcycle, enerd, force_vir, shake_vir, total_vir, pres, constr,
+                        &signaller, lastbox, &totalNumberOfBondedInteractions, &bSumEkinhOld,
                         (bGStat ? CGLO_GSTAT : 0) | (!EI_VV(ir->eI) && bCalcEner ? CGLO_ENERGY : 0)
                                 | (!EI_VV(ir->eI) && bStopCM ? CGLO_STOPCM : 0)
                                 | (!EI_VV(ir->eI) ? CGLO_TEMPERATURE : 0)
@@ -1424,12 +1423,12 @@ void gmx::LegacySimulator::do_md()
                                 | (shouldCheckNumberOfBondedInteractions ? CGLO_CHECK_NUMBER_OF_BONDED_INTERACTIONS
                                                                          : 0));
                 checkNumberOfBondedInteractions(mdlog, cr, totalNumberOfBondedInteractions,
-                                                top_global, &top, state->x.rvec_array(), state->box,
-                                                &shouldCheckNumberOfBondedInteractions);
+                                                top_global, &top, makeConstArrayRef(state->x),
+                                                state->box, &shouldCheckNumberOfBondedInteractions);
                 if (!EI_VV(ir->eI) && bStopCM)
                 {
-                    process_and_stopcm_grp(fplog, &vcm, *mdatoms, state->x.rvec_array(),
-                                           state->v.rvec_array());
+                    process_and_stopcm_grp(fplog, &vcm, *mdatoms, makeArrayRef(state->x),
+                                           makeArrayRef(state->v));
                     inc_nrnb(nrnb, eNR_STOPCM, mdatoms->homenr);
 
                     // TODO: The special case of removing CM motion should be dealt more gracefully
index a5f484c5a27b6e62e13cd34a49ba2f566b90f0de..12daf94c25e0d86c7c5b40a47e347016997ab6fb 100644 (file)
@@ -298,13 +298,13 @@ void gmx::LegacySimulator::do_mimic()
                  | (shouldCheckNumberOfBondedInteractions ? CGLO_CHECK_NUMBER_OF_BONDED_INTERACTIONS : 0));
         bool   bSumEkinhOld = false;
         t_vcm* vcm          = nullptr;
-        compute_globals(gstat, cr, ir, fr, ekind, state->x.rvec_array(), state->v.rvec_array(),
-                        state->box, state->lambda[efptVDW], mdatoms, nrnb, vcm, nullptr, enerd,
-                        force_vir, shake_vir, total_vir, pres, constr, &nullSignaller, state->box,
-                        &totalNumberOfBondedInteractions, &bSumEkinhOld, cglo_flags);
+        compute_globals(gstat, cr, ir, fr, ekind, makeConstArrayRef(state->x),
+                        makeConstArrayRef(state->v), state->box, state->lambda[efptVDW], mdatoms, nrnb,
+                        vcm, nullptr, enerd, force_vir, shake_vir, total_vir, pres, constr, &nullSignaller,
+                        state->box, &totalNumberOfBondedInteractions, &bSumEkinhOld, cglo_flags);
     }
     checkNumberOfBondedInteractions(mdlog, cr, totalNumberOfBondedInteractions, top_global, &top,
-                                    state->x.rvec_array(), state->box,
+                                    makeConstArrayRef(state->x), state->box,
                                     &shouldCheckNumberOfBondedInteractions);
 
     if (MASTER(cr))
@@ -485,15 +485,15 @@ void gmx::LegacySimulator::do_mimic()
             t_vcm*              vcm              = nullptr;
             SimulationSignaller signaller(&signals, cr, ms, doInterSimSignal, doIntraSimSignal);
 
-            compute_globals(gstat, cr, ir, fr, ekind, state->x.rvec_array(), state->v.rvec_array(),
-                            state->box, state->lambda[efptVDW], mdatoms, nrnb, vcm, wcycle, enerd,
-                            nullptr, nullptr, nullptr, nullptr, constr, &signaller, state->box,
-                            &totalNumberOfBondedInteractions, &bSumEkinhOld,
+            compute_globals(gstat, cr, ir, fr, ekind, makeConstArrayRef(state->x),
+                            makeConstArrayRef(state->v), state->box, state->lambda[efptVDW], mdatoms,
+                            nrnb, vcm, wcycle, enerd, nullptr, nullptr, nullptr, nullptr, constr,
+                            &signaller, state->box, &totalNumberOfBondedInteractions, &bSumEkinhOld,
                             CGLO_GSTAT | CGLO_ENERGY
                                     | (shouldCheckNumberOfBondedInteractions ? CGLO_CHECK_NUMBER_OF_BONDED_INTERACTIONS
                                                                              : 0));
             checkNumberOfBondedInteractions(mdlog, cr, totalNumberOfBondedInteractions, top_global,
-                                            &top, state->x.rvec_array(), state->box,
+                                            &top, makeConstArrayRef(state->x), state->box,
                                             &shouldCheckNumberOfBondedInteractions);
         }
 
index 482fca7461cec98776cb9dfb9403ff8ee1b87e84..dc45ee51944b2edcb22b12ceb0aa6f74707b29e4 100644 (file)
@@ -373,13 +373,13 @@ void gmx::LegacySimulator::do_rerun()
                  | (shouldCheckNumberOfBondedInteractions ? CGLO_CHECK_NUMBER_OF_BONDED_INTERACTIONS : 0));
         bool   bSumEkinhOld = false;
         t_vcm* vcm          = nullptr;
-        compute_globals(gstat, cr, ir, fr, ekind, state->x.rvec_array(), state->v.rvec_array(),
-                        state->box, state->lambda[efptVDW], mdatoms, nrnb, vcm, nullptr, enerd,
-                        force_vir, shake_vir, total_vir, pres, constr, &nullSignaller, state->box,
-                        &totalNumberOfBondedInteractions, &bSumEkinhOld, cglo_flags);
+        compute_globals(gstat, cr, ir, fr, ekind, makeConstArrayRef(state->x),
+                        makeConstArrayRef(state->v), state->box, state->lambda[efptVDW], mdatoms, nrnb,
+                        vcm, nullptr, enerd, force_vir, shake_vir, total_vir, pres, constr, &nullSignaller,
+                        state->box, &totalNumberOfBondedInteractions, &bSumEkinhOld, cglo_flags);
     }
     checkNumberOfBondedInteractions(mdlog, cr, totalNumberOfBondedInteractions, top_global, &top,
-                                    state->x.rvec_array(), state->box,
+                                    makeConstArrayRef(state->x), state->box,
                                     &shouldCheckNumberOfBondedInteractions);
 
     if (MASTER(cr))
@@ -617,15 +617,15 @@ void gmx::LegacySimulator::do_rerun()
             t_vcm*              vcm              = nullptr;
             SimulationSignaller signaller(&signals, cr, ms, doInterSimSignal, doIntraSimSignal);
 
-            compute_globals(gstat, cr, ir, fr, ekind, state->x.rvec_array(), state->v.rvec_array(),
-                            state->box, state->lambda[efptVDW], mdatoms, nrnb, vcm, wcycle, enerd,
-                            force_vir, shake_vir, total_vir, pres, constr, &signaller, state->box,
-                            &totalNumberOfBondedInteractions, &bSumEkinhOld,
+            compute_globals(gstat, cr, ir, fr, ekind, makeConstArrayRef(state->x),
+                            makeConstArrayRef(state->v), state->box, state->lambda[efptVDW], mdatoms,
+                            nrnb, vcm, wcycle, enerd, force_vir, shake_vir, total_vir, pres, constr,
+                            &signaller, state->box, &totalNumberOfBondedInteractions, &bSumEkinhOld,
                             CGLO_GSTAT | CGLO_ENERGY
                                     | (shouldCheckNumberOfBondedInteractions ? CGLO_CHECK_NUMBER_OF_BONDED_INTERACTIONS
                                                                              : 0));
             checkNumberOfBondedInteractions(mdlog, cr, totalNumberOfBondedInteractions, top_global,
-                                            &top, state->x.rvec_array(), state->box,
+                                            &top, makeConstArrayRef(state->x), state->box,
                                             &shouldCheckNumberOfBondedInteractions);
         }
 
index 8f74b0d0f1b90c7c6937a989d7f59af1c4056475..6ba52b81444d932db60772cc7fb69151a85eda27 100644 (file)
@@ -129,15 +129,13 @@ void ComputeGlobalsElement<algorithm>::elementSetup()
 
         compute(-1, CGLO_GSTAT | CGLO_STOPCM, nullSignaller_.get(), false, true);
 
-        auto v = as_rvec_array(statePropagatorData_->velocitiesView().paddedArrayRef().data());
+        auto v = statePropagatorData_->velocitiesView();
         // At initialization, do not pass x with acceleration-correction mode
         // to avoid (incorrect) correction of the initial coordinates.
-        rvec* xPtr = nullptr;
-        if (vcm_.mode != ecmLINEAR_ACCELERATION_CORRECTION)
-        {
-            xPtr = as_rvec_array(statePropagatorData_->positionsView().paddedArrayRef().data());
-        }
-        process_and_stopcm_grp(fplog_, &vcm_, *mdAtoms_->mdatoms(), xPtr, v);
+        auto x = vcm_.mode == ecmLINEAR_ACCELERATION_CORRECTION ? ArrayRefWithPadding<RVec>()
+                                                                : statePropagatorData_->positionsView();
+        process_and_stopcm_grp(fplog_, &vcm_, *mdAtoms_->mdatoms(), x.unpaddedArrayRef(),
+                               v.unpaddedArrayRef());
         inc_nrnb(nrnb_, eNR_STOPCM, mdAtoms_->mdatoms()->homenr);
     }
 
@@ -285,8 +283,8 @@ void ComputeGlobalsElement<algorithm>::compute(gmx::Step            step,
                                                bool                 useLastBox,
                                                bool                 isInit)
 {
-    auto x       = as_rvec_array(statePropagatorData_->positionsView().paddedArrayRef().data());
-    auto v       = as_rvec_array(statePropagatorData_->velocitiesView().paddedArrayRef().data());
+    auto x       = statePropagatorData_->positionsView().unpaddedArrayRef();
+    auto v       = statePropagatorData_->velocitiesView().unpaddedArrayRef();
     auto box     = statePropagatorData_->constBox();
     auto lastbox = useLastBox ? statePropagatorData_->constPreviousBox()
                               : statePropagatorData_->constBox();