antioch-0.4.0
gsl_spliner_test.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // Antioch - A Gas Dynamics Thermochemistry Library
5 //
6 // Copyright (C) 2014-2016 Paul T. Bauman, Benjamin S. Kirk,
7 // Sylvain Plessis, Roy H. Stonger
8 //
9 // Copyright (C) 2013 The PECOS Development Team
10 //
11 // This library is free software; you can redistribute it and/or
12 // modify it under the terms of the Version 2.1 GNU Lesser General
13 // Public License as published by the Free Software Foundation.
14 //
15 // This library 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.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
23 // Boston, MA 02110-1301 USA
24 //
25 //-----------------------------------------------------------------------el-
26 
27 #include "antioch_config.h"
28 
29 #ifdef ANTIOCH_HAVE_GSL
30 #ifdef ANTIOCH_HAVE_CPPUNIT
31 
32 // C++
33 #include <limits>
34 #include <cmath>
35 
36 // Antioch
38 #include "antioch/gsl_spliner.h"
39 #include "antioch/vector_utils.h"
40 
41 // Base class
42 #include "gsl_spliner_test_base.h"
43 
44 namespace AntiochTesting
45 {
46  template<typename Scalar>
47  class GSLSplinerTest : public GSLSplinerTestBase<Scalar>
48  {
49  public:
50 
51  void setUp()
52  {
53  this->init_data();
54  }
55 
56  // Helper function
57  template<typename FunctionType>
58  void run_manually_inited_test( Scalar tol )
59  {
60  FunctionType exact_func;
61  exact_func.init(this->_x_min, this->_x_max);
62 
63  this->fill_ref(this->_x_ref,this->_y_ref,this->_n_data, this->_x_min, this->_x_max, exact_func );
64 
65  Antioch::GSLSpliner spline;
66  spline.spline_init(this->_x_ref, this->_y_ref);
67 
68  this->compare_values( tol, spline, exact_func );
69  }
70 
71  // Helper function
72  template<typename FunctionType>
73  void run_constructor_inited_test( Scalar tol )
74  {
75  FunctionType exact_func;
76  exact_func.init(this->_x_min, this->_x_max);
77 
78  this->fill_ref(this->_x_ref,this->_y_ref,this->_n_data, this->_x_min, this->_x_max, exact_func );
79 
80  Antioch::GSLSpliner spline(this->_x_ref, this->_y_ref);
81 
82  this->compare_values( tol, spline, exact_func );
83  }
84 
85  // Helper function
86  void compare_values( Scalar tol, Antioch::GSLSpliner& spline, GSLSplinerTestFunction<Scalar>& exact_func )
87  {
88  for(unsigned int n = 0; n < this->_n_test; n++)
89  {
90  Scalar x = this->_x_min + (Scalar)(n) * (this->_x_max - this->_x_min) / (Scalar)(this->_n_test-1);
91  Scalar exact_value = exact_func(x);
92  Scalar interp_value = spline.interpolated_value(x);
93  CPPUNIT_ASSERT_DOUBLES_EQUAL( interp_value,
94  exact_value,
95  tol );
96  }
97  }
98 
99  void test_manually_inited_spline_constant_func()
100  {
101  const Scalar tol = std::numeric_limits<Scalar>::epsilon() * 10;
102 
103  this->run_manually_inited_test<ConstantTestFunction<Scalar> >(tol);
104  }
105 
106  void test_constructor_inited_spline_constant_func()
107  {
108  const Scalar tol = std::numeric_limits<Scalar>::epsilon() * 10;
109 
110  this->run_constructor_inited_test<ConstantTestFunction<Scalar> >(tol);
111  }
112 
113  void test_manually_inited_spline_linear_func()
114  {
115  const Scalar tol = std::numeric_limits<Scalar>::epsilon() * 50;
116 
117  this->run_manually_inited_test<LinearTestFunction<Scalar> >(tol);
118  }
119 
120  void test_constructor_inited_spline_linear_func()
121  {
122  const Scalar tol = std::numeric_limits<Scalar>::epsilon() * 50;
123 
124  this->run_constructor_inited_test<LinearTestFunction<Scalar> >(tol);
125  }
126 
127  void test_manually_inited_spline_cubic_func()
128  {
129  const Scalar tol = std::numeric_limits<Scalar>::epsilon() * 50;
130 
131  this->run_manually_inited_test<CubicTestFunction<Scalar> >(tol);
132  }
133 
134  void test_constructor_inited_spline_cubic_func()
135  {
136  const Scalar tol = std::numeric_limits<Scalar>::epsilon() * 50;
137 
138  this->run_constructor_inited_test<CubicTestFunction<Scalar> >(tol);
139  }
140  };
141 
142  class GslSplinerFloatTest : public GSLSplinerTest<float>
143  {
144  public:
145  CPPUNIT_TEST_SUITE( GslSplinerFloatTest );
146 
147  CPPUNIT_TEST( test_manually_inited_spline_constant_func );
148  CPPUNIT_TEST( test_constructor_inited_spline_constant_func );
149  CPPUNIT_TEST( test_manually_inited_spline_linear_func );
150  CPPUNIT_TEST( test_constructor_inited_spline_linear_func );
151  CPPUNIT_TEST( test_manually_inited_spline_cubic_func );
152  CPPUNIT_TEST( test_constructor_inited_spline_cubic_func );
153 
154  CPPUNIT_TEST_SUITE_END();
155  };
156 
157  class GslSplinerDoubleTest : public GSLSplinerTest<double>
158  {
159  public:
160  CPPUNIT_TEST_SUITE( GslSplinerDoubleTest );
161 
162  CPPUNIT_TEST( test_manually_inited_spline_constant_func );
163  CPPUNIT_TEST( test_constructor_inited_spline_constant_func );
164  CPPUNIT_TEST( test_manually_inited_spline_linear_func );
165  CPPUNIT_TEST( test_constructor_inited_spline_linear_func );
166  CPPUNIT_TEST( test_manually_inited_spline_cubic_func );
167  CPPUNIT_TEST( test_constructor_inited_spline_cubic_func );
168 
169  CPPUNIT_TEST_SUITE_END();
170  };
171 
172  CPPUNIT_TEST_SUITE_REGISTRATION( GslSplinerFloatTest );
173  CPPUNIT_TEST_SUITE_REGISTRATION( GslSplinerDoubleTest );
174 
175 } // end namespace AntiochTesting
176 
177 #endif // ANTIOCH_HAVE_CPPUNIT
178 #endif // ANTIOCH_HAVE_GSL
CPPUNIT_TEST_SUITE_REGISTRATION(ArrheniusRateEigenFloatTest)

Generated on Thu Jul 7 2016 11:09:46 for antioch-0.4.0 by  doxygen 1.8.8