Line data Source code
1 : /*
2 : * Copyright (c) 2009-2015: G-CSC, Goethe University Frankfurt
3 : * Author: Dmitry Logashenko
4 : *
5 : * This file is part of UG4.
6 : *
7 : * UG4 is free software: you can redistribute it and/or modify it under the
8 : * terms of the GNU Lesser General Public License version 3 (as published by the
9 : * Free Software Foundation) with the following additional attribution
10 : * requirements (according to LGPL/GPL v3 §7):
11 : *
12 : * (1) The following notice must be displayed in the Appropriate Legal Notices
13 : * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14 : *
15 : * (2) The following notice must be displayed at a prominent place in the
16 : * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17 : *
18 : * (3) The following bibliography is recommended for citation and must be
19 : * preserved in all covered files:
20 : * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21 : * parallel geometric multigrid solver on hierarchically distributed grids.
22 : * Computing and visualization in science 16, 4 (2013), 151-164"
23 : * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24 : * flexible software system for simulating pde based models on high performance
25 : * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26 : *
27 : * This program is distributed in the hope that it will be useful,
28 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 : * GNU Lesser General Public License for more details.
31 : */
32 : #include <cmath>
33 : #include "math_constants.h"
34 : // own header
35 : #include "orthopoly.h"
36 :
37 : namespace ug
38 : {
39 :
40 : /** returns the values of the Legendre polynomials
41 : *
42 : * The polynomials are \f$L_2\f$-orthogonal on \f$[-1, 1]\f$. They satisfy
43 : * the recursion \f$P_0 (x) = 1\f$, \f$P_1 (1) = x\f$,
44 : * \f$P_k (x) = ((2 k - 1) x P_{k-1} (x) - (k - 1) P_{k-2} (x)) / k\f$.
45 : * The \f$L_2\f$-norm of \f$P_k\f$ is \f$\sqrt {2 / (2 k + 1)}\f$.
46 : */
47 0 : number LegendrePoly
48 : (
49 : size_t k, ///< index of the polynomial, \f$k \ge 0\f$
50 : number x ///< argument of the polynomial
51 : )
52 : {
53 0 : if (k == 0) return 1;
54 0 : else if (k == 1) return x;
55 :
56 0 : return ((2 * k - 1) * x * LegendrePoly (k-1, x) - (k - 1) * LegendrePoly (k - 2, x)) / k;
57 : }
58 :
59 : /** returns the scalar square of the Legendre polynomials (the squared weighted norm)
60 : *
61 : * The polynomials are \f$L_2\f$-orthogonal on \f$[-1, 1]\f$. They satisfy
62 : * the recursion \f$P_0 (x) = 1\f$, \f$P_1 (1) = x\f$,
63 : * \f$P_k (x) = ((2 k - 1) x P_{k-1} (x) - (k - 1) P_{k-2} (x)) / k\f$.
64 : * The \f$L_2\f$-square of \f$P_k\f$ is \f$2 / (2 k + 1)\f$.
65 : * Note that this function returns not the \f$L_2\f$ norm but the weighted
66 : * norm \f$\sqrt {\frac{1}{b-a} \int_a^b P_k^2 (x) \, dx}\f$, where
67 : * \f$a=-1\f$, \f$b=1\f$.
68 : */
69 0 : number SqNormOfLegendrePoly
70 : (
71 : size_t k ///< index of the polynomial, \f$k \ge 0\f$
72 : )
73 : {
74 0 : return (number) 1 / (2 * k + 1);
75 : }
76 :
77 : /** returns the values of the normalized Legendre polynomials
78 : *
79 : * The Legendre polynomials are \f$L_2\f$-orthogonal on \f$[-1, 1]\f$.
80 : * They satisfy the recursion \f$P_0 (x) = 1\f$, \f$P_1 (1) = x\f$,
81 : * \f$(n+1) P_k (x) = (2 k - 1) x P_{k-1} (x) - (k - 1) P_{n-2} (x)\f$.
82 : * The \f$L_2\f$-norm of \f$P_k\f$ is \f$\sqrt {2 / (2 k + 1)}\f$.
83 : * This function returns \f$\sqrt {(2 k + 1) / 2} P_k (x)\f$.
84 : */
85 0 : number NormalizedLegendrePoly
86 : (
87 : size_t k, ///< index of the polynomial, \f$k \ge 0\f$
88 : number x ///< argument of the polynomial
89 : )
90 : {
91 0 : return sqrt (((number) (2 * k + 1))) * LegendrePoly (k, x);
92 : }
93 :
94 : /** returns the values of the Chebyshev polynomials of the first kind
95 : *
96 : * The polynomials are orthogonal on \f$[-1, 1]\f$ w.r.t. the scalar product
97 : * \f$ \int_{-1}^1 \phi (x) \cdot \psi (x) \frac{1}{\sqrt {1 - x^2}} \, dx \f$
98 : * They satisfy the recursion \f$T_0 (x) = 1\f$, \f$T_1 (1) = x\f$,
99 : * \f$T_k (x) = 2 x P_{k-1} (x) - P_{k-2} (x)\f$.
100 : * The corresponding norm of \f$T_k\f$ is \f$\tfrac{\pi}{2}\f$ for \f$k > 0\f$
101 : * and \f$\pi\f$ for \f$k = 0\f$.
102 : */
103 0 : number Chebyshev1Poly
104 : (
105 : size_t k, ///< index of the polynomial, \f$k \ge 0\f$
106 : number x ///< argument of the polynomial
107 : )
108 : {
109 0 : if (k == 0) return 1;
110 0 : else if (k == 1) return x;
111 :
112 0 : return 2 * x * Chebyshev1Poly (k-1, x) - Chebyshev1Poly (k - 2, x);
113 : }
114 :
115 : /** returns the scalar square of the Chebyshev polynomials of the first kind (the squared norm)
116 : *
117 : * The polynomials are orthogonal on \f$[-1, 1]\f$ w.r.t. the scalar product
118 : * \f$ \int_{-1}^1 \phi (x) \cdot \psi (x) \frac{1}{\sqrt {1 - x^2}} \, dx \f$
119 : * They satisfy the recursion \f$T_0 (x) = 1\f$, \f$T_1 (1) = x\f$,
120 : * \f$T_k (x) = 2 x P_{k-1} (x) - P_{k-2} (x)\f$.
121 : * The corresponding norm of \f$T_k\f$ is \f$\tfrac{\pi}{2}\f$ for \f$k > 0\f$
122 : * and \f$\pi\f$ for \f$k = 0\f$.
123 : */
124 0 : number SqNormOfChebyshev1Poly
125 : (
126 : size_t k ///< index of the polynomial, \f$k \ge 0\f$
127 : )
128 : {
129 0 : if (k == 0) return PI * PI;
130 : return PI * PI / 4;
131 : }
132 :
133 : /** returns the values the normalized Chebyshev polynomials of the first kind
134 : *
135 : * The polynomials are orthogonal on \f$[-1, 1]\f$ w.r.t. the scalar product
136 : * \f$ \int_{-1}^1 \phi (x) \cdot \psi (x) \frac{1}{\sqrt {1 - x^2}} \, dx \f$
137 : * They satisfy the recursion \f$T_0 (x) = 1\f$, \f$T_1 (1) = x\f$,
138 : * \f$T_k (x) = 2 x T_{k-1} (x) - T_{k-2} (x)\f$.
139 : * The corresponding norm of \f$T_k\f$ is \f$\tfrac{\pi}{2}\f$ for \f$k > 0\f$
140 : * and \f$\pi\f$ for \f$k = 0\f$.
141 : *
142 : * This function returns \f$T_k (x)\f$ divided by its norm.
143 : */
144 0 : number NormalizedChebyshev1Poly
145 : (
146 : size_t k, ///< index of the polynomial, \f$k \ge 0\f$
147 : number x ///< argument of the polynomial
148 : )
149 : {
150 0 : if (k == 0) return Chebyshev1Poly (0, x) / PI;
151 :
152 0 : return Chebyshev1Poly (k, x) * 2 / PI;
153 : }
154 :
155 : /** returns the values of the Chebyshev polynomials of the second kind
156 : *
157 : * The polynomials are orthogonal on \f$[-1, 1]\f$ w.r.t. the scalar product
158 : * \f$ \int_{-1}^1 \phi (x) \cdot \psi (x) \sqrt {1 - x^2} \, dx \f$
159 : * They satisfy the recursion \f$U_0 (x) = 1\f$, \f$U_1 (1) = 2 x\f$,
160 : * \f$U_k (x) = 2 x U_{k-1} (x) - U_{k-2} (x)\f$.
161 : * The corresponding norm of \f$T_k\f$ is \f$\tfrac{\pi}{2}\f$.
162 : */
163 0 : number Chebyshev2Poly
164 : (
165 : size_t k, ///< index of the polynomial, \f$k \ge 0\f$
166 : number x ///< argument of the polynomial
167 : )
168 : {
169 0 : if (k == 0) return 1;
170 0 : else if (k == 1) return 2 * x;
171 :
172 0 : return 2 * x * Chebyshev2Poly (k-1, x) - Chebyshev2Poly (k - 2, x);
173 : }
174 :
175 : /** returns the scalar square of the Chebyshev polynomials of the second kind (the squared norm)
176 : *
177 : * The polynomials are orthogonal on \f$[-1, 1]\f$ w.r.t. the scalar product
178 : * \f$ \int_{-1}^1 \phi (x) \cdot \psi (x) \sqrt {1 - x^2} \, dx \f$
179 : * They satisfy the recursion \f$U_0 (x) = 1\f$, \f$U_1 (1) = 2 x\f$,
180 : * \f$U_k (x) = 2 x U_{k-1} (x) - U_{k-2} (x)\f$.
181 : * The corresponding norm of \f$T_k\f$ is \f$\tfrac{\pi}{2}\f$.
182 : */
183 0 : number SqNormOfChebyshev2Poly
184 : (
185 : size_t k ///< index of the polynomial, \f$k \ge 0\f$
186 : )
187 : {
188 0 : return PI * PI / 4;
189 : }
190 :
191 : /** returns the values the normalized Chebyshev polynomials of the second kind
192 : *
193 : * The polynomials are orthogonal on \f$[-1, 1]\f$ w.r.t. the scalar product
194 : * \f$ \int_{-1}^1 \phi (x) \cdot \psi (x) \sqrt {1 - x^2} \, dx \f$
195 : * They satisfy the recursion \f$U_0 (x) = 1\f$, \f$U_1 (1) = 2 x\f$,
196 : * \f$U_k (x) = 2 x U_{k-1} (x) - U_{k-2} (x)\f$.
197 : * The corresponding norm of \f$T_k\f$ is \f$\tfrac{\pi}{2}\f$.
198 : */
199 0 : number NormalizedChebyshev2Poly
200 : (
201 : size_t k, ///< index of the polynomial, \f$k \ge 0\f$
202 : number x ///< argument of the polynomial
203 : )
204 : {
205 0 : return Chebyshev2Poly (k, x) * 2 / PI;
206 : }
207 :
208 : } // namespace ug
209 :
210 : /* End of File */
|