Debian Codegraph @

include/deal.II/base/function_cspline.h

raw
1 // ------------------------------------------------------------------------
2 //
3 // SPDX-License-Identifier: LGPL-2.1-or-later
4 // Copyright (C) 2016 - 2024 by the deal.II authors
5 //
6 // This file is part of the deal.II library.
7 //
8 // Part of the source code is dual licensed under Apache-2.0 WITH
9 // LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10 // governing the source code and code contributions can be found in
11 // LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12 //
13 // ------------------------------------------------------------------------
14
15 #ifndef dealii_function_cspline_h
16 #define dealii_function_cspline_h
17
18 #include <deal.II/base/config.h>
19
20 #ifdef DEAL_II_WITH_GSL
21 # include <deal.II/base/function.h>
22 # include <deal.II/base/mutex.h>
23 # include <deal.II/base/point.h>
24
25 # include <gsl/gsl_spline.h>
26
27 # include <memory>
28
29 DEAL_II_NAMESPACE_OPEN
30
31 namespace Functions
32 {
33 DeclException1(ExcCSplineEmpty,
34 int,
35 << "Interpolation points vector size can not be <" << arg1
36 << ">.");
37
38 DeclException2(ExcCSplineSizeMismatch,
39 int,
40 int,
41 << "The size of interpolation points <" << arg1
42 << "> is different from the size of interpolation values <"
43 << arg2 << ">.");
44
45
46 DeclException3(ExcCSplineOrder,
47 int,
48 double,
49 double,
50 << "The input interpolation points are not strictly ordered : "
51 << std::endl
52 << "x[" << arg1 << "] = " << arg2 << " >= x[" << (arg1 + 1)
53 << "] = " << arg3 << '.');
54
55 DeclException3(
56 ExcCSplineRange,
57 double,
58 double,
59 double,
60 << "Spline function can not be evaluated outside of the interpolation range: "
61 << std::endl
62 << arg1 << " is not in [" << arg2 << ';' << arg3 << "].");
63
64 /**
65 * The cubic spline function using GNU Scientific Library.
66 * The resulting curve is piecewise cubic on each interval, with matching
67 * first and second derivatives at the supplied data-points. The second
68 * derivative is chosen to be zero at the first point and last point.
69 *
70 * @note This function is only implemented for dim==1 .
71 *
72 * @ingroup functions
73 */
74 template <int dim>
75 class CSpline : public Function<dim>
76 {
77 public:
78 /**
79 * Constructor which should be provided with a set of points at which
80 * interpolation is to be done @p interpolation_points and a set of function
81 * values @p interpolation_values .
82 */
83 CSpline(const std::vector<double> &interpolation_points,
84 const std::vector<double> &interpolation_values);
85
86 virtual double
87 value(const Point<dim> &point,
88 const unsigned int component = 0) const override;
89
90 virtual Tensor<1, dim>
91 gradient(const Point<dim> &p,
92 const unsigned int component = 0) const override;
93
94 virtual SymmetricTensor<2, dim>
95 hessian(const Point<dim> &p,
96 const unsigned int component = 0) const override;
97
98 virtual double
99 laplacian(const Point<dim> &p,
100 const unsigned int component = 0) const override;
101
102 /**
103 * Return an estimate for the memory consumption, in bytes, of this object.
104 */
105 virtual std::size_t
106 memory_consumption() const override;
107
108 private:
109 /**
110 * Points at which interpolation is provided
111 */
112 const std::vector<double> interpolation_points;
113
114 /**
115 * Values of the function at interpolation points
116 */
117 const std::vector<double> interpolation_values;
118
119 /**
120 * GSL accelerator for spline interpolation
121 */
122 std::unique_ptr<gsl_interp_accel, void (*)(gsl_interp_accel *)> acc;
123
124 /**
125 * GSL cubic spline interpolator
126 */
127 std::unique_ptr<gsl_spline, void (*)(gsl_spline *)> cspline;
128
129 /**
130 * A mutex for accelerator object.
131 */
132 mutable Threads::Mutex acc_mutex;
133 };
134 } // namespace Functions
135
136 DEAL_II_NAMESPACE_CLOSE
137
138 #else
139
140 // Make sure the scripts that create the C++20 module input files have
141 // something to latch on if the preprocessor #ifdef above would
142 // otherwise lead to an empty content of the file.
143 DEAL_II_NAMESPACE_OPEN
144 DEAL_II_NAMESPACE_CLOSE
145
146 #endif
147
148 #endif