48 template <
typename NumericType>
50 ParserBase<NumericType>(
"XML",filename,verbose),
52 _reaction_block(NULL),
60 std::cerr <<
"ERROR: unable to load xml file " << filename << std::endl;
61 std::cerr <<
"Error of tinyxml2 library:\n"
68 if(this->
verbose())std::cout <<
"Having opened file " << filename << std::endl;
141 template <
typename NumericType>
147 template <
typename NumericType>
151 _species_block = NULL;
152 _reaction_block = NULL;
154 _rate_constant = NULL;
159 if(_doc->LoadFile(filename.c_str()))
161 std::cerr <<
"ERROR: unable to load xml file " << filename << std::endl;
162 std::cerr <<
"Error of tinyxml2 library:\n"
163 <<
"\tID = " << _doc->
ErrorID() <<
"\n"
164 <<
"\tError String1 = " << _doc->GetErrorStr1() <<
"\n"
165 <<
"\tError String2 = " << _doc->GetErrorStr2() << std::endl;
169 if(this->verbose())std::cout <<
"Having opened file " << filename << std::endl;
174 template <
typename NumericType>
178 _reaction_block = _doc->FirstChildElement(
"ctml");
179 if (!_reaction_block)
181 std::cerr <<
"ERROR: no <ctml> tag found in input file"
195 _rate_constant = NULL;
197 return _reaction_block;
202 template <
typename NumericType>
208 std::vector<std::string> molecules;
210 split_string(std::string(_species_block->GetText()),
" ",molecules);
216 template <
typename NumericType>
220 _reaction = (_reaction)?
224 _rate_constant = NULL;
230 template <
typename NumericType>
239 _rate_constant = _rate_constant->NextSiblingElement(kinetics_model.c_str());
247 _rate_constant = _reaction->FirstChildElement(_map.at(
ParsingKey::KINETICS_MODEL).c_str())->FirstChildElement(kinetics_model.c_str());
252 _rate_constant = NULL;
255 return _rate_constant;
258 template <
typename NumericType>
264 template <
typename NumericType>
267 std::stringstream id;
272 template <
typename NumericType>
278 template <
typename NumericType>
284 std::string(chem_proc):
288 template <
typename NumericType>
292 (std::string(_reaction->Attribute(_map.at(
ParsingKey::REVERSIBLE).c_str())) == std::string(
"no"))?
false:
true
297 template <
typename NumericType>
300 unsigned int imod(0);
302 while(!rate_constant)
304 if(imod == kinetics_models.size() - 1)
306 std::cerr <<
"Could not find a suitable kinetics model.\n"
307 <<
"Implemented kinetics models are:\n";
309 for(
unsigned int m = 0; m < kinetics_models.size(); m++)
310 std::cerr <<
" " << kinetics_models[m] <<
"\n";
312 std::cerr <<
"See Antioch documentation for more details."
320 return kinetics_models[imod];
323 template <
typename NumericType>
327 return this->molecules_pairs(reactants, reactants_pair);
330 template <
typename NumericType>
334 return this->molecules_pairs(products, products_pair);
337 template <
typename NumericType>
341 std::map<std::string,NumericType> map;
343 std::vector<std::pair<std::string,NumericType> > pairs;
344 if(this->molecules_pairs(orders,pairs))
346 for(
unsigned int s = 0; s < pairs.size(); s++)
348 map.insert(pairs[s]);
356 template <
typename NumericType>
360 std::map<std::string,NumericType> map;
362 std::vector<std::pair<std::string,NumericType> > pairs;
363 if(this->molecules_pairs(orders,pairs))
365 for(
unsigned int s = 0; s < pairs.size(); s++)
367 map.insert(pairs[s]);
375 template <
typename NumericType>
376 template <
typename PairedType>
383 std::vector<std::string> mol_pairs;
389 for(
unsigned int p=0; p < mol_pairs.size(); p++ )
391 std::pair<std::string,PairedType> pair( split_string_on_colon<PairedType>(mol_pairs[p]) );
393 molecules_pairs.push_back(pair);
403 template <
typename NumericType>
415 antioch_assert(_rate_constant->NextSiblingElement(kin_model.c_str()));
418 std::string error =
"I can understand the need to put attributes everywhere, really, but in this case, I'm ";
419 error +=
"afraid that it's not a good idea to have two \'name\' attributes: only the low pressure limit should have it.";
425 std::string error =
"The keyword associated with the \'name\' attribute within the description of a falloff should be, and only be, ";
426 error +=
"\'k0\' to specify the low pressure limit. It seems that the one you provided, \'";
428 error +=
"\' is not this one. Please correct it at reaction";
429 error += this->reaction_id();
431 error += this->reaction_equation();
437 antioch_assert(_rate_constant->NextSiblingElement(kin_model.c_str()));
449 template <
typename NumericType>
467 template <
typename NumericType>
485 template <
typename NumericType>
494 std::vector<std::string> values;
497 par_values.resize(values.size());
498 for(
unsigned int i = 0; i < values.size(); i++)
499 par_values[i] = string_to_T<NumericType>(values[i].c_str());
510 template <
typename NumericType>
512 const std::string& elem_name,
513 const std::string& attribute,
514 const std::string& attr_value )
const
520 if( !element->
Attribute(attribute.c_str()) )
521 antioch_error_msg(
"ERROR: Could not find attribute "+attribute+
" for current element!");
524 if( std::string( element->
Attribute(attribute.c_str()) ) == attr_value )
525 elem_with_attr = element;
532 while( elem_with_attr )
534 std::string curr_attr;
535 if( elem_with_attr->
Attribute(attribute.c_str()) )
536 curr_attr = std::string(elem_with_attr->
Attribute(attribute.c_str()));
538 if( curr_attr == attr_value )
545 if( !elem_with_attr )
546 antioch_error_msg(
"ERROR: Could not find XMLElement with attribute = "+attribute+
" whose value is "+attr_value+
"!");
553 template <
typename NumericType>
561 template <
typename NumericType>
565 return this->get_parameter(_rate_constant,_map.at(
ParsingKey::POWER).c_str(),b,b_unit);
568 template <
typename NumericType>
575 template <
typename NumericType>
582 template <
typename NumericType>
586 return this->get_parameter(_rate_constant,_map.at(
ParsingKey::HV_LAMBDA).c_str(),lambda,lambda_unit);
589 template <
typename NumericType>
596 template <
typename NumericType>
603 template <
typename NumericType>
612 if(std::atof(rate_constant->FirstChildElement(_map.at(
ParsingKey::POWER).c_str())->GetText()) != 0.)
619 template <
typename NumericType>
630 std::vector<std::string> values;
635 for(
unsigned int i = 0; i < values.size(); i++)
636 par_values.push_back(split_string_on_colon<NumericType>(values[i]));
645 template <
typename NumericType>
652 template <
typename NumericType>
659 template <
typename NumericType>
666 template <
typename NumericType>
674 template <
typename NumericType>
675 template <
typename ThermoType>
682 const std::vector<ChemicalSpecies<NumericType>*>& chem_species = chem_mixture.chemical_species();
685 std::string nasa_xml_section = this->nasa_xml_section(thermo);
687 for(
unsigned int s = 0; s < chem_mixture.n_species(); s++)
696 const std::string& name = chem_species[s]->species();
699 spec = this->find_element_with_attribute( species_block,
715 std::vector<NumericType> temps;
716 std::vector<NumericType> values;
718 std::vector<std::string> coeffs_str;
748 for(
unsigned int d = 0; d < coeffs_str.size(); d++)
749 values.push_back(string_to_T<NumericType>(coeffs_str[d]));
752 if( temps.size() > 1 )
754 NumericType prev_Tmax = *(temps.end()-2);
756 NumericType diff = (Tmin - prev_Tmax)/prev_Tmax;
758 const NumericType tol = std::numeric_limits<NumericType>::epsilon() * 10.;
760 if(std::abs(diff) > tol)
772 thermo.add_curve_fit(name, values, temps);
const char * Attribute(const char *name, const char *value=0) const
void remove_newline_from_strings(std::vector< std::string > &strings)
Strips newline characters from strings in the input vector, strings.
#define antioch_assert(asserted)
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 split_string(const std::string &input, const std::string &delimiter, std::vector< std::string > &results)
All characters in delimiter will be treated as a delimiter.
bool rate_constant_Tref_parameter(NumericType &Tref, std::string &Tref_unit, std::string &def_unit) const
return true if Tref
bool initialize()
Read header of file, go to interesting part.
bool verify_Kooij_in_place_of_Arrhenius() const
return true if a Kooij is called Arrhenuis
bool Troe_T2_parameter(NumericType &T2, std::string &T2_unit, std::string &def_unit) const
return true is alpha
const std::map< std::string, NumericType > reactants_orders() const
return a map between reactants' name and found partial orders
std::map< ParsingKey, std::string > _default_unit
#define antioch_not_implemented()
void change_file(const std::string &filename)
bool Troe_alpha_parameter(NumericType &alpha, std::string &alpha_unit, std::string &def_unit) const
return true is alpha
ANTIOCH_NUMERIC_TYPE_CLASS_INSTANTIATE(ASCIIParser)
const ChemicalMixture< CoeffType > & chemical_mixture() const
method to send this back
const char * GetErrorStr1() const
Return a possibly helpful diagnostic location or string.
ANTIOCH_XML_PARSER_INSTANTIATE()
const char * GetErrorStr2() const
Return a possibly helpful secondary diagnostic location or string.
bool rate_constant_Berthelot_coefficient_parameter(NumericType &D, std::string &D_unit, std::string &def_unit) const
return true if D coefficient
bool efficiencies(std::vector< std::pair< std::string, NumericType > > &par_values) const
return true if efficiencies are found
bool rate_constant(const std::string &kinetics_model)
go to next rate constant
void read_thermodynamic_data_root(ThermoType &thermo)
reads the thermo, NASA generalist
const std::string reaction_chemical_process() const
return reaction chemical process
bool Troe_T3_parameter(NumericType &T3, std::string &T3_unit, std::string &def_unit) const
return true is alpha
XMLParser()
Never use default constructor.
int ErrorID() const
Return the errorID.
int LoadFile(const char *filename)
bool molecules_pairs(tinyxml2::XMLElement *molecules, std::vector< std::pair< std::string, PairedType > > &products_pair) const
return pairs of molecules and stoichiometric coefficients
bool Troe() const
return true if there's a Troe block
const XMLElement * NextSiblingElement(const char *value=0) const
Get the next (right) sibling element of this node, with an opitionally supplied name.
bool rate_constant_preexponential_parameter(NumericType &A, std::string &A_unit, std::string &def_unit) const
return true if pre exponentiel coefficient
#define antioch_error_msg(errmsg)
bool rate_constant_activation_energy_parameter(NumericType &Ea, std::string &Ea_unit, std::string &def_unit) const
return true if activation energie
const std::string reaction_equation() const
return reaction equation
std::map< ParsingKey, std::string > _map
const XMLElement * FirstChildElement(const char *value=0) const
tinyxml2::XMLDocument * _doc
bool products_pairs(std::vector< std::pair< std::string, int > > &products_pair) const
return pairs of products and stoichiometric coefficients
bool rate_constant_lambda_parameter(std::vector< NumericType > &lambda, std::string &lambda_unit, std::string &def_unit) const
return true if lambda
Nothing is stored, this parser is based on the tinyxml2 implementation.
#define antioch_parsing_error(description)
bool get_parameter(const tinyxml2::XMLElement *ptr, const std::string &par, NumericType &par_value, std::string &par_unit) const
return a parameter's value
Class storing chemical mixture properties.
The parameters are reduced parameters.
bool is_k0(unsigned int nrc, const std::string &kin_model) const
return true if the concerned reaction rate is the low pressure limit
const std::string reaction_kinetics_model(const std::vector< std::string > &kinetics_models) const
return reaction kinetics model
bool reactants_pairs(std::vector< std::pair< std::string, int > > &reactants_pair) const
return pairs of reactants and stoichiometric coefficients
const std::vector< std::string > species_list()
reads the species set
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...
const char * GetText() const
A parser is an instance related to a file.
unsigned int where_is_k0(const std::string &kin_model) const
return index of k0 (0 or 1)
bool reaction_reversible() const
return reversible state
const std::map< std::string, NumericType > products_orders() const
return a map between products' name and found partial orders
bool Troe_T1_parameter(NumericType &T1, std::string &T1_unit, std::string &def_unit) const
return true is alpha
bool rate_constant_cross_section_parameter(std::vector< NumericType > &sigma, std::string &sigma_unit, std::string &def_unit) const
return true if sigma