antioch-0.4.0
List of all members | Public Member Functions | Private Member Functions | Private Attributes | Friends
Antioch::ReactionSet< CoeffType > Singleton Reference

This class encapsulates all the reaction mechanisms considered in a chemical nonequilibrium simulation. More...

#include <kinetics_evaluator.h>

Public Member Functions

 ReactionSet (const ChemicalMixture< CoeffType > &chem_mixture)
 Constructor. More...
 
 ~ReactionSet ()
 
unsigned int n_species () const
 
unsigned int n_reactions () const
 
void add_reaction (Reaction< CoeffType > *reaction)
 Add a reaction to the system. More...
 
void remove_reaction (unsigned int nr)
 remove a reaction from the system. More...
 
const Reaction< CoeffType > & reaction (const unsigned int r) const
 
Reaction< CoeffType > & reaction (const unsigned int r)
 
unsigned int reaction_by_id (const std::string &reaction_id) const
 
template<typename ParamType >
void set_parameter_of_reaction (const std::string &reaction_id, const std::vector< std::string > &keywords, ParamType value)
 change a parameter of a reaction More...
 
CoeffType get_parameter_of_reaction (const std::string &reaction_id, const std::vector< std::string > &keywords) const
 
const ChemicalMixture
< CoeffType > & 
chemical_mixture () const
 
template<typename StateType , typename VectorStateType , typename VectorReactionsType >
void compute_reaction_rates (const KineticsConditions< StateType, VectorStateType > &conditions, const VectorStateType &molar_densities, const VectorStateType &h_RT_minus_s_R, VectorReactionsType &net_reaction_rates) const
 Compute the rates of progress for each reaction. More...
 
template<typename StateType , typename VectorStateType , typename VectorReactionsType , typename MatrixReactionsType >
void compute_reaction_rates_and_derivs (const KineticsConditions< StateType, VectorStateType > &conditions, const VectorStateType &molar_densities, const VectorStateType &h_RT_minus_s_R, const VectorStateType &dh_RT_minus_s_R_dT, VectorReactionsType &net_reaction_rates, VectorReactionsType &dnet_rate_dT, MatrixReactionsType &dnet_rate_dX_s) const
 Compute the rates of progress and derivatives for each reaction. More...
 
template<typename StateType , typename VectorStateType >
void print_chemical_scheme (std::ostream &output, const KineticsConditions< StateType, VectorStateType > &conditions, const VectorStateType &molar_densities, const VectorStateType &h_RT_minus_s_R, std::vector< VectorStateType > &lossMatrix, std::vector< VectorStateType > &prodMatrix, std::vector< VectorStateType > &netMatrix) const
 
template<typename StateType , typename VectorStateType >
void get_reactive_scheme (const KineticsConditions< StateType, VectorStateType > &conditions, const VectorStateType &molar_densities, const VectorStateType &h_RT_minus_s_R, VectorStateType &net_rates, VectorStateType &kfwd_const, VectorStateType &kbkwd_const, VectorStateType &kfwd, VectorStateType &kbkwd, VectorStateType &fwd_conc, VectorStateType &bkwd_conc) const
 
void print (std::ostream &os=std::cout) const
 Formatted print, by default to std::cout. More...
 

Private Member Functions

 ReactionSet ()
 
void find_kinetics_model_parameter (const unsigned int r, const std::vector< std::string > &keywords, unsigned int &nr, std::string &unit, int &l) const
 helper function More...
 
void find_chemical_process_parameter (ReactionType::Parameters paramChem, const std::vector< std::string > &keywords, unsigned int &species) const
 helper function More...
 

Private Attributes

const ChemicalMixture
< CoeffType > & 
_chem_mixture
 
std::vector< Reaction
< CoeffType > * > 
_reactions
 
const CoeffType _P0_R
 Scaling for equilibrium constant. More...
 

Friends

std::ostream & operator<< (std::ostream &os, const ReactionSet< CoeffType > &rset)
 Formatted print. More...
 

Detailed Description

template<typename CoeffType = double>
singleton Antioch::ReactionSet< CoeffType >

This class encapsulates all the reaction mechanisms considered in a chemical nonequilibrium simulation.

Definition at line 42 of file kinetics_evaluator.h.

Constructor & Destructor Documentation

template<typename CoeffType >
Antioch::ReactionSet< CoeffType >::ReactionSet ( const ChemicalMixture< CoeffType > &  chem_mixture)
inline

Constructor.

Definition at line 256 of file reaction_set.h.

257  : _chem_mixture(chem_mixture),
258  _P0_R(1.0e5/Constants::R_universal<CoeffType>()) //SI
259  {
260  return;
261  }
const CoeffType _P0_R
Scaling for equilibrium constant.
Definition: reaction_set.h:186
const ChemicalMixture< CoeffType > & _chem_mixture
Definition: reaction_set.h:181
template<typename CoeffType >
Antioch::ReactionSet< CoeffType >::~ReactionSet ( )
inline

Definition at line 266 of file reaction_set.h.

267  {
268  for(unsigned int ir = 0; ir < _reactions.size(); ir++)delete _reactions[ir];
269  return;
270  }
std::vector< Reaction< CoeffType > * > _reactions
Definition: reaction_set.h:183
template<typename CoeffType = double>
Antioch::ReactionSet< CoeffType >::ReactionSet ( )
private

Member Function Documentation

template<typename CoeffType >
void Antioch::ReactionSet< CoeffType >::add_reaction ( Reaction< CoeffType > *  reaction)
inline

Add a reaction to the system.

Definition at line 207 of file reaction_set.h.

Referenced by Antioch::read_reaction_set_data().

