antioch-0.4.0
reaction_rate_vector_test_base.h
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 #ifndef ANTIOCH_REACTION_RATE_VECTOR_TEST_BASE_H
28 #define ANTIOCH_REACTION_RATE_VECTOR_TEST_BASE_H
29 
30 #include "antioch_config.h"
31 
32 #ifdef ANTIOCH_HAVE_CPPUNIT
33 
34 #include <cppunit/extensions/HelperMacros.h>
35 #include <cppunit/TestCase.h>
36 
37 namespace AntiochTesting
38 {
39  template <typename ReactionRate, typename PairScalars>
40  class ReactionRateVectorTestBase : public CppUnit::TestCase
41  {
42  public:
43 
44  void test_rate( const ReactionRate& reaction_rate,
45  const PairScalars& T,
46  typename Antioch::value_type<PairScalars>::type /*Scalar*/ tol )
47  {
48  const PairScalars rate = reaction_rate(T);
49  const PairScalars exact_rate = this->exact_rate(T);
50 
51  for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple)
52  {
53  CPPUNIT_ASSERT_DOUBLES_EQUAL( rate[2*tuple],
54  exact_rate[0],
55  tol );
56 
57  CPPUNIT_ASSERT_DOUBLES_EQUAL( rate[2*tuple+1],
58  exact_rate[1],
59  tol );
60 
61  }
62  }
63 
64  void test_deriv( const ReactionRate& reaction_rate,
65  const PairScalars& T,
66  typename Antioch::value_type<PairScalars>::type /*Scalar*/ tol )
67  {
68  const PairScalars deriv = reaction_rate.derivative(T);
69  const PairScalars exact_deriv = this->exact_deriv(T);
70 
71  for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple)
72  {
73  CPPUNIT_ASSERT_DOUBLES_EQUAL( deriv[2*tuple],
74  exact_deriv[0],
75  tol );
76 
77  CPPUNIT_ASSERT_DOUBLES_EQUAL( deriv[2*tuple+1],
78  exact_deriv[1],
79  tol );
80 
81  }
82  }
83 
84  void test_rate_and_deriv( const ReactionRate& reaction_rate,
85  const PairScalars& T,
86  typename Antioch::value_type<PairScalars>::type /*Scalar*/ tol )
87  {
88  // Init using T as the "example"
89  PairScalars rate = T;
90  PairScalars deriv = T;
91 
92  reaction_rate.rate_and_derivative(T,rate,deriv);
93 
94  const PairScalars exact_rate = this->exact_rate(T);
95  const PairScalars exact_deriv = this->exact_deriv(T);
96 
97  for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple)
98  {
99  CPPUNIT_ASSERT_DOUBLES_EQUAL( rate[2*tuple],
100  exact_rate[0],
101  tol );
102 
103  CPPUNIT_ASSERT_DOUBLES_EQUAL( rate[2*tuple+1],
104  exact_rate[1],
105  tol );
106 
107  CPPUNIT_ASSERT_DOUBLES_EQUAL( deriv[2*tuple],
108  exact_deriv[0],
109  tol );
110 
111  CPPUNIT_ASSERT_DOUBLES_EQUAL( deriv[2*tuple+1],
112  exact_deriv[1],
113  tol );
114  }
115  }
116 
117 
118  protected:
119 
120  // Should be new'd/deleted in subclasses for each PairScalar type
121  PairScalars* _example;
122 
123  PairScalars setup_T( const PairScalars& example )
124  {
125  // Construct from example to avoid resizing issues
126  PairScalars T = example;
127  for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple)
128  {
129  T[2*tuple] = 1500.1;
130  T[2*tuple+1] = 1600.1;
131  }
132  return T;
133  }
134 
135  virtual PairScalars exact_rate( PairScalars T ) =0;
136  virtual PairScalars exact_deriv( PairScalars T ) =0;
137 
138  };
139 
140 } // end namespace AntiochTesting
141 
142 #endif // ANTIOCH_HAVE_CPPUNIT
143 
144 #endif // ANTIOCH_REACTION_RATE_VECTOR_TEST_BASE_H
void test_rate_and_deriv(const ReactionRate &reaction_rate, const PairScalars &T, typename Antioch::value_type< PairScalars >::typetol)
void test_deriv(const ReactionRate &reaction_rate, const PairScalars &T, typename Antioch::value_type< PairScalars >::typetol)
PairScalars setup_T(const PairScalars &example)
virtual PairScalars exact_rate(PairScalars T)=0
virtual PairScalars exact_deriv(PairScalars T)=0
void test_rate(const ReactionRate &reaction_rate, const PairScalars &T, typename Antioch::value_type< PairScalars >::typetol)

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