LORENE
cl_ptens_rr.C
1 /*
2  * Methods for linear combinations for Ope_pois_tens_rr
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_ptens_rr.C,v 1.4 2016/12/05 16:18:12 j_novak Exp $
32  * $Log: cl_ptens_rr.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/12/23 16:30:15 j_novak
43  * New files and class for the solution of the rr component of the tensor Poisson
44  * equation.
45  *
46  *
47  *
48  * $Header: /cvsroot/Lorene/C++/Source/Ope_elementary/Ope_pois_vect_r/cl_ptens_rr.C,v 1.4 2016/12/05 16:18:12 j_novak Exp $
49  *
50  */
51 
52 //fichiers includes
53 #include <cstdlib>
54 
55 #include "matrice.h"
56 #include "type_parite.h"
57 
58 /* FONCTIONS FAISANT DES COMBINAISONS LINEAIRES DES LIGNES.
59  *
60  * Entree :
61  * La Matrice de l'operateur
62  * l : nbre quantique
63  * puis = puissance dans la ZEC
64  * La base de developpement en R
65  *
66  * Sortie :
67  * Renvoie la matrice apres Combinaison lineaire
68  *
69  */
70 
71 namespace Lorene {
72 Matrice _cl_ptens_rr_pas_prevu (const Matrice&, int, double, int) ;
73 Matrice _cl_ptens_rr_cheb (const Matrice&, int, double, int) ;
74 Matrice _cl_ptens_rr_chebi (const Matrice&, int, double, int) ;
75 Matrice _cl_ptens_rr_chebu (const Matrice&, int, double, int) ;
76 Matrice _cl_ptens_rr_chebp (const Matrice&, int, double, int) ;
77 
78 // Version Matrice --> Matrice
79 Matrice _cl_ptens_rr_pas_prevu (const Matrice &source, int l, double echelle, int puis) {
80  cout << "Combinaison lineaire pas prevu..." << endl ;
81  cout << "Source : " << source << endl ;
82  cout << "l : " << l << endl ;
83  cout << "dzpuis : " << puis << endl ;
84  cout << "Echelle : " << echelle << endl ;
85  abort() ;
86  exit(-1) ;
87  return source;
88 }
89 
90 
91  //-------------------
92  //-- R_CHEB ------
93  //-------------------
94 
95 Matrice _cl_ptens_rr_cheb (const Matrice &source, int l, double echelle, int) {
96  int n = source.get_dim(0) ;assert (n == source.get_dim(1)) ;
97 
98 
99  const int nmax = 100 ; // Nombre de Matrices stockees
100  static Matrice* tab[nmax] ; // les matrices calculees
101  static int nb_dejafait = 0 ; // nbre de matrices calculees
102  static int l_dejafait[nmax] ;
103  static int nr_dejafait[nmax] ;
104  static double vieux_echelle = 0 ;
105 
106  // Si on a change l'echelle : on detruit tout :
107  if (vieux_echelle != echelle) {
108  for (int i=0 ; i<nb_dejafait ; i++) {
109  l_dejafait[i] = -1 ;
110  nr_dejafait[i] = -1 ;
111  delete tab[i] ;
112  }
113  nb_dejafait = 0 ;
114  vieux_echelle = echelle ;
115  }
116 
117  int indice = -1 ;
118 
119  // On determine si la matrice a deja ete calculee :
120  for (int conte=0 ; conte<nb_dejafait ; conte ++)
121  if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
122  indice = conte ;
123 
124  // Calcul a faire :
125  if (indice == -1) {
126  if (nb_dejafait >= nmax) {
127  cout << "_cl_ptens_rr_cheb : trop de matrices" << endl ;
128  abort() ;
129  exit (-1) ;
130  }
131 
132  l_dejafait[nb_dejafait] = l ;
133  nr_dejafait[nb_dejafait] = n ;
134 
135  Matrice barre(source) ;
136  int dirac = 1 ;
137  for (int i=0 ; i<n-2 ; i++) {
138  for (int j=i ; j<(n>(i+7)? i+7 : n) ; j++)
139  barre.set(i, j) = ((1+dirac)*source(i, j)-source(i+2, j))
140  /(i+1) ;
141  if (i==0) dirac = 0 ;
142  }
143 
144  Matrice res(barre) ;
145  for (int i=0 ; i<n-4 ; i++)
146  for (int j=i ; j<(n>(i+5)? i+5 : n) ; j++)
147  res.set(i, j) = barre(i, j)-barre(i+2, j) ;
148  tab[nb_dejafait] = new Matrice(res) ;
149  nb_dejafait ++ ;
150  return res ;
151  }
152 
153  // Cas ou le calcul a deja ete effectue :
154  else
155  return *tab[indice] ;
156 }
157 
158  //-------------------
159  //-- R_CHEBP -----
160  //-------------------
161 
162 
163 Matrice _cl_ptens_rr_chebp (const Matrice &source, int l, double, int) {
164 
165  int n = source.get_dim(0) ;
166  assert (n == source.get_dim(1)) ;
167 
168  const int nmax = 100 ; // Nombre de Matrices stockees
169  static Matrice* tab[nmax] ; // les matrices calculees
170  static int nb_dejafait = 0 ; // nbre de matrices calculees
171  static int l_dejafait[nmax] ;
172  static int nr_dejafait[nmax] ;
173 
174  int indice = -1 ;
175 
176  // On determine si la matrice a deja ete calculee :
177  for (int conte=0 ; conte<nb_dejafait ; conte ++)
178  if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
179  indice = conte ;
180 
181  // Calcul a faire :
182  if (indice == -1) {
183  if (nb_dejafait >= nmax) {
184  cout << "_cl_ptens_rr_chebp : trop de matrices" << endl ;
185  abort() ;
186  exit (-1) ;
187  }
188 
189  l_dejafait[nb_dejafait] = l ;
190  nr_dejafait[nb_dejafait] = n ;
191 
192  Matrice barre(source) ;
193 
194  int dirac = 1 ;
195  for (int i=0 ; i<n-2 ; i++) {
196  for (int j=0 ; j<n ; j++)
197  barre.set(i, j) = (1+dirac)*source(i, j)-source(i+2, j) ;
198  if (i==0) dirac = 0 ;
199  }
200 
201  Matrice tilde(barre) ;
202  for (int i=0 ; i<n-4 ; i++)
203  for (int j=0 ; j<n ; j++)
204  tilde.set(i, j) = barre(i, j)-barre(i+2, j) ;
205 
206  Matrice res(tilde) ;
207  for (int i=0 ; i<n-4 ; i++)
208  for (int j=0 ; j<n ; j++)
209  res.set(i, j) = tilde(i, j)-tilde(i+1, j) ;
210  tab[nb_dejafait] = new Matrice(res) ;
211  nb_dejafait ++ ;
212  return res ;
213  }
214 
215  // Cas ou le calcul a deja ete effectue :
216  else
217  return *tab[indice] ;
218 }
219 
220  //-------------------
221  //-- R_CHEBI -----
222  //-------------------
223 
224 
225 Matrice _cl_ptens_rr_chebi (const Matrice &source, int l, double, int) {
226  int n = source.get_dim(0) ;
227  assert (n == source.get_dim(1)) ;
228 
229 
230  const int nmax = 100 ; // Nombre de Matrices stockees
231  static Matrice* tab[nmax] ; // les matrices calculees
232  static int nb_dejafait = 0 ; // nbre de matrices calculees
233  static int l_dejafait[nmax] ;
234  static int nr_dejafait[nmax] ;
235 
236  int indice = -1 ;
237 
238  // On determine si la matrice a deja ete calculee :
239  for (int conte=0 ; conte<nb_dejafait ; conte ++)
240  if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
241  indice = conte ;
242 
243  // Calcul a faire :
244  if (indice == -1) {
245  if (nb_dejafait >= nmax) {
246  cout << "_cl_ptens_rr_chebi : trop de matrices" << endl ;
247  abort() ;
248  exit (-1) ;
249  }
250 
251  l_dejafait[nb_dejafait] = l ;
252  nr_dejafait[nb_dejafait] = n ;
253 
254  Matrice barre(source) ;
255 
256  for (int i=0 ; i<n-2 ; i++)
257  for (int j=0 ; j<n ; j++)
258  barre.set(i, j) = source(i, j)-source(i+2, j) ;
259 
260  Matrice tilde(barre) ;
261  for (int i=0 ; i<n-4 ; i++)
262  for (int j=0 ; j<n ; j++)
263  tilde.set(i, j) = barre(i, j)-barre(i+2, j) ;
264 
265  Matrice res(tilde) ;
266  for (int i=0 ; i<n-4 ; i++)
267  for (int j=0 ; j<n ; j++)
268  res.set(i, j) = tilde(i, j)-tilde(i+1, j) ;
269  tab[nb_dejafait] = new Matrice(res) ;
270  nb_dejafait ++ ;
271  return res ;
272  }
273 
274  // Cas ou le calcul a deja ete effectue :
275  else
276  return *tab[indice] ;
277 }
278  //-------------------
279  //-- R_CHEBU -----
280  //-------------------
281 
282 Matrice _cl_ptens_rr_chebu (const Matrice &source, int l, double, int puis) {
283  int n = source.get_dim(0) ;
284  assert (n == source.get_dim(1)) ;
285  if (puis != 4) {
286  cout << "_ope_ptens_rr_mat_r_chebu : only the case dzpuis = 4 "
287  << '\n' << "is implemented! \n"
288  << "dzpuis = " << puis << endl ;
289  abort() ;
290  }
291 
292  const int nmax = 200 ; // Nombre de Matrices stockees
293  static Matrice* tab[nmax] ; // les matrices calculees
294  static int nb_dejafait = 0 ; // nbre de matrices calculees
295  static int l_dejafait[nmax] ;
296  static int nr_dejafait[nmax] ;
297 
298  int indice = -1 ;
299 
300  // On determine si la matrice a deja ete calculee :
301  for (int conte=0 ; conte<nb_dejafait ; conte ++)
302  if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
303  indice = conte ;
304 
305  // Calcul a faire :
306  if (indice == -1) {
307  if (nb_dejafait >= nmax) {
308  cout << "_cl_ptens_rr_chebu_quatre : trop de matrices" << endl ;
309  abort() ;
310  exit (-1) ;
311  }
312 
313  l_dejafait[nb_dejafait] = l ;
314  nr_dejafait[nb_dejafait] = n ;
315 
316  Matrice barre(source) ;
317 
318  int dirac = 1 ;
319  for (int i=0 ; i<n-2 ; i++) {
320  for (int j=0 ; j<n ; j++)
321  barre.set(i, j) = ((1+dirac)*source(i, j)-source(i+2, j)) ;
322  if (i==0) dirac = 0 ;
323  }
324 
325  Matrice tilde(barre) ;
326  for (int i=0 ; i<n-4 ; i++)
327  for (int j=0 ; j<n ; j++)
328  tilde.set(i, j) = (barre(i, j)-barre(i+2, j)) ;
329 
330  Matrice prime(tilde) ;
331  for (int i=0 ; i<n-4 ; i++)
332  for (int j=0 ; j<n ; j++)
333  prime.set(i, j) = (tilde(i, j)-tilde(i+1, j)) ;
334 
335  Matrice res(prime) ;
336  for (int i=0 ; i<n-4 ; i++)
337  for (int j=0 ; j<n ; j++)
338  res.set(i, j) = (prime(i, j)-prime(i+2, j)) ;
339  tab[nb_dejafait] = new Matrice(res) ;
340  nb_dejafait ++ ;
341  return res ;
342  }
343 
344  // Cas ou le calcul a deja ete effectue :
345  else
346  return *tab[indice] ;
347 }
348 
349 
350  //-------------------------
351  //- La routine a appeler ---
352  //---------------------------
353 
354 Matrice cl_ptens_rr(const Matrice &source, int l, double echelle,
355  int puis, int base_r) {
356 
357  // Routines de derivation
358  static Matrice (*combinaison[MAX_BASE])(const Matrice &, int, double, int) ;
359  static int nap = 0 ;
360 
361  // Premier appel
362  if (nap==0) {
363  nap = 1 ;
364  for (int i=0 ; i<MAX_BASE ; i++) {
365  combinaison[i] = _cl_ptens_rr_pas_prevu ;
366  }
367  // Les routines existantes
368  combinaison[R_CHEB >> TRA_R] = _cl_ptens_rr_cheb ;
369  combinaison[R_CHEBU >> TRA_R] = _cl_ptens_rr_chebu ;
370  combinaison[R_CHEBP >> TRA_R] = _cl_ptens_rr_chebp ;
371  combinaison[R_CHEBI >> TRA_R] = _cl_ptens_rr_chebi ;
372  }
373 
374  Matrice res(combinaison[base_r](source, l, echelle, puis)) ;
375  return res ;
376 }
377 
378 }
Lorene prototypes.
Definition: app_hor.h:67
#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
int get_dim(int i) const
Returns the dimension of the matrix.
Definition: matrice.C:263
#define R_CHEBU
base de Chebychev ordinaire (fin), dev. en 1/r
Definition: type_parite.h:180
#define MAX_BASE
Nombre max. de bases differentes.
Definition: type_parite.h:144
#define R_CHEB
base de Chebychev ordinaire (fin)
Definition: type_parite.h:166