LORENE
val_dern_1d.C
1/*
2 * Copyright (c) 2004 Jerome Novak
3 *
4 * This file is part of LORENE.
5 *
6 * LORENE is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * LORENE is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with LORENE; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
22
23
24
25/*
26 * $Id: val_dern_1d.C,v 1.3 2016/12/05 16:18:09 j_novak Exp $
27 * $Log: val_dern_1d.C,v $
28 * Revision 1.3 2016/12/05 16:18:09 j_novak
29 * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
30 *
31 * Revision 1.2 2014/10/13 08:53:27 j_novak
32 * Lorene classes and functions now belong to the namespace Lorene.
33 *
34 * Revision 1.1 2004/02/17 09:21:39 j_novak
35 * New functions for calculating values of the derivatives of a function
36 * using its Chebyshev coefficients.
37 *
38 *
39 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Operators/val_dern_1d.C,v 1.3 2016/12/05 16:18:09 j_novak Exp $
40 *
41 */
42
43#include "type_parite.h"
44#include "tbl.h"
45
46/*
47 * Functions computing value of f^(n) at boundaries of the interval [-1, 1],
48 * using the Chebyshev expansion of f. Note: n=0 works too.
49 *
50 * Input : 1-dimensional Tbl containing the Chebyshev coefficients of f.
51 * int base : base of spectral expansion.
52 *
53 * Output : double : the value of the n-th derivative of f at x=+/- 1.
54 *
55 */
56
57
58namespace Lorene {
59double val1_dern_1d(int n, const Tbl& tb, int base_r)
60{
61
62 //This function should be OK for any radial base
63 assert ( (base_r == R_CHEB) || (base_r == R_CHEBI) || (base_r == R_CHEBP) ||
64 (base_r == R_CHEBU) ) ;
65
66 assert (n>=0) ;
67 assert (tb.get_ndim() == 1) ;
68 int nr = tb.get_dim(0) ;
69
70 double resu = 0. ;
71
72 int n_ini = ( (base_r == R_CHEBP) || (base_r == R_CHEBI) ) ? n / 2 : n ;
73
74 double *tbi = &tb.t[n_ini] ;
75 for (int i=n_ini; i<nr; i++) {
76 double fact = 1. ;
77 int ii = i ;
78 if (base_r == R_CHEBP) ii *= 2 ;
79 if (base_r == R_CHEBI) ii = 2*i + 1 ;
80 for (int j=0; j<n; j++)
81 fact *= double(ii*ii - j*j)/double(2*j + 1) ;
82 resu += fact * (*tbi) ;
83 tbi++ ;
84 }
85
86 return resu ;
87}
88
89double valm1_dern_1d(int n, const Tbl& tb, int base_r)
90{
91
92 //This function should be OK for any radial base
93 assert ( (base_r == R_CHEB) || (base_r == R_CHEBI) || (base_r == R_CHEBP) ||
94 (base_r == R_CHEBU) ) ;
95
96 assert (n>=0) ;
97 assert (tb.get_ndim() == 1) ;
98 int nr = tb.get_dim(0) ;
99
100 double resu = 0. ;
101 double parite, fac ;
102 int n_ini ;
103 switch (base_r) {
104 case R_CHEBP:
105 n_ini = n / 2 ;
106 parite = 1 ;
107 fac = (n%2 == 0 ? 1 : -1) ;
108 break ;
109 case R_CHEBI:
110 n_ini = n / 2 ;
111 fac = (n%2 == 0 ? -1 : 1) ;
112 parite = 1 ;
113 break ;
114 default:
115 n_ini = n ;
116 parite = -1 ;
117 fac = 1 ;
118 break ;
119 }
120 double *tbi = &tb.t[n_ini] ;
121
122 for (int i=n_ini; i<nr; i++) {
123 double fact = fac ;
124 int ii = i ;
125 if (base_r == R_CHEBP) ii *= 2 ;
126 if (base_r == R_CHEBI) ii = 2*i + 1 ;
127 for (int j=0; j<n; j++)
128 fact *= double(ii*ii - j*j)/double(2*j + 1) ;
129 resu += fact * (*tbi) ;
130 fac *= parite ;
131 tbi++ ;
132 }
133
134 return resu ;
135}
136}
Basic array class.
Definition tbl.h:161
#define R_CHEBU
base de Chebychev ordinaire (fin), dev. en 1/r
#define R_CHEBI
base de Cheb. impaire (rare) seulement
#define R_CHEB
base de Chebychev ordinaire (fin)
#define R_CHEBP
base de Cheb. paire (rare) seulement
Lorene prototypes.
Definition app_hor.h:67