File: laplacien_mat.C

package info (click to toggle)
lorene 0.0.0~cvs20161116%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, stretch
  • size: 26,444 kB
  • ctags: 13,953
  • sloc: cpp: 212,946; fortran: 21,645; makefile: 1,750; sh: 4
file content (582 lines) | stat: -rw-r--r-- 15,482 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
/*
 *   Copyright (c) 1999-2001 Philippe Grandclement
 *
 *   This file is part of LORENE.
 *
 *   LORENE is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   LORENE is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with LORENE; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */


char laplacien_mat_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/PDE/laplacien_mat.C,v 1.11 2014/10/13 08:53:29 j_novak Exp $" ;

/*
 * $Id: laplacien_mat.C,v 1.11 2014/10/13 08:53:29 j_novak Exp $
 * $Log: laplacien_mat.C,v $
 * Revision 1.11  2014/10/13 08:53:29  j_novak
 * Lorene classes and functions now belong to the namespace Lorene.
 *
 * Revision 1.10  2014/10/06 15:16:08  j_novak
 * Modified #include directives to use c++ syntax.
 *
 * Revision 1.9  2007/12/11 15:28:22  jl_cornou
 * Jacobi(0,2) polynomials partially implemented
 *
 * Revision 1.8  2007/06/06 07:43:28  p_grandclement
 * nmax increased to 200
 *
 * Revision 1.7  2005/01/27 10:19:43  j_novak
 * Now using Diff operators to build the matrices.
 *
 * Revision 1.6  2004/10/05 15:44:21  j_novak
 * Minor speed enhancements.
 *
 * Revision 1.5  2004/02/06 10:53:54  j_novak
 * New dzpuis = 5 -> dzpuis = 3 case (not ready yet).
 *
 * Revision 1.4  2003/01/31 08:49:58  e_gourgoulhon
 * Increased the number nmax of stored matrices from 100 to 200.
 *
 * Revision 1.3  2002/10/16 14:37:11  j_novak
 * Reorganization of #include instructions of standard C++, in order to
 * use experimental version 3 of gcc.
 *
 * Revision 1.2  2002/10/09 12:47:32  j_novak
 * Execution speed improved
 *
 * Revision 1.1.1.1  2001/11/20 15:19:28  e_gourgoulhon
 * LORENE
 *
 * Revision 2.15  2000/05/22  13:36:33  phil
 * ajout du cas dzpuis == 3
 *
 * Revision 2.14  2000/01/04  19:00:09  phil
 * Double nmax
 *
 * Revision 2.13  1999/10/11  14:27:26  phil
 * & -> &&
 *
 * Revision 2.12  1999/09/30  09:17:11  phil
 * remplacement && en & et initialisation des variables statiques.
 *
 * Revision 2.11  1999/09/17  15:19:30  phil
 * correction de definition de nmax
 *
 * Revision 2.10  1999/09/03  14:07:15  phil
 * pas de modif
 *
 * Revision 2.9  1999/07/08  09:54:20  phil
 * *** empty log message ***
 *
 * Revision 2.8  1999/07/07  10:02:39  phil
 * Passage aux operateurs 1d
 *
 * Revision 2.7  1999/06/23  12:34:07  phil
 * ajout de dzpuis = 2
 *
 * Revision 2.6  1999/04/28  10:45:54  phil
 * augmentation de NMAX a 50
 *
 * Revision 2.5  1999/04/19  14:03:42  phil
 * *** empty log message ***
 *
 * Revision 2.4  1999/04/16  13:15:52  phil
 * *** empty log message ***
 *
 * Revision 2.3  1999/04/14  13:57:26  phil
 * Sauvegarde des Matrices deja calculees
 *
 * Revision 2.2  1999/04/13  13:58:30  phil
 * ajout proto.h
 *
 * Revision 2.1  1999/04/07  14:22:17  phil
 * *** empty log message ***
 *
 * Revision 2.0  1999/04/07  14:09:41  phil
 * *** empty log message ***
 *
 *
 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/PDE/laplacien_mat.C,v 1.11 2014/10/13 08:53:29 j_novak Exp $
 *
 */

