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