Make relax_shell_flexcon independent of t_state
authorPascal Merz <pascal.merz@me.com>
Tue, 9 Jul 2019 13:14:27 +0000 (07:14 -0600)
committerPaul Bauer <paul.bauer.q@gmail.com>
Thu, 11 Jul 2019 06:16:15 +0000 (08:16 +0200)
This change writes out the fields of t_state needed as explicit
arguments of relax_shell_flexcon instead of taking a pointer to
the full t_state object. This simplifies refactoring the t_state
object in future commits.

Change-Id: Iec3d0aea7462325963341b1d192cff697b764a7c

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

index 95a5a3467d6071d1b76764bc488f2dcc212799f2..77d2dc5cb4188837a1d512e375d3e2ebbee6368f 100644 (file)
@@ -889,7 +889,13 @@ void gmx::Simulator::do_md()
                                 enforcedRotation, step,
                                 ir, imdSession, pull_work, bNS, force_flags, &top,
                                 constr, enerd, fcd,
-                                state, f.arrayRefWithPadding(), force_vir, mdatoms,
+                                state->natoms,
+                                state->x.arrayRefWithPadding(),
+                                state->v.arrayRefWithPadding(),
+                                state->box,
+                                state->lambda,
+                                &state->hist,
+                                f.arrayRefWithPadding(), force_vir, mdatoms,
                                 nrnb, wcycle, graph,
                                 shellfc, fr, ppForceWorkload, t, mu_tot,
                                 vsite,
index 85a302e885a177ccdc96e148b33316951da74a87..9e12af90dc73e6d267c5d8531be8a025438ea5d8 100644 (file)
@@ -434,7 +434,13 @@ void gmx::Simulator::do_mimic()
                                 enforcedRotation, step,
                                 ir, imdSession, pull_work, bNS, force_flags, &top,
                                 constr, enerd, fcd,
-                                state, f.arrayRefWithPadding(), force_vir, mdatoms,
+                                state->natoms,
+                                state->x.arrayRefWithPadding(),
+                                state->v.arrayRefWithPadding(),
+                                state->box,
+                                state->lambda,
+                                &state->hist,
+                                f.arrayRefWithPadding(), force_vir, mdatoms,
                                 nrnb, wcycle, graph,
                                 shellfc, fr, ppForceWorkload, t, mu_tot,
                                 vsite,
index 8ac7a260be23682dbac06de2146ae78326226220..5058bf7493f6a9d9102944527127bf2f762c6b79 100644 (file)
@@ -2853,7 +2853,12 @@ Simulator::do_nm()
                                         constr,
                                         enerd,
                                         fcd,
-                                        &state_work.s,
+                                        state_work.s.natoms,
+                                        state_work.s.x.arrayRefWithPadding(),
+                                        state_work.s.v.arrayRefWithPadding(),
+                                        state_work.s.box,
+                                        state_work.s.lambda,
+                                        &state_work.s.hist,
                                         state_work.f.arrayRefWithPadding(),
                                         vir,
                                         mdatoms,
index be4ac14160e068af57e1bee1df64330e96d28d61..cfbbc5a29aa00670d4462386053c363316c9f12a 100644 (file)
@@ -556,7 +556,13 @@ void gmx::Simulator::do_rerun()
                                 enforcedRotation, step,
                                 ir, imdSession, pull_work, bNS, force_flags, &top,
                                 constr, enerd, fcd,
-                                state, f.arrayRefWithPadding(), force_vir, mdatoms,
+                                state->natoms,
+                                state->x.arrayRefWithPadding(),
+                                state->v.arrayRefWithPadding(),
+                                state->box,
+                                state->lambda,
+                                &state->hist,
+                                f.arrayRefWithPadding(), force_vir, mdatoms,
                                 nrnb, wcycle, graph,
                                 shellfc, fr, ppForceWorkload, t, mu_tot,
                                 vsite,
