antioch-0.4.0
Functions
ideal_gas_micro_thermo_unit.C File Reference
#include <cmath>
#include <limits>
#include "antioch/vector_utils_decl.h"
#include "antioch/physical_constants.h"
#include "antioch/chemical_mixture.h"
#include "antioch/ideal_gas_micro_thermo.h"
#include "antioch/cea_evaluator.h"
#include "antioch/cea_curve_fit.h"
#include "antioch/cea_mixture_parsing.h"
#include "antioch/vector_utils.h"

Go to the source code of this file.

Functions

template<typename Scalar >
bool test_zero (const Scalar val, const Scalar tol)
 
template<typename Scalar >
int test_relative (const Scalar val, const Scalar truth, const Scalar tol, const std::string &words)
 
template<typename Scalar >
int test_molecule (unsigned int spec, const Scalar &n_tr_dofs, const Scalar &R_spec, const Scalar &cv_over_R, const Scalar &T, const Antioch::IdealGasMicroThermo< Antioch::NASAEvaluator< Scalar, Antioch::CEACurveFit< Scalar > >, Scalar > &thermo, const std::string &name)
 
template<typename Scalar >
int tester ()
 
int main ()
 

Function Documentation

int main ( )

Definition at line 168 of file ideal_gas_micro_thermo_unit.C.

169 {
170 
171  int ierr = (tester<double>() ||
172  tester<long double>() ||
173  tester<float>());
174 
175  return ierr;
176 }
template<typename Scalar >
int test_molecule ( unsigned int  spec,
const Scalar &  n_tr_dofs,
const Scalar &  R_spec,
const Scalar &  cv_over_R,
const Scalar &  T,
const Antioch::IdealGasMicroThermo< Antioch::NASAEvaluator< Scalar, Antioch::CEACurveFit< Scalar > >, Scalar > &  thermo,
const std::string &  name 
)

Definition at line 78 of file ideal_gas_micro_thermo_unit.C.

References test_relative().

Referenced by tester().

84 {
85  const Scalar tol = (std::numeric_limits<Scalar>::epsilon() * 2 < 5e-17L)?5e-17L:
86  std::numeric_limits<Scalar>::epsilon() * 2;
87 
88  int return_flag = 0;
89  // values over R are:
90  // cv_tr / R = n_tr_dofs
91  // cv_trans / R = 1.5
92  // cv_rot / R = max(n_tr_dofs - 1.5,0)
93  // cv_vib / R = cp / R - 1 - n_tr_dofs
94 
95  Scalar cv_rot = (n_tr_dofs > Scalar(1.5))?n_tr_dofs - Scalar(1.5):Scalar(0.);
96  Scalar cv_vib = (n_tr_dofs < 2.)?0.L:cv_over_R - n_tr_dofs;
97 
98  return_flag = test_relative(thermo.cv_tr_over_R(spec), n_tr_dofs, tol, "cv_tr_over_R of " + name) || return_flag;
99  return_flag = test_relative(thermo.cv_tr(spec), R_spec * n_tr_dofs, tol, "cv_tr of " + name) || return_flag;
100  return_flag = test_relative(thermo.cv_trans_over_R(spec), Scalar(1.5), tol, "cv_trans_over_R of " + name) || return_flag;
101  return_flag = test_relative(thermo.cv_trans(spec), R_spec * Scalar(1.5), tol, "cv_trans of " + name) || return_flag;
102  return_flag = test_relative(thermo.cv_rot_over_R(spec), cv_rot, tol, "cv_rot_over_R of " + name) || return_flag;
103  return_flag = test_relative(thermo.cv_rot(spec), R_spec * cv_rot, tol, "cv_rot of " + name) || return_flag;
104 // vibration requires CEA fits, tolerance is somewhat loose...
105  return_flag = test_relative(thermo.cv_vib_over_R(spec,T), cv_vib, Scalar(200.L) * tol, "cv_vib_over_R of " + name) || return_flag;
106  return_flag = test_relative(thermo.cv_vib(spec,T), R_spec * cv_vib, Scalar(200.L) * tol, "cv_vib of " + name) || return_flag;
107 
108  return return_flag;
109 }
const CoeffType cv_rot_over_R(unsigned int s) const
cv_rot/R
const CoeffType cv_tr(unsigned int s) const
cv_trans-rot
const CoeffType cv_tr_over_R(unsigned int s) const
cv_trans_rot/R
const CoeffType cv_trans_over_R(unsigned int s) const
cv_trans/R
const CoeffType cv_trans(unsigned int s) const
cv_trans
int test_relative(const Scalar val, const Scalar truth, const Scalar tol, const std::string &words)
template<typename Scalar >
int test_relative ( const Scalar  val,
const Scalar  truth,
const Scalar  tol,
const std::string &  words 
)

Definition at line 55 of file ideal_gas_micro_thermo_unit.C.

References test_zero().

Referenced by test_molecule().

