2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2014,2015,2016,2017,2018 by the GROMACS development team.
5 * Copyright (c) 2019,2020, by the GROMACS development team, led by
6 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
7 * and including many others, as listed in the AUTHORS file in the
8 * top-level source directory and at http://www.gromacs.org.
10 * GROMACS is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public License
12 * as published by the Free Software Foundation; either version 2.1
13 * of the License, or (at your option) any later version.
15 * GROMACS is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with GROMACS; if not, see
22 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
23 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 * If you want to redistribute modifications to GROMACS, please
26 * consider that scientific software is very special. Version
27 * control is crucial - bugs must be traceable. We will be happy to
28 * consider code for inclusion in the official distribution, but
29 * derived work must not be called official GROMACS. Details are found
30 * in the README & COPYING files - if they are missing, get the
31 * official version at http://www.gromacs.org.
33 * To help us fund GROMACS development, we humbly ask that you cite
34 * the research papers on the package. Check out http://www.gromacs.org.
38 * Implements test of autocorrelation function routines
40 * \author Anders Gärdenäs <anders.gardenas@gmail.com>
41 * \author David van der Spoel <david.vanderspoel@icm.uu.se>
42 * \ingroup module_correlationfunctions
46 #include "gromacs/correlationfunctions/autocorr.h"
52 #include <gtest/gtest.h>
54 #include "gromacs/correlationfunctions/expfit.h"
55 #include "gromacs/fft/fft.h"
56 #include "gromacs/utility/gmxassert.h"
57 #include "gromacs/utility/smalloc.h"
59 #include "testutils/refdata.h"
60 #include "testutils/testasserts.h"
61 #include "testutils/testfilemanager.h"
63 #include "correlationdataset.h"
70 //! Definition of pointer to class containing test data.
71 typedef std::unique_ptr<CorrelationDataSet> CorrelationDataSetPointer;
73 class AutocorrTest : public ::testing::Test
77 static CorrelationDataSetPointer data_;
78 // Need raw pointer for passing this to C routines
79 static t_pargs* tempArgs_;
81 test::TestReferenceData refData_;
82 test::TestReferenceChecker checker_;
84 // Use erefdataCreateMissing for creating new files
85 AutocorrTest() : checker_(refData_.rootChecker())
88 checker_.setDefaultTolerance(test::relativeToleranceAsFloatingPoint(1, 1e-6));
90 checker_.setDefaultTolerance(test::relativeToleranceAsFloatingPoint(1, 1e-3));
94 // Static initiation, only run once every test.
95 static void SetUpTestCase()
98 std::string fileName = "testCOS3.xvg";
99 data_ = std::make_unique<CorrelationDataSet>(fileName);
100 nrFrames_ = data_->getNrLines();
101 tempArgs_ = add_acf_pargs(&n, nullptr);
104 static void TearDownTestCase()
111 void test(unsigned long mode, bool bNormalize)
113 bool bAverage = true;
114 bool bVerbose = false;
116 int dim = getDim(mode);
117 std::vector<real> result;
119 for (int i = 0; i < nrFrames_; i++)
121 for (int m = 0; m < dim; m++)
123 result.push_back(data_->getValue(m, i));
126 real* ptr = result.data();
127 low_do_autocorr(nullptr,
140 data_->getStartTime(),
144 double testResult = 0;
145 for (int i = 0; i < get_acfnout(); i++)
147 testResult += result[i];
149 checker_.checkSequenceArray(get_acfnout(), ptr, "AutocorrelationFunction");
150 checker_.checkReal(testResult, "Integral");
153 static int getDim(unsigned long type)
157 case eacNormal: return 1;
158 case eacVector: return 3;
161 // Several intended fall-throughs follow
167 case eacP4: return 3;
168 case eacIden: return 1;
169 default: GMX_RELEASE_ASSERT(false, "Invalid auto correlation option"); return -1;
174 int AutocorrTest::nrFrames_;
175 CorrelationDataSetPointer AutocorrTest::data_;
176 t_pargs* AutocorrTest::tempArgs_;
178 TEST_F(AutocorrTest, EacNormal)
180 test(eacNormal, true);
183 TEST_F(AutocorrTest, EacNoNormalize)
185 test(eacNormal, false);
188 TEST_F(AutocorrTest, EacCos)
193 TEST_F(AutocorrTest, EacVector)
195 test(eacVector, true);
198 TEST_F(AutocorrTest, EacRcross)
200 test(eacRcross, true);
203 TEST_F(AutocorrTest, EacP0)
208 TEST_F(AutocorrTest, EacP1)
213 TEST_F(AutocorrTest, EacP2)
218 TEST_F(AutocorrTest, EacP3)
223 TEST_F(AutocorrTest, EacP4)