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 30 #include "antioch/antioch_asserts.h" 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 65 /*!\class XMLParser 66 67 Nothing is stored, this parser is based on the tinyxml2 68 implementation. Please note that no other file should include 69 the `tinyxml2_imp.h' header. 70 71 The defaults units are based and derived on Cantera: 72 - pre-exponential parameters in (m3/kmol)^(m-1)/s 73 - activation energy in cal/mol, 74 - power parameter without unit 75 - cross-section typically in cm2/nm, 76 - lambda typically in nm, 77 */ 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 87 //// first local pointers 88 /*! Read header of file, go to interesting part*/ 89 bool initialize(); 90 91 /// species 92 //! reads the species set 93 const std::vector<std::string> species_list() ; 94 95 //! reads the thermo, NASA generalist, no templates for virtual read_thermodynamic_data(NASAThermoMixture<NumericType,NASA7CurveFit<NumericType>> & thermo)96 void read_thermodynamic_data(NASAThermoMixture<NumericType, NASA7CurveFit<NumericType> >& thermo) 97 {this->read_thermodynamic_data_root(thermo);} 98 99 //! reads the thermo, NASA generalist, no templates for virtual read_thermodynamic_data(NASAThermoMixture<NumericType,NASA9CurveFit<NumericType>> & thermo)100 void read_thermodynamic_data(NASAThermoMixture<NumericType, NASA9CurveFit<NumericType> >& thermo) 101 {this->read_thermodynamic_data_root(thermo);} 102 103 //! reads the thermo, NASA generalist, no templates for virtual read_thermodynamic_data(NASAThermoMixture<NumericType,CEACurveFit<NumericType>> &)104 void read_thermodynamic_data(NASAThermoMixture<NumericType, CEACurveFit<NumericType> >& /*thermo*/) 105 {antioch_error_msg("ERROR: XML Parsing only supports parsing for NASA7CurveFit and NASA9CurveFit!");} 106 107 108 /// reaction 109 110 /*! go to next reaction*/ 111 bool reaction(); 112 113 /*! go to next rate constant*/ 114 bool rate_constant(const std::string & kinetics_model); 115 116 /*! return true if there's a Troe block*/ 117 bool Troe() const; 118 119 /*! return reaction id, 0 if not provided*/ 120 const std::string reaction_id() const; 121 122 /*! return reaction equation */ 123 const std::string reaction_equation() const; 124 125 /*! return reaction chemical process*/ 126 const std::string reaction_chemical_process() const; 127 128 /*! return reaction kinetics model*/ 129 const std::string reaction_kinetics_model(const std::vector<std::string> &kinetics_models) const; 130 131 /*! return reversible state*/ 132 bool reaction_reversible() const; 133 134 /*! return pairs of reactants and stoichiometric coefficients*/ 135 bool reactants_pairs(std::vector<std::pair<std::string,int> > & reactants_pair) const; 136 137 /*! return pairs of products and stoichiometric coefficients*/ 138 bool products_pairs(std::vector<std::pair<std::string,int> > & products_pair) const; 139 140 /*! return a map between reactants' name and found partial orders */ 141 const std::map<std::string,NumericType> reactants_orders() const; 142 143 /*! return a map between products' name and found partial orders */ 144 const std::map<std::string,NumericType> products_orders() const; 145 146 /*! return true if the concerned reaction rate is the low pressure limit 147 * 148 * In the case of falloff reactions, there is the attribute "name" to 149 * specify which rate constant is the low pressure limit. This attribute 150 * should have "k0" as value, and nothing else. 151 * 152 * If no "name" attribute is provided, the first rate constant is the low 153 * pressure limit, if two "name" attribute are provided, or if the value 154 * is not "k0", an exception is thrown. 155 */ 156 bool is_k0(unsigned int nrc, const std::string & kin_model) const; 157 158 /*! return index of k0 (0 or 1)*/ 159 unsigned int where_is_k0(const std::string & kin_model) const; 160 161 /*! return true if pre exponentiel coefficient*/ 162 bool rate_constant_preexponential_parameter( NumericType & A, std::string & A_unit, std::string & def_unit) const; 163 164 /*! return true if beta coefficient*/ 165 bool rate_constant_power_parameter( NumericType & b, std::string & b_unit, std::string & def_unit) const; 166 167 /*! return true if activation energie*/ 168 bool rate_constant_activation_energy_parameter(NumericType & Ea, std::string & Ea_unit, std::string & def_unit) const; 169 170 /*! return true if D coefficient*/ 171 bool rate_constant_Berthelot_coefficient_parameter(NumericType & D, std::string & D_unit, std::string & def_unit) const; 172 173 /*! return true if Tref*/ 174 bool rate_constant_Tref_parameter( NumericType & Tref, std::string & Tref_unit, std::string & def_unit) const; 175 176 /*! return true if lambda*/ 177 bool rate_constant_lambda_parameter( std::vector<NumericType> & lambda, std::string & lambda_unit, std::string & def_unit) const; 178 179 /*! return true if sigma*/ 180 bool rate_constant_cross_section_parameter(std::vector<NumericType> & sigma, std::string & sigma_unit, std::string & def_unit) const; 181 182 /*! return true if a Kooij is called Arrhenuis*/ 183 bool verify_Kooij_in_place_of_Arrhenius() const; 184 185 /*! return true if efficiencies are found*/ 186 bool efficiencies(std::vector<std::pair<std::string,NumericType> > & par_values) const; 187 188 /*! return true if alpha*/ 189 bool Troe_alpha_parameter(NumericType & alpha, std::string & alpha_unit, std::string & def_unit) const; 190 191 /*! return true if T1*/ 192 bool Troe_T1_parameter( NumericType & T1, std::string & T1_unit, std::string & def_unit) const; 193 194 /*! return true if T2*/ 195 bool Troe_T2_parameter( NumericType & T2, std::string & T2_unit, std::string & def_unit) const; 196 197 /*! return true if T3*/ 198 bool Troe_T3_parameter( NumericType & T3, std::string & T3_unit, std::string & def_unit) const; 199 200 /*! return true if a Troe parameter in a GRI way*/ 201 bool Troe_GRI_parameter( NumericType & pa, unsigned int index) const; 202 203 private: 204 205 //! reads the thermo, NASA generalist 206 template <typename ThermoType> 207 void read_thermodynamic_data_root(ThermoType & thermo); 208 209 /*! return pairs of molecules and stoichiometric coefficients*/ 210 template <typename PairedType> 211 bool molecules_pairs(tinyxml2::XMLElement * molecules, std::vector<std::pair<std::string,PairedType> > & products_pair) const; 212 213 /*! return a parameter's value*/ 214 bool get_parameter(const tinyxml2::XMLElement * ptr, const std::string & par, NumericType & par_value, std::string & par_unit) const; 215 216 /*! return a parameter's values*/ 217 bool get_parameter(const tinyxml2::XMLElement * ptr, const std::string & par, std::vector<NumericType> & numpar, std::string & par_unit) const; 218 219 /*! return the unit of current pointer*/ 220 const std::string unit(tinyxml2::XMLElement * parameter) const; 221 222 /*! Search the siblings of the element to find the element with the 223 given value for the given attribute. Return pointer to that element. */ 224 tinyxml2::XMLElement * find_element_with_attribute( const tinyxml2::XMLElement * element, 225 const std::string& elem_name, 226 const std::string& attribute, 227 const std::string& attr_value ) const; 228 229 //! For the given thermo type, return the string for the corresponding XML section nasa_xml_section(NASAThermoMixture<NumericType,NASA7CurveFit<NumericType>> &)230 std::string nasa_xml_section( NASAThermoMixture<NumericType, NASA7CurveFit<NumericType> >& /*thermo*/ ) 231 { return _map.at(ParsingKey::NASA7); } 232 233 //! For the given thermo type, return the string for the corresponding XML section nasa_xml_section(NASAThermoMixture<NumericType,NASA9CurveFit<NumericType>> &)234 std::string nasa_xml_section( NASAThermoMixture<NumericType, NASA9CurveFit<NumericType> >& /*thermo*/ ) 235 { return _map.at(ParsingKey::NASA9); } 236 237 //! For the given thermo type, return the string for the corresponding XML section nasa_xml_section(NASAThermoMixture<NumericType,CEACurveFit<NumericType>> &)238 std::string nasa_xml_section( NASAThermoMixture<NumericType, CEACurveFit<NumericType> >& /*thermo*/ ) 239 { antioch_error_msg("ERROR: Only supported for NASA7CurveFit and NASA9CurveFit!"); return "";} 240 241 242 /*! Never use default constructor*/ 243 XMLParser(); 244 tinyxml2::XMLDocument * _doc; 245 246 // 247 tinyxml2::XMLElement * _species_block; 248 tinyxml2::XMLElement * _thermo_block; 249 tinyxml2::XMLElement * _reaction_block; 250 tinyxml2::XMLElement * _reaction; 251 252 tinyxml2::XMLElement * _rate_constant; 253 tinyxml2::XMLElement * _Troe; 254 255 std::map<ParsingKey,std::string> _map; 256 std::map<ParsingKey,std::string> _default_unit; 257 // GRI30 258 std::map<GRI30Comp, std::string> _gri_map; 259 260 }; 261 262 }//end namespace Antioch 263 264 #endif 265