antioch-0.4.0
chemical_mixture.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 // This class
29 
30 // Antioch
32 #include "antioch/ascii_parser.h"
34 
35 namespace Antioch
36 {
37  template<typename CoeffType>
38  ChemicalMixture<CoeffType>::ChemicalMixture(const std::string & filename, const bool verbose,
39  const std::string & species_data,
40  const std::string & vibration_data,
41  const std::string & electronic_data)
42  {
43  ASCIIParser<CoeffType> parser(filename,verbose);
44 
45  read_chemical_species_composition<CoeffType>(static_cast<ParserBase<CoeffType> *> (&parser), *this);
46 
47  parser.change_file(species_data);
48  this->read_species_characteristics(&parser,species_data,vibration_data,electronic_data);
49 
50  return;
51  }
52 
53  template<typename CoeffType>
55  const std::string & species_data,
56  const std::string & vibration_data,
57  const std::string & electronic_data)
58  {
59  read_chemical_species_composition<CoeffType>(parser, *this);
60 
61  this->read_species_characteristics(parser,species_data,vibration_data,electronic_data);
62 
63  return;
64  }
65 
66  template<typename CoeffType>
67  ChemicalMixture<CoeffType>::ChemicalMixture(const std::vector<std::string>& species_list,
68  const bool verbose,
69  const std::string & species_data,
70  const std::string & vibration_data,
71  const std::string & electronic_data)
72  {
73  this->initialize_species(species_list);
74 
75  Antioch::ASCIIParser<CoeffType> parser(species_data,verbose);
76 
77  this->read_species_characteristics(static_cast<ParserBase<CoeffType> *>(&parser),species_data,vibration_data,electronic_data);
78 
79  return;
80  }
81 
82  template<typename CoeffType>
84  {
85  // Clean up all the ChemicalSpecies we stored
86  for( typename std::vector<ChemicalSpecies<CoeffType>* >::iterator it = _chemical_species.begin();
87  it < _chemical_species.end(); ++it )
88  {
89  delete (*it);
90  }
91 
92  return;
93  }
94 
95  template<typename CoeffType>
97  const std::string & /*species_data*/,
98  const std::string & vibration_data,
99  const std::string & electronic_data)
100  {
101  // species file is already in parser object
102  this->read_species_mandatory_characteristics(parser);
103 
104  //... and any vibrational data
105  parser->change_file(vibration_data);
106  this->read_species_vibrational_characteristics(parser);
107 
108  //... and any electronic data
109  parser->change_file(electronic_data);
110  this->read_species_electronic_characteristics(parser);
111  }
112 
113  template<typename CoeffType>
114  void ChemicalMixture<CoeffType>::initialize_species( const std::vector<std::string>& species_list )
115  {
116  _chemical_species.resize( species_list.size(), NULL );
117  // Build up name map for all possible species
118  this->init_species_name_map(species_list);
119 
120  // Build up inverse name map
121  this->build_inverse_name_map();
122 
123  // Populate species list for requested species
124  _species_list.reserve( species_list.size() );
125  for( unsigned int s = 0; s < species_list.size(); s++ )
126  {
127  if( _species_name_map.find( species_list[s] ) == _species_name_map.end() )
128  {
129  std::cerr << "Error in ChemicalMixture: Unknown species " << species_list[s] << std::endl;
130  antioch_error();
131  }
132 
133  _species_list.push_back( _species_name_map.find( species_list[s] )->second );
134  }
135  }
136 
137  template<typename CoeffType>
138  void ChemicalMixture<CoeffType>::init_species_name_map(const std::vector<std::string> & species_list)
139  {
140  _species_name_map.clear();
141  for(unsigned int s = 0; s < species_list.size(); s++)
142  {
143  _species_name_map[species_list[s]] = s;
144  }
145  }
146 
147  template<typename CoeffType>
149  {
150  for( std::map<std::string,Species>::const_iterator it = _species_name_map.begin();
151  it != _species_name_map.end(); ++it )
152  {
153  _species_inv_name_map.insert( std::make_pair( it->second, it->first ) );
154  }
155 
156  return;
157  }
158 
159  template <typename CoeffType>
161  {
162  read_species_data<CoeffType>(parser, *this);
163  }
164 
165  template <typename CoeffType>
167  {
168  read_species_vibrational_data<CoeffType>(parser, *this);
169  }
170 
171  template <typename CoeffType>
173  {
174  read_species_electronic_data<CoeffType>(parser, *this);
175  }
176 
177  template<typename CoeffType>
178  void ChemicalMixture<CoeffType>::add_species( const unsigned int index,
179  const std::string& name,
180  CoeffType mol_wght,
181  CoeffType h_form,
182  CoeffType n_tr_dofs, int charge)
183  {
184  _chemical_species[index] =
185  new ChemicalSpecies<CoeffType>(name, mol_wght, h_form, n_tr_dofs, charge);
186  }
187 
188  template<typename CoeffType>
190  const CoeffType theta_v,
191  const unsigned int ndg_v )
192  {
193  (_chemical_species[index])->add_vibrational_data(theta_v, ndg_v);
194  }
195 
196  template<typename CoeffType>
198  const CoeffType theta_e,
199  const unsigned int ndg_e )
200  {
201  (_chemical_species[index])->add_electronic_data(theta_e, ndg_e);
202  }
203 
204 } // end namespace Antioch
205 
206 // Instantiate
void read_species_vibrational_characteristics(ParserBase< CoeffType > *parser)
method to read vibrational characteristics
void init_species_name_map(const std::vector< std::string > &species_list)
#define antioch_error()
ANTIOCH_NUMERIC_TYPE_CLASS_INSTANTIATE(Antioch::ChemicalMixture)
void read_species_mandatory_characteristics(ParserBase< CoeffType > *parser)
method to read mandatory characteristics
void change_file(const std::string &filename)
Definition: ascii_parser.C:78
Class to encapsulate data for each chemical species.
virtual void change_file(const std::string &filename)=0
void initialize_species(const std::vector< std::string > &species_list)
method to initialize, backward compatibility
void add_species(const unsigned int index, const std::string &name, CoeffType mol_wght, CoeffType h_form, CoeffType n_tr_dofs, int charge)
void read_species_characteristics(ParserBase< CoeffType > *parser, const std::string &species_data, const std::string &vibration_data, const std::string &electronic_data)
method to read characteristics, using one parser
void add_species_vibrational_data(const unsigned int index, const CoeffType theta_v, const unsigned int ndg_v)
Class storing chemical mixture properties.
void add_species_electronic_data(const unsigned int index, const CoeffType theta_e, const unsigned int ndg_e)
The parameters are reduced parameters.
ChemicalMixture(const std::string &filename=DefaultFilename::species_list(), const bool verbose=true, const std::string &species_data=DefaultFilename::chemical_mixture(), const std::string &vibration_data=DefaultFilename::vibrational_data(), const std::string &electronic_data=DefaultFilename::electronic_data())
ascii parser by default
void read_species_electronic_characteristics(ParserBase< CoeffType > *parser)
method to read electronic characteristics
A parser is an instance related to a file.

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