Debian Codegraph @

src/math/aslInterpolation.h

raw
1 /*
2 * Advanced Simulation Library <http://asl.org.il>
3 *
4 * Copyright 2015 Avtech Scientific <http://avtechscientific.com>
5 *
6 *
7 * This file is part of Advanced Simulation Library (ASL).
8 *
9 * ASL is free software: you can redistribute it and/or modify it
10 * under the terms of the GNU Affero General Public License as
11 * published by the Free Software Foundation, version 3 of the License.
12 *
13 * ASL is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with ASL. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23
24 /// \file aslVectors.h definition of class АVec<T>
25
26 #ifndef ASLINTERPOLATION
27 #define ASLINTERPOLATION
28
29
30 #include "../aslUtilities.h"
31 #include <cmath>
32
33
34 namespace asl
35 {
36 class ElementBase;
37 typedef std::shared_ptr<ElementBase> Element;
38
39 template <class Func> class UniversalFunction
40 {
41 public:
42 inline double operator()(double x);
43 inline double operator()(Element x);
44 };
45
46 ///Linear spline function
47 /**
48 \ingroup Splines
49
50 this class defines a spline function \f$ (1-|x/r_0|),~~~ |x|<r_0 \f$
51 \image html linearS.png ""
52 */
53 class LinearSpline
54 {
55 public:
56 template <typename T> inline T operator(T x,T r0)
57 {
58 return fabs(x)<r0 ? 1.- fabs(x)/r0 : 0;
59 }
60 };
61
62 ///Quadratic spline function
63 /**
64 \ingroup Splines
65
66 this class defines a spline function \f$ (1-|x|/r_0)^2,~~~ |x|<r_0 \f$
67 \image html quadraticS.png ""
68 */
69 class QuadraticSpline
70 {
71 public:
72 template <typename T> inline T operator(T x,T r0)
73 {
74 T a(fabs(x));
75 T b((1.- a/r0));
76 return a<r0 ? b*b : 0;
77 }
78 };
79
80 ///Qubic spline function
81 /**
82 \ingroup Splines
83
84 this class defines a spline function \f$ (1-|x|/r_0)^3,~~~ |x|<r_0 \f$
85 \image html qubicS.png ""
86 */
87 class QubicSpline
88 {
89 public:
90 template <typename T> inline T operator(T x,T r0)
91 {
92 T a(fabs(x));
93 T b((1.- a/r0));
94 return a<r0 ? b*b*b : 0;
95 }
96 };
97
98 ///Qubic spline function
99 /**
100 \ingroup Splines
101
102 this class defines a spline function \f$ (1-|x|/r_0)^3,~~~ |x|<r_0 \f$
103 \image html qubicS1.png ""
104 */
105 class QubicSpline1
106 {
107 public:
108 template <typename T> inline T operator(T x,T r0)
109 {
110 T a(fabs(x));
111 T b(a/r0);
112 T b2(b*b);
113 return b < 1 ? 2. * b2*b - 3. * b2 + 1 : 0;
114 }
115 };
116
117 // --------------------------- Implementation ---------------------
118
119 template <class Func> inline double UniversalFunction<Func>::operator()(double x)
120 {
121 return Func(x);
122 }
123
124 template <class Func> inline Element UniversalFunction<Func>::operator()(Element x)
125 {
126 return Func(x);
127 }
128
129 } // asl
130
131 #endif
132