antioch-0.4.0
Stockmayer_unit.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 
27 
28 #include "antioch_config.h"
29 
30 // Antioch
37 #include "antioch/cea_curve_fit.h"
38 #include "antioch/nasa_mixture.h"
39 #include "antioch/nasa_evaluator.h"
42 #include "antioch/gsl_spliner.h"
45 #include "antioch/vector_utils.h"
46 
47 // C++
48 #include <limits>
49 #include <iostream>
50 #include <iomanip>
51 
52 
53 #ifdef ANTIOCH_HAVE_GSL
54 
55 // not necessary (yet?)
56 template <typename Scalar>
57 int check_value(const Scalar ref, const Scalar candidate, const Scalar tol, const std::string& test_name)
58 {
59  int return_flag = 0;
60 
61  std::cout << "Testing "+test_name << "...";
62 
63  Scalar error = std::abs((ref - candidate)/ref);
64 
65  if( error > tol)
66  {
67  std::cout << "FAILED!" << std::endl;
68  std::cerr << std::scientific << std::setprecision(16);
69  std::cerr << " reference = " << ref << std::endl
70  << " candidate = " << candidate << std::endl
71  << " relative error = " << error << std::endl
72  << " tolerance = " << tol << std::endl;
73  return_flag = 1;
74  }
75  else
76  {
77  std::cout << "PASSED!" << std::endl;
78  }
79 
80  return return_flag;
81 }
82 
83 template <typename Scalar>
84 int tester()
85 {
86  std::vector<std::string> molecules;
87  molecules.push_back("CH4"); // T_max = 14,140 K; 11,743 K; 7,330 K
88  molecules.push_back("N2"); // T_max = 9,753 K; 11,743 K; 6,088 K
89  molecules.push_back("H2"); // T_max = 3,800 K; 6,8088 K; 7,330 K
90 
91  const unsigned int n_species = molecules.size();
92 
93  // mixture
94  Antioch::ChemicalMixture<Scalar> chem_mixture( molecules );
95 
96  // macro thermo
98 
99  // ASCII and true are default, but let's be verbose
101 
103  MacroThermo nasa_thermo( nasa_mixture );
104 
105  // micro thermo
107  MicroThermo micro_thermo(nasa_thermo, chem_mixture);
108 
109  // transport
110  Antioch::TransportMixture<Scalar> tran_mixture( chem_mixture );
111 
112 
113  // sets, GSLSpliner implicit
115  ps_mu(tran_mixture);
116  Antioch::build_kinetics_theory_viscosity<Scalar,Antioch::GSLSpliner>(ps_mu);
117 
119  bimol_D( tran_mixture );
120 
121  int return_flag(0);
122 
123  Scalar T_max(8000.L);
124 
125  ps_mu.extrapolate_max_temp(T_max);
126  bimol_D.extrapolate_max_temp(T_max);
127 
128  std::vector<std::vector<Scalar> > D_matrix_reg(n_species);
129  std::vector<std::vector<Scalar> > D_matrix(n_species);
130  for( unsigned int s = 0; s < n_species; s++ )
131  {
132  D_matrix[s].resize(n_species);
133  D_matrix_reg[s].resize(n_species);
134  }
135 
136  Scalar mu_CH4_reg = 1.0573148339577483e-04;
137  Scalar mu_N2_reg = 1.5770745584335467e-04;
138  Scalar mu_H2_reg = 4.6078198688681625e-05;
139 
140  D_matrix_reg[0][0] = 8.1850066826705467e-03;
141  D_matrix_reg[0][1] = 7.7255676543780075e-03;
142  D_matrix_reg[0][2] = 4.5830263450987500e-02;
143  D_matrix_reg[1][0] = 7.7255676543780075e-03;
144  D_matrix_reg[1][1] = 7.0195276250601020e-03;
145  D_matrix_reg[1][2] = 3.1562763815500983e-03;
146  D_matrix_reg[2][0] = 4.5830263450987500e-02;
147  D_matrix_reg[2][1] = 3.1562763815500983e-03;
148  D_matrix_reg[2][2] = -4.3151204734397887e-03;
149 
150  Scalar mu_CH4 = ps_mu(0,7900.0);
151  Scalar mu_N2 = ps_mu(1,7900.0);
152  Scalar mu_H2 = ps_mu(2,3900.0);
153 
154  bimol_D.compute_binary_diffusion_matrix(6900.0, 1.0, D_matrix);
155 
156  Scalar tol = 10.0*std::numeric_limits<Scalar>::epsilon();
157 
158  // Check viscosity against regression values
159  return_flag = check_value( mu_CH4_reg, mu_CH4, tol, "mu_CH4" ) ||
160  check_value( mu_N2_reg, mu_N2, tol, "mu_N2" ) ||
161  check_value( mu_H2_reg, mu_H2, tol, "mu_H2" );
162 
163  // Matrix had better be symmetric
164  for( unsigned int s = 0; s < n_species; s++ )
165  {
166  for( unsigned int t = s+1; t < n_species; t++ )
167  {
168  std::stringstream convert;
169  convert << s;
170  std::string test_name = "D["+convert.str()+"]";
171  convert.str("");
172  convert << t;
173  test_name += "["+convert.str()+"] symmetry";
174 
175  return_flag = return_flag ||
176  check_value( D_matrix[s][t], D_matrix[t][s], tol, test_name );
177  }
178  }
179 
180  // Check binary diffusion matrix against regression values
181  for( unsigned int s = 0; s < n_species; s++ )
182  {
183  for( unsigned int t = 0; t < n_species; t++ )
184  {
185  std::stringstream convert;
186  convert << s;
187  std::string test_name = "D["+convert.str()+"]";
188  convert.str("");
189  convert << t;
190  test_name += "["+convert.str()+"]";
191 
192  return_flag = return_flag ||
193  check_value( D_matrix_reg[s][t], D_matrix[s][t], tol, test_name );
194  }
195  }
196 
197  return return_flag;
198 }
199 
200 
201 
202 #endif // ANTIOCH_HAVE_GSL
203 
204 
205 int main()
206 {
207 #ifdef ANTIOCH_HAVE_GSL
208  // No long double test because GSL (used for splining) only supports double
209  return (tester<float>() ||
210  tester<double>());
211 #else
212  // 77 return code tells Automake we skipped this.
213  return 77;
214 #endif
215 }
Container class for species viscosities.
Container class for species binary diffusion models.
void read_nasa_mixture_data(NASAThermoMixture< NumericType, CurveType > &thermo, const std::string &filename=DefaultSourceFilename::thermo_data(), ParsingType=ASCII, bool verbose=true)
int main()
int tester(const std::string &testname)
Class storing chemical mixture properties.
Definition: ascii_parser.h:55
static const std::string & thermo_data()
Class storing chemical mixture properties.

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