From 1e96663cc1f518221f28a1665aab2818b4eb9ed4 Mon Sep 17 00:00:00 2001 From: ejjordan Date: Mon, 22 Mar 2021 10:30:50 +0100 Subject: [PATCH] More const ref in shellfc Pass a const ref to t_mdatoms in shellfc functions. Part of work to make refactoring t_mdatoms easier. --- src/gromacs/domdec/mdsetup.cpp | 2 +- src/gromacs/domdec/mdsetup.h | 2 +- src/gromacs/mdrun/md.cpp | 2 +- src/gromacs/mdrun/mimic.cpp | 2 +- src/gromacs/mdrun/minimize.cpp | 2 +- src/gromacs/mdrun/rerun.cpp | 2 +- src/gromacs/mdrun/shellfc.cpp | 39 +++++++++---------- src/gromacs/mdrun/shellfc.h | 4 +- src/gromacs/modularsimulator/forceelement.cpp | 4 +- 9 files changed, 29 insertions(+), 30 deletions(-) diff --git a/src/gromacs/domdec/mdsetup.cpp b/src/gromacs/domdec/mdsetup.cpp index c2fd29ccb3..ccf793b0bd 100644 --- a/src/gromacs/domdec/mdsetup.cpp +++ b/src/gromacs/domdec/mdsetup.cpp @@ -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) diff --git a/src/gromacs/domdec/mdsetup.h b/src/gromacs/domdec/mdsetup.h index 007c410660..0023b797c9 100644 --- a/src/gromacs/domdec/mdsetup.h +++ b/src/gromacs/domdec/mdsetup.h @@ -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 * diff --git a/src/gromacs/mdrun/md.cpp b/src/gromacs/mdrun/md.cpp index d577f3b08d..77d3641a6d 100644 --- a/src/gromacs/mdrun/md.cpp +++ b/src/gromacs/mdrun/md.cpp @@ -1145,7 +1145,7 @@ void gmx::LegacySimulator::do_md() &state->hist, &f.view(), force_vir, - mdatoms, + *mdatoms, nrnb, wcycle, shellfc, diff --git a/src/gromacs/mdrun/mimic.cpp b/src/gromacs/mdrun/mimic.cpp index f64a8c3e5d..78239e1b07 100644 --- a/src/gromacs/mdrun/mimic.cpp +++ b/src/gromacs/mdrun/mimic.cpp @@ -544,7 +544,7 @@ void gmx::LegacySimulator::do_mimic() &state->hist, &f.view(), force_vir, - mdatoms, + *mdatoms, nrnb, wcycle, shellfc, diff --git a/src/gromacs/mdrun/minimize.cpp b/src/gromacs/mdrun/minimize.cpp index 33b067bde1..7c59a56005 100644 --- a/src/gromacs/mdrun/minimize.cpp +++ b/src/gromacs/mdrun/minimize.cpp @@ -3222,7 +3222,7 @@ void LegacySimulator::do_nm() &state_work.s.hist, &state_work.f.view(), vir, - mdatoms, + *mdatoms, nrnb, wcycle, shellfc, diff --git a/src/gromacs/mdrun/rerun.cpp b/src/gromacs/mdrun/rerun.cpp index 8b11f9630e..6ae83c4b3f 100644 --- a/src/gromacs/mdrun/rerun.cpp +++ b/src/gromacs/mdrun/rerun.cpp @@ -654,7 +654,7 @@ void gmx::LegacySimulator::do_rerun() &state->hist, &f.view(), force_vir, - mdatoms, + *mdatoms, nrnb, wcycle, shellfc, diff --git a/src/gromacs/mdrun/shellfc.cpp b/src/gromacs/mdrun/shellfc.cpp index 73c14ac3b5..0b630b6a52 100644 --- a/src/gromacs/mdrun/shellfc.cpp +++ b/src/gromacs/mdrun/shellfc.cpp @@ -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& 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 xOld, ArrayRef 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 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]); } } diff --git a/src/gromacs/mdrun/shellfc.h b/src/gromacs/mdrun/shellfc.h index 76722cd33f..6d3120fd98 100644 --- a/src/gromacs/mdrun/shellfc.h +++ b/src/gromacs/mdrun/shellfc.h @@ -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 countPtypes(FILE* fplog, const gmx_mtop_t* mtop); +gmx::EnumerationArray countPtypes(FILE* fplog, const gmx_mtop_t& mtop); #endif diff --git a/src/gromacs/modularsimulator/forceelement.cpp b/src/gromacs/modularsimulator/forceelement.cpp index 48fa24754d..77565e161c 100644 --- a/src/gromacs/modularsimulator/forceelement.cpp +++ b/src/gromacs/modularsimulator/forceelement.cpp @@ -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_, -- 2.22.0