Introduce SimulatorBuilder
[gromacs.git] / src / gromacs / awh / correlationgrid.h
blob5d3456b44bccefe18c90df1085aca4472bde77ef
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2015,2016,2017,2018, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
36 /*! \internal \file
38 * \brief
39 * Declares the CorrelationGrid class to collect correlation statistics on a grid, using several block lengths.
41 * \author Viveca Lindahl
42 * \author Berk Hess <hess@kth.se>
43 * \ingroup module_awh
46 #ifndef GMX_AWH_CORRELATIONGRID_H
47 #define GMX_AWH_CORRELATIONGRID_H
49 #include <cstddef>
51 #include <vector>
53 #include "gromacs/utility/arrayref.h"
54 #include "gromacs/utility/basedefinitions.h"
55 #include "gromacs/utility/gmxassert.h"
57 #include "correlationtensor.h"
59 namespace gmx
62 struct CorrelationGridHistory;
64 /*! \internal
65 * \brief Grid of local correlation tensors.
67 * This class provides the means for a bias to interaction with the grid
68 * of correlation tensors. The grid should have the same number of points
69 * and the same dimensionality as the bias grid.
71 class CorrelationGrid
73 public:
74 //! Enum that sets how we measure block length.
75 enum class BlockLengthMeasure
77 Time, //!< Measure block length in time.
78 Weight //!< Measure block length in sampled weight.
81 /*! \brief Constructor.
83 * \param[in] numPoints Number of points in the grid.
84 * \param[in] numDims Number of dimensions of the grid.
85 * \param[in] blockLengthInit Initial length of the blocks used for block averaging.
86 * \param[in] blockLengthMeasure Sets how we measure block length.
87 * \param[in] dtSample Time step for sampling correlations.
89 CorrelationGrid(int numPoints,
90 int numDims,
91 double blockLengthInit,
92 BlockLengthMeasure blockLengthMeasure,
93 double dtSample);
95 /*! \brief Adds a weighted data vector to one point in the correlation grid.
97 * \param[in] pointIndex Index of the point to add data to.
98 * \param[in] weight Weight to assign to the data.
99 * \param[in] data One data point for each grid dimension.
100 * \param[in] t The time when the data was sampled.
102 void addData(int pointIndex,
103 double weight,
104 gmx::ArrayRef<const double> data,
105 double t)
107 tensors_[pointIndex].addData(weight, data, blockLengthMeasure == BlockLengthMeasure::Weight, t);
110 /*! \brief Restores the correlation grid state from the correlation grid history.
112 * The setup in the history should match that of this simulation.
113 * If this is not the case, an exception is thrown.
115 * \param[in] correlationGridHistory The correlation grid state history.
117 void restoreStateFromHistory(const CorrelationGridHistory &correlationGridHistory);
119 /*! \brief Returns the number of elements in the tensor: dim*(dim+1)/2.
121 int tensorSize() const
123 GMX_RELEASE_ASSERT(!tensors_.empty(), "Should only call tensorSize on a valid grid");
125 return tensors_[0].blockDataList()[0].correlationIntegral().size();
128 /*! \brief Returns the size of the block data list.
130 int blockDataListSize() const
132 GMX_RELEASE_ASSERT(!tensors_.empty(), "Should only call tensorSize on a valid grid");
134 return tensors_[0].blockDataList().size();
137 /*! \brief Get a const reference to the correlation grid data.
139 const std::vector<CorrelationTensor> &tensors() const
141 return tensors_;
144 /* Right now the below functions are only used for an initial log printing. */
146 /*! \brief Get the current blocklength.
148 double getBlockLength() const;
150 /*! \brief Get the current number of blocks.
152 * If we have a finite block span we have a constant number of blocks,
153 * otherwise we are always adding more blocks (and we don't keep
154 * track of the number), so we return -1.
156 int getNumBlocks() const;
158 public:
159 const double dtSample; /**< Time in between samples. */
160 const BlockLengthMeasure blockLengthMeasure; /**< The measure for the block length. */
161 private:
162 std::vector<CorrelationTensor> tensors_; /**< Correlation tensor grid */
165 } // namespace gmx
167 #endif /* GMX_AWH_CORRELATIONGRID_H */