cubic_spline.hpp
Go to the documentation of this file.
1 
8 /*****************************************************************************
9 ** Ifdefs
10 *****************************************************************************/
11 
12 #ifndef ECL_GEOMETRY_CUBIC_SPLINE_HPP_
13 #define ECL_GEOMETRY_CUBIC_SPLINE_HPP_
14 
15 /*****************************************************************************
16 ** Includes
17 *****************************************************************************/
18 
19 #include "polynomial.hpp"
20 #include <ecl/config/macros.hpp>
21 #include <ecl/concepts/macros.hpp>
22 #include <ecl/concepts/streams.hpp>
24 #include <ecl/containers/array.hpp>
27 
28 /*****************************************************************************
29 ** Namespaces
30 *****************************************************************************/
31 
32 namespace ecl {
33 
34 /*****************************************************************************
35 ** Forward Declarations
36 *****************************************************************************/
37 
38 class CubicSpline;
39 
40 namespace blueprints {
41 
42 class C2CubicSpline;
43 class DerivativeHeuristicCubicSpline;
44 
45 } // namespace blueprints
46 
47 /*****************************************************************************
48 ** BluePrintFactory
49 *****************************************************************************/
58 template<>
59 class ECL_PUBLIC BluePrintFactory< CubicSpline > {
60  public:
72  static blueprints::C2CubicSpline Natural(const Array<double>& x_set, const Array<double>& y_set);
85  static blueprints::C2CubicSpline ContinuousDerivatives(
86  const Array<double>& x_set, const Array<double>& y_set, const double ydot_0, const double ydot_f);
100  static blueprints::DerivativeHeuristicCubicSpline DerivativeHeuristic(
101  const Array<double>& x_set, const Array<double>& y_set, const double ydot_0, const double ydot_f);
102 
103  virtual ~BluePrintFactory() {}
104 };
105 
106 /*****************************************************************************
107 ** Interface [CubicSpline]
108 *****************************************************************************/
123 class ECL_PUBLIC CubicSpline : public BluePrintFactory< CubicSpline > {
124  public:
125  /******************************************
126  ** Constructors
127  *******************************************/
133  CubicSpline () {};
160  template<typename Derived>
161  CubicSpline(const BluePrint< Derived > &blueprint) {
162  blueprint.implementApply(*this);
163  }
164  virtual ~CubicSpline () {};
165 
166  /******************************************
167  ** Access
168  *******************************************/
170  friend class blueprints::C2CubicSpline;
179  double operator()(const double &x) const;
188  double derivative(double x) const;
197  double dderivative(double x) const;
198 
206  const Array<double>& domain() { return discretised_domain; }
215  const Array<CubicPolynomial>& polynomials() { return cubic_polynomials; }
216 
217  /******************************************
218  ** Streaming
219  *******************************************/
231  template <typename OutputStream>
232  friend OutputStream& operator << (OutputStream &ostream, const CubicSpline &cubic_spline);
233 
234  private:
235  Array<double> discretised_domain; // N+1 x_i's
236  // Would normally use pointers here, but the polynomials have fixed storage
237  // size, the copy cost is small and the access times will be faster this way.
238  Array<CubicPolynomial> cubic_polynomials; // N polynomials
239 };
240 
241 /*****************************************************************************
242 ** Implementation [CubicSpline][Streaming]
243 *****************************************************************************/
244 
245 template <typename OutputStream>
246 OutputStream& operator << (OutputStream &ostream, const CubicSpline &cubic_spline) {
247 
249 
250  for ( unsigned int i = 0; i < cubic_spline.cubic_polynomials.size(); ++i ) {
251  ostream << cubic_spline.cubic_polynomials[i] << "\n";
252  }
253  ostream.flush();
254  return ostream;
255 }
256 
257 /*****************************************************************************
258 ** BluePrints
259 *****************************************************************************/
260 
261 namespace blueprints {
262 
263 /*****************************************************************************
264 ** Interface [C2CubicSpline]
265 *****************************************************************************/
266 
276 class ECL_PUBLIC C2CubicSpline : public ecl::BluePrint<C2CubicSpline> {
277  public:
281  typedef ecl::CubicSpline base_type;
287  C2CubicSpline() {};
288 
301  C2CubicSpline(const ecl::Array<double>& x_set, const ecl::Array<double>& y_set,
302  const double ydot_0, const double ydot_f);
303 
304  virtual ~C2CubicSpline() {};
318  C2CubicSpline(const ecl::Array<double>& x_set, const ecl::Array<double>& y_set);
319 
327  ecl::CubicSpline instantiate();
328 
336  void apply(ecl::CubicSpline& spline) const;
337 
338  private:
339  ecl::Array<double> x_data;
340  ecl::Array<double> y_data;
341  ecl::Array<double> yddot_data;
342 };
343 
344 /*****************************************************************************
345 ** Interface [DerivativeHeuristicCubicSpline]
346 *****************************************************************************/
347 
362 class ECL_PUBLIC DerivativeHeuristicCubicSpline : public ecl::BluePrint<DerivativeHeuristicCubicSpline> {
363  public:
367  typedef ecl::CubicSpline base_type;
373  DerivativeHeuristicCubicSpline() {};
374 
388  DerivativeHeuristicCubicSpline(const ecl::Array<double>& x_set, const ecl::Array<double>& y_set,
389  const double ydot_0, const double ydot_f);
390 
391  virtual ~DerivativeHeuristicCubicSpline() {};
399  ecl::CubicSpline instantiate();
400 
408  void apply(ecl::CubicSpline& spline) const;
409 
410  private:
411  ecl::Array<double> x_data;
412  ecl::Array<double> y_data;
413  ecl::Array<double> ydot_data;
414 };
415 
416 } // namespace blueprints
417 } // namespace ecl
418 
419 #endif /* ECL_GEOMETRY_CUBIC_SPLINE_HPP_ */
ecl_compile_time_concept_check
#define ecl_compile_time_concept_check(Model)
polynomial.hpp
Representations for polynomial functions.
ecl::operator<<
OutputStream & operator<<(OutputStream &ostream, const Array< ElementType, ArraySize > &array)
ecl::blueprints::C2CubicSpline
Blueprint for generating a cubic spline satisfying C2 constraints.
Definition: cubic_spline.hpp:284
streams.hpp
blueprints.hpp
ecl::CubicSpline::cubic_polynomials
Array< CubicPolynomial > cubic_polynomials
Definition: cubic_spline.hpp:246
array.hpp
ecl::BluePrint
ecl::StreamConcept
standard_exception.hpp
containers.hpp
ecl::CubicSpline
Storage container for a cubic spline interpolation.
Definition: cubic_spline.hpp:129
ecl::Array< double >
macros.hpp
ecl
Embedded control libraries.
ECL_PUBLIC
#define ECL_PUBLIC
ecl::blueprints::DerivativeHeuristicCubicSpline
Blueprint for generating a cubic spline satisfying C2 constraints.
Definition: cubic_spline.hpp:370


ecl_geometry
Author(s): Daniel Stonier
autogenerated on Wed Mar 2 2022 00:16:39