00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 char ope_poisson_2d_mat_C[] = "$Header: /cvsroot/Lorene/C++/Source/Ope_elementary/Ope_poisson_2d/ope_poisson_2d_mat.C,v 1.1 2004/08/24 09:14:47 p_grandclement Exp $" ;
00022
00023
00024
00025
00026
00027
00028 #include <math.h>
00029 #include <stdlib.h>
00030
00031 #include "proto.h"
00032 #include "ope_elementary.h"
00033
00034
00035
00036
00037
00038 Matrice _poisson_2d_mat_pas_prevu(int, int, double, double, int) {
00039 cout << "laplacien pas prevu..." << endl ;
00040 abort() ;
00041 exit(-1) ;
00042 Matrice res(1, 1) ;
00043 return res;
00044 }
00045
00046
00047
00048
00049
00050
00051
00052 Matrice _poisson_2d_mat_r_chebp (int n, int l, double, double, int) {
00053
00054 const int nmax = 100 ;
00055 static Matrice* tab[nmax] ;
00056 static int nb_dejafait = 0 ;
00057 static int l_dejafait[nmax] ;
00058 static int nr_dejafait[nmax] ;
00059
00060 int indice = -1 ;
00061
00062
00063 for (int conte=0 ; conte<nb_dejafait ; conte ++)
00064 if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
00065 indice = conte ;
00066
00067
00068 if (indice == -1) {
00069 if (nb_dejafait >= nmax) {
00070 cout << "_poisson_2d_mat_r_chebp : trop de matrices" << endl ;
00071 abort() ;
00072 exit (-1) ;
00073 }
00074
00075
00076 l_dejafait[nb_dejafait] = l ;
00077 nr_dejafait[nb_dejafait] = n ;
00078
00079 Matrice dd(n, n) ;
00080 dd.set_etat_qcq() ;
00081 Matrice xd(n, n) ;
00082 xd.set_etat_qcq() ;
00083 Matrice xx(n, n) ;
00084 xx.set_etat_qcq() ;
00085
00086 double* vect = new double[n] ;
00087
00088 for (int i=0 ; i<n ; i++) {
00089 for (int j=0 ; j<n ; j++)
00090 vect[j] = 0 ;
00091 vect[i] = 1 ;
00092 d2sdx2_1d (n, &vect, R_CHEBP) ;
00093
00094 for (int j=0 ; j<n ; j++)
00095 dd.set(j, i) = vect[j] ;
00096 }
00097
00098 for (int i=0 ; i<n ; i++) {
00099 for (int j=0 ; j<n ; j++)
00100 vect[j] = 0 ;
00101 vect[i] = 1 ;
00102 sxdsdx_1d (n, &vect, R_CHEBP) ;
00103 for (int j=0 ; j<n ; j++)
00104 xd.set(j, i) = vect[j] ;
00105
00106 }
00107
00108 for (int i=0 ; i<n ; i++) {
00109 for (int j=0 ; j<n ; j++)
00110 vect[j] = 0 ;
00111 vect[i] = 1 ;
00112 sx2_1d (n, &vect, R_CHEBP) ;
00113 for (int j=0 ; j<n ; j++)
00114 xx.set(j, i) = vect[j] ;
00115 }
00116
00117 delete [] vect ;
00118
00119 Matrice res(n, n) ;
00120 res = dd+xd-l*l*xx ;
00121 tab[nb_dejafait] = new Matrice(res) ;
00122 nb_dejafait ++ ;
00123 return res ;
00124 }
00125
00126
00127 else
00128 return *tab[indice] ;
00129 }
00130
00131
00132
00133
00134
00135
00136
00137
00138 Matrice _poisson_2d_mat_r_chebi (int n, int l, double, double, int) {
00139
00140 const int nmax = 100 ;
00141 static Matrice* tab[nmax] ;
00142 static int nb_dejafait = 0 ;
00143 static int l_dejafait[nmax] ;
00144 static int nr_dejafait[nmax] ;
00145
00146 int indice = -1 ;
00147
00148
00149 for (int conte=0 ; conte<nb_dejafait ; conte ++)
00150 if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
00151 indice = conte ;
00152
00153
00154 if (indice == -1) {
00155 if (nb_dejafait >= nmax) {
00156 cout << "_poisson_2d_mat_r_chebi : trop de matrices" << endl ;
00157 abort() ;
00158 exit (-1) ;
00159 }
00160
00161
00162 l_dejafait[nb_dejafait] = l ;
00163 nr_dejafait[nb_dejafait] = n ;
00164
00165 Matrice dd(n, n) ;
00166 dd.set_etat_qcq() ;
00167 Matrice xd(n, n) ;
00168 xd.set_etat_qcq() ;
00169 Matrice xx(n, n) ;
00170 xx.set_etat_qcq() ;
00171
00172 double* vect = new double[n] ;
00173
00174 for (int i=0 ; i<n ; i++) {
00175 for (int j=0 ; j<n ; j++)
00176 vect[j] = 0 ;
00177 vect[i] = 1 ;
00178 d2sdx2_1d (n, &vect, R_CHEBI) ;
00179 for (int j=0 ; j<n ; j++)
00180 dd.set(j, i) = vect[j] ;
00181 }
00182
00183 for (int i=0 ; i<n ; i++) {
00184 for (int j=0 ; j<n ; j++)
00185 vect[j] = 0 ;
00186 vect[i] = 1 ;
00187 sxdsdx_1d (n, &vect, R_CHEBI) ;
00188 for (int j=0 ; j<n ; j++)
00189 xd.set(j, i) = vect[j] ;
00190 }
00191
00192 for (int i=0 ; i<n ; i++) {
00193 for (int j=0 ; j<n ; j++)
00194 vect[j] = 0 ;
00195 vect[i] = 1 ;
00196 sx2_1d (n, &vect, R_CHEBI) ;
00197 for (int j=0 ; j<n ; j++)
00198 xx.set(j, i) = vect[j] ;
00199 }
00200
00201 delete [] vect ;
00202
00203 Matrice res(n, n) ;
00204 res = dd+xd-l*l*xx ;
00205 tab[nb_dejafait] = new Matrice(res) ;
00206 nb_dejafait ++ ;
00207 return res ;
00208 }
00209
00210
00211 else
00212 return *tab[indice] ;
00213 }
00214
00215
00216
00217
00218
00219
00220
00221
00222 Matrice _poisson_2d_mat_r_chebu_deux(int,int) ;
00223 Matrice _poisson_2d_mat_r_chebu_trois(int,int) ;
00224 Matrice _poisson_2d_mat_r_chebu_quatre(int,int) ;
00225
00226 Matrice _poisson_2d_mat_r_chebu( int n, int l, double, double, int puis) {
00227 Matrice res(n, n) ;
00228 res.set_etat_qcq() ;
00229 switch (puis) {
00230 case 4 :
00231 res = _poisson_2d_mat_r_chebu_quatre (n, l) ;
00232 break ;
00233 case 3 :
00234 res = _poisson_2d_mat_r_chebu_trois (n, l) ;
00235 break ;
00236 case 2 :
00237 res = _poisson_2d_mat_r_chebu_deux (n, l) ;
00238 break ;
00239 default :
00240 abort() ;
00241 exit(-1) ;
00242 }
00243 return res ;
00244 }
00245
00246
00247 Matrice _poisson_2d_mat_r_chebu_quatre (int n, int l) {
00248
00249 const int nmax = 200 ;
00250 static Matrice* tab[nmax] ;
00251 static int nb_dejafait = 0 ;
00252 static int l_dejafait[nmax] ;
00253 static int nr_dejafait[nmax] ;
00254
00255 int indice = -1 ;
00256
00257
00258 for (int conte=0 ; conte<nb_dejafait ; conte ++)
00259 if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
00260 indice = conte ;
00261
00262
00263 if (indice == -1) {
00264 if (nb_dejafait >= nmax) {
00265 cout << "_poisson_2d_mat_r_chebu_quatre : trop de matrices" << endl ;
00266 abort() ;
00267 exit (-1) ;
00268 }
00269
00270
00271 l_dejafait[nb_dejafait] = l ;
00272 nr_dejafait[nb_dejafait] = n ;
00273
00274 Matrice dd(n, n) ;
00275 dd.set_etat_qcq() ;
00276 Matrice dx (n,n) ;
00277 dx.set_etat_qcq() ;
00278 Matrice xx(n, n) ;
00279 xx.set_etat_qcq() ;
00280
00281 double* vect = new double[n] ;
00282
00283 for (int i=0 ; i<n ; i++) {
00284 for (int j=0 ; j<n ; j++)
00285 vect[j] = 0 ;
00286 vect[i] = 1 ;
00287 d2sdx2_1d (n, &vect, R_CHEBU) ;
00288 for (int j=0 ; j<n ; j++)
00289 dd.set(j, i) = vect[j] ;
00290 }
00291
00292 for (int i=0 ; i<n ; i++) {
00293 for (int j=0 ; j<n ; j++)
00294 vect[j] = 0 ;
00295 vect[i] = 1 ;
00296 sxdsdx_1d (n, &vect, R_CHEBU) ;
00297 for (int j=0 ; j<n ; j++)
00298 dx.set(j, i) = vect[j] ;
00299 }
00300
00301 for (int i=0 ; i<n ; i++) {
00302 for (int j=0 ; j<n ; j++)
00303 vect[j] = 0 ;
00304 vect[i] = 1 ;
00305 sx2_1d (n, &vect, R_CHEBU) ;
00306 for (int j=0 ; j<n ; j++)
00307 xx.set(j, i) = vect[j] ;
00308 }
00309
00310 delete [] vect ;
00311
00312 Matrice res(n, n) ;
00313 res = dd+dx-l*l*xx ;
00314 tab[nb_dejafait] = new Matrice(res) ;
00315 nb_dejafait ++ ;
00316 return res ;
00317 }
00318
00319
00320 else
00321 return *tab[indice] ;
00322 }
00323
00324
00325 Matrice _poisson_2d_mat_r_chebu_trois (int n, int l) {
00326
00327 const int nmax = 200 ;
00328 static Matrice* tab[nmax] ;
00329 static int nb_dejafait = 0 ;
00330 static int l_dejafait[nmax] ;
00331 static int nr_dejafait[nmax] ;
00332
00333 int indice = -1 ;
00334
00335
00336 for (int conte=0 ; conte<nb_dejafait ; conte ++)
00337 if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
00338 indice = conte ;
00339
00340
00341 if (indice == -1) {
00342 if (nb_dejafait >= nmax) {
00343 cout << "_poisson_2d_mat_r_chebu_trois : trop de matrices" << endl ;
00344 abort() ;
00345 exit (-1) ;
00346 }
00347
00348
00349 l_dejafait[nb_dejafait] = l ;
00350 nr_dejafait[nb_dejafait] = n ;
00351
00352 Matrice dd(n, n) ;
00353 dd.set_etat_qcq() ;
00354 Matrice dx(n, n) ;
00355 dx.set_etat_qcq() ;
00356 Matrice xx(n, n) ;
00357 xx.set_etat_qcq() ;
00358
00359 double* vect = new double[n] ;
00360 double* auxi = new double[n] ;
00361
00362 for (int i=0 ; i<n ; i++) {
00363
00364 for (int j=0 ; j<n ; j++)
00365 vect[j] = 0 ;
00366 vect[i] = 1 ;
00367 d2sdx2_1d (n, &vect, R_CHEBU) ;
00368 mult_xm1_1d_cheb (n, vect, auxi) ;
00369 for (int j=0 ; j<n ; j++)
00370 dd.set(j, i) = auxi[j] ;
00371 }
00372
00373 for (int i=0 ; i<n ; i++) {
00374 for (int j=0 ; j<n ; j++)
00375 vect[j] = 0 ;
00376 vect[i] = 1 ;
00377 dsdx_1d (n, &vect, R_CHEBU) ;
00378 for (int j=0 ; j<n ; j++)
00379 dx.set(j, i) = vect[j] ;
00380 }
00381
00382
00383 for (int i=0 ; i<n ; i++) {
00384 for (int j=0 ; j<n ; j++)
00385 vect[j] = 0 ;
00386 vect[i] = 1 ;
00387 sxm1_1d_cheb (n, vect) ;
00388 for (int j=0 ; j<n ; j++)
00389 xx.set(j, i) = vect[j] ;
00390 }
00391
00392 delete [] vect ;
00393 delete [] auxi ;
00394
00395 Matrice res(n, n) ;
00396 res = dd+dx-l*l*xx ;
00397 tab[nb_dejafait] = new Matrice(res) ;
00398 nb_dejafait ++ ;
00399 return res ;
00400 }
00401
00402
00403 else
00404 return *tab[indice] ;
00405 }
00406
00407
00408
00409 Matrice _poisson_2d_mat_r_chebu_deux (int n, int l) {
00410
00411 const int nmax = 200 ;
00412 static Matrice* tab[nmax] ;
00413 static int nb_dejafait = 0 ;
00414 static int l_dejafait[nmax] ;
00415 static int nr_dejafait[nmax] ;
00416
00417 int indice = -1 ;
00418
00419
00420 for (int conte=0 ; conte<nb_dejafait ; conte ++)
00421 if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
00422 indice = conte ;
00423
00424
00425 if (indice == -1) {
00426 if (nb_dejafait >= nmax) {
00427 cout << "_poisson_2d_mat_r_chebu_deux : trop de matrices" << endl ;
00428 abort() ;
00429 exit (-1) ;
00430 }
00431
00432
00433 l_dejafait[nb_dejafait] = l ;
00434 nr_dejafait[nb_dejafait] = n ;
00435
00436 Matrice dx (n,n) ;
00437 dx.set_etat_qcq() ;
00438 Matrice res(n, n) ;
00439 res.set_etat_qcq() ;
00440
00441
00442 double* vect = new double[n] ;
00443
00444 double* x2vect = new double[n] ;
00445
00446 for (int i=0 ; i<n ; i++) {
00447 for (int j=0 ; j<n ; j++)
00448 vect[j] = 0 ;
00449 vect[i] = 1 ;
00450 d2sdx2_1d (n, &vect, R_CHEBU) ;
00451 mult2_xm1_1d_cheb (n, vect, x2vect) ;
00452 for (int j=0 ; j<n ; j++)
00453 res.set(j, i) = x2vect[j] ;
00454 }
00455
00456 for (int i=0 ; i<n ; i++) {
00457 for (int j=0 ; j<n ; j++)
00458 vect[j] = 0 ;
00459 vect[i] = 1 ;
00460 dsdx_1d (n, &vect, R_CHEBU) ;
00461 mult_xm1_1d_cheb (n, vect, x2vect) ;
00462 for (int j=0 ; j<n ; j++)
00463 dx.set(j, i) = x2vect[j] ;
00464 }
00465
00466 delete [] vect ;
00467 delete [] x2vect ;
00468
00469 res = res + dx ;
00470
00471 for (int i=0 ; i<n ; i++)
00472 res.set(i, i) -= l*l ;
00473
00474 tab[nb_dejafait] = new Matrice(res) ;
00475 nb_dejafait ++ ;
00476 return res ;
00477 }
00478
00479
00480 else
00481 return *tab[indice] ;
00482 }
00483
00484
00485
00486
00487
00488
00489 Matrice _poisson_2d_mat_r_cheb (int n, int l, double alf, double bet, int) {
00490
00491 double echelle = bet / alf ;
00492
00493 const int nmax = 200 ;
00494 static Matrice* tab[nmax] ;
00495 static int nb_dejafait = 0 ;
00496 static int l_dejafait[nmax] ;
00497 static int nr_dejafait[nmax] ;
00498 static double vieux_echelle = 0;
00499
00500
00501 if (vieux_echelle != echelle) {
00502 for (int i=0 ; i<nb_dejafait ; i++) {
00503 l_dejafait[i] = -1 ;
00504 nr_dejafait[i] = -1 ;
00505 delete tab[i] ;
00506 }
00507
00508 nb_dejafait = 0 ;
00509 vieux_echelle = echelle ;
00510 }
00511
00512 int indice = -1 ;
00513
00514
00515 for (int conte=0 ; conte<nb_dejafait ; conte ++)
00516 if ((l_dejafait[conte] == l) && (nr_dejafait[conte] == n))
00517 indice = conte ;
00518
00519
00520 if (indice == -1) {
00521 if (nb_dejafait >= nmax) {
00522 cout << "_poisson_2d_mat_r_cheb : trop de matrices" << endl ;
00523 abort() ;
00524 exit (-1) ;
00525 }
00526
00527
00528 l_dejafait[nb_dejafait] = l ;
00529 nr_dejafait[nb_dejafait] = n ;
00530
00531 Matrice dd(n, n) ;
00532 dd.set_etat_qcq() ;
00533 Matrice xd(n, n) ;
00534 xd.set_etat_qcq() ;
00535 Matrice xx(n, n) ;
00536 xx.set_etat_qcq() ;
00537
00538 double* vect = new double[n] ;
00539
00540 for (int i=0 ; i<n ; i++) {
00541 for (int j=0 ; j<n ; j++)
00542 vect[j] = 0 ;
00543 vect[i] = 1 ;
00544 d2sdx2_1d (n, &vect, R_CHEB) ;
00545 for (int j=0 ; j<n ; j++)
00546 dd.set(j, i) = vect[j]*echelle*echelle ;
00547 }
00548
00549 for (int i=0 ; i<n ; i++) {
00550 for (int j=0 ; j<n ; j++)
00551 vect[j] = 0 ;
00552 vect[i] = 1 ;
00553 d2sdx2_1d (n, &vect, R_CHEB) ;
00554 multx_1d (n, &vect, R_CHEB) ;
00555 for (int j=0 ; j<(n>i+1 ? i+1 : n) ; j++)
00556 dd.set(j, i) += 2*echelle*vect[j] ;
00557 }
00558
00559 for (int i=0 ; i<n ; i++) {
00560 for (int j=0 ; j<n ; j++)
00561 vect[j] = 0 ;
00562 vect[i] = 1 ;
00563 d2sdx2_1d (n, &vect, R_CHEB) ;
00564 multx_1d (n, &vect, R_CHEB) ;
00565 multx_1d (n, &vect, R_CHEB) ;
00566 for (int j=0 ; j<(n>i+1 ? i+1 : n) ; j++)
00567 dd.set(j, i) += vect[j] ;
00568 }
00569
00570 for (int i=0 ; i<n ; i++) {
00571 for (int j=0 ; j<n ; j++)
00572 vect[j] = 0 ;
00573 vect[i] = 1 ;
00574 sxdsdx_1d (n, &vect, R_CHEB) ;
00575 for (int j=0 ; j<n ; j++)
00576 xd.set(j, i) = vect[j]*echelle ;
00577 }
00578
00579 for (int i=0 ; i<n ; i++) {
00580 for (int j=0 ; j<n ; j++)
00581 vect[j] = 0 ;
00582 vect[i] = 1 ;
00583 sxdsdx_1d (n, &vect, R_CHEB) ;
00584 multx_1d (n, &vect, R_CHEB) ;
00585 for (int j=0 ; j<(n>i+1 ? i+1 : n) ; j++)
00586 xd.set(j, i) += vect[j] ;
00587 }
00588
00589 for (int i=0 ; i<n ; i++) {
00590 for (int j=0 ; j<n ; j++)
00591 vect[j] = 0 ;
00592 vect[i] = 1 ;
00593 sx2_1d (n, &vect, R_CHEB) ;
00594 for (int j=0 ; j<n ; j++)
00595 xx.set(j, i) = vect[j] ;
00596 }
00597
00598 delete [] vect ;
00599
00600 Matrice res(n, n) ;
00601 res = dd+xd-l*l*xx ;
00602 tab[nb_dejafait] = new Matrice(res) ;
00603 nb_dejafait ++ ;
00604 return res ;
00605 }
00606
00607
00608 else
00609 return *tab[indice] ;
00610 }
00611
00612
00613 void Ope_poisson_2d::do_ope_mat() const {
00614 if (ope_mat != 0x0)
00615 delete ope_mat ;
00616
00617
00618 static Matrice (*poisson_2d_mat[MAX_BASE])(int, int, double, double, int);
00619 static int nap = 0 ;
00620
00621
00622 if (nap==0) {
00623 nap = 1 ;
00624 for (int i=0 ; i<MAX_BASE ; i++) {
00625 poisson_2d_mat[i] = _poisson_2d_mat_pas_prevu ;
00626 }
00627
00628 poisson_2d_mat[R_CHEB >> TRA_R] = _poisson_2d_mat_r_cheb ;
00629 poisson_2d_mat[R_CHEBP >> TRA_R] = _poisson_2d_mat_r_chebp ;
00630 poisson_2d_mat[R_CHEBI >> TRA_R] = _poisson_2d_mat_r_chebi ;
00631 poisson_2d_mat[R_CHEBU >> TRA_R] = _poisson_2d_mat_r_chebu ;
00632 }
00633 ope_mat = new Matrice(poisson_2d_mat[base_r](nr, l_quant, alpha, beta, dzpuis)) ;
00634 }