GRINS-0.6.0
cantera_chem_thermo_test.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 #include <iomanip>
27 
28 // GRINS
29 #include "grins_config.h"
30 #include "grins/cantera_mixture.h"
31 #include "grins/cantera_thermo.h"
32 #include "grins/cantera_kinetics.h"
33 #include "grins/cached_values.h"
34 
35 // libMesh
36 #include "libmesh/getpot.h"
37 
38 #ifdef GRINS_HAVE_CANTERA
39 int main(int argc, char* argv[])
40 {
41  // Check command line count.
42  if( argc < 2 )
43  {
44  // TODO: Need more consistent error handling.
45  std::cerr << "Error: Must specify input file." << std::endl;
46  exit(1); // TODO: something more sophisticated for parallel runs?
47  }
48 
49  GetPot input( argv[1] );
50 
51  std::vector<std::string> species(5);
52  species[0] = input( "Physics/Chemistry/species", "DIE!", 0 );
53  species[1] = input( "Physics/Chemistry/species", "DIE!", 1 );
54  species[2] = input( "Physics/Chemistry/species", "DIE!", 2 );
55  species[3] = input( "Physics/Chemistry/species", "DIE!", 3 );
56  species[4] = input( "Physics/Chemistry/species", "DIE!", 4 );
57 
58  GRINS::CanteraMixture cantera_mixture(input);
59 
60  Cantera::IdealGasMix& cantera = cantera_mixture.get_chemistry();
61 
62  GRINS::CanteraThermodynamics cantera_thermo(cantera_mixture);
63 
64  GRINS::CanteraKinetics cantera_kinetics(cantera_mixture);
65 
66  double T = 1500.0;
67 
68  double P = 100000.0;
69 
70  std::vector<double> Y(5,0.2);
71 
72  GRINS::CachedValues cache;
73 
77 
78  std::vector<double> Tqp(1,T);
79  std::vector<double> Pqp(1,P);
80  std::vector<std::vector<double> > Yqp(1,Y);
81 
85 
86  std::vector<double> omega_dot(5,0.0);
87 
88  cantera_kinetics.omega_dot(cache,0,omega_dot);
89 
90  const double cv = cantera_thermo.cv( cache, 0 );
91  const double cp = cantera_thermo.cp( cache, 0 );
92 
93  std::vector<double> h(5,0.0);
94 
95  cantera_thermo.h(cache,0,h);
96 
97  cantera.setState_TPY(T,P,&Y[0]);
98  const double e = cantera.intEnergy_mass();
99 
100  int return_flag = 0;
101 
102  const double tol = 1.0e-15;
103 
104  const double e_reg = 1.1354093541825727e+07;
105  if( std::fabs( (e - e_reg)/e_reg ) > tol )
106  {
107  std::cerr << "Error: Mismatch in internal energy." << std::endl
108  << std::setprecision(16) << std::scientific
109  << "e = " << e << std::endl
110  << "e_reg = " << e_reg << std::endl;
111  return_flag = 1;
112  }
113 
114  const double cv_reg = 8.8382964243437857e+02;
115  if( std::fabs( (cv - cv_reg)/cv_reg ) > tol )
116  {
117  std::cerr << "Error: Mismatch in cv." << std::endl
118  << std::setprecision(16) << std::scientific
119  << "cv = " << cv << std::endl
120  << "cv_reg = " << cv_reg << std::endl;
121  return_flag = 1;
122  }
123 
124  const double cp_reg = 1.2732313697364564e+03;
125  if( std::fabs( (cp - cp_reg)/cp_reg ) > tol )
126  {
127  std::cerr << "Error: Mismatch in cp." << std::endl
128  << std::setprecision(16) << std::scientific
129  << "cp = " << cp << std::endl
130  << "cp_reg = " << cp_reg << std::endl;
131  return_flag = 1;
132  }
133 
134  std::vector<double> od_reg(5,0.0);
135  /* Values before rescaling omega dot by molar mass
136  od_reg[0] = 3.3421893152544762e+03;
137  od_reg[1] = -1.0546740386620191e+04;
138  od_reg[2] = 8.6026851320309106e+03;
139  od_reg[3] = -1.5287063762539863e+04;
140  od_reg[4] = 1.2490795641209472e+04; */
141 
142  od_reg[0] = 9.3626353539094969e+04;
143  od_reg[1] = -3.3748303628338216e+05;
144  od_reg[2] = 2.5813337444763799e+05;
145  od_reg[3] = -2.1412192748531760e+05;
146  od_reg[4] = 1.9984523578196683e+05;
147 
148  for( unsigned int i = 0; i < 5; i++ )
149  {
150  if( std::fabs( (omega_dot[i] - od_reg[i])/od_reg[i] ) > tol )
151  {
152  std::cerr << "Error: Mismatch in omega_dot." << std::endl
153  << std::setprecision(16) << std::scientific
154  << "i = " << i << std::endl
155  << "omega_dot = " << omega_dot[i] << std::endl
156  << "od_reg = " << od_reg[i] << std::endl;
157  return_flag = 1;
158  }
159  }
160 
161  std::vector<double> h_reg(5,0.0);
162  h_reg[0] = 1.3709248272267890e+06;
163  h_reg[1] = 1.2692054328083945e+06;
164  h_reg[2] = 4.3659730250572553e+06;
165  h_reg[3] = 3.5529883128718123e+07;
166  h_reg[4] = 1.7154994250083648e+07;
167 
168  for( unsigned int i = 0; i < 5; i++ )
169  {
170  if( std::fabs( (h[i] - h_reg[i])/h_reg[i] ) > tol )
171  {
172  std::cerr << "Error: Mismatch in internal energy." << std::endl
173  << std::setprecision(16) << std::scientific
174  << "i = " << i << std::endl
175  << "h = " << h[i] << std::endl
176  << "h_reg = " << h_reg[i] << std::endl;
177  return_flag = 1;
178  }
179  }
180 
181 
182  /*
183  std::cout << std::setprecision(16) << std::scientific
184  << "omega_dot = " << omega_dot[0] << ", " << omega_dot[1] << ", " << omega_dot[2]
185  << ", " << omega_dot[3] << ", " << omega_dot[4] << std::endl;
186  std::cout << std::setprecision(16) << std::scientific << "e = " << e << std::endl;
187  std::cout << std::setprecision(16) << std::scientific << "cv = " << cv << std::endl;
188  std::cout << std::setprecision(16) << std::scientific << "cp = " << cp << std::endl;
189  std::cout << std::setprecision(16) << std::scientific
190  << "h = " << h[0] << ", " << h[1] << ", " << h[2]
191  << ", " << h[3] << ", " << h[4] << std::endl;
192  */
193  return return_flag;
194 }
195 #else //GRINS_HAVE_CANTERA
196 int main()
197 {
198  // automake expects 77 for a skipped test
199  return 77;
200 }
201 #endif
void omega_dot(const CachedValues &cache, unsigned int qp, std::vector< libMesh::Real > &omega_dot) const
libMesh::Real cp(const CachedValues &cache, unsigned int qp) const
void set_values(unsigned int quantity, std::vector< libMesh::Number > &values)
Definition: cached_values.C:72
Wrapper class for evaluating thermo properties using Cantera.
int main(int argc, char *argv[])
Cantera::IdealGasMix & get_chemistry()
libMesh::Real cv(const CachedValues &cache, unsigned int qp) const
Wrapper class for storing state for computing thermochemistry and transport properties using Cantera...
void add_quantity(unsigned int quantity)
Definition: cached_values.C:40
libMesh::Real h(const CachedValues &cache, unsigned int qp, unsigned int species) const
void set_vector_values(unsigned int quantity, std::vector< std::vector< libMesh::Number > > &values)
Definition: cached_values.C:93

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