//fichiers includes
#include <cstdio>
#include <cstdlib>

#include "diff.h"
#include "proto.h"

/*
 * Routine calculant l'operateur suivant :
 * 
 * -R_CHEB : r^2d2sdx2+2*rdsdx-l*(l+1)Id
 * 
 * -R_CHEBP et R_CHEBI : d2sdx2+2/r dsdx-l(l+1)/r^2
 * 	
 * -R_CHEBU : d2sdx2-l(l+1)/x^2
 * 
 * -R_JACO02 : d2sdx2 + 2/r dsdx - l(l+1)/r^2
 * 
 * Entree :
 *	-n nbre de points en r
	-l voire operateur.
	-echelle utile uniquement pour R_CHEB : represente beta/alpha 
						(cf mapping)
	
	- puis : exposant de multiplication dans la ZEC
	- base_r : base de developpement
	
    Sortie :
	La fonction renvoie la matrice.
	
 */
		//-----------------------------------
		// Routine pour les cas non prevus --
		//-----------------------------------

namespace Lorene {
Matrice _laplacien_mat_pas_prevu(int n, int l, double echelle, int puis) {
    cout << "laplacien pas prevu..." << endl ;
    cout << "n : " << n << endl ;
    cout << "l : " << l << endl ;
    cout << "puissance : " << puis << endl ;
    cout << "echelle : " << echelle << endl ;
    abort() ;
    exit(-1) ;
    Matrice res(1, 1) ;
    return res;
}


		   //-------------------------
		   //--   CAS R_JACO02   -----
		   //-------------------------
		    

Matrice _laplacien_mat_r_jaco02 (int n, int l, double, int) {
   
   const int nmax = 200 ;// Nombre de Matrices stockees
   static Matrice* tab[nmax] ;  // les matrices calculees
   static int nb_dejafait = 0 ; // nbre de matrices calculees
   static int l_dejafait[nmax] ;
   static int nr_dejafait[nmax] ;
    
   int indice = -1 ;
   
   // On determine si la matrice a deja ete calculee :
   for (int conte=0 ; conte<nb_dejafait ; conte ++)
    if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
	indice = conte ;
    
   // Calcul a faire : 
   if (indice  == -1) {
       if (nb_dejafait >= nmax) {
	   cout << "_laplacien_mat_r_jaco02 : trop de matrices" << endl ;
	   abort() ;
	   exit (-1) ;
       }
       

    l_dejafait[nb_dejafait] = l ;
    nr_dejafait[nb_dejafait] = n ;
    
    Diff_dsdx2 d2(R_JACO02, n) ;
    Diff_sxdsdx sxd(R_JACO02, n) ;
    Diff_sx2 sx2(R_JACO02, n) ;
    
    tab[nb_dejafait] = new Matrice(d2 + 2.*sxd -(l*(l+1))*sx2) ;

    indice = nb_dejafait ;
    nb_dejafait ++ ;	
   }
    
   return *tab[indice] ;
}


		   //-------------------------
		   //--   CAS R_CHEBP    -----
		   //--------------------------
		    

Matrice _laplacien_mat_r_chebp (int n, int l, double, int) {
   
   const int nmax = 200 ;// Nombre de Matrices stockees
   static Matrice* tab[nmax] ;  // les matrices calculees
   static int nb_dejafait = 0 ; // nbre de matrices calculees
   static int l_dejafait[nmax] ;
   static int nr_dejafait[nmax] ;
    
   int indice = -1 ;
   
   // On determine si la matrice a deja ete calculee :
   for (int conte=0 ; conte<nb_dejafait ; conte ++)
    if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
	indice = conte ;
    
   // Calcul a faire : 
   if (indice  == -1) {
       if (nb_dejafait >= nmax) {
	   cout << "_laplacien_mat_r_chebp : trop de matrices" << endl ;
	   abort() ;
	   exit (-1) ;
       }
       

    l_dejafait[nb_dejafait] = l ;
    nr_dejafait[nb_dejafait] = n ;
    
    Diff_dsdx2 d2(R_CHEBP, n) ;
    Diff_sxdsdx sxd(R_CHEBP, n) ;
    Diff_sx2 sx2(R_CHEBP, n) ;
    
    tab[nb_dejafait] = new Matrice(d2 + 2.*sxd -(l*(l+1))*sx2) ;

    indice = nb_dejafait ;
    nb_dejafait ++ ;	
   }
    
   return *tab[indice] ;
}



