Use ArrayRef in ewald_LRcorrection
authorJoe Jordan <ejjordan12@gmail.com>
Fri, 19 Mar 2021 10:50:48 +0000 (10:50 +0000)
committerMark Abraham <mark.j.abraham@gmail.com>
Fri, 19 Mar 2021 10:50:48 +0000 (10:50 +0000)
This will make refactoring t_mdatoms easier. Also changed
signatures of calculateLongRangeNonbondeds to use more
ArrayRef.

src/gromacs/ewald/long_range_correction.cpp
src/gromacs/ewald/long_range_correction.h
src/gromacs/mdlib/force.cpp
src/gromacs/mdlib/force.h
src/gromacs/mdlib/sim_util.cpp

index ce2625717c2b2f52b304fcc8ff99cabcdeaeca95..b5791ead4746be2ef7935312c5cbc0e3a8f213ea 100644 (file)
  * perturbations. The parameter vectors for LJ-PME are likewise
  * undefined when LJ-PME is not active. This works because
  * bHaveChargeOrTypePerturbed handles the control flow. */
-void ewald_LRcorrection(const int         numAtomsLocal,
-                        const t_commrec*  cr,
-                        int               numThreads,
-                        int               thread,
-                        const t_forcerec& fr,
-                        const t_inputrec& ir,
-                        const real*       chargeA,
-                        const real*       chargeB,
-                        gmx_bool          bHaveChargePerturbed,
-                        const rvec        x[],
-                        const matrix      box,
-                        const rvec        mu_tot[],
-                        rvec*             f,
-                        real*             Vcorr_q,
-                        real              lambda_q,
-                        real*             dvdlambda_q)
+void ewald_LRcorrection(const int                      numAtomsLocal,
+                        const t_commrec*               cr,
+                        int                            numThreads,
+                        int                            thread,
+                        const t_forcerec&              fr,
+                        const t_inputrec&              ir,
+                        gmx::ArrayRef<const real>      chargeA,
+                        gmx::ArrayRef<const real>      chargeB,
+                        bool                           bHaveChargePerturbed,
+                        gmx::ArrayRef<const gmx::RVec> x,
+                        const matrix                   box,
+                        gmx::ArrayRef<const gmx::RVec> mu_tot,
+                        gmx::ArrayRef<gmx::RVec>       f,
+                        real*                          Vcorr_q,
+                        real                           lambda_q,
+                        real*                          dvdlambda_q)
 {
     /* We need to correct only self interactions */
     const int start = (numAtomsLocal * thread) / numThreads;
@@ -211,11 +211,11 @@ void ewald_LRcorrection(const int         numAtomsLocal,
                          * We could implement a reduction over threads,
                          * but this case is rarely used.
                          */
-                        const real* qPtr   = (q == 0 ? chargeA : chargeB);
-                        real        sumQZ2 = 0;
+                        gmx::ArrayRef<const real> charge = (q == 0 ? chargeA : chargeB);
+                        real                      sumQZ2 = 0;
                         for (int i = 0; i < numAtomsLocal; i++)
                         {
-                            sumQZ2 += qPtr[i] * x[i][ZZ] * x[i][ZZ];
+                            sumQZ2 += charge[i] * x[i][ZZ] * x[i][ZZ];
                         }
                         Vdipole[q] -= dipole_coeff * fr.qsum[q]
                                       * (sumQZ2 + fr.qsum[q] * box[ZZ][ZZ] * box[ZZ][ZZ] / 12);
index df0a7405695f847ce1e8d2b8c9440a8fb978300c..f6fb0c5e8cc1d36c18e996a433cdfb573621d88d 100644 (file)
@@ -4,7 +4,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 by the GROMACS development team.
- * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019,2020,2021, 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.
 #define GMX_EWALD_LONG_RANGE_CORRECTION_H
 
 #include "gromacs/math/vectypes.h"
-#include "gromacs/topology/block.h"
-#include "gromacs/utility/basedefinitions.h"
 #include "gromacs/utility/real.h"
 
 struct t_commrec;
 struct t_forcerec;
 struct t_inputrec;
 
+namespace gmx
+{
+template<typename>
+class ArrayRef;
+}
+
 /*! \brief Calculate long-range Ewald correction terms.
  *
  * Calculate correction for electrostatic surface dipole terms.
  */
-void ewald_LRcorrection(int               numAtomsLocal,
-                        const t_commrec*  cr,
-                        int               numThreads,
-                        int               thread,
-                        const t_forcerec& fr,
-                        const t_inputrec& ir,
-                        const real*       chargeA,
-                        const real*       chargeB,
-                        gmx_bool          bHaveChargePerturbed,
-                        const rvec        x[],
-                        const matrix      box,
-                        const rvec        mu_tot[],
-                        rvec*             f,
-                        real*             Vcorr_q,
-                        real              lambda_q,
-                        real*             dvdlambda_q);
+void ewald_LRcorrection(int                            numAtomsLocal,
+                        const t_commrec*               cr,
+                        int                            numThreads,
+                        int                            thread,
+                        const t_forcerec&              fr,
+                        const t_inputrec&              ir,
+                        gmx::ArrayRef<const real>      chargeA,
+                        gmx::ArrayRef<const real>      chargeB,
+                        bool                           bHaveChargePerturbed,
+                        gmx::ArrayRef<const gmx::RVec> x,
+                        const matrix                   box,
+                        gmx::ArrayRef<const gmx::RVec> mu_tot,
+                        gmx::ArrayRef<gmx::RVec>       f,
+                        real*                          Vcorr_q,
+                        real                           lambda_q,
+                        real*                          dvdlambda_q);
 
 #endif
index ad4f2f27d19a18432abd79054788b962b6f21e82..a598288f34af6692df77bd33b2f95f1d0ff60cdb 100644 (file)
@@ -100,20 +100,20 @@ static void reduceEwaldThreadOuput(int nthreads, ewald_corr_thread_t* ewc_t)
     }
 }
 
