antioch-0.4.0
kinetics_theory_viscosity_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 // valarray has to be declared before Antioch or gcc can't find the
28 // right versions of exp() and pow() to use??
29 
30 #include "antioch_config.h"
31 
32 #include <valarray>
33 
34 #ifdef ANTIOCH_HAVE_EIGEN
35 #include "Eigen/Dense"
36 #endif
37 
38 #ifdef ANTIOCH_HAVE_METAPHYSICL
39 #include "metaphysicl/numberarray.h"
40 #endif
41 
42 #ifdef ANTIOCH_HAVE_VEXCL
43 #include "vexcl/vexcl.hpp"
44 #endif
45 
51 
53 #include "antioch/gsl_spliner.h"
54 
55 #include "antioch/eigen_utils.h"
57 #include "antioch/valarray_utils.h"
58 #include "antioch/vexcl_utils.h"
59 #include "antioch/vector_utils.h"
60 
62 
63 #ifdef ANTIOCH_HAVE_GRVY
64 #include "grvy.h"
65 
66 GRVY::GRVY_Timer_Class gt;
67 #endif
68 
69 #include <cmath>
70 #include <limits>
71 
72 #ifdef ANTIOCH_HAVE_GSL
73 template <typename Scalar, typename Element>
74 int test_viscosity( const Element & mu, const Scalar & mu_exact, const Scalar & tol )
75 {
76  using std::abs;
77 
78  int return_flag = 0;
79 
80  const double rel_error = abs( (mu - mu_exact)/mu_exact);
81 
82  if( rel_error > tol )
83  {
84  std::cerr << std::setprecision(15) << std::scientific;
85  std::cerr << "Error: Mismatch in viscosity" << std::endl
86  << "mu(T) = " << mu << std::endl
87  << "mu_exact = " << mu_exact << std::endl
88  << "rel_error = " << rel_error << std::endl
89  << "tol = " << tol << std::endl;
90  return_flag = 1;
91  }
92 
93  return return_flag;
94 }
95 
96 template <typename PairScalars>
97 int vectester(const PairScalars& example, const std::string& testname)
98 {
99  using std::abs;
100  using std::exp;
101 
102  typedef typename Antioch::value_type<PairScalars>::type Scalar;
103 
104 // value for N2
105  const Scalar LJ_depth(97.530L);
106  const Scalar LJ_diameter(3.621L);
107  const Scalar dipole_moment(0.L);
108  const Scalar mass(28.016e-3L/Antioch::Constants::Avogadro<Scalar>());
109 
110  Antioch::KineticsTheoryViscosity<Scalar,Antioch::GSLSpliner> mu_sp(LJ_depth,LJ_diameter,dipole_moment,mass);
111 
112  // Construct from example to avoid resizing issues
113  PairScalars T = example;
114  for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple)
115  {
116  T[2*tuple] = 1500.1;
117  T[2*tuple+1] = 1600.1;
118  }
119 
120  const Scalar mu_exact0 = 0.0000417395098853601937871105407365424874568203066945573066;
121  const Scalar mu_exact1 = 0.0000431082906407300464864929380770860406892212065614947462;
122 
123  int return_flag = 0;
124 
125 #ifdef ANTIOCH_HAVE_GRVY
126  gt.BeginTimer(testname);
127 #endif
128 
129  PairScalars mu = mu_sp(T) * mu_sp.Stockmayer(T);
130 
131 #ifdef ANTIOCH_HAVE_GRVY
132  gt.EndTimer(testname);
133 #endif
134 
135  const Scalar tol = (std::numeric_limits<Scalar>::epsilon()*10 < 5e-17)?5e-17:
136  std::numeric_limits<Scalar>::epsilon()*10;
137 
138  for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple)
139  {
140  return_flag = test_viscosity( mu[2*tuple], mu_exact0, tol ) || return_flag;
141  return_flag = test_viscosity( mu[2*tuple+1], mu_exact1, tol ) || return_flag;
142  }
143 
144  return return_flag;
145 }
146 #endif // ANTIOCH_HAVE_GSL
147 
148 int main()
149 {
150  int returnval = 0;
151 
152 #ifdef ANTIOCH_HAVE_GSL
153 
154  returnval = returnval ||
155  vectester (std::valarray<float>(2*ANTIOCH_N_TUPLES), "valarray<float>");
156  returnval = returnval ||
157  vectester (std::valarray<double>(2*ANTIOCH_N_TUPLES), "valarray<double>");
158  returnval = returnval ||
159  vectester (std::valarray<long double>(2*ANTIOCH_N_TUPLES), "valarray<ld>");
160 #ifdef ANTIOCH_HAVE_EIGEN
161  returnval = returnval ||
162  vectester (Eigen::Array<float, 2*ANTIOCH_N_TUPLES, 1>(), "Eigen::ArrayXf");
163  returnval = returnval ||
164  vectester (Eigen::Array<double, 2*ANTIOCH_N_TUPLES, 1>(), "Eigen::ArrayXd");
165  returnval = returnval ||
166  vectester (Eigen::Array<long double, 2*ANTIOCH_N_TUPLES, 1>(), "Eigen::ArrayXld");
167 #endif
168 #ifdef ANTIOCH_HAVE_METAPHYSICL
169  returnval = returnval ||
170  vectester (MetaPhysicL::NumberArray<2*ANTIOCH_N_TUPLES, float> (0), "NumberArray<float>");
171  returnval = returnval ||
172  vectester (MetaPhysicL::NumberArray<2*ANTIOCH_N_TUPLES, double> (0), "NumberArray<double>");
173  returnval = returnval ||
174  vectester (MetaPhysicL::NumberArray<2*ANTIOCH_N_TUPLES, long double> (0), "NumberArray<ld>");
175 #endif
176 #ifdef ANTIOCH_HAVE_VEXCL
177  vex::Context ctx_f (vex::Filter::All);
178  if (!ctx_f.empty())
179  returnval = returnval ||
180  vectester (vex::vector<float> (ctx_f, 2*ANTIOCH_N_TUPLES), "vex::vector<float>");
181 
182  vex::Context ctx_d (vex::Filter::DoublePrecision);
183  if (!ctx_d.empty())
184  returnval = returnval ||
185  vectester (vex::vector<double> (ctx_d, 2*ANTIOCH_N_TUPLES), "vex::vector<double>");
186 #endif
187 
188 #ifdef ANTIOCH_HAVE_GRVY
189  gt.Finalize();
190  gt.Summarize();
191 #endif
192 
193 #else // ANTIOCH_HAVE_GSL
194  // 77 return code tells Automake we skipped this.
195  returnval = 77;
196 #endif
197 
198  return returnval;
199 }
int test_viscosity(const Scalar mu, const Scalar mu_exact, const Scalar tol)
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