antioch-0.4.0
kinetics_theory_thermal_conductivity_vec_unit.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 
28 // valarray has to be declared before Antioch or gcc can't find the
29 // right versions of exp() and pow() to use??
30 
31 #include "antioch_config.h"
32 
33 #include <valarray>
34 
35 #ifdef ANTIOCH_HAVE_EIGEN
36 #include "Eigen/Dense"
37 #endif
38 
39 #ifdef ANTIOCH_HAVE_METAPHYSICL
40 #include "metaphysicl/numberarray.h"
41 #endif
42 
43 #ifdef ANTIOCH_HAVE_VEXCL
44 #include "vexcl/vexcl.hpp"
45 #endif
46 
51 
55 
56 #include "antioch/eigen_utils.h"
58 #include "antioch/valarray_utils.h"
59 #include "antioch/vexcl_utils.h"
60 
61 #ifdef ANTIOCH_HAVE_GRVY
62 #include "grvy.h"
63 
64 GRVY::GRVY_Timer_Class gt;
65 #endif
66 
67 #include <cmath>
68 #include <limits>
69 
70 template <typename Scalar, typename Element>
71 int test_k( const Element & k, const Scalar & k_exact, const Scalar & tol )
72 {
73  using std::abs;
74 
75  int return_flag = 0;
76 
77  const Scalar rel_error = abs( (k - k_exact)/k_exact);
78 
79  if( rel_error > tol )
80  {
81  std::cerr << std::setprecision(20) << std::scientific
82  << "Error: Mismatch in thermal conductivity" << std::endl
83  << "k = " << k << std::endl
84  << "k_exact = " << k_exact << std::endl
85  << "rel_error = " << rel_error << std::endl
86  << "tol = " << tol << std::endl;
87  return_flag = 1;
88  }
89 
90  return return_flag;
91 }
92 
93 template <typename PairScalars>
94 int vectester(const PairScalars& example, const std::string& testname)
95 {
96 
97  typedef typename Antioch::value_type<PairScalars>::type Scalar;
98 
99  std::vector<std::string> species_str_list;
100  const unsigned int n_species = 1;
101  species_str_list.reserve(n_species);
102  species_str_list.push_back( "N2" );
103 
104  const Scalar LJ_depth_N2 = 97.53L;
105  const Scalar Z_298 = 4.0L;
106 
107  Antioch::ChemicalMixture<Scalar> chem_mixture( species_str_list );
108 
109  Antioch::StatMechThermodynamics<Scalar> thermo( chem_mixture );
110 
112 
113  // Construct from example to avoid resizing issues
114  PairScalars mu = example;
115  PairScalars dss = example;
116  PairScalars rho = example;
117  PairScalars T = example;
118  for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple)
119  {
120  T[2*tuple] = 1500.1;
121  T[2*tuple+1] = 1600.1;
122  mu[2*tuple] = 3.14e-3;
123  mu[2*tuple+1] = 3.14e-3;
124  dss[2*tuple] = 5.23e-5;
125  dss[2*tuple+1] = 5.23e-5;
126  rho[2*tuple] = 1.4;
127  rho[2*tuple+1] = 1.4;
128  }
129 
130  const Scalar k_exact0 = 3.19434291925996020233442116364270671873509961381739235964650684;
131  const Scalar k_exact1 = 3.2021908709042895344166123247634817043607657971633006497668;
132 
133  int return_flag = 0;
134 
135 #ifdef ANTIOCH_HAVE_GRVY
136  gt.BeginTimer(testname);
137 #endif
138 
139  const PairScalars k_ps = k(0,mu,T,rho,dss);
140 
141 #ifdef ANTIOCH_HAVE_GRVY
142  gt.EndTimer(testname);
143 #endif
144 
145  const Scalar tol = (std::numeric_limits<Scalar>::epsilon()*10 < 7e-17)?
146  7e-17:
147  std::numeric_limits<Scalar>::epsilon()*10;
148 
149  for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple)
150  {
151 
152  return_flag = test_k( k_ps[2*tuple], k_exact0, tol ) || return_flag;
153  return_flag = test_k( k_ps[2*tuple+1], k_exact1, tol ) || return_flag;
154  }
155 
156  return return_flag;
157 }
158 
159 
160 int main()
161 {
162  int returnval = 0;
163 
164  returnval = returnval ||
165  vectester (std::valarray<float>(2*ANTIOCH_N_TUPLES), "valarray<float>");
166  returnval = returnval ||
167  vectester (std::valarray<double>(2*ANTIOCH_N_TUPLES), "valarray<double>");
168  returnval = returnval ||
169  vectester (std::valarray<long double>(2*ANTIOCH_N_TUPLES), "valarray<ld>");
170 #ifdef ANTIOCH_HAVE_EIGEN
171  returnval = returnval ||
172  vectester (Eigen::Array<float, 2*ANTIOCH_N_TUPLES, 1>(), "Eigen::ArrayXf");
173  returnval = returnval ||
174  vectester (Eigen::Array<double, 2*ANTIOCH_N_TUPLES, 1>(), "Eigen::ArrayXd");
175  returnval = returnval ||
176  vectester (Eigen::Array<long double, 2*ANTIOCH_N_TUPLES, 1>(), "Eigen::ArrayXld");
177 #endif
178 #ifdef ANTIOCH_HAVE_METAPHYSICL
179  returnval = returnval ||
180  vectester (MetaPhysicL::NumberArray<2*ANTIOCH_N_TUPLES, float> (0), "NumberArray<float>");
181  returnval = returnval ||
182  vectester (MetaPhysicL::NumberArray<2*ANTIOCH_N_TUPLES, double> (0), "NumberArray<double>");
183  returnval = returnval ||
184  vectester (MetaPhysicL::NumberArray<2*ANTIOCH_N_TUPLES, long double> (0), "NumberArray<ld>");
185 #endif
186 #ifdef ANTIOCH_HAVE_VEXCL
187  vex::Context ctx_f (vex::Filter::All);
188  if (!ctx_f.empty())
189  returnval = returnval ||
190  vectester (vex::vector<float> (ctx_f, 2*ANTIOCH_N_TUPLES), "vex::vector<float>");
191 
192  vex::Context ctx_d (vex::Filter::DoublePrecision);
193  if (!ctx_d.empty())
194  returnval = returnval ||
195  vectester (vex::vector<double> (ctx_d, 2*ANTIOCH_N_TUPLES), "vex::vector<double>");
196 #endif
197 
198 #ifdef ANTIOCH_HAVE_GRVY
199  gt.Finalize();
200  gt.Summarize();
201 #endif
202 
203  return returnval;
204 }
Conductivity based on kinetic theory of mixtures approximations.
int test_k(const Element &k, const Scalar &k_exact, const Scalar &tol)
Class storing chemical mixture properties.
int vectester(const PairScalars &example, const std::string &testname)

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