antioch-0.4.0
Functions
kinetics_reversibility_unit.C File Reference
#include "antioch/vector_utils.h"
#include "antioch/reaction.h"
#include "antioch/reaction_enum.h"
#include "antioch/reaction_parsing.h"
#include "antioch/kinetics_parsing.h"
#include "antioch/chemical_species.h"
#include "antioch/chemical_mixture.h"
#include "antioch/physical_constants.h"
#include "antioch/cea_thermo.h"
#include "antioch/cmath_shims.h"
#include <iomanip>
#include <string>
#include <limits>

Go to the source code of this file.

Functions

template<typename Scalar >
int tester (const std::string &testname)
 
int main ()
 

Function Documentation

int main ( )

Definition at line 159 of file kinetics_reversibility_unit.C.

160 {
161  return (tester<double>("double") ||
162  tester<long double>("long double") ||
163  tester<float>("float"));
164 }
template<typename Scalar >
int tester ( const std::string &  testname)

Definition at line 45 of file kinetics_reversibility_unit.C.

References Antioch::KineticsModel::A, Antioch::Reaction< CoeffType, VectorCoeffType >::add_forward_rate(), Antioch::Reaction< CoeffType, VectorCoeffType >::add_product(), Antioch::Reaction< CoeffType, VectorCoeffType >::add_reactant(), Antioch::Reaction< CoeffType, VectorCoeffType >::compute_rate_of_progress(), Antioch::KineticsModel::E, Antioch::ReactionType::ELEMENTARY, Antioch::CEAThermodynamics< CoeffType >::h_RT_minus_s_R(), Antioch::Reaction< CoeffType, VectorCoeffType >::initialize(), Antioch::KineticsModel::KOOIJ, std::pow(), Antioch::Reaction< CoeffType, VectorCoeffType >::print(), Antioch::Reaction< CoeffType, VectorCoeffType >::set_reversibility(), and Antioch::ChemicalMixture< CoeffType >::species_name_map().

