antioch-0.4.0
blottner_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 // $Id$
28 //
29 //--------------------------------------------------------------------------
30 //--------------------------------------------------------------------------
31 
32 
33 
34 #include <valarray>
35 
36 #ifdef ANTIOCH_HAVE_EIGEN
37 #include "Eigen/Dense"
38 #endif
39 
40 #ifdef ANTIOCH_HAVE_METAPHYSICL
41 #include "metaphysicl/numberarray.h"
42 #endif
43 
44 #ifdef ANTIOCH_HAVE_VEXCL
45 #include "vexcl/vexcl.hpp"
46 #endif
47 
48 // Declare metaprogramming overloads before they're used
53 
54 // C++
55 #include <cmath>
56 #include <iostream>
57 #include <limits>
58 
59 // Antioch
61 
62 #include "antioch/eigen_utils.h"
64 #include "antioch/valarray_utils.h"
65 #include "antioch/vexcl_utils.h"
66 
67 #ifdef ANTIOCH_HAVE_GRVY
68 #include "grvy.h"
69 
70 GRVY::GRVY_Timer_Class gt;
71 #endif
72 
73 
74 template <typename Scalar, typename PairScalars>
75 int test_viscosity( const PairScalars mu, const PairScalars mu_exact,
76  const Scalar tol, const std::string& testname )
77 {
78  using std::abs;
79 
80  int return_flag = 0;
81 
82  const PairScalars rel_error = abs( (mu - mu_exact)/mu_exact);
83 
84  if( Antioch::max(rel_error) > tol )
85  {
86  std::cerr << "Error: Mismatch in viscosity" << std::endl
87  << "mu(T) = (" << mu[0] << ',' << mu[1] << ')' << std::endl
88  << "mu_exact = (" << mu_exact[0] << ',' << mu_exact[1] << ')' << std::endl
89  << "rel_error = (" << rel_error[0] << ',' << rel_error[1] << ')' << std::endl
90  << "tol = " << tol << std::endl;
91  return_flag = 1;
92  }
93 
94  return return_flag;
95 }
96 
97 template <typename PairScalars>
98 int vectester(const PairScalars& example, const std::string& testname)
99 {
100  typedef typename Antioch::value_type<PairScalars>::type Scalar;
101 
102  const Scalar a = 3.14e-3L;
103  const Scalar b = 2.71e-2L;
104  const Scalar c = 42.0e-5L;
105 
107 
108  std::cout << mu << std::endl;
109 
110  PairScalars T = example;
111  PairScalars mu_exact = example;
112  PairScalars mu_exact2 = example;
113 
114  for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple)
115  {
116  T[2*tuple] = 1521.2L;
117  T[2*tuple+1] = 1621.2L;
118 
119  // bc gives
120  mu_exact[2*tuple] = 0.1444222341677025337305172031086891L;
121  mu_exact[2*tuple+1] = 0.1450979382180072302532592937776388L;
122 
123  mu_exact2[2*tuple] = .1221724955488799960527696821225472L;
124  mu_exact2[2*tuple+1] = .1224428450807678499433510473203746L;
125  }
126 
127  int return_flag = 0;
128 
129  const Scalar tol = std::numeric_limits<Scalar>::epsilon() * 2;
130 
131 #ifdef ANTIOCH_HAVE_GRVY
132  gt.BeginTimer(testname);
133 #endif
134 
135  const PairScalars mu_T = mu(T);
136 
137 #ifdef ANTIOCH_HAVE_GRVY
138  gt.EndTimer(testname);
139 #endif
140 
141  return_flag = test_viscosity( mu_T, mu_exact, tol, testname );
142 
143  const Scalar a2 = 1e-3L;
144  const Scalar b2 = 2e-2L;
145  const Scalar c2 = 3e-5L;
146 
147  mu.reset_coeffs( a2, b2, c2 );
148 
149 #ifdef ANTIOCH_HAVE_GRVY
150  gt.BeginTimer(testname);
151 #endif
152 
153  const PairScalars mu2_T = mu(T);
154 
155 #ifdef ANTIOCH_HAVE_GRVY
156  gt.EndTimer(testname);
157 #endif
158 
159  return_flag = test_viscosity( mu2_T, mu_exact2, tol, testname );
160 
161  return return_flag;
162 }
163 
164 int main()
165 {
166  int returnval = 0;
167 
168  returnval = returnval ||
169  vectester (std::valarray<float>(2*ANTIOCH_N_TUPLES), "valarray<float>");
170  returnval = returnval ||
171  vectester (std::valarray<double>(2*ANTIOCH_N_TUPLES), "valarray<double>");
172  returnval = returnval ||
173  vectester (std::valarray<long double>(2*ANTIOCH_N_TUPLES), "valarray<ld>");
174 #ifdef ANTIOCH_HAVE_EIGEN
175  returnval = returnval ||
176  vectester (Eigen::Array<float, 2*ANTIOCH_N_TUPLES, 1>(), "Eigen::ArrayXf");
177  returnval = returnval ||
178  vectester (Eigen::Array<double, 2*ANTIOCH_N_TUPLES, 1>(), "Eigen::ArrayXd");
179  returnval = returnval ||
180  vectester (Eigen::Array<long double, 2*ANTIOCH_N_TUPLES, 1>(), "Eigen::ArrayXld");
181 #endif
182 #ifdef ANTIOCH_HAVE_METAPHYSICL
183  returnval = returnval ||
184  vectester (MetaPhysicL::NumberArray<2*ANTIOCH_N_TUPLES, float> (0), "NumberArray<float>");
185  returnval = returnval ||
186  vectester (MetaPhysicL::NumberArray<2*ANTIOCH_N_TUPLES, double> (0), "NumberArray<double>");
187  returnval = returnval ||
188  vectester (MetaPhysicL::NumberArray<2*ANTIOCH_N_TUPLES, long double> (0), "NumberArray<ld>");
189 #endif
190 #ifdef ANTIOCH_HAVE_VEXCL
191  vex::Context ctx_f (vex::Filter::All);
192  if (!ctx_f.empty())
193  returnval = returnval ||
194  vectester (vex::vector<float> (ctx_f, 2*ANTIOCH_N_TUPLES), "vex::vector<float>");
195 
196  vex::Context ctx_d (vex::Filter::DoublePrecision);
197  if (!ctx_d.empty())
198  returnval = returnval ||
199  vectester (vex::vector<double> (ctx_d, 2*ANTIOCH_N_TUPLES), "vex::vector<double>");
200 #endif
201 
202 #ifdef ANTIOCH_HAVE_GRVY
203  gt.Finalize();
204  gt.Summarize();
205 #endif
206 
207  return returnval;
208 }
Antioch::enable_if_c< is_eigen< T >::value, typename value_type< T >::type >::type max(const T &in)
Definition: eigen_utils.h:88
int test_viscosity(const PairScalars mu, const PairScalars mu_exact, const Scalar tol, const std::string &testname)
int vectester(const PairScalars &example, const std::string &testname)
void reset_coeffs(const CoeffType a, const CoeffType b, const CoeffType c)

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