00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 char map_radial_poisson_cpt_C[] = "$Header: /cvsroot/Lorene/C++/Source/Map/map_radial_poisson_cpt.C,v 1.5 2007/10/18 08:19:32 e_gourgoulhon Exp $" ;
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128 #include <stdlib.h>
00129 #include <math.h>
00130
00131
00132 #include "tenseur.h"
00133 #include "param.h"
00134 #include "proto.h"
00135 #include "graphique.h"
00136 #include "utilitaires.h"
00137
00138
00139 Mtbl_cf sol_poisson_compact(const Mtbl_cf&, double, double, bool) ;
00140 Mtbl_cf sol_poisson_compact(const Map_af&, const Mtbl_cf&, const Tbl&,
00141 const Tbl&, bool) ;
00142
00143
00145
00147
00148 void Map_radial::poisson_compact(const Cmp& source, const Cmp& aa,
00149 const Tenseur& bb, const Param& par,
00150 Cmp& psi) const {
00151
00152
00153
00154
00155
00156 assert(source.get_etat() != ETATNONDEF) ;
00157 assert(aa.get_etat() != ETATNONDEF) ;
00158 assert(bb.get_etat() != ETATNONDEF) ;
00159 assert(aa.get_mp() == source.get_mp()) ;
00160 assert(bb.get_mp() == source.get_mp()) ;
00161 assert(psi.get_mp() == source.get_mp()) ;
00162
00163
00164
00165
00166 assert(*(bb.get_triad()) == bvect_spher) ;
00167
00168
00169
00170 int nitermax = par.get_int() ;
00171 int& niter = par.get_int_mod() ;
00172 double precis = par.get_double(0) ;
00173 double relax = par.get_double(1) ;
00174 double unmrelax = 1. - relax ;
00175
00176
00177
00178
00179 if ( source.get_etat() == ETATZERO ) {
00180 psi.set_etat_zero() ;
00181 return ;
00182 }
00183
00184
00185
00186
00187
00188 Mtbl tmp = dxdr ;
00189 double dxdr_c = tmp(0, 0, 0, 0) ;
00190
00191 double alph = dxdr_c * dxdr_c * aa(0, 0, 0, 0) ;
00192
00193 const Valeur& b_r = bb(0).va ;
00194
00195 Valeur vatmp = dxdr*dxdr*b_r ;
00196
00197 double bet = min(vatmp)(0) ;
00198
00199 cout << "Map_radial::poisson_compact : alph, bet : " << alph << " "
00200 << bet << endl ;
00201
00202
00203
00204
00205
00206 int nz = mg->get_nzone() ;
00207
00208 psi.annule(1, nz-1) ;
00209
00210
00211
00212 Cmp psi_jm1 = psi ;
00213 Cmp b_grad_psi(this) ;
00214 Valeur sour_j(*mg) ;
00215 Valeur aux_psi(*mg) ;
00216 Valeur lap_xi_psi(*mg) ;
00217 Valeur oper_psi(*mg) ;
00218 Valeur dpsi(*mg) ;
00219 Valeur d2psi(*mg) ;
00220
00221 Valeur& vpsi = psi.va ;
00222
00223
00224
00225
00226
00227 Tbl tdiff(nz) ;
00228 double diff ;
00229 niter = 0 ;
00230
00231
00232 do {
00233
00234
00235
00236
00237 b_grad_psi = bb(0) % psi.dsdr() +
00238 bb(1) % psi.srdsdt() +
00239 bb(2) % psi.srstdsdp() ;
00240
00241
00242 vpsi.ylm() ;
00243
00244
00245
00246 dpsi = vpsi.dsdx() ;
00247 dpsi.ylm() ;
00248
00249
00250
00251
00252 aux_psi = 2.*dpsi + (vpsi.lapang()).sx() ;
00253
00254 d2psi = vpsi.d2sdx2() ;
00255 d2psi.ylm() ;
00256
00257 lap_xi_psi = d2psi + aux_psi.sx() ;
00258
00259
00260
00261 sour_j = source.va
00262 + alph * ( lap_xi_psi - (lap_xi_psi.mult_x()).mult_x() )
00263 - aa.va * (psi.laplacien()).va
00264 + bet * dpsi.mult_x()
00265 - b_grad_psi.va ;
00266
00267 sour_j.std_base_scal() ;
00268 sour_j.coef() ;
00269 sour_j.ylm() ;
00270
00271
00272
00273 double somlzero = 0 ;
00274 for (int i=0; i<mg->get_nr(0); i++) {
00275 somlzero += fabs( (*(sour_j.c_cf))(0, 0, 0, i) ) ;
00276 (sour_j.c_cf)->set(0, 0, 0, i) = 0 ;
00277 }
00278
00279 if (somlzero > 1.e-10) {
00280 cout << "### WARNING : Map_radial::poisson_compact : " << endl
00281 << " the l=0 part of the effective source is > 1.e-10 : "
00282 << somlzero << endl ;
00283 }
00284
00285
00286
00287
00288
00289
00290 bool reamorce = (niter == 0) ;
00291
00292 assert(sour_j.c_cf != 0x0) ;
00293
00294 psi.set_etat_zero() ;
00295 psi.set_etat_qcq() ;
00296 vpsi = sol_poisson_compact( *(sour_j.c_cf), alph, bet, reamorce ) ;
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374 aux_psi = vpsi.dsdx() ;
00375
00376 aux_psi = 2.*aux_psi + (vpsi.lapang()).sx() ;
00377
00378 lap_xi_psi = vpsi.d2sdx2() + aux_psi.sx() ;
00379
00380 oper_psi = alph * ( lap_xi_psi - (lap_xi_psi.mult_x()).mult_x() )
00381 + bet * (vpsi.dsdx()).mult_x() ;
00382
00383
00384 double maxc = fabs( max(*(vpsi.c_cf))(0) ) ;
00385 double minc = fabs( min(*(vpsi.c_cf))(0) ) ;
00386 double max_abs_psi = ( maxc > minc ) ? maxc : minc ;
00387
00388 maxc = fabs( max(*(sour_j.c_cf))(0) ) ;
00389 minc = fabs( min(*(sour_j.c_cf))(0) ) ;
00390 double max_abs_sou = ( maxc > minc ) ? maxc : minc ;
00391
00392 Mtbl_cf diff_opsou = *oper_psi.c_cf - *sour_j.c_cf ;
00393 maxc = fabs( max(diff_opsou)(0) ) ;
00394 minc = fabs( min(diff_opsou)(0) ) ;
00395 double max_abs_diff = ( maxc > minc ) ? maxc : minc ;
00396
00397
00398
00399
00400
00401 cout << " Step " << niter
00402 << " : test (1-xi^2) Lap_xi(psi) + b xi dpsi/dxi : " << endl ;
00403 cout << " max |psi| |sou| |oper(psi)-sou|: "
00404 << max_abs_psi << " " << max_abs_sou << " "
00405 << max_abs_diff << endl ;
00406
00407
00408
00409
00410 vpsi.ylm_i() ;
00411
00412 psi = relax * psi + unmrelax * psi_jm1 ;
00413
00414 tdiff = diffrel(psi, psi_jm1) ;
00415
00416 diff = max(tdiff) ;
00417
00418 cout <<
00419 " Relative difference psi^J <-> psi^{J-1} : "
00420 << tdiff(0) << endl ;
00421
00422
00423
00424
00425
00426
00427 psi_jm1 = psi ;
00428 niter++ ;
00429
00430 }
00431 while ( (diff > precis) && (niter < nitermax) ) ;
00432
00433
00434
00435
00436
00437 }
00438
00439
00440
00442
00444
00445
00446 void Map_radial::poisson_compact(int nzet, const Cmp& source, const Cmp& aa,
00447 const Tenseur& bb, const Param& par,
00448 Cmp& psi) const {
00449
00450 if (nzet == 1) {
00451 poisson_compact(source, aa, bb, par, psi) ;
00452 return ;
00453 }
00454
00455
00456
00457
00458
00459 assert(source.get_etat() != ETATNONDEF) ;
00460 assert(aa.get_etat() != ETATNONDEF) ;
00461 assert(bb.get_etat() != ETATNONDEF) ;
00462 assert(aa.get_mp() == source.get_mp()) ;
00463 assert(bb.get_mp() == source.get_mp()) ;
00464 assert(psi.get_mp() == source.get_mp()) ;
00465
00466
00467
00468
00469 assert(*(bb.get_triad()) == bvect_spher) ;
00470
00471
00472
00473
00474 if ( source.get_etat() == ETATZERO ) {
00475 psi.set_etat_zero() ;
00476 return ;
00477 }
00478
00479
00480
00481 int nitermax = par.get_int() ;
00482 int& niter = par.get_int_mod() ;
00483 double precis = par.get_double(0) ;
00484 double relax = par.get_double(1) ;
00485 double unmrelax = 1. - relax ;
00486
00487
00488 Map_af mpaff(*this) ;
00489
00490
00491
00492 Tbl ac(nzet,3) ;
00493 ac.annule_hard() ;
00494 Tbl bc(nzet,3) ;
00495 bc.annule_hard() ;
00496
00497 Valeur ap = aa.va ;
00498 Valeur bp = bb(0).va ;
00499
00500
00501 int nrm1 = mg->get_nr(0) - 1 ;
00502 ac.set(0,0) = ap(0,0,0,0) ;
00503 ac.set(0,2) = ap(0,0,0,nrm1) - ac(0,0) ;
00504
00505 bc.set(0,1) = bp(0,0,0,nrm1) ;
00506
00507
00508 for (int lz=1; lz<nzet-1; lz++) {
00509 nrm1 = mg->get_nr(lz) - 1 ;
00510 ac.set(lz,0) = 0.5 * ( ap(lz,0,0,nrm1) + ap(lz,0,0,0) ) ;
00511 ac.set(lz,1) = 0.5 * ( ap(lz,0,0,nrm1) - ap(lz,0,0,0) ) ;
00512
00513 bc.set(lz,0) = 0.5 * ( bp(lz,0,0,nrm1) + bp(lz,0,0,0) ) ;
00514 bc.set(lz,1) = 0.5 * ( bp(lz,0,0,nrm1) - bp(lz,0,0,0) ) ;
00515 }
00516
00517
00518 int lext = nzet - 1 ;
00519 nrm1 = mg->get_nr(lext) - 1 ;
00520 ac.set(lext,0) = 0.5 * ap(lext,0,0,0) ;
00521 ac.set(lext,1) = - ac(lext,0) ;
00522
00523 bc.set(lext,0) = 0.5 * ( bp(lext,0,0,nrm1) + bp(lext,0,0,0) ) ;
00524 bc.set(lext,1) = 0.5 * ( bp(lext,0,0,nrm1) - bp(lext,0,0,0) ) ;
00525
00526 cout << "ac : " << ac << endl ;
00527 cout << "bc : " << bc << endl ;
00528
00529
00530
00531
00532 Mtbl ta(mg) ;
00533 Mtbl tb(mg) ;
00534 ta.annule_hard() ;
00535 tb.annule_hard() ;
00536 for (int lz=0; lz<nzet; lz++) {
00537 const double* xi = mg->get_grille3d(lz)->x ;
00538 double* tta = ta.set(lz).t ;
00539 double* ttb = tb.set(lz).t ;
00540 int np = mg->get_np(lz) ;
00541 int nt = mg->get_nt(lz) ;
00542 int nr = mg->get_nr(lz) ;
00543 int pt = 0 ;
00544 for (int k=0; k<np; k++) {
00545 for (int j=0; j<nt; j++) {
00546 for (int i=0; i<nr; i++) {
00547 tta[pt] = ac(lz,0) + xi[i] * (ac(lz,1) + ac(lz,2) * xi[i]) ;
00548 ttb[pt] = bc(lz,0) + xi[i] * (bc(lz,1) + bc(lz,2) * xi[i]) ;
00549 pt++ ;
00550 }
00551 }
00552 }
00553 }
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576 int nz = mg->get_nzone() ;
00577
00578 psi.annule(nzet, nz-1) ;
00579
00580
00581
00582 Cmp psi_jm1 = psi ;
00583 Cmp b_grad_psi(this) ;
00584 Valeur sour_j(*mg) ;
00585 Valeur aux_psi(*mg) ;
00586 Valeur lap_xi_psi(*mg) ;
00587 Valeur oper_psi(*mg) ;
00588 Valeur dpsi(*mg) ;
00589 Valeur d2psi(*mg) ;
00590
00591 Valeur& vpsi = psi.va ;
00592
00593
00594
00595
00596
00597 Tbl tdiff(nz) ;
00598 double diff ;
00599 niter = 0 ;
00600
00601
00602 do {
00603
00604
00605
00606
00607 b_grad_psi = bb(0) % psi.dsdr() + bb(1) % psi.srdsdt() + bb(2) % psi.srstdsdp() ;
00608
00609
00610 vpsi.ylm() ;
00611
00612
00613
00614 Cmp lap_zeta(mpaff) ;
00615 mpaff.laplacien(psi, 0, lap_zeta) ;
00616
00617 Cmp grad_zeta(mpaff) ;
00618 mpaff.dsdr(psi, grad_zeta) ;
00619
00620 sour_j = source.va
00621 + ta * lap_zeta.va - aa.va * (psi.laplacien()).va
00622 + tb * grad_zeta.va - b_grad_psi.va ;
00623
00624 sour_j.std_base_scal() ;
00625 sour_j.coef() ;
00626 sour_j.ylm() ;
00627
00628
00629
00630
00631
00632 for (int lz=0; lz<nzet; lz++) {
00633 double somlzero = 0 ;
00634 for (int i=0; i<mg->get_nr(lz); i++) {
00635 somlzero += fabs( (*(sour_j.c_cf))(lz, 0, 0, i) ) ;
00636 (sour_j.c_cf)->set(lz, 0, 0, i) = 0 ;
00637 }
00638 if (somlzero > 1.e-10) {
00639 cout << "### WARNING : Map_radial::poisson_compact : " << endl
00640 << " domain no. " << lz << " : the l=0 part of the effective source is > 1.e-10 : "
00641 << somlzero << endl ;
00642 }
00643 }
00644
00645
00646
00647
00648 bool reamorce = (niter == 0) ;
00649
00650 assert(sour_j.c_cf != 0x0) ;
00651
00652 psi.set_etat_zero() ;
00653 psi.set_etat_qcq() ;
00654
00655 vpsi = sol_poisson_compact(mpaff, *(sour_j.c_cf), ac, bc, reamorce) ;
00656
00657
00658
00659
00660 mpaff.laplacien(psi, 0, lap_zeta) ;
00661 mpaff.dsdr(psi, grad_zeta) ;
00662
00663 oper_psi = ta * lap_zeta.va + tb * grad_zeta.va ;
00664 oper_psi.std_base_scal() ;
00665 oper_psi.coef() ;
00666 oper_psi.ylm() ;
00667
00668 Mtbl_cf diff_opsou = *oper_psi.c_cf - *sour_j.c_cf ;
00669
00670
00671
00672 cout << "poisson_compact: step " << niter << " : " << endl ;
00673 for (int lz=0; lz<nzet; lz++) {
00674 double maxc = fabs( max(*(vpsi.c_cf))(lz) ) ;
00675 double minc = fabs( min(*(vpsi.c_cf))(lz) ) ;
00676 double max_abs_psi = ( maxc > minc ) ? maxc : minc ;
00677
00678 maxc = fabs( max(*(sour_j.c_cf))(lz) ) ;
00679 minc = fabs( min(*(sour_j.c_cf))(lz) ) ;
00680 double max_abs_sou = ( maxc > minc ) ? maxc : minc ;
00681
00682 maxc = fabs( max(diff_opsou)(lz) ) ;
00683 minc = fabs( min(diff_opsou)(lz) ) ;
00684 double max_abs_diff = ( maxc > minc ) ? maxc : minc ;
00685
00686 cout << " lz = " << lz << " : max |psi| |sou| |oper(psi)-sou|: "
00687 << max_abs_psi << " " << max_abs_sou << " "
00688 << max_abs_diff << endl ;
00689 }
00690
00691
00692
00693
00694 vpsi.ylm_i() ;
00695
00696 psi = relax * psi + unmrelax * psi_jm1 ;
00697
00698 tdiff = diffrel(psi, psi_jm1) ;
00699
00700 diff = max(tdiff) ;
00701
00702 cout << " Relative difference psi^J <-> psi^{J-1} : "
00703 << tdiff << endl ;
00704
00705
00706
00707
00708 psi_jm1 = psi ;
00709 niter++ ;
00710
00711 }
00712 while ( (diff > precis) && (niter < nitermax) ) ;
00713
00714
00715
00716
00717
00718 psi.annule(nzet, nz-1) ;
00719
00720 }
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738