LORENE
xdsdx_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 char xdsdx_1d_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Operators/xdsdx_1d.C,v 1.4 2014/10/13 08:53:27 j_novak Exp $" ;
24 
25 /*
26  * $Id: xdsdx_1d.C,v 1.4 2014/10/13 08:53:27 j_novak Exp $
27  * $Log: xdsdx_1d.C,v $
28  * Revision 1.4 2014/10/13 08:53:27 j_novak
29  * Lorene classes and functions now belong to the namespace Lorene.
30  *
31  * Revision 1.3 2014/10/06 15:16:07 j_novak
32  * Modified #include directives to use c++ syntax.
33  *
34  * Revision 1.2 2002/10/16 14:37:11 j_novak
35  * Reorganization of #include instructions of standard C++, in order to
36  * use experimental version 3 of gcc.
37  *
38  * Revision 1.1.1.1 2001/11/20 15:19:29 e_gourgoulhon
39  * LORENE
40  *
41  * Revision 2.0 1999/10/11 09:55:46 phil
42  * *** empty log message ***
43  *
44  *
45  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Operators/xdsdx_1d.C,v 1.4 2014/10/13 08:53:27 j_novak Exp $
46  *
47  */
48 
49  // Includes
50 #include <cstdlib>
51 
52 #include "headcpp.h"
53 #include "type_parite.h"
54 
55 
56 
57  //----------------------------------
58  // Routine pour les cas non prevus --
59  //----------------------------------
60 
61 namespace Lorene {
62 void _xdsdx_1d_pas_prevu(int nr, double* tb, double *xo) {
63  cout << "xdsdx pas prevu..." << endl ;
64  cout << "Nombre de points : " << nr << endl ;
65  cout << "Valeurs : " << tb << " " << xo <<endl ;
66  abort() ;
67  exit(-1) ;
68 }
69 
70 
71  //---------------
72  // cas R_CHEB ---
73  //---------------
74 
75 void _xdsdx_1d_r_cheb(int nr, double* tb, double *xo) {
76 
77  double somme = 0 ;
78  //Premiere boucle sur r :
79  for (int i=nr-1 ; i>= 0 ; i-=2) {
80  if (i==nr-1)
81  somme += i*tb[i] ;
82  else somme += i*tb[i]+(i+2)*tb[i+2] ;
83  xo[i] = somme ;
84  }
85 
86  //Seconde boucle sur r :
87  somme = 0 ;
88  for (int i=nr-2 ; i>=0 ; i-=2) {
89  if (i==nr-2)
90  somme += i*tb[i] ;
91  else
92  somme += i*tb[i]+(i+2)*tb[i+2] ;
93  xo[i] = somme ;
94  }
95  xo[0] *= .5 ;
96 }
97 
98  //-----------------
99  // cas R_CHEBP ---
100  //----------------
101 
102 void _xdsdx_1d_r_chebp(int nr, double* tb, double *xo) {
103 
104  double somme = 0 ;
105  for (int i=nr-1 ; i>=0 ; i--) {
106  if (i==nr-1)
107  somme += (2*i)*tb[i] ;
108  else
109  somme += (2*i)*tb[i]+(2*i+2)*tb[i+1] ;
110  xo[i] = somme ;
111  }
112 
113  xo[0] *= .5 ;
114 }
115 
116  //---------------
117  // cas R_CHEBI --
118  //---------------
119 
120 void _xdsdx_1d_r_chebi(int nr, double* tb, double *xo) {
121 
122  double somme = 0 ;
123  for (int i=nr-1 ; i>=0 ; i--) {
124  if (i==nr-1)
125  somme += (2*i+1)*tb[i] ;
126  else
127  somme += (2*i+1)*tb[i]+(2*i+3)*tb[i+1] ;
128  xo[i] = somme ;
129 
130  }
131 }
132 
133 
134  // ---------------------
135  // La routine a appeler
136  //----------------------
137 
138 
139 void xdsdx_1d(int nr, double** tb, int base_r)
140 {
141 
142  // Routines de derivation
143  static void (*xdsdx_1d[MAX_BASE])(int, double*, double *) ;
144  static int nap = 0 ;
145 
146  // Premier appel
147  if (nap==0) {
148  nap = 1 ;
149  for (int i=0 ; i<MAX_BASE ; i++) {
150  xdsdx_1d[i] = _xdsdx_1d_pas_prevu ;
151  }
152  // Les routines existantes
153  xdsdx_1d[R_CHEB >> TRA_R] = _xdsdx_1d_r_cheb ;
154  xdsdx_1d[R_CHEBP >> TRA_R] = _xdsdx_1d_r_chebp ;
155  xdsdx_1d[R_CHEBI >> TRA_R] = _xdsdx_1d_r_chebi ;
156  }
157 
158  double *result = new double[nr] ;
159 
160  xdsdx_1d[base_r](nr, *tb, result) ;
161 
162  delete [] (*tb) ;
163  (*tb) = result ;
164 }
165 }
R_CHEB
#define R_CHEB
base de Chebychev ordinaire (fin)
Definition: type_parite.h:166
Lorene
Lorene prototypes.
Definition: app_hor.h:64
R_CHEBP
#define R_CHEBP
base de Cheb. paire (rare) seulement
Definition: type_parite.h:168
R_CHEBI
#define R_CHEBI
base de Cheb. impaire (rare) seulement
Definition: type_parite.h:170
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