antioch-0.4.0
chemkin_parser.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 #ifndef ANTIOCH_CHEMKIN_PARSER_H
27 #define ANTIOCH_CHEMKIN_PARSER_H
28 
29 //Antioch
31 #include "antioch/string_utils.h"
32 #include "antioch/parser_base.h"
33 #include "antioch/parsing_enum.h"
34 #include "antioch/units.h"
36 
37 //C++
38 #include <fstream>
39 #include <string>
40 #include <vector>
41 #include <map>
42 
43 namespace Antioch{
44 
45 
46  template <typename NumericType>
47  class ChemicalMixture;
48 
49  template <typename NumericType, typename CurveType>
50  class NASAThermoMixture;
51 
52  template <typename NumericType>
53  class NASA7CurveFit;
54 
55  template <typename NumericType>
56  class NASA9CurveFit;
57 
58  // backward compatibility
59  template <typename NumericType>
60  class CEACurveFit;
61 
78  template <typename NumericType = double>
79  class ChemKinParser: public ParserBase<NumericType>
80  {
81  public:
82  ChemKinParser(const std::string &filename, bool verbose = true);
84 
85  void change_file(const std::string & filename);
86 
88 
90  const std::vector<std::string> species_list();
91 
92  // reads the mandatory data, not valid yet in ChemKin
93 // void read_chemical_species(ChemicalMixture<NumericType> & chem_mixture);
94 
95  // reads the vibrational data, not valid yet in ChemKin
96 // void read_vibrational_data(ChemicalMixture<NumericType> & chem_mixture);
97 
98  // reads the electronic data, not valid yet in ChemKin
99 // void read_electronic_data(ChemicalMixture<NumericType> & chem_mixture);
100 
102 
103 //global overload
104 // it seems that they're all linked in
105 // a way so they shadow themselves
106 // => we need to implement all or nothing
107 
110  {this->read_thermodynamic_data_root(thermo);}
111 
114  {antioch_error_msg("ERROR: ChemKin Parsing only supports parsing for NASA7CurveFit!");}
115 
118  {antioch_error_msg("ERROR: ChemKin Parsing only supports parsing for NASA7CurveFit!");}
119 
122  {antioch_error_msg("ERROR: ChemKin Parsing only supports parsing for NASA7CurveFit!");}
123 
125 
127  bool initialize();
128 
130  bool reaction();
131 
133  bool rate_constant(const std::string & /* kinetics_model */);
134 
136  bool Troe() const;
137 
139  const std::string reaction_id() const;
140 
142  const std::string reaction_equation() const;
143 
145  const std::string reaction_chemical_process() const;
146 
148  const std::string reaction_kinetics_model(const std::vector<std::string> & /*kinetics_models*/) const;
149 
151  bool reaction_reversible() const;
152 
154  bool reactants_pairs(std::vector<std::pair<std::string,int> > & reactants_pair) const;
155 
157  bool products_pairs(std::vector<std::pair<std::string,int> > & products_pair) const;
158 
160  const std::map<std::string,NumericType> reactants_orders() const;
161 
163  const std::map<std::string,NumericType> products_orders() const;
164 
166  bool is_k0(unsigned int nrc, const std::string & kin_model) const;
167 
169  unsigned int where_is_k0(const std::string & /*kin_model*/) const;
170 
172  bool rate_constant_preexponential_parameter( NumericType & A, std::string & A_unit, std::string & def_unit) const;
173 
175  bool rate_constant_power_parameter( NumericType & b, std::string & b_unit, std::string & def_unit) const;
176 
178  bool rate_constant_activation_energy_parameter(NumericType & Ea, std::string & Ea_unit, std::string & def_unit) const;
179 
181  bool rate_constant_Berthelot_coefficient_parameter(NumericType & D, std::string & D_unit, std::string & def_unit) const;
182 
184  bool rate_constant_Tref_parameter( NumericType & Tref, std::string & Tref_unit, std::string & def_unit) const;
185 
187  bool rate_constant_lambda_parameter( std::vector<NumericType> & lambda, std::string & lambda_unit, std::string & def_unit) const;
188 
190  bool rate_constant_cross_section_parameter(std::vector<NumericType> & sigma, std::string & sigma_unit, std::string & def_unit) const;
191 
194 
196  bool efficiencies(std::vector<std::pair<std::string,NumericType> > & par_values) const;
197 
199  bool Troe_alpha_parameter(NumericType & alpha, std::string & alpha_unit, std::string & def_unit) const;
200 
202  bool Troe_T1_parameter( NumericType & T1, std::string & T1_unit, std::string & def_unit) const;
203 
205  bool Troe_T2_parameter( NumericType & T2, std::string & T2_unit, std::string & def_unit) const;
206 
208  bool Troe_T3_parameter( NumericType & T3, std::string & T3_unit, std::string & def_unit) const;
209 
210  private:
211 
213  template <typename CurveType>
215 
217  void parse_a_line(const std::string & line);
218 
220  void parse_equation_coef(const std::string & line);
221 
223  void parse_reversible_parameters(const std::string & line);
224 
226  void parse_equation(std::string &equation);
227 
229  void parse_coefficients_line(const std::string &line);
230 
232  void parse_forward_orders(const std::string & line);
233 
235  void parse_backward_orders(const std::string & line);
236 
238  void parse_orders(const std::string & line, std::vector<std::pair<std::string, NumericType> > & reaction_orders);
239 
241  std::pair<std::string,NumericType> parse_molecule(const std::string & molecule);
242 
244  bool is_real_number(const char & c) const;
245 
247  void rescale_stoichiometry();
248 
250  bool after_coma_digits(NumericType number) const;
251 
253  unsigned int factor_to_int(NumericType number) const;
254 
256  bool next_reaction(const std::string & line);
257 
259  bool next_meaningful_line(std::string & line);
260 
262  ChemKinParser();
263  std::ifstream _doc;
264 
265 
267  unsigned int _nrates; // total number of rates
268  unsigned int _crates; // current place
269 
270  unsigned int _pow_unit; // for A unit
271 
272  // ChemKin allows real stoichiometric coefficients
273  std::vector<std::pair<std::string,NumericType> > _reactants;
274  std::vector<std::pair<std::string,NumericType> > _products;
275 
276  std::vector<std::pair<std::string,NumericType> > _reactants_orders;
277  std::vector<std::pair<std::string,NumericType> > _products_orders;
278 
279  std::string _equation;
280  std::string _chemical_process;
281  std::string _kinetics_model;
282 
283  std::vector<NumericType> _A;
284  std::vector<NumericType> _b;
285  std::vector<NumericType> _Ea;
286  std::vector<NumericType> _D; // ChemKin don't use it, but whatever, let's generalize, just in case
287 
288  std::vector<std::pair<std::string,NumericType> > _efficiencies;
289 
290  NumericType _Tref; // ChemKin don't use it, but whatever, let's generalize, just in case
291  NumericType _Troe_alpha;
292  NumericType _Troe_T1;
293  NumericType _Troe_T2;
294  NumericType _Troe_T3;
295 
296  std::map<ParsingKey,std::string> _map;
297  std::map<ParsingKey,std::string> _default_unit;
298 
299  std::map<std::string,std::string> _unit_custom_ea;
300  std::map<std::string,std::string> _unit_custom_A;
301 
302  std::string _cached_line;
305 
307 
308  };
309 
310  template <typename NumericType>
311  inline
313  {
314  return (_chemical_process.find("TroeFalloff") != std::string::npos);
315  }
316 
317  template <typename NumericType>
318  inline
319  const std::string ChemKinParser<NumericType>::reaction_id() const
320  {
321  return _equation;
322  }
323 
324  template <typename NumericType>
325  inline
327  {
328  return _equation;
329  }
330 
331  template <typename NumericType>
332  inline
334  {
335  return _chemical_process;
336  }
337 
338  template <typename NumericType>
339  inline
341  {
342  return _reversible;
343  }
344 
345  template <typename NumericType>
346  inline
347  const std::string ChemKinParser<NumericType>::reaction_kinetics_model(const std::vector<std::string> & /*kinetics_models*/) const
348  {
349  return _kinetics_model;
350  }
351 
352  template <typename NumericType>
353  inline
354  bool ChemKinParser<NumericType>::is_k0(unsigned int nrc, const std::string & /*kin_model*/) const
355  {
356  // k0 is always the first, explicit in ChemKin
357  return (nrc == 0);
358  }
359 
360  template <typename NumericType>
361  inline
362  unsigned int ChemKinParser<NumericType>::where_is_k0(const std::string & /*kin_model*/) const
363  {
364  return 0;
365  }
366 
367  template <typename NumericType>
368  inline
369  bool ChemKinParser<NumericType>::rate_constant_Berthelot_coefficient_parameter(NumericType & /*D*/, std::string & /*D_unit*/, std::string & /*def_unit*/) const
370  {
371  return false; //not a chemkin model
372  }
373 
374  template <typename NumericType>
375  inline
376  bool ChemKinParser<NumericType>::rate_constant_lambda_parameter(std::vector<NumericType> & /*lambda*/, std::string & /*lambda_unit*/, std::string & /*def_unit*/) const
377  {
378  return false; //not a supported chemkin model yet
379  }
380 
381  template <typename NumericType>
382  inline
383  bool ChemKinParser<NumericType>::rate_constant_cross_section_parameter(std::vector<NumericType> & /*sigma*/, std::string & /*sigma_unit*/, std::string & /*def_unit*/) const
384  {
385  return false; //not a supported chemkin model yet
386  }
387 
388  template <typename NumericType>
389  inline
391  {
392  return false;
393  }
394 
395 }//end namespace Antioch
396 
397 #endif
bool rate_constant_preexponential_parameter(NumericType &A, std::string &A_unit, std::string &def_unit) const
return true if pre exponentiel coefficient
bool rate_constant_lambda_parameter(std::vector< NumericType > &lambda, std::string &lambda_unit, std::string &def_unit) const
return true if lambda
bool after_coma_digits(NumericType number) const
check if the stoichiometric coef is an integer
const std::string reaction_kinetics_model(const std::vector< std::string > &) const
return reaction kinetics model
void parse_orders(const std::string &line, std::vector< std::pair< std::string, NumericType > > &reaction_orders)
Convenient method.
bool rate_constant_Tref_parameter(NumericType &Tref, std::string &Tref_unit, std::string &def_unit) const
return true if Tref
bool rate_constant_cross_section_parameter(std::vector< NumericType > &sigma, std::string &sigma_unit, std::string &def_unit) const
return true if sigma
void rescale_stoichiometry()
if stoichiometry is real, make them integer
std::vector< std::pair< std::string, NumericType > > _efficiencies
unsigned int factor_to_int(NumericType number) const
look for q when given r = p / q
std::vector< NumericType > _b
void parse_equation_coef(const std::string &line)
Convenient method.
std::string _chemical_process
std::map< ParsingKey, std::string > _map
bool rate_constant_power_parameter(NumericType &b, std::string &b_unit, std::string &def_unit) const
return true if beta coefficient
const std::string reaction_id() const
return reaction id, 0 if not provided
void read_thermodynamic_data(NASAThermoMixture< NumericType, NASA7CurveFit< NumericType > > &thermo)
reads the thermo, NASA generalist, no templates for virtual
void read_thermodynamic_data_root(NASAThermoMixture< NumericType, CurveType > &thermo)
reads the thermo, NASA generalist
bool Troe_alpha_parameter(NumericType &alpha, std::string &alpha_unit, std::string &def_unit) const
return true is alpha
bool is_k0(unsigned int nrc, const std::string &kin_model) const
return true if "name" attribute is found with value "k0"
const ChemKinDefinitions _spec
std::vector< NumericType > _D
const std::string reaction_chemical_process() const
return reaction chemical process
bool rate_constant_activation_energy_parameter(NumericType &Ea, std::string &Ea_unit, std::string &def_unit) const
return true if activation energie
std::vector< NumericType > _Ea
bool products_pairs(std::vector< std::pair< std::string, int > > &products_pair) const
return pairs of products and stoichiometric coefficients
void parse_forward_orders(const std::string &line)
Convenient method.
bool next_reaction(const std::string &line)
verify if line is a new reaction
bool initialize()
Read header of file, go to interesting part.
void read_thermodynamic_data(CEAThermodynamics< NumericType > &)
reads the thermo, CEA deprecated
const std::map< std::string, NumericType > reactants_orders() const
return a map between reactants' name and found partial orders
bool Troe_T3_parameter(NumericType &T3, std::string &T3_unit, std::string &def_unit) const
return true is alpha
bool reaction()
go to next reaction
This class stores the NASA polynomial fit to the thermodynamics quantities and .
Definition: ascii_parser.h:68
#define antioch_error_msg(errmsg)
bool reactants_pairs(std::vector< std::pair< std::string, int > > &reactants_pair) const
return pairs of reactants and stoichiometric coefficients
bool Troe_T2_parameter(NumericType &T2, std::string &T2_unit, std::string &def_unit) const
return true is alpha
This class only differs from NASA9CurveFit in the construction.
Definition: ascii_parser.h:72
void read_thermodynamic_data(NASAThermoMixture< NumericType, NASA9CurveFit< NumericType > > &)
reads the thermo, NASA generalist, no templates for virtual
void parse_equation(std::string &equation)
Convenient method.
std::map< ParsingKey, std::string > _default_unit
bool reaction_reversible() const
return reversible state
bool verbose() const
Definition: parser_base.h:248
void read_thermodynamic_data(NASAThermoMixture< NumericType, CEACurveFit< NumericType > > &)
reads the thermo, NASA generalist, no templates for virtual
ChemKinParser()
Never use default constructor.
bool next_meaningful_line(std::string &line)
finding next line that might be a reaction
std::map< std::string, std::string > _unit_custom_ea
bool rate_constant_Berthelot_coefficient_parameter(NumericType &D, std::string &D_unit, std::string &def_unit) const
return true if D coefficient
Advanced unit class.
bool verify_Kooij_in_place_of_Arrhenius() const
return true if a Kooij is called Arrhenuis
void parse_reversible_parameters(const std::string &line)
Convenient method.
const std::vector< std::string > species_list()
read SPECIES block
std::vector< std::pair< std::string, NumericType > > _reactants
std::vector< std::pair< std::string, NumericType > > _products_orders
const std::string reaction_equation() const
return reaction equation
bool Troe_T1_parameter(NumericType &T1, std::string &T1_unit, std::string &def_unit) const
return true is alpha
bool Troe() const
return true if there's a Troe block
void parse_coefficients_line(const std::string &line)
Convenient method.
const std::map< std::string, NumericType > products_orders() const
return a map between products' name and found partial orders
void change_file(const std::string &filename)
std::vector< std::pair< std::string, NumericType > > _reactants_orders
The parameters are reduced parameters.
std::vector< std::pair< std::string, NumericType > > _products
bool efficiencies(std::vector< std::pair< std::string, NumericType > > &par_values) const
return true if efficiencies are found
std::map< std::string, std::string > _unit_custom_A
unsigned int where_is_k0(const std::string &) const
return index of k0 (0 or 1)
std::pair< std::string, NumericType > parse_molecule(const std::string &molecule)
Convenient method.
A parser is an instance related to a file.
std::vector< NumericType > _A
void parse_backward_orders(const std::string &line)
Convenient method.
bool is_real_number(const char &c) const
Convenient method.
void parse_a_line(const std::string &line)
Convenient method.
ChemKin format file reader.
bool rate_constant(const std::string &)
go to next rate constant

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