LORENE
prepa_ptens_rr.C
1/*
2 * Methods preparing the operators of Ope_pois_tens_rr for inversion.
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: prepa_ptens_rr.C,v 1.4 2016/12/05 16:18:12 j_novak Exp $
32 * $Log: prepa_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 * $Header: /cvsroot/Lorene/C++/Source/Ope_elementary/Ope_pois_vect_r/prepa_ptens_rr.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/*
58 * Fonctions supprimant le nombre de colonnes (les premieres)
59 et de lignes (les dernieres) a l'operateur renvoye par laplacien_mat, de facon
60 a ce qu'il ne soit plus degenere. Ceci doit etre fait apres les combinaisons
61 lineaires. La mise a bandes et la decomposition LU sont egalement effectuees ici
62
63
64 Entree : lap : resultat de laplacien_mat
65 l : associe a lap
66 puis : puissance dans la ZEC
67 base_r : base de developpement
68
69 Sortie : renvoie un operateur non degenere ....
70 */
71
72namespace Lorene {
73Matrice _nondeg_ptens_rr_pas_prevu(const Matrice &, int , double, int) ;
74Matrice _nondeg_ptens_rr_cheb (const Matrice&, int, double, int) ;
75Matrice _nondeg_ptens_rr_chebp (const Matrice&, int, double, int) ;
76Matrice _nondeg_ptens_rr_chebi (const Matrice&, int, double, int) ;
77Matrice _nondeg_ptens_rr_chebu (const Matrice&, int, double, int) ;
78
79
80 //------------------------------------
81 // Routine pour les cas non prevus --
82 //-----------------------------------
83
84Matrice _nondeg_ptens_rr_pas_prevu(const Matrice &lap, int l, double echelle, int puis) {
85 cout << "Construction non degeneree pas prevue..." << endl ;
86 cout << "l : " << l << endl ;
87 cout << "lap : " << lap << endl ;
88 cout << "echelle : " << echelle << endl ;
89 cout << " puis : " << puis << endl ;
90 abort() ;
91 exit(-1) ;
92 Matrice res(1, 1) ;
93 return res;
94}
95
96
97
98 //-------------------
99 //-- R_CHEB -------
100 //--------------------
101
102Matrice _nondeg_ptens_rr_cheb (const Matrice &lap, int l, double echelle, int) {
103
104
105 int n = lap.get_dim(0) ;
106
107 const int nmax = 200 ; // Nombre de Matrices stockees
108 static Matrice* tab[nmax] ; // les matrices calculees
109 static int nb_dejafait = 0 ; // nbre de matrices calculees
110 static int l_dejafait[nmax] ;
111 static int nr_dejafait[nmax] ;
112 static double vieux_echelle = 0;
113
114 // Si on a change l'echelle : on detruit tout :
115 if (vieux_echelle != echelle) {
116 for (int i=0 ; i<nb_dejafait ; i++) {
117 l_dejafait[i] = -1 ;
118 nr_dejafait[i] = -1 ;
119 delete tab[i] ;
120 }
121 vieux_echelle = echelle ;
122 nb_dejafait = 0 ;
123 }
124
125 int indice = -1 ;
126
127 // On determine si la matrice a deja ete calculee :
128 for (int conte=0 ; conte<nb_dejafait ; conte ++)
129 if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
130 indice = conte ;
131
132 // Calcul a faire :
133 if (indice == -1) {
134 if (nb_dejafait >= nmax) {
135 cout << "_nondeg_ptens_rr_cheb : trop de matrices" << endl ;
136 abort() ;
137 exit (-1) ;
138 }
139
140
141 l_dejafait[nb_dejafait] = l ;
142 nr_dejafait[nb_dejafait] = n ;
143
144
145 //assert (l<n) ;
146
147 Matrice res(n-2, n-2) ;
148 res.set_etat_qcq() ;
149 for (int i=0 ; i<n-2 ; i++)
150 for (int j=0 ; j<n-2 ; j++)
151 res.set(i, j) = lap(i, j+2) ;
152
153 res.set_band(2, 2) ;
154 res.set_lu() ;
155 tab[nb_dejafait] = new Matrice(res) ;
156 nb_dejafait ++ ;
157 return res ;
158 }
159
160 // Cas ou le calcul a deja ete effectue :
161 else
162 return *tab[indice] ;
163}
164
165
166
167
168 //------------------
169 //-- R_CHEBP ----
170 //------------------
171
172Matrice _nondeg_ptens_rr_chebp (const Matrice &lap, int l, double, int) {
173
174 int n = lap.get_dim(0) ;
175
176
177 const int nmax = 200 ; // Nombre de Matrices stockees
178 static Matrice* tab[nmax] ; // les matrices calculees
179 static int nb_dejafait = 0 ; // nbre de matrices calculees
180 static int l_dejafait[nmax] ;
181 static int nr_dejafait[nmax] ;
182
183 int indice = -1 ;
184
185 // On determine si la matrice a deja ete calculee :
186 for (int conte=0 ; conte<nb_dejafait ; conte ++)
187 if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
188 indice = conte ;
189
190 // Calcul a faire :
191 if (indice == -1) {
192 if (nb_dejafait >= nmax) {
193 cout << "_nondeg_ptens_rr_chebp : trop de matrices" << endl ;
194 abort() ;
195 exit (-1) ;
196 }
197
198
199 l_dejafait[nb_dejafait] = l ;
200 nr_dejafait[nb_dejafait] = n ;
201
202 assert (l%2 == 0) ;
203
204 if (l==2) {
205 Matrice res(n-1, n-1) ;
206 res.set_etat_qcq() ;
207 for (int i=0 ; i<n-1 ; i++)
208 for (int j=0 ; j<n-1 ; j++)
209 res.set(i, j) = lap(i, j+1) ;
210 res.set_band(3, 0) ;
211 res.set_lu() ;
212 tab[nb_dejafait] = new Matrice(res) ;
213 nb_dejafait ++ ;
214 return res ;
215 }
216 else {
217 Matrice res(n-2, n-2) ;
218 res.set_etat_qcq() ;
219 for (int i=0 ;i<n-2 ; i++)
220 for (int j=0 ; j<n-2 ; j++)
221 res.set(i, j) = lap(i, j+2) ;
222
223 res.set_band(2, 1) ;
224 res.set_lu() ;
225 tab[nb_dejafait] = new Matrice(res) ;
226 nb_dejafait ++ ;
227 return res ;
228 }
229 }
230 // Cas ou le calcul a deja ete effectue :
231 else
232 return *tab[indice] ;
233}
234
235
236
237
238 //-------------------
239 //-- R_CHEBI -----
240 //-------------------
241
242Matrice _nondeg_ptens_rr_chebi (const Matrice &lap, int l, double, int) {
243
244 int n = lap.get_dim(0) ;
245
246 const int nmax = 200 ; // Nombre de Matrices stockees
247 static Matrice* tab[nmax] ; // les matrices calculees
248 static int nb_dejafait = 0 ; // nbre de matrices calculees
249 static int l_dejafait[nmax] ;
250 static int nr_dejafait[nmax] ;
251
252 int indice = -1 ;
253
254 // On determine si la matrice a deja ete calculee :
255 for (int conte=0 ; conte<nb_dejafait ; conte ++)
256 if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
257 indice = conte ;
258
259 // Calcul a faire :
260 if (indice == -1) {
261 if (nb_dejafait >= nmax) {
262 cout << "_nondeg_ptens_rr_chebi : trop de matrices" << endl ;
263 abort() ;
264 exit (-1) ;
265 }
266
267
268 l_dejafait[nb_dejafait] = l ;
269 nr_dejafait[nb_dejafait] = n ;
270
271
272 assert (l%2 == 1) ;
273 // assert (l<=2*n-1) ;
274
275 Matrice res(n-2, n-2) ;
276 res.set_etat_qcq() ;
277 for (int i=0 ;i<n-2 ; i++)
278 for (int j=0 ; j<n-2 ; j++)
279 res.set(i, j) = lap(i, j+2) ;
280
281 res.set_band(2, 1) ;
282 res.set_lu() ;
283 tab[nb_dejafait] = new Matrice(res) ;
284 nb_dejafait ++ ;
285 return res ;
286 }
287 // Cas ou le calcul a deja ete effectue :
288 else
289 return *tab[indice] ;
290}
291
292
293
294
295 //-------------------
296 //-- R_CHEBU -----
297 //-------------------
298
299
300Matrice _nondeg_ptens_rr_chebu (const Matrice &lap, int l, double, int puis) {
301
302 if (puis != 4) {
303 cout << "_ope_ptens_rr_mat_r_chebu : only the case dzpuis = 4 "
304 << '\n' << "is implemented! \n"
305 << "dzpuis = " << puis << endl ;
306 abort() ;
307 }
308 int n = lap.get_dim(0) ;
309
310 const int nmax = 200; // Nombre de Matrices stockees
311 static Matrice* tab[nmax] ; // les matrices calculees
312 static int nb_dejafait = 0 ; // nbre de matrices calculees
313 static int l_dejafait[nmax] ;
314 static int nr_dejafait[nmax] ;
315
316 int indice = -1 ;
317
318 // On determine si la matrice a deja ete calculee :
319 for (int conte=0 ; conte<nb_dejafait ; conte ++)
320 if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
321 indice = conte ;
322
323 // Calcul a faire :
324 if (indice == -1) {
325 if (nb_dejafait >= nmax) {
326 cout << "_nondeg_ptens_rr_chebu : trop de matrices" << endl ;
327 abort() ;
328 exit (-1) ;
329 }
330
331 l_dejafait[nb_dejafait] = l ;
332 nr_dejafait[nb_dejafait] = n ;
333
334 Matrice res(n-3, n-3) ;
335 res.set_etat_qcq() ;
336 for (int i=0 ;i<n-3 ; i++)
337 for (int j=0 ; j<n-3 ; j++)
338 res.set(i, j) = lap(i, j+3) ;
339
340 res.set_band(2, 1) ;
341 res.set_lu() ;
342 tab[nb_dejafait] = new Matrice(res) ;
343 nb_dejafait ++ ;
344 return res ;
345
346 }
347 // Cas ou le calcul a deja ete effectue :
348 else
349 return *tab[indice] ;
350}
351
352
353 //-------------------
354 //-- Fonction ----
355 //-------------------
356
357
358Matrice nondeg_ptens_rr(const Matrice &lap, int l, double echelle, int puis, int base_r)
359{
360
361 // Routines de derivation
362 static Matrice (*nondeg_ptens_rr[MAX_BASE])(const Matrice&, int, double, int) ;
363 static int nap = 0 ;
364
365 // Premier appel
366 if (nap==0) {
367 nap = 1 ;
368 for (int i=0 ; i<MAX_BASE ; i++) {
369 nondeg_ptens_rr[i] = _nondeg_ptens_rr_pas_prevu ;
370 }
371 // Les routines existantes
372 nondeg_ptens_rr[R_CHEB >> TRA_R] = _nondeg_ptens_rr_cheb ;
373 nondeg_ptens_rr[R_CHEBU >> TRA_R] = _nondeg_ptens_rr_chebu ;
374 nondeg_ptens_rr[R_CHEBP >> TRA_R] = _nondeg_ptens_rr_chebp ;
375 nondeg_ptens_rr[R_CHEBI >> TRA_R] = _nondeg_ptens_rr_chebi ;
376 }
377 assert (l>=2) ;
378 Matrice res(nondeg_ptens_rr[base_r](lap, l, echelle, puis)) ;
379 return res ;
380}
381
382}
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