46 {
47  using std::abs;
48  using std::exp;
49  using std::pow;
50 
51  std::vector<std::string> species_str_list;
52  const unsigned int n_species = 4;
53  species_str_list.reserve(n_species);
54  species_str_list.push_back( "N2" );
55  species_str_list.push_back( "O" );
56  species_str_list.push_back( "NO" );
57  species_str_list.push_back( "N" );
58 
59  Antioch::ChemicalMixture<Scalar> chem_mixture( species_str_list );
60  Antioch::CEAThermodynamics<Scalar> thermo( chem_mixture );
61 
62  //fill on hand reaction_set
63  const std::string equation("N2 + O [=] NO + N");
64  const Scalar A = 5.7e+9L;
65  const Scalar b = 0.42L;
66  const Scalar E = 85269.6L;// cal/mol
69  const bool reversible(true);
70 
71  const Scalar T = 1500.0L; // K
72  const Scalar P = 1.0e5L; // Pa
73  const Antioch::KineticsConditions<Scalar> conditions(T);
74 
75  const Scalar P0_RT(1.0e5/Antioch::Constants::R_universal<Scalar>()/T);
76  std::vector<Scalar> h_RT_minus_s_R(n_species);
77 
78  typedef typename Antioch::CEAThermodynamics<Scalar>::template Cache<Scalar> Cache;
79  thermo.h_RT_minus_s_R(Cache(T),h_RT_minus_s_R);
80  // Molar densities, equimolar
81  std::vector<Scalar> molar_densities(n_species , P/Antioch::Constants::R_universal<Scalar>()/T/Scalar(n_species));
82 // Theory
83  Scalar k = A * Antioch::ant_pow(T,b) * Antioch::ant_exp(-E/(1.9858775L*T));
84  Scalar Keq = Antioch::ant_exp(h_RT_minus_s_R[0] + h_RT_minus_s_R[1] - h_RT_minus_s_R[2] - h_RT_minus_s_R[3]);
85  Scalar kback = k/Keq;
86  Scalar rate_fwd = k * molar_densities[0] * molar_densities[1];
87  Scalar rate_back = kback * molar_densities[2] * molar_densities[3];
88  Scalar net_rate = rate_fwd - rate_back;
89 
90 //reversible reaction
91  Antioch::Reaction<Scalar>* my_rxn = Antioch::build_reaction<Scalar>(n_species, equation,reversible,typeReaction,kineticsModel);
92  std::vector<Scalar> data;
93  data.push_back(A);
94  data.push_back(b);
95  data.push_back(E);
96  data.push_back(1.L);
97  data.push_back(1.9858775L);
98  Antioch::KineticsType<Scalar>* rate = Antioch::build_rate<Scalar>(data,kineticsModel);
99  my_rxn->add_forward_rate(rate);
100  my_rxn->add_reactant("N2",chem_mixture.species_name_map().at("N2"),1);
101  my_rxn->add_reactant("O" ,chem_mixture.species_name_map().at("O") ,1);
102  my_rxn->add_product ("NO",chem_mixture.species_name_map().at("NO"),1);
103  my_rxn->add_product ("N" ,chem_mixture.species_name_map().at("N") ,1);
104  my_rxn->initialize();
105  my_rxn->print();
106 
107 //
108  Scalar rate_reversible = my_rxn->compute_rate_of_progress(molar_densities,conditions,P0_RT,h_RT_minus_s_R);
109 
110 //irreversible reaction
111  my_rxn->set_reversibility(false);
112  Scalar rate_irreversible = my_rxn->compute_rate_of_progress(molar_densities,conditions,P0_RT,h_RT_minus_s_R);
113 
114  int return_flag = 0;
115 
116  const Scalar tol = std::numeric_limits<Scalar>::epsilon() * 100;
117 
118  if( abs( (rate_reversible - net_rate)/net_rate) > tol )
119  {
120  std::cout << "Error: Mismatch in " << testname << " rate reversibility." << std::endl
121  << std::setprecision(25)
122  << "net_rate_antioch(T) = " << rate_reversible << std::endl
123  << "net_rate_theory = " << net_rate << std::endl
124  << "relative error: " << abs( (rate_reversible - net_rate)/net_rate) << std::endl
125  << "tolerance: " << tol << std::endl;
126 
127  return_flag = 1;
128  }
129 
130  if( abs( (rate_irreversible - rate_fwd)/rate_fwd) > tol )
131  {
132  std::cout << "Error: Mismatch in " << testname << " rate reversibility." << std::endl
133  << std::setprecision(25)
134  << "irr_rate_antioch(T) = " << rate_reversible << std::endl
135  << "irr_rate_theory = " << rate_fwd << std::endl
136  << "relative error: " << abs( (rate_irreversible - rate_fwd)/rate_fwd) << std::endl
137  << "tolerance: " << tol << std::endl;
138 
139  return_flag = 1;
140  }
141 
142  if( abs( (abs(rate_reversible - rate_irreversible) - rate_back)/rate_back) > tol )
143  {
144  std::cout << "Error: Mismatch in " << testname << " rate reversibility." << std::endl
145  << std::setprecision(25)
146  << "irrev_rate_antioch(T) - rev_rate_antioch(T) = " << rate_irreversible - rate_reversible << std::endl
147  << "back_rate_theory = " << rate_back << std::endl
148  << "relative error: " << abs( ((rate_reversible - rate_irreversible) - rate_back)/rate_back) << std::endl
149  << "tolerance: " << tol << std::endl;
150 
151  return_flag = 1;
152  }
153 
154  delete my_rxn;
155 
156  return return_flag;
157 }
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
A single reaction mechanism.
Definition: reaction.h:108
void initialize(unsigned int index=0)
Computes derived quantities.
Definition: reaction.h:723
base class for kinetics models
Definition: kinetics_type.h:82
Antioch::enable_if_c< Antioch::is_valarray< T >::value, typename Antioch::state_type< T >::type >::type pow(const T &in, const T2 &n)
void set_reversibility(const bool reversible)
Set the reversibility of reaction.
Definition: reaction.h:432
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
void add_forward_rate(KineticsType< CoeffType, VectorCoeffType > *rate)
Add a forward rate object.
Definition: reaction.h:469
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
Class storing chemical mixture properties.
StateType h_RT_minus_s_R(const Cache< StateType > &cache, unsigned int species) const
We currently need different specializations for scalar vs vector inputs here.
Definition: cea_thermo.h:420
void print(std::ostream &os=std::cout) const
Formatted print, by default to std::cout.
Definition: reaction.h:824
This class contains the conditions of the chemistry.

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