GRINS-0.8.0
kinetics_test_base.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // GRINS - General Reacting Incompressible Navier-Stokes
5 //
6 // Copyright (C) 2014-2017 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 #ifndef GRINS_KINETICS_TEST_BASE_H
26 #define GRINS_KINETICS_TEST_BASE_H
27 
28 #include "grins_config.h"
29 
30 #ifdef GRINS_HAVE_CPPUNIT
31 
32 #include <cppunit/extensions/HelperMacros.h>
33 
34 #include "species_test_base.h"
35 #include "thermochem_test_common.h"
36 #include "testing_utils.h"
37 
38 #include "libmesh/libmesh_common.h"
39 
40 namespace GRINSTesting
41 {
43  {
44  public:
45 
46  template<typename ThermoMixture, typename ThermoEvaluator>
47  void test_omega_dot_common( ThermoMixture& mixture, NASAThermoTestBase& thermo_funcs,
48  const std::vector<libMesh::Real>& Y, libMesh::Real rel_tol )
49  {
50  CPPUNIT_ASSERT_EQUAL(_active_species.size(), Y.size() );
51 
52  ThermoEvaluator evaluator( mixture );
53 
54  libMesh::Real rho = 1.0e-3;
55 
56  std::vector<libMesh::Real> molar_densities(_active_species.size(),0.0);
57  for( unsigned int s = 0; s < _active_species.size(); s++ )
58  molar_densities[s] = rho*Y[s]/this->molar_mass(s);
59 
60  libMesh::Real T = 300;
61  while( T <= 1000 )
62  {
63  std::vector<libMesh::Real> forward_rates, backward_rates;
64  this->compute_reaction_rates( T, molar_densities, thermo_funcs, forward_rates, backward_rates );
65 
66  std::vector<libMesh::Real> omega_dot_exact(_active_species.size(), 0.0);
67  std::vector<libMesh::Real> omega_dot_computed(_active_species.size());
68 
69  evaluator.omega_dot( T, rho, Y, omega_dot_computed );
70 
71  for( unsigned int s = 0; s < _active_species.size(); s++ )
72  for( unsigned int r = 0; r < _n_reactions; r++ )
73  {
74  unsigned int species = _active_species[s];
75  libMesh::Real stoich = _product_stoich_coeffs[r][species] - _reactant_stoich_coeffs[r][species];
76 
77  omega_dot_exact[s] += this->molar_mass(species)*stoich*( forward_rates[r] - backward_rates[r] );
78  }
79 
80  for( unsigned int s = 0; s < _active_species.size(); s++ )
81  {
82  unsigned int species = _active_species[s];
83 
84  std::stringstream ss;
85  ss << T;
86  std::string message = "T = "+ss.str();
87 
88  ss.str(std::string());
89  ss << s;
90  message += ", species = "+mixture.species_name(species);
91 
92  /*
93  std::cout << message
94  << ", omega_dot_exact = " << omega_dot_exact[s]
95  << ", omega_dot_computed = " << omega_dot_computed[s]
96  << std::endl;
97  */
98 
99  libMesh::Real tol = TestingUtils::abs_tol_from_rel_tol( omega_dot_exact[s], rel_tol );
100  CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( message,
101  omega_dot_exact[s],
102  omega_dot_computed[s],
103  tol );
104  }
105 
106  T += 100.0;
107  }
108  }
109 
110  protected:
111 
112  unsigned int _n_reactions;
113 
114  std::vector<libMesh::Real> _Ea_coeffs;
115  std::vector<libMesh::Real> _preexp_coeffs;
116  std::vector<libMesh::Real> _temp_exp_coeffs;
117 
118  std::vector<std::vector<libMesh::Real> > _three_body_coeffs;
119  std::vector<bool> _is_three_body_rxn;
120 
121  std::vector<std::vector<libMesh::Real> > _reactant_stoich_coeffs;
122  std::vector<std::vector<libMesh::Real> > _product_stoich_coeffs;
123 
124  private:
125 
126  void compute_reaction_rates( libMesh::Real T,
127  const std::vector<libMesh::Real>& molar_densities,
128  NASAThermoTestBase& thermo_funcs,
129  std::vector<libMesh::Real>& forward_rates,
130  std::vector<libMesh::Real>& backward_rates )
131  {
132  forward_rates.resize(_n_reactions,1.0);
133  backward_rates.resize(_n_reactions,1.0);
134 
135  for( unsigned int r = 0; r < _n_reactions; r++ )
136  {
137  libMesh::Real fwd_rate_coeff = ThermochemTestCommon::arrhenius_rate( _preexp_coeffs[r],
138  _temp_exp_coeffs[r],
139  _Ea_coeffs[r],
140  T );
141 
142  libMesh::Real Keq = this->eq_constant(T,
143  _reactant_stoich_coeffs[r],
144  _product_stoich_coeffs[r],
145  thermo_funcs);
146 
147  libMesh::Real bkwd_rate_coeff = fwd_rate_coeff/Keq;
148 
149  forward_rates[r] *= fwd_rate_coeff;
150  backward_rates[r] *= bkwd_rate_coeff;
151 
152  for( unsigned int s = 0; s < _active_species.size(); s++ )
153  {
154  forward_rates[r] *= std::pow(molar_densities[s],_reactant_stoich_coeffs[r][s]);
155 
156  backward_rates[r] *= std::pow(molar_densities[s],_product_stoich_coeffs[r][s]);
157  }
158 
159  if( _is_three_body_rxn[r] )
160  {
161  libMesh::Real M = ThermochemTestCommon::compute_third_body_molar_density( molar_densities,
162  _three_body_coeffs[r] );
163  forward_rates[r] *= M;
164  backward_rates[r] *= M;
165  }
166  }
167  }
168 
169  libMesh::Real eq_constant( libMesh::Real T,
170  std::vector<libMesh::Real>& reactant_stoich_coeffs,
171  std::vector<libMesh::Real>& product_stoich_coeffs,
172  NASAThermoTestBase& thermo_funcs )
173  {
174  CPPUNIT_ASSERT_EQUAL( reactant_stoich_coeffs.size(), product_stoich_coeffs.size() );
175 
176  libMesh::Real coeff_sum = 0.0;
177  libMesh::Real exp_sum = 0.0;
178 
179  for( unsigned int s = 0; s < reactant_stoich_coeffs.size(); s++ )
180  {
181  libMesh::Real stoich = (product_stoich_coeffs[s] - reactant_stoich_coeffs[s]);
182 
183  coeff_sum += stoich;
184  exp_sum += stoich*( thermo_funcs.h_RT_exact(s,T) - thermo_funcs.s_R_exact(s,T) );
185  }
186 
187  libMesh::Real P_RT = 1e5/(GRINS::Constants::R_universal*T);
188 
189  return std::pow(P_RT,coeff_sum)*std::exp(-exp_sum);
190  }
191 
192  };
193 
194 } // namespace GRINSTesting
195 
196 #endif // GRINS_HAVE_CPPUNIT
197 
198 #endif // GRINS_KINETICS_TEST_BASE_H
libMesh::Real eq_constant(libMesh::Real T, std::vector< libMesh::Real > &reactant_stoich_coeffs, std::vector< libMesh::Real > &product_stoich_coeffs, NASAThermoTestBase &thermo_funcs)
virtual libMesh::Real s_R_exact(unsigned int species_idx, libMesh::Real T)=0
std::vector< std::vector< libMesh::Real > > _product_stoich_coeffs
const libMesh::Real R_universal
Universal Gas Constant, R, [J/(kmol-K)].
std::vector< libMesh::Real > _temp_exp_coeffs
libMesh::Real molar_mass(unsigned int idx)
static libMesh::Real compute_third_body_molar_density(const std::vector< libMesh::Real > &molar_densities, const std::vector< libMesh::Real > &three_body_efficiencies)
void test_omega_dot_common(ThermoMixture &mixture, NASAThermoTestBase &thermo_funcs, const std::vector< libMesh::Real > &Y, libMesh::Real rel_tol)
static libMesh::Real arrhenius_rate(libMesh::Real A, libMesh::Real b, libMesh::Real Ea, libMesh::Real T)
std::vector< libMesh::Real > _preexp_coeffs
std::vector< std::vector< libMesh::Real > > _three_body_coeffs
static libMesh::Real abs_tol_from_rel_tol(libMesh::Real exact, libMesh::Real rel_tol)
Get absolute tolerance from input relative tol.
Definition: testing_utils.h:44
std::vector< std::vector< libMesh::Real > > _reactant_stoich_coeffs
virtual libMesh::Real h_RT_exact(unsigned int species_idx, libMesh::Real T)=0
std::vector< unsigned int > _active_species
std::vector< bool > _is_three_body_rxn
void compute_reaction_rates(libMesh::Real T, const std::vector< libMesh::Real > &molar_densities, NASAThermoTestBase &thermo_funcs, std::vector< libMesh::Real > &forward_rates, std::vector< libMesh::Real > &backward_rates)
std::vector< libMesh::Real > _Ea_coeffs

Generated on Tue Dec 19 2017 12:47:29 for GRINS-0.8.0 by  doxygen 1.8.9.1