Code-Eli  0.3.6
piecewise_four_digit_creator_test_suite.hpp
Go to the documentation of this file.
1 /*********************************************************************************
2 * Copyright (c) 2013 David D. Marshall <ddmarsha@calpoly.edu>
3 *
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * David D. Marshall - initial code and implementation
11 ********************************************************************************/
12 
13 #ifndef piecewise_four_digit_creator_test_suite_hpp
14 #define piecewise_four_digit_creator_test_suite_hpp
15 
16 #include <cmath> // std::pow, std::exp
17 
18 #include <typeinfo> // typeid
19 #include <string> // std::string
20 #include <sstream> // std::stringstream
21 #include <iomanip> // std::setw
22 #include <limits> // std::numeric_limits
23 
24 #include "eli/constants/math.hpp"
25 #include "eli/mutil/fd/d1o2.hpp"
26 #include "eli/mutil/fd/d2o2.hpp"
29 
30 template<typename data__>
31 class piecewise_four_digit_creator_test_suite : public Test::Suite
32 {
33  private:
41 
42  tolerance_type tol;
43 
44  protected:
45  void AddTests(const float &)
46  {
47  // add the tests
49  }
50  void AddTests(const double &)
51  {
52  // add the tests
54  }
55  void AddTests(const long double &)
56  {
57  // add the tests
59  }
60 
61  public:
63  {
64  AddTests(data__());
65  }
67  {
68  }
69 
70  private:
71  void octave_print(int figno, const piecewise_curve_type &pc) const
72  {
73  index_type i, pp, ns;
74  data_type tmin, tmax;
75 
76  ns=pc.number_segments();
77  pc.get_parameter_min(tmin);
78  pc.get_parameter_max(tmax);
79 
80  std::cout << "figure(" << figno << ");" << std::endl;
81 
82  // get control points and print
83  std::cout << "cp_x=[";
84  for (pp=0; pp<ns; ++pp)
85  {
86  curve_type bez;
87  pc.get(bez, pp);
88  for (i=0; i<=bez.degree(); ++i)
89  {
90  std::cout << bez.get_control_point(i).x();
91  if (i<bez.degree())
92  std::cout << ", ";
93  else if (pp<ns-1)
94  std::cout << "; ";
95  }
96  std::cout << std::endl;
97  }
98  std::cout << "];" << std::endl;
99 
100  std::cout << "cp_y=[";
101  for (pp=0; pp<ns; ++pp)
102  {
103  curve_type bez;
104  pc.get(bez, pp);
105  for (i=0; i<=bez.degree(); ++i)
106  {
107  std::cout << bez.get_control_point(i).y();
108  if (i<bez.degree())
109  std::cout << ", ";
110  else if (pp<ns-1)
111  std::cout << "; ";
112  }
113  std::cout << std::endl;
114  }
115  std::cout << "];" << std::endl;
116 
117  std::cout << "cp_z=[";
118  for (pp=0; pp<ns; ++pp)
119  {
120  curve_type bez;
121  pc.get(bez, pp);
122  for (i=0; i<=bez.degree(); ++i)
123  {
124  std::cout << bez.get_control_point(i).z();
125  if (i<bez.degree())
126  std::cout << ", ";
127  else if (pp<ns-1)
128  std::cout << "; ";
129  }
130  std::cout << std::endl;
131  }
132  std::cout << "];" << std::endl;
133 
134  // initialize the t parameters
135  std::vector<data__> t(129);
136  for (i=0; i<static_cast<index_type>(t.size()); ++i)
137  {
138  t[i]=tmin+(tmax-tmin)*static_cast<data__>(i)/(t.size()-1);
139  }
140 
141  // set the surface points
142  std::cout << "surf_x=[";
143  for (i=0; i<static_cast<index_type>(t.size()); ++i)
144  {
145  std::cout << pc.f(t[i]).x();
146  if (i<static_cast<index_type>(t.size()-1))
147  std::cout << ", ";
148  }
149  std::cout << "];" << std::endl;
150 
151  std::cout << "surf_y=[";
152  for (i=0; i<static_cast<index_type>(t.size()); ++i)
153  {
154  std::cout << pc.f(t[i]).y();
155  if (i<static_cast<index_type>(t.size()-1))
156  std::cout << ", ";
157  }
158  std::cout << "];" << std::endl;
159 
160  std::cout << "surf_z=[";
161  for (i=0; i<static_cast<index_type>(t.size()); ++i)
162  {
163  std::cout << pc.f(t[i]).z();
164  if (i<static_cast<index_type>(t.size()-1))
165  std::cout << ", ";
166  }
167  std::cout << "];" << std::endl;
168 
169  std::cout << "setenv('GNUTERM', 'x11');" << std::endl;
170  std::cout << "plot(surf_x, surf_y, '-k');" << std::endl;
171  std::cout << "hold on;" << std::endl;
172  std::cout << "plot(cp_x', cp_y', '-ok', 'MarkerFaceColor', [0 0 0]);" << std::endl;
173  std::cout << "hold off;" << std::endl;
174  std::cout << "axis equal;" << std::endl;
175  }
176 
178  {
179  point_creator_type af;
180 
181  data_type th, cam, cam_loc;
182  bool rtn;
183 
184  // set airfoil thickness
185  th=24;
186  rtn=af.set_thickness(th);
187  TEST_ASSERT(rtn);
188  TEST_ASSERT(af.get_thickness()==th);
189 
190  // set airfoil camber
191  cam=2;
192  cam_loc=3;
193  rtn=af.set_camber(cam, cam_loc);
194  TEST_ASSERT(rtn);
195  TEST_ASSERT(af.get_maximum_camber()==cam);
196  TEST_ASSERT(af.get_maximum_camber_location()==cam_loc);
197 
198  // test the name
199  std::string name, name_ref;
200 
201  af.set_sharp_trailing_edge(true);
202 
203  name_ref="NACA "+std::to_string(static_cast<int>(std::round(cam)))
204  +std::to_string(static_cast<int>(std::round(cam_loc)))
205  +std::to_string(static_cast<int>(std::round(th)));
206  name=af.get_name();
207  TEST_ASSERT(name==name_ref);
208 
209 
210  piecewise_curve_type af_pwc;
211 
212  af.create(af_pwc);
213 
214 // octave_print(1, af_pwc);
215 
216  }
217 };
218 
219 #endif
220 
piecewise_curve_type::point_type point_type
Definition: piecewise_four_digit_creator_test_suite.hpp:36
bool set_camber(const data_type &cam, const data_type &cam_loc)
Definition: piecewise_four_digit_creator.hpp:135
data_type get_maximum_camber() const
Definition: piecewise_four_digit_creator.hpp:140
eli::geom::curve::piecewise< eli::geom::curve::bezier, data__, 3 > piecewise_curve_type
Definition: piecewise_four_digit_creator_test_suite.hpp:34
piecewise_curve_type::data_type data_type
Definition: piecewise_four_digit_creator_test_suite.hpp:37
piecewise_four_digit_creator_test_suite()
Definition: piecewise_four_digit_creator_test_suite.hpp:62
data_type get_thickness() const
Definition: piecewise_four_digit_creator.hpp:130
tol__ tolerance_type
Definition: piecewise.hpp:278
data__ data_type
Definition: piecewise.hpp:276
data_type get_parameter_min() const
Definition: piecewise.hpp:366
curve_type::index_type index_type
Definition: piecewise.hpp:271
piecewise_curve_type::index_type index_type
Definition: piecewise_four_digit_creator_test_suite.hpp:38
index_type number_segments() const
Definition: piecewise.hpp:419
bool set_thickness(const data_type &t)
Definition: piecewise_four_digit_creator.hpp:125
Definition: piecewise.hpp:244
curve__< data__, dim__, tol__ > curve_type
Definition: piecewise.hpp:270
void create_airfoil_test()
Definition: piecewise_four_digit_creator_test_suite.hpp:177
std::string get_name() const
Definition: piecewise_four_digit_creator.hpp:155
data_type get_maximum_camber_location() const
Definition: piecewise_four_digit_creator.hpp:145
void octave_print(int figno, const piecewise_curve_type &pc) const
Definition: piecewise_four_digit_creator_test_suite.hpp:71
void AddTests(const long double &)
Definition: piecewise_four_digit_creator_test_suite.hpp:55
tolerance_type tol
Definition: piecewise_four_digit_creator_test_suite.hpp:42
void AddTests(const float &)
Definition: piecewise_four_digit_creator_test_suite.hpp:45
void set_sharp_trailing_edge(bool fl)
Definition: piecewise_four_digit_creator.hpp:116
data_type get_parameter_max() const
Definition: piecewise.hpp:374
eli::geom::curve::piecewise_four_digit_creator< data__, 3, tolerance_type > point_creator_type
Definition: piecewise_four_digit_creator_test_suite.hpp:40
Definition: piecewise_four_digit_creator_test_suite.hpp:31
void AddTests(const double &)
Definition: piecewise_four_digit_creator_test_suite.hpp:50
point_type f(const data_type &t) const
Definition: piecewise.hpp:1732
Definition: piecewise_four_digit_creator.hpp:100
piecewise_curve_type::curve_type curve_type
Definition: piecewise_four_digit_creator_test_suite.hpp:35
piecewise_curve_type::tolerance_type tolerance_type
Definition: piecewise_four_digit_creator_test_suite.hpp:39
error_code get(curve_type &curve, const index_type &index) const
Definition: piecewise.hpp:729
curve_type::point_type point_type
Definition: piecewise.hpp:272
~piecewise_four_digit_creator_test_suite()
Definition: piecewise_four_digit_creator_test_suite.hpp:66
virtual bool create(piecewise< bezier, data_type, dim__, tolerance_type > &pc) const
Definition: piecewise_four_digit_creator.hpp:160