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