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