Sort all includes in src/gromacs
[alexxy/gromacs.git] / src / gromacs / fft / tests / fft.cpp
index cd1fc323cd027d989fa2bb2fbb0d9b39334718c8..446d50307f9e2bf2da800be03ed2a2550f264f2d 100644 (file)
@@ -1,48 +1,60 @@
 /*
+ * This file is part of the GROMACS molecular simulation package.
  *
- *                This source code is part of
+ * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
  *
- *                 G   R   O   M   A   C   S
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
  *
- *          GROningen MAchine for Chemical Simulations
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
  *
- * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
- * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2009, The GROMACS development team,
- * check out http://www.gromacs.org for more information.
-
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
  *
- * If you want to redistribute modifications, please consider that
- * scientific software is very special. Version control is crucial -
- * bugs must be traceable. We will be happy to consider code for
- * inclusion in the official distribution, but derived work must not
- * be called official GROMACS. Details are found in the README & COPYING
- * files - if they are missing, get the official version at www.gromacs.org.
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
  *
  * To help us fund GROMACS development, we humbly ask that you cite
- * the papers on the package - you can find them in the top README file.
- *
- * For more info, check our website at http://www.gromacs.org
+ * the research papers on the package. Check out http://www.gromacs.org.
  */
 /*! \internal \file
  * \brief
  * Tests utilities for fft calculations.
  *
+ * Current reference data is generated in double precision using the Reference
+ * build type, except for the compiler (Apple Clang).
+ *
  * \author Roland Schulz <roland@utk.edu>
  * \ingroup module_fft
  */
+#include "gmxpre.h"
+
+#include "gromacs/fft/fft.h"
+
 #include <vector>
 
 #include <gtest/gtest.h>
 
-#include "gromacs/fft/fft.h"
 #include "gromacs/fft/parallel_3dfft.h"
 #include "gromacs/utility/stringutil.h"
+
 #include "testutils/refdata.h"
+#include "testutils/testasserts.h"
 
 namespace
 {
@@ -75,16 +87,27 @@ const real inputdata[] = { //print ",\n".join([",".join(["%4s"%(random.randint(-
 class BaseFFTTest : public ::testing::Test
 {
     public:
-        BaseFFTTest() : checker_(data_.rootChecker())
+        BaseFFTTest()
+            : checker_(data_.rootChecker()), flags_(GMX_FFT_FLAG_CONSERVATIVE)
         {
+            // TODO: These tolerances are just something that has been observed
+            // to be sufficient to pass the tests.  It would be nicer to
+            // actually argue about why they are sufficient (or what is).
+#ifdef GMX_DOUBLE
+            checker_.setDefaultTolerance(gmx::test::relativeRealTolerance(10.0, 512));
+#else
+            checker_.setDefaultTolerance(gmx::test::relativeRealTolerance(10.0, 64));
+#endif
         }
         ~BaseFFTTest()
         {
             gmx_fft_cleanup();
         }
+
         gmx::test::TestReferenceData    data_;
         gmx::test::TestReferenceChecker checker_;
         std::vector<real>               in_, out_;
+        int                             flags_;
 };
 
 class FFTTest : public BaseFFTTest
@@ -154,7 +177,7 @@ TEST_P(FFTTest1D, Complex)
     real* in  = &in_[0];
     real* out = &out_[0];
 
-    gmx_fft_init_1d(&fft_, nx, 0);
+    gmx_fft_init_1d(&fft_, nx, flags_);
 
     gmx_fft_1d(fft_, GMX_FFT_FORWARD, in, out);
     checker_.checkSequenceArray(nx*2, out, "forward");
@@ -173,7 +196,7 @@ TEST_P(FFTTest1D, Real)
     real* in  = &in_[0];
     real* out = &out_[0];
 
-    gmx_fft_init_1d_real(&fft_, rx, 0);
+    gmx_fft_init_1d_real(&fft_, rx, flags_);
 
     gmx_fft_1d_real(fft_, GMX_FFT_REAL_TO_COMPLEX, in, out);
     checker_.checkSequenceArray(cx*2, out, "forward");
@@ -195,7 +218,7 @@ TEST_F(ManyFFTTest, Complex1DLength48Multi5Test)
     real* in  = &in_[0];
     real* out = &out_[0];
 
-    gmx_fft_init_many_1d(&fft_, nx, N, 0);
+    gmx_fft_init_many_1d(&fft_, nx, N, flags_);
 
     gmx_fft_many_1d(fft_, GMX_FFT_FORWARD, in, out);
     checker_.checkSequenceArray(nx*2*N, out, "forward");
@@ -214,7 +237,7 @@ TEST_F(ManyFFTTest, Real1DLength48Multi5Test)
     real* in  = &in_[0];
     real* out = &out_[0];
 
-    gmx_fft_init_many_1d_real(&fft_, rx, N, 0);
+    gmx_fft_init_many_1d_real(&fft_, rx, N, flags_);
 
     gmx_fft_many_1d_real(fft_, GMX_FFT_REAL_TO_COMPLEX, in, out);
     checker_.checkSequenceArray(cx*2*N, out, "forward");
@@ -233,7 +256,7 @@ TEST_F(FFTTest, Real2DLength18_15Test)
     real* in  = &in_[0];
     real* out = &out_[0];
 
-    gmx_fft_init_2d_real(&fft_, rx, ny, 0);
+    gmx_fft_init_2d_real(&fft_, rx, ny, flags_);
 
     gmx_fft_2d_real(fft_, GMX_FFT_REAL_TO_COMPLEX, in, out);
     checker_.checkSequenceArray(cx*2*ny, out, "forward");
@@ -252,7 +275,7 @@ TEST_F(FFFTest3D, Real5_6_9)
     ivec       local_ndata, offset, rsize, csize, complex_order;
 
     gmx_parallel_3dfft_init(&fft_, ndata, &rdata, &cdata,
-                            comm, NULL, NULL, TRUE, 1);
+                            comm, TRUE, 1);
 
     gmx_parallel_3dfft_real_limits(fft_, local_ndata, offset, rsize);
     gmx_parallel_3dfft_complex_limits(fft_, complex_order,
@@ -262,15 +285,13 @@ TEST_F(FFFTest3D, Real5_6_9)
     int size = csize[0]*csize[1]*csize[2];
 
     memcpy(rdata, inputdata, size*sizeof(t_complex));
-    gmx_parallel_3dfft_execute(fft_, GMX_FFT_REAL_TO_COMPLEX, rdata, cdata,
-                               0, NULL);
+    gmx_parallel_3dfft_execute(fft_, GMX_FFT_REAL_TO_COMPLEX, 0, NULL);
     //TODO use std::complex and add checkComplex for it
     checker_.checkSequenceArray(size*2,
                                 reinterpret_cast<real*>(cdata), "forward");
 
     memcpy(cdata, inputdata, size*sizeof(t_complex));
-    gmx_parallel_3dfft_execute(fft_, GMX_FFT_COMPLEX_TO_REAL, rdata, cdata,
-                               0, NULL);
+    gmx_parallel_3dfft_execute(fft_, GMX_FFT_COMPLEX_TO_REAL, 0, NULL);
     for (int i = 0; i < ndata[0]*ndata[1]; i++) //check sequence but skip unused data
     {
         checker_.checkSequenceArray(ndata[2], rdata+i*rsize[2],