antioch-0.4.0
sigma_bin_converter_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 // C++
33 #include <limits>
34 #include <string>
35 #include <iostream>
36 #include <iomanip>
37 #include <fstream>
38 
39 // Antioch
44 #include "antioch/vector_utils.h"
45 /*
46  x[0] = 1.; y[0] = 1.;
47  x[1] = 2.; y[1] = 2.;
48  x[2] = 3.; y[2] = 5.;
49  x[3] = 4.; y[3] = 8.;
50  x[4] = 5.; y[4] = 6.;
51  x[5] = 6.; y[5] = 10.;
52  x[6] = 7.; y[6] = 7.;
53  x[7] = 8.; y[7] = 4.;
54  x[8] = 9.; y[8] = 2.;
55  x[9] = 10.; y[9] = 0.3; // right stairs, this value is useless
56 */
57 template <typename VectorScalar>
58 void make_custom(unsigned int choice, VectorScalar & x, VectorScalar & y)
59 {
60  // sum_{bin} Delta x * y
61  switch(choice)
62  {
63  case(0): // 9 bin contained in ref -> [2.5;8.5] within [1;10]
64  {
65  x.resize(9); y.resize(9);
66  x[0] = 2.50L; y[0] = 2.25L/0.75L; // 0.50 * 2 + 0.25 * 5
67  x[1] = 3.25L; y[1] = 3.75L/0.75L; // 0.75 * 5
68  x[2] = 4.00L; y[2] = 6.00L/0.75L; // 0.75 * 8
69  x[3] = 4.75L; y[3] = 5.00L/0.75L; // 0.25 * 8 + 0.5 * 6
70  x[4] = 5.50L; y[4] = 5.50L/0.75L; // 0.25 * 6 + 0.25 * 10
71  x[5] = 6.25L; y[5] = 7.50L/0.75L; // 0.75 * 10
72  x[6] = 7.00L; y[6] = 5.25L/0.75L; // 0.75 * 7
73  x[7] = 7.75L; y[7] = 3.75L/0.75L; // 0.25 * 7 + 0.5 * 4
74  x[8] = 8.50L; y[8] = 0.00L/0.75L; // 0. (right stairs)
75  break;
76  }
77  case(1):// 9 bin outside ref -> [0;12] containing [1;10]
78  {
79  x.resize(9); y.resize(9);
80  x[0] = 0.00L; y[0] = 0.50L/1.50L; // 0.5 * 1
81  x[1] = 1.50L; y[1] = 2.50L/1.50L; // 0.5 * 1 + 2.0 * 1
82  x[2] = 3.00L; y[2] = 9.00L/1.50L; // 1.0 * 5 + 0.5 * 8
83  x[3] = 4.50L; y[3] = 10.0L/1.50L; // 0.5 * 8 + 1.0 * 6
84  x[4] = 6.00L; y[4] = 13.5L/1.50L; // 1.0 * 10 + 0.5 * 7
85  x[5] = 7.50L; y[5] = 7.50L/1.50L; // 0.50 * 7 + 1.0 * 4
86  x[6] = 9.00L; y[6] = 2.00L/1.50L; // 1.0 * 2
87  x[7] = 10.5L; y[7] = 0.00L/1.50L; // 0
88  x[8] = 12.0L; y[8] = 0.00L/1.50L; // 0. (right stairs)
89  break;
90  }
91  case(2): // 5 bins beyond only min -> [-1;3.8] in [0;10]
92  {
93  x.resize(5); y.resize(5);
94  x[0] = -1.00L; y[0] = 0.00L/1.20L; // 0
95  x[1] = 0.20L; y[1] = 0.40L/1.20L; // 0.4 * 1
96  x[2] = 1.40L; y[2] = 1.80L/1.20L; // 0.6 * 1 + 0.6 * 2
97  x[3] = 2.60L; y[3] = 4.80L/1.20L; // 0.4 * 2 + 0.8 * 5
98  x[4] = 3.80L; y[4] = 00.0L/1.20L; // 0. (right stairs)
99  break;
100  }
101  case(3):// 6 bins beyond only max -> [2;10.75] in [0;10]
102  {
103  x.resize(6); y.resize(6);
104  x[0] = 2.00L; y[0] = 5.75L/1.75L; // 1.00 * 2 + 0.75 * 5
105  x[1] = 3.75L; y[1] = 12.25L/1.75L; // 0.25 * 5 + 1.00 * 8 + 0.50 * 6
106  x[2] = 5.50L; y[2] = 14.75L/1.75L; // 0.50 * 6 + 1.00 * 10 + 0.25 * 7
107  x[3] = 7.25L; y[3] = 9.25L/1.75L; // 0.75 * 7 + 1.00 * 4
108  x[4] = 9.00L; y[4] = 2.00L/1.75L; // 1.00 * 2
109  x[5] = 10.75L; y[5] = 00.00L/1.75L; // 0. (right stairs)
110  break;
111  }
112  }
113 
114 }
115 
116 template <typename VectorScalar>
117 void make_reference(VectorScalar & x, VectorScalar & y)
118 {
119  x.resize(10,0);
120  y.resize(10,0);
121  for(unsigned int i = 0; i < 10; i++)
122  {
123  x[i] = ((typename Antioch::value_type<VectorScalar>::type)(i+1));
124  }
125  y[0] = 1.L;
126  y[1] = 2.L;
127  y[2] = 5.L;
128  y[3] = 8.L;
129  y[4] = 6.L;
130  y[5] = 10.L;
131  y[6] = 7.L;
132  y[7] = 4.L;
133  y[8] = 2.L;
134  y[9] = 0.3L;
135 
136 }
137 
138 
139 template <typename Scalar>
140 int tester()
141 {
142  std::vector<Scalar> bin_ref_x,bin_ref_y;
143 
144  make_reference(bin_ref_x,bin_ref_y);
145 
147 
148  const Scalar tol = std::numeric_limits<Scalar>::epsilon() * 10;
149 
150  int return_flag = 0;
151 
152  // 4 cases:
153  // - custom inside ref
154  // - ref inside custom
155  // - custom beyond only min ref
156  // - custom beyond only max ref
157  for(unsigned int i = 0; i < 4; i++)
158  {
159  std::vector<Scalar> bin_custom_x, exact_sol_y;
160  make_custom(i,bin_custom_x,exact_sol_y);
161  std::vector<Scalar> bin_custom_y(bin_custom_x.size());
162 
163  bin.y_on_custom_grid(bin_ref_x,bin_ref_y,
164  bin_custom_x,bin_custom_y);
165 
166 
167  for(unsigned int il = 0; il < bin_custom_x.size() - 1; il++)
168  {
169  const Scalar dist = (exact_sol_y[il] < tol)?std::abs(bin_custom_y[il] - exact_sol_y[il]):std::abs(bin_custom_y[il] - exact_sol_y[il])/exact_sol_y[il];
170  if( dist > tol )
171  {
172  std::cout << std::scientific << std::setprecision(16)
173  << "Error: Mismatch in bin values." << std::endl
174  << "case (" << bin_custom_x[il] << ";" << bin_custom_x[il+1] << ")" << std::endl
175  << "bin = " << bin_custom_y[il] << std::endl
176  << "bin_exact = " << exact_sol_y[il] << std::endl
177  << "relative error = " << dist << std::endl
178  << "tolerance = " << tol << std::endl;
179 
180  return_flag = 1;
181  }
182  }
183  }
184 
185  return return_flag;
186 }
187 
188 int main()
189 {
190 
191  return (tester<float>() ||
192  tester<double>() ||
193  tester<long double>()
194  );
195 }
void make_reference(VectorScalar &x, VectorScalar &y)
int tester()
void y_on_custom_grid(const VectorCoeffType &x_old, const VectorCoeffType &y_old, const VectorStateType &x_new, VectorStateType &y_new) const
void make_custom(unsigned int choice, VectorScalar &x, VectorScalar &y)

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