smooth_linear_spline.hpp
Go to the documentation of this file.
1 
8 /*****************************************************************************
9 ** Ifdefs
10 *****************************************************************************/
11 
12 #ifndef ECL_SMOOTH_LINEAR_SPLINE_HPP_
13 #define ECL_SMOOTH_LINEAR_SPLINE_HPP_
14 
15 /*****************************************************************************
16 ** Includes
17 *****************************************************************************/
18 
19 #include <ecl/config/macros.hpp>
20 #include <ecl/concepts/streams.hpp>
21 #include <ecl/containers/array.hpp>
24 #include "polynomial.hpp"
25 #include "macros.hpp"
26 
27 /*****************************************************************************
28 ** Namespaces
29 *****************************************************************************/
30 
31 namespace ecl {
32 
33 /*****************************************************************************
34 ** Interface [SmoothLinearSpline]
35 *****************************************************************************/
45 class ecl_geometry_PUBLIC SmoothLinearSpline {
46 public:
53  SmoothLinearSpline() {}
77  SmoothLinearSpline(const Array<double>& x_data, const Array<double>& y_data, double a_max);
78 
79  virtual ~SmoothLinearSpline() {}
80 
90  double operator()(const double &x) const;
101  double derivative(const double &x) const;
110  double dderivative(const double &x) const;
111 
120  const Array<double>& domain() const { return discretised_domain; }
121 
122  /*********************
123  * Static Constructor
124  **********************/
136  static SmoothLinearSpline Interpolation(const Array<double>& x_data, const Array<double>& y_data, double a_max)
137  {
138  try {
139  return SmoothLinearSpline(x_data, y_data, a_max);
140  } catch ( DataException<int> &e ) {
141  throw DataException<int>(LOC,e);
142  }
143  return SmoothLinearSpline(); // avoid a warning because of the rethrown exception.
144  }
145 
146  /******************************************
147  * Streaming
148  *******************************************/
162  template <typename OutputStream>
163  friend OutputStream& operator << (OutputStream &ostream, const SmoothLinearSpline &smooth_linear_spline);
164 
165 private:
166  Array<double> discretised_domain; // 2*N points (2 end points + 2*(N-1) corner points)
167  Array<LinearFunction> segments; // N linear segments
168  Array<QuinticPolynomial> corners; // N-1 corners
169 };
170 
171 /*****************************************************************************
172 ** Implementation [SmoothLinearSpline][Streaming]
173 *****************************************************************************/
174 
175 template <typename OutputStream>
176 OutputStream& operator << (OutputStream &ostream, const SmoothLinearSpline &smooth_linear_spline) {
177 
178  ecl_compile_time_concept_check(StreamConcept<OutputStream>);
179 
180  ostream << smooth_linear_spline.segments[0] << "\n";
181  for ( unsigned int i = 1; i < smooth_linear_spline.segments.size(); ++i ) {
182  ostream << smooth_linear_spline.corners[i-1] << "\n";
183  ostream << smooth_linear_spline.segments[i] << "\n";
184  }
185  ostream.flush();
186  return ostream;
187 }
188 
189 } // namespace ecl
190 
191 #endif /* ECL_SMOOTH_LINEAR_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_geometry_PUBLIC
#define ecl_geometry_PUBLIC
Definition: macros.hpp:37
macros.hpp
Macros for ecl geometry.
streams.hpp
data_exception.hpp
array.hpp
standard_exception.hpp
macros.hpp
ecl
Embedded control libraries.


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