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 #include "grins_config.h"
27 
28 #ifdef GRINS_HAVE_CANTERA
29 
30 // This class
31 #include "grins/cantera_mixture.h"
32 
33 // GRINS
35 
36 // libMesh
37 #include "libmesh/getpot.h"
38 
39 namespace GRINS
40 {
41  CanteraMixture::CanteraMixture( const GetPot& input, const std::string& material )
42  : ParameterUser("CanteraMixture")
43  {
44  const std::string cantera_chem_file = MaterialsParsing::parse_chemical_kinetics_datafile_name( input, material );
45 
46  std::string mixture = this->parse_mixture(input,material);
47 
48  try
49  {
50  _cantera_gas.reset( new Cantera::IdealGasMix( cantera_chem_file, mixture ) );
51  }
52  catch(Cantera::CanteraError)
53  {
54  Cantera::showErrors(std::cerr);
55  libmesh_error();
56  }
57 
58  try
59  {
60  _cantera_transport.reset( Cantera::newTransportMgr("Mix", _cantera_gas.get()) );
61  }
62  catch(Cantera::CanteraError)
63  {
64  Cantera::showErrors(std::cerr);
65  libmesh_error();
66  }
67 
68  return;
69  }
70 
72  {
73  return;
74  }
75 
76  std::string CanteraMixture::parse_mixture( const GetPot& input, const std::string& material )
77  {
78  std::string mixture;
79 
80  if( input.have_variable("Physics/Chemistry/mixture") )
81  {
82  MaterialsParsing::dep_input_warning("Physics/Chemistry/mixture",
83  "GasMixture/Cantera/gas_mixture" );
84 
85  mixture = input( "Physics/Chemistry/mixture", "DIE!" );
86  }
87  else if( input.have_variable("Materials/"+material+"/GasMixture/Cantera/gas_mixture") )
88  {
89  mixture = input("Materials/"+material+"/GasMixture/Cantera/gas_mixture", "DIE!");
90  }
91  else
92  {
93  libmesh_error_msg("ERROR: Could not find valid input for Cantera gas_mixture!");
94  }
95 
96  return mixture;
97  }
98 
99  libMesh::Real CanteraMixture::M_mix( const std::vector<libMesh::Real>& mass_fractions ) const
100  {
101  libmesh_assert_equal_to( mass_fractions.size(), _cantera_gas->nSpecies() );
102 
103  libMesh::Real M = 0;
104  for( unsigned int s = 0; s < mass_fractions.size(); s++ )
105  {
106  M += mass_fractions[s]/(this->M(s));
107  }
108 
109  return 1.0/M;
110  }
111 
112  libMesh::Real CanteraMixture::R_mix( const std::vector<libMesh::Real>& mass_fractions ) const
113  {
114  libmesh_assert_equal_to( mass_fractions.size(), _cantera_gas->nSpecies() );
115 
116  libMesh::Real R = 0.0;
117  for( unsigned int s = 0; s < mass_fractions.size(); s++ )
118  {
119  R += mass_fractions[s]*this->R(s);
120  }
121 
122  return R;
123  }
124 
125  void CanteraMixture::X( libMesh::Real M_mix, const std::vector<libMesh::Real>& mass_fractions,
126  std::vector<libMesh::Real>& mole_fractions ) const
127  {
128  libmesh_assert_equal_to( mass_fractions.size(), _cantera_gas->nSpecies() );
129 
130  libmesh_assert_equal_to( mole_fractions.size(), mass_fractions.size() );
131 
132  for( unsigned int s = 0; s < mass_fractions.size(); s++ )
133  {
134  mole_fractions[s] = this->X(s, M_mix, mass_fractions[s]);
135  }
136 
137  return;
138  }
139 
140 }// end namespace GRINS
141 
142 #endif // GRINS_HAVE_CANTERA
libMesh::UniquePtr< Cantera::Transport > _cantera_transport
libMesh::Real R(unsigned int species) const
libMesh::Real X(unsigned int species, libMesh::Real M, libMesh::Real mass_fraction) const
libMesh::UniquePtr< Cantera::IdealGasMix > _cantera_gas
GRINS namespace.
libMesh::Real M_mix(const std::vector< libMesh::Real > &mass_fractions) const
libMesh::Real R_mix(const std::vector< libMesh::Real > &mass_fractions) const
ParameterUser base class. Utility methods for subclasses.
static void dep_input_warning(const std::string &old_option, const std::string &property)
Helper function for parsing/maintaing backward compatibility.
static std::string parse_chemical_kinetics_datafile_name(const GetPot &input, const std::string &material)
libMesh::Real M(unsigned int species) const
std::string parse_mixture(const GetPot &input, const std::string &material)

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