8e8a92c4fa110c0a6b930b866fdc47a422f83d85
[alexxy/gromacs.git] / src / gromacs / mdtypes / awh-correlation-history.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2015,2016,2017, 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.
8  *
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.
13  *
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.
18  *
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.
23  *
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.
31  *
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.
34  */
35
36 /*! \libinternal \file
37  *
38  * \brief
39  * Contains datatypes and function declarations needed by AWH to
40  * have its force correlation data checkpointed.
41  *
42  * \author Viveca Lindahl
43  * \author Berk Hess <hess@kth.se>
44  * \inlibraryapi
45  * \ingroup module_mdtypes
46  */
47
48 #ifndef GMX_MDTYPES_AWH_CORRELATION_HISTORY_H
49 #define GMX_MDTYPES_AWH_CORRELATION_HISTORY_H
50
51 #include <vector>
52
53 namespace gmx
54 {
55
56 /*! \cond INTERNAL */
57
58 //! Correlation block averaging data.
59 struct CorrelationBlockDataHistory
60 {
61     double blockSumWeight;                       /**< Sum weights for current block. */
62     double blockSumSquareWeight;                 /**< Sum weights^2 for current block. */
63     double blockSumWeightX;                      /**< Weighted sum of x for current block. */
64     double blockSumWeightY;                      /**< Weighted sum of y for current block. */
65     double sumOverBlocksSquareBlockWeight;       /**< Sum over all blocks in the simulation of block weight^2 over the whole simulation. */
66     double sumOverBlocksBlockSquareWeight;       /**< Sum over all blocks in the simulation of weight^2 over the whole simulation. */
67     double sumOverBlocksBlockWeightBlockWeightX; /**< Sum over all blocks in the simulation of block weight times blockSumWeightX over the whole simulation. */
68     double sumOverBlocksBlockWeightBlockWeightY; /**< Sum over all blocks in the simulation of block weight times blockSumWeightY over the whole simulation. */
69     double blockLength;                          /**< The length of each block used for block averaging. */
70     int    previousBlockIndex;                   /**< The last block index data was added to (needed only for block length in terms of time). */
71     double correlationIntegral;                  /**< The time integral of the correlation function of x and y, corr(x(0), y(t)). */
72 };
73
74 //! Grid of local correlation matrices.
75 struct CorrelationGridHistory
76 {
77     /* These counts here since we curently need them for initializing the correlation grid when reading a checkpoint */
78     int numCorrelationTensors; /**< Number correlation tensors in the grid (equal to the number of points). */
79     int tensorSize;            /**< The number of stored correlation matrix elements. */
80     int blockDataListSize;     /**< To be able to increase the block length later on, data is saved for several block lengths for each element. */
81
82     /* We store all tensor sequentially in a buffer */
83     std::vector<CorrelationBlockDataHistory> blockDataBuffer; /**< Buffer that contains the correlation data. */
84 };
85
86 /*! \endcond */
87
88 /*! \brief
89  * Initialize correlation grid history, sets all sizes.
90  *
91  * \param[in,out] correlationGridHistory  Correlation grid history for master rank.
92  * \param[in] numCorrelationTensors       Number of correlation tensors in the grid.
93  * \param[in] tensorSize                  Number of correlation elements in each tensor.
94  * \param[in] blockDataListSize           The number of blocks in the list of each tensor element.
95  */
96 void initCorrelationGridHistory(CorrelationGridHistory *correlationGridHistory,
97                                 int                     numCorrelationTensors,
98                                 int                     tensorSize,
99                                 int                     blockDataListSize);
100
101 }      // namespace gmx
102
103 #endif /* GMX_MDTYPES_AWH_CORRELATION_HISTORY_H */