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