antioch-0.4.0
xml_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_XML_PARSER_H
27 #define ANTIOCH_XML_PARSER_H
28 
29 //Antioch
31 #include "antioch/string_utils.h"
32 #include "antioch/parser_base.h"
33 #include "antioch/parsing_enum.h"
34 
35 //C++
36 #include <string>
37 #include <vector>
38 #include <map>
39 
40 namespace tinyxml2
41 {
42  class XMLDocument;
43  class XMLElement;
44 }
45 
46 namespace Antioch{
47 
48 
49  template <typename CoeffType>
50  class ChemicalMixture;
51 
52  template <typename NumericType, typename CurveType>
53  class NASAThermoMixture;
54 
55  template <typename NumericType>
56  class NASA7CurveFit;
57 
58  template <typename NumericType>
59  class NASA9CurveFit;
60 
61  // backward compatibility
62  template <typename NumericType>
63  class CEACurveFit;
64 
78  template <typename NumericType = double>
79  class XMLParser: public ParserBase<NumericType>
80  {
81  public:
82  XMLParser(const std::string &filename, bool verbose = true);
83  ~XMLParser();
84 
85  void change_file(const std::string & filename);
86 
88 
89  bool initialize();
90 
93  const std::vector<std::string> species_list() ;
94 
97  {this->read_thermodynamic_data_root(thermo);}
98 
101  {this->read_thermodynamic_data_root(thermo);}
102 
105  {antioch_error_msg("ERROR: XML Parsing only supports parsing for NASA7CurveFit and NASA9CurveFit!");}
106 
109  {antioch_error_msg("ERROR: XML Parsing only supports parsing for NASA7CurveFit and NASA9CurveFit!");}
110 
112 
114  bool reaction();
115 
117  bool rate_constant(const std::string & kinetics_model);
118 
120  bool Troe() const;
121 
123  const std::string reaction_id() const;
124 
126  const std::string reaction_equation() const;
127 
129  const std::string reaction_chemical_process() const;
130 
132  const std::string reaction_kinetics_model(const std::vector<std::string> &kinetics_models) const;
133 
135  bool reaction_reversible() const;
136 
138  bool reactants_pairs(std::vector<std::pair<std::string,int> > & reactants_pair) const;
139 
141  bool products_pairs(std::vector<std::pair<std::string,int> > & products_pair) const;
142 
144  const std::map<std::string,NumericType> reactants_orders() const;
145 
147  const std::map<std::string,NumericType> products_orders() const;
148 
159  bool is_k0(unsigned int nrc, const std::string & kin_model) const;
160 
162  unsigned int where_is_k0(const std::string & kin_model) const;
163 
165  bool rate_constant_preexponential_parameter( NumericType & A, std::string & A_unit, std::string & def_unit) const;
166 
168  bool rate_constant_power_parameter( NumericType & b, std::string & b_unit, std::string & def_unit) const;
169 
171  bool rate_constant_activation_energy_parameter(NumericType & Ea, std::string & Ea_unit, std::string & def_unit) const;
172 
174  bool rate_constant_Berthelot_coefficient_parameter(NumericType & D, std::string & D_unit, std::string & def_unit) const;
175 
177  bool rate_constant_Tref_parameter( NumericType & Tref, std::string & Tref_unit, std::string & def_unit) const;
178 
180  bool rate_constant_lambda_parameter( std::vector<NumericType> & lambda, std::string & lambda_unit, std::string & def_unit) const;
181 
183  bool rate_constant_cross_section_parameter(std::vector<NumericType> & sigma, std::string & sigma_unit, std::string & def_unit) const;
184 
187 
189  bool efficiencies(std::vector<std::pair<std::string,NumericType> > & par_values) const;
190 
192  bool Troe_alpha_parameter(NumericType & alpha, std::string & alpha_unit, std::string & def_unit) const;
193 
195  bool Troe_T1_parameter( NumericType & T1, std::string & T1_unit, std::string & def_unit) const;
196 
198  bool Troe_T2_parameter( NumericType & T2, std::string & T2_unit, std::string & def_unit) const;
199 
201  bool Troe_T3_parameter( NumericType & T3, std::string & T3_unit, std::string & def_unit) const;
202 
203  private:
204 
206  template <typename ThermoType>
207  void read_thermodynamic_data_root(ThermoType & thermo);
208 
210  template <typename PairedType>
211  bool molecules_pairs(tinyxml2::XMLElement * molecules, std::vector<std::pair<std::string,PairedType> > & products_pair) const;
212 
214  bool get_parameter(const tinyxml2::XMLElement * ptr, const std::string & par, NumericType & par_value, std::string & par_unit) const;
215 
217  bool get_parameter(const tinyxml2::XMLElement * ptr, const std::string & par, std::vector<NumericType> & numpar, std::string & par_unit) const;
218 
220  const std::string unit(tinyxml2::XMLElement * parameter) const;
221 
225  const std::string& elem_name,
226  const std::string& attribute,
227  const std::string& attr_value ) const;
228 
230  std::string nasa_xml_section( NASAThermoMixture<NumericType, NASA7CurveFit<NumericType> >& /*thermo*/ )
231  { return _map.at(ParsingKey::NASA7); }
232 
234  std::string nasa_xml_section( NASAThermoMixture<NumericType, NASA9CurveFit<NumericType> >& /*thermo*/ )
235  { return _map.at(ParsingKey::NASA9); }
236 
238  std::string nasa_xml_section( NASAThermoMixture<NumericType, CEACurveFit<NumericType> >& /*thermo*/ )
239  { antioch_error_msg("ERROR: Only supported for NASA7CurveFit and NASA9CurveFit!"); return "";}
240 
243  { antioch_error_msg("ERROR: Only supported for NASA7CurveFit and NASA9CurveFit!"); return "";}
244 
245 
246 
248  XMLParser();
250 
251 //
256 
259 
260  std::map<ParsingKey,std::string> _map;
261  std::map<ParsingKey,std::string> _default_unit;
262 
263  };
264 
265 }//end namespace Antioch
266 
267 #endif
bool rate_constant_power_parameter(NumericType &b, std::string &b_unit, std::string &def_unit) const
return true if beta coefficient
Definition: xml_parser.C:562
const std::string reaction_id() const
return reaction id, 0 if not provided
Definition: xml_parser.C:265
tinyxml2::XMLElement * _rate_constant
Definition: xml_parser.h:257
void read_thermodynamic_data(NASAThermoMixture< NumericType, CEACurveFit< NumericType > > &)
reads the thermo, NASA generalist, no templates for virtual
Definition: xml_parser.h:104
bool rate_constant_Tref_parameter(NumericType &Tref, std::string &Tref_unit, std::string &def_unit) const
return true if Tref
Definition: xml_parser.C:597
bool initialize()
Read header of file, go to interesting part.
Definition: xml_parser.C:175
bool verify_Kooij_in_place_of_Arrhenius() const
return true if a Kooij is called Arrhenuis
Definition: xml_parser.C:604
bool Troe_T2_parameter(NumericType &T2, std::string &T2_unit, std::string &def_unit) const
return true is alpha
Definition: xml_parser.C:660
void read_thermodynamic_data(NASAThermoMixture< NumericType, NASA7CurveFit< NumericType > > &thermo)
reads the thermo, NASA generalist, no templates for virtual
Definition: xml_parser.h:96
const std::map< std::string, NumericType > reactants_orders() const
return a map between reactants' name and found partial orders
Definition: xml_parser.C:338
tinyxml2::XMLElement * _reaction_block
Definition: xml_parser.h:254
std::map< ParsingKey, std::string > _default_unit
Definition: xml_parser.h:261
void change_file(const std::string &filename)
Definition: xml_parser.C:148
bool Troe_alpha_parameter(NumericType &alpha, std::string &alpha_unit, std::string &def_unit) const
return true is alpha
Definition: xml_parser.C:646
void read_thermodynamic_data(CEAThermodynamics< NumericType > &)
reads the thermo, CEA deprecated
Definition: xml_parser.h:108
std::string nasa_xml_section(NASAThermoMixture< NumericType, CEACurveFit< NumericType > > &)
For the given thermo type, return the string for the corresponding XML section.
Definition: xml_parser.h:238
std::string nasa_xml_section(NASAThermoMixture< NumericType, NASA9CurveFit< NumericType > > &)
For the given thermo type, return the string for the corresponding XML section.
Definition: xml_parser.h:234
bool rate_constant_Berthelot_coefficient_parameter(NumericType &D, std::string &D_unit, std::string &def_unit) const
return true if D coefficient
Definition: xml_parser.C:576
bool efficiencies(std::vector< std::pair< std::string, NumericType > > &par_values) const
return true if efficiencies are found
Definition: xml_parser.C:620
bool rate_constant(const std::string &kinetics_model)
go to next rate constant
Definition: xml_parser.C:231
void read_thermodynamic_data_root(ThermoType &thermo)
reads the thermo, NASA generalist
Definition: xml_parser.C:676
const std::string reaction_chemical_process() const
return reaction chemical process
Definition: xml_parser.C:279
bool Troe_T3_parameter(NumericType &T3, std::string &T3_unit, std::string &def_unit) const
return true is alpha
Definition: xml_parser.C:667
std::string nasa_xml_section(NASAThermoMixture< NumericType, NASA7CurveFit< NumericType > > &)
For the given thermo type, return the string for the corresponding XML section.
Definition: xml_parser.h:230
XMLParser()
Never use default constructor.
bool molecules_pairs(tinyxml2::XMLElement *molecules, std::vector< std::pair< std::string, PairedType > > &products_pair) const
return pairs of molecules and stoichiometric coefficients
Definition: xml_parser.C:377
bool Troe() const
return true if there's a Troe block
Definition: xml_parser.C:259
const std::string unit(tinyxml2::XMLElement *parameter) const
return the unit of current pointer
This class stores the NASA polynomial fit to the thermodynamics quantities and .
Definition: ascii_parser.h:68
bool rate_constant_preexponential_parameter(NumericType &A, std::string &A_unit, std::string &def_unit) const
return true if pre exponentiel coefficient
Definition: xml_parser.C:554
#define antioch_error_msg(errmsg)
This class only differs from NASA9CurveFit in the construction.
Definition: ascii_parser.h:72
tinyxml2::XMLElement * _species_block
Definition: xml_parser.h:252
bool rate_constant_activation_energy_parameter(NumericType &Ea, std::string &Ea_unit, std::string &def_unit) const
return true if activation energie
Definition: xml_parser.C:569
const std::string reaction_equation() const
return reaction equation
Definition: xml_parser.C:273
void read_thermodynamic_data(NASAThermoMixture< NumericType, NASA9CurveFit< NumericType > > &thermo)
reads the thermo, NASA generalist, no templates for virtual
Definition: xml_parser.h:100
std::map< ParsingKey, std::string > _map
Definition: xml_parser.h:260
bool verbose() const
Definition: parser_base.h:248
tinyxml2::XMLElement * _reaction
Definition: xml_parser.h:255
tinyxml2::XMLDocument * _doc
Definition: xml_parser.h:249
bool products_pairs(std::vector< std::pair< std::string, int > > &products_pair) const
return pairs of products and stoichiometric coefficients
Definition: xml_parser.C:331
bool rate_constant_lambda_parameter(std::vector< NumericType > &lambda, std::string &lambda_unit, std::string &def_unit) const
return true if lambda
Definition: xml_parser.C:583
bool get_parameter(const tinyxml2::XMLElement *ptr, const std::string &par, NumericType &par_value, std::string &par_unit) const
return a parameter's value
Definition: xml_parser.C:468
bool reaction()
reaction
Definition: xml_parser.C:217
The parameters are reduced parameters.
std::string nasa_xml_section(CEAThermodynamics< NumericType > &)
For the given thermo type, return the string for the corresponding XML section.
Definition: xml_parser.h:242
bool is_k0(unsigned int nrc, const std::string &kin_model) const
return true if the concerned reaction rate is the low pressure limit
Definition: xml_parser.C:404
const std::string reaction_kinetics_model(const std::vector< std::string > &kinetics_models) const
return reaction kinetics model
Definition: xml_parser.C:298
bool reactants_pairs(std::vector< std::pair< std::string, int > > &reactants_pair) const
return pairs of reactants and stoichiometric coefficients
Definition: xml_parser.C:324
const std::vector< std::string > species_list()
reads the species set
Definition: xml_parser.C:203
tinyxml2::XMLElement * find_element_with_attribute(const tinyxml2::XMLElement *element, const std::string &elem_name, const std::string &attribute, const std::string &attr_value) const
Search the siblings of the element to find the element with the given value for the given attribute...
Definition: xml_parser.C:511
unsigned int where_is_k0(const std::string &kin_model) const
return index of k0 (0 or 1)
Definition: xml_parser.C:450
bool reaction_reversible() const
return reversible state
Definition: xml_parser.C:289
tinyxml2::XMLElement * _thermo_block
Definition: xml_parser.h:253
tinyxml2::XMLElement * _Troe
Definition: xml_parser.h:258
const std::map< std::string, NumericType > products_orders() const
return a map between products' name and found partial orders
Definition: xml_parser.C:357
bool Troe_T1_parameter(NumericType &T1, std::string &T1_unit, std::string &def_unit) const
return true is alpha
Definition: xml_parser.C:653
bool rate_constant_cross_section_parameter(std::vector< NumericType > &sigma, std::string &sigma_unit, std::string &def_unit) const
return true if sigma
Definition: xml_parser.C:590

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