antioch-0.4.0
read_reaction_set_data.C
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 
28 
29 // Antioch
31 #include "antioch/string_utils.h"
32 #include "antioch/units.h"
33 #include "antioch/reaction_set.h"
37 #include "antioch/ascii_parser.h"
38 #include "antioch/chemkin_parser.h"
39 #include "antioch/xml_parser.h"
40 
41 namespace Antioch
42 {
43  template <typename NumericType>
45  const std::string & provided_unit,
46  const std::vector<std::string> & accepted_unit,
47  const std::string & equation,
48  const std::string & parameter_name)
49  {
50  if(provided_unit.empty() && default_unit.is_united()) //no unit provided and there is one
51  {
52  antioch_unit_required(parameter_name,default_unit.get_symbol());
53  }else // test
54  {
55  bool found(false);
56  for(unsigned int i = 0; i < accepted_unit.size(); i++)
57  {
58  if(Units<NumericType>(accepted_unit[i]).is_homogeneous(provided_unit))
59  {
60  found = true;
61  break;
62  }
63  }
64  if(!found)
65  {
66  std::string errorstring("Error in reaction " + equation);
67  errorstring += "\n" + parameter_name + " parameter's unit should be homogeneous to \"" + accepted_unit[0] + "\"";
68  for(unsigned int i = 1; i < accepted_unit.size(); i++)errorstring += ", or \"" + accepted_unit[i] + "\"";
69  errorstring += " and you provided \"" + provided_unit + "\"";
70  antioch_unit_error(errorstring);
71  }
72  default_unit.set_unit(provided_unit);
73  }
74  }
75 
76  template<typename NumericType>
77  void read_reaction_set_data( const std::string& filename,
78  const bool verbose,
79  ReactionSet<NumericType>& reaction_set,
80  ParsingType type )
81  {
82  ParserBase<NumericType> * parser(NULL);
83  switch(type)
84  {
85  case ASCII:
86  parser = new ASCIIParser<NumericType>(filename,verbose);
87  break;
88  case CHEMKIN:
89  parser = new ChemKinParser<NumericType>(filename,verbose);
90  break;
91  case XML:
92  parser = new XMLParser<NumericType>(filename,verbose);
93  break;
94  default:
95  antioch_parsing_error("unknown type");
96  }
97 
98  //error or no reaction data
99  if(!parser->initialize())return;
100 
101  const ChemicalMixture<NumericType>& chem_mixture = reaction_set.chemical_mixture();
102  unsigned int n_species = chem_mixture.n_species();
103  // Sanity Check on species
104  /*
105  tinyxml2::XMLElement* species = element->FirstChildElement("phase");
106  species = species->FirstChildElement("speciesArray");
107 
108  std::vector<std::string> species_names;
109 
110  std::cout << species->GetText() << std::endl;
111 
112  SplitString(std::string(species->GetText()),
113  " ",
114  species_names,
115  false);
116 
117 
118  if( n_species != species_names.size() )
119  {
120  std::cerr << "Error: Mismatch in n_species and the number of species specified in" << std::endl
121  << " the kinetics XML file " << filename << std::endl
122  << " Found species: " << species->GetText() << std::endl;
123  antioch_error();
124  }
125  */
126 
127  std::map<std::string,KineticsModel::KineticsModel> kin_keyword;
128  kin_keyword["Constant"] = KineticsModel::CONSTANT;
129  kin_keyword["HercourtEssen"] = KineticsModel::HERCOURT_ESSEN;
130  kin_keyword["Berthelot"] = KineticsModel::BERTHELOT;
131  kin_keyword["Arrhenius"] = KineticsModel::ARRHENIUS;
132  kin_keyword["BerthelotHercourtEssen"] = KineticsModel::BHE;
133  kin_keyword["Kooij"] = KineticsModel::KOOIJ;
134  kin_keyword["ModifiedArrhenius"] = KineticsModel::KOOIJ; //for Arrhenius fans
135  kin_keyword["VantHoff"] = KineticsModel::VANTHOFF;
136  kin_keyword["photochemistry"] = KineticsModel::PHOTOCHEM;
137 
138  std::map<KineticsModel::KineticsModel,unsigned int> kinetics_model_map;
139  kinetics_model_map[KineticsModel::CONSTANT] = 0;
140  kinetics_model_map[KineticsModel::HERCOURT_ESSEN] = 1;
141  kinetics_model_map[KineticsModel::BERTHELOT] = 2;
142  kinetics_model_map[KineticsModel::ARRHENIUS] = 3;
143  kinetics_model_map[KineticsModel::BHE] = 4;
144  kinetics_model_map[KineticsModel::KOOIJ] = 5;
145  kinetics_model_map[KineticsModel::VANTHOFF] = 7;
146  kinetics_model_map[KineticsModel::PHOTOCHEM] = 8;
147 
148  std::vector<std::string> models;
149  models.push_back("Constant");
150  models.push_back("HercourtEssen");
151  models.push_back("Berthelot");
152  models.push_back("Arrhenius");
153  models.push_back("BerthelotHercourtEssen");
154  models.push_back("Kooij");
155  models.push_back("ModifiedArrhenius");
156  models.push_back("VantHoff");
157  models.push_back("photochemistry");
158 
159  std::map<std::string,ReactionType::ReactionType> proc_keyword;
160  proc_keyword["Elementary"] = ReactionType::ELEMENTARY;
161  proc_keyword["Duplicate"] = ReactionType::DUPLICATE;
162  proc_keyword["ThreeBody"] = ReactionType::THREE_BODY;
163  proc_keyword["threeBody"] = ReactionType::THREE_BODY; // Cantera/backward compatiblity
164  proc_keyword["LindemannFalloff"] = ReactionType::LINDEMANN_FALLOFF;
165  proc_keyword["TroeFalloff"] = ReactionType::TROE_FALLOFF;
166  proc_keyword["LindemannFalloffThreeBody"] = ReactionType::LINDEMANN_FALLOFF_THREE_BODY;
167  proc_keyword["TroeFalloffThreeBody"] = ReactionType::TROE_FALLOFF_THREE_BODY;
168 
169  while (parser->reaction())
170  {
171  if (verbose) std::cout << "Reaction \"" << parser->reaction_id() << "\":\n"
172  << " eqn: " << parser->reaction_equation()
173  << std::endl;
174 
177 
178  if (!parser->reaction_chemical_process().empty())
179  {
180  if (verbose) std::cout << " type: " << parser->reaction_chemical_process() << std::endl;
181  if(!proc_keyword.count(parser->reaction_chemical_process()))
182  {
183  std::cerr << "Implemented chemical processes are:\n"
184  << " Elementary (default)\n"
185  << " Duplicate\n"
186  << " ThreeBody\n"
187  << " LindemannFalloff\n"
188  << " TroeFalloff\n"
189  << " LindemannFalloffThreeBody\n"
190  << " TroeFalloffThreeBody\n"
191  << "See Antioch documentation for more details."
192  << std::endl;
194  }
195  typeReaction = proc_keyword[parser->reaction_chemical_process()];
196  }
197 
198  bool reversible(parser->reaction_reversible());
199  if (verbose) std::cout << "reversible: " << reversible << std::endl;
200 
201  kineticsModel = kin_keyword[parser->reaction_kinetics_model(models)];
202  const std::string reading_kinetics_model = parser->reaction_kinetics_model(models);
203 
204  // usually Kooij is called Arrhenius, check here
205  if(kineticsModel == KineticsModel::ARRHENIUS)
206  {
208  {
209  kineticsModel = KineticsModel::KOOIJ;
211  std::cout << "In reaction(s) including " << parser->reaction_id() << "\n"
212  << "An equation of the form \"A * (T/Tref)^beta * exp(-Ea/(R*T))\" is a Kooij equation,\n"
213  << "I guess a modified Arrhenius could be a name too. Whatever, the correct label is\n"
214  << "\"Kooij\", or, << à la limite >> \"ModifiedArrhenius\". Please use those terms instead,\n"
215  << "thanks and a good day to you, user." << std::endl;
216  ); // antioch_do_once
217  }
218  }
219 
220  // construct a Reaction object
221  Reaction<NumericType>* my_rxn = build_reaction<NumericType>(n_species, parser->reaction_equation(),
222  reversible,typeReaction,kineticsModel);
223  my_rxn->set_id(parser->reaction_id());
224 
225  // We will add the reaction, unless we do not have a
226  // reactant or product
227  bool relevant_reaction = true;
228  NumericType order_reaction(0);
229  std::vector<std::pair<std::string,int> > molecules_pairs;
230 
231  if(parser->reactants_pairs(molecules_pairs))
232  {
233 
234  std::map<std::string,NumericType> orders = parser->reactants_orders();
235  if (verbose)
236  {
237  std::cout << "\n reactants: ";
238  for(unsigned int ir = 0; ir < molecules_pairs.size(); ir++)
239  {
240  NumericType order = (orders.count(molecules_pairs[ir].first))?orders.at(molecules_pairs[ir].first):static_cast<NumericType>(molecules_pairs[ir].second);
241  std::cout << molecules_pairs[ir].first << ":" << molecules_pairs[ir].second << "," << order << ", ";
242  }
243  }
244 
245  for( unsigned int p=0; p < molecules_pairs.size(); p++ )
246  {
247  if(molecules_pairs[p].first == "e-") molecules_pairs[p].first = "e";
248 
249  if(verbose) std::cout << "\n " << molecules_pairs[p].first << " " << molecules_pairs[p].second;
250 
251  if( !chem_mixture.species_name_map().count( molecules_pairs[p].first ) )
252  {
253  relevant_reaction = false;
254  if (verbose) std::cout << "\n -> skipping this reaction (no reactant " << molecules_pairs[p].first << ")";
255  }
256  else
257  {
258  NumericType order = (orders.count(molecules_pairs[p].first))?orders.at(molecules_pairs[p].first):static_cast<NumericType>(molecules_pairs[p].second);
259  my_rxn->add_reactant( molecules_pairs[p].first,
260  chem_mixture.species_name_map().find( molecules_pairs[p].first )->second,
261  molecules_pairs[p].second, order );
262  order_reaction += order;
263  }
264  }
265  }
266 
267  molecules_pairs.clear();
268  if(parser->products_pairs(molecules_pairs))
269  {
270 
271  std::map<std::string,NumericType> orders = parser->products_orders();
272  if(verbose) std::cout << "\n products: ";
273  for(unsigned int ir = 0; ir < molecules_pairs.size(); ir++)
274  {
275  NumericType order = (orders.count(molecules_pairs[ir].first))?orders.at(molecules_pairs[ir].first):static_cast<NumericType>(molecules_pairs[ir].second);
276  std::cout << molecules_pairs[ir].first << ":" << molecules_pairs[ir].second << "," << order << ", ";
277  }
278 
279  for (unsigned int p=0; p < molecules_pairs.size(); p++)
280  {
281  if(molecules_pairs[p].first == "e-") molecules_pairs[p].first = "e";
282 
283  if(verbose) std::cout << "\n " << molecules_pairs[p].first << " " << molecules_pairs[p].second;
284 
285  if( !chem_mixture.species_name_map().count( molecules_pairs[p].first ) )
286  {
287  relevant_reaction = false;
288  if (verbose) std::cout << "\n -> skipping this reaction (no product " << molecules_pairs[p].first << ")";
289  }
290  else
291  {
292  NumericType order = (orders.count(molecules_pairs[p].first))?orders.at(molecules_pairs[p].first):static_cast<NumericType>(molecules_pairs[p].second);
293  my_rxn->add_product( molecules_pairs[p].first,
294  chem_mixture.species_name_map().find( molecules_pairs[p].first )->second,
295  molecules_pairs[p].second, order );
296  }
297  }
298  if(verbose) std::cout << std::endl;
299  }
300 
301  if(!relevant_reaction)
302  {
303  if(verbose) std::cout << "skipped reaction\n\n";
304  delete my_rxn;
305  continue;
306  }
307 
308  while(parser->rate_constant(reading_kinetics_model)) //for duplicate and falloff models, several kinetics rate to load, no mixing allowed
309  {
310 
311  /* Any data is formatted by the parser method.
312  * For any data required, parser sends back:
313  * - true/false if data is found
314  * - value of data
315  * - unit of data if found, empty string else
316  * - default unit of data
317  *
318  * The parser defines the defaults, note the special case
319  * of the pre-exponential parameters:
320  * its unit is [quantity-1]^(order - 1)/s, thus the parser
321  * defines only the [quantity-1] unit (SI unit is m^3/mol)
322  * as default.
323  */
324 
325  std::vector<NumericType> data; // for rate constant
326 
327  Units<NumericType> def_unit;
328  int pow_unit(order_reaction - 1);
329  bool is_falloff(false);
330  bool is_k0(false);
331  //threebody always
332  if(my_rxn->type() == ReactionType::THREE_BODY)pow_unit++;
333  //falloff for k0
334  if(my_rxn->type() == ReactionType::LINDEMANN_FALLOFF ||
335  my_rxn->type() == ReactionType::TROE_FALLOFF ||
338  {
339  is_falloff = verbose;
340  //k0 is either determined by an explicit name, or is the first of unnamed rate constants
341  if(parser->is_k0(my_rxn->n_rate_constants(),reading_kinetics_model))
342  {
343  pow_unit++;
344  is_k0 = verbose;
345  }
346  }
347 
348  NumericType par_value(-1.);
349  std::vector<NumericType> par_values;
350  std::string par_unit;
351  std::string default_unit;
352  std::vector<std::string> accepted_unit;
353 
354  // verbose as we read along
355  if(verbose)std::cout << " rate: " << models[kinetics_model_map[kineticsModel]] << " model\n";
356  if(is_falloff){
357  (is_k0)?std::cout << " Low pressure limit rate constant\n":std::cout << " High pressure limit rate constant\n";
358  }
359 
360  // pre-exponential
361  if(parser->rate_constant_preexponential_parameter(par_value, par_unit, default_unit))
362  {
363  // using Units object to build accepted_unit
364  accepted_unit.clear();
365  def_unit.set_unit("m3/mol");
366  //to the m-1 power
367  if(pow_unit != 0)
368  {
369  def_unit *= pow_unit;
370  }else
371  {
372  def_unit.clear();
373  }
374  def_unit.substract("s"); // per second
375  accepted_unit.push_back(def_unit.get_symbol());
376 
377  def_unit.set_unit(default_unit);
378  //to the m-1 power
379  if(pow_unit != 0)
380  {
381  def_unit *= pow_unit;
382  }else
383  {
384  def_unit.clear();
385  }
386  def_unit.substract("s"); // per second
387  verify_unit_of_parameter(def_unit, par_unit, accepted_unit, my_rxn->equation(), "A");
388  if(verbose)
389  {
390  std::cout << " A: " << par_value
391  << " " << def_unit.get_symbol() << std::endl;
392  }
393  data.push_back(par_value * def_unit.get_SI_factor());
394  }
395 
396  // beta
397  if(parser->rate_constant_power_parameter(par_value,par_unit,default_unit))
398  {
399  accepted_unit.clear();
400  accepted_unit.push_back("");
401  def_unit.set_unit(default_unit);
402  verify_unit_of_parameter(def_unit, par_unit, accepted_unit, my_rxn->equation(), "beta");
403  if(par_value == 0.)//if ARRHENIUS parameterized as KOOIJ, bad test, need to rethink it
404  {
405  std::cerr << "In reaction " << parser->reaction_id() << "\n"
406  << "An equation of the form \"A * exp(-Ea/(R*T))\" is an Arrhenius equation,\n"
407  << "and most certainly not a Kooij one\n"
408  << "it has been corrected, but please, change that in your file.\n"
409  << "Thanks and a good day to you, user." << std::endl;
410  kineticsModel = KineticsModel::ARRHENIUS;
411  }else
412  {
413  data.push_back(par_value * def_unit.get_SI_factor());
414  }
415  if(verbose)
416  {
417  std::cout << " b: " << par_value << std::endl;
418  }
419  }
420 
421  // activation energy
422  if(parser->rate_constant_activation_energy_parameter(par_value,par_unit,default_unit))
423  {
424  accepted_unit.clear();
425  accepted_unit.push_back("J/mol");
426  accepted_unit.push_back("K");
427  def_unit.set_unit(default_unit);
428  verify_unit_of_parameter(def_unit, par_unit, accepted_unit, my_rxn->equation(), "Ea");
429  data.push_back(par_value * def_unit.get_SI_factor());
430  if(verbose)
431  {
432  std::cout << " E: " << par_value
433  << " " << def_unit.get_symbol() << std::endl;
434  }
435  }
436 
437 
438  // Berthelot coefficient (D)
439  if(parser->rate_constant_Berthelot_coefficient_parameter(par_value,par_unit,default_unit))
440  {
441  accepted_unit.clear();
442  accepted_unit.push_back("K");
443  def_unit.set_unit(default_unit);
444  verify_unit_of_parameter(def_unit, par_unit, accepted_unit, my_rxn->equation(), "D");
445  data.push_back(par_value * def_unit.get_SI_factor());
446  if(verbose)
447  {
448  std::cout << " D: " << par_value
449  << " " << def_unit.get_symbol() << std::endl;
450  }
451  }
452 
453  // Tref, not for everyone
454  if(kineticsModel == KineticsModel::HERCOURT_ESSEN ||
455  kineticsModel == KineticsModel::BHE ||
456  kineticsModel == KineticsModel::KOOIJ ||
457  kineticsModel == KineticsModel::VANTHOFF)
458  {
459  par_value = 1.;
460  if(parser->rate_constant_Tref_parameter(par_value,par_unit,default_unit))
461  {
462  accepted_unit.clear();
463  accepted_unit.push_back("K");
464  def_unit.set_unit(default_unit);
465  verify_unit_of_parameter(def_unit, par_unit, accepted_unit, my_rxn->equation(), "Tref");
466  }else
467  {
468  antioch_parameter_required("Tref","1 K");
469  }
470  data.push_back(par_value);
471  }
472 
473  // scale E -> E/R
474  if(kineticsModel == KineticsModel::ARRHENIUS ||
475  kineticsModel == KineticsModel::KOOIJ ||
476  kineticsModel == KineticsModel::VANTHOFF)
477  {
478  parser->rate_constant_activation_energy_parameter(par_value,par_unit,default_unit);
479  (par_unit.empty())?def_unit.set_unit(default_unit):def_unit.set_unit(par_unit);
480  // now finding R unit: [Ea] / [K]
481  def_unit.substract("K");
482 
483  par_value = (def_unit.is_united())?
484  Antioch::Constants::R_universal<NumericType>() // Ea already tranformed in SI
485  :1.L; // no unit, so Ea already in K
486  data.push_back(par_value);
487  }
488 
489  //photochemistry
490  // lambda is either a length (def nm) or cm-1
491  // cross-section has several possibilities if given
492  // * cm2 per bin:
493  // - length (typically nm) or cm-1
494  // * cm2 no bin given:
495  // - if given, lambda unit
496  // - if not, nm
497 
498  // starting with lambda (for bin unit in cross-section)
499  // lambda is not in SI (m is really to violent), it will be nm
500  if(parser->rate_constant_lambda_parameter(par_values,par_unit,default_unit))
501  {
503  accepted_unit.clear();
504  accepted_unit.push_back("nm");
505  accepted_unit.push_back("cm-1");
506  def_unit.set_unit(default_unit);
507  verify_unit_of_parameter(def_unit, par_unit, accepted_unit, my_rxn->equation(), "lambda");
508 
509  data.clear();
510 
511  if(def_unit.is_homogeneous("nm"))// it's a length
512  {
513  for(unsigned int il = 0; il < par_values.size(); il++)
514  {
515  data.push_back(par_values[il] * def_unit.factor_to_some_unit("nm"));
516  }
517  }else // it's the inverse of a length
518  {
519  for(unsigned int il = 0; il < par_values.size(); il++)
520  {
521  data.push_back(1.L/(par_values[il] * def_unit.factor_to_some_unit("nm-1")));
522  }
523  }
524 
525  //now the cross-section
526 
527  NumericType bin_coefficient = (def_unit.is_homogeneous("nm"))?def_unit.factor_to_some_unit("nm"):
528  def_unit.factor_to_some_unit("nm-1");
529  if(!parser->rate_constant_cross_section_parameter(par_values,par_unit,default_unit))
530  {
531  std::cerr << "Where is the cross-section? In what universe have you photochemistry with a wavelength grid and no cross-section on it?" << std::endl;
532  antioch_error();
533  }
534  //test length
535  if(par_values.size() != data.size())
536  {
537  std::cerr << "Your cross-section vector and your lambda vector don't have the same size!\n"
538  << "What am I supposed to do with that?"
539  << std::endl;
540  antioch_error();
541  }
542 
543  /* here we will use two def unit:
544  * cs_unit, cm2 by default
545  * bin_unit, nm by default.
546  *
547  * strict rigorous unit is
548  * - (cs_unit - bin_unit): cm2/nm
549  * correct unit is
550  * - cs_unit: cm2
551  *
552  * so we need to test against those two possibilities.
553  * Now the funny part is that we test homogeneity, not
554  * equality, for generality purposes, so in case of strict
555  * rigorous unit, we need to decompose the read_unit into
556  * cross_section and bin units, so we can make the appropriate change.
557  *
558  * !TODO make the decomposition instead of strict equality
559  */
560 
561  accepted_unit.clear();
562  accepted_unit.push_back("cm2"); // only cross-section
563  accepted_unit.push_back("cm2/nm"); // per bin, bin is length-like
564  accepted_unit.push_back("cm2/nm-1"); // per bin, bin is inverse length-like
565  verify_unit_of_parameter(def_unit, par_unit, accepted_unit, my_rxn->equation(), "cross-section");
566 
567 
568  if(def_unit.is_homogeneous("cm2")) // gotta use the bin unit, real unit is [cs]/[provided bin unit]
569  {
570  for(unsigned int ics = 0; ics < par_values.size(); ics++)
571  {
572  data.push_back(par_values[ics] * def_unit.get_SI_factor() / bin_coefficient); //cs in SI, bin in nm or nm-1
573  }
574  }else // bin unit is provided
575  {
576  std::string target_unit = (def_unit.is_homogeneous("cm2/nm"))?"m2/nm":"m2/nm-1";
577  for(unsigned int ics = 0; ics < par_values.size(); ics++)
578  {
579  data.push_back(par_values[ics] * def_unit.factor_to_some_unit(target_unit));
580  }
581  }
582 
583  } //end photochemistry
584 
585  if(data.empty()) //replace the old "if no A parameters" as A is not required anymore
586  {
587  std::cerr << "Somehow, I have a bad feeling about a chemical reaction without any data parameters...\n"
588  << "This is too sad, I give up...\n"
589  << "Please, check the reaction " << my_rxn->equation() << " before coming back to me." << std::endl;
590  antioch_error(); //HEY!!!
591  }
592 
593  KineticsType<NumericType>* rate = build_rate<NumericType>(data,kineticsModel);
594 
595  my_rxn->add_forward_rate(rate);
596 
597  } //end of duplicate/falloff kinetics description loop
598 
599  // for falloff, we need a way to know which rate constant is the low pressure limit
600  // and which is the high pressure limit
601  // usually by calling the low pressure limite "k0". If nothing given, by default
602  // the first rate constant encountered is the low limit,
603  // so we need to change something only if the second rate constant has a "name" attribute
604  // of value "k0"
605  if(my_rxn->type() == ReactionType::LINDEMANN_FALLOFF ||
606  my_rxn->type() == ReactionType::TROE_FALLOFF ||
609  {
611  if(parser->where_is_k0(reading_kinetics_model) == 1) // second given is k0
612  {
613  my_rxn->swap_forward_rates(0,1);
614  }
615  }
616 
617 
618  std::vector<std::pair<std::string,NumericType> > efficiencies;
619  //efficiencies are only for three body reactions
620  if(parser->efficiencies(efficiencies))
621  {
625 
626  for(unsigned int p = 0; p < efficiencies.size(); p++)
627  {
628  if(verbose)std::cout << "\n" << efficiencies[p].first << " " << efficiencies[p].second;
629 
630  if(efficiencies[p].first == "e-") efficiencies[p].first = "e";
631 
632  // it is possible that the efficiency is specified for a species we are not
633  // modeling - so only add the efficiency if it is included in our list
634  if( chem_mixture.species_name_map().count( efficiencies[p].first ) )
635  {
636  my_rxn->set_efficiency( efficiencies[p].first,
637  chem_mixture.species_name_map().find( efficiencies[p].first )->second,
638  efficiencies[p].second );
639  }
640  }
641  if(verbose)std::cout << std::endl;
642  }
643 
644  //F parameters only for Troe falloff
645  if(parser->Troe())
646  {
649 
652 
653  Units<NumericType> def_unit;
654  NumericType par_value(-1.);
655  std::string par_unit;
656  std::string default_unit;
657  std::vector<std::string> accepted_unit;
658 
659  // alpha
660  if(!parser->Troe_alpha_parameter(par_value,par_unit,default_unit))
661  {
662  std::cerr << "alpha parameter of Troe falloff missing!" << std::endl;
663  antioch_error();
664  }
665  accepted_unit.clear();
666  accepted_unit.push_back("");
667  def_unit.set_unit(default_unit);
668  verify_unit_of_parameter(def_unit, par_unit, accepted_unit, my_fall_rxn->equation(), "alpha");
669  my_fall_rxn->F().set_alpha(par_value * def_unit.get_SI_factor());
670 
671  // T***
672  if(!parser->Troe_T3_parameter(par_value,par_unit,default_unit))
673  {
674  std::cerr << "T*** parameter of Troe falloff missing!" << std::endl;
675  antioch_error();
676  }
677  accepted_unit.clear();
678  accepted_unit.push_back("K");
679  def_unit.set_unit(default_unit);
680  verify_unit_of_parameter(def_unit, par_unit, accepted_unit, my_fall_rxn->equation(), "T***");
681  my_fall_rxn->F().set_T3(par_value * def_unit.get_SI_factor());
682 
683  // T*
684  if(!parser->Troe_T1_parameter(par_value,par_unit,default_unit))
685  {
686  std::cerr << "T* parameter of Troe falloff missing!" << std::endl;
687  antioch_error();
688  }
689  // accepted unit is the same
690  def_unit.set_unit(default_unit);
691  verify_unit_of_parameter(def_unit, par_unit, accepted_unit, my_fall_rxn->equation(), "T*");
692  my_fall_rxn->F().set_T1(par_value * def_unit.get_SI_factor());
693 
694  // T** is optional
695  if(parser->Troe_T2_parameter(par_value,par_unit,default_unit))
696  {
697  def_unit.set_unit(default_unit);
698  verify_unit_of_parameter(def_unit, par_unit, accepted_unit, my_fall_rxn->equation(), "T**");
699  my_fall_rxn->F().set_T2(par_value * def_unit.get_SI_factor());
700  }
701  }
702 
703  reaction_set.add_reaction(my_rxn);
704 
705  if(verbose) std::cout << "\n\n";
706  }
707 
708  if(parser)
709  delete parser;
710  }
711 
712  // Instantiate
714 
715 } // end namespace Antioch
bool is_united() const
Test if the unit is non empty.
Definition: units.h:298
#define antioch_assert(asserted)
void add_reactant(const std::string &name, const unsigned int r_id, const unsigned int stoichiometric_coeff, const CoeffType partial_order=std::numeric_limits< CoeffType >::infinity())
Definition: reaction.h:588
virtual const std::string reaction_kinetics_model(const std::vector< std::string > &) const
Definition: parser_base.h:179
A single reaction mechanism.
Definition: reaction.h:108
#define antioch_unit_required(parameter, defaultunit)
const std::string get_symbol() const
String symbol getter.
Definition: units.h:330
virtual bool Troe_T1_parameter(NumericType &, std::string &, std::string &) const
Definition: parser_base.h:233
#define antioch_not_implemented()
This class encapsulates all the reaction mechanisms considered in a chemical nonequilibrium simulatio...
const std::string & equation() const
Definition: reaction.h:410
base class for kinetics models
Definition: kinetics_type.h:82
#define antioch_assert_equal_to(expr1, expr2)
virtual const std::string reaction_chemical_process() const
Definition: parser_base.h:176
virtual bool rate_constant_lambda_parameter(std::vector< NumericType > &, std::string &, std::string &) const
Definition: parser_base.h:218
virtual const std::map< std::string, NumericType > reactants_orders() const
return a map between reactants' name and found partial orders
Definition: parser_base.h:191
virtual bool initialize()=0
void set_id(const std::string &id)
set the reaction id.
Definition: reaction.h:403
#define antioch_parameter_required(parameter, defaultpar)
virtual bool rate_constant_Berthelot_coefficient_parameter(NumericType &, std::string &, std::string &) const
Definition: parser_base.h:212
virtual bool Troe_T2_parameter(NumericType &, std::string &, std::string &) const
Definition: parser_base.h:236
virtual bool rate_constant_activation_energy_parameter(NumericType &, std::string &, std::string &) const
Definition: parser_base.h:209
#define antioch_error()
virtual bool rate_constant_power_parameter(NumericType &, std::string &, std::string &) const
Definition: parser_base.h:206
ANTIOCH_READ_REACTION_SET_DATA_INSTANTIATE()
virtual unsigned int where_is_k0(const std::string &) const
Definition: parser_base.h:200
void set_unit(const std::string &sym, std::string na)
Units setter, sets the unit to the given symbol and name.
Definition: units.h:1144
virtual const std::map< std::string, NumericType > products_orders() const
return a map between products' name and found partial orders
Definition: parser_base.h:194
virtual bool rate_constant_preexponential_parameter(NumericType &, std::string &, std::string &) const
Definition: parser_base.h:203
Base class for falloff processes.
virtual bool Troe_T3_parameter(NumericType &, std::string &, std::string &) const
Definition: parser_base.h:239
T get_SI_factor() const
Multiplicative coefficient getter.
Definition: units.h:334
virtual bool rate_constant_Tref_parameter(NumericType &, std::string &, std::string &) const
Definition: parser_base.h:215
#define antioch_unit_error(description)
unsigned int n_rate_constants() const
Return the number of rate constant objects.
Definition: reaction.h:477
virtual bool Troe() const
Definition: parser_base.h:167
const std::map< std::string, Species > & species_name_map() const
virtual bool reactants_pairs(std::vector< std::pair< std::string, int > > &) const
Definition: parser_base.h:185
T factor_to_some_unit(const Units< T > &target) const
Calculates the factor to any given unit.
Definition: units.h:755
virtual const std::string reaction_id() const
Definition: parser_base.h:170
void add_forward_rate(KineticsType< CoeffType, VectorCoeffType > *rate)
Add a forward rate object.
Definition: reaction.h:469
virtual bool rate_constant(const std::string &)
go to next rate constant
Definition: parser_base.h:162
unsigned int n_species() const
Returns the number of species in this mixture.
virtual const std::string reaction_equation() const
Definition: parser_base.h:173
Advanced unit class.
const ChemicalMixture< CoeffType > & chemical_mixture() const
Definition: reaction_set.h:248
void add_product(const std::string &name, const unsigned int p_id, const unsigned int stoichiometric_coeff, const CoeffType partial_order=std::numeric_limits< CoeffType >::infinity())
Definition: reaction.h:605
void clear()
Clear the unit.
Definition: units.h:390
Nothing is stored, this parser is based on the tinyxml2 implementation.
virtual bool efficiencies(std::vector< std::pair< std::string, NumericType > > &) const
Definition: parser_base.h:227
#define antioch_parsing_error(description)
bool is_homogeneous(const Units< T > &rhs) const
Homogenity testing with another Units.
Definition: units.h:892
Class storing chemical mixture properties.
ReactionType::ReactionType type() const
Type of reaction.
Definition: reaction.h:417
void read_reaction_set_data(const std::string &filename, const bool verbose, ReactionSet< NumericType > &reaction_set, ParsingType type=ASCII)
The parameters are reduced parameters.
virtual bool verify_Kooij_in_place_of_Arrhenius() const
Definition: parser_base.h:224
#define antioch_do_once(do_this)
An advanced unit class.
Definition: units.h:111
virtual bool Troe_alpha_parameter(NumericType &, std::string &, std::string &) const
Definition: parser_base.h:230
virtual bool rate_constant_cross_section_parameter(std::vector< NumericType > &, std::string &, std::string &) const
Definition: parser_base.h:221
virtual bool reaction_reversible() const
Definition: parser_base.h:182
virtual bool reaction()
reaction
Definition: parser_base.h:159
void set_efficiency(const std::string &, const unsigned int s, const CoeffType efficiency)
Definition: reaction.h:640
virtual bool products_pairs(std::vector< std::pair< std::string, int > > &) const
Definition: parser_base.h:188
void add_reaction(Reaction< CoeffType > *reaction)
Add a reaction to the system.
Definition: reaction_set.h:207
A parser is an instance related to a file.
void swap_forward_rates(unsigned int irate, unsigned int jrate)
Swap two forward rates object.
Definition: reaction.h:484
void verify_unit_of_parameter(Units< NumericType > &default_unit, const std::string &provided_unit, const std::vector< std::string > &accepted_unit, const std::string &equation, const std::string &parameter_name)
void substract(const Units< T > &rhs)
Alternative call to Units& operator-=(const Units &)
Definition: units.h:257
We parse the file here, with an exhaustive unit management.
ChemKin format file reader.
virtual bool is_k0(unsigned int, const std::string &) const
Definition: parser_base.h:197

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