GRINS-0.6.0
antioch_evaluator_regression.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // GRINS - General Reacting Incompressible Navier-Stokes
5 //
6 // Copyright (C) 2014-2015 Paul T. Bauman, Roy H. Stogner
7 // Copyright (C) 2010-2013 The PECOS Development Team
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the Version 2.1 GNU Lesser General
11 // Public License as published by the Free Software Foundation.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
21 // Boston, MA 02110-1301 USA
22 //
23 //-----------------------------------------------------------------------el-
24 
25 
26 #include "grins_config.h"
27 
28 #ifdef GRINS_HAVE_ANTIOCH
29 
30 // C++
31 #include <iomanip>
32 #include <limits>
33 #include <vector>
34 
35 // GRINS
36 #include "grins/antioch_mixture.h"
38 #include "grins/cached_values.h"
39 
40 // libMesh
41 #include "libmesh/getpot.h"
42 
43 // Antioch
44 #include "antioch/cea_evaluator.h"
45 #include "antioch/stat_mech_thermo.h"
46 
47 // Boost
48 #include "boost/math/special_functions/fpclassify.hpp" //isnan
49 
50 int test_generic( const libMesh::Real value, const libMesh::Real value_reg, const std::string& name )
51 {
52  int return_flag = 0;
53 
54  const double tol = std::numeric_limits<double>::epsilon()*40;
55 
56  const double rel_error = std::fabs( (value - value_reg)/value_reg );
57 
58  if( rel_error > tol )
59  {
60  return_flag = 1;
61  std::cout << "Mismatch in "+name << std::endl
62  << name+" = " << value << std::endl
63  << name+"_reg = " << value_reg << std::endl
64  << "rel_error = " << rel_error << std::endl;
65  }
66 
67  return return_flag;
68 }
69 
70 template<typename Thermo>
71 int test_cp( const libMesh::Real cp );
72 
73 template<typename Thermo>
74 int test_cv( const libMesh::Real cv );
75 
76 template<typename Thermo>
77 int test_h_s( const libMesh::Real h_s );
78 
79 template<>
80 int test_cp<Antioch::CEAEvaluator<libMesh::Real> >( const libMesh::Real cp )
81 {
82  double cp_reg = 1.2361869971209990e+03;
83 
84  return test_generic(cp,cp_reg,"cp");
85 }
86 
87 template<>
88 int test_cv<Antioch::CEAEvaluator<libMesh::Real> >( const libMesh::Real cv )
89 {
90  double cv_reg = 8.4681056933423179e+02;
91 
92  return test_generic(cv,cv_reg,"cv");
93 }
94 
95 template<>
96 int test_h_s<Antioch::CEAEvaluator<libMesh::Real> >( const libMesh::Real h_s )
97 {
98  double h_s_reg = 7.6606764036494098e+05;
99 
100  return test_generic(h_s,h_s_reg,"h_s");
101 }
102 
103 template<>
104 int test_cp<Antioch::StatMechThermodynamics<libMesh::Real> >( const libMesh::Real cp )
105 {
106  double cp_reg = 1.2309250447693457e+03;
107 
108  return test_generic(cp,cp_reg,"cp");
109 }
110 
111 template<>
112 int test_cv<Antioch::StatMechThermodynamics<libMesh::Real> >( const libMesh::Real cv )
113 {
114  double cv_reg = 8.4154861698257866e+02;
115 
116  return test_generic(cv,cv_reg,"cv");
117 }
118 
119 template<>
120 int test_h_s<Antioch::StatMechThermodynamics<libMesh::Real> >( const libMesh::Real h_s )
121 {
122  double h_s_reg = 7.6397682090011111e+05;
123 
124  return test_generic(h_s,h_s_reg,"h_s");
125 }
126 
127 
128 template <typename Thermo>
129 int test_evaluator( const GRINS::AntiochMixture& antioch_mixture )
130 {
131  GRINS::AntiochEvaluator<Thermo> antioch_evaluator( antioch_mixture );
132 
133  libMesh::Real T = 1000;
134 
135  libMesh::Real rho = 1.0e-3;
136 
137  const unsigned int n_species = 5;
138 
139  std::vector<libMesh::Real> Y(n_species,0.2);
140 
141  libMesh::Real R_mix = antioch_mixture.R_mix(Y);
142 
143  GRINS::CachedValues cache;
144 
146  std::vector<double> Tqp(1,T);
148 
150  std::vector<double> rhoqp(1,rho);
152 
154  std::vector<double> Rqp(1,R_mix);
156 
158  std::vector<std::vector<double> > Yqp(1,Y);
160 
161  std::vector<libMesh::Real> omega_dot(n_species,0.0);
162 
163  libMesh::Real cp = antioch_evaluator.cp( cache, 0 );
164 
165  std::cout << std::scientific << std::setprecision(16)
166  << "cp = " << cp << std::endl;
167 
168  libMesh::Real cv = antioch_evaluator.cv( cache, 0 );
169 
170  std::cout << std::scientific << std::setprecision(16)
171  << "cv = " << cv << std::endl;
172 
173  libMesh::Real h_s = antioch_evaluator.h_s( cache, 0, 0 );
174 
175  std::cout << std::scientific << std::setprecision(16)
176  << "h_s = " << h_s << std::endl;
177 
178  int return_flag = 0;
179  int return_flag_temp = 0;
180 
181  return_flag_temp = test_cp<Thermo>( cp );
182  if( return_flag_temp != 0 ) return_flag = 1;
183 
184  return_flag_temp = test_cv<Thermo>( cv );
185  if( return_flag_temp != 0 ) return_flag = 1;
186 
187  return_flag_temp = test_h_s<Thermo>( h_s );
188  if( return_flag_temp != 0 ) return_flag = 1;
189 
190  antioch_evaluator.omega_dot( cache, 0, omega_dot );
191 
192  for( unsigned int i = 0; i < n_species; i++ )
193  {
194  std::cout << std::scientific << std::setprecision(16)
195  << "omega_dot(" << i << ") = " << omega_dot[i] << std::endl;
196  }
197 
198 
199  double tol = std::numeric_limits<double>::epsilon()*40;
200 
201  // Check that omega_dot sums to 1
202  libMesh::Real sum = 0.0;
203  for( unsigned int s = 0; s < n_species; s++ )
204  {
205  sum += omega_dot[s];
206  }
207 
208  if( std::fabs(sum) > tol )
209  {
210  std::cout << "Error: Sum of mass sources not equal to zero!" << std::endl
211  << "sum = " << sum << std::endl;
212  return_flag = 1;
213  }
214 
215  bool omega_is_nan = false;
216  for( unsigned int s = 0; s < n_species; s++ )
217  {
218  if( boost::math::isnan(omega_dot[s]) )
219  {
220  omega_is_nan = true;
221  return_flag = 1;
222  }
223  }
224 
225  if( omega_is_nan )
226  {
227  std::cerr << "Error: Detected NAN's for omega_dot!" << std::endl;
228  }
229 
230  // Now check against regression values
231  std::vector<libMesh::Real> omega_dot_reg(n_species,0.0);
232  omega_dot_reg[0] = 4.3561014567820650e-01;
233  omega_dot_reg[1] = -3.6797207156306633e+00;
234  omega_dot_reg[2] = 2.9970582875850726e+00;
235  omega_dot_reg[3] = -1.8346634812051223e+00;
236  omega_dot_reg[4] = 2.0817157635725065e+00;
237 
238  for( unsigned int s = 0; s < n_species; s++ )
239  {
240  if( std::fabs( (omega_dot[s] - omega_dot_reg[s])/omega_dot_reg[s] ) > tol )
241  {
242  std::cerr << "Error: Mismatch in omega_dot." << std::endl
243  << std::setprecision(16) << std::scientific
244  << "s = " << s << std::endl
245  << "omega_dot = " << omega_dot[s] << std::endl
246  << "omega_dot_reg = " << omega_dot_reg[s] << std::endl;
247  return_flag = 1;
248  }
249  }
250 
251  return return_flag;
252 }
253 
254 
255 int main( int argc, char* argv[] )
256 {
257  // Check command line count.
258  if( argc < 2 )
259  {
260  // TODO: Need more consistent error handling.
261  std::cerr << "Error: Must specify input file." << std::endl;
262  exit(1);
263  }
264 
265  GetPot input( argv[1] );
266 
267  GRINS::AntiochMixture antioch_mixture(input);
268 
269  int return_flag = 0;
270 
271  std::cout << "Running AntiochCEAThermo regression test." << std::endl;
272  return_flag = test_evaluator<Antioch::CEAEvaluator<libMesh::Real> >( antioch_mixture );
273 
274  std::cout << std::endl << "Running AntiochStatMechThermo regression test." << std::endl;
275  return_flag = test_evaluator<Antioch::StatMechThermodynamics<libMesh::Real> >( antioch_mixture );
276 
277  return return_flag;
278 }
279 
280 #else //GRINS_HAVE_ANTIOCH
281 int main()
282 {
283  // automake expects 77 for a skipped test
284  return 77;
285 }
286 #endif
libMesh::Real cv(const CachedValues &cache, unsigned int qp)
Wrapper class for evaluating chemistry and thermo properties using Antioch.
libMesh::Real R_mix(const std::vector< libMesh::Real > &mass_fractions) const
Mixture gas constant, [J/kg-K].
void set_values(unsigned int quantity, std::vector< libMesh::Number > &values)
Definition: cached_values.C:72
int main(int argc, char *argv[])
libMesh::Real cp(const CachedValues &cache, unsigned int qp)
int test_generic(const libMesh::Real value, const libMesh::Real value_reg, const std::string &name)
int test_h_s(const libMesh::Real h_s)
void omega_dot(const CachedValues &cache, unsigned int qp, std::vector< libMesh::Real > &omega_dot)
libMesh::Real h_s(const CachedValues &cache, unsigned int qp, unsigned int species)
int test_cv(const libMesh::Real cv)
int test_cp(const libMesh::Real cp)
int test_evaluator(const GRINS::AntiochMixture &antioch_mixture)
Wrapper class for storing state for Antioch thermo and kinetics.
void add_quantity(unsigned int quantity)
Definition: cached_values.C:40
void set_vector_values(unsigned int quantity, std::vector< std::vector< libMesh::Number > > &values)
Definition: cached_values.C:93

Generated on Mon Jun 22 2015 21:32:20 for GRINS-0.6.0 by  doxygen 1.8.9.1