		   //------------------------
		   //--   CAS R_CHEBI    ----
		   //------------------------
		    

Matrice _laplacien_mat_r_chebi (int n, int l, double, int) {
   
   const int nmax = 200 ;// Nombre de Matrices stockees
   static Matrice* tab[nmax] ;  // les matrices calculees
   static int nb_dejafait = 0 ; // nbre de matrices calculees
   static int l_dejafait[nmax] ;
   static int nr_dejafait[nmax] ;
    
   int indice = -1 ;
   
   // On determine si la matrice a deja ete calculee :
   for (int conte=0 ; conte<nb_dejafait ; conte ++)
    if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
	indice = conte ;
    
   // Calcul a faire : 
   if (indice  == -1) {
       if (nb_dejafait >= nmax) {
	   cout << "_laplacien_mat_r_chebi : trop de matrices" << endl ;
	   abort() ;
	   exit (-1) ;
       }
       
	
    l_dejafait[nb_dejafait] = l ;
    nr_dejafait[nb_dejafait] = n ;
    
    Diff_dsdx2 d2(R_CHEBI, n) ;
    Diff_sxdsdx sxd(R_CHEBI, n) ;
    Diff_sx2 sx2(R_CHEBI, n) ;
    
    tab[nb_dejafait] = new Matrice(d2 + 2.*sxd - (l*(l+1))*sx2) ;
    indice = nb_dejafait ;
    nb_dejafait ++ ;
   } 
    
   return *tab[indice] ;
}




		   //-------------------------
		   //--   CAS R_CHEBU    -----
		   //-------------------------

Matrice _laplacien_mat_r_chebu( int n, int l, double, int puis) {
    Matrice res(n, n) ;
    res.set_etat_qcq() ;
    switch (puis) {
	case 4 :
	    res = _laplacien_mat_r_chebu_quatre (n, l) ;
	    break ;
	case 3 :
	    res = _laplacien_mat_r_chebu_trois (n, l) ;
	    break ;
	case 2 :
	    res = _laplacien_mat_r_chebu_deux (n, l) ;
	    break ;
	case 5 :
	    res = _laplacien_mat_r_chebu_cinq (n, l) ;
	    break ;
	default :
	    abort() ;
	    exit(-1) ;
    }
    return res ;
}
    