index 3a186d70c2975ac3bb5ebe3af019dc62e3e1427a..564dc42fbc2ce87eec5d65becfa0d819df7493f0 100644 (file)
@@ -981,7 +981,12 @@ void relax_shell_flexcon(FILE                                     *fplog,
                          gmx::Constraints                         *constr,
                          gmx_enerdata_t                           *enerd,
                          t_fcdata                                 *fcd,
-                         t_state                                  *state,
+                         int                                       natoms,
+                         gmx::ArrayRefWithPadding<gmx::RVec>       x,
+                         gmx::ArrayRefWithPadding<gmx::RVec>       v,
+                         matrix                                    box,
+                         gmx::ArrayRef<real>                       lambda,
+                         history_t                                *hist,
                          gmx::ArrayRefWithPadding<gmx::RVec>       f,
                          tensor                                    force_vir,
                          const t_mdatoms                          *md,
@@ -996,6 +1001,9 @@ void relax_shell_flexcon(FILE                                     *fplog,
                          const gmx_vsite_t                        *vsite,
                          const DDBalanceRegionHandler             &ddBalanceRegionHandler)
 {
+    auto          xRvec = as_rvec_array(x.paddedArrayRef().data());
+    auto          vRvec = as_rvec_array(v.paddedArrayRef().data());
+
     int           nshell;
     t_shell      *shell;
     const t_idef *idef;
@@ -1031,7 +1039,7 @@ void relax_shell_flexcon(FILE                                     *fplog,
     }
     else
     {
-        nat = state->natoms;
+        nat = natoms;
     }
 
     for (i = 0; (i < 2); i++)
@@ -1059,19 +1067,19 @@ void relax_shell_flexcon(FILE                                     *fplog,
          * before do_force is called, which normally puts all
          * charge groups in the box.
          */
-        auto xRef = state->x.arrayRefWithPadding().paddedArrayRef();
-        put_atoms_in_box_omp(fr->ePBC, state->box, xRef.subArray(0, md->homenr), gmx_omp_nthreads_get(emntDefault));
+        auto xRef = x.paddedArrayRef();
+        put_atoms_in_box_omp(fr->ePBC, box, xRef.subArray(0, md->homenr), gmx_omp_nthreads_get(emntDefault));
 
         if (graph)
         {
-            mk_mshift(fplog, graph, fr->ePBC, state->box, state->x.rvec_array());
+            mk_mshift(fplog, graph, fr->ePBC, box, xRvec);
         }
     }
 
     /* After this all coordinate arrays will contain whole charge groups */
     if (graph)
     {
-        shift_self(graph, state->box, state->x.rvec_array());
+        shift_self(graph, box, xRvec);
     }
 
     if (nflexcon)
@@ -1084,14 +1092,14 @@ void relax_shell_flexcon(FILE                                     *fplog,
         }
         acc_dir = shfc->acc_dir;
         x_old   = shfc->x_old;
-        auto x = makeArrayRef(state->x);
-        auto v = makeArrayRef(state->v);
+        auto xArrayRef = x.paddedArrayRef();
+        auto vArrayRef = v.paddedArrayRef();
         for (i = 0; i < homenr; i++)
         {
             for (d = 0; d < DIM; d++)
             {
                 shfc->x_old[i][d] =
-                    x[i][d] - v[i][d]*inputrec->delta_t;
+                    xArrayRef[i][d] - vArrayRef[i][d]*inputrec->delta_t;
             }
         }
     }
@@ -1101,28 +1109,28 @@ void relax_shell_flexcon(FILE                                     *fplog,
      */
     if (shfc->bPredict && !bCont && (EI_STATE_VELOCITY(inputrec->eI) || bInit))
     {
-        predict_shells(fplog, state->x.rvec_array(), state->v.rvec_array(), inputrec->delta_t, nshell, shell,
+        predict_shells(fplog, xRvec, vRvec, inputrec->delta_t, nshell, shell,
                        md->massT, nullptr, bInit);
     }
 
     /* do_force expected the charge groups to be in the box */
     if (graph)
     {
-        unshift_self(graph, state->box, state->x.rvec_array());
+        unshift_self(graph, box, xRvec);
     }
 
     /* Calculate the forces first time around */
     if (gmx_debug_at)
     {
-        pr_rvecs(debug, 0, "x b4 do_force", state->x.rvec_array(), homenr);
+        pr_rvecs(debug, 0, "x b4 do_force", xRvec, homenr);
     }
     int shellfc_flags = force_flags | (bVerbose ? GMX_FORCE_ENERGY : 0);
     do_force(fplog, cr, ms, inputrec, nullptr, enforcedRotation, imdSession,
              pull_work,
              mdstep, nrnb, wcycle, top,
-             state->box, state->x.arrayRefWithPadding(), &state->hist,
+             box, x, hist,
              forceWithPadding[Min], force_vir, md, enerd, fcd,
-             state->lambda, graph,
+             lambda, graph,
              fr, ppForceWorkload, vsite, mu_tot, t, nullptr,
              (bDoNS ? GMX_FORCE_NS : 0) | shellfc_flags,
              ddBalanceRegionHandler);
@@ -1132,9 +1140,9 @@ void relax_shell_flexcon(FILE                                     *fplog,
     {
         init_adir(shfc,
                   constr, inputrec, cr, dd_ac1, mdstep, md, end,
-                  shfc->x_old, state->x.rvec_array(), state->x.rvec_array(), as_rvec_array(force[Min].data()),
+                  shfc->x_old, xRvec, xRvec, as_rvec_array(force[Min].data()),
                   shfc->acc_dir,
-                  state->box, state->lambda, &dum);
+                  box, lambda, &dum);
 
         for (i = 0; i < end; i++)
         {
@@ -1162,11 +1170,11 @@ void relax_shell_flexcon(FILE                                     *fplog,
          * shell positions are updated, therefore the other particles must
          * be set here, in advance.
          */
-        std::copy(state->x.begin(),
-                  state->x.end(),
+        std::copy(x.paddedArrayRef().begin(),
+                  x.paddedArrayRef().end(),
                   posWithPadding[Min].paddedArrayRef().begin());
-        std::copy(state->x.begin(),
-                  state->x.end(),
+        std::copy(x.paddedArrayRef().begin(),
+                  x.paddedArrayRef().end(),
                   posWithPadding[Try].paddedArrayRef().begin());
     }
 
@@ -1196,19 +1204,19 @@ void relax_shell_flexcon(FILE                                     *fplog,
         if (vsite)
         {
             construct_vsites(vsite, as_rvec_array(pos[Min].data()),
-                             inputrec->delta_t, state->v.rvec_array(),
+                             inputrec->delta_t, vRvec,
                              idef->iparams, idef->il,
-                             fr->ePBC, fr->bMolPBC, cr, state->box);
+                             fr->ePBC, fr->bMolPBC, cr, box);
         }
 
         if (nflexcon)
         {
             init_adir(shfc,
                       constr, inputrec, cr, dd_ac1, mdstep, md, end,
-                      x_old, state->x.rvec_array(),
+                      x_old, xRvec,
                       as_rvec_array(pos[Min].data()),
                       as_rvec_array(force[Min].data()), acc_dir,
-                      state->box, state->lambda, &dum);
+                      box, lambda, &dum);
 
             directional_sd(pos[Min], pos[Try], acc_dir, end, fr->fc_stepsize);
         }
@@ -1219,7 +1227,7 @@ void relax_shell_flexcon(FILE                                     *fplog,
         /* do_force expected the charge groups to be in the box */
         if (graph)
         {
-            unshift_self(graph, state->box, as_rvec_array(pos[Try].data()));
+            unshift_self(graph, box, as_rvec_array(pos[Try].data()));
         }
 
         if (gmx_debug_at)
@@ -1231,9 +1239,9 @@ void relax_shell_flexcon(FILE                                     *fplog,
         do_force(fplog, cr, ms, inputrec, nullptr, enforcedRotation, imdSession,
                  pull_work,
                  1, nrnb, wcycle,
-                 top, state->box, posWithPadding[Try], &state->hist,
+                 top, box, posWithPadding[Try], hist,
                  forceWithPadding[Try], force_vir,
-                 md, enerd, fcd, state->lambda, graph,
+                 md, enerd, fcd, lambda, graph,
                  fr, ppForceWorkload, vsite, mu_tot, t, nullptr,
                  shellfc_flags,
                  ddBalanceRegionHandler);
@@ -1248,10 +1256,10 @@ void relax_shell_flexcon(FILE                                     *fplog,
         {
             init_adir(shfc,
                       constr, inputrec, cr, dd_ac1, mdstep, md, end,
-                      x_old, state->x.rvec_array(),
+                      x_old, xRvec,
                       as_rvec_array(pos[Try].data()),
                       as_rvec_array(force[Try].data()),
-                      acc_dir, state->box, state->lambda, &dum);
+                      acc_dir, box, lambda, &dum);
 
             for (i = 0; i < end; i++)
             {
@@ -1298,12 +1306,12 @@ void relax_shell_flexcon(FILE                                     *fplog,
             {
                 /* Correct the velocities for the flexible constraints */
                 invdt = 1/inputrec->delta_t;
-                auto v = makeArrayRef(state->v);
+                auto vArrayRef = v.paddedArrayRef();
                 for (i = 0; i < end; i++)
                 {
                     for (d = 0; d < DIM; d++)
                     {
-                        v[i][d] += (pos[Try][i][d] - pos[Min][i][d])*invdt;
+                        vArrayRef[i][d] += (pos[Try][i][d] - pos[Min][i][d])*invdt;
                     }
                 }
             }
@@ -1334,7 +1342,7 @@ void relax_shell_flexcon(FILE                                     *fplog,
     }
 
     /* Copy back the coordinates and the forces */
-    std::copy(pos[Min].begin(), pos[Min].end(), makeArrayRef(state->x).data());
+    std::copy(pos[Min].begin(), pos[Min].end(), x.paddedArrayRef().data());
     std::copy(force[Min].begin(), force[Min].end(), f.unpaddedArrayRef().begin());
 }
 
index e22dd239c96e67e7ea2e04af9320505c866b502d..f886a6795c6131b1e1aee37ba003f5074ca8607d 100644 (file)
@@ -49,6 +49,7 @@ struct gmx_enfrot;
 struct gmx_multisim_t;
 struct gmx_shellfc_t;
 struct gmx_mtop_t;
+class history_t;
 struct pull_t;
 struct t_forcerec;
 struct t_fcdata;
@@ -86,7 +87,12 @@ void relax_shell_flexcon(FILE                                     *log,
                          gmx::Constraints                         *constr,
                          gmx_enerdata_t                           *enerd,
                          t_fcdata                                 *fcd,
-                         t_state                                  *state,
+                         int                                       natoms,
+                         gmx::ArrayRefWithPadding<gmx::RVec>       x,
+                         gmx::ArrayRefWithPadding<gmx::RVec>       v,
+                         matrix                                    box,
+                         gmx::ArrayRef<real>                       lambda,
+                         history_t                                *hist,
                          gmx::ArrayRefWithPadding<gmx::RVec>       f,
                          tensor                                    force_vir,
                          const t_mdatoms                          *md,