antioch-0.4.0
nasa_mixture_xml_parsing_test.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 #include "antioch_config.h"
28 
29 #ifdef ANTIOCH_HAVE_CPPUNIT
30 
31 // C++
32 #include <limits>
33 
34 // Antioch
35 #include "nasa7_thermo_test_base.h"
36 #include "nasa9_thermo_test_base.h"
40 #include "antioch/nasa_mixture.h"
42 #include "antioch/xml_parser.h"
43 
44 namespace AntiochTesting
45 {
46  template<typename Scalar>
48  {
49  public:
50 
52  {
53  std::vector<std::string> species_str_list(2);
54  species_str_list[0] = "N2";
55  species_str_list[1] = "NO2";
56 
57  Antioch::ChemicalMixture<Scalar> chem_mixture( species_str_list );
59 
60  std::string filename = std::string(ANTIOCH_SHARE_XML_INPUT_FILES_SOURCE_PATH)+"nasa9_thermo.xml";
61 
62  Antioch::read_nasa_mixture_data( nasa_mixture, filename, Antioch::XML );
63 
64  const Antioch::NASA9CurveFit<Scalar>& N2_curve_fit = nasa_mixture.curve_fit(0);
65  const Antioch::NASA9CurveFit<Scalar>& NO2_curve_fit = nasa_mixture.curve_fit(1);
66 
67  CPPUNIT_ASSERT_EQUAL( (unsigned int)5, N2_curve_fit.n_intervals() );
68  CPPUNIT_ASSERT_EQUAL( (unsigned int)4, NO2_curve_fit.n_intervals() );
69 
70  // Check N2 coefficients
71  this->check_coefficients( N2_curve_fit.coefficients(0), this->_N2_coeffs_0_200 );
72  this->check_coefficients( N2_curve_fit.coefficients(1), this->_N2_coeffs_200_1000 );
73  this->check_coefficients( N2_curve_fit.coefficients(2), this->_N2_coeffs_1000_6000 );
74  this->check_coefficients( N2_curve_fit.coefficients(3), this->_N2_coeffs_6000_20000 );
75  this->check_coefficients( N2_curve_fit.coefficients(4), this->_N2_coeffs_20000_99999 );
76 
77  // Check NO2 coefficients
78  this->check_coefficients( NO2_curve_fit.coefficients(0), this->_NO2_coeffs_0_200 );
79  this->check_coefficients( NO2_curve_fit.coefficients(1), this->_NO2_coeffs_200_1000 );
80  this->check_coefficients( NO2_curve_fit.coefficients(2), this->_NO2_coeffs_1000_6000 );
81  this->check_coefficients( NO2_curve_fit.coefficients(3), this->_NO2_coeffs_6000_99999 );
82  }
83 
84  void check_coefficients( const Scalar* parsed_coeffs, std::vector<Scalar>& exact_coeffs )
85  {
86  for( unsigned int c = 0; c < exact_coeffs.size(); c++ )
87  CPPUNIT_ASSERT_DOUBLES_EQUAL( exact_coeffs[c], parsed_coeffs[c], this->tol() );
88  }
89 
90  Scalar tol()
91  { return std::numeric_limits<Scalar>::epsilon() * 10; }
92 
93  };
94 
95  template<typename Scalar>
97  {
98  public:
99 
101  {
102  std::vector<std::string> species_str_list(2);
103  species_str_list[0] = "H2";
104  species_str_list[1] = "N2";
105 
106  Antioch::ChemicalMixture<Scalar> chem_mixture( species_str_list );
107 
108  std::string thermo_filename = std::string(ANTIOCH_TESTING_INPUT_FILES_PATH)+"nasa7_thermo_test.xml";
109 
111 
112  Antioch::read_nasa_mixture_data( nasa_mixture, thermo_filename, Antioch::XML );
113 
114  this->check_curve_fits(nasa_mixture);
115  }
116 
118  {
119  std::string thermo_filename = std::string(ANTIOCH_TESTING_INPUT_FILES_PATH)+"nasa7_thermo_test.xml";
120 
121  Antioch::XMLParser<Scalar> xml_parser(thermo_filename,false);
122 
123  std::vector<std::string> species_str_list = xml_parser.species_list();
124 
125  Antioch::ChemicalMixture<Scalar> chem_mixture( species_str_list );
126 
128 
129  xml_parser.read_thermodynamic_data(nasa_mixture);
130 
131  this->check_curve_fits(nasa_mixture);
132  }
133 
135  {
136  const Antioch::NASA7CurveFit<Scalar>& H2_curve_fit = nasa_mixture.curve_fit(0);
137  const Antioch::NASA7CurveFit<Scalar>& N2_curve_fit = nasa_mixture.curve_fit(1);
138 
139  CPPUNIT_ASSERT_EQUAL( (unsigned int)2, H2_curve_fit.n_intervals() );
140  CPPUNIT_ASSERT_EQUAL( (unsigned int)2, N2_curve_fit.n_intervals() );
141 
142  // Check N2 coefficients
143  this->check_coefficients( H2_curve_fit.coefficients(0), this->_H2_coeffs_200_1000 );
144  this->check_coefficients( H2_curve_fit.coefficients(1), this->_H2_coeffs_1000_3500 );
145 
146  // Check NO2 coefficients
147  this->check_coefficients( N2_curve_fit.coefficients(0), this->_N2_coeffs_300_1000 );
148  this->check_coefficients( N2_curve_fit.coefficients(1), this->_N2_coeffs_1000_5000 );
149  }
150 
151  void check_coefficients( const Scalar* parsed_coeffs, std::vector<Scalar>& exact_coeffs )
152  {
153  for( unsigned int c = 0; c < exact_coeffs.size(); c++ )
154  CPPUNIT_ASSERT_DOUBLES_EQUAL( exact_coeffs[c], parsed_coeffs[c], this->tol() );
155  }
156 
157  Scalar tol()
158  { return std::numeric_limits<Scalar>::epsilon() * 10; }
159 
160  };
161 
163  {
164  public:
166 
168 
170 
171  };
172 
174  {
175  public:
177 
179 
181 
182  };
183 
185  {
186  public:
188 
190 
192 
193  };
194 
196  {
197  public:
199 
202 
204 
205  };
206 
208  {
209  public:
211 
214 
216 
217  };
218 
220  {
221  public:
223 
226 
228 
229  };
230 
237 
238 } // end namespace AntiochTesting
239 
240 #endif // ANTIOCH_HAVE_CPPUNIT
CPPUNIT_TEST_SUITE(NASA9XMLParsingTestFloat)
const NASAFit & curve_fit(unsigned int s) const
Definition: nasa_mixture.h:179
const CoeffType * coefficients(const unsigned int interval) const
The ordering/packing of the coefficients will depend on the subclass.
CPPUNIT_TEST_SUITE(NASA9XMLParsingTestDouble)
void read_thermodynamic_data(NASAThermoMixture< NumericType, NASA7CurveFit< NumericType > > &thermo)
reads the thermo, NASA generalist, no templates for virtual
Definition: xml_parser.h:96
CPPUNIT_TEST_SUITE(NASA9XMLParsingTestLongDouble)
void read_nasa_mixture_data(NASAThermoMixture< NumericType, CurveType > &thermo, const std::string &filename=DefaultSourceFilename::thermo_data(), ParsingType=ASCII, bool verbose=true)
This class stores the NASA polynomial fit to the thermodynamics quantities and .
Definition: ascii_parser.h:68
CPPUNIT_TEST_SUITE(NASA7XMLParsingTestLongDouble)
CPPUNIT_TEST_SUITE_REGISTRATION(ArrheniusRateEigenFloatTest)
void check_coefficients(const Scalar *parsed_coeffs, std::vector< Scalar > &exact_coeffs)
Nothing is stored, this parser is based on the tinyxml2 implementation.
Class storing chemical mixture properties.
unsigned int n_intervals() const
The number of intervals for this NASA9 curve fit.
const std::vector< std::string > species_list()
reads the species set
Definition: xml_parser.C:203
void check_curve_fits(const Antioch::NASAThermoMixture< Scalar, Antioch::NASA7CurveFit< Scalar > > &nasa_mixture)
CPPUNIT_TEST_SUITE(NASA7XMLParsingTestDouble)
CPPUNIT_TEST_SUITE(NASA7XMLParsingTestFloat)
void check_coefficients(const Scalar *parsed_coeffs, std::vector< Scalar > &exact_coeffs)

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