Change vector references to Arrayref in AWH
authorPaul Bauer <paul.bauer.q@gmail.com>
Wed, 10 Mar 2021 09:39:18 +0000 (10:39 +0100)
committerPaul Bauer <paul.bauer.q@gmail.com>
Wed, 10 Mar 2021 09:39:18 +0000 (10:39 +0100)
Preparation for further refactoring.

14 files changed:
src/gromacs/applied_forces/awh/bias.cpp
src/gromacs/applied_forces/awh/bias.h
src/gromacs/applied_forces/awh/biasgrid.cpp
src/gromacs/applied_forces/awh/biasgrid.h
src/gromacs/applied_forces/awh/biasparams.cpp
src/gromacs/applied_forces/awh/biasparams.h
src/gromacs/applied_forces/awh/biassharing.cpp
src/gromacs/applied_forces/awh/biassharing.h
src/gromacs/applied_forces/awh/biasstate.cpp
src/gromacs/applied_forces/awh/biasstate.h
src/gromacs/applied_forces/awh/coordstate.cpp
src/gromacs/applied_forces/awh/coordstate.h
src/gromacs/applied_forces/awh/histogramsize.cpp
src/gromacs/applied_forces/awh/histogramsize.h

index 4021fc08d0b291facbe3e2869b556909ad0359f3..4d1ae3ce8402f13b02149ab914117e15fb6974bc 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2015,2016,2017,2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2015,2016,2017,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.
@@ -253,7 +253,7 @@ gmx::ArrayRef<const double> Bias::calcForceAndUpdateBias(const awh_dvec
  * \param[in] pointState  The state of the points in a bias.
  * \returns the total sample count.
  */
-static int64_t countSamples(const std::vector<PointState>& pointState)
+static int64_t countSamples(ArrayRef<const PointState> pointState)
 {
     double numSamples = 0;
     for (const PointState& point : pointState)
@@ -362,14 +362,14 @@ void Bias::updateHistory(AwhBiasHistory* biasHistory) const
 Bias::Bias(int                            biasIndexInCollection,
            const AwhParams&               awhParams,
            const AwhBiasParams&           awhBiasParams,
-           const std::vector<DimParams>&  dimParamsInit,
+           ArrayRef<const DimParams>      dimParamsInit,
            double                         beta,
            double                         mdTimeStep,
            int                            numSharingSimulations,
            const std::string&             biasInitFilename,
            ThisRankWillDoIO               thisRankWillDoIO,
            BiasParams::DisableUpdateSkips disableUpdateSkips) :
-    dimParams_(dimParamsInit),
+    dimParams_(dimParamsInit.begin(), dimParamsInit.end()),
     grid_(dimParamsInit, awhBiasParams.dimParams),
     params_(awhParams,
             awhBiasParams,
index 5fd4ad5c82760c4aeb3ec8313658573aecf0cde3..f3386facf36825571bfbdb6e51fec315de5a6427 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2015,2016,2017,2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2015,2016,2017,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.
@@ -166,7 +166,7 @@ public:
     Bias(int                            biasIndexInCollection,
          const AwhParams&               awhParams,
          const AwhBiasParams&           awhBiasParams,
-         const std::vector<DimParams>&  dimParams,
+         ArrayRef<const DimParams>      dimParams,
          double                         beta,
          double                         mdTimeStep,
          int                            numSharingSimulations,
@@ -279,7 +279,7 @@ public:
 
     /*! \brief Returns the dimension parameters.
      */
-    inline const std::vector<DimParams>& dimParams() const { return dimParams_; }
+    inline ArrayRef<const DimParams> dimParams() const { return dimParams_; }
 
     //! Returns the bias parameters
     inline const BiasParams& params() const { return params_; }
index af639fbf6fccc0a4198b5c05d93a35fc0a13923b..1f4ce66d5f0961d309c99afbe6c52276bdb802d9 100644 (file)
@@ -309,7 +309,7 @@ namespace
  * \param[in] indexMulti Multidimensional grid point index to convert to a linear one.
  * \returns the linear index.
  */
-int multiDimGridIndexToLinear(const std::vector<GridAxis>& axis, const awh_ivec indexMulti)
+int multiDimGridIndexToLinear(ArrayRef<const GridAxis> axis, const awh_ivec indexMulti)
 {
     awh_ivec numPointsDim = { 0 };
 
@@ -557,7 +557,7 @@ static int pointDistanceAlongAxis(const GridAxis& axis, double x, double x0)
  * \param[in] axis    The grid axes.
  * \returns true if the value is in the grid.
  */
-static bool valueIsInGrid(const awh_dvec value, const std::vector<GridAxis>& axis)
+static bool valueIsInGrid(const awh_dvec value, ArrayRef<const GridAxis> axis)
 {
     /* For each dimension get the one-dimensional index and check if it is in range. */
     for (size_t d = 0; d < axis.size(); d++)
@@ -634,7 +634,7 @@ int GridAxis::nearestIndex(double value) const
  * \param[in] axis   The grid axes.
  * \returns the point index nearest to the value.
  */
-static int getNearestIndexInGrid(const awh_dvec value, const std::vector<GridAxis>& axis)
+static int getNearestIndexInGrid(const awh_dvec value, ArrayRef<const GridAxis> axis)
 {
     awh_ivec indexMulti;
 
@@ -811,7 +811,7 @@ GridAxis::GridAxis(double origin, double end, double period, int numPoints, bool
     }
 }
 
-BiasGrid::BiasGrid(const std::vector<DimParams>& dimParams, const AwhDimParams* awhDimParams)
+BiasGrid::BiasGrid(ArrayRef<const DimParams> dimParams, const AwhDimParams* awhDimParams)
 {
     /* Define the discretization along each dimension */
     awh_dvec period;
index 8ca2c263a59bf6b1a3ce2cb6556dd1b6f7bb6b31..0a4bbc30341bcd39ccafb5cab34a9f01612e6989 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2015,2016,2017,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2015,2016,2017,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.
@@ -58,6 +58,8 @@
 #include <optional>
 #include <string>
 
+#include "gromacs/utility/arrayref.h"
+
 #include "dimparams.h" /* This is needed for awh_dvec */
 
 namespace gmx
@@ -197,7 +199,7 @@ public:
      * coordinate living on the grid (determines the grid spacing).
      * \param[in] awhDimParams  Dimension params from inputrec.
      */
-    BiasGrid(const std::vector<DimParams>& dimParams, const AwhDimParams* awhDimParams);
+    BiasGrid(ArrayRef<const DimParams> dimParams, const AwhDimParams* awhDimParams);
 
     /*! \brief Returns the number of points in the grid.
      *
@@ -221,7 +223,7 @@ public:
      *
      * \returns a constant reference to the grid axes.
      */
-    const std::vector<GridAxis>& axis() const { return axis_; }
+    ArrayRef<const GridAxis> axis() const { return axis_; }
 
     /*! \brief Returns a grid axis.
      *
index 1e66ba164baa4b3c14074fd744ce947f1c039c86..9524c7047b2bc81dad71e82f4b2c9f9b0c08313d 100644 (file)
@@ -115,9 +115,9 @@ int64_t calcTargetUpdateInterval(const AwhParams& awhParams, const AwhBiasParams
  * \param[in] gridAxis          The BiasGrid axes.
  * \returns the check interval in steps.
  */
-int64_t calcCheckCoveringInterval(const AwhParams&              awhParams,
-                                  const std::vector<DimParams>& dimParams,
-                                  const std::vector<GridAxis>&  gridAxis)
+int64_t calcCheckCoveringInterval(const AwhParams&          awhParams,
+                                  ArrayRef<const DimParams> dimParams,
+                                  ArrayRef<const GridAxis>  gridAxis)
 {
     /* Each sample will have a width of sigma. To cover the axis a
        minimum number of samples of width sigma is required. */
@@ -174,10 +174,10 @@ int64_t calcCheckCoveringInterval(const AwhParams&              awhParams,
  * \param[in] samplingTimestep  Sampling frequency of probability weights.
  * \returns estimate of initial histogram size.
  */
-double getInitialHistogramSizeEstimate(const AwhBiasParams&         awhBiasParams,
-                                       const std::vector<GridAxis>& gridAxis,
-                                       double                       beta,
-                                       double                       samplingTimestep)
+double getInitialHistogramSizeEstimate(const AwhBiasParams&     awhBiasParams,
+                                       ArrayRef<const GridAxis> gridAxis,
+                                       double                   beta,
+                                       double                   samplingTimestep)
 {
     /* Get diffusion factor */
     double              maxCrossingTime = 0.;
@@ -221,15 +221,15 @@ int getNumSharedUpdate(const AwhBiasParams& awhBiasParams, int numSharingSimulat
 
 } // namespace
 
-BiasParams::BiasParams(const AwhParams&              awhParams,
-                       const AwhBiasParams&          awhBiasParams,
-                       const std::vector<DimParams>& dimParams,
-                       double                        beta,
-                       double                        mdTimeStep,
-                       DisableUpdateSkips            disableUpdateSkips,
-                       int                           numSharingSimulations,
-                       const std::vector<GridAxis>&  gridAxis,
-                       int                           biasIndex) :
+BiasParams::BiasParams(const AwhParams&          awhParams,
+                       const AwhBiasParams&      awhBiasParams,
+                       ArrayRef<const DimParams> dimParams,
+                       double                    beta,
+                       double                    mdTimeStep,
+                       DisableUpdateSkips        disableUpdateSkips,
+                       int                       numSharingSimulations,
+                       ArrayRef<const GridAxis>  gridAxis,
+                       int                       biasIndex) :
     invBeta(beta > 0 ? 1 / beta : 0),
     numStepsSampleCoord_(awhParams.nstSampleCoord),
     numSamplesUpdateFreeEnergy_(awhParams.numSamplesUpdateFreeEnergy),
index 9fed42fa078aa82c86ddbda242f9b4631da62106..b416d9855659bab1f8fd85634ebb40b9ea8e5155 100644 (file)
@@ -60,6 +60,8 @@
 namespace gmx
 {
 
+template<typename>
+class ArrayRef;
 struct AwhBiasParams;
 struct AwhParams;
 struct DimParams;
@@ -189,15 +191,15 @@ public:
      * \param[in] disableUpdateSkips     If to disable update skips, useful for testing.
      * \param[in] biasIndex              Index of the bias.
      */
-    BiasParams(const AwhParams&              awhParams,
-               const AwhBiasParams&          awhBiasParams,
-               const std::vector<DimParams>& dimParams,
-               double                        beta,
-               double                        mdTimeStep,
-               DisableUpdateSkips            disableUpdateSkips,
-               int                           numSharingSimulations,
-               const std::vector<GridAxis>&  gridAxis,
-               int                           biasIndex);
+    BiasParams(const AwhParams&          awhParams,
+               const AwhBiasParams&      awhBiasParams,
+               ArrayRef<const DimParams> dimParams,
+               double                    beta,
+               double                    mdTimeStep,
+               DisableUpdateSkips        disableUpdateSkips,
+               int                       numSharingSimulations,
+               ArrayRef<const GridAxis>  gridAxis,
+               int                       biasIndex);
 
     /* Data members */
     const double invBeta; /**< 1/beta = kT in kJ/mol */
index b377931fa04bf2c538f774a93ae990abddf43ee0..73bc4a6e8dd95f8dc8dd71780aba7dd985c3ec18 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2017,2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2017,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.
@@ -79,9 +79,9 @@ bool haveBiasSharingWithinSimulation(const AwhParams& awhParams)
     return haveSharing;
 }
 
-void biasesAreCompatibleForSharingBetweenSimulations(const AwhParams&           awhParams,
-                                                     const std::vector<size_t>& pointSize,
-                                                     const gmx_multisim_t*      multiSimComm)
+void biasesAreCompatibleForSharingBetweenSimulations(const AwhParams&       awhParams,
+                                                     ArrayRef<const size_t> pointSize,
+                                                     const gmx_multisim_t*  multiSimComm)
 {
     const int numSim = multiSimComm->numSimulations_;
 
index 751fe2f9a5f9b7c8bbce89d6684013023dcdc437..0b79170937377cad91df83dd70d12246971655d8 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2017,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2017,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.
@@ -56,6 +56,8 @@ struct gmx_multisim_t;
 namespace gmx
 {
 
+template<typename>
+class ArrayRef;
 struct AwhParams;
 
 /*! \brief Returns if any bias is sharing within a simulation.
@@ -75,9 +77,9 @@ bool haveBiasSharingWithinSimulation(const AwhParams& awhParams);
  * \param[in] pointSize     Vector of grid-point sizes for each bias.
  * \param[in] multiSimComm  Struct for multi-simulation communication.
  */
-void biasesAreCompatibleForSharingBetweenSimulations(const AwhParams&           awhParams,
-                                                     const std::vector<size_t>& pointSize,
-                                                     const gmx_multisim_t*      multiSimComm);
+void biasesAreCompatibleForSharingBetweenSimulations(const AwhParams&       awhParams,
+                                                     ArrayRef<const size_t> pointSize,
+                                                     const gmx_multisim_t*  multiSimComm);
 
 } // namespace gmx
 
index 783cfab1f8a1335421cd098a76a2aca4c0597e70..d7c35b2351bb6370ddfae345706f08c3e522da27 100644 (file)
@@ -220,14 +220,14 @@ double freeEnergyMinimumValue(gmx::ArrayRef<const PointState> pointState)
  * \param[in] gridpointIndex         The index of the current grid point.
  * \returns the log of the biased probability weight.
  */
-double biasedLogWeightFromPoint(const std::vector<DimParams>&  dimParams,
-                                const std::vector<PointState>& points,
-                                const BiasGrid&                grid,
-                                int                            pointIndex,
-                                double                         pointBias,
-                                const awh_dvec                 value,
-                                gmx::ArrayRef<const double>    neighborLambdaEnergies,
-                                int                            gridpointIndex)
+double biasedLogWeightFromPoint(ArrayRef<const DimParams>  dimParams,
+                                ArrayRef<const PointState> points,
+                                const BiasGrid&            grid,
+                                int                        pointIndex,
+                                double                     pointBias,
+                                const awh_dvec             value,
+                                ArrayRef<const double>     neighborLambdaEnergies,
+                                int                        gridpointIndex)
 {
     double logWeight = detail::c_largeNegativeExponent;
 
@@ -275,9 +275,9 @@ double biasedLogWeightFromPoint(const std::vector<DimParams>&  dimParams,
  * \returns The calculated marginal distribution in a 1D array with
  * as many elements as there are points along the axis of interest.
  */
-std::vector<double> calculateFELambdaMarginalDistribution(const BiasGrid&          grid,
-                                                          gmx::ArrayRef<const int> neighbors,
-                                                          gmx::ArrayRef<const double> probWeightNeighbor)
+std::vector<double> calculateFELambdaMarginalDistribution(const BiasGrid&        grid,
+                                                          ArrayRef<const int>    neighbors,
+                                                          ArrayRef<const double> probWeightNeighbor)
 {
     const std::optional<int> lambdaAxisIndex = grid.lambdaAxisIndex();
     GMX_RELEASE_ASSERT(lambdaAxisIndex,
@@ -297,9 +297,9 @@ std::vector<double> calculateFELambdaMarginalDistribution(const BiasGrid&
 
 } // namespace
 
-void BiasState::calcConvolvedPmf(const std::vector<DimParams>& dimParams,
-                                 const BiasGrid&               grid,
-                                 std::vector<float>*           convolvedPmf) const
+void BiasState::calcConvolvedPmf(ArrayRef<const DimParams> dimParams,
+                                 const BiasGrid&           grid,
+                                 std::vector<float>*       convolvedPmf) const
 {
     size_t numPoints = grid.numPoints();
 
@@ -348,7 +348,7 @@ namespace
  * \param[in,out] pointState  The state of all points.
  * \param[in]     params      The bias parameters.
  */
-void updateTargetDistribution(gmx::ArrayRef<PointState> pointState, const BiasParams& params)
+void updateTargetDistribution(ArrayRef<PointState> pointState, const BiasParams& params)
 {
     double freeEnergyCutoff = 0;
     if (params.eTarget == AwhTargetType::Cutoff)
@@ -475,11 +475,11 @@ int BiasState::warnForHistogramAnomalies(const BiasGrid& grid, int biasIndex, do
     return numWarnings;
 }
 
-double BiasState::calcUmbrellaForceAndPotential(const std::vector<DimParams>& dimParams,
-                                                const BiasGrid&               grid,
-                                                int                           point,
-                                                ArrayRef<const double>        neighborLambdaDhdl,
-                                                gmx::ArrayRef<double>         force) const
+double BiasState::calcUmbrellaForceAndPotential(ArrayRef<const DimParams> dimParams,
+                                                const BiasGrid&           grid,
+                                                int                       point,
+                                                ArrayRef<const double>    neighborLambdaDhdl,
+                                                ArrayRef<double>          force) const
 {
     double potential = 0;
     for (size_t d = 0; d < dimParams.size(); d++)
@@ -508,12 +508,12 @@ double BiasState::calcUmbrellaForceAndPotential(const std::vector<DimParams>& di
     return potential;
 }
 
-void BiasState::calcConvolvedForce(const std::vector<DimParams>& dimParams,
-                                   const BiasGrid&               grid,
-                                   gmx::ArrayRef<const double>   probWeightNeighbor,
-                                   ArrayRef<const double>        neighborLambdaDhdl,
-                                   gmx::ArrayRef<double>         forceWorkBuffer,
-                                   gmx::ArrayRef<double>         force) const
+void BiasState::calcConvolvedForce(ArrayRef<const DimParams> dimParams,
+                                   const BiasGrid&           grid,
+                                   ArrayRef<const double>    probWeightNeighbor,
+                                   ArrayRef<const double>    neighborLambdaDhdl,
+                                   ArrayRef<double>          forceWorkBuffer,
+                                   ArrayRef<double>          force) const
 {
     for (size_t d = 0; d < dimParams.size(); d++)
     {
@@ -539,15 +539,15 @@ void BiasState::calcConvolvedForce(const std::vector<DimParams>& dimParams,
     }
 }
 
-double BiasState::moveUmbrella(const std::vector<DimParams>& dimParams,
-                               const BiasGrid&               grid,
-                               gmx::ArrayRef<const double>   probWeightNeighbor,
-                               ArrayRef<const double>        neighborLambdaDhdl,
-                               gmx::ArrayRef<double>         biasForce,
-                               int64_t                       step,
-                               int64_t                       seed,
-                               int                           indexSeed,
-                               bool                          onlySampleUmbrellaGridpoint)
+double BiasState::moveUmbrella(ArrayRef<const DimParams> dimParams,
+                               const BiasGrid&           grid,
+                               ArrayRef<const double>    probWeightNeighbor,
+                               ArrayRef<const double>    neighborLambdaDhdl,
+                               ArrayRef<double>          biasForce,
+                               int64_t                   step,
+                               int64_t                   seed,
+                               int                       indexSeed,
+                               bool                      onlySampleUmbrellaGridpoint)
 {
     /* Generate and set a new coordinate reference value */
     coordState_.sampleUmbrellaGridpoint(
@@ -737,11 +737,11 @@ void mergeSharedUpdateLists(std::vector<int>*     updateList,
  * last update. \param[in] endUpdatelist     The end of the rectangular that has been sampled since
  * last update. \param[in,out] updateList    Local update list to set (assumed >= npoints long).
  */
-void makeLocalUpdateList(const BiasGrid&                grid,
-                         const std::vector<PointState>& points,
-                         const awh_ivec                 originUpdatelist,
-                         const awh_ivec                 endUpdatelist,
-                         std::vector<int>*              updateList)
+void makeLocalUpdateList(const BiasGrid&            grid,
+                         ArrayRef<const PointState> points,
+                         const awh_ivec             originUpdatelist,
+                         const awh_ivec             endUpdatelist,
+                         std::vector<int>*          updateList)
 {
     awh_ivec origin;
     awh_ivec numPoints;
@@ -961,11 +961,11 @@ void labelCoveredPoints(const std::vector<bool>& visited,
 
 } // namespace
 
-bool BiasState::isSamplingRegionCovered(const BiasParams&             params,
-                                        const std::vector<DimParams>& dimParams,
-                                        const BiasGrid&               grid,
-                                        const t_commrec*              commRecord,
-                                        const gmx_multisim_t*         multiSimComm) const
+bool BiasState::isSamplingRegionCovered(const BiasParams&         params,
+                                        ArrayRef<const DimParams> dimParams,
+                                        const BiasGrid&           grid,
+                                        const t_commrec*          commRecord,
+                                        const gmx_multisim_t*     multiSimComm) const
 {
     /* Allocate and initialize arrays: one for checking visits along each dimension,
        one for keeping track of which points to check and one for the covered points.
@@ -1106,15 +1106,15 @@ static void normalizeFreeEnergyAndPmfSum(std::vector<PointState>* pointState)
     }
 }
 
-void BiasState::updateFreeEnergyAndAddSamplesToHistogram(const std::vector<DimParams>& dimParams,
-                                                         const BiasGrid&               grid,
-                                                         const BiasParams&             params,
-                                                         const t_commrec*              commRecord,
-                                                         const gmx_multisim_t*         multiSimComm,
-                                                         double                        t,
-                                                         int64_t                       step,
-                                                         FILE*                         fplog,
-                                                         std::vector<int>*             updateList)
+void BiasState::updateFreeEnergyAndAddSamplesToHistogram(ArrayRef<const DimParams> dimParams,
+                                                         const BiasGrid&           grid,
+                                                         const BiasParams&         params,
+                                                         const t_commrec*          commRecord,
+                                                         const gmx_multisim_t*     multiSimComm,
+                                                         double                    t,
+                                                         int64_t                   step,
+                                                         FILE*                     fplog,
+                                                         std::vector<int>*         updateList)
 {
     /* Note hat updateList is only used in this scope and is always
      * re-initialized. We do not use a local vector, because that would
@@ -1252,9 +1252,9 @@ void BiasState::updateFreeEnergyAndAddSamplesToHistogram(const std::vector<DimPa
     histogramSize_.incrementNumUpdates();
 }
 
-double BiasState::updateProbabilityWeightsAndConvolvedBias(const std::vector<DimParams>& dimParams,
-                                                           const BiasGrid&               grid,
-                                                           gmx::ArrayRef<const double> neighborLambdaEnergies,
+double BiasState::updateProbabilityWeightsAndConvolvedBias(ArrayRef<const DimParams> dimParams,
+                                                           const BiasGrid&           grid,
+                                                           ArrayRef<const double> neighborLambdaEnergies,
                                                            std::vector<double, AlignedAllocator<double>>* weight) const
 {
     /* Only neighbors of the current coordinate value will have a non-negligible chance of getting sampled */
@@ -1340,9 +1340,9 @@ double BiasState::updateProbabilityWeightsAndConvolvedBias(const std::vector<Dim
     return std::log(weightSum);
 }
 
-double BiasState::calcConvolvedBias(const std::vector<DimParams>& dimParams,
-                                    const BiasGrid&               grid,
-                                    const awh_dvec&               coordValue) const
+double BiasState::calcConvolvedBias(ArrayRef<const DimParams> dimParams,
+                                    const BiasGrid&           grid,
+                                    const awh_dvec&           coordValue) const
 {
     int              point     = grid.nearestIndex(coordValue);
     const GridPoint& gridPoint = grid.point(point);
@@ -1566,7 +1566,7 @@ void BiasState::broadcast(const t_commrec* commRecord)
     gmx_bcast(sizeof(histogramSize_), &histogramSize_, commRecord->mpi_comm_mygroup);
 }
 
-void BiasState::setFreeEnergyToConvolvedPmf(const std::vector<DimParams>& dimParams, const BiasGrid& grid)
+void BiasState::setFreeEnergyToConvolvedPmf(ArrayRef<const DimParams> dimParams, const BiasGrid& grid)
 {
     std::vector<float> convolvedPmf;
 
@@ -1626,12 +1626,12 @@ static int countTrailingZeroRows(const double* const* data, int numRows, int num
  * \param[in]     biasIndex   The index of the bias.
  * \param[in,out] pointState  The state of the points in this bias.
  */
-static void readUserPmfAndTargetDistribution(const std::vector<DimParams>& dimParams,
-                                             const BiasGrid&               grid,
-                                             const std::string&            filename,
-                                             int                           numBias,
-                                             int                           biasIndex,
-                                             std::vector<PointState>*      pointState)
+static void readUserPmfAndTargetDistribution(ArrayRef<const DimParams> dimParams,
+                                             const BiasGrid&           grid,
+                                             const std::string&        filename,
+                                             int                       numBias,
+                                             int                       biasIndex,
+                                             std::vector<PointState>*  pointState)
 {
     /* Read the PMF and target distribution.
        From the PMF, the convolved PMF, or the reference value free energy, can be calculated
@@ -1821,12 +1821,12 @@ void BiasState::normalizePmf(int numSharingSims)
     }
 }
 
-void BiasState::initGridPointState(const AwhBiasParams&          awhBiasParams,
-                                   const std::vector<DimParams>& dimParams,
-                                   const BiasGrid&               grid,
-                                   const BiasParams&             params,
-                                   const std::string&            filename,
-                                   int                           numBias)
+void BiasState::initGridPointState(const AwhBiasParams&      awhBiasParams,
+                                   ArrayRef<const DimParams> dimParams,
+                                   const BiasGrid&           grid,
+                                   const BiasParams&         params,
+                                   const std::string&        filename,
+                                   int                       numBias)
 {
     /* Modify PMF, free energy and the constant target distribution factor
      * to user input values if there is data given.
@@ -1869,10 +1869,10 @@ void BiasState::initGridPointState(const AwhBiasParams&          awhBiasParams,
     normalizePmf(params.numSharedUpdate);
 }
 
-BiasState::BiasState(const AwhBiasParams&          awhBiasParams,
-                     double                        histogramSizeInitial,
-                     const std::vector<DimParams>& dimParams,
-                     const BiasGrid&               grid) :
+BiasState::BiasState(const AwhBiasParams&      awhBiasParams,
+                     double                    histogramSizeInitial,
+                     ArrayRef<const DimParams> dimParams,
+                     const BiasGrid&           grid) :
     coordState_(awhBiasParams, dimParams, grid),
     points_(grid.numPoints()),
     weightSumCovering_(grid.numPoints()),
index 622f96f12c464a194402d5409cddf3c0743f24b8..97a632ffbd3e87c0c5676c2ebee675bee67756bc 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2015,2016,2017,2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2015,2016,2017,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.
@@ -107,10 +107,10 @@ public:
      * \param[in] dimParams             The dimension parameters.
      * \param[in] grid                  The bias grid.
      */
-    BiasState(const AwhBiasParams&          awhBiasParams,
-              double                        histogramSizeInitial,
-              const std::vector<DimParams>& dimParams,
-              const BiasGrid&               grid);
+    BiasState(const AwhBiasParams&      awhBiasParams,
+              double                    histogramSizeInitial,
+              ArrayRef<const DimParams> dimParams,
+              const BiasGrid&           grid);
 
     /*! \brief
      * Restore the bias state from history.
@@ -157,9 +157,9 @@ private:
      * \param[in] grid          The grid.
      * \param[in,out] convolvedPmf  Array returned will be of the same length as the AWH grid to store the convolved PMF in.
      */
-    void calcConvolvedPmf(const std::vector<DimParams>& dimParams,
-                          const BiasGrid&               grid,
-                          std::vector<float>*           convolvedPmf) const;
+    void calcConvolvedPmf(ArrayRef<const DimParams> dimParams,
+                          const BiasGrid&           grid,
+                          std::vector<float>*       convolvedPmf) const;
 
     /*! \brief
      * Convolves the PMF and sets the initial free energy to its convolution.
@@ -167,7 +167,7 @@ private:
      * \param[in] dimParams  The bias dimensions parameters
      * \param[in] grid       The bias grid.
      */
-    void setFreeEnergyToConvolvedPmf(const std::vector<DimParams>& dimParams, const BiasGrid& grid);
+    void setFreeEnergyToConvolvedPmf(ArrayRef<const DimParams> dimParams, const BiasGrid& grid);
 
     /*! \brief
      * Normalize the PMF histogram.
@@ -187,12 +187,12 @@ public:
      * \param[in] filename        Name of file to read PMF and target from.
      * \param[in] numBias         The number of biases.
      */
-    void initGridPointState(const AwhBiasParams&          awhBiasParams,
-                            const std::vector<DimParams>& dimParams,
-                            const BiasGrid&               grid,
-                            const BiasParams&             params,
-                            const std::string&            filename,
-                            int                           numBias);
+    void initGridPointState(const AwhBiasParams&      awhBiasParams,
+                            ArrayRef<const DimParams> dimParams,
+                            const BiasGrid&           grid,
+                            const BiasParams&         params,
+                            const std::string&        filename,
+                            int                       numBias);
 
     /*! \brief
      * Performs statistical checks on the collected histograms and warns if issues are detected.
@@ -224,11 +224,11 @@ public:
      * \param[in,out] force      Force vector to set.
      * Returns the umbrella potential.
      */
-    double calcUmbrellaForceAndPotential(const std::vector<DimParams>& dimParams,
-                                         const BiasGrid&               grid,
-                                         int                           point,
-                                         ArrayRef<const double>        neighborLambdaDhdl,
-                                         gmx::ArrayRef<double>         force) const;
+    double calcUmbrellaForceAndPotential(ArrayRef<const DimParams> dimParams,
+                                         const BiasGrid&           grid,
+                                         int                       point,
+                                         ArrayRef<const double>    neighborLambdaDhdl,
+                                         ArrayRef<double>          force) const;
 
     /*! \brief
      * Calculates and sets the convolved force acting on the coordinate.
@@ -248,12 +248,12 @@ public:
      * \param[in]     forceWorkBuffer     Force work buffer, values only used internally.
      * \param[in,out] force               Bias force vector to set.
      */
-    void calcConvolvedForce(const std::vector<DimParams>& dimParams,
-                            const BiasGrid&               grid,
-                            gmx::ArrayRef<const double>   probWeightNeighbor,
-                            ArrayRef<const double>        neighborLambdaDhdl,
-                            gmx::ArrayRef<double>         forceWorkBuffer,
-                            gmx::ArrayRef<double>         force) const;
+    void calcConvolvedForce(ArrayRef<const DimParams> dimParams,
+                            const BiasGrid&           grid,
+                            ArrayRef<const double>    probWeightNeighbor,
+                            ArrayRef<const double>    neighborLambdaDhdl,
+                            ArrayRef<double>          forceWorkBuffer,
+                            ArrayRef<double>          force) const;
 
     /*! \brief
      * Move the center point of the umbrella potential.
@@ -281,15 +281,15 @@ public:
      * force and potential.
      * \returns the new potential value.
      */
-    double moveUmbrella(const std::vector<DimParams>& dimParams,
-                        const BiasGrid&               grid,
-                        gmx::ArrayRef<const double>   probWeightNeighbor,
-                        ArrayRef<const double>        neighborLambdaDhdl,
-                        gmx::ArrayRef<double>         biasForce,
-                        int64_t                       step,
-                        int64_t                       seed,
-                        int                           indexSeed,
-                        bool                          onlySampleUmbrellaGridpoint);
+    double moveUmbrella(ArrayRef<const DimParams> dimParams,
+                        const BiasGrid&           grid,
+                        ArrayRef<const double>    probWeightNeighbor,
+                        ArrayRef<const double>    neighborLambdaDhdl,
+                        ArrayRef<double>          biasForce,
+                        int64_t                   step,
+                        int64_t                   seed,
+                        int                       indexSeed,
+                        bool                      onlySampleUmbrellaGridpoint);
 
 private:
     /*! \brief
@@ -361,11 +361,11 @@ private:
      * \param[in] multiSimComm  Struct for multi-simulation communication.
      * \returns true if covered.
      */
-    bool isSamplingRegionCovered(const BiasParams&             params,
-                                 const std::vector<DimParams>& dimParams,
-                                 const BiasGrid&               grid,
-                                 const t_commrec*              commRecord,
-                                 const gmx_multisim_t*         multiSimComm) const;
+    bool isSamplingRegionCovered(const BiasParams&         params,
+                                 ArrayRef<const DimParams> dimParams,
+                                 const BiasGrid&           grid,
+                                 const t_commrec*          commRecord,
+                                 const gmx_multisim_t*     multiSimComm) const;
 
     /*! \brief
      * Return the new reference weight histogram size for the current update.
@@ -416,15 +416,15 @@ public:
      * \param[in,out] fplog       Log file.
      * \param[in,out] updateList  Work space to store a temporary list.
      */
-    void updateFreeEnergyAndAddSamplesToHistogram(const std::vector<DimParams>& dimParams,
-                                                  const BiasGrid&               grid,
-                                                  const BiasParams&             params,
-                                                  const t_commrec*              commRecord,
-                                                  const gmx_multisim_t*         ms,
-                                                  double                        t,
-                                                  int64_t                       step,
-                                                  FILE*                         fplog,
-                                                  std::vector<int>*             updateList);
+    void updateFreeEnergyAndAddSamplesToHistogram(ArrayRef<const DimParams> dimParams,
+                                                  const BiasGrid&           grid,
+                                                  const BiasParams&         params,
+                                                  const t_commrec*          commRecord,
+                                                  const gmx_multisim_t*     ms,
+                                                  double                    t,
+                                                  int64_t                   step,
+                                                  FILE*                     fplog,
+                                                  std::vector<int>*         updateList);
 
     /*! \brief
      * Update the probability weights and the convolved bias.
@@ -449,8 +449,8 @@ public:
      * \returns the convolved bias.
      */
 
-    double updateProbabilityWeightsAndConvolvedBias(const std::vector<DimParams>& dimParams,
-                                                    const BiasGrid&               grid,
+    double updateProbabilityWeightsAndConvolvedBias(ArrayRef<const DimParams> dimParams,
+                                                    const BiasGrid&           grid,
                                                     ArrayRef<const double> neighborLambdaEnergies,
                                                     std::vector<double, AlignedAllocator<double>>* weight) const;
 
@@ -464,7 +464,7 @@ public:
      * \param[in] grid                The grid.
      * \param[in] probWeightNeighbor  Probability weights of the neighbors.
      */
-    void sampleProbabilityWeights(const BiasGrid& grid, gmx::ArrayRef<const double> probWeightNeighbor);
+    void sampleProbabilityWeights(const BiasGrid& grid, ArrayRef<const double> probWeightNeighbor);
 
     /*! \brief
      * Sample the reaction coordinate and PMF for future updates or analysis.
@@ -479,7 +479,7 @@ public:
      */
     void sampleCoordAndPmf(const std::vector<DimParams>& dimParams,
                            const BiasGrid&               grid,
-                           gmx::ArrayRef<const double>   probWeightNeighbor,
+                           ArrayRef<const double>        probWeightNeighbor,
                            double                        convolvedBias);
     /*! \brief
      * Calculates the convolved bias for a given coordinate value.
@@ -496,9 +496,9 @@ public:
      * \param[in] coordValue  Coordinate value.
      * \returns the convolved bias >= -GMX_FLOAT_MAX.
      */
-    double calcConvolvedBias(const std::vector<DimParams>& dimParams,
-                             const BiasGrid&               grid,
-                             const awh_dvec&               coordValue) const;
+    double calcConvolvedBias(ArrayRef<const DimParams> dimParams,
+                             const BiasGrid&           grid,
+                             const awh_dvec&           coordValue) const;
 
     /*! \brief
      * Fills the given array with PMF values.
@@ -509,7 +509,7 @@ public:
      *
      * \param[out] pmf  Array(ref) to be filled with the PMF values, should have the same size as the bias grid.
      */
-    void getPmf(gmx::ArrayRef<float> /*pmf*/) const;
+    void getPmf(ArrayRef<float> /*pmf*/) const;
 
     /*! \brief Returns the current coordinate state.
      */
index bfa7022b102a7e9f6395372213ed9cc267cfa42f..544a940bb4ad3b1d3c60fe2af2e734e9c50da6b4 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2015,2016,2017,2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2015,2016,2017,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.
@@ -63,9 +63,9 @@
 namespace gmx
 {
 
-CoordState::CoordState(const AwhBiasParams&          awhBiasParams,
-                       const std::vector<DimParams>& dimParams,
-                       const BiasGrid&               grid)
+CoordState::CoordState(const AwhBiasParams&      awhBiasParams,
+                       ArrayRef<const DimParams> dimParams,
+                       const BiasGrid&           grid)
 {
     for (size_t d = 0; d < dimParams.size(); d++)
     {
index f38ce86de98e2c27f0216138d849397f47654859..05995f826c5ebd58973b035dc340d6fac5694f78 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2015,2016,2017,2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2015,2016,2017,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.
@@ -77,9 +77,7 @@ public:
      * \param[in] dimParams      The dimension Parameters.
      * \param[in] grid           The grid.
      */
-    CoordState(const AwhBiasParams&          awhBiasParams,
-               const std::vector<DimParams>& dimParams,
-               const BiasGrid&               grid);
+    CoordState(const AwhBiasParams& awhBiasParams, ArrayRef<const DimParams> dimParams, const BiasGrid& grid);
 
     /*! \brief
      * Sample a new umbrella reference point given the current coordinate value.
index f16deed99a720c7c618d37703a7592f6bc6510d5..059d8cc6de81988dd9fd446472f5e9b055de71ce 100644 (file)
@@ -150,7 +150,7 @@ namespace
  * \param[in] pointStates  The state of the bias points.
  * \returns true if the histogram is equilibrated.
  */
-bool histogramIsEquilibrated(const std::vector<PointState>& pointStates)
+bool histogramIsEquilibrated(ArrayRef<const PointState> pointStates)
 {
     /* Get the total weight of the total weight histogram; needed for normalization. */
     double totalWeight     = 0;
@@ -207,12 +207,12 @@ bool histogramIsEquilibrated(const std::vector<PointState>& pointStates)
 
 } // namespace
 
-double HistogramSize::newHistogramSize(const BiasParams&              params,
-                                       double                         t,
-                                       bool                           covered,
-                                       const std::vector<PointState>& pointStates,
-                                       ArrayRef<double>               weightsumCovering,
-                                       FILE*                          fplog)
+double HistogramSize::newHistogramSize(const BiasParams&          params,
+                                       double                     t,
+                                       bool                       covered,
+                                       ArrayRef<const PointState> pointStates,
+                                       ArrayRef<double>           weightsumCovering,
+                                       FILE*                      fplog)
 {
     double newHistogramSize;
     if (inInitialStage_)
index 7d9313549cd8443ec0e042e722e1785c25b9c94f..9c60adedfef9899f4817f79c467ed741b0fde36f 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2015,2016,2017,2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2015,2016,2017,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.
@@ -122,12 +122,12 @@ public:
      * \param[in,out] fplog              Log file.
      * \returns the new histogram size.
      */
-    double newHistogramSize(const BiasParams&              params,
-                            double                         t,
-                            bool                           covered,
-                            const std::vector<PointState>& pointStates,
-                            ArrayRef<double>               weightsumCovering,
-                            FILE*                          fplog);
+    double newHistogramSize(const BiasParams&          params,
+                            double                     t,
+                            bool                       covered,
+                            ArrayRef<const PointState> pointStates,
+                            ArrayRef<double>           weightsumCovering,
+                            FILE*                      fplog);
 
     /*! \brief Restores the histogram size from history.
      *