LORENE
sxpun_1d.C
1/*
2 * Copyright (c) 2000-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
23
24
25/*
26 * $Id: sxpun_1d.C,v 1.9 2016/12/05 16:18:09 j_novak Exp $
27 * $Log: sxpun_1d.C,v $
28 * Revision 1.9 2016/12/05 16:18:09 j_novak
29 * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
30 *
31 * Revision 1.8 2014/10/13 08:53:27 j_novak
32 * Lorene classes and functions now belong to the namespace Lorene.
33 *
34 * Revision 1.7 2014/10/06 15:16:07 j_novak
35 * Modified #include directives to use c++ syntax.
36 *
37 * Revision 1.6 2008/08/27 08:50:10 jl_cornou
38 * Added Jacobi(0,2) polynomials
39 *
40 * Revision 1.5 2007/12/21 13:59:02 j_novak
41 * Suppression of call to pow(-1, something).
42 *
43 * Revision 1.4 2007/12/12 09:56:57 jl_cornou
44 * *** empty log message ***
45 *
46 * Revision 1.2 2002/10/16 14:37:07 j_novak
47 * Reorganization of #include instructions of standard C++, in order to
48 * use experimental version 3 of gcc.
49 *
50 * Revision 1.1.1.1 2001/11/20 15:19:29 e_gourgoulhon
51 * LORENE
52 *
53 * Revision 2.0 2000/04/03 17:01:59 phil
54 * *** empty log message ***
55 *
56 *
57 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Operators/sxpun_1d.C,v 1.9 2016/12/05 16:18:09 j_novak Exp $
58 *
59 */
60
61
62#include <cstdlib>
63#include <cmath>
64
65#include "tbl.h"
66#include "type_parite.h"
67
68/*
69 * Operateur :
70 * -R_CHEB : (f-f(-1))/(x+1)
71 * -R_JACO02 : (f-f(-1))/(x+1)
72 *
73 *
74 * Entree : coefficients de f dans tb
75 * nr : nombre de points en r
76 * Sortie : coefficient du resultat dans tb
77 *
78 *
79 */
80
81
82 //-----------------------------------
83 // Routine pour les cas non prevus --
84 //-----------------------------------
85
86namespace Lorene {
87void _sxpun_1d_pas_prevu(int nr, double* tb, double *res) {
88 cout << "sxpun pas prevu..." << endl ;
89 cout << " valeurs: " << tb << " " << res << endl ;
90 cout << "nr : " << nr << endl ;
91 abort () ;
92 exit(-1) ;
93}
94
95
96
97 //---------------
98 // cas R_CHEB ---
99 //---------------
100
101void _sxpun_1d_r_cheb (int nr, double* tb, double *xo)
102{
103
104 assert (nr >= 3) ;
105
106 xo[nr-1] = 0 ;
107 xo[nr-2] = 2*(tb[nr-1]-xo[nr-1]) ;
108
109 for (int i=nr-3 ; i>0 ; i--)
110 xo[i] = 2*tb[i+1]-2*xo[i+1]-xo[i+2] ;
111
112 double somme = 0 ;
113 for (int i=0 ; i<nr ; i++)
114 if (i%2 == 0)
115 somme += tb[i] ;
116 else
117 somme -= tb[i] ;
118
119 xo[0] = tb[0]-xo[1]/2.-somme ;
120}
121
122
123 //---------------
124 // cas R_JACO02 -
125 //---------------
126
127void _sxpun_1d_r_jaco02 (int nr, double* tb, double* xo)
128{
129
130 xo[nr-1] = 0 ;
131 double somme ;
132 for (int i = 0 ; i < nr-1 ; i++) {
133 somme = 0 ;
134 for (int j = i+1 ; j < nr ; j++) {
135 int signe = ((j-1-i)%2 == 0 ? 1 : -1) ;
136 somme += signe*((j+1)*(j+2)/double((i+1)*(i+2))-(i+1)*(i+2)/double((j+1)*(j+2)))*tb[j] ;
137 }
138 xo[i] = (2*i+3)/double(4)*somme ;
139 }
140}
141
142 //----------------------------
143 // La routine a appeler ----
144 //----------------------------
145
146
147void sxpun_1d(int nr, double **tb, int base_r) // Version appliquee a this
148{
149
150// Routines de derivation
151static void (*sxpun_1d[MAX_BASE])(int, double *, double *) ;
152static int nap = 0 ;
153
154 // Premier appel
155 if (nap==0) {
156 nap = 1 ;
157 for (int i=0 ; i<MAX_BASE ; i++) {
158 sxpun_1d[i] = _sxpun_1d_pas_prevu ;
159 }
160 // Les routines existantes
161 sxpun_1d[R_CHEB >> TRA_R] = _sxpun_1d_r_cheb ;
162 sxpun_1d[R_JACO02 >> TRA_R] = _sxpun_1d_r_jaco02 ;
163 }
164
165 double *result = new double[nr] ;
166 sxpun_1d[base_r](nr, *tb, result) ;
167
168 delete [] (*tb) ;
169 (*tb) = result ;
170}
171}
#define MAX_BASE
Nombre max. de bases differentes.
#define R_JACO02
base de Jacobi(0,2) ordinaire (finjac)
#define TRA_R
Translation en R, used for a bitwise shift (in hex).
#define R_CHEB
base de Chebychev ordinaire (fin)
Lorene prototypes.
Definition app_hor.h:67