    // Cas ou dzpuis = 4
Matrice _laplacien_mat_r_chebu_quatre (int n, int l) {
        
   const int nmax = 200 ;// Nombre de Matrices stockees
   static Matrice* tab[nmax] ;  // les matrices calculees
   static int nb_dejafait = 0 ; // nbre de matrices calculees
   static int l_dejafait[nmax] ;
   static int nr_dejafait[nmax] ;
    
   int indice = -1 ;
   
   // On determine si la matrice a deja ete calculee :
   for (int conte=0 ; conte<nb_dejafait ; conte ++)
    if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
	indice = conte ;
    
   // Calcul a faire : 
   if (indice  == -1) {
       if (nb_dejafait >= nmax) {
	   cout << "_laplacien_mat_r_chebu_quatre : trop de matrices" << endl ;
	   abort() ;
	   exit (-1) ;
       }
       
    	
    l_dejafait[nb_dejafait] = l ;
    nr_dejafait[nb_dejafait] = n ;
    
    Diff_dsdx2 dd(R_CHEBU, n) ;
    Diff_sx2 xx(R_CHEBU, n) ;
    
    tab[nb_dejafait] = new Matrice(dd-(l*(l+1))*xx) ;
    indice = nb_dejafait ;
    nb_dejafait ++ ;
   } 
    
   return *tab[indice] ;
}

// Cas ou dzpuis =3 
Matrice _laplacien_mat_r_chebu_trois (int n, int l) {
        
   const int nmax = 200 ;// Nombre de Matrices stockees
   static Matrice* tab[nmax] ;  // les matrices calculees
   static int nb_dejafait = 0 ; // nbre de matrices calculees
   static int l_dejafait[nmax] ;
   static int nr_dejafait[nmax] ;
    
   int indice = -1 ;
   
   // On determine si la matrice a deja ete calculee :
   for (int conte=0 ; conte<nb_dejafait ; conte ++)
    if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
	indice = conte ;
    
   // Calcul a faire : 
   if (indice  == -1) {
       if (nb_dejafait >= nmax) {
	   cout << "_laplacien_mat_r_chebu_trois : trop de matrices" << endl ;
	   abort() ;
	   exit (-1) ;
       }
       
    	
    l_dejafait[nb_dejafait] = l ;
    nr_dejafait[nb_dejafait] = n ;
    
    Diff_xdsdx2 xd2(R_CHEBU, n) ;
    Diff_sx sx(R_CHEBU, n) ;

    tab[nb_dejafait] = new Matrice(xd2 -(l*(l+1))*sx) ;
    
    indice = nb_dejafait ;
    nb_dejafait ++ ;
   } 
    
   return *tab[indice] ;
}


    //Cas ou dzpuis = 2
Matrice _laplacien_mat_r_chebu_deux (int n, int l) {
        
   const int nmax = 200 ;// Nombre de Matrices stockees
   static Matrice* tab[nmax] ;  // les matrices calculees
   static int nb_dejafait = 0 ; // nbre de matrices calculees
   static int l_dejafait[nmax] ;
   static int nr_dejafait[nmax] ;
    
   int indice = -1 ;
   
   // On determine si la matrice a deja ete calculee :
   for (int conte=0 ; conte<nb_dejafait ; conte ++)
    if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
	indice = conte ;
    
   // Calcul a faire : 
   if (indice  == -1) {
       if (nb_dejafait >= nmax) {
	   cout << "_laplacien_mat_r_chebu_deux : trop de matrices" << endl ;
	   abort() ;
	   exit (-1) ;
       }
       
    	
    l_dejafait[nb_dejafait] = l ;
    nr_dejafait[nb_dejafait] = n ;

    Diff_x2dsdx2 x2dd(R_CHEBU, n) ;
    Diff_id id(R_CHEBU, n) ;
    
    tab[nb_dejafait] = new Matrice(x2dd - (l*(l+1))*id) ;
    
    indice = nb_dejafait ;
    nb_dejafait ++ ;
   } 

   return *tab[indice] ;
}

    //Cas ou dzpuis = 5
Matrice _laplacien_mat_r_chebu_cinq (int n, int l) {
        
   const int nmax = 200 ;// Nombre de Matrices stockees
   static Matrice* tab[nmax] ;  // les matrices calculees
   static int nb_dejafait = 0 ; // nbre de matrices calculees
   static int l_dejafait[nmax] ;
   static int nr_dejafait[nmax] ;
    
   int indice = -1 ;
   
   // On determine si la matrice a deja ete calculee :
   for (int conte=0 ; conte<nb_dejafait ; conte ++)
    if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
	indice = conte ;
    
   // Calcul a faire : 
   if (indice  == -1) {
       if (nb_dejafait >= nmax) {
	   cout << "_laplacien_mat_r_chebu_cinq : trop de matrices" << endl ;
	   abort() ;
	   exit (-1) ;
       }
       
    	
    l_dejafait[nb_dejafait] = l ;
    nr_dejafait[nb_dejafait] = n ;
    
    Diff_x2dsdx2 x2dd(R_CHEBU, n) ;
    Diff_xdsdx xd1(R_CHEBU, n) ;
    Diff_id id(R_CHEBU, n) ;

    tab[nb_dejafait] = new Matrice( x2dd + 6.*xd1 + (6-l*(l+1))*id ) ;

    indice = nb_dejafait ;
    nb_dejafait ++ ;
   } 
    
   return *tab[indice] ;
}

