2 * This file is part of the GROMACS molecular simulation package.
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.
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.
38 * Implements the CorrelationGrid class to collect correlation statistics on a grid, using several block lengths.
40 * \author Viveca Lindahl
41 * \author Berk Hess <hess@kth.se>
47 #include "correlationgrid.h"
49 #include "gromacs/math/utilities.h"
50 #include "gromacs/utility/gmxassert.h"
59 * Return the number of block data structs needed for keeping a certain number of blocks.
61 * The list start with 1 block and doubles, so we need 1 + 2log(numBlocks).
63 * \param[in] numBlocks Number of blocks.
64 * \returns the number of block data structs.
66 int getBlockDataListSize(int numBlocks
)
68 int blockDataListSize
= 1;
70 while (numBlocks
> (1 << (blockDataListSize
- 1)))
75 GMX_RELEASE_ASSERT((1 << (blockDataListSize
- 1)) == numBlocks
, "numBlocks should be a power of 2");
77 return blockDataListSize
;
82 CorrelationGrid::CorrelationGrid(int numPoints
,
84 double blockLengthInit
,
85 BlockLengthMeasure blockLengthMeasure
,
88 blockLengthMeasure(blockLengthMeasure
)
90 /* Set the initial block length for the block averaging. The length doesn't really matter
91 after the block length has been doubled a few times, as long as it's set small enough */
92 if (blockLengthMeasure
== BlockLengthMeasure::Weight
)
94 blockLengthInit
= blockLengthInit
> 0 ? blockLengthInit
: 1;
98 blockLengthInit
= blockLengthInit
> 0 ? blockLengthInit
: dtSample
;
101 /* Set the number of blocks. The number of blocks determines the current span of the data
102 and how many different block lengths (nblockdata) we need to keep track of to be able to
103 increase the block length later */
104 int numBlocks
= CorrelationTensor::c_numCorrelationBlocks
;
105 int BlockDataListSize
= getBlockDataListSize(numBlocks
);
107 tensors_
.resize(numPoints
, CorrelationTensor(numDim
, BlockDataListSize
, blockLengthInit
));
110 int CorrelationGrid::getNumBlocks() const
112 const auto &blockDataList
= tensors()[0].blockDataList();
113 double maxBlockLength
= blockDataList
.back().blockLength();
114 double minBlockLength
= blockDataList
[0].blockLength();
116 /* If we have a finite block span we have a constant number of blocks, otherwise we are always adding more blocks (and we don't keep track of the number) */
117 if (maxBlockLength
< GMX_DOUBLE_MAX
)
119 return static_cast<int>(maxBlockLength
/minBlockLength
);
127 double CorrelationGrid::getBlockLength() const
129 /* Return the minimum blocklength */
130 return tensors()[0].blockDataList()[0].blockLength();