antioch-0.4.0
kinetics_unit.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 // $Id$
28 //
29 //--------------------------------------------------------------------------
30 //--------------------------------------------------------------------------
31 
32 // C++
33 #include <limits>
34 #include <string>
35 #include <vector>
36 
37 // Antioch
38 #include "antioch/vector_utils.h"
39 
43 #include "antioch/reaction_set.h"
45 #include "antioch/cea_thermo.h"
47 
48 template <typename Scalar>
49 int tester_N2N(const std::string& input_name)
50 {
51  using std::abs;
52 
53  std::vector<std::string> species_str_list;
54  const unsigned int n_species = 2;
55  species_str_list.reserve(n_species);
56  species_str_list.push_back( "N2" );
57  species_str_list.push_back( "N" );
58 
59  Antioch::ChemicalMixture<Scalar> chem_mixture( species_str_list );
60  Antioch::ReactionSet<Scalar> reaction_set( chem_mixture );
61  Antioch::CEAThermodynamics<Scalar> thermo( chem_mixture );
62 
63  Antioch::read_reaction_set_data_xml<Scalar>( input_name, false, reaction_set );
64 
65  Antioch::KineticsEvaluator<Scalar> kinetics( reaction_set, 0 );
66  std::vector<Scalar> omega_dot(n_species);
67 
68  const Scalar P = 1.0e5;
69 
70  // Mass fractions
71  std::vector<Scalar> Y(n_species,0.2);
72 
73  const Scalar R_mix = chem_mixture.R(Y);
74 
75  const unsigned int n_T_samples = 10;
76  const Scalar T0 = 500;
77  const Scalar T_inc = 500;
78 
79  std::vector<Scalar> molar_densities(n_species,0.0);
80  std::vector<Scalar> h_RT_minus_s_R(n_species);
81 
82  int return_flag = 0;
83 
84  for( unsigned int i = 0; i < n_T_samples; i++ )
85  {
86  const Scalar T = T0 + T_inc*static_cast<Scalar>(i);
87  const Scalar rho = P/(R_mix*T);
88  chem_mixture.molar_densities(rho,Y,molar_densities);
90 
91  typedef typename Antioch::CEAThermodynamics<Scalar>::template Cache<Scalar> Cache;
92 
93  thermo.h_RT_minus_s_R(Cache(T),h_RT_minus_s_R);
94 
95  if( i == 0 )
96  {
97  std::vector<std::vector<Scalar> > loss_matrix;
98  std::vector<std::vector<Scalar> > prod_matrix;
99  std::vector<std::vector<Scalar> > net_matrix;
100 
101  reaction_set.print_chemical_scheme( std::cout, cond, molar_densities, h_RT_minus_s_R, loss_matrix, prod_matrix, net_matrix );
102  }
103 
104  kinetics.compute_mass_sources( cond, molar_densities, h_RT_minus_s_R, omega_dot );
105 
106  // Omega dot had better sum to 0.0
107  Scalar sum = 0;
108  for( unsigned int s = 0; s < n_species; s++ )
109  {
110  sum += omega_dot[s];
111  }
112  const Scalar sum_tol = std::numeric_limits<Scalar>::epsilon() * 1.0e6; // 1.0e-10;
113  if( abs( sum ) > sum_tol )
114  {
115  return_flag = 1;
116  std::cerr << "Error: omega_dot did not sum to 0.0." << std::endl
117  << std::scientific << std::setprecision(16)
118  << "T = " << T << std::endl
119  << "sum = " << sum << ", sum_tol = " << sum_tol << std::endl;
120  for( unsigned int s = 0; s < n_species; s++ )
121  {
122  std::cerr << std::scientific << std::setprecision(16)
123  << "omega_dot(" << chem_mixture.chemical_species()[s]->species() << ") = "
124  << omega_dot[s] << std::endl;
125  }
126  std::cout << std::endl << std::endl;
127  }
128  }
129 
130  return return_flag;
131 }
132 
133 
134 template <typename Scalar>
135 int tester(const std::string& input_name)
136 {
137  using std::abs;
138 
139  std::vector<std::string> species_str_list;
140  const unsigned int n_species = 5;
141  species_str_list.reserve(n_species);
142  species_str_list.push_back( "N2" );
143  species_str_list.push_back( "O2" );
144  species_str_list.push_back( "N" );
145  species_str_list.push_back( "O" );
146  species_str_list.push_back( "NO" );
147 
148  Antioch::ChemicalMixture<Scalar> chem_mixture( species_str_list );
149  Antioch::ReactionSet<Scalar> reaction_set( chem_mixture );
150  Antioch::CEAThermodynamics<Scalar> thermo( chem_mixture );
151 
152  Antioch::read_reaction_set_data_xml<Scalar>( input_name, false, reaction_set );
153 
154  Antioch::KineticsEvaluator<Scalar> kinetics( reaction_set, 0 );
155  std::vector<Scalar> omega_dot(n_species);
156 
157  const Scalar P = 1.0e5;
158 
159  // Mass fractions
160  std::vector<Scalar> Y(n_species,0.2);
161 
162  const Scalar R_mix = chem_mixture.R(Y);
163 
164  const unsigned int n_T_samples = 10;
165  const Scalar T0 = 500;
166  const Scalar T_inc = 500;
167 
168  std::vector<Scalar> molar_densities(n_species,0.0);
169  std::vector<Scalar> h_RT_minus_s_R(n_species);
170 
171  int return_flag = 0;
172 
173  for( unsigned int i = 0; i < n_T_samples; i++ )
174  {
175  const Scalar T = T0 + T_inc*static_cast<Scalar>(i);
176  const Scalar rho = P/(R_mix*T);
177  chem_mixture.molar_densities(rho,Y,molar_densities);
179 
180  typedef typename Antioch::CEAThermodynamics<Scalar>::template Cache<Scalar> Cache;
181 
182  thermo.h_RT_minus_s_R(Cache(T),h_RT_minus_s_R);
183 
184  kinetics.compute_mass_sources( cond, molar_densities, h_RT_minus_s_R, omega_dot );
185 
186  // Omega dot had better sum to 0.0
187  Scalar sum = 0;
188  for( unsigned int s = 0; s < n_species; s++ )
189  {
190  sum += omega_dot[s];
191  }
192  // [PB]: Need to raise the tol scaling to 5.0e6 for my Mac laptop.
193  const Scalar sum_tol = std::numeric_limits<Scalar>::epsilon() * 5.0e6; // 1.6e-10;
194  if( abs( sum ) > sum_tol )
195  {
196  return_flag = 1;
197  std::cerr << "Error: omega_dot did not sum to 0.0." << std::endl
198  << std::scientific << std::setprecision(16)
199  << "T = " << T << std::endl
200  << "sum = " << sum << ", sum_tol = " << sum_tol << std::endl;
201  for( unsigned int s = 0; s < n_species; s++ )
202  {
203  std::cerr << std::scientific << std::setprecision(16)
204  << "omega_dot(" << chem_mixture.chemical_species()[s]->species() << ") = "
205  << omega_dot[s] << std::endl;
206  }
207  std::cout << std::endl << std::endl;
208  }
209  }
210 
211  return return_flag;
212 }
213 
214 
215 int main(int argc, char* argv[])
216 {
217  // Check command line count.
218  if( argc < 2 )
219  {
220  // TODO: Need more consistent error handling.
221  std::cerr << "Error: Must specify reaction set XML input file." << std::endl;
222  antioch_error();
223  }
224 
225  int return_flag=0;
226 
227  return_flag += (tester<double>(std::string(argv[1])) ||
228  tester<long double>(std::string(argv[1])) ||
229  tester<float>(std::string(argv[1])));
230 
231  return_flag += (tester_N2N<double>(std::string(argv[1])) ||
232  tester_N2N<long double>(std::string(argv[1])) ||
233  tester_N2N<float>(std::string(argv[1])));
234 
235  return return_flag;
236 }
237 
void print_chemical_scheme(std::ostream &output, const KineticsConditions< StateType, VectorStateType > &conditions, const VectorStateType &molar_densities, const VectorStateType &h_RT_minus_s_R, std::vector< VectorStateType > &lossMatrix, std::vector< VectorStateType > &prodMatrix, std::vector< VectorStateType > &netMatrix) const
Definition: reaction_set.h:556
This class encapsulates all the reaction mechanisms considered in a chemical nonequilibrium simulatio...
CoeffType R(const unsigned int s) const
Gas constant for species s in [J/kg-K].
#define antioch_error()
int tester_N2N(const std::string &input_name)
Definition: kinetics_unit.C:49
Class to handle computing mass source terms for a given ReactionSet.
X(const unsigned int species, const StateType &M, const StateType &mass_fraction) const template< typename VectorStateType > void X(typename Antioch VectorStateType void molar_densities(const StateType &rho, const VectorStateType &mass_fractions, VectorStateType &molar_densities) const
int main(int argc, char *argv[])
Class storing chemical mixture properties.
StateType h_RT_minus_s_R(const Cache< StateType > &cache, unsigned int species) const
We currently need different specializations for scalar vs vector inputs here.
Definition: cea_thermo.h:420
const std::vector< ChemicalSpecies< CoeffType > * > & chemical_species() const
int tester(const std::string &input_name)
This class contains the conditions of the chemistry.
We parse the file here, with an exhaustive unit management.

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