LORENE
dsdx_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: dsdx_1d.C,v 1.10 2016/12/05 16:18:07 j_novak Exp $
27 * $Log: dsdx_1d.C,v $
28 * Revision 1.10 2016/12/05 16:18:07 j_novak
29 * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
30 *
31 * Revision 1.9 2015/03/25 15:03:00 j_novak
32 * Correction of a bug...
33 *
34 * Revision 1.8 2015/03/05 08:49:31 j_novak
35 * Implemented operators with Legendre bases.
36 *
37 * Revision 1.7 2014/10/13 08:53:23 j_novak
38 * Lorene classes and functions now belong to the namespace Lorene.
39 *
40 * Revision 1.6 2014/10/06 15:16:06 j_novak
41 * Modified #include directives to use c++ syntax.
42 *
43 * Revision 1.5 2007/12/12 12:30:48 jl_cornou
44 * *** empty log message ***
45 *
46 * Revision 1.4 2007/12/11 15:28:18 jl_cornou
47 * Jacobi(0,2) polynomials partially implemented
48 *
49 * Revision 1.3 2006/04/10 15:19:20 j_novak
50 * New definition of 1D operators dsdx and sx in the nucleus (bases R_CHEBP and
51 * R_CHEBI).
52 *
53 * Revision 1.2 2005/01/10 16:34:53 j_novak
54 * New class for 1D mono-domain differential operators.
55 *
56 * Revision 1.1 2004/02/06 10:53:53 j_novak
57 * New dzpuis = 5 -> dzpuis = 3 case (not ready yet).
58 *
59 *
60 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Operators/dsdx_1d.C,v 1.10 2016/12/05 16:18:07 j_novak Exp $
61 *
62 */
63
64#include <cmath>
65#include <cstdlib>
66#include "type_parite.h"
67#include "headcpp.h"
68#include "proto.h"
69
70/*
71 * Routine appliquant l'operateur dsdx.
72 *
73 * Entree : tb contient les coefficients du developpement
74 * int nr : nombre de points en r.
75 *
76 * Sortie : tb contient dsdx
77 *
78 */
79
80 //----------------------------------
81 // Routine pour les cas non prevus --
82 //----------------------------------
83
84namespace Lorene {
85void _dsdx_1d_pas_prevu(int nr, double* tb, double *xo) {
86 cout << "dsdx pas prevu..." << endl ;
87 cout << "Nombre de points : " << nr << endl ;
88 cout << "Valeurs : " << tb << " " << xo <<endl ;
89 abort() ;
90 exit(-1) ;
91}
92
93 //----------------
94 // cas R_CHEBU ---
95 //----------------
96
97void _dsdx_1d_r_chebu(int nr, double* tb, double *xo)
98{
99
100 double som ;
101
102 xo[nr-1] = 0 ;
103 som = 2*(nr-1) * tb[nr-1] ;
104 xo[nr-2] = som ;
105 for (int i = nr-4 ; i >= 0 ; i -= 2 ) {
106 som += 2*(i+1) * tb[i+1] ;
107 xo[i] = som ;
108 } // Fin de la premiere boucle sur r
109 som = 2*(nr-2) * tb[nr-2] ;
110 xo[nr-3] = som ;
111 for (int i = nr-5 ; i >= 0 ; i -= 2 ) {
112 som += 2*(i+1) * tb[i+1] ;
113 xo[i] = som ;
114 } // Fin de la deuxieme boucle sur r
115 xo[0] *= .5 ;
116
117}
118
119
120 //----------------
121 // cas R_JACO02 --
122 //----------------
123
124void _dsdx_1d_r_jaco02(int nr, double* tb, double *xo)
125{
126
127 double som ;
128
129 xo[nr-1] = 0 ;
130 for (int i = 0 ; i < nr-1 ; i++ ) {
131 som = 0 ;
132 for ( int j = i+1 ; j < nr ; j++ ) {
133 som += (1 - pow(double(-1),(j-i))*(i+1)*(i+2)/double((j+1)*(j+2)))*tb[j] ;
134 } // Fin de la boucle auxiliaire
135 xo[i] = (i+1.5)*som ;
136 } // Fin de la boucle sur R
137
138}
139
140 //----------------
141 // cas R_CHEBI ---
142 //----------------
143
144void _dsdx_1d_r_chebi(int nr, double* tb, double *xo)
145{
146
147 double som ;
148
149 xo[nr-1] = 0 ;
150 som = 2*(2*nr-3) * tb[nr-2] ;
151 xo[nr-2] = som ;
152 for (int i = nr-3 ; i >= 0 ; i -- ) {
153 som += 2*(2*i+1) * tb[i] ;
154 xo[i] = som ;
155 }
156 xo[0] *= .5 ;
157}
158
159 //----------------
160 // cas R_CHEBP ---
161 //----------------
162
163void _dsdx_1d_r_chebp(int nr, double* tb, double *xo)
164{
165
166 double som ;
167
168 xo[nr-1] = 0 ;
169 som = 4*(nr-1) * tb[nr-1] ;
170 xo[nr-2] = som ;
171 for (int i = nr-3 ; i >= 0 ; i --) {
172 som += 4*(i+1) * tb[i+1] ;
173 xo[i] = som ;
174 }
175}
176
177 //--------------
178 // cas R_LEG ---
179 //--------------
180
181void _dsdx_1d_r_leg(int nr, double* tb, double *xo)
182{
183 double som ;
184
185 xo[nr-1] = 0 ;
186 som = tb[nr-1] ;
187 xo[nr-2] = double(2*nr-3)*som ;
188 for (int i = nr-4 ; i >= 0 ; i -= 2 ) {
189 som += tb[i+1] ;
190 xo[i] = double(2*i+1)*som ;
191 } // Fin de la premiere boucle sur r
192 som = tb[nr-2] ;
193 if (nr > 2) xo[nr-3] = double(2*nr-5)*som ;
194 for (int i = nr-5 ; i >= 0 ; i -= 2 ) {
195 som += tb[i+1] ;
196 xo[i] = double(2*i+1)*som ;
197 } // Fin de la deuxieme boucle sur r
198}
199
200 //---------------
201 // cas R_LEGI ---
202 //---------------
203
204void _dsdx_1d_r_legi(int nr, double* tb, double *xo)
205{
206
207 double som ;
208
209 xo[nr-1] = 0 ;
210 som = tb[nr-2] ;
211 if (nr > 1) xo[nr-2] = double(4*nr-7)*som ;
212 for (int i = nr-3 ; i >= 0 ; i -- ) {
213 som += tb[i] ;
214 xo[i] = double(4*i+1)*som ;
215 }
216}
217
218 //---------------
219 // cas R_LEGP ---
220 //---------------
221
222void _dsdx_1d_r_legp(int nr, double* tb, double *xo)
223{
224
225 double som ;
226
227 xo[nr-1] = 0 ;
228 som = tb[nr-1] ;
229 if (nr > 1) xo[nr-2] = double(4*nr-5)*som ;
230 for (int i = nr-3 ; i >= 0 ; i --) {
231 som += tb[i+1] ;
232 xo[i] = double(4*i+3)*som ;
233 }
234}
235
236 // ---------------------
237 // La routine a appeler
238 //----------------------
239
240
241void dsdx_1d(int nr, double** tb, int base_r)
242{
243
244 // Routines de derivation
245 static void (*dsdx_1d[MAX_BASE])(int, double*, double *) ;
246 static int nap = 0 ;
247
248 // Premier appel
249 if (nap==0) {
250 nap = 1 ;
251 for (int i=0 ; i<MAX_BASE ; i++) {
252 dsdx_1d[i] = _dsdx_1d_pas_prevu ;
253 }
254 // Les routines existantes
255 dsdx_1d[R_CHEBU >> TRA_R] = _dsdx_1d_r_chebu ;
256 dsdx_1d[R_CHEBP >> TRA_R] = _dsdx_1d_r_chebp ;
257 dsdx_1d[R_CHEBI >> TRA_R] = _dsdx_1d_r_chebi ;
258 dsdx_1d[R_CHEB >> TRA_R] = _dsdx_1d_r_cheb ;
259 dsdx_1d[R_LEGP >> TRA_R] = _dsdx_1d_r_legp ;
260 dsdx_1d[R_LEGI >> TRA_R] = _dsdx_1d_r_legi ;
261 dsdx_1d[R_LEG >> TRA_R] = _dsdx_1d_r_leg ;
262 dsdx_1d[R_JACO02 >> TRA_R] = _dsdx_1d_r_jaco02 ;
263
264 }
265
266 double *result = new double[nr] ;
267
268 dsdx_1d[base_r](nr, *tb, result) ;
269
270 delete [] (*tb) ;
271 (*tb) = result ;
272}
273}
Cmp pow(const Cmp &, int)
Power .
Definition cmp_math.C:351
#define R_LEGP
base de Legendre paire (rare) seulement
#define MAX_BASE
Nombre max. de bases differentes.
#define R_CHEBU
base de Chebychev ordinaire (fin), dev. en 1/r
#define R_JACO02
base de Jacobi(0,2) ordinaire (finjac)
#define R_LEGI
base de Legendre impaire (rare) seulement
#define R_CHEBI
base de Cheb. impaire (rare) seulement
#define R_LEG
base de Legendre ordinaire (fin)
#define TRA_R
Translation en R, used for a bitwise shift (in hex).
#define R_CHEB
base de Chebychev ordinaire (fin)
#define R_CHEBP
base de Cheb. paire (rare) seulement
Lorene prototypes.
Definition app_hor.h:67