208  {
209  _reactions.push_back(reaction);
210 
211  // and make sure it is initialized!
212  _reactions.back()->initialize(_reactions.size() - 1);
213 
214  return;
215  }
std::vector< Reaction< CoeffType > * > _reactions
Definition: reaction_set.h:183
template<typename CoeffType >
const ChemicalMixture< CoeffType > & Antioch::ReactionSet< CoeffType >::chemical_mixture ( ) const
inline

Definition at line 248 of file reaction_set.h.

Referenced by Antioch::read_reaction_set_data().

249  {
250  return _chem_mixture;
251  }
const ChemicalMixture< CoeffType > & _chem_mixture
Definition: reaction_set.h:181
template<typename CoeffType >
template<typename StateType , typename VectorStateType , typename VectorReactionsType >
void Antioch::ReactionSet< CoeffType >::compute_reaction_rates ( const KineticsConditions< StateType, VectorStateType > &  conditions,
const VectorStateType &  molar_densities,
const VectorStateType &  h_RT_minus_s_R,
VectorReactionsType &  net_reaction_rates 
) const
inline

Compute the rates of progress for each reaction.

Todo:
Make these assertions vector-compatible

Definition at line 275 of file reaction_set.h.

References antioch_assert_equal_to, and Antioch::KineticsConditions< StateType, VectorStateType >::T().

279  {
280  antioch_assert_equal_to( net_reaction_rates.size(), this->n_reactions() );
281 
283  // antioch_assert_greater(T, 0.0);
284 
285  antioch_assert_equal_to( molar_densities.size(), this->n_species() );
286  antioch_assert_equal_to( h_RT_minus_s_R.size(), this->n_species() );
287 
288  // useful constants
289  const StateType P0_RT = _P0_R/conditions.T(); // used to transform equilibrium constant from pressure units
290 
291  // compute reaction forward rates & other reaction-sized arrays
292  for (unsigned int rxn=0; rxn<this->n_reactions(); rxn++)
293  {
294  net_reaction_rates[rxn] = this->reaction(rxn).compute_rate_of_progress(molar_densities, conditions, P0_RT, h_RT_minus_s_R);
295  }
296 
297  return;
298  }
#define antioch_assert_equal_to(expr1, expr2)
const Reaction< CoeffType > & reaction(const unsigned int r) const
Definition: reaction_set.h:232
unsigned int n_species() const
Definition: reaction_set.h:193
StateType compute_rate_of_progress(const VectorStateType &molar_densities, const KineticsConditions< StateType, VectorStateType > &conditions, const StateType &P0_RT, const VectorStateType &h_RT_minus_s_R) const
Definition: reaction.h:1020
unsigned int n_reactions() const
Definition: reaction_set.h:200
const CoeffType _P0_R
Scaling for equilibrium constant.
Definition: reaction_set.h:186
template<typename CoeffType >
template<typename StateType , typename VectorStateType , typename VectorReactionsType , typename MatrixReactionsType >
void Antioch::ReactionSet< CoeffType >::compute_reaction_rates_and_derivs ( const KineticsConditions< StateType, VectorStateType > &  conditions,
const VectorStateType &  molar_densities,
const VectorStateType &  h_RT_minus_s_R,
const VectorStateType &  dh_RT_minus_s_R_dT,
VectorReactionsType &  net_reaction_rates,
VectorReactionsType &  dnet_rate_dT,
MatrixReactionsType &  dnet_rate_dX_s 
) const
inline

Compute the rates of progress and derivatives for each reaction.

Todo:
Make these assertions vector-compatible

Definition at line 303 of file reaction_set.h.

References antioch_assert_equal_to, and Antioch::KineticsConditions< StateType, VectorStateType >::T().

310  {
311  antioch_assert_equal_to( net_reaction_rates.size(), this->n_reactions() );
312  antioch_assert_equal_to( dnet_rate_dT.size(), this->n_reactions() );
313  antioch_assert_equal_to( dnet_rate_dX_s.size(), this->n_reactions() );
314 #ifdef NDEBUG
315 #else
316  for (unsigned int r=0; r < this->n_reactions(); r++)
317  {
318  antioch_assert_equal_to( dnet_rate_dX_s[r].size(), this->n_species() );
319  }
320 #endif
321 
323  // antioch_assert_greater(T, 0.0);
324 
325  antioch_assert_equal_to( molar_densities.size(), this->n_species() );
326  antioch_assert_equal_to( h_RT_minus_s_R.size(), this->n_species() );
327 
328  // useful constants
329  const StateType P0_RT = _P0_R/conditions.T(); // used to transform equilibrium constant from pressure units
330 
331  // compute reaction forward rates & other reaction-sized arrays
332  for (unsigned int rxn=0; rxn<this->n_reactions(); rxn++)
333  {
335  conditions, P0_RT, h_RT_minus_s_R, dh_RT_minus_s_R_dT,
336  net_reaction_rates[rxn],
337  dnet_rate_dT[rxn],
338  dnet_rate_dX_s[rxn] );
339  }
340 
341  return;
342  }
#define antioch_assert_equal_to(expr1, expr2)
const Reaction< CoeffType > & reaction(const unsigned int r) const
Definition: reaction_set.h:232
unsigned int n_species() const
Definition: reaction_set.h:193
unsigned int n_reactions() const
Definition: reaction_set.h:200
void compute_rate_of_progress_and_derivatives(const VectorStateType &molar_densities, const ChemicalMixture< CoeffType > &, const KineticsConditions< StateType, VectorStateType > &conditions, const StateType &P0_RT, const VectorStateType &h_RT_minus_s_R, const VectorStateType &dh_RT_minus_s_R_dT, StateType &net_reaction_rate, StateType &dnet_rate_dT, VectorStateType &dnet_rate_dX_s) const
Definition: reaction.h:1075
const CoeffType _P0_R
Scaling for equilibrium constant.
Definition: reaction_set.h:186
const ChemicalMixture< CoeffType > & _chem_mixture
Definition: reaction_set.h:181
template<typename CoeffType >
void Antioch::ReactionSet< CoeffType >::find_chemical_process_parameter ( ReactionType::Parameters  paramChem,
const std::vector< std::string > &  keywords,
unsigned int &  species 
) const
inlineprivate

