GRINS-0.6.0
cantera_mixture_unit.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // GRINS - General Reacting Incompressible Navier-Stokes
5 //
6 // Copyright (C) 2014-2015 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"
33 
34 // libMesh
35 #include "libmesh/getpot.h"
36 
37 #ifdef GRINS_HAVE_CANTERA
38 int main( int argc, char* argv[] )
39 {
40  // Check command line count.
41  if( argc < 2 )
42  {
43  // TODO: Need more consistent error handling.
44  std::cerr << "Error: Must specify input file." << std::endl;
45  exit(1);
46  }
47 
48  GetPot input( argv[1] );
49 
50 
51 
52  GRINS::CanteraMixture cantera(input);
53 
54  std::vector<double> mass_fractions( 5, 0.2 );
55 
56  const double M_N2 = 14.00674*2;
57  const double M_O2 = 15.9994*2;
58  const double M_N = 14.00674;
59  const double M_O = 15.9994;
60  const double M_NO = (14.00674+15.9994);
61 
62  double R_exact = Cantera::GasConstant*( mass_fractions[0]/M_N2
63  + mass_fractions[1]/M_O2
64  + mass_fractions[3]/M_N
65  + mass_fractions[4]/M_O
66  + mass_fractions[2]/M_NO );
67 
68  double M_exact = 1.0/( mass_fractions[0]/M_N2
69  + mass_fractions[1]/M_O2
70  + mass_fractions[3]/M_N
71  + mass_fractions[4]/M_O
72  + mass_fractions[2]/M_NO );
73 
74  std::vector<double> X_exact(5, 0.0);
75  X_exact[0] = mass_fractions[0]*M_exact/M_N2;
76  X_exact[1] = mass_fractions[1]*M_exact/M_O2;
77  X_exact[3] = mass_fractions[3]*M_exact/M_N;
78  X_exact[4] = mass_fractions[4]*M_exact/M_O;
79  X_exact[2] = mass_fractions[2]*M_exact/M_NO;
80 
81  int return_flag = 0;
82 
83  const double tol = std::numeric_limits<double>::epsilon()*10;
84 
85  if( std::fabs( (cantera.R_mix(mass_fractions) - R_exact)/R_exact) > tol )
86  {
87  std::cerr << "Error: Mismatch in mixture gas constant." << std::endl
88  << std::setprecision(16) << std::scientific
89  << "R = " << cantera.R_mix(mass_fractions) << std::endl
90  << "R_exact = " << R_exact << std::endl;
91  return_flag = 1;
92  }
93 
94  if( std::fabs( (cantera.M_mix(mass_fractions) - M_exact)/M_exact ) > tol )
95  {
96  std::cerr << "Error: Mismatch in mixture molar mass." << std::endl
97  << std::setprecision(16) << std::scientific
98  << "M = " << cantera.M_mix(mass_fractions) << std::endl
99  << "M_exact = " << M_exact << std::endl;
100  return_flag = 1;
101  }
102 
103  std::vector<double> X(5);
104  cantera.X( cantera.M_mix(mass_fractions), mass_fractions, X );
105  for( unsigned int s = 0; s < 5; s++ )
106  {
107  if( std::fabs( (X[s] - X_exact[s])/X_exact[s]) > tol )
108  {
109  std::cerr << "Error: Mismatch in mole fraction for species " << s << std::endl
110  << std::setprecision(16) << std::scientific
111  << "X = " << X[s] << std::endl
112  << "X_exact = " << X_exact[s] << std::endl;
113  return_flag = 1;
114  }
115  }
116 
117  return return_flag;
118 }
119 #else //GRINS_HAVE_CANTERA
120 int main()
121 {
122  // automake expects 77 for a skipped test
123  return 77;
124 }
125 #endif
libMesh::Real X(unsigned int species, libMesh::Real M, libMesh::Real mass_fraction) const
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...
int main(int argc, char *argv[])

Generated on Mon Jun 22 2015 21:32:20 for GRINS-0.6.0 by  doxygen 1.8.9.1