Hermes2D  3.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(std::vector<double> points, std::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 
39  void free();
40 
42  void calculate_coeffs();
43 
45  double value(double x) const;
46 
48  Hermes::Ord value(Hermes::Ord x) const { return Hermes::Ord(3); };
49 
51  double derivative(double x) const;
52 
54  Hermes::Ord derivative(Hermes::Ord x) const { return Hermes::Ord(2); };
55 
62  void plot(const char* filename, double extension, bool plot_derivative = false, int subdiv = 50) const;
63 
64  protected:
67  bool find_interval(double x_in, int& m) const;
68 
70  double extrapolate_value(double point_end, double value_end, double derivative_end, double x_in) const;
72  std::vector<double> points;
73 
75  std::vector<double> values;
76 
78  double bc_left, bc_right;
79 
84  bool first_der_left, first_der_right;
90  bool extrapolate_der_left, extrapolate_der_right;
91 
93  double point_left, value_left, derivative_left;
94  double point_right, value_right, derivative_right;
95 
97  std::vector<SplineCoeff> coeffs;
98 
100  double get_derivative_from_interval(double x_in, int m) const;
101 
103  double get_value_from_interval(double x_in, int m) const;
104  };
105  }
106 }
107 #endif
Definition: adapt.h:24
std::vector< double > points
Grid points, ordered.
Definition: spline.h:72
Hermes::Ord value(Hermes::Ord x) const
One-dimensional function integration order.
Definition: spline.h:48
std::vector< SplineCoeff > coeffs
A set of four coefficients a, b, c, d for an elementary cubic spline.
Definition: spline.h:97
Common definitions for Hermes2D.
double point_left
Values and derivatives at end points for extrapolation purposes.
Definition: spline.h:93
double bc_left
Boundary conditions.
Definition: spline.h:78
Hermes::Ord derivative(Hermes::Ord x) const
One-dimensional function derivative integration order.
Definition: spline.h:54
std::vector< double > values
Values at the grid points.
Definition: spline.h:75