LORENE
cl_pvect_r.C
1/*
2 * Methods for linear combinations for Ope_pois_vect_r
3 *
4 * (see file ope_elementary.h for documentation).
5 *
6 */
7
8/*
9 * Copyright (c) 2004 Jerome Novak
10 *
11 * This file is part of LORENE.
12 *
13 * LORENE is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License version 2
15 * as published by the Free Software Foundation.
16 *
17 * LORENE is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with LORENE; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 */
27
28
29
30/*
31 * $Id: cl_pvect_r.C,v 1.4 2016/12/05 16:18:12 j_novak Exp $
32 * $Log: cl_pvect_r.C,v $
33 * Revision 1.4 2016/12/05 16:18:12 j_novak
34 * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
35 *
36 * Revision 1.3 2014/10/13 08:53:34 j_novak
37 * Lorene classes and functions now belong to the namespace Lorene.
38 *
39 * Revision 1.2 2014/10/06 15:16:13 j_novak
40 * Modified #include directives to use c++ syntax.
41 *
42 * Revision 1.1 2004/05/10 15:28:22 j_novak
43 * First version of functions for the solution of the r-component of the
44 * vector Poisson equation.
45 *
46 *
47 * $Header: /cvsroot/Lorene/C++/Source/Ope_elementary/Ope_pois_vect_r/cl_pvect_r.C,v 1.4 2016/12/05 16:18:12 j_novak Exp $
48 *
49 */
50
51//fichiers includes
52#include <cstdlib>
53
54#include "matrice.h"
55#include "type_parite.h"
56
57/* FONCTIONS FAISANT DES COMBINAISONS LINEAIRES DES LIGNES.
58 *
59 * Entree :
60 * La Matrice de l'operateur
61 * l : nbre quantique
62 * puis = puissance dans la ZEC
63 * La base de developpement en R
64 *
65 * Sortie :
66 * Renvoie la matrice apres Combinaison lineaire
67 *
68 */
69
70namespace Lorene {
71Matrice _cl_pvect_r_pas_prevu (const Matrice&, int, double, int) ;
72Matrice _cl_pvect_r_cheb (const Matrice&, int, double, int) ;
73Matrice _cl_pvect_r_chebi (const Matrice&, int, double, int) ;
74Matrice _cl_pvect_r_chebu (const Matrice&, int, double, int) ;
75Matrice _cl_pvect_r_chebp (const Matrice&, int, double, int) ;
76
77// Version Matrice --> Matrice
78Matrice _cl_pvect_r_pas_prevu (const Matrice &source, int l, double echelle, int puis) {
79 cout << "Combinaison lineaire pas prevu..." << endl ;
80 cout << "Source : " << source << endl ;
81 cout << "l : " << l << endl ;
82 cout << "dzpuis : " << puis << endl ;
83 cout << "Echelle : " << echelle << endl ;
84 abort() ;
85 exit(-1) ;
86 return source;
87}
88
89
90 //-------------------
91 //-- R_CHEB ------
92 //-------------------
93
94Matrice _cl_pvect_r_cheb (const Matrice &source, int l, double echelle, int) {
95 int n = source.get_dim(0) ;assert (n == source.get_dim(1)) ;
96
97
98 const int nmax = 100 ; // Nombre de Matrices stockees
99 static Matrice* tab[nmax] ; // les matrices calculees
100 static int nb_dejafait = 0 ; // nbre de matrices calculees
101 static int l_dejafait[nmax] ;
102 static int nr_dejafait[nmax] ;
103 static double vieux_echelle = 0 ;
104
105 // Si on a change l'echelle : on detruit tout :
106 if (vieux_echelle != echelle) {
107 for (int i=0 ; i<nb_dejafait ; i++) {
108 l_dejafait[i] = -1 ;
109 nr_dejafait[i] = -1 ;
110 delete tab[i] ;
111 }
112 nb_dejafait = 0 ;
113 vieux_echelle = echelle ;
114 }
115
116 int indice = -1 ;
117
118 // On determine si la matrice a deja ete calculee :
119 for (int conte=0 ; conte<nb_dejafait ; conte ++)
120 if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
121 indice = conte ;
122
123 // Calcul a faire :
124 if (indice == -1) {
125 if (nb_dejafait >= nmax) {
126 cout << "_cl_pvect_r_cheb : trop de matrices" << endl ;
127 abort() ;
128 exit (-1) ;
129 }
130
131 l_dejafait[nb_dejafait] = l ;
132 nr_dejafait[nb_dejafait] = n ;
133
134 Matrice barre(source) ;
135 int dirac = 1 ;
136 for (int i=0 ; i<n-2 ; i++) {
137 for (int j=i ; j<(n>(i+7)? i+7 : n) ; j++)
138 barre.set(i, j) = ((1+dirac)*source(i, j)-source(i+2, j))
139 /(i+1) ;
140 if (i==0) dirac = 0 ;
141 }
142
143 Matrice res(barre) ;
144 for (int i=0 ; i<n-4 ; i++)
145 for (int j=i ; j<(n>(i+5)? i+5 : n) ; j++)
146 res.set(i, j) = barre(i, j)-barre(i+2, j) ;
147 tab[nb_dejafait] = new Matrice(res) ;
148 nb_dejafait ++ ;
149 return res ;
150 }
151
152 // Cas ou le calcul a deja ete effectue :
153 else
154 return *tab[indice] ;
155}
156
157 //-------------------
158 //-- R_CHEBP -----
159 //-------------------
160
161
162Matrice _cl_pvect_r_chebp (const Matrice &source, int l, double, int) {
163
164 int n = source.get_dim(0) ;
165 assert (n == source.get_dim(1)) ;
166
167 const int nmax = 100 ; // Nombre de Matrices stockees
168 static Matrice* tab[nmax] ; // les matrices calculees
169 static int nb_dejafait = 0 ; // nbre de matrices calculees
170 static int l_dejafait[nmax] ;
171 static int nr_dejafait[nmax] ;
172
173 int indice = -1 ;
174
175 // On determine si la matrice a deja ete calculee :
176 for (int conte=0 ; conte<nb_dejafait ; conte ++)
177 if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
178 indice = conte ;
179
180 // Calcul a faire :
181 if (indice == -1) {
182 if (nb_dejafait >= nmax) {
183 cout << "_cl_pvect_r_chebp : trop de matrices" << endl ;
184 abort() ;
185 exit (-1) ;
186 }
187
188 l_dejafait[nb_dejafait] = l ;
189 nr_dejafait[nb_dejafait] = n ;
190
191 Matrice barre(source) ;
192
193 int dirac = 1 ;
194 for (int i=0 ; i<n-2 ; i++) {
195 for (int j=0 ; j<n ; j++)
196 barre.set(i, j) = (1+dirac)*source(i, j)-source(i+2, j) ;
197 if (i==0) dirac = 0 ;
198 }
199
200 Matrice tilde(barre) ;
201 for (int i=0 ; i<n-4 ; i++)
202 for (int j=0 ; j<n ; j++)
203 tilde.set(i, j) = barre(i, j)-barre(i+2, j) ;
204
205 Matrice res(tilde) ;
206 for (int i=0 ; i<n-4 ; i++)
207 for (int j=0 ; j<n ; j++)
208 res.set(i, j) = tilde(i, j)-tilde(i+1, j) ;
209 tab[nb_dejafait] = new Matrice(res) ;
210 nb_dejafait ++ ;
211 return res ;
212 }
213
214 // Cas ou le calcul a deja ete effectue :
215 else
216 return *tab[indice] ;
217}
218
219 //-------------------
220 //-- R_CHEBI -----
221 //-------------------
222
223
224Matrice _cl_pvect_r_chebi (const Matrice &source, int l, double, int) {
225 int n = source.get_dim(0) ;
226 assert (n == source.get_dim(1)) ;
227
228
229 const int nmax = 100 ; // Nombre de Matrices stockees
230 static Matrice* tab[nmax] ; // les matrices calculees
231 static int nb_dejafait = 0 ; // nbre de matrices calculees
232 static int l_dejafait[nmax] ;
233 static int nr_dejafait[nmax] ;
234
235 int indice = -1 ;
236
237 // On determine si la matrice a deja ete calculee :
238 for (int conte=0 ; conte<nb_dejafait ; conte ++)
239 if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
240 indice = conte ;
241
242 // Calcul a faire :
243 if (indice == -1) {
244 if (nb_dejafait >= nmax) {
245 cout << "_cl_pvect_r_chebi : trop de matrices" << endl ;
246 abort() ;
247 exit (-1) ;
248 }
249
250 l_dejafait[nb_dejafait] = l ;
251 nr_dejafait[nb_dejafait] = n ;
252
253 Matrice barre(source) ;
254
255 for (int i=0 ; i<n-2 ; i++)
256 for (int j=0 ; j<n ; j++)
257 barre.set(i, j) = source(i, j)-source(i+2, j) ;
258
259 Matrice tilde(barre) ;
260 for (int i=0 ; i<n-4 ; i++)
261 for (int j=0 ; j<n ; j++)
262 tilde.set(i, j) = barre(i, j)-barre(i+2, j) ;
263
264 Matrice res(tilde) ;
265 for (int i=0 ; i<n-4 ; i++)
266 for (int j=0 ; j<n ; j++)
267 res.set(i, j) = tilde(i, j)-tilde(i+1, j) ;
268 tab[nb_dejafait] = new Matrice(res) ;
269 nb_dejafait ++ ;
270 return res ;
271 }
272
273 // Cas ou le calcul a deja ete effectue :
274 else
275 return *tab[indice] ;
276}
277 //-------------------
278 //-- R_CHEBU -----
279 //-------------------
280
281Matrice _cl_pvect_r_chebu (const Matrice &source, int l, double, int puis) {
282 int n = source.get_dim(0) ;
283 assert (n == source.get_dim(1)) ;
284 if (puis != 4) {
285 cout << "_ope_pvect_r_mat_r_chebu : only the case dzpuis = 4 "
286 << '\n' << "is implemented! \n"
287 << "dzpuis = " << puis << endl ;
288 abort() ;
289 }
290
291 const int nmax = 200 ; // Nombre de Matrices stockees
292 static Matrice* tab[nmax] ; // les matrices calculees
293 static int nb_dejafait = 0 ; // nbre de matrices calculees
294 static int l_dejafait[nmax] ;
295 static int nr_dejafait[nmax] ;
296
297 int indice = -1 ;
298
299 // On determine si la matrice a deja ete calculee :
300 for (int conte=0 ; conte<nb_dejafait ; conte ++)
301 if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
302 indice = conte ;
303
304 // Calcul a faire :
305 if (indice == -1) {
306 if (nb_dejafait >= nmax) {
307 cout << "_cl_pvect_r_chebu_quatre : trop de matrices" << endl ;
308 abort() ;
309 exit (-1) ;
310 }
311
312 l_dejafait[nb_dejafait] = l ;
313 nr_dejafait[nb_dejafait] = n ;
314
315 Matrice barre(source) ;
316
317 int dirac = 1 ;
318 for (int i=0 ; i<n-2 ; i++) {
319 for (int j=0 ; j<n ; j++)
320 barre.set(i, j) = ((1+dirac)*source(i, j)-source(i+2, j)) ;
321 if (i==0) dirac = 0 ;
322 }
323
324 Matrice tilde(barre) ;
325 for (int i=0 ; i<n-4 ; i++)
326 for (int j=0 ; j<n ; j++)
327 tilde.set(i, j) = (barre(i, j)-barre(i+2, j)) ;
328
329 Matrice prime(tilde) ;
330 for (int i=0 ; i<n-4 ; i++)
331 for (int j=0 ; j<n ; j++)
332 prime.set(i, j) = (tilde(i, j)-tilde(i+1, j)) ;
333
334 Matrice res(prime) ;
335 for (int i=0 ; i<n-4 ; i++)
336 for (int j=0 ; j<n ; j++)
337 res.set(i, j) = (prime(i, j)-prime(i+2, j)) ;
338 tab[nb_dejafait] = new Matrice(res) ;
339 nb_dejafait ++ ;
340 return res ;
341 }
342
343 // Cas ou le calcul a deja ete effectue :
344 else
345 return *tab[indice] ;
346}
347
348
349 //-------------------------
350 //- La routine a appeler ---
351 //---------------------------
352
353Matrice cl_pvect_r(const Matrice &source, int l, double echelle,
354 int puis, int base_r) {
355
356 // Routines de derivation
357 static Matrice (*combinaison[MAX_BASE])(const Matrice &, int, double, int) ;
358 static int nap = 0 ;
359
360 // Premier appel
361 if (nap==0) {
362 nap = 1 ;
363 for (int i=0 ; i<MAX_BASE ; i++) {
364 combinaison[i] = _cl_pvect_r_pas_prevu ;
365 }
366 // Les routines existantes
367 combinaison[R_CHEB >> TRA_R] = _cl_pvect_r_cheb ;
368 combinaison[R_CHEBU >> TRA_R] = _cl_pvect_r_chebu ;
369 combinaison[R_CHEBP >> TRA_R] = _cl_pvect_r_chebp ;
370 combinaison[R_CHEBI >> TRA_R] = _cl_pvect_r_chebi ;
371 }
372
373 Matrice res(combinaison[base_r](source, l, echelle, puis)) ;
374 return res ;
375}
376
377}
Matrix handling.
Definition matrice.h:152
int get_dim(int i) const
Returns the dimension of the matrix.
Definition matrice.C:263
#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