helper function

Definition at line 438 of file reaction_set.h.

References antioch_assert_greater, antioch_error, and Antioch::ReactionType::EFFICIENCIES.

439  {
440 // there's not really a unit issue here:
441 // * efficiencies: unitless
442 // * Troe alpha: unitless
443 // * Troe T*: temperature, if it's other than K, you're a bad (like really really bad) scientist, get off my library
444 // * Troe T**: temperature, see above
445 // * Troe T***: temperature, do I really need to say anything?
446 
447  if(paramChem == ReactionType::Parameters::EFFICIENCIES) // who?
448  {
449  antioch_assert_greater(keywords.size(),1); // we need a name
450 
451  if(!this->chemical_mixture().species_name_map().count(keywords[1]))
452  antioch_error(); //who's this?
453 
454  species = this->chemical_mixture().species_name_map().at(keywords[1]);
455  }
456 
457  return;
458  }
#define antioch_assert_greater(expr1, expr2)
#define antioch_error()
const ChemicalMixture< CoeffType > & chemical_mixture() const
Definition: reaction_set.h:248
template<typename CoeffType >
void Antioch::ReactionSet< CoeffType >::find_kinetics_model_parameter ( const unsigned int  r,
const std::vector< std::string > &  keywords,
unsigned int &  nr,
std::string &  unit,
int &  l 
) const
inlineprivate

helper function

Definition at line 374 of file reaction_set.h.

References antioch_error, Antioch::ReactionType::DUPLICATE, Antioch::ReactionType::ELEMENTARY, Antioch::KineticsModel::HIGH_PRESSURE, Antioch::ReactionType::LINDEMANN_FALLOFF, Antioch::ReactionType::LINDEMANN_FALLOFF_THREE_BODY, Antioch::KineticsModel::LOW_PRESSURE, Antioch::KineticsModel::PHOTOCHEM, Antioch::string_to_kin_enum(), Antioch::ReactionType::TROE_FALLOFF, and Antioch::ReactionType::TROE_FALLOFF_THREE_BODY.

375  {
376 // now we need to know a few things:
377 // if we are in a falloff or duplicate, next keyword is which rate we want, then unit
378 // if we are in an elementary photochemistry, next keyword is which index of sigma or lamba we want, then unit
379 // else we may have a unit
380  switch(this->reaction(r).type())
381  {
383  {
384  nr = std::stoi(keywords[1]); // C++11, throws an exception on error
385  if(keywords.size() > 2)unit = keywords[2];
386  }
387  break;
392  {
393  switch(string_to_kin_enum(keywords[1])) // falloff, if here by error, NOT_FOUND is get (0)
394  {
395  // This is hard-coded (because we want a vector and not a map)
396  // low pressure is the first, high pressure the second
397  // see FalloffReaction object
399  {
400  nr = 0;
401  }
402  break;
404  {
405  nr = 1;
406  }
407  break;
408  default: // ?
409  {
410  antioch_error();
411  }
412  break;
413  }
414  if(keywords.size() > 2)unit = keywords[2]; // unit baby!
415  }
416  break;
417  case ReactionType::ELEMENTARY: // photochem only
418  {
420  {
421  l = std::stoi(keywords[1]); // C++11, throws an exception on error
422  if(keywords.size() > 2)unit = keywords[2];
423  }
424  }
425  break;
426  default:
427  {
428  if(keywords.size() > 1)unit = keywords[1]; // unit baby!
429  }
430  break;
431  }
432 
433  return;
434  }
const Reaction< CoeffType > & reaction(const unsigned int r) const
Definition: reaction_set.h:232
#define antioch_error()
KineticsModel::Parameters string_to_kin_enum(const std::string &str)
Definition: string_utils.h:192
KineticsModel::KineticsModel kinetics_model() const
Model of kinetics.
Definition: reaction.h:440
template<typename CoeffType >
CoeffType Antioch::ReactionSet< CoeffType >::get_parameter_of_reaction ( const std::string &  reaction_id,
const std::vector< std::string > &  keywords 
) const
inline
Returns
a parameter of a reaction

Definition at line 462 of file reaction_set.h.

References antioch_assert, antioch_error, std::max(), Antioch::KineticsModel::NOT_FOUND, Antioch::set_zero(), Antioch::string_to_chem_enum(), and Antioch::string_to_kin_enum().

Referenced by tester().

