Remove mdatoms from do_walls
authorejjordan <ejjordan@kth.se>
Wed, 28 Apr 2021 12:56:28 +0000 (14:56 +0200)
committerJoe Jordan <ejjordan12@gmail.com>
Tue, 4 May 2021 19:01:34 +0000 (19:01 +0000)
Also changed one pointer arg to ArrayRef.

src/gromacs/mdlib/sim_util.cpp
src/gromacs/mdlib/wall.cpp
src/gromacs/mdlib/wall.h

index 232b587eb41f237595e00c451c6f97d296266192..540bad7f0046adb39e9cef08b7f7e13873831eea 100644 (file)
@@ -1832,11 +1832,15 @@ void do_force(FILE*                               fplog,
         real dvdl_walls = do_walls(inputrec,
                                    *fr,
                                    box,
-                                   *mdatoms,
+                                   gmx::arrayRefFromArray(mdatoms->typeA, mdatoms->nr),
+                                   gmx::arrayRefFromArray(mdatoms->typeB, mdatoms->nr),
+                                   gmx::arrayRefFromArray(mdatoms->cENER, mdatoms->nr),
+                                   mdatoms->homenr,
+                                   mdatoms->nPerturbed,
                                    x.unpaddedConstArrayRef(),
                                    &forceOutMtsLevel0.forceWithVirial(),
                                    lambda[static_cast<int>(FreeEnergyPerturbationCouplingType::Vdw)],
-                                   enerd->grpp.energyGroupPairTerms[NonBondedEnergyTerms::LJSR].data(),
+                                   enerd->grpp.energyGroupPairTerms[NonBondedEnergyTerms::LJSR],
                                    nrnb);
         enerd->dvdl_lin[FreeEnergyPerturbationCouplingType::Vdw] += dvdl_walls;
     }
index 2b9942a1f4802846300ca63c68db6a1a68837a51..89a3adb2e744a466acb3f489fb0fde0c3e3e6a24 100644 (file)
@@ -165,22 +165,25 @@ static void tableForce(real r, const t_forcetable& tab, real Cd, real Cr, real*
     }
 }
 
-real do_walls(const t_inputrec&              ir,
-              const t_forcerec&              fr,
-              const matrix                   box,
-              const t_mdatoms&               md,
-              gmx::ArrayRef<const gmx::RVec> x,
-              gmx::ForceWithVirial*          forceWithVirial,
-              real                           lambda,
-              real                           Vlj[],
-              t_nrnb*                        nrnb)
+real do_walls(const t_inputrec&                   ir,
+              const t_forcerec&                   fr,
+              const matrix                        box,
+              gmx::ArrayRef<const int>            typeA,
+              gmx::ArrayRef<const int>            typeB,
+              gmx::ArrayRef<const unsigned short> cENER,
+              const int                           homenr,
+              const int                           numPerturbedAtoms,
+              gmx::ArrayRef<const gmx::RVec>      x,
+              gmx::ForceWithVirial*               forceWithVirial,
+              real                                lambda,
+              gmx::ArrayRef<real>                 Vlj,
+              t_nrnb*                             nrnb)
 {
     constexpr real sixth   = 1.0 / 6.0;
     constexpr real twelfth = 1.0 / 12.0;
 
-    int                   ntw[2];
-    real                  fac_d[2], fac_r[2];
-    const unsigned short* gid = md.cENER;
+    int  ntw[2];
+    real fac_d[2], fac_r[2];
 
     const int   nwall     = ir.nwall;
     const int   ngid      = ir.opts.ngener;
@@ -210,36 +213,36 @@ real do_walls(const t_inputrec&              ir,
 
     real   dvdlambda = 0;
     double sumRF     = 0;
-    for (int lam = 0; lam < (md.nPerturbed ? 2 : 1); lam++)
+    for (int lam = 0; lam < (numPerturbedAtoms ? 2 : 1); lam++)
     {
-        real       lamfac;
-        const int* type;
-        if (md.nPerturbed)
+        real                     lamfac;
+        gmx::ArrayRef<const int> type;
+        if (numPerturbedAtoms != 0)
         {
             if (lam == 0)
             {
                 lamfac = 1 - lambda;
-                type   = md.typeA;
+                type   = typeA;
             }
             else
             {
                 lamfac = lambda;
-                type   = md.typeB;
+                type   = typeB;
             }
         }
         else
         {
             lamfac = 1;
-            type   = md.typeA;
+            type   = typeA;
         }
 
         real Vlambda = 0;
-        for (int i = 0; i < md.homenr; i++)
+        for (int i = 0; i < homenr; i++)
         {
             for (int w = 0; w < std::min(nwall, 2); w++)
             {
                 /* The wall energy groups are always at the end of the list */
-                const int ggid = gid[i] * ngid + ngid - nwall + w;
+                const int ggid = cENER[i] * ngid + ngid - nwall + w;
                 const int at   = type[i];
                 /* nbfp now includes the 6/12 derivative prefactors */
                 const real Cd = nbfp[ntw[w] + 2 * at] * sixth;
@@ -274,7 +277,7 @@ real do_walls(const t_inputrec&              ir,
                     switch (ir.wall_type)
                     {
                         case WallType::Table:
-                            tableForce(r, *fr.wall_tab[w][gid[i]], Cd, Cr, &V, &F);
+                            tableForce(r, *fr.wall_tab[w][cENER[i]], Cd, Cr, &V, &F);
                             F *= lamfac;
                             break;
                         case WallType::NineThree:
@@ -324,12 +327,12 @@ real do_walls(const t_inputrec&              ir,
                 }
             }
         }
-        if (md.nPerturbed)
+        if (numPerturbedAtoms != 0)
         {
             dvdlambda += (lam == 0 ? -1 : 1) * Vlambda;
         }
 
-        inc_nrnb(nrnb, eNR_WALLS, md.homenr);
+        inc_nrnb(nrnb, eNR_WALLS, homenr);
     }
 
     if (forceWithVirial->computeVirial_)
index 7beff73de3d587e5c65f94d04d392441c5496b73..01126f68625463f3b63f795aa8ef39ff576706fb 100644 (file)
@@ -58,14 +58,18 @@ void make_wall_tables(FILE*                   fplog,
                       const SimulationGroups* groups,
                       t_forcerec*             fr);
 
-real do_walls(const t_inputrec&              ir,
-              const t_forcerec&              fr,
-              const matrix                   box,
-              const t_mdatoms&               md,
-              gmx::ArrayRef<const gmx::RVec> x,
-              gmx::ForceWithVirial*          forceWithVirial,
-              real                           lambda,
-              real                           Vlj[],
-              t_nrnb*                        nrnb);
+real do_walls(const t_inputrec&                   ir,
+              const t_forcerec&                   fr,
+              const matrix                        box,
+              gmx::ArrayRef<const int>            typeA,
+              gmx::ArrayRef<const int>            typeB,
+              gmx::ArrayRef<const unsigned short> cENER,
+              int                                 homenr,
+              int                                 numPerturbedAtoms,
+              gmx::ArrayRef<const gmx::RVec>      x,
+              gmx::ForceWithVirial*               forceWithVirial,
+              real                                lambda,
+              gmx::ArrayRef<real>                 Vlj,
+              t_nrnb*                             nrnb);
 
 #endif