antioch-0.4.0
rotational_relaxation_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 
50 
52 
53 #include "antioch/eigen_utils.h"
55 #include "antioch/valarray_utils.h"
56 #include "antioch/vexcl_utils.h"
57 
58 #include "antioch/cmath_shims.h"
59 
60 #ifdef ANTIOCH_HAVE_GRVY
61 #include "grvy.h"
62 
63 GRVY::GRVY_Timer_Class gt;
64 #endif
65 
66 #include <cmath>
67 #include <limits>
68 
69 const long double pi(3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825);
70 
71 template <typename Scalar>
72 Scalar F(const Scalar & x)
73 {
74  return 1.L + Antioch::ant_pow(pi,(float)1.5)/2.L * Antioch::ant_sqrt(x)
75  + (pi*pi/4.L + 2.L) * x
76  + Antioch::ant_pow(pi * x,(float)1.5);
77 }
78 
79 template <typename Scalar>
80 Scalar z(const Scalar & T, const Scalar & eps_kb, const Scalar & z_298)
81 {
82  return z_298 * F(eps_kb / 298.L) / F(eps_kb / T);
83 }
84 
85 
86 template <typename PairScalars>
87 int vectester(const PairScalars& example, const std::string& testname)
88 {
89 
90 std::cout << "entering " << testname << std::endl;
91  typedef typename Antioch::value_type<PairScalars>::type Scalar;
92 
93  const Scalar eps_kb = 97.53L; // N2 value
94  const Scalar z_298 = 4.0L; // N2 value
95 
96  Antioch::RotationalRelaxation<Scalar> rot(z_298,eps_kb);
97 
98  // Construct from example to avoid resizing issues
99  PairScalars T = example;
100  for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple)
101  {
102  T[2*tuple] = 1500.1L;
103  T[2*tuple+1] = 1600.1L;
104  }
105 
106  int return_flag = 0;
107 
108 #ifdef ANTIOCH_HAVE_GRVY
109  gt.BeginTimer(testname);
110 #endif
111 
112  const PairScalars Z = rot(T);
113 
114 #ifdef ANTIOCH_HAVE_GRVY
115  gt.EndTimer(testname);
116 #endif
117 
118  const Scalar tol = (std::numeric_limits<Scalar>::epsilon()*10 < 5e-17)?
119  5e-17:
120  std::numeric_limits<Scalar>::epsilon()*10;
121 
122  for (unsigned int tuple=0; tuple != ANTIOCH_N_TUPLES; ++tuple)
123  {
124  const Scalar Z_exact0 = z( (Scalar)1500.1, eps_kb, z_298);
125  const Scalar Z_exact1 = z( (Scalar)1600.1, eps_kb, z_298);
126 
127  if( abs( (Z[2*tuple] - Z_exact0)/Z_exact0 ) > tol )
128  {
129  std::cout << std::scientific << std::setprecision(20)
130  << "Error: Mismatch in Z values in test " << testname << std::endl
131  << "Z(T0) = " << Z[2*tuple] << std::endl
132  << "Z_exact = " << Z_exact0 << std::endl
133  << "absolute difference = " << Z[2*tuple] - Z_exact0 << std::endl
134  << "relative difference = " << std::abs(Z[2*tuple] - Z_exact0) / Z_exact0 << std::endl
135  << "tolerance = " << tol << std::endl;
136 
137  return_flag = 1;
138  break;
139  }
140 
141  if( abs( (Z[2*tuple+1] - Z_exact1)/Z_exact1 ) > tol )
142  {
143  std::cout << std::scientific << std::setprecision(20)
144  << "Error: Mismatch in Z values in test " << testname << std::endl
145  << "Z(T1) = " << Z[2*tuple+1] << std::endl
146  << "Z_exact = " << Z_exact1 << std::endl
147  << "absolute difference = " << Z[2*tuple+1] - Z_exact1 << std::endl
148  << "relative difference = " << std::abs(Z[2*tuple+1] - Z_exact1) / Z_exact1 << std::endl
149  << "tolerance = " << tol << std::endl;
150 
151  return_flag = 1;
152  break;
153  }
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 }
Scalar Z(const Scalar &T, const Scalar &eps_kb, const Scalar &z_298)
Scalar F(const Scalar &x)
const long double pi(3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825)
int vectester(const PairScalars &example, const std::string &testname)
Scalar z(const Scalar &T, const Scalar &eps_kb, const Scalar &z_298)

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