Hermes2D  2.0
spline.h
1 // This file is part of Hermes2D.
2 //
3 // Hermes2D is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 2 of the License, or
6 // (at your option) any later version.
7 //
8 // Hermes2D is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with Hermes2D. If not, see <http://www.gnu.org/licenses/>.
15 
16 #ifndef __H2D_SPLINE_H
17 #define __H2D_SPLINE_H
18 
19 #include "global.h"
20 
21 namespace Hermes
22 {
23  namespace Hermes2D
24  {
25  class HERMES_API CubicSpline : public Hermes::Hermes1DFunction<double>
26  {
27  public:
29  CubicSpline(Hermes::vector<double> points, Hermes::vector<double> values,
30  double bc_left, double bc_right,
31  bool first_der_left = true, bool first_der_right = true,
32  bool extend_der_left = true, bool extend_der_right = true);
33 
34  CubicSpline(double const_value);
35 
37  ~CubicSpline();
38 
40  void calculate_coeffs();
41 
43  double value(double x) const;
44 
46  Hermes::Ord value(Hermes::Ord x) const {return Hermes::Ord(3);};
47 
49  double derivative(double x) const;
50 
52  Hermes::Ord derivative(Hermes::Ord x) const {return Hermes::Ord(2);};
53 
60  void plot(const char* filename, double extension, bool plot_derivative = false, int subdiv = 50) const;
61 
62  protected:
65  bool find_interval(double x_in, int& m) const;
66 
68  double extrapolate_value(double point_end, double value_end, double derivative_end, double x_in) const;
70  Hermes::vector<double> points;
71 
73  Hermes::vector<double> values;
74 
76  double bc_left, bc_right;
77 
82  bool first_der_left, first_der_right;
88  bool extrapolate_der_left, extrapolate_der_right;
89 
91  double point_left, value_left, derivative_left;
92  double point_right, value_right, derivative_right;
93 
95  Hermes::vector<SplineCoeff> coeffs;
96 
98  double get_derivative_from_interval(double x_in, int m) const;
99 
101  double get_value_from_interval(double x_in, int m) const;
102  };
103  }
104 }
105 #endif