Debian Codegraph @

School05/Monday/ortho_poly.h

raw symbols SCIP
1 /*
2 * Declaration of class Ortho_poly and derived classes
3 */
4
5 /*
6 * Copyright (c) 2005 Eric Gourgoulhon
7 *
8 * This file is part of LORENE.
9 *
10 * LORENE is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * LORENE is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with LORENE; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
24 */
25
26 /*
27 * $Id: ortho_poly.h,v 1.1 2005/11/14 01:57:00 e_gourgoulhon Exp $
28 * $Log: ortho_poly.h,v $
29 * Revision 1.1 2005/11/14 01:57:00 e_gourgoulhon
30 * First version
31 *
32 *
33 * $Header: /cvsroot/Lorene/School05/Monday/ortho_poly.h,v 1.1 2005/11/14 01:57:00 e_gourgoulhon Exp $
34 *
35 */
36
37 #ifndef __ORTHO_POLY_H_
38 #define __ORTHO_POLY_H_
39
40 class Grid ;
41
42 //----------------------------------//
43 // class Ortho_poly //
44 //----------------------------------//
45
46 /** Base class for orthogonal polynomials on [-1,1]. \ingroup (poly)
47 * Storage of polynomials of an orthogonal family \f$(p_i)\f$ up to a
48 * given degree \e N.
49 * The class \c Ortho_poly is abstract: it cannot be instanciated.
50 *
51 */
52 class Ortho_poly {
53
54 // Data :
55 // -----
56 protected:
57 const int nn ; ///< \e N = maximum degree of the polynomials
58
59 /** Pointer on the Gauss nodes
60 */
61 mutable const Grid* p_gauss_nodes ;
62
63 /** Pointer on the Gauss weights
64 */
65 mutable double* p_gauss_weights ;
66
67 /** Pointer on the gamma factors (squares of the polynomials with
68 * respect to the discrete scalar product associated with the
69 * Gauss nodes)
70 */
71 mutable double* p_gauss_gamma ;
72
73 /** Pointer on the Gauss-Lobatto nodes
74 */
75 mutable const Grid* p_gauss_lobatto_nodes ;
76
77 /** Pointer on the Gauss-Lobatto weights
78 */
79 mutable double* p_gauss_lobatto_weights ;
80
81 /** Pointer on the gamma factors (square of the polynomials with
82 * respect to the discrete scalar product associated with the
83 * Gauss-Lobatto nodes)
84 */
85 mutable double* p_gauss_lobatto_gamma ;
86
87
88 // Constructors - Destructor
89 // -------------------------
90 protected:
91 Ortho_poly(const Ortho_poly& ) ; ///< Copy constructor
92
93 /** Constructor to be used only by derived classes (hence protected)
94 * @param ni maximum degree \e N of the polynomials
95 */
96 Ortho_poly(int ni) ;
97
98 public:
99 virtual ~Ortho_poly() ; ///< Destructor
100
101 // Mutators / assignment
102 // ---------------------
103 public:
104 /// Assignment to another Ortho_poly
105 void operator=(const Ortho_poly&) ;
106
107 // Accessors
108 // ---------
109 public:
110 int n() const ; ///< returns \e N, i.e. the maximum degree of the polynomials
111
112 // Computation
113 // -----------
114 public:
115 /** Weight function \f$w\f$.
116 *
117 * @param x point in [-1,1] where the weight function is to be evaluated
118 * @return value of \f$w(x)\f$
119 */
120 virtual double weight(double x) const = 0 ;
121
122 /** Value of the polynomial \f$p_i\f$
123 *
124 * @param i no. of the polynomial
125 * @param x point in [-1,1] where the polynomial is to be evaluated
126 * @return value of \f$p_i(x)\f$
127 *
128 */
129 virtual double operator()(int i, double x) const = 0 ;
130
131 /// Gauss nodes
132 virtual const Grid& gauss_nodes() const = 0 ;
133
134 /** Gauss weights
135 *
136 * @param i index of the weight
137 * @return weight \f$w_i\f$
138 */
139 virtual double gauss_weight(int i) const = 0 ;
140
141 /** Gamma factor \f$\gamma_i\f$ (square of the polynomial
142 * number \e i with
143 * respect to the discrete scalar product associated with the
144 * Gauss nodes)
145 */
146 virtual double gauss_gamma(int i) const = 0 ;
147
148 /// Gauss-Lobatto nodes
149 virtual const Grid& gauss_lobatto_nodes() const = 0 ;
150
151 /** Gauss-Lobatto weights
152 *
153 * @param i index of the weight
154 * @return weight \f$w_i\f$
155 */
156 virtual double gauss_lobatto_weight(int i) const = 0 ;
157
158 /** Gamma factor \f$\gamma_i\f$ (square of the polynomial number
159 * \e i with
160 * respect to the discrete scalar product associated with the
161 * Gauss-Lobatto nodes)
162 */
163 virtual double gauss_lobatto_gamma(int i) const = 0 ;
164
165 /** Coefficients of the interpolant polynomial through the
166 * Gauss nodes.
167 *
168 * @param (*f)(double) function to be interpolated
169 * @param cf [output] array containing the \e N+1 coefficients
170 * of the expansion of the interpolant on the basis polynomials.
171 * This array must be of size at least \e N+1 and must have
172 * been allocated by the user prior to the call of this method.
173 */
174 void coef_interpolant_Gauss(double (*f)(double), double* cf) const ;
175
176 /** Coefficients of the interpolant polynomial through the
177 * Gauss-Lobatto nodes.
178 *
179 * @param (*f)(double) function to be interpolated
180 * @param cf [output] array containing the \e N+1 coefficients
181 * of the expansion of the interpolant on the basis polynomials.
182 * This array must be of size at least \e N+1 and must have
183 * been allocated by the user prior to the call of this method.
184 */
185 void coef_interpolant_GL(double (*f)(double), double* cf) const ;
186
187 /** Coefficients of the expansion over the basis polynomials of the
188 * orthogonal projection on the space of polynomials of maximum
189 * degree \e N.
190 *
191 * @param (*f)(double) function to be projected
192 * @param cf [output] array containing the \e N+1 coefficients of the
193 * expansion over the basis polynomials of the
194 * orthogonal projection on the space of polynomials of maximum
195 * degree \e N.
196 * This array must be of size at least \e N+1 and must have
197 * been allocated by the user prior to the call of this method.
198 */
199 virtual void coef_projection(double (*f)(double), double* cf) const = 0 ;
200
201 /** Value of some expansion over the polynomials:
202 * \f$\sum_{i=0}^N a_i\, p_i(x)\f$
203 *
204 * @param a array of size at least \e N+1 and storing the \e N+1
205 * coefficients \f$a_i\f$ of the expansion on the basis
206 * polynomials \f$p_i(x)\f$.
207 * For an interpolant polynomial, \e a is the array \c cf
208 * computed by the method
209 * \c coef_interpolant_Gauss (Gauss nodes) or
210 * \c coef_interpolant_GL (Gauss-Lobatto nodes)
211 * @param x point in [-1,1] where the series is to be evaluated
212 * @return value of \f$\sum_{i=0}^N a_i\, p_i(x)\f$
213 */
214 double series(const double* a, double x) const ;
215
216 };
217
218 //----------------------------------//
219 // class Chebyshev_poly //
220 //----------------------------------//
221
222 /** Chebyshev polynomials. \ingroup (poly)
223 * Each instance of this class represents a family of Chebyshev polynomials
224 * \f$(T_i)\f$ up to a given degree \e N.
225 *
226 */
227 class Chebyshev_poly : public Ortho_poly {
228
229 // Constructors - Destructor
230 // -------------------------
231 public:
232 /** Standard constructor
233 * @param ni maximum degree of the polynomials
234 */
235 Chebyshev_poly(int ni ) ;
236
237 Chebyshev_poly(const Chebyshev_poly& ) ; ///< Copy constructor
238
239 public:
240 virtual ~Chebyshev_poly() ; ///< Destructor
241
242 // Mutators / assignment
243 // ---------------------
244 public:
245 /// Assignment to another Chebyshev_poly
246 void operator=(const Chebyshev_poly&) ;
247
248
249 // Computation
250 // -----------
251 public:
252 /** Weight function \f$w\f$.
253 *
254 * @param x point in [-1,1] where the weight function is to be evaluated
255 * @return \f$w(x)=1/\sqrt{1-x^2}\f$
256 */
257 virtual double weight(double x) const ;
258
259 /** Value of the polynomial \f$p_i\f$
260 *
261 * @param i no. of the polynomial
262 * @param x point in [-1,1] where the polynomial is to be evaluated
263 * @return value of \f$p_i(x)\f$
264 *
265 */
266 virtual double operator()(int i, double x) const ;
267
268 /// Gauss nodes
269 virtual const Grid& gauss_nodes() const ;
270
271 /** Gauss weights
272 *
273 * @param i index of the weight
274 * @return weight \f$w_i\f$
275 */
276 virtual double gauss_weight(int i) const ;
277
278 /** Gamma factor \f$\gamma_i\f$ (square of the polynomial no. \e i with
279 * respect to the discrete scalar product associated with the
280 * Gauss nodes)
281 */
282 virtual double gauss_gamma(int i) const ;
283
284 /// Gauss-Lobatto nodes
285 virtual const Grid& gauss_lobatto_nodes() const ;
286
287 /** Gauss-Lobatto weights
288 *
289 * @param i index of the weight
290 * @return weight \f$w_i\f$
291 */
292 virtual double gauss_lobatto_weight(int i) const ;
293
294 /** Gamma factor \f$\gamma_i\f$ (square of the polynomial no. \e i with
295 * respect to the discrete scalar product associated with the
296 * Gauss-Lobatto nodes)
297 */
298 virtual double gauss_lobatto_gamma(int i) const ;
299
300 /** Coefficients of the interpolant polynomial through the
301 * Gauss-Lobatto nodes via a FFT.
302 *
303 * @param (*f)(double) function to be interpolated
304 * @param cf [output] array of size containing the \e N+1 coefficients
305 * of the expansion of the interpolant on the Chebyshev
306 * polynomials.
307 * This array must be of size at least \e N+1 and must have
308 * allocated by the user prior to the call of this method.
309 */
310 void coef_interpolant_GL_FFT(double (*f)(double), double* cf) const ;
311
312 /** Coefficients of the expansion over the Chebyshev polynomials of the
313 * orthogonal projection on the space of polynomials of maximum
314 * degree \e N.
315 *
316 * @param (*f)(double) function to be projected
317 * @param cf [output] array containing the \e N+1 coefficients of the
318 * expansion over the Chebyshev polynomials of the
319 * orthogonal projection on the space of polynomials of maximum
320 * degree \e N.
321 * This array must be of size at least \e N+1 and must have
322 * been allocated by the user prior to the call of this method.
323 */
324 virtual void coef_projection(double (*f)(double), double* cf) const ;
325
326 };
327
328 /// Display of an object of class \c Chebyshev_poly
329 ostream& operator<<(ostream& , const Chebyshev_poly& ) ;
330
331
332 //----------------------------------//
333 // class Legendre_poly //
334 //----------------------------------//
335
336 /** Legendre polynomials. \ingroup (poly)
337 * Each instance of this class represents a family of Legendre polynomials
338 * \f$(T_i)\f$ up to a given degree \e N.
339 *
340 */
341 class Legendre_poly : public Ortho_poly {
342
343 // Constructors - Destructor
344 // -------------------------
345 public:
346 /** Standard constructor
347 * @param ni maximum degree of the polynomials
348 */
349 Legendre_poly(int ni ) ;
350
351 Legendre_poly(const Legendre_poly& ) ; ///< Copy constructor
352
353 public:
354 virtual ~Legendre_poly() ; ///< Destructor
355
356 // Mutators / assignment
357 // ---------------------
358 public:
359 /// Assignment to another Legendre_poly
360 void operator=(const Legendre_poly&) ;
361
362
363 // Computation
364 // -----------
365 public:
366 /** Weight function \f$w\f$.
367 *
368 * @param x point in [-1,1] where the weight function is to be evaluated
369 * @return \f$w(x)=1\f$ (= constant value 1 for Legendre polynomials)
370 */
371 virtual double weight(double x) const ;
372
373 /** Value of the polynomial \f$p_i\f$
374 *
375 * @param i no. of the polynomial
376 * @param x point in [-1,1] where the polynomial is to be evaluated
377 * @return value of \f$p_i(x)\f$
378 *
379 */
380 virtual double operator()(int i, double x) const ;
381
382 /// Gauss nodes
383 virtual const Grid& gauss_nodes() const ;
384
385 /** Gauss weights
386 *
387 * @param i index of the weight
388 * @return weight \f$w_i\f$
389 */
390 virtual double gauss_weight(int i) const ;
391
392 /** Gamma factor \f$\gamma_i\f$ (square of the polynomial no. \e i with
393 * respect to the discrete scalar product associated with the
394 * Gauss nodes)
395 */
396 virtual double gauss_gamma(int i) const ;
397
398 /// Gauss-Lobatto nodes
399 virtual const Grid& gauss_lobatto_nodes() const ;
400
401 /** Gauss-Lobatto weights
402 *
403 * @param i index of the weight
404 * @return weight \f$w_i\f$
405 */
406 virtual double gauss_lobatto_weight(int i) const ;
407
408 /** Gamma factor \f$\gamma_i\f$ (square of the polynomial no. \e i with
409 * respect to the discrete scalar product associated with the
410 * Gauss-Lobatto nodes)
411 */
412 virtual double gauss_lobatto_gamma(int i) const ;
413
414 /** Coefficients of the expansion over the Legendre polynomials of the
415 * orthogonal projection on the space of polynomials of maximum
416 * degree \e N.
417 *
418 * @param (*f)(double) function to be projected
419 * @param cf [output] array containing the \e N+1 coefficients of the
420 * expansion over the Legendre polynomials of the
421 * orthogonal projection on the space of polynomials of maximum
422 * degree \e N.
423 * This array must be of size at least \e N+1 and must have
424 * been allocated by the user prior to the call of this method.
425 */
426 virtual void coef_projection(double (*f)(double), double* cf) const ;
427
428 };
429
430 /// Display of an object of class \c Legendre_poly
431 ostream& operator<<(ostream& , const Legendre_poly& ) ;
432
433
434 #endif
435