		   //-------------------------
		   //--   CAS R_CHEB    -----
		   //-----------------------
		    

Matrice _laplacien_mat_r_cheb (int n, int l, double echelle, int) {
            
   const int nmax = 200 ;// Nombre de Matrices stockees
   static Matrice* tab[nmax] ;  // les matrices calculees
   static int nb_dejafait = 0 ; // nbre de matrices calculees
   static int l_dejafait[nmax] ;
   static int nr_dejafait[nmax] ;
   static double vieux_echelle = 0;
   
   // Si on a change l'echelle : on detruit tout :
   if (vieux_echelle != echelle) {
       for (int i=0 ; i<nb_dejafait ; i++) {
	   l_dejafait[i] = -1 ;
	   nr_dejafait[i] = -1 ;
	   delete tab[i] ;
       }
       
       nb_dejafait = 0 ;
       vieux_echelle = echelle ;
   }
   
   int indice = -1 ;
   
   // On determine si la matrice a deja ete calculee :
   for (int conte=0 ; conte<nb_dejafait ; conte ++)
       if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
	   indice = conte ;
   
   // Calcul a faire : 
   if (indice  == -1) {
       if (nb_dejafait >= nmax) {
	   cout << "_laplacien_mat_r_cheb : trop de matrices" << endl ;
	   abort() ;
	   exit (-1) ;
       }
       
       
       l_dejafait[nb_dejafait] = l ;
       nr_dejafait[nb_dejafait] = n ;
       
       Diff_dsdx2 d2(R_CHEB, n) ;
       Diff_xdsdx2 xd2(R_CHEB, n) ;
       Diff_x2dsdx2 x2d2(R_CHEB, n) ;
       Diff_dsdx d1(R_CHEB, n) ;
       Diff_xdsdx xd1(R_CHEB, n) ;
       Diff_id id(R_CHEB, n) ;

       tab[nb_dejafait] = 
	   new Matrice(x2d2 + (2*echelle)*xd2 + (echelle*echelle)*d2
		       + 2*xd1 + (2*echelle)*d1 - (l*(l+1))*id) ;
    indice = nb_dejafait ;
    nb_dejafait ++ ;
   } 
   
   return *tab[indice] ;  
}


		 //--------------------------
		//- La routine a appeler  ---
	       //----------------------------
Matrice laplacien_mat(int n, int l, double echelle, int puis, int base_r)
{

		// Routines de derivation
    static Matrice (*laplacien_mat[MAX_BASE])(int, int, double, int) ;
    static int nap = 0 ;

		// Premier appel
    if (nap==0) {
	nap = 1 ;
	for (int i=0 ; i<MAX_BASE ; i++) {
	    laplacien_mat[i] = _laplacien_mat_pas_prevu ;
	}
		// Les routines existantes
	laplacien_mat[R_CHEB >> TRA_R] = _laplacien_mat_r_cheb ;
	laplacien_mat[R_CHEBU >> TRA_R] = _laplacien_mat_r_chebu ;
	laplacien_mat[R_CHEBP >> TRA_R] = _laplacien_mat_r_chebp ;
	laplacien_mat[R_CHEBI >> TRA_R] = _laplacien_mat_r_chebi ;
	laplacien_mat[R_JACO02 >> TRA_R] = _laplacien_mat_r_jaco02 ;
    }
    
    return laplacien_mat[base_r](n, l, echelle, puis) ;
}

}