antioch-0.4.0
nasa9_curve_fit_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_CPPUNIT
30 
31 // C++
32 #include <limits>
33 
34 // Antioch
36 #include "antioch/temp_cache.h"
37 #include "nasa9_thermo_test_base.h"
38 
39 namespace AntiochTesting
40 {
41  template<typename Scalar>
42  class NASA9CurveFitTest : public NASA9ThermoTestBase<Scalar>
43  {
44  public:
45 
47  {
48  {
50  this->three_interval_test(curve_fit);
51  }
52 
53  {
55  this->two_interval_test(curve_fit);
56  }
57 
58  }
59 
61  {
62  {
63  std::vector<Scalar> temp(4);
64  temp[0] = 200;
65  temp[1] = 1000;
66  temp[2] = 6000;
67  temp[3] = 20000;
68 
70  this->three_interval_test(curve_fit);
71  }
72 
73  {
74  std::vector<Scalar> temp(3);
75  temp[0] = 200;
76  temp[1] = 1000;
77  temp[2] = 6000;
78 
80  this->two_interval_test(curve_fit);
81  }
82 
83  }
84 
86  {
87  Scalar T = 302.0;
88  this->test_cp( T, this->_N2_coeffs_200_1000, curve_fit );
89  this->test_h( T, this->_N2_coeffs_200_1000, curve_fit );
90  this->test_s( T, this->_N2_coeffs_200_1000, curve_fit );
91 
92  T = 3002.0;
93  this->test_cp( T, this->_N2_coeffs_1000_6000, curve_fit );
94  this->test_h( T, this->_N2_coeffs_1000_6000, curve_fit );
95  this->test_s( T, this->_N2_coeffs_1000_6000, curve_fit );
96 
97  T = 7002.0;
98  this->test_cp( T, this->_N2_coeffs_6000_20000, curve_fit );
99  this->test_h( T, this->_N2_coeffs_6000_20000, curve_fit );
100  this->test_s( T, this->_N2_coeffs_6000_20000, curve_fit );
101  }
102 
104  {
105  Scalar T = 302.0;
106  this->test_cp( T, this->_NO2_coeffs_200_1000, curve_fit );
107  this->test_h( T, this->_NO2_coeffs_200_1000, curve_fit );
108  this->test_s( T, this->_NO2_coeffs_200_1000, curve_fit );
109 
110  T = 3002.0;
111  this->test_cp( T, this->_NO2_coeffs_1000_6000, curve_fit );
112  this->test_h( T, this->_NO2_coeffs_1000_6000, curve_fit );
113  this->test_s( T, this->_NO2_coeffs_1000_6000, curve_fit );
114  }
115 
116  void test_cp( Scalar T,
117  const std::vector<Scalar>& exact_coeffs,
118  const Antioch::NASA9CurveFit<Scalar>& curve_fit )
119  {
121  Scalar cp = this->cp_exact( T,
122  exact_coeffs[0],
123  exact_coeffs[1],
124  exact_coeffs[2],
125  exact_coeffs[3],
126  exact_coeffs[4],
127  exact_coeffs[5],
128  exact_coeffs[6] );
129 
130  CPPUNIT_ASSERT_DOUBLES_EQUAL( cp, curve_fit.cp_over_R(cache), this->tol() );
131  }
132 
133  void test_h( Scalar T,
134  const std::vector<Scalar>& exact_coeffs,
135  const Antioch::NASA9CurveFit<Scalar>& curve_fit )
136  {
138  Scalar h = this->h_exact( T,
139  exact_coeffs[0],
140  exact_coeffs[1],
141  exact_coeffs[2],
142  exact_coeffs[3],
143  exact_coeffs[4],
144  exact_coeffs[5],
145  exact_coeffs[6],
146  exact_coeffs[7] );
147 
148  CPPUNIT_ASSERT_DOUBLES_EQUAL( h, curve_fit.h_over_RT(cache), this->tol() );
149  }
150 
151  void test_s( Scalar T,
152  const std::vector<Scalar>& exact_coeffs,
153  const Antioch::NASA9CurveFit<Scalar>& curve_fit )
154  {
156  Scalar s = this->s_exact( T,
157  exact_coeffs[0],
158  exact_coeffs[1],
159  exact_coeffs[2],
160  exact_coeffs[3],
161  exact_coeffs[4],
162  exact_coeffs[5],
163  exact_coeffs[6],
164  exact_coeffs[8] );
165 
166  CPPUNIT_ASSERT_DOUBLES_EQUAL( s, curve_fit.s_over_R(cache), this->tol() );
167  }
168 
169  Scalar tol()
170  { return std::numeric_limits<Scalar>::epsilon() * 500; }
171 
172  Scalar cp_exact( Scalar T, Scalar a0, Scalar a1, Scalar a2,
173  Scalar a3, Scalar a4, Scalar a5, Scalar a6 )
174  {
175  return a0/(T*T) + a1/T + a2 + a3*T + a4*(T*T) + a5*(T*T*T) + a6*(T*T*T*T);
176  }
177 
178  Scalar h_exact( Scalar T, Scalar a0, Scalar a1, Scalar a2,
179  Scalar a3, Scalar a4, Scalar a5, Scalar a6,
180  Scalar a7 )
181  {
182  return -a0/(T*T) + a1*std::log(T)/T + a2 + a3*T/2.0L + a4*(T*T)/3.0L
183  + a5*(T*T*T)/4.0L + a6*(T*T*T*T)/5.0L + a7/T;
184  }
185 
186  Scalar s_exact( Scalar T, Scalar a0, Scalar a1, Scalar a2,
187  Scalar a3, Scalar a4, Scalar a5, Scalar a6,
188  Scalar a8 )
189  {
190  return -a0/(2.L*T*T) - a1/T + a2*std::log(T) + a3*T + a4*(T*T)/2.0L
191  + a5*(T*T*T)/3.0L + a6*(T*T*T*T)/4.0L + a8;
192  }
193 
194  };
195 
197  {
198  public:
200 
203 
205 
206  };
207 
209  {
210  public:
212 
215 
217 
218  };
219 
220  class NASA9CurveFitTestLongDouble : public NASA9CurveFitTest<long double>
221  {
222  public:
224 
227 
229 
230  };
231 
235 
236 } // end namespace AntiochTesting
237 
238 #endif // ANTIOCH_HAVE_CPPUNIT
CPPUNIT_TEST(test_nasa9_default_temp_intervals)
void test_h(Scalar T, const std::vector< Scalar > &exact_coeffs, const Antioch::NASA9CurveFit< Scalar > &curve_fit)
CPPUNIT_TEST_SUITE(NASA9CurveFitTestLongDouble)
CPPUNIT_TEST(test_nasa9_default_temp_intervals)
CPPUNIT_TEST_SUITE(NASA9CurveFitTestFloat)
void three_interval_test(const Antioch::NASA9CurveFit< Scalar > &curve_fit)
CPPUNIT_TEST_SUITE(NASA9CurveFitTestDouble)
const StateType cp_over_R(const TempCache< StateType > &cache) const
Scalar cp(Scalar T, Scalar a0, Scalar a1, Scalar a2, Scalar a3, Scalar a4, Scalar a5, Scalar a6)
Scalar h_exact(Scalar T, Scalar a0, Scalar a1, Scalar a2, Scalar a3, Scalar a4, Scalar a5, Scalar a6, Scalar a7)
void test_s(Scalar T, const std::vector< Scalar > &exact_coeffs, const Antioch::NASA9CurveFit< Scalar > &curve_fit)
StateType h_over_RT(const TempCache< StateType > &cache) const
Scalar s_exact(Scalar T, Scalar a0, Scalar a1, Scalar a2, Scalar a3, Scalar a4, Scalar a5, Scalar a6, Scalar a8)
This class stores the NASA polynomial fit to the thermodynamics quantities and .
Definition: ascii_parser.h:68
CPPUNIT_TEST_SUITE_REGISTRATION(ArrheniusRateEigenFloatTest)
StateType s_over_R(const TempCache< StateType > &cache) const
void two_interval_test(const Antioch::NASA9CurveFit< Scalar > &curve_fit)
void test_cp(Scalar T, const std::vector< Scalar > &exact_coeffs, const Antioch::NASA9CurveFit< Scalar > &curve_fit)
CPPUNIT_TEST(test_nasa9_default_temp_intervals)
Scalar cp_exact(Scalar T, Scalar a0, Scalar a1, Scalar a2, Scalar a3, Scalar a4, Scalar a5, Scalar a6)

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