tension_function.hpp
Go to the documentation of this file.
1 
8 /*****************************************************************************
9 ** Ifdefs
10 *****************************************************************************/
11 
12 #ifndef ECL_GEOMETRY_TENSION_FUNCTION_HPP_
13 #define ECL_GEOMETRY_TENSION_FUNCTION_HPP_
14 
15 /*****************************************************************************
16 ** Includes
17 *****************************************************************************/
18 
19 #include "function_math.hpp"
20 #include <ecl/config/macros.hpp>
21 #include <ecl/concepts/macros.hpp>
22 #include <ecl/concepts/streams.hpp>
23 #include <ecl/containers/array.hpp>
24 #include <ecl/errors/compile_time_assert.hpp>
25 #include <ecl/utilities/blueprints.hpp>
26 #include <ecl/formatters/floats.hpp>
27 
28 /*****************************************************************************
29 ** Namespaces
30 *****************************************************************************/
31 
32 namespace ecl {
33 
34 /*****************************************************************************
35 ** Forward Declarations
36 *****************************************************************************/
37 
38 class TensionFunction;
39 
40 namespace blueprints {
41 
42 class TensionSecondDerivativeInterpolation;
43 
44 } // namespace blueprints
45 
46 /*****************************************************************************
47 ** BluePrintFactory
48 *****************************************************************************/
57 template<>
58 class ECL_PUBLIC BluePrintFactory< TensionFunction > {
59  public:
77  static blueprints::TensionSecondDerivativeInterpolation Interpolation(const double x_i, const double y_i, const double yddot_i,
78  const double x_f, const double y_f, const double yddot_f);
79 
80  virtual ~BluePrintFactory() {};
81 };
82 
83 /*****************************************************************************
84 ** Interface [TensionFunction]
85 *****************************************************************************/
110 class ECL_PUBLIC TensionFunction : public BluePrintFactory< TensionFunction > {
111  public:
112  /*********************
113  ** Constructors
114  **********************/
121  TensionFunction() {}
122  virtual ~TensionFunction() {}
145  template<typename Derived>
146  TensionFunction(const BluePrint< Derived > &blueprint) {
147  blueprint.implementApply(*this);
148  }
149 
150  /*********************
151  ** Derivatives
152  **********************/
163  double derivative(const double &tau, const double &x) const;
164 
175  double dderivative(const double &tau, const double &x) const;
176 
177  /*********************
178  ** Accessors
179  **********************/
190  double operator ()(const double &tau, const double &x) const;
191 
192  /*********************
193  ** Friends
194  **********************/
195  friend class blueprints::TensionSecondDerivativeInterpolation;
196 
197 
198  template <typename OutputStream>
199  friend OutputStream& operator << (OutputStream &ostream, const TensionFunction &function);
200 
201  private:
202  double z_0, z_f; // yddot_0, yddot_f
203  double x_0, x_f;
204  double y_0, y_f;
205 };
206 
207 
208 /*****************************************************************************
209 ** Streaming Operator [TensionFunction]
210 *****************************************************************************/
222 template <typename OutputStream>
223 OutputStream& operator << (OutputStream &ostream, const TensionFunction &function)
224 {
226 
227  Format<double> format;
228  format.precision(2);
229  double h = function.x_f - function.x_0;
230  if ( ( function.z_0 == 0.0 ) && ( function.z_f == 0.0 ) ) {
231  ostream << "0.0";
232  } else {
233  ostream << "{";
234  if ( function.z_0 != 0.0 ) {
235  ostream << format(function.z_0) << "*sinh[tau(";
236  ostream << format(function.x_f) << "-x)] + ";
237  }
238  if ( function.z_f != 0.0 ) {
239  ostream << format(function.z_f) << "*sinh[tau(x-";
240  ostream << format(function.x_0) << ")]}/[tau^2 sinh(";
241  ostream << format(function.x_f - function.x_0) << "*tau)]";
242  }
243  }
244  ostream << "\n";
245  ostream << " + (";
246  ostream << format(function.y_0/h) << "-";
247  ostream << format(function.z_0/h) << "/tau^2)(";
248  ostream << format(function.x_f) << "-x)\n";
249  ostream << " + (";
250  ostream << format(function.y_f/h) << "-";
251  ostream << format(function.z_f/h) << "/tau^2)(x-";
252  ostream << format(function.x_0) << ")\n";
253  ostream.flush();
254 
255  return ostream;
256 }
257 
258 /*****************************************************************************
259 ** BluePrints
260 *****************************************************************************/
261 
262 namespace blueprints {
263 
264 /*****************************************************************************
265 ** Interface [TensionSecondDerivativeInterpolation]
266 *****************************************************************************/
267 
284 class ECL_PUBLIC TensionSecondDerivativeInterpolation : public ecl::BluePrint<TensionSecondDerivativeInterpolation> {
285  public:
289  typedef ecl::TensionFunction base_type;
302  TensionSecondDerivativeInterpolation(const double x_i, const double y_i, const double yddot_i,
303  const double x_f, const double y_f, const double yddot_f) :
304  x_initial(x_i),
305  y_initial(y_i),
306  yddot_initial(yddot_i),
307  x_final(x_f),
308  y_final(y_f),
309  yddot_final(yddot_f)
310  {}
311  virtual ~TensionSecondDerivativeInterpolation() {}
312 
320  ecl::TensionFunction instantiate();
321 
329  void apply(base_type& function) const;
330 
331  private:
332  double x_initial, y_initial, yddot_initial;
333  double x_final, y_final, yddot_final;
334 };
335 
336 
337 }; // namespace blueprints
338 }; // namespace ecl
339 
340 #endif /*ECL_GEOMETRY_TENSION_FUNCTION_HPP_*/
Formatter for double types.
Definition: floats.hpp:519
Defines validating functionality for the streams concept.
OutputStream & operator<<(OutputStream &ostream, const Void void_object)
Output stream operator for Void objects.
Definition: void.hpp:76
Representation of a tension function.
FormatFloat< Number > & precision(const unsigned int p)
#define ECL_PUBLIC
#define ecl_compile_time_concept_check(Model)
Compile time concept checking assertion.
This is a parent template for blueprints using crtp.


xbot_node
Author(s): Roc, wangpeng@droid.ac.cn
autogenerated on Sat Oct 10 2020 03:28:13