LORENE
sx2_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 
23 
24 
25 /*
26  * $Id: sx2_1d.C,v 1.7 2016/12/05 16:18:08 j_novak Exp $
27  * $Log: sx2_1d.C,v $
28  * Revision 1.7 2016/12/05 16:18:08 j_novak
29  * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
30  *
31  * Revision 1.6 2015/03/05 08:49:32 j_novak
32  * Implemented operators with Legendre bases.
33  *
34  * Revision 1.5 2014/10/13 08:53:27 j_novak
35  * Lorene classes and functions now belong to the namespace Lorene.
36  *
37  * Revision 1.4 2014/10/06 15:16:07 j_novak
38  * Modified #include directives to use c++ syntax.
39  *
40  * Revision 1.3 2007/12/11 15:28:18 jl_cornou
41  * Jacobi(0,2) polynomials partially implemented
42  *
43  * Revision 1.2 2002/10/16 14:36:59 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.1 1999/07/08 09:55:21 phil
51  * correction gestion memoire
52  *
53  * Revision 2.0 1999/07/07 10:15:03 phil
54  * *** empty log message ***
55  *
56  *
57  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Operators/sx2_1d.C,v 1.7 2016/12/05 16:18:08 j_novak Exp $
58  *
59  */
60 
61 // Includes
62 #include <cstdlib>
63 
64 
65 #include "headcpp.h"
66 #include "type_parite.h"
67 #include "proto.h"
68 
69 /*
70  * Operateurs non singuliers :
71  * R_CHEB : Identite
72  * R_CHEBP, R_CHEBI : (f-f(0)-f'(0)x)/x^2
73  * R_CHEBU : (f-f(1)-(x-1)*f'(1))/(x-1)^2
74  *
75  *Entree : tb contient coefficients de developpement en r
76  * nr : nombre de points en r.
77  *Sortie : tb contient les coefficients du resultat
78  *
79  */
80 namespace Lorene {
81 
82  void _sx_1d_r_legp(int, double* , double *) ;
83  void _sx_1d_r_legi(int, double* , double *) ;
84 
85 
86  //-----------------------------------
87  // Routine pour les cas non prevus --
88  //-----------------------------------
89 
90 void _sx2_1d_pas_prevu(int nr, double* tb, double *res) {
91  cout << "sx2 pas prevu..." << tb << " " << res << endl ;
92  cout << "nr : " << nr << endl ;
93  abort() ;
94  exit(-1) ;
95 }
96 
97 
98  //-------------
99  // Identite --
100  //------------
101 
102 void _sx2_1d_identite(int nr, double*tb ,double *res) {
103  for (int i=0 ; i<nr ; i++)
104  res[i] = tb[i] ;
105 }
106 
107 
108  //---------------
109  // cas R_CHEBP --
110  //---------------
111 
112 void _sx2_1d_r_chebp(int nr, double* tb, double *xo)
113 {
114 
115 
116 
117  double somp, somn ;
118  int sgn = 1 ;
119 
120  xo[nr-1] = 0 ;
121  somp = 4 * sgn * (nr-1) * tb[nr-1] ;
122  somn = 2 * sgn * tb[nr-1] ;
123  xo[nr-2] = somp - 2*(nr-2)*somn ;
124  for (int i = nr-3 ; i >= 0 ; i-- ) {
125  sgn = - sgn ;
126  somp += 4 * (i+1) * sgn * tb[i+1] ;
127  somn += 2 * sgn * tb[i+1] ;
128  xo[i] = somp - 2*i * somn ;
129  } // Fin de la premiere boucle sur r
130  for (int i=0 ; i<nr ; i+=2) {
131  xo[i] = -xo[i] ;
132  } // Fin de la deuxieme boucle sur r
133  xo[0] *= .5 ;
134 
135 }
136 
137 
138  //---------------
139  // cas R_CHEBI --
140  //---------------
141 
142 void _sx2_1d_r_chebi(int nr, double* tb, double *xo)
143 {
144  double somp, somn ;
145  int sgn = 1 ;
146 
147  xo[nr-1] = 0 ;
148  somp = 2 * sgn * (2*(nr-1)+1) * tb[nr-1] ;
149  somn = 2 * sgn * tb[nr-1] ;
150  xo[nr-2] = somp - (2*(nr-2)+1)*somn ;
151  for (int i = nr-3 ; i >= 0 ; i-- ) {
152  sgn = - sgn ;
153  somp += 2 * (2*(i+1)+1) * sgn * tb[i+1] ;
154  somn += 2 * sgn * tb[i+1] ;
155  xo[i] = somp - (2*i+1) * somn ;
156  } // Fin de la premiere boucle sur r
157  for (int i=0 ; i<nr ; i+=2) {
158  xo[i] = -xo[i] ;
159  } // Fin de la deuxieme boucle sur r
160 
161 }
162  //----------------
163  // cas R_CHEBU --
164  //---------------
165 
166 void _sxm12_1d_r_chebu(int nr, double* tb, double *xo) {
167 
168  // On appelle juste deux fois la routine existante :
169  sxm1_1d_cheb(nr, tb) ;
170  sxm1_1d_cheb(nr, tb) ;
171  for (int i=0 ; i<nr ; i++)
172  xo[i] = tb[i] ;
173 }
174 
175  //--------------
176  // cas R_LEGP --
177  //--------------
178 
179 void _sx2_1d_r_legp(int nr, double* tb, double *xo)
180 {
181  // On appelle juste deux fois la routine existante :
182  double* interm = new double[nr] ;
183  _sx_1d_r_legp(nr, tb, interm) ;
184  _sx_1d_r_legi(nr, interm, xo) ;
185  delete [] interm ;
186 
187 }
188 
189 
190  //--------------
191  // cas R_LEGI --
192  //--------------
193 
194 void _sx2_1d_r_legi(int nr, double* tb, double *xo)
195 {
196  // On appelle juste deux fois la routine existante :
197  double* interm = new double[nr] ;
198  _sx_1d_r_legi(nr, tb, interm) ;
199  _sx_1d_r_legp(nr, interm, xo) ;
200  delete [] interm ;
201 }
202 
203  //----------------------
204  // La routine a appeler
205  //----------------------
206 
207 void sx2_1d(int nr, double **tb, int base_r) // Version appliquee a this
208 {
209 
210 // Routines de derivation
211 static void (*sx2_1d[MAX_BASE])(int, double *, double*) ;
212 static int nap = 0 ;
213 
214  // Premier appel
215  if (nap==0) {
216  nap = 1 ;
217  for (int i=0 ; i<MAX_BASE ; i++) {
218  sx2_1d[i] = _sx2_1d_pas_prevu ;
219  }
220  // Les routines existantes
221  sx2_1d[R_CHEB >> TRA_R] = _sx2_1d_identite ;
222  sx2_1d[R_CHEBP >> TRA_R] = _sx2_1d_r_chebp ;
223  sx2_1d[R_CHEBI >> TRA_R] = _sx2_1d_r_chebi ;
224  sx2_1d[R_LEG >> TRA_R] = _sx2_1d_identite ;
225  sx2_1d[R_LEGP >> TRA_R] = _sx2_1d_r_legp ;
226  sx2_1d[R_LEGI >> TRA_R] = _sx2_1d_r_legi ;
227  sx2_1d[R_CHEBU >> TRA_R] = _sxm12_1d_r_chebu ;
228  }
229 
230  double *result = new double[nr] ;
231  sx2_1d[base_r](nr, *tb, result) ;
232 
233  delete [] (*tb) ;
234  (*tb) = result ;
235 }
236 }
Lorene prototypes.
Definition: app_hor.h:67
#define R_LEGP
base de Legendre paire (rare) seulement
Definition: type_parite.h:184
#define R_LEGI
base de Legendre impaire (rare) seulement
Definition: type_parite.h:186
#define TRA_R
Translation en R, used for a bitwise shift (in hex)
Definition: type_parite.h:158
#define R_CHEBI
base de Cheb. impaire (rare) seulement
Definition: type_parite.h:170
#define R_CHEBP
base de Cheb. paire (rare) seulement
Definition: type_parite.h:168
#define R_CHEBU
base de Chebychev ordinaire (fin), dev. en 1/r
Definition: type_parite.h:180
#define MAX_BASE
Nombre max. de bases differentes.
Definition: type_parite.h:144
#define R_LEG
base de Legendre ordinaire (fin)
Definition: type_parite.h:182
#define R_CHEB
base de Chebychev ordinaire (fin)
Definition: type_parite.h:166