AVX512 transposeScatterIncr/DecrU with load/store
[alexxy/gromacs.git] / src / gromacs / correlationfunctions / tests / autocorr.cpp
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2014,2015, 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 /*! \internal \file
36  * \brief
37  * Implements test of autocorrelation function routines
38  *
39  * \author Anders G&auml;rden&auml;s <anders.gardenas@gmail.com>
40  * \author David van der Spoel <david.vanderspoel@icm.uu.se>
41  * \ingroup module_correlationfunctions
42  */
43 #include "gmxpre.h"
44
45 #include "gromacs/correlationfunctions/autocorr.h"
46
47 #include <cmath>
48
49 #include <memory>
50
51 #include <gtest/gtest.h>
52
53 #include "gromacs/correlationfunctions/expfit.h"
54 #include "gromacs/fft/fft.h"
55 #include "gromacs/utility/gmxassert.h"
56 #include "gromacs/utility/smalloc.h"
57
58 #include "testutils/refdata.h"
59 #include "testutils/testasserts.h"
60 #include "testutils/testfilemanager.h"
61
62 #include "correlationdataset.h"
63
64 namespace gmx
65 {
66 namespace
67 {
68
69 //! Definition of pointer to class containing test data.
70 typedef std::unique_ptr<CorrelationDataSet> CorrelationDataSetPointer;
71
72 class AutocorrTest : public ::testing::Test
73 {
74     protected:
75
76         static int                                  nrFrames_;
77         static CorrelationDataSetPointer            data_;
78         // Need raw pointer for passing this to C routines
79         static t_pargs                            * tempArgs_;
80
81         test::TestReferenceData                     refData_;
82         test::TestReferenceChecker                  checker_;
83
84         // Use erefdataCreateMissing for creating new files
85         AutocorrTest( )
86             : checker_(refData_.rootChecker())
87         {
88 #if GMX_DOUBLE
89             checker_.setDefaultTolerance(test::relativeToleranceAsFloatingPoint(1, 1e-6));
90 #else
91             checker_.setDefaultTolerance(test::relativeToleranceAsFloatingPoint(1, 1e-3));
92 #endif
93         }
94
95         // Static initiation, only run once every test.
96         static void SetUpTestCase()
97         {
98             int         n        = 0;
99             std::string fileName = "testCOS3.xvg";
100             data_                = CorrelationDataSetPointer(new CorrelationDataSet(fileName));
101             nrFrames_            = data_->getNrLines();
102             tempArgs_            = add_acf_pargs(&n, NULL);
103         }
104
105         static void TearDownTestCase()
106         {
107
108             sfree(tempArgs_);
109             tempArgs_ = NULL;
110             gmx_fft_cleanup();
111         }
112
113         void test(unsigned long mode)
114         {
115             bool              bAverage      = false;
116             bool              bNormalize    = true;
117             bool              bVerbose      = false;
118             int               nrRestart     = 1;
119             int               dim           = getDim(mode);
120             std::vector<real> result;
121
122             for (int i = 0; i < nrFrames_; i++)
123             {
124                 for (int m = 0; m < dim; m++)
125                 {
126                     result.push_back(data_->getValue(m, i));
127                 }
128             }
129             real *ptr = result.data();
130             low_do_autocorr(0, 0, 0,   nrFrames_, 1,
131                             get_acfnout(), &ptr, data_->getDt(), mode,
132                             nrRestart, bAverage, bNormalize,
133                             bVerbose, data_->getStartTime(), data_->getEndTime(),
134                             effnNONE);
135
136             double testResult = 0;
137             for (int i = 0; i < nrFrames_; i++)
138             {
139                 testResult += result[i];
140             }
141             checker_.checkSequenceArray(nrFrames_, ptr,
142                                         "AutocorrelationFunction");
143             checker_.checkReal(testResult, "Integral");
144         }
145
146         int getDim(unsigned long type)
147         {
148             switch (type)
149             {
150                 case eacNormal:
151                     return 1;
152                 case eacVector:
153                     return 3;
154                 case eacCos:
155                     return 1;
156                 case eacRcross:
157                     return 3;
158                 case eacP0:
159                     return 3;
160                 case eacP1:
161                     return 3;
162                 case eacP2:
163                     return 3;
164                 case eacP3:
165                     return 3;
166                 case eacP4:
167                     return 3;
168                 case eacIden:
169                     return 1;
170                 default:
171                     GMX_RELEASE_ASSERT(false, "Invalid auto correlation option");
172                     return -1;
173             }
174
175         }
176
177 };
178
179 int                         AutocorrTest::nrFrames_;
180 CorrelationDataSetPointer   AutocorrTest::data_;
181 t_pargs                   * AutocorrTest::tempArgs_;
182
183 TEST_F (AutocorrTest, EacNormal)
184 {
185     test(eacNormal);
186 }
187
188 TEST_F (AutocorrTest, EacCos)
189 {
190     test(eacCos);
191 }
192
193 TEST_F (AutocorrTest, EacVector)
194 {
195     test(eacVector);
196 }
197
198 TEST_F (AutocorrTest, EacRcross)
199 {
200     test(eacRcross);
201 }
202
203 TEST_F (AutocorrTest, EacP0)
204 {
205     test(eacP0);
206 }
207
208 TEST_F (AutocorrTest, EacP1)
209 {
210     test(eacP1);
211 }
212
213 TEST_F (AutocorrTest, EacP2)
214 {
215     test(eacP2);
216 }
217
218 TEST_F (AutocorrTest, EacP3)
219 {
220     test(eacP3);
221 }
222
223 TEST_F (AutocorrTest, EacP4)
224 {
225     test(eacP4);
226 }
227
228
229 }
230
231 }