GRINS-0.8.0
cantera_mixture.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // GRINS - General Reacting Incompressible Navier-Stokes
5 //
6 // Copyright (C) 2014-2017 Paul T. Bauman, Roy H. Stogner
7 // Copyright (C) 2010-2013 The PECOS Development Team
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the Version 2.1 GNU Lesser General
11 // Public License as published by the Free Software Foundation.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
21 // Boston, MA 02110-1301 USA
22 //
23 //-----------------------------------------------------------------------el-
24 
25 
26 // C++
27 #include <iomanip>
28 #include <limits>
29 #include <vector>
30 
31 // GRINS
32 #include "grins/cantera_mixture.h"
34 #include "grins/physics_naming.h"
35 
36 // libMesh
37 #include "libmesh/getpot.h"
38 
39 #ifdef GRINS_HAVE_CANTERA
40 int main( int argc, char* argv[] )
41 {
42  // Check command line count.
43  if( argc < 2 )
44  {
45  // TODO: Need more consistent error handling.
46  std::cerr << "Error: Must specify input file." << std::endl;
47  exit(1);
48  }
49 
50  GetPot input( argv[1] );
51 
52 
53 
54  GRINS::CanteraMixture cantera(input,"TestMaterial");
55 
56  std::vector<double> mass_fractions( 5, 0.2 );
57 
58  const double M_N2 = 14.00674*2;
59  const double M_O2 = 15.9994*2;
60  const double M_N = 14.00674;
61  const double M_O = 15.9994;
62  const double M_NO = (14.00674+15.9994);
63 
64  double R_exact = Cantera::GasConstant*( mass_fractions[0]/M_N2
65  + mass_fractions[1]/M_O2
66  + mass_fractions[3]/M_N
67  + mass_fractions[4]/M_O
68  + mass_fractions[2]/M_NO );
69 
70  double M_exact = 1.0/( mass_fractions[0]/M_N2
71  + mass_fractions[1]/M_O2
72  + mass_fractions[3]/M_N
73  + mass_fractions[4]/M_O
74  + mass_fractions[2]/M_NO );
75 
76  std::vector<double> X_exact(5, 0.0);
77  X_exact[0] = mass_fractions[0]*M_exact/M_N2;
78  X_exact[1] = mass_fractions[1]*M_exact/M_O2;
79  X_exact[3] = mass_fractions[3]*M_exact/M_N;
80  X_exact[4] = mass_fractions[4]*M_exact/M_O;
81  X_exact[2] = mass_fractions[2]*M_exact/M_NO;
82 
83  int return_flag = 0;
84 
85  const double tol = std::numeric_limits<double>::epsilon()*10;
86 
87  if( std::fabs( (cantera.R_mix(mass_fractions) - R_exact)/R_exact) > tol )
88  {
89  std::cerr << "Error: Mismatch in mixture gas constant." << std::endl
90  << std::setprecision(16) << std::scientific
91  << "R = " << cantera.R_mix(mass_fractions) << std::endl
92  << "R_exact = " << R_exact << std::endl;
93  return_flag = 1;
94  }
95 
96  if( std::fabs( (cantera.M_mix(mass_fractions) - M_exact)/M_exact ) > tol )
97  {
98  std::cerr << "Error: Mismatch in mixture molar mass." << std::endl
99  << std::setprecision(16) << std::scientific
100  << "M = " << cantera.M_mix(mass_fractions) << std::endl
101  << "M_exact = " << M_exact << std::endl;
102  return_flag = 1;
103  }
104 
105  std::vector<double> X(5);
106  cantera.X( cantera.M_mix(mass_fractions), mass_fractions, X );
107  for( unsigned int s = 0; s < 5; s++ )
108  {
109  if( std::fabs( (X[s] - X_exact[s])/X_exact[s]) > tol )
110  {
111  std::cerr << "Error: Mismatch in mole fraction for species " << s << std::endl
112  << std::setprecision(16) << std::scientific
113  << "X = " << X[s] << std::endl
114  << "X_exact = " << X_exact[s] << std::endl;
115  return_flag = 1;
116  }
117  }
118 
119  return return_flag;
120 }
121 #else //GRINS_HAVE_CANTERA
122 int main()
123 {
124  // automake expects 77 for a skipped test
125  return 77;
126 }
127 #endif
libMesh::Real X(unsigned int species, libMesh::Real M, libMesh::Real mass_fraction) const
int main(int argc, char *argv[])
libMesh::Real M_mix(const std::vector< libMesh::Real > &mass_fractions) const
libMesh::Real R_mix(const std::vector< libMesh::Real > &mass_fractions) const
Wrapper class for storing state for computing thermochemistry and transport properties using Cantera...

Generated on Tue Dec 19 2017 12:47:28 for GRINS-0.8.0 by  doxygen 1.8.9.1