LORENE
d2sdx2_1d.C
1/*
2 * Copyright (c) 1999-2001 Philippe Grandclement
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
23char d2sdx2_1d_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Operators/d2sdx2_1d.C,v 1.7 2015/03/05 08:49:31 j_novak Exp $" ;
24
25/*
26 * $Id: d2sdx2_1d.C,v 1.7 2015/03/05 08:49:31 j_novak Exp $
27 * $Log: d2sdx2_1d.C,v $
28 * Revision 1.7 2015/03/05 08:49:31 j_novak
29 * Implemented operators with Legendre bases.
30 *
31 * Revision 1.6 2014/10/13 08:53:23 j_novak
32 * Lorene classes and functions now belong to the namespace Lorene.
33 *
34 * Revision 1.5 2014/10/06 15:16:06 j_novak
35 * Modified #include directives to use c++ syntax.
36 *
37 * Revision 1.4 2007/12/11 15:28:18 jl_cornou
38 * Jacobi(0,2) polynomials partially implemented
39 *
40 * Revision 1.3 2002/10/16 15:05:54 j_novak
41 * *** empty log message ***
42 *
43 * Revision 1.2 2002/10/16 14:36:58 j_novak
44 * Reorganization of #include instructions of standard C++, in order to
45 * use experimental version 3 of gcc.
46 *
47 * Revision 1.1.1.1 2001/11/20 15:19:29 e_gourgoulhon
48 * LORENE
49 *
50 * Revision 2.4 1999/10/11 15:18:14 phil
51 * *** empty log message ***
52 *
53 * Revision 2.3 1999/10/11 14:27:06 phil
54 * initialisation des variables statiques
55 *
56 * Revision 2.2 1999/09/03 14:15:56 phil
57 * Correction termes 0 (/2)
58 *
59 * Revision 2.1 1999/07/08 09:53:13 phil
60 * correction gestion memoire
61 *
62 * Revision 2.0 1999/07/07 10:15:26 phil
63 * *** empty log message ***
64 *
65 *
66 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Operators/d2sdx2_1d.C,v 1.7 2015/03/05 08:49:31 j_novak Exp $
67 *
68 */
69
70#include <cstdlib>
71#include "type_parite.h"
72#include "headcpp.h"
73#include "proto.h"
74
75/*
76 * Routine appliquant l'operateur d2sdx2.
77 *
78 * Entree : tb contient les coefficients du developpement
79 * int nr : nombre de points en r.
80 *
81 * Sortie : tb contient d2sdx2
82 *
83 */
84
85 //----------------------------------
86 // Routine pour les cas non prevus --
87 //----------------------------------
88
89namespace Lorene {
90void _d2sdx2_1d_pas_prevu(int nr, double* tb, double *xo) {
91 cout << "d2sdx2 pas prevu..." << endl ;
92 cout << "Nombre de points : " << nr << endl ;
93 cout << "Valeurs : " << tb << " " << xo <<endl ;
94 abort() ;
95 exit(-1) ;
96}
97
98 //----------------
99 // cas R_CHEBU ---
100 //----------------
101
102void _d2sdx2_1d_r_chebu(int nr, double* tb, double *xo)
103{
104 // Variables statiques
105 static double* cx1 = 0x0 ;
106 static double* cx2 = 0x0 ;
107 static double* cx3 = 0x0 ;
108 static int nr_pre = 0 ;
109
110 // Test sur np pour initialisation eventuelle
111 if (nr > nr_pre) {
112 nr_pre = nr ;
113 if (cx1 != 0x0) delete [] cx1 ;
114 if (cx2 != 0x0) delete [] cx2 ;
115 if (cx3 != 0x0) delete [] cx3 ;
116 cx1 = new double [nr] ;
117 cx2 = new double [nr] ;
118 cx3 = new double [nr] ;
119 for (int i=0 ; i<nr ; i++) {
120 cx1[i] = (i+2)*(i+2)*(i+2) ;
121 cx2[i] = (i+2) ;
122 cx3[i] = i*i ;
123 }
124 }
125
126 double som1, som2 ;
127
128 xo[nr-1] = 0 ;
129 som1 = (nr-1)*(nr-1)*(nr-1) * tb[nr-1] ;
130 som2 = (nr-1) * tb[nr-1] ;
131 xo[nr-3] = som1 - (nr-3)*(nr-3)*som2 ;
132 for (int i = nr-5 ; i >= 0 ; i -= 2 ) {
133 som1 += cx1[i] * tb[i+2] ;
134 som2 += cx2[i] * tb[i+2] ;
135 xo[i] = som1 - cx3[i] * som2 ;
136 } // Fin de la premiere boucle sur r
137
138 xo[nr-2] = 0 ;
139 som1 = (nr-2)*(nr-2)*(nr-2) * tb[nr-2] ;
140 som2 = (nr-2) * tb[nr-2] ;
141 xo[nr-4] = som1 - (nr-4)*(nr-4)*som2 ;
142 for (int i = nr-6 ; i >= 0 ; i -= 2 ) {
143 som1 += cx1[i] * tb[i+2] ;
144 som2 += cx2[i] * tb[i+2] ;
145 xo[i] = som1 - cx3[i] * som2 ;
146 } // Fin de la deuxieme boucle sur r
147 xo[0] *= 0.5 ;
148
149}
150
151 //---------------
152 // cas R_CHEB ---
153 //---------------
154
155void _d2sdx2_1d_r_cheb(int nr, double* tb, double *xo)
156{
157
158 // Variables statiques
159 static double* cx1 = 0x0 ;
160 static double* cx2 = 0x0 ;
161 static double* cx3 = 0x0 ;
162 static int nr_pre = 0 ;
163
164 // Test sur np pour initialisation eventuelle
165 if (nr > nr_pre) {
166 nr_pre = nr ;
167 if (cx1 != 0x0) delete [] cx1 ;
168 if (cx2 != 0x0) delete [] cx2 ;
169 if (cx3 != 0x0) delete [] cx3 ;
170 cx1 = new double [nr] ;
171 cx2 = new double [nr] ;
172 cx3 = new double [nr] ;
173 for (int i=0 ; i<nr ; i++) {
174 cx1[i] = (i+2)*(i+2)*(i+2) ;
175 cx2[i] = (i+2) ;
176 cx3[i] = i*i ;
177 }
178 }
179
180 double som1, som2 ;
181
182 xo[nr-1] = 0 ;
183 som1 = (nr-1)*(nr-1)*(nr-1) * tb[nr-1] ;
184 som2 = (nr-1) * tb[nr-1] ;
185 xo[nr-3] = som1 - (nr-3)*(nr-3)*som2 ;
186 for (int i = nr-5 ; i >= 0 ; i -= 2 ) {
187 som1 += cx1[i] * tb[i+2] ;
188 som2 += cx2[i] * tb[i+2] ;
189 xo[i] = som1 - cx3[i] * som2 ;
190 } // Fin de la premiere boucle sur r
191 xo[nr-2] = 0 ;
192 som1 = (nr-2)*(nr-2)*(nr-2) * tb[nr-2] ;
193 som2 = (nr-2) * tb[nr-2] ;
194 xo[nr-4] = som1 - (nr-4)*(nr-4)*som2 ;
195 for (int i = nr-6 ; i >= 0 ; i -= 2 ) {
196 som1 += cx1[i] * tb[i+2] ;
197 som2 += cx2[i] * tb[i+2] ;
198 xo[i] = som1 - cx3[i] * som2 ;
199 } // Fin de la deuxieme boucle sur r
200 xo[0] *= .5 ;
201
202}
203
204 //----------------
205 // cas R_JACO02 --
206 //----------------
207
208void _d2sdx2_1d_r_jaco02(int nr, double* tb, double *xo)
209{
210 dsdx_1d(nr, &tb, R_JACO02 >> TRA_R) ;
211 dsdx_1d(nr, &tb, R_JACO02 >> TRA_R) ;
212 for (int i = 0 ; i<nr ; i++) {
213 xo[i] = tb[i] ;
214 }
215}
216
217
218 //-----------------
219 // cas R_CHEBP ---
220 //----------------
221
222void _d2sdx2_1d_r_chebp(int nr, double* tb, double *xo)
223{
224 // Variables statiques
225 static double* cx1 = 0x0 ;
226 static double* cx2 = 0x0 ;
227 static double* cx3 = 0x0 ;
228 static int nr_pre = 0 ;
229
230 // Test sur np pour initialisation eventuelle
231 if (nr > nr_pre) {
232 nr_pre = nr ;
233 if (cx1 != 0x0) delete [] cx1 ;
234 if (cx2 != 0x0) delete [] cx2 ;
235 if (cx3 != 0x0) delete [] cx3 ;
236 cx1 = new double [nr] ;
237 cx2 = new double [nr] ;
238 cx3 = new double [nr] ;
239 for (int i=0 ; i<nr ; i++) {
240 cx1[i] = 8*(i+1)*(i+1)*(i+1) ;
241 cx2[i] = 2*(i+1) ;
242 cx3[i] = 4*i*i ;
243 }
244 }
245
246 double som1, som2 ;
247
248 xo[nr-1] = 0 ;
249 som1 = 8*(nr-1)*(nr-1)*(nr-1) * tb[nr-1] ;
250 som2 = 2*(nr-1) * tb[nr-1] ;
251 xo[nr-2] = som1 - 4*(nr-2)*(nr-2)*som2 ;
252
253 for (int i = nr-3 ; i >= 0 ; i-- ) {
254 som1 += cx1[i] * tb[i+1] ;
255 som2 += cx2[i] * tb[i+1] ;
256 xo[i] = som1 - cx3[i] * som2 ;
257 } // Fin de la boucle sur r
258 xo[0] *= .5 ;
259}
260
261 //---------------
262 // cas R_CHEBI --
263 //---------------
264
265void _d2sdx2_1d_r_chebi(int nr, double* tb, double *xo)
266{
267 // Variables statiques
268 static double* cx1 = 0x0 ;
269 static double* cx2 = 0x0 ;
270 static double* cx3 = 0x0 ;
271 static int nr_pre = 0 ;
272
273 // Test sur np pour initialisation eventuelle
274
275 if (nr > nr_pre) {
276 nr_pre = nr ;
277 if (cx1 != 0x0) delete [] cx1 ;
278 if (cx2 != 0x0) delete [] cx2 ;
279 if (cx3 != 0x0) delete [] cx3 ;
280 cx1 = new double [nr] ;
281 cx2 = new double [nr] ;
282 cx3 = new double [nr] ;
283 for (int i=0 ; i<nr ; i++) {
284 cx1[i] = (2*i+3)*(2*i+3)*(2*i+3) ;
285 cx2[i] = (2*i+3) ;
286 cx3[i] = (2*i+1)*(2*i+1) ;
287 }
288 }
289
290 // pt. sur le tableau de double resultat
291 double som1, som2 ;
292
293 xo[nr-1] = 0 ;
294 som1 = (2*nr-1)*(2*nr-1)*(2*nr-1) * tb[nr-1] ;
295 som2 = (2*nr-1) * tb[nr-1] ;
296 xo[nr-2] = som1 - (2*nr-3)*(2*nr-3)*som2 ;
297 for (int i = nr-3 ; i >= 0 ; i-- ) {
298 som1 += cx1[i] * tb[i+1] ;
299 som2 += cx2[i] * tb[i+1] ;
300 xo[i] = som1 - cx3[i] * som2 ;
301 } // Fin de la boucle su r
302
303}
304
305 //--------------
306 // cas R_LEG ---
307 //--------------
308
309void _d2sdx2_1d_r_leg(int nr, double* tb, double *xo)
310{
311
312 // Variables statiques
313 static double* cx1 = 0x0 ;
314 static double* cx2 = 0x0 ;
315 static double* cx3 = 0x0 ;
316 static int nr_pre = 0 ;
317
318 // Test sur np pour initialisation eventuelle
319 if (nr > nr_pre) {
320 nr_pre = nr ;
321 if (cx1 != 0x0) delete [] cx1 ;
322 if (cx2 != 0x0) delete [] cx2 ;
323 if (cx3 != 0x0) delete [] cx3 ;
324 cx1 = new double [nr] ;
325 cx2 = new double [nr] ;
326 cx3 = new double [nr] ;
327 for (int i=0 ; i<nr ; i++) {
328 cx1[i] = (i+2)*(i+3) ;
329 cx2[i] = i*(i+1) ;
330 cx3[i] = double(i) + 0.5 ;
331 }
332 }
333
334 double som1, som2 ;
335
336 xo[nr-1] = 0 ;
337 som1 = (nr-1)* nr * tb[nr-1] ;
338 som2 = tb[nr-1] ;
339 if (nr > 2)
340 xo[nr-3] = (double(nr) - 2.5) * (som1 - (nr-3)*(nr-2)*som2) ;
341 for (int i = nr-5 ; i >= 0 ; i -= 2 ) {
342 som1 += cx1[i] * tb[i+2] ;
343 som2 += tb[i+2] ;
344 xo[i] = cx3[i]*(som1 - cx2[i] * som2) ;
345 } // Fin de la premiere boucle sur r
346 if (nr > 1) xo[nr-2] = 0 ;
347 if (nr > 3) {
348 som1 = (nr-2)*(nr-1) * tb[nr-2] ;
349 som2 = tb[nr-2] ;
350 xo[nr-4] = (double(nr) - 3.5) * (som1 - (nr-4)*(nr-3)*som2) ;
351 }
352 for (int i = nr-6 ; i >= 0 ; i -= 2 ) {
353 som1 += cx1[i] * tb[i+2] ;
354 som2 += tb[i+2] ;
355 xo[i] = cx3[i]*(som1 - cx2[i] * som2) ;
356 } // Fin de la deuxieme boucle sur r
357
358}
359
360 //---------------
361 // cas R_LEGP ---
362 //---------------
363
364void _d2sdx2_1d_r_legp(int nr, double* tb, double *xo)
365{
366 // Variables statiques
367 static double* cx1 = 0x0 ;
368 static double* cx2 = 0x0 ;
369 static double* cx3 = 0x0 ;
370 static int nr_pre = 0 ;
371
372 // Test sur np pour initialisation eventuelle
373 if (nr > nr_pre) {
374 nr_pre = nr ;
375 if (cx1 != 0x0) delete [] cx1 ;
376 if (cx2 != 0x0) delete [] cx2 ;
377 if (cx3 != 0x0) delete [] cx3 ;
378 cx1 = new double [nr] ;
379 cx2 = new double [nr] ;
380 cx3 = new double [nr] ;
381 for (int i=0 ; i<nr ; i++) {
382 cx1[i] = (2*i+2)*(2*i+3) ;
383 cx2[i] = 2*i*2*(i+1) ;
384 cx3[i] = double(2*i)+ 0.5 ;
385 }
386 }
387
388 double som1, som2 ;
389
390 xo[nr-1] = 0 ;
391 som1 = (2*nr-2)*(2*nr-1)* tb[nr-1] ;
392 som2 = tb[nr-1] ;
393 if (nr > 1)
394 xo[nr-2] = (double(2*nr) - 1.5)*(som1 - 2*(nr-2)*(2*nr-1)*som2) ;
395 for (int i = nr-3 ; i >= 0 ; i-- ) {
396 som1 += cx1[i] * tb[i+1] ;
397 som2 += tb[i+1] ;
398 xo[i] = cx3[i]*(som1 - cx2[i]*som2) ;
399 } // Fin de la boucle sur r
400}
401
402 //---------------
403 // cas R_LEGI --
404 //---------------
405
406void _d2sdx2_1d_r_legi(int nr, double* tb, double *xo)
407{
408 // Variables statiques
409 static double* cx1 = 0x0 ;
410 static double* cx2 = 0x0 ;
411 static double* cx3 = 0x0 ;
412 static int nr_pre = 0 ;
413
414 // Test sur np pour initialisation eventuelle
415
416 if (nr > nr_pre) {
417 nr_pre = nr ;
418 if (cx1 != 0x0) delete [] cx1 ;
419 if (cx2 != 0x0) delete [] cx2 ;
420 if (cx3 != 0x0) delete [] cx3 ;
421 cx1 = new double [nr] ;
422 cx2 = new double [nr] ;
423 cx3 = new double [nr] ;
424 for (int i=0 ; i<nr ; i++) {
425 cx1[i] = (2*i+3)*(2*i+4) ;
426 cx2[i] = (2*i+1)*(2*i+2) ;
427 cx3[i] = double(2*i) + 1.5 ;
428 }
429 }
430
431 // pt. sur le tableau de double resultat
432 double som1, som2 ;
433
434 xo[nr-1] = 0 ;
435 som1 = (2*nr-1)*(2*nr) * tb[nr-1] ;
436 som2 = tb[nr-1] ;
437 if (nr > 1)
438 xo[nr-2] = (double(nr) - 1.5)*(som1 - (2*nr-3)*(2*nr-2)*som2) ;
439 for (int i = nr-3 ; i >= 0 ; i-- ) {
440 som1 += cx1[i] * tb[i+1] ;
441 som2 += tb[i+1] ;
442 xo[i] = cx3[i]*(som1 - cx2[i] * som2) ;
443 } // Fin de la boucle sur r
444}
445
446
447 // ---------------------
448 // La routine a appeler
449 //----------------------
450
451
452void d2sdx2_1d(int nr, double** tb, int base_r)
453{
454
455 // Routines de derivation
456 static void (*d2sdx2_1d[MAX_BASE])(int, double*, double *) ;
457 static int nap = 0 ;
458
459 // Premier appel
460 if (nap==0) {
461 nap = 1 ;
462 for (int i=0 ; i<MAX_BASE ; i++) {
463 d2sdx2_1d[i] = _d2sdx2_1d_pas_prevu ;
464 }
465 // Les routines existantes
466 d2sdx2_1d[R_CHEB >> TRA_R] = _d2sdx2_1d_r_cheb ;
467 d2sdx2_1d[R_CHEBU >> TRA_R] = _d2sdx2_1d_r_chebu ;
468 d2sdx2_1d[R_CHEBP >> TRA_R] = _d2sdx2_1d_r_chebp ;
469 d2sdx2_1d[R_CHEBI >> TRA_R] = _d2sdx2_1d_r_chebi ;
470 d2sdx2_1d[R_LEG >> TRA_R] = _d2sdx2_1d_r_leg ;
471 d2sdx2_1d[R_LEGP >> TRA_R] = _d2sdx2_1d_r_legp ;
472 d2sdx2_1d[R_LEGI >> TRA_R] = _d2sdx2_1d_r_legi ;
473 d2sdx2_1d[R_JACO02 >> TRA_R] = _d2sdx2_1d_r_jaco02 ;
474 }
475
476 double *result = new double[nr] ;
477
478 d2sdx2_1d[base_r](nr, *tb, result) ;
479
480 delete [] (*tb) ;
481 (*tb) = result ;
482}
483}
#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:64