antioch-0.4.0
Functions
kinetics_unit.C File Reference
#include <limits>
#include <string>
#include <vector>
#include "antioch/vector_utils.h"
#include "antioch/antioch_asserts.h"
#include "antioch/chemical_species.h"
#include "antioch/chemical_mixture.h"
#include "antioch/reaction_set.h"
#include "antioch/read_reaction_set_data.h"
#include "antioch/cea_thermo.h"
#include "antioch/kinetics_evaluator.h"

Go to the source code of this file.

Functions

template<typename Scalar >
int tester_N2N (const std::string &input_name)
 
template<typename Scalar >
int tester (const std::string &input_name)
 
int main (int argc, char *argv[])
 

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 215 of file kinetics_unit.C.

References antioch_error.

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 }
#define antioch_error()
template<typename Scalar >
int tester ( const std::string &  input_name)

Definition at line 135 of file kinetics_unit.C.

References Antioch::ChemicalMixture< CoeffType >::chemical_species(), Antioch::CEAThermodynamics< CoeffType >::h_RT_minus_s_R(), Antioch::ChemicalMixture< CoeffType >::molar_densities, and Antioch::ChemicalMixture< CoeffType >::R().

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 }
This class encapsulates all the reaction mechanisms considered in a chemical nonequilibrium simulatio...
Class to handle computing mass source terms for a given ReactionSet.
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
This class contains the conditions of the chemistry.
template<typename Scalar >
int tester_N2N ( const std::string &  input_name)

Definition at line 49 of file kinetics_unit.C.

References Antioch::ChemicalMixture< CoeffType >::chemical_species(), Antioch::CEAThermodynamics< CoeffType >::h_RT_minus_s_R(), Antioch::ChemicalMixture< CoeffType >::molar_densities, Antioch::ReactionSet< CoeffType >::print_chemical_scheme(), and Antioch::ChemicalMixture< CoeffType >::R().

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 }
This class encapsulates all the reaction mechanisms considered in a chemical nonequilibrium simulatio...
Class to handle computing mass source terms for a given ReactionSet.
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
This class contains the conditions of the chemistry.

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