LORENE
multx2_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: multx2_1d.C,v 1.6 2016/12/05 16:18:07 j_novak Exp $
27  * $Log: multx2_1d.C,v $
28  * Revision 1.6 2016/12/05 16:18:07 j_novak
29  * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
30  *
31  * Revision 1.5 2015/03/05 08:49:32 j_novak
32  * Implemented operators with Legendre bases.
33  *
34  * Revision 1.4 2014/10/13 08:53:24 j_novak
35  * Lorene classes and functions now belong to the namespace Lorene.
36  *
37  * Revision 1.3 2014/10/06 15:16:06 j_novak
38  * Modified #include directives to use c++ syntax.
39  *
40  * Revision 1.2 2002/10/16 14:36:58 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.0 1999/10/11 09:53:08 phil
48  * *** empty log message ***
49  *
50  *
51  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Operators/multx2_1d.C,v 1.6 2016/12/05 16:18:07 j_novak Exp $
52  *
53  */
54 
55 // Includes
56 #include <cstdlib>
57 #include <cassert>
58 
59 #include "headcpp.h"
60 #include "type_parite.h"
61 #include "proto.h"
62 
63  //-----------------------------------
64  // Routine pour les cas non prevus --
65  //-----------------------------------
66 
67 namespace Lorene {
68 void _multx2_1d_pas_prevu(int nr, double* tb, double *res) {
69  cout << "multx2 pas prevu..." << tb << " " << res << endl ;
70  cout << "nr : " << nr << endl ;
71  abort() ;
72  exit(-1) ;
73 }
74 
75  //---------------
76  // cas R_CHEBP --
77  //---------------
78 
79 void _multx2_1d_r_chebp(int nr, double* tb, double *xo) {
80 
81  assert (nr>2) ;
82 
83  xo[0] = (2*tb[0]+tb[1])/4 ;
84  xo[1] = (2*tb[0]+2*tb[1]+tb[2])/4 ;
85 
86  for (int i=2 ; i<nr-1 ; i++)
87  xo[i] = (tb[i-1]+2*tb[i]+tb[i+1])/4 ;
88 
89  xo[nr-1] = (tb[nr-2]+2*tb[nr-1])/4 ;
90 }
91 
92 
93  //---------------
94  // cas R_CHEBI --
95  //---------------
96 
97 void _multx2_1d_r_chebi(int nr, double* tb, double *xo){
98 
99  assert(nr>2) ;
100 
101  xo[0] = (3*tb[0]+tb[1])/4 ;
102 
103  for (int i=1 ; i<nr-1 ; i++)
104  xo[i] = (tb[i-1]+2*tb[i]+tb[i+1])/4 ;
105 
106  xo[nr-1] = 0. ;//(tb[nr-2]+2*tb[nr-1])/4 ;
107 }
108 
109  //---------------
110  // cas R_CHEB --
111  //---------------
112 
113 void _multx2_1d_r_cheb(int nr, double* tb, double *xo){
114 
115  assert(nr>3) ;
116 
117  xo[0] = (2*tb[0]+tb[2])/4 ;
118  xo[1] = (3*tb[1]+tb[3])/4 ;
119  xo[2] = (2*tb[0]+2*tb[2]+tb[4])/4 ;
120 
121  for (int i=3 ; i<nr-2 ; i++)
122  xo[i] = (tb[i-2]+2*tb[i]+tb[i+2])/4 ;
123 
124  for (int i=nr-2 ; i<nr ; i++)
125  xo[i] = (tb[i-2]+2*tb[i])/4 ;
126 }
127 
128 
129  //--------------
130  // cas R_LEGP --
131  //--------------
132 
133 void _multx2_1d_r_legp(int nr, double* tb, double *xo) {
134 
135  assert (nr>2) ;
136 
137  xo[0] = tb[0]/3. + 2.*tb[1]/15. ;
138 
139  for (int i=1 ; i<nr-1 ; i++)
140  xo[i] = double(2*i*(2*i-1))*tb[i-1]/double((4*i-1)*(4*i-3))
141  + (double(4*i*i)/double((4*i-1)*(4*i+1))
142  + double((2*i+1)*(2*i+1))/double((4*i+1)*(4*i+3)))*tb[i]
143  + double((2*i+1)*(2*i+2))*tb[i+1]/double((4*i+3)*(4*i+5)) ;
144  xo[nr-1] = double((2*nr-2)*(2*nr-3))*tb[nr-2]/double((4*nr-5)*(4*nr-7))
145  + (double(4*(nr-1)*(nr-1))/double((4*nr-5)*(4*nr-3))
146  + double((2*nr-1)*(2*nr-1))/double((4*nr-3)*(4*nr-1)))*tb[nr-1] ;
147 }
148 
149 
150  //--------------
151  // cas R_LEGI --
152  //--------------
153 
154 void _multx2_1d_r_legi(int nr, double* tb, double *xo){
155 
156  assert(nr>2) ;
157 
158  xo[0] = 0.6*tb[0] + 6.*tb[1]/35. ;
159 
160  for (int i=1 ; i<nr-1 ; i++)
161  xo[i] = double(2*i*(2*i+1))*tb[i-1]/double((4*i+1)*(4*i-1))
162  + (double((2*i+1)*(2*i+1))/double((4*i+1)*(4*i+3))
163  + double((2*i+2)*(2*i+2))/double((4*i+3)*(4*i+5)) )*tb[i]
164  + double((2*i+2)*(2*i+3))*tb[i+1]/double((4*i+7)*(4*i+5)) ;
165  xo[nr-1] = 0. ;
166 }
167 
168  //-------------
169  // cas R_LEG --
170  //-------------
171 
172 void _multx2_1d_r_leg(int nr, double* tb, double *xo){
173 
174  assert(nr>3) ;
175 
176  xo[0] = tb[0]/3. + 2.*tb[2]/15. ;
177  xo[1] = 0.6*tb[1] + 6.*tb[3]/35. ;
178  for (int i=2 ; i<nr-2 ; i++)
179  xo[i] = double(i*(i-1))*tb[i-2]/double((2*i-1)*(2*i-3))
180  + (double(i*i)/double((2*i-1)*(2*i+1))
181  + double((i+1)*(i+1))/double((2*i+1)*(2*i+3)))*tb[i]
182  + double((i+1)*(i+2))*tb[i+2]/double((2*i+3)*(2*i+5)) ;
183  for (int i=nr-2 ; i<nr ; i++)
184  xo[i] = double(i*(i-1))*tb[i-2]/double((2*i-1)*(2*i-3))
185  + (double(i*i)/double((2*i-1)*(2*i+1))
186  + double((i+1)*(i+1))/double((2*i+1)*(2*i+3)))*tb[i] ;
187 }
188 
189 
190 
191 
192  //----------------------
193  // La routine a appeler
194  //----------------------
195 
196 void multx2_1d(int nr, double **tb, int base_r) // Version appliquee a this
197 {
198 
199 // Routines de derivation
200 static void (*multx2_1d[MAX_BASE])(int, double *, double*) ;
201 static int nap = 0 ;
202 
203  // Premier appel
204  if (nap==0) {
205  nap = 1 ;
206  for (int i=0 ; i<MAX_BASE ; i++) {
207  multx2_1d[i] = _multx2_1d_pas_prevu ;
208  }
209  // Les routines existantes
210  multx2_1d[R_CHEB >> TRA_R] = _multx2_1d_r_cheb ;
211  multx2_1d[R_CHEBP >> TRA_R] = _multx2_1d_r_chebp ;
212  multx2_1d[R_CHEBI >> TRA_R] = _multx2_1d_r_chebi ;
213  multx2_1d[R_LEG >> TRA_R] = _multx2_1d_r_leg ;
214  multx2_1d[R_LEGP >> TRA_R] = _multx2_1d_r_legp ;
215  multx2_1d[R_LEGI >> TRA_R] = _multx2_1d_r_legi ;
216  }
217 
218  double *result = new double[nr] ;
219  multx2_1d[base_r](nr, *tb, result) ;
220 
221  delete [] (*tb) ;
222  (*tb) = result ;
223 }
224 }
Lorene prototypes.
Definition: app_hor.h:67
#define R_LEGP
base de Legendre paire (rare) seulement
Definition: type_parite.h:184
#define R_LEGI
base de Legendre impaire (rare) seulement
Definition: type_parite.h:186
#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_LEG
base de Legendre ordinaire (fin)
Definition: type_parite.h:182
#define R_CHEB
base de Chebychev ordinaire (fin)
Definition: type_parite.h:166