LORENE
sx_1d.C
1/*
2 * Copyright (c) 2006 Jerome Novak
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: sx_1d.C,v 1.5 2016/12/05 16:18:09 j_novak Exp $
27 * $Log: sx_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 2015/03/05 08:49:32 j_novak
32 * Implemented operators with Legendre bases.
33 *
34 * Revision 1.3 2014/10/13 08:53:27 j_novak
35 * Lorene classes and functions now belong to the namespace Lorene.
36 *
37 * Revision 1.2 2014/10/06 15:16:07 j_novak
38 * Modified #include directives to use c++ syntax.
39 *
40 * Revision 1.1 2006/04/10 15:19:20 j_novak
41 * New definition of 1D operators dsdx and sx in the nucleus (bases R_CHEBP and
42 * R_CHEBI).
43 *
44 *
45 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Operators/sx_1d.C,v 1.5 2016/12/05 16:18:09 j_novak Exp $
46 *
47 */
48
49
50 // Includes
51#include <cstdlib>
52
53#include "headcpp.h"
54#include "type_parite.h"
55#include "proto.h"
56
57
58/*
59 * 1/x operator (division by x)
60 *
61 * Only for the bases R_CHEBP and R_CHEBI
62 *
63 * Input :
64 *
65 * int nr : number of coefficients
66 * tb : the array of coefficients of the input function
67 *
68 * Output :
69 * tb : the array of coefficients of the result
70 */
71
72
73 //----------------------------
74 // Bases not implemented -----
75 //----------------------------
76
77namespace Lorene {
78void _sx_1d_pas_prevu(int , double* , double *) {
79 cout << "sx_1d : base not implemented..." << endl ;
80 abort() ;
81 exit(-1) ;
82}
83
84
85 //-------------------
86 // case R_CHEBP ---
87 //-------------------
88
89void _sx_1d_r_chebp (int nr, double* tb, double* res) {
90
91 double som ;
92 int sign = 1 ;
93 res[nr-1] = 0 ;
94 som = 2 * sign * tb[nr-1] ;
95 res[nr-2] = som ;
96 for (int i=nr-3 ; i>=0 ; i--) {
97 sign = - sign ;
98 som += 2 * sign * tb[i+1] ;
99 res[i] = (i%2 == 0 ? -1 : 1) * som ;
100 }
101
102}
103
104
105 //-------------------
106 // case R_CHEBI ---
107 //-------------------
108
109void _sx_1d_r_chebi (int nr, double* tb, double* res) {
110
111 double som ;
112 int sign = 1 ;
113 res[nr-1] = 0 ;
114 som = 2 * sign * tb[nr-2] ;
115 res[nr-2] = som ;
116 for (int i=nr-3 ; i>=0 ; i--) {
117 sign = - sign ;
118 som += 2 * sign * tb[i] ;
119 res[i] = (i%2 == 0 ? -1 : 1) * som ;
120 }
121 res[0] *= 0.5 ;
122}
123
124 //-------------------
125 // case R_CHEBU ---
126 //-------------------
127
128void _sx_1d_r_chebu (int nr, double* tb, double* res) {
129
130 for (int i=0; i<nr; i++)
131 res[i] = tb[i] ;
132
133 sxm1_1d_cheb(nr, res) ;
134
135}
136
137 //------------------
138 // case R_LEGP ---
139 //------------------
140
141void _sx_1d_r_legp (int nr, double* tb, double* res) {
142
143 double term = 0 ;
144 res[nr-1] = 0 ;
145 for (int i=nr-2 ; i>=0 ; i--) {
146 term += tb[i+1] ;
147 res[i] = double(4*i+3)/double(2*i+2)*term ;
148 term *= -double(2*i+1)/double(2*i+2) ;
149 }
150
151}
152
153
154 //------------------
155 // case R_LEGI ---
156 //------------------
157
158void _sx_1d_r_legi (int nr, double* tb, double* res) {
159
160 double term = 0 ;
161 res[nr-1] = 0 ;
162 for (int i=nr-2; i>=0; i--) {
163 term += tb[i] ;
164 res[i] = double(4*i+1)/double(2*i+1)*term ;
165 term *= -double(2*i)/double(2*i+1) ;
166 }
167}
168
169
170
171 // ----------------------
172 // The calling function
173 //-----------------------
174
175void sx_1d(int nr, double **tb, int base_r)
176{
177
178 static void (*sx_1d[MAX_BASE])(int, double *, double *) ;
179 static int nap = 0 ;
180
181 // Premier appel
182 if (nap==0) {
183 nap = 1 ;
184 for (int i=0 ; i<MAX_BASE ; i++) {
185 sx_1d[i] = _sx_1d_pas_prevu ;
186 }
187 // Les routines existantes
188 sx_1d[R_CHEBP >> TRA_R] = _sx_1d_r_chebp ;
189 sx_1d[R_CHEBI >> TRA_R] = _sx_1d_r_chebi ;
190 sx_1d[R_LEGP >> TRA_R] = _sx_1d_r_legp ;
191 sx_1d[R_LEGI >> TRA_R] = _sx_1d_r_legi ;
192 sx_1d[R_CHEBU >> TRA_R] = _sx_1d_r_chebu ;
193 }
194
195
196 double *result = new double[nr] ;
197 sx_1d[base_r](nr, *tb, result) ;
198 delete [] (*tb) ;
199 (*tb) = result ;
200}
201
202}
#define R_LEGP
base de Legendre paire (rare) seulement
#define MAX_BASE
Nombre max. de bases differentes.
#define R_CHEBU
base de Chebychev ordinaire (fin), dev. en 1/r
#define R_LEGI
base de Legendre impaire (rare) seulement
#define R_CHEBI
base de Cheb. impaire (rare) seulement
#define TRA_R
Translation en R, used for a bitwise shift (in hex).
#define R_CHEBP
base de Cheb. paire (rare) seulement
Lorene prototypes.
Definition app_hor.h:67