Code-Eli  0.3.6
piecewise_four_digit_creator.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 eli_geom_curve_piecewise_airfoil_creator_base_hpp
14 #define eli_geom_curve_piecewise_airfoil_creator_base_hpp
15 
16 #include <vector>
17 
18 #include "eli/code_eli.hpp"
19 
23 
24 namespace eli
25 {
26  namespace geom
27  {
28  namespace curve
29  {
30  template<typename data__, unsigned short dim__, typename tol__>
32  {
33  public:
34  typedef data__ data_type;
35  typedef Eigen::Matrix<data_type, 1, dim__> point_type;
36  typedef typename point_type::Index index_type;
37  typedef tol__ tolerance_type;
38 
39  public:
40  piecewise_airfoil_creator_base(const data_type &tt0) : dt(4), t0(tt0)
41  {
42  for (index_type i=0; i<static_cast<index_type>(dt.size()); ++i)
43  dt[i]=1;
44  }
47 
48  index_type get_number_segments() const
49  {
50  return static_cast<index_type>(dt.size());
51  }
52 
53  void set_t0(const data_type &tt0) {t0=tt0;}
54  data_type get_t0() const {return t0;}
55 
56  void set_segment_dt(const data_type &dtt, const index_type &i)
57  {
58  if ((dtt>0) && (i>=0) && (i<static_cast<index_type>(dt.size())))
59  dt[i]=dtt;
60  else
61  assert(false);
62  }
63  data_type get_segment_dt(const index_type &i) const
64  {
65  if ((i<0) || (i>=static_cast<index_type>(dt.size())))
66  {
67  assert(false);
68  return static_cast<data_type>(-1);
69  }
70 
71  return dt[i];
72  }
73 
75 
76  private:
77  std::vector<data_type> dt;
78  data_type t0;
79  };
80  }
81  }
82 }
83 #endif
84 
85 #ifndef eli_geom_curve_piecewise_four_digit_creator_hpp
86 #define eli_geom_curve_piecewise_four_digit_creator_hpp
87 
88 #include "eli/code_eli.hpp"
89 
92 
93 namespace eli
94 {
95  namespace geom
96  {
97  namespace curve
98  {
99  template<typename data__, unsigned short dim__, typename tol__>
101  {
102  public:
110 
111  piecewise_four_digit_creator() : piecewise_airfoil_creator_base<data_type, dim__, tolerance_type>(0) {}
113  : piecewise_airfoil_creator_base<data_type, dim__, tolerance_type>(ppc) {}
115 
117  {
119  }
120  bool sharp_trailing_edge() const
121  {
122  return af.sharp_trailing_edge();
123  }
124 
125  bool set_thickness(const data_type &t)
126  {
127  return af.set_thickness(t);
128  }
129 
130  data_type get_thickness() const
131  {
132  return af.get_thickness();
133  }
134 
135  bool set_camber(const data_type &cam, const data_type &cam_loc)
136  {
137  return af.set_camber(cam, cam_loc);
138  }
139 
140  data_type get_maximum_camber() const
141  {
142  return af.get_maximum_camber();
143  }
144 
145  data_type get_maximum_camber_location() const
146  {
148  }
149 
150  bool set_name(const std::string &name)
151  {
152  return af.set_name(name);
153  }
154 
155  std::string get_name() const
156  {
157  return af.get_name();
158  }
159 
161  {
162  typedef piecewise<bezier, data_type, dim__, tolerance_type> piecewise_curve_type;
163  typedef typename piecewise_curve_type::curve_type curve_type;
164  typedef typename piecewise_curve_type::error_code error_code;
165  typedef typename curve_type::fit_container_type fit_container_type;
166  typedef typename curve_type::dimension_type dimension_type;
167 
168  af_point_type temppt;
169 
170  std::vector<point_type, Eigen::aligned_allocator<point_type> > pts;
171 
172 // point_type d1start, d1end, d2start, d2end;
173 
174  index_type i;
175  index_type nseg(this->get_number_segments());
176 
177  // Number of sample points per segment.
178  index_type nref=25;
179 
180  // Number of points evaluated around airfoil.
181  index_type npt = nref*nseg+1;
182  pts.resize(npt);
183  // Leading edge point index.
184  index_type ile(1+(npt-1)/2);
185 
186  // Set up initial parameter and parameter step.
187  data_type xi(af.get_u_min());
188  data_type dxi((af.get_u_max()-af.get_u_min())/(npt-1));
189  std::vector< data_type > xis;
190  xis.resize(npt);
191 
192  // Evaluate airfoil.
193  for( i = 0; i < npt; i++ )
194  {
195  if(i==ile)
196  {
197  xi=0; // Force exact floating point value for le.
198  }
199  else if(i==npt-1)
200  {
201  xi=af.get_u_max(); // Force exact floating point value for te.
202  }
203 
204  temppt = af.f(xi);
205  pts[i] = point_type(temppt.x(), temppt.y(), 0);
206  xis[i] = xi;
207  xi += dxi;
208  }
209 
210  pc.clear();
211  pc.set_t0(this->get_t0());
212 
213  index_type istart(0), iend(nref);
214 
215 // temppt = af.fp(xis[istart]);
216 // temppt = af.tangent(xis[istart]);
217 // d1start = point_type(temppt.x(), temppt.y(), 0);
218 // temppt = af.fpp(xis[istart]);
219 // d2start = point_type(temppt.x(), temppt.y(), 0);
220 
221  for( i = 0; i < nseg; i++ )
222  {
223 // temppt = af.fp(xis[iend]);
224 // temppt = af.tangent(xis[iend]);
225 // d1end = point_type(temppt.x(), temppt.y(), 0);
226 // temppt = af.fpp(xis[iend]);
227 // d2end = point_type(temppt.x(), temppt.y(), 0);
228 
229  // set up fit container
230  fit_container_type fcon;
231 
232  fcon.set_points(pts.begin()+istart, pts.begin()+iend+1);
233  fcon.add_start_C0_constraint();
234  fcon.add_end_C0_constraint();
235 
236 // C1 and C2 fits are problematic. I believe this is because they fit the magnitude of the
237 // supplied derivative, not just its direction (for first derivatives). In general,
238 // using af.tangent works better than af.fp. Results can be obtained for low order curves.
239 // The resulting curves blow up for higher order, or for C2 using .fp or .tangent.
240 
241 // fcon.add_start_C1_constraint(d1start);
242 // fcon.add_end_C1_constraint(d1end);
243 // fcon.add_start_C2_constraint(d1start,d2start);
244 // fcon.add_end_C2_constraint(d1end,d2end);
245 
246  // do fit
247  dimension_type dim(10);
248  curve_type bez;
249 
250  bez.fit(fcon, dim);
251 
252  // Push back to piecewise curve.
253  error_code err = pc.push_back(bez, this->get_segment_dt(i));
254  if (err!=piecewise_curve_type::NO_ERRORS)
255  {
256  assert(false);
257  return false;
258  }
259 
260  istart = iend;
261 // d1start = d1end;
262 // d2start = d2end;
263 
264  iend = iend + nref;
265  }
266 
267  return false;
268  }
269 
270  private:
271  airfoil_type af;
272  };
273  }
274  }
275 }
276 #endif
point_type f(const data_type &xi) const
Definition: four_digit.hpp:130
data_type get_u_max() const
Definition: four_digit.hpp:57
bool set_camber(const data_type &cam, const data_type &cam_loc)
Definition: piecewise_four_digit_creator.hpp:135
Definition: math.hpp:20
airfoil_type af
Definition: piecewise_four_digit_creator.hpp:271
data_type get_maximum_camber() const
Definition: piecewise_four_digit_creator.hpp:140
piecewise_four_digit_creator()
Definition: piecewise_four_digit_creator.hpp:111
data_type get_thickness() const
Definition: piecewise_four_digit_creator.hpp:130
error_code push_back(const curve_type &curve, const data_type &dt=1.0)
Definition: piecewise.hpp:688
index_type get_number_segments() const
Definition: piecewise_four_digit_creator.hpp:48
data_type get_segment_dt(const index_type &i) const
Definition: piecewise_four_digit_creator.hpp:63
bool set_camber(const data_type &cam, const data_type &cam_loc)
Definition: four_digit.hpp:78
eli::geom::curve::pseudo::four_digit< data_type > airfoil_type
Definition: piecewise_four_digit_creator.hpp:108
base_class_type::data_type data_type
Definition: piecewise_four_digit_creator.hpp:104
bool set_thickness(const data_type &t)
Definition: piecewise_four_digit_creator.hpp:125
Eigen::Matrix< data_type, 1, dim__ > point_type
Definition: piecewise_four_digit_creator.hpp:35
data_type get_thickness() const
Definition: four_digit.hpp:76
Definition: piecewise.hpp:244
data_type t0
Definition: piecewise_four_digit_creator.hpp:78
Definition: piecewise_four_digit_creator.hpp:31
std::string get_name() const
Definition: four_digit.hpp:121
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
virtual ~piecewise_airfoil_creator_base()
Definition: piecewise_four_digit_creator.hpp:46
point_type::Index index_type
Definition: piecewise_four_digit_creator.hpp:36
data_type get_maximum_camber() const
Definition: four_digit.hpp:90
piecewise_airfoil_creator_base(const data_type &tt0)
Definition: piecewise_four_digit_creator.hpp:40
bool set_name(const std::string &name)
Definition: four_digit.hpp:93
base_class_type::index_type index_type
Definition: piecewise_four_digit_creator.hpp:106
data_type get_u_min() const
Definition: four_digit.hpp:56
bool sharp_trailing_edge() const
Definition: piecewise_four_digit_creator.hpp:120
bool set_name(const std::string &name)
Definition: piecewise_four_digit_creator.hpp:150
Eigen::Matrix< data_type, 1, 2 > point_type
Definition: four_digit.hpp:36
data_type get_t0() const
Definition: piecewise_four_digit_creator.hpp:54
base_class_type::tolerance_type tolerance_type
Definition: piecewise_four_digit_creator.hpp:107
void clear()
Definition: piecewise.hpp:599
void set_sharp_trailing_edge(bool fl)
Definition: piecewise_four_digit_creator.hpp:116
std::vector< data_type > dt
Definition: piecewise_four_digit_creator.hpp:77
data__ data_type
Definition: piecewise_four_digit_creator.hpp:34
virtual bool create(piecewise< bezier, data_type, dim__, tolerance_type > &pc) const =0
tol__ tolerance_type
Definition: piecewise_four_digit_creator.hpp:37
base_class_type::point_type point_type
Definition: piecewise_four_digit_creator.hpp:105
void set_t0(const data_type &t0_in)
Definition: piecewise.hpp:340
piecewise_airfoil_creator_base(const piecewise_airfoil_creator_base< data_type, dim__, tolerance_type > &pac)
Definition: piecewise_four_digit_creator.hpp:45
Definition: piecewise_four_digit_creator.hpp:100
void set_sharp_trailing_edge(bool fl)
Definition: four_digit.hpp:59
void set_t0(const data_type &tt0)
Definition: piecewise_four_digit_creator.hpp:53
void set_segment_dt(const data_type &dtt, const index_type &i)
Definition: piecewise_four_digit_creator.hpp:56
airfoil_type::point_type af_point_type
Definition: piecewise_four_digit_creator.hpp:109
data_type get_maximum_camber_location() const
Definition: four_digit.hpp:91
bool set_thickness(const data_type &t)
Definition: four_digit.hpp:66
bool sharp_trailing_edge() const
Definition: four_digit.hpp:64
virtual bool create(piecewise< bezier, data_type, dim__, tolerance_type > &pc) const
Definition: piecewise_four_digit_creator.hpp:160
~piecewise_four_digit_creator()
Definition: piecewise_four_digit_creator.hpp:114
piecewise_four_digit_creator(const piecewise_four_digit_creator< data_type, dim__, tolerance_type > &ppc)
Definition: piecewise_four_digit_creator.hpp:112
piecewise_airfoil_creator_base< data__, dim__, tol__ > base_class_type
Definition: piecewise_four_digit_creator.hpp:103