56 {
57  using std::abs;
58 
59  bool test = (test_zero(truth,tol))?!test_zero(val,tol):(abs( (val-truth)/truth ) > tol );
60  Scalar diff = (test_zero(truth,tol))?val:abs( (val-truth)/truth );
61  if(test)
62  {
63  std::cerr << std::scientific << std::setprecision(20);
64  std::cerr << "Error: Mismatch in " << words
65  << "\n Expected = " << truth
66  << "\n Computed = " << val
67  << "\n Relative diff = " << diff
68  << "\n Tolerance = " << tol
69  << std::endl;
70  return 1;
71  }else
72  {
73  return 0;
74  }
75 }
bool test_zero(const Scalar val, const Scalar tol)
template<typename Scalar >
bool test_zero ( const Scalar  val,
const Scalar  tol 
)

Definition at line 44 of file ideal_gas_micro_thermo_unit.C.

Referenced by test_relative().

45 {
46  using std::abs;
47 
48  if( abs(val) > tol )
49  return false;
50  else
51  return true;
52 }
template<typename Scalar >
int tester ( )

Definition at line 111 of file ideal_gas_micro_thermo_unit.C.

References Antioch::ASCII, Antioch::NASAEvaluator< CoeffType, CEACurveFit< CoeffType > >::cv_over_R(), Antioch::read_cea_mixture_data(), test_molecule(), and Antioch::DefaultSourceFilename::thermo_data().

112 {
113  const Scalar Mm_N = 14.008e-3; //in SI kg/mol
114  const Scalar Mm_O = 16e-3; //in SI kg/mol
115  const Scalar Mm_N2 = 2.L * Mm_N; //in SI kg/mol
116  const Scalar Mm_O2 = 2.L * Mm_O; //in SI kg/mol
117  const Scalar Mm_NO = Mm_O + Mm_N; //in SI kg/mol
118 
119  std::vector<std::string> species_str_list;
120  const unsigned int n_species = 5;
121  species_str_list.reserve(n_species);
122  species_str_list.push_back( "N2" );
123  species_str_list.push_back( "O2" );
124  species_str_list.push_back( "N" );
125  species_str_list.push_back( "O" );
126  species_str_list.push_back( "NO" );
127 
128  Antioch::ChemicalMixture<Scalar> chem_mixture( species_str_list );
129 
130 // required for Cv, we take default CEA
131  Antioch::CEAThermoMixture<Scalar> nasa_mixture( chem_mixture );
133  Antioch::CEAEvaluator<Scalar> nasa_thermo( nasa_mixture );
134 
136  Scalar > id_thermo( nasa_thermo, chem_mixture );
137 
138  // Mass fractions
139  std::vector<Scalar> mass_fractions( 5, 0.2 );
140  mass_fractions[0] = 0.5;
141  mass_fractions[1] = 0.2;
142  mass_fractions[2] = 0.1;
143  mass_fractions[3] = 0.1;
144  mass_fractions[4] = 0.1;
145 
146  const Scalar R_N2 = Antioch::Constants::R_universal<Scalar>() / Mm_N2;
147  const Scalar R_O2 = Antioch::Constants::R_universal<Scalar>() / Mm_O2;
148  const Scalar R_N = Antioch::Constants::R_universal<Scalar>() / Mm_N;
149  const Scalar R_O = Antioch::Constants::R_universal<Scalar>() / Mm_O;
150  const Scalar R_NO = Antioch::Constants::R_universal<Scalar>() / Mm_NO;
151 
152  int return_flag = 0;
153 
154  Scalar T = 300.1;
155 
156  // N2
157  return_flag = test_molecule(0,Scalar(2.5),R_N2,nasa_thermo.cv_over_R(Antioch::TempCache<Scalar>(T),0), T, id_thermo, "N2") || return_flag;
158  return_flag = test_molecule(1,Scalar(2.5),R_O2,nasa_thermo.cv_over_R(Antioch::TempCache<Scalar>(T),1), T, id_thermo, "O2") || return_flag;
159  return_flag = test_molecule(2,Scalar(1.5),R_N, nasa_thermo.cv_over_R(Antioch::TempCache<Scalar>(T),2), T, id_thermo, "N") || return_flag;
160  return_flag = test_molecule(3,Scalar(1.5),R_O, nasa_thermo.cv_over_R(Antioch::TempCache<Scalar>(T),3), T, id_thermo, "O") || return_flag;
161  return_flag = test_molecule(4,Scalar(2.5),R_NO,nasa_thermo.cv_over_R(Antioch::TempCache<Scalar>(T),4), T, id_thermo, "NO") || return_flag;
162 
163 
164  return return_flag;
165 }
void read_cea_mixture_data(CEAThermoMixture< NumericType > &thermo, const std::string &filename, ParsingType type, bool verbose=true)
static const std::string & thermo_data()
Class storing chemical mixture properties.
int test_molecule(unsigned int spec, const Scalar &n_tr_dofs, const Scalar &R_spec, const Scalar &cv_over_R, const Scalar &T, const Antioch::IdealGasMicroThermo< Antioch::NASAEvaluator< Scalar, Antioch::CEACurveFit< Scalar > >, Scalar > &thermo, const std::string &name)

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