-void calculateLongRangeNonbondeds(t_forcerec*                   fr,
-                                  const t_inputrec&             ir,
-                                  const t_commrec*              cr,
-                                  t_nrnb*                       nrnb,
-                                  gmx_wallcycle_t               wcycle,
-                                  const t_mdatoms*              md,
-                                  gmx::ArrayRef<const RVec>     coordinates,
-                                  gmx::ForceWithVirial*         forceWithVirial,
-                                  gmx_enerdata_t*               enerd,
-                                  const matrix                  box,
-                                  const real*                   lambda,
-                                  const rvec*                   mu_tot,
-                                  const gmx::StepWorkload&      stepWork,
-                                  const DDBalanceRegionHandler& ddBalanceRegionHandler)
+void calculateLongRangeNonbondeds(t_forcerec*                    fr,
+                                  const t_inputrec&              ir,
+                                  const t_commrec*               cr,
+                                  t_nrnb*                        nrnb,
+                                  gmx_wallcycle_t                wcycle,
+                                  const t_mdatoms*               md,
+                                  gmx::ArrayRef<const RVec>      coordinates,
+                                  gmx::ForceWithVirial*          forceWithVirial,
+                                  gmx_enerdata_t*                enerd,
+                                  const matrix                   box,
+                                  gmx::ArrayRef<const real>      lambda,
+                                  gmx::ArrayRef<const gmx::RVec> mu_tot,
+                                  const gmx::StepWorkload&       stepWork,
+                                  const DDBalanceRegionHandler&  ddBalanceRegionHandler)
 {
     const bool computePmeOnCpu = (EEL_PME(fr->ic->eeltype) || EVDW_PME(fr->ic->vdwtype))
                                  && thisRankHasDuty(cr, DUTY_PME)
@@ -160,7 +160,6 @@ void calculateLongRangeNonbondeds(t_forcerec*                   fr,
                          * exclusion forces) are calculated, so we can store
                          * the forces in the normal, single forceWithVirial->force_ array.
                          */
-                        const rvec* x = as_rvec_array(coordinates.data());
                         ewald_LRcorrection(
                                 md->homenr,
                                 cr,
@@ -168,13 +167,13 @@ void calculateLongRangeNonbondeds(t_forcerec*                   fr,
                                 t,
                                 *fr,
                                 ir,
-                                md->chargeA,
-                                md->chargeB,
+                                gmx::constArrayRefFromArray(md->chargeA, md->nr),
+                                gmx::constArrayRefFromArray(md->chargeB, md->nr),
                                 (md->nChargePerturbed != 0),
-                                x,
+                                coordinates,
                                 box,
                                 mu_tot,
-                                as_rvec_array(forceWithVirial->force_.data()),
+                                forceWithVirial->force_,
                                 &ewc_t.Vcorr_q,
                                 lambda[static_cast<int>(FreeEnergyPerturbationCouplingType::Coul)],
                                 &ewc_t.dvdl[FreeEnergyPerturbationCouplingType::Coul]);
index 6f795d020597775ceb92fd2b157bd98378a4897f..a25a42d6c23973760f344db4fb4efe8a1e61e02e 100644 (file)
@@ -143,8 +143,8 @@ void calculateLongRangeNonbondeds(t_forcerec*                    fr,
                                   gmx::ForceWithVirial*          forceWithVirial,
                                   gmx_enerdata_t*                enerd,
                                   const matrix                   box,
-                                  const real*                    lambda,
-                                  const rvec*                    mu_tot,
+                                  gmx::ArrayRef<const real>      lambda,
+                                  gmx::ArrayRef<const gmx::RVec> mu_tot,
                                   const gmx::StepWorkload&       stepWork,
                                   const DDBalanceRegionHandler&  ddBalanceRegionHandler);
 
index 55b94a7abb9ed6fc2afafaa1b5b6a2ff87adc77e..5208ffc5c1c5c40e877551e139f97d7d3367d622 100644 (file)
@@ -1886,8 +1886,8 @@ void do_force(FILE*                               fplog,
                                      &forceOutMtsLevel1->forceWithVirial(),
                                      enerd,
                                      box,
-                                     lambda.data(),
-                                     as_rvec_array(dipoleData.muStateAB),
+                                     lambda,
+                                     dipoleData.muStateAB,
                                      stepWork,
                                      ddBalanceRegionHandler);
     }