463  {
464  antioch_assert(keywords.size()); // not zero
465 
466  CoeffType parameter;
467  // when CoeffType is vectorizable, we want
468  // to have as little rewriting as possible
469  set_zero(parameter);
470 
471  unsigned int r = this->reaction_by_id(reaction_id);
472 
473  // 1 parse high level
474  KineticsModel::Parameters paramKin = string_to_kin_enum(keywords[0]);
475  ReactionType::Parameters paramChem = string_to_chem_enum(keywords[0]);
476 
477 // provide the necessary enum,
478 // index of reaction rate if kinetics
479 // index of species if chemical
481  {
482  // which rate? Duplicate want an unsigned int, falloff a keyword
483  unsigned int nr(0); // default is one rate
484  std::string unit("SI"); // default internal parameter unit system
485  int l(-1); // if vectorized parameter
486 
487  this->find_kinetics_model_parameter(r,keywords,nr,unit,l);
488 
489  // let's get this
490  parameter = reaction(r).get_parameter_of_rate(paramKin, nr, unit);
491 
492  }else if(paramChem != ReactionType::Parameters::NOT_FOUND)
493  {
494  unsigned int species = std::numeric_limits<unsigned int>::max(); // sensible default
495 
496  this->find_chemical_process_parameter(paramChem, keywords, species);
497 
498  // let's get this
499  parameter = reaction(r).get_parameter_of_chemical_process(paramChem, species);
500  }else
501  {
502  antioch_error();
503  }
504 
505  return parameter;
506 
507  }
#define antioch_assert(asserted)
CoeffType get_parameter_of_chemical_process(ReactionType::Parameters parameter, unsigned int species=std::numeric_limits< unsigned int >::max()) const
get a parameter from the chemical process
Definition: reaction.h:1415
const Reaction< CoeffType > & reaction(const unsigned int r) const
Definition: reaction_set.h:232
#define antioch_error()
max(const _Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &a, const _Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &b) ANTIOCH_AUTOFUNC(_Matrix< _Scalar ANTIOCH_COMMA _Rows ANTIOCH_COMMA _Cols ANTIOCH_COMMA _Options ANTIOCH_COMMA _MaxRows ANTIOCH_COMMA _MaxCols >
KineticsModel::Parameters string_to_kin_enum(const std::string &str)
Definition: string_utils.h:192
unsigned int reaction_by_id(const std::string &reaction_id) const
Definition: reaction_set.h:347
void find_chemical_process_parameter(ReactionType::Parameters paramChem, const std::vector< std::string > &keywords, unsigned int &species) const
helper function
Definition: reaction_set.h:438
CoeffType get_parameter_of_rate(KineticsModel::Parameters parameter, unsigned int n_reaction=0, const std::string &unit="SI") const
get a parameter from the rate constant
Definition: reaction.h:1320
void set_zero(_Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &a)
Definition: eigen_utils.h:217
void find_kinetics_model_parameter(const unsigned int r, const std::vector< std::string > &keywords, unsigned int &nr, std::string &unit, int &l) const
helper function
Definition: reaction_set.h:374
ReactionType::Parameters string_to_chem_enum(const std::string &str)
Definition: string_utils.h:232
template<typename CoeffType >
template<typename StateType , typename VectorStateType >
void Antioch::ReactionSet< CoeffType >::get_reactive_scheme ( const KineticsConditions< StateType, VectorStateType > &  conditions,
const VectorStateType &  molar_densities,
const VectorStateType &  h_RT_minus_s_R,
VectorStateType &  net_rates,
VectorStateType &  kfwd_const,
VectorStateType &  kbkwd_const,
VectorStateType &  kfwd,
VectorStateType &  kbkwd,
VectorStateType &  fwd_conc,
VectorStateType &  bkwd_conc 
) const
inline
Todo:
Make these assertions vector-compatible

Definition at line 802 of file reaction_set.h.

References antioch_assert_equal_to, Antioch::Reaction< CoeffType, VectorCoeffType >::compute_forward_rate_coefficient(), Antioch::Reaction< CoeffType, VectorCoeffType >::equilibrium_constant(), Antioch::Reaction< CoeffType, VectorCoeffType >::n_products(), Antioch::Reaction< CoeffType, VectorCoeffType >::n_reactants(), std::pow(), Antioch::Reaction< CoeffType, VectorCoeffType >::product_id(), Antioch::Reaction< CoeffType, VectorCoeffType >::product_partial_order(), Antioch::Reaction< CoeffType, VectorCoeffType >::reactant_id(), Antioch::Reaction< CoeffType, VectorCoeffType >::reactant_partial_order(), Antioch::Reaction< CoeffType, VectorCoeffType >::reversible(), and Antioch::KineticsConditions< StateType, VectorStateType >::T().

Referenced by tester().

812  {
814  // antioch_assert_greater(T, 0.0);
815 
816  antioch_assert_equal_to( molar_densities.size(), this->n_species() );
817  antioch_assert_equal_to( h_RT_minus_s_R.size(), this->n_species() );
818 
819  // useful constants
820  const StateType P0_RT = _P0_R/conditions.T(); // used to transform equilibrium constant from pressure units
821 
822  net_rates.resize(this->n_reactions(),0);
823  kfwd_const.resize(this->n_reactions(),0);
824  kfwd.resize(this->n_reactions(),0);
825  kbkwd_const.resize(this->n_reactions(),0);
826  kbkwd.resize(this->n_reactions(),0);
827  fwd_conc.resize(this->n_reactions(),1);
828  bkwd_conc.resize(this->n_reactions(),1);
829 
830  // compute reaction forward rates & other reaction-sized arrays
831  for (unsigned int rxn=0; rxn<this->n_reactions(); rxn++)
832  {
833  const Reaction<CoeffType>& reaction = this->reaction(rxn);
834  kfwd_const[rxn] = reaction.compute_forward_rate_coefficient(molar_densities,conditions);
835  kfwd[rxn] = kfwd_const[rxn];
836 
837  for (unsigned int r=0; r<reaction.n_reactants(); r++)
838  {
839  fwd_conc[rxn] *= pow( molar_densities[reaction.reactant_id(r)],
840  reaction.reactant_partial_order(r));
841  }
842  kfwd[rxn] *= fwd_conc[rxn];
843 
844  if(reaction.reversible())
845  {
846  StateType keq = reaction.equilibrium_constant( P0_RT, h_RT_minus_s_R );
847 
848  kbkwd_const[rxn] = kfwd_const[rxn]/keq;
849  kbkwd[rxn] = kbkwd_const[rxn];
850  for (unsigned int p=0; p<reaction.n_products(); p++)
851  {
852  bkwd_conc[rxn] *= pow( molar_densities[reaction.product_id(p)],
853  reaction.product_partial_order(p));
854  }
855  kbkwd[rxn] *= bkwd_conc[rxn];
856  }
857 
858  net_rates[rxn] = kfwd[rxn] - kbkwd[rxn];
859 
860  }
861 
862  return;
863  }
#define antioch_assert_equal_to(expr1, expr2)
const Reaction< CoeffType > & reaction(const unsigned int r) const
Definition: reaction_set.h:232
Antioch::enable_if_c< Antioch::is_valarray< T >::value, typename Antioch::state_type< T >::type >::type pow(const T &in, const T2 &n)
unsigned int n_species() const
Definition: reaction_set.h:193
unsigned int n_reactions() const
Definition: reaction_set.h:200
const CoeffType _P0_R
Scaling for equilibrium constant.
Definition: reaction_set.h:186
template<typename CoeffType >
unsigned int Antioch::ReactionSet< CoeffType >::n_reactions ( ) const
inline
Returns
the number of reactions.

Definition at line 200 of file reaction_set.h.

Referenced by tester().

201  {
202  return _reactions.size();
203  }
std::vector< Reaction< CoeffType > * > _reactions
Definition: reaction_set.h:183
template<typename CoeffType >
unsigned int Antioch::ReactionSet< CoeffType >::n_species ( ) const
inline
Returns
the number of species.

Definition at line 193 of file reaction_set.h.

Referenced by Antioch::KineticsEvaluator< CoeffType, StateType >::KineticsEvaluator().

194  {
195  return _chem_mixture.n_species();
196  }
const ChemicalMixture< CoeffType > & _chem_mixture
Definition: reaction_set.h:181
template<typename CoeffType >
void Antioch::ReactionSet< CoeffType >::print ( std::ostream &  os = std::cout) const
inline

Formatted print, by default to std::cout.

Definition at line 868 of file reaction_set.h.

869  {
870  os << "# Number of reactions: " << this->n_reactions() << "\n";
871 
872  for (unsigned int r=0; r < this->n_reactions(); r++)
873  {
874  os << "# " << r << '\n'
875  << (this->reaction(r)) << "\n";
876  }
877 
878  return;
879  }
const Reaction< CoeffType > & reaction(const unsigned int r) const
Definition: reaction_set.h:232
unsigned int n_reactions() const
Definition: reaction_set.h:200
template<typename CoeffType >
template<typename StateType , typename VectorStateType >
void Antioch::ReactionSet< CoeffType >::print_chemical_scheme ( std::ostream &  output,
const KineticsConditions< StateType, VectorStateType > &  conditions,
const VectorStateType &  molar_densities,
const VectorStateType &  h_RT_minus_s_R,
std::vector< VectorStateType > &  lossMatrix,
std::vector< VectorStateType > &  prodMatrix,
std::vector< VectorStateType > &  netMatrix 
) const
inline

Definition at line 556 of file reaction_set.h.

References Antioch::Reaction< CoeffType, VectorCoeffType >::n_products(), Antioch::Reaction< CoeffType, VectorCoeffType >::n_reactants(), Antioch::Reaction< CoeffType, VectorCoeffType >::product_id(), Antioch::Reaction< CoeffType, VectorCoeffType >::product_stoichiometric_coefficient(), Antioch::Reaction< CoeffType, VectorCoeffType >::reactant_id(), and Antioch::Reaction< CoeffType, VectorCoeffType >::reactant_stoichiometric_coefficient().

Referenced by tester_N2N().

563  {
564 
565  //filling matrixes
566  VectorStateType netRate,kfwd_const,kbkwd_const,kfwd,kbkwd,fwd_conc,bkwd_conc;
567 
568  //getting reaction infos
569  get_reactive_scheme(conditions,molar_densities,h_RT_minus_s_R,netRate,kfwd_const,kbkwd_const,kfwd,kbkwd,fwd_conc,bkwd_conc);
570 
571  lossMatrix.resize(this->n_species());
572  prodMatrix.resize(this->n_species());
573  netMatrix.resize(this->n_species());
574 
575  for(unsigned int s = 0; s < this->n_species(); s++)
576  {
577  lossMatrix[s].resize(this->n_reactions(),0.);
578  prodMatrix[s].resize(this->n_reactions(),0.);
579  netMatrix[s].resize(this->n_reactions(),0.);
580  }
581 
582 
583  //filling matrixes
584  for(unsigned int rxn = 0; rxn < this->n_reactions(); rxn++)
585  {
586  const Reaction<CoeffType>& reaction = this->reaction(rxn);
587  for (unsigned int r=0; r<reaction.n_reactants(); r++)
588  {
589  lossMatrix[reaction.reactant_id(r)][rxn] += - static_cast<CoeffType>(reaction.reactant_stoichiometric_coefficient(r)) * kfwd[rxn];
590  prodMatrix[reaction.reactant_id(r)][rxn] += static_cast<CoeffType>(reaction.reactant_stoichiometric_coefficient(r)) * kbkwd[rxn];
591  netMatrix[reaction.reactant_id(r)][rxn] += lossMatrix[reaction.reactant_id(r)][rxn] + prodMatrix[reaction.reactant_id(r)][rxn];
592  }
593  for (unsigned int p=0; p<reaction.n_products(); p++)
594  {
595  lossMatrix[reaction.product_id(p)][rxn] += - static_cast<CoeffType>(reaction.product_stoichiometric_coefficient(p)) * kbkwd[rxn];
596  prodMatrix[reaction.product_id(p)][rxn] += static_cast<CoeffType>(reaction.product_stoichiometric_coefficient(p)) * kfwd[rxn];
597  netMatrix[reaction.product_id(p)][rxn] += lossMatrix[reaction.product_id(p)][rxn] + prodMatrix[reaction.product_id(p)][rxn];
598  }
599  }
600 
601  //explanation of header
602  output << "# molar units considered for those budgets (kmol, m3, s)" << std::endl;
603  output << "# formatted as follow:" << std::endl;
604  output << "# rows: species, columns: reactions" << std::endl;
605  output << "#" << std::endl;
606  output << "# | equation" << std::endl;
607  output << "# | rate coefficient forward , rate coefficient backward" << std::endl;
608  output << "# | forward concentrations , backward concentrations" << std::endl;
609  output << "# | rate forward , rate backward" << std::endl;
610  output << "# ------------------------------------------------------------------" << std::endl;
611  output << "# species | production term , loss term" << std::endl;
612  output << "# species | net production/loss term" << std::endl;
613  output << "#" << std::endl << std::endl;
614 
615 
616  //header
617  // // equation
618  output << std::setw(10) << " ";
619  for(unsigned int rxn = 0; rxn < this->n_reactions(); rxn++)
620  {
621  output << std::setw(31) << this->_reactions[rxn]->equation();
622  }
623  output << std::endl;
624  // // coeffs
625  output << std::setw(10) << " ";
626  for(unsigned int rxn = 0; rxn < this->n_reactions(); rxn++)
627  {
628  output << std::setw(15) << kfwd_const[rxn] << "," << std::setw(15) << kbkwd_const[rxn];
629  }
630  output << std::endl;
631  // // conc
632  output << std::setw(10) << " ";
633  for(unsigned int rxn = 0; rxn < this->n_reactions(); rxn++)
634  {
635  output << std::setw(15) << fwd_conc[rxn] << "," << std::setw(15) << bkwd_conc[rxn];
636  }
637  output << std::endl;
638  // // rates
639  output << std::setw(10) << " ";
640  for(unsigned int rxn = 0; rxn < this->n_reactions(); rxn++)
641  {
642  output << std::setw(15) << kfwd[rxn] << "," << std::setw(15) << kbkwd[rxn];
643  }
644  output << std::endl;
645  output << "----------------------------" << std::endl;
646 
647  //species
648 
649  for(unsigned int isp = 0; isp < this->n_species(); isp++)
650  {
651  output << std::setw(10) << _chem_mixture.chemical_species()[isp]->species();
652  for(unsigned int rxn = 0; rxn < this->n_reactions(); rxn++)
653  {
654  output << std::setw(15) << std::scientific << std::setprecision(6) << prodMatrix[isp][rxn] << ","
655  << std::setw(15) << std::scientific << std::setprecision(6) << lossMatrix[isp][rxn];
656  }
657  output << std::endl;
658  // // net
659  output << std::setw(10) << "";
660  for(unsigned int rxn = 0; rxn < this->n_reactions(); rxn++)
661  {
662  output << std::setw(31) << std::scientific << std::setprecision(16) << netMatrix[isp][rxn];
663  }
664  output << std::endl;
665  }
666  output << std::endl;
667  output << std::endl;
668  output << std::endl;
669 
670  output << "# production table" << std::endl << std::endl;
671  //header
672  // // equation
673  output << std::setw(10) << " ";
674  for(unsigned int rxn = 0; rxn < this->n_reactions(); rxn++)
675  {
676  output << std::setw(31) << this->_reactions[rxn]->equation();
677  }
678  output << std::setw(31) << "Total" << std::endl;
679  for(unsigned int isp = 0; isp < this->n_species(); isp++)
680  {
681  output << std::setw(10) << _chem_mixture.chemical_species()[isp]->species();
682  CoeffType rowTotal(0.);
683  for(unsigned int rxn = 0; rxn < this->n_reactions(); rxn++)
684  {
685  output << std::setw(31) << std::scientific << std::setprecision(16) << prodMatrix[isp][rxn];
686  rowTotal += prodMatrix[isp][rxn];
687  }
688  output << std::setw(31) << std::scientific << std::setprecision(16) << rowTotal << std::endl;
689  }
690  output << std::endl << std::endl;
691 
692  output << "# loss table" << std::endl << std::endl;
693  //header
694  // // equation
695  output << std::setw(10) << " ";
696  for(unsigned int rxn = 0; rxn < this->n_reactions(); rxn++)
697  {
698  output << std::setw(31) << this->_reactions[rxn]->equation();
699  }
700  output << std::setw(31) << "Total" << std::endl;
701  for(unsigned int isp = 0; isp < this->n_species(); isp++)
702  {
703  output << std::setw(10) << _chem_mixture.chemical_species()[isp]->species();
704  CoeffType rowTotal(0.);
705  for(unsigned int rxn = 0; rxn < this->n_reactions(); rxn++)
706  {
707  output << std::setw(31) << std::scientific << std::setprecision(16) << lossMatrix[isp][rxn];
708  rowTotal += lossMatrix[isp][rxn];
709  }
710  output << std::setw(31) << std::scientific << std::setprecision(16) << rowTotal << std::endl;
711  }
712  output << std::endl << std::endl;
713 
714  output << "# net table" << std::endl << std::endl;
715  //header
716  // // equation
717  output << std::setw(10) << " ";
718  for(unsigned int rxn = 0; rxn < this->n_reactions(); rxn++)
719  {
720  output << std::setw(31) << this->_reactions[rxn]->equation();
721  }
722  output << std::setw(31) << "Total" << std::endl;
723 
724  CoeffType columnTotal(0.);
725  std::vector<CoeffType> columnSum;
726  columnSum.resize(this->n_reactions(),0.);
727  CoeffType netTotalRow(0.);
728 
729  for(unsigned int isp = 0; isp < this->n_species(); isp++)
730  {
731  output << std::setw(10) << _chem_mixture.chemical_species()[isp]->species();
732  CoeffType rowTotal(0.);
733  for(unsigned int rxn = 0; rxn < this->n_reactions(); rxn++)
734  {
735  output << std::setw(31) << std::scientific << std::setprecision(16) << netMatrix[isp][rxn];
736  rowTotal += netMatrix[isp][rxn];
737  columnSum[rxn] += netMatrix[isp][rxn];
738  }
739  output << std::setw(31) << std::scientific << std::setprecision(16) << rowTotal << std::endl;
740  netTotalRow += rowTotal;
741  }
742  output << std::setw(10) << "Total";
743  for(unsigned int rxn = 0; rxn < this->n_reactions(); rxn++)
744  {
745  output << std::setw(31) << std::scientific << std::setprecision(16) << columnSum[rxn];
746  columnTotal += columnSum[rxn];
747  }
748  output << std::endl << std::endl;
749  output << "sum of row sums: " << std::scientific << std::setprecision(16) << netTotalRow << std::endl;
750  output << "sum of column sums: " << std::scientific << std::setprecision(16) << columnTotal << std::endl << std::endl;
751  output << "# net table, mass here (kg, m3, s)" << std::endl << std::endl;
752  //header
753  // // equation
754  output << std::setw(10) << " ";
755  for(unsigned int rxn = 0; rxn < this->n_reactions(); rxn++)
756  {
757  output << std::setw(31) << this->_reactions[rxn]->equation();
758  }
759  output << std::setw(31) << "Total" << std::endl;
760 
761  columnTotal = 0.;
762  columnSum.resize(this->n_reactions(),0.);
763  netTotalRow = 0.;
764 
765  for(unsigned int isp = 0; isp < this->n_species(); isp++)
766  {
767  output << std::setw(10) << _chem_mixture.chemical_species()[isp]->species();
768  CoeffType rowTotal(0.);
769  for(unsigned int rxn = 0; rxn < this->n_reactions(); rxn++)
770  {
771  output << std::setw(31) << std::scientific << std::setprecision(16) << netMatrix[isp][rxn];
772  rowTotal += netMatrix[isp][rxn] * _chem_mixture.M(isp);
773  columnSum[rxn] += netMatrix[isp][rxn] * _chem_mixture.M(isp);
774  }
775  output << std::setw(31) << std::scientific << std::setprecision(16) << rowTotal << std::endl;
776  netTotalRow += rowTotal;
777  }
778  output << std::setw(10) << "Total";
779  for(unsigned int rxn = 0; rxn < this->n_reactions(); rxn++)
780  {
781  output << std::setw(31) << std::scientific << std::setprecision(16) << columnSum[rxn];
782  columnTotal += columnSum[rxn];
783  }
784  output << std::endl << std::endl;
785 
786  output << std::endl << std::endl;
787  output << "# Mixture informations" << std::endl;
788  output << "# species / concentration / molar mass" << std::endl;
789  for(unsigned int isp = 0; isp < this->n_species(); isp++)
790  {
791  output << std::setw(10) << _chem_mixture.chemical_species()[isp]->species()
792  << std::setw(31) << molar_densities[isp]
793  << std::setw(31) << _chem_mixture.M(isp) << std::endl;
794  }
795 
796  return;
797  }
std::vector< Reaction< CoeffType > * > _reactions
Definition: reaction_set.h:183
const Reaction< CoeffType > & reaction(const unsigned int r) const
Definition: reaction_set.h:232
unsigned int n_species() const
Definition: reaction_set.h:193
unsigned int n_reactions() const
Definition: reaction_set.h:200
const ChemicalMixture< CoeffType > & _chem_mixture
Definition: reaction_set.h:181
void get_reactive_scheme(const KineticsConditions< StateType, VectorStateType > &conditions, const VectorStateType &molar_densities, const VectorStateType &h_RT_minus_s_R, VectorStateType &net_rates, VectorStateType &kfwd_const, VectorStateType &kbkwd_const, VectorStateType &kfwd, VectorStateType &kbkwd, VectorStateType &fwd_conc, VectorStateType &bkwd_conc) const
Definition: reaction_set.h:802
template<typename CoeffType >
const Reaction< CoeffType > & Antioch::ReactionSet< CoeffType >::reaction ( const unsigned int  r) const
inline
Returns
a constant reference to reaction r.

Definition at line 232 of file reaction_set.h.

References antioch_assert_less.

Referenced by tester().

233  {
234  antioch_assert_less(r, this->n_reactions());
235  return *_reactions[r];
236  }
std::vector< Reaction< CoeffType > * > _reactions
Definition: reaction_set.h:183
#define antioch_assert_less(expr1, expr2)
unsigned int n_reactions() const
Definition: reaction_set.h:200
template<typename CoeffType >
Reaction< CoeffType > & Antioch::ReactionSet< CoeffType >::reaction ( const unsigned int  r)
inline
Returns
a writeable reference to reaction r.

Definition at line 240 of file reaction_set.h.

References antioch_assert_less.

241  {
242  antioch_assert_less(r, this->n_reactions());
243  return *_reactions[r];
244  }
std::vector< Reaction< CoeffType > * > _reactions
Definition: reaction_set.h:183
#define antioch_assert_less(expr1, expr2)
unsigned int n_reactions() const
Definition: reaction_set.h:200
template<typename CoeffType >
unsigned int Antioch::ReactionSet< CoeffType >::reaction_by_id ( const std::string &  reaction_id) const
inline
Returns
the index of a reaction given its id

Definition at line 347 of file reaction_set.h.

References antioch_error, and antioch_warning.

348  {
349  unsigned int r(0);
350  for(r = 0; r < this->n_reactions(); r++)
351  {
352  if(this->reaction(r).id() == reaction_id)
353  break;
354  }
355  if(r >= this->n_reactions())
356  {
357  std::string errmsg = "Error: did not find reaction \"" + reaction_id + "\"\nIds are: ";
358  for(r = 0; r < this->n_reactions(); r++)
359  {
360  errmsg += this->reaction(r).id() + ", ";
361  if(r%10 == 0)errmsg += "\n"; // a few formatting is nice
362  }
363  antioch_warning(errmsg);
364  antioch_error();
365  }
366 
367  return r;
368  }
#define antioch_warning(message)
const Reaction< CoeffType > & reaction(const unsigned int r) const
Definition: reaction_set.h:232
const std::string & id() const
Definition: reaction.h:396
#define antioch_error()
unsigned int n_reactions() const
Definition: reaction_set.h:200
template<typename CoeffType >
void Antioch::ReactionSet< CoeffType >::remove_reaction ( unsigned int  nr)
inline

remove a reaction from the system.

Definition at line 219 of file reaction_set.h.

References antioch_assert_less.

220  {
221  antioch_assert_less(nr,_reactions.size());
222 
223  //first clear the memory
224  delete _reactions[nr];
225 
226  //second, release the spot
227  _reactions.erase(_reactions.begin() + nr);
228  }
std::vector< Reaction< CoeffType > * > _reactions
Definition: reaction_set.h:183
#define antioch_assert_less(expr1, expr2)
template<typename CoeffType >
template<typename ParamType >
void Antioch::ReactionSet< CoeffType >::set_parameter_of_reaction ( const std::string &  reaction_id,
const std::vector< std::string > &  keywords,
ParamType  value 
)
inline

change a parameter of a reaction

Definition at line 512 of file reaction_set.h.

References antioch_assert, antioch_error, std::max(), Antioch::KineticsModel::NOT_FOUND, Antioch::string_to_chem_enum(), and Antioch::string_to_kin_enum().

Referenced by tester().

513  {
514  antioch_assert(keywords.size()); // not zero
515 
516  // 1 find the reaction
517  unsigned int r = this->reaction_by_id(reaction_id);
518 
519  // 1 parse high level
520  KineticsModel::Parameters paramKin = string_to_kin_enum(keywords[0]);
521  ReactionType::Parameters paramChem = string_to_chem_enum(keywords[0]);
522 // provide the necessary enum,
523 // index of reaction rate if kinetics
524 // index of species if chemical
526  {
527  // which rate? Duplicate want an unsigned int, falloff a keyword
528  unsigned int nr(0); // default is one rate
529  std::string unit("SI"); // default internal parameter unit system
530  int l(-1); // for vectorized parameter
531 
532  this->find_kinetics_model_parameter(r,keywords,nr,unit,l);
533 
534  // let's set this
535  (l < 0)?this->reaction(r).set_parameter_of_rate(paramKin, value, nr, unit):
536  this->reaction(r).set_parameter_of_rate(paramKin, value, nr, l, unit);
537 
538  }else if(paramChem != ReactionType::Parameters::NOT_FOUND)
539  {
540  unsigned int species = std::numeric_limits<unsigned int>::max(); // sensible default
541 
542  this->find_chemical_process_parameter(paramChem, keywords, species);
543 
544  // let's set this
545  this->reaction(r).set_parameter_of_chemical_process(paramChem, value, species);
546  }else
547  {
548  antioch_error();
549  }
550 
551  }
#define antioch_assert(asserted)
const Reaction< CoeffType > & reaction(const unsigned int r) const
Definition: reaction_set.h:232
void set_parameter_of_rate(KineticsModel::Parameters parameter, CoeffType new_value, unsigned int n_reaction=0, const std::string &unit="SI")
reset a parameter from the rate constant
Definition: reaction.h:1304
#define antioch_error()
max(const _Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &a, const _Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &b) ANTIOCH_AUTOFUNC(_Matrix< _Scalar ANTIOCH_COMMA _Rows ANTIOCH_COMMA _Cols ANTIOCH_COMMA _Options ANTIOCH_COMMA _MaxRows ANTIOCH_COMMA _MaxCols >
void set_parameter_of_chemical_process(ReactionType::Parameters parameter, CoeffType new_value, unsigned int species=std::numeric_limits< unsigned int >::max())
reset a parameter from the chemical process
Definition: reaction.h:1336
KineticsModel::Parameters string_to_kin_enum(const std::string &str)
Definition: string_utils.h:192
unsigned int reaction_by_id(const std::string &reaction_id) const
Definition: reaction_set.h:347
void find_chemical_process_parameter(ReactionType::Parameters paramChem, const std::vector< std::string > &keywords, unsigned int &species) const
helper function
Definition: reaction_set.h:438
void find_kinetics_model_parameter(const unsigned int r, const std::vector< std::string > &keywords, unsigned int &nr, std::string &unit, int &l) const
helper function
Definition: reaction_set.h:374
ReactionType::Parameters string_to_chem_enum(const std::string &str)
Definition: string_utils.h:232

Friends And Related Function Documentation

template<typename CoeffType = double>
std::ostream& operator<< ( std::ostream &  os,
const ReactionSet< CoeffType > &  rset 
)
friend

Formatted print.

Definition at line 153 of file reaction_set.h.

154  {
155  rset.print(os);
156  return os;
157  }

Member Data Documentation

template<typename CoeffType = double>
const ChemicalMixture<CoeffType>& Antioch::ReactionSet< CoeffType >::_chem_mixture
private

Definition at line 181 of file reaction_set.h.

template<typename CoeffType = double>
const CoeffType Antioch::ReactionSet< CoeffType >::_P0_R
private

Scaling for equilibrium constant.

Definition at line 186 of file reaction_set.h.

template<typename CoeffType = double>
std::vector<Reaction<CoeffType>* > Antioch::ReactionSet< CoeffType >::_reactions
private

Definition at line 183 of file reaction_set.h.


The documentation for this singleton was generated from the following files:

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