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 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769
|
/*
* Method of the class Map_et for the (iterative) resolution of the scalar
* Poisson equation.
*
* (see file map.h for the documentation).
*
*/
/*
* Copyright (c) 2004 Francois Limousin
* Copyright (c) 1999-2003 Eric Gourgoulhon
* Copyright (c) 2000-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 map_et_poisson_C[] = "$Header: /cvsroot/Lorene/C++/Source/Map/map_et_poisson.C,v 1.7 2014/10/13 08:53:05 j_novak Exp $" ;
/*
* $Id: map_et_poisson.C,v 1.7 2014/10/13 08:53:05 j_novak Exp $
* $Log: map_et_poisson.C,v $
* Revision 1.7 2014/10/13 08:53:05 j_novak
* Lorene classes and functions now belong to the namespace Lorene.
*
* Revision 1.6 2005/08/25 12:14:09 p_grandclement
* Addition of a new method to solve the scalar Poisson equation, based on a multi-domain Tau-method
*
* Revision 1.5 2005/04/04 21:31:31 e_gourgoulhon
* Added argument lambda to method poisson_angu
* to deal with the generalized angular Poisson equation:
* Lap_ang u + lambda u = source.
*
* Revision 1.4 2004/06/22 12:20:17 j_novak
* *** empty log message ***
*
* Revision 1.3 2004/05/25 14:28:01 f_limousin
* First version of method Map_et::poisson_angu().
*
* Revision 1.2 2003/10/15 21:11:26 e_gourgoulhon
* Added method poisson_angu.
*
* Revision 1.1.1.1 2001/11/20 15:19:27 e_gourgoulhon
* LORENE
*
* Revision 1.7 2000/05/22 14:55:30 phil
* ajout du cas dzpuis = 3
*
* Revision 1.6 2000/03/30 09:18:37 eric
* Modifs affichage.
*
* Revision 1.5 2000/03/29 12:01:38 eric
* *** empty log message ***
*
* Revision 1.4 2000/03/29 11:48:09 eric
* Modifs affichage.
*
* Revision 1.3 2000/03/10 15:48:25 eric
* MODIFS IMPORTANTES:
* ssj est desormais traitee comme un Cmp (et non plus une Valeur) ce qui
* permet un traitement automatique du dzpuis associe.
* Traitement de dzpuis.
*
* Revision 1.2 2000/03/07 16:50:57 eric
* Possibilite d'avoir une source avec dzpuis = 2.
*
* Revision 1.1 1999/12/22 17:11:24 eric
* Initial revision
*
*
* $Header: /cvsroot/Lorene/C++/Source/Map/map_et_poisson.C,v 1.7 2014/10/13 08:53:05 j_novak Exp $
*
*/
// Header Lorene:
#include "map.h"
#include "cmp.h"
#include "scalar.h"
#include "param.h"
#include "graphique.h"
//*****************************************************************************
namespace Lorene {
void Map_et::poisson(const Cmp& source, Param& par, Cmp& uu) const {
assert(source.get_etat() != ETATNONDEF) ;
assert(source.get_mp() == this) ;
assert( source.check_dzpuis(2) || source.check_dzpuis(4)
|| source.check_dzpuis(3)) ;
assert(uu.get_mp() == this) ;
assert(uu.check_dzpuis(0)) ;
int nz = mg->get_nzone() ;
int nzm1 = nz - 1 ;
// Indicator of existence of a compactified external domain
bool zec = false ;
if (mg->get_type_r(nzm1) == UNSURR) {
zec = true ;
}
//-------------------------------
// Computation of the prefactor a ---> Cmp apre
//-------------------------------
Mtbl unjj = 1 + srdrdt*srdrdt + srstdrdp*srstdrdp ;
Mtbl apre1(*mg) ;
apre1.set_etat_qcq() ;
for (int l=0; l<nz; l++) {
*(apre1.t[l]) = alpha[l]*alpha[l] ;
}
apre1 = apre1 * dxdr * dxdr * unjj ;
Cmp apre(*this) ;
apre = apre1 ;
Tbl amax0 = max(apre1) ; // maximum values in each domain
// The maximum values of a in each domain are put in a Mtbl
Mtbl amax1(*mg) ;
amax1.set_etat_qcq() ;
for (int l=0; l<nz; l++) {
*(amax1.t[l]) = amax0(l) ;
}
Cmp amax(*this) ;
amax = amax1 ;
//-------------------
// Initializations
//-------------------
int nitermax = par.get_int() ;
int& niter = par.get_int_mod() ;
double lambda = par.get_double() ;
double unmlambda = 1. - lambda ;
double precis = par.get_double(1) ;
Cmp& ssj = par.get_cmp_mod() ;
Cmp ssjm1 = ssj ;
Cmp ssjm2 = ssjm1 ;
Valeur& vuu = uu.va ;
Valeur vuujm1(*mg) ;
if (uu.get_etat() == ETATZERO) {
vuujm1 = 1 ; // to take relative differences
vuujm1.set_base( vuu.base ) ;
}
else{
vuujm1 = vuu ;
}
// Affine mapping for the Laplacian-tilde
Map_af mpaff(*this) ;
Param par_nul ;
cout << "Map_et::poisson : relat. diff. u^J <-> u^{J-1} : " << endl ;
//==========================================================================
//==========================================================================
// Start of iteration
//==========================================================================
//==========================================================================
Tbl tdiff(nz) ;
double diff ;
niter = 0 ;
do {
//====================================================================
// Computation of R(u) (the result is put in uu)
//====================================================================
//-----------------------
// First operations on uu
//-----------------------
Valeur duudx = (uu.va).dsdx() ; // d/dx
const Valeur& d2uudtdx = duudx.dsdt() ; // d^2/dxdtheta
const Valeur& std2uudpdx = duudx.stdsdp() ; // 1/sin(theta) d^2/dxdphi
//------------------
// Angular Laplacian
//------------------
Valeur sxlapang = uu.va ;
sxlapang.ylm() ;
sxlapang = sxlapang.lapang() ;
sxlapang = sxlapang.sx() ; // Lap_ang(uu) /x in the nucleus
// Lap_ang(uu) in the shells
// Lap_ang(uu) /(x-1) in the ZEC
//---------------------------------------------------------------
// Computation of
// [ 2 /(dRdx) ( A - 1 ) duu/dx + 1/R (B - 1) Lap_ang(uu) ] / x
//
// with A = 1/(dRdx) R/(x+beta_l/alpha_l) unjj
// B = [1/(dRdx) R/(x+beta_l/alpha_l)]^2 unjj
//
// The result is put in uu (via vuu)
//---------------------------------------------------------------
Valeur varduudx = duudx ;
if (zec) {
varduudx.annule(nzm1) ; // term in d/dx set to zero in the ZEC
}
uu.set_etat_qcq() ;
Base_val sauve_base = varduudx.base ;
vuu = 2. * dxdr * ( rsxdxdr * unjj - 1.) * varduudx
+ ( rsxdxdr*rsxdxdr * unjj - 1.) * xsr * sxlapang ;
vuu.set_base(sauve_base) ;
vuu = vuu.sx() ;
//---------------------------------------
// Computation of R(u)
//
// The result is put in uu (via vuu)
//---------------------------------------
sauve_base = vuu.base ;
vuu = xsr * vuu
+ 2. * dxdr * ( sr2drdt * d2uudtdx
+ sr2stdrdp * std2uudpdx ) ;
vuu += dxdr * ( lapr_tp + dxdr * (
dxdr* unjj * d2rdx2
- 2. * ( sr2drdt * d2rdtdx + sr2stdrdp * sstd2rdpdx ) )
) * duudx ;
vuu.set_base(sauve_base) ;
// Since the assignment is performed on vuu (uu.va), the treatment
// of uu.dzpuis must be performed by hand:
uu.set_dzpuis(4) ;
if (source.get_dzpuis() == 2) {
uu.dec2_dzpuis() ; // uu.dzpuis: 4 -> 2
}
if (source.get_dzpuis() == 3) {
uu.dec_dzpuis() ; //uu.dzpuis 4 -> 3
}
//====================================================================
// Computation of the effective source s^J of the ``affine''
// Poisson equation
//====================================================================
ssj = lambda * ssjm1 + unmlambda * ssjm2 ;
ssj = ( source + uu + (amax - apre) * ssj ) / amax ;
(ssj.va).set_base((source.va).base) ;
//====================================================================
// Resolution of the ``affine'' Poisson equation
//====================================================================
if ( source.get_dzpuis() == 0 ){
ssj.set_dzpuis( 4 ) ;
}
else {
ssj.set_dzpuis( source.get_dzpuis() ) ; // Choice of the resolution
// dzpuis = 2, 3 or 4
}
assert( uu.check_dzpuis( ssj.get_dzpuis() ) ) ;
mpaff.poisson(ssj, par_nul, uu) ;
tdiff = diffrel(vuu, vuujm1) ;
diff = max(tdiff) ;
cout << " step " << niter << " : " ;
for (int l=0; l<nz; l++) {
cout << tdiff(l) << " " ;
}
cout << endl ;
//=================================
// Updates for the next iteration
//=================================
ssjm2 = ssjm1 ;
ssjm1 = ssj ;
vuujm1 = vuu ;
niter++ ;
} // End of iteration
while ( (diff > precis) && (niter < nitermax) ) ;
//==========================================================================
//==========================================================================
// End of iteration
//==========================================================================
//==========================================================================
}
//*****************************************************************************
// VERSION WITH A TAU METHOD
//*****************************************************************************
void Map_et::poisson_tau(const Cmp& source, Param& par, Cmp& uu) const {
assert(source.get_etat() != ETATNONDEF) ;
assert(source.get_mp() == this) ;
assert( source.check_dzpuis(2) || source.check_dzpuis(4)
|| source.check_dzpuis(3)) ;
assert(uu.get_mp() == this) ;
assert(uu.check_dzpuis(0)) ;
int nz = mg->get_nzone() ;
int nzm1 = nz - 1 ;
// Indicator of existence of a compactified external domain
bool zec = false ;
if (mg->get_type_r(nzm1) == UNSURR) {
zec = true ;
}
//-------------------------------
// Computation of the prefactor a ---> Cmp apre
//-------------------------------
Mtbl unjj = 1 + srdrdt*srdrdt + srstdrdp*srstdrdp ;
Mtbl apre1(*mg) ;
apre1.set_etat_qcq() ;
for (int l=0; l<nz; l++) {
*(apre1.t[l]) = alpha[l]*alpha[l] ;
}
apre1 = apre1 * dxdr * dxdr * unjj ;
Cmp apre(*this) ;
apre = apre1 ;
Tbl amax0 = max(apre1) ; // maximum values in each domain
// The maximum values of a in each domain are put in a Mtbl
Mtbl amax1(*mg) ;
amax1.set_etat_qcq() ;
for (int l=0; l<nz; l++) {
*(amax1.t[l]) = amax0(l) ;
}
Cmp amax(*this) ;
amax = amax1 ;
//-------------------
// Initializations
//-------------------
int nitermax = par.get_int() ;
int& niter = par.get_int_mod() ;
double lambda = par.get_double() ;
double unmlambda = 1. - lambda ;
double precis = par.get_double(1) ;
Cmp& ssj = par.get_cmp_mod() ;
Cmp ssjm1 = ssj ;
Cmp ssjm2 = ssjm1 ;
Valeur& vuu = uu.va ;
Valeur vuujm1(*mg) ;
if (uu.get_etat() == ETATZERO) {
vuujm1 = 1 ; // to take relative differences
vuujm1.set_base( vuu.base ) ;
}
else{
vuujm1 = vuu ;
}
// Affine mapping for the Laplacian-tilde
Map_af mpaff(*this) ;
Param par_nul ;
cout << "Map_et::poisson_tau : relat. diff. u^J <-> u^{J-1} : " << endl ;
//==========================================================================
//==========================================================================
// Start of iteration
//==========================================================================
//==========================================================================
Tbl tdiff(nz) ;
double diff ;
niter = 0 ;
do {
//====================================================================
// Computation of R(u) (the result is put in uu)
//====================================================================
//-----------------------
// First operations on uu
//-----------------------
Valeur duudx = (uu.va).dsdx() ; // d/dx
const Valeur& d2uudtdx = duudx.dsdt() ; // d^2/dxdtheta
const Valeur& std2uudpdx = duudx.stdsdp() ; // 1/sin(theta) d^2/dxdphi
//------------------
// Angular Laplacian
//------------------
Valeur sxlapang = uu.va ;
sxlapang.ylm() ;
sxlapang = sxlapang.lapang() ;
sxlapang = sxlapang.sx() ; // Lap_ang(uu) /x in the nucleus
// Lap_ang(uu) in the shells
// Lap_ang(uu) /(x-1) in the ZEC
//---------------------------------------------------------------
// Computation of
// [ 2 /(dRdx) ( A - 1 ) duu/dx + 1/R (B - 1) Lap_ang(uu) ] / x
//
// with A = 1/(dRdx) R/(x+beta_l/alpha_l) unjj
// B = [1/(dRdx) R/(x+beta_l/alpha_l)]^2 unjj
//
// The result is put in uu (via vuu)
//---------------------------------------------------------------
Valeur varduudx = duudx ;
if (zec) {
varduudx.annule(nzm1) ; // term in d/dx set to zero in the ZEC
}
uu.set_etat_qcq() ;
Base_val sauve_base = varduudx.base ;
vuu = 2. * dxdr * ( rsxdxdr * unjj - 1.) * varduudx
+ ( rsxdxdr*rsxdxdr * unjj - 1.) * xsr * sxlapang ;
vuu.set_base(sauve_base) ;
vuu = vuu.sx() ;
//---------------------------------------
// Computation of R(u)
//
// The result is put in uu (via vuu)
//---------------------------------------
sauve_base = vuu.base ;
vuu = xsr * vuu
+ 2. * dxdr * ( sr2drdt * d2uudtdx
+ sr2stdrdp * std2uudpdx ) ;
vuu += dxdr * ( lapr_tp + dxdr * (
dxdr* unjj * d2rdx2
- 2. * ( sr2drdt * d2rdtdx + sr2stdrdp * sstd2rdpdx ) )
) * duudx ;
vuu.set_base(sauve_base) ;
// Since the assignment is performed on vuu (uu.va), the treatment
// of uu.dzpuis must be performed by hand:
uu.set_dzpuis(4) ;
if (source.get_dzpuis() == 2) {
uu.dec2_dzpuis() ; // uu.dzpuis: 4 -> 2
}
if (source.get_dzpuis() == 3) {
uu.dec_dzpuis() ; //uu.dzpuis 4 -> 3
}
//====================================================================
// Computation of the effective source s^J of the ``affine''
// Poisson equation
//====================================================================
ssj = lambda * ssjm1 + unmlambda * ssjm2 ;
ssj = ( source + uu + (amax - apre) * ssj ) / amax ;
(ssj.va).set_base((source.va).base) ;
//====================================================================
// Resolution of the ``affine'' Poisson equation
//====================================================================
if ( source.get_dzpuis() == 0 ){
ssj.set_dzpuis( 4 ) ;
}
else {
ssj.set_dzpuis( source.get_dzpuis() ) ; // Choice of the resolution
// dzpuis = 2, 3 or 4
}
assert( uu.check_dzpuis( ssj.get_dzpuis() ) ) ;
mpaff.poisson_tau(ssj, par_nul, uu) ;
tdiff = diffrel(vuu, vuujm1) ;
diff = max(tdiff) ;
cout << " step " << niter << " : " ;
for (int l=0; l<nz; l++) {
cout << tdiff(l) << " " ;
}
cout << endl ;
//=================================
// Updates for the next iteration
//=================================
ssjm2 = ssjm1 ;
ssjm1 = ssj ;
vuujm1 = vuu ;
niter++ ;
} // End of iteration
while ( (diff > precis) && (niter < nitermax) ) ;
//==========================================================================
//==========================================================================
// End of iteration
//==========================================================================
//==========================================================================
}
void Map_et::poisson_angu(const Scalar& source, Param& par, Scalar& uu,
double lambda) const {
if (lambda != double(0)) {
cout <<
"Map_et::poisson_angu : the case lambda != 0 is not treated yet !"
<< endl ;
abort() ;
}
assert(source.get_mp() == *this) ;
assert(uu.get_mp() == *this) ;
int nz = mg->get_nzone() ;
int nzm1 = nz - 1 ;
int* nrm6 = new int[nz];
for (int l=0; l<=nzm1; l++)
nrm6[l] = mg->get_nr(l) - 6 ;
//## // Indicator of existence of a compactified external domain
// bool zec = false ;
// if (mg->get_type_r(nzm1) == UNSURR) {
// zec = true ;
// }
//-------------------
// Initializations
//-------------------
int nitermax = par.get_int() ;
int& niter = par.get_int_mod() ;
double relax = par.get_double() ;
double precis = par.get_double(1) ;
Cmp& ssjcmp = par.get_cmp_mod() ;
Scalar ssj (ssjcmp) ;
Scalar ssjm1 (ssj) ;
int dzpuis = source.get_dzpuis() ;
ssj.set_dzpuis(dzpuis) ;
uu.set_dzpuis(dzpuis) ;
ssjm1.set_dzpuis(dzpuis) ;
Valeur& vuu = uu.set_spectral_va() ;
Valeur vuujm1(*mg) ;
if (uu.get_etat() == ETATZERO) {
vuujm1 = 1 ; // to take relative differences
vuujm1.set_base( vuu.base ) ;
}
else{
vuujm1 = vuu ;
}
// Affine mapping for the Laplacian-tilde
Map_af mpaff(*this) ;
Param par_nul ;
cout << "Map_et::poisson angu : relat. diff. u^J <-> u^{J-1} : " << endl ;
//==========================================================================
//==========================================================================
// Start of iteration
//==========================================================================
//==========================================================================
Tbl tdiff(nz) ;
double diff ;
niter = 0 ;
do {
//====================================================================
// Computation of R(u) (the result is put in uu)
//====================================================================
//-----------------------
// First operations on uu
//-----------------------
Valeur duudx = (uu.set_spectral_va()).dsdx() ; // d/dx
const Valeur& d2uudxdx = duudx.dsdx() ; // d^2/dxdx
const Valeur& d2uudtdx = duudx.dsdt() ; // d^2/dxdtheta
const Valeur& std2uudpdx = duudx.stdsdp() ; // 1/sin(theta) d^2/dxdphi
//---------------------------------------
// Computation of R(u)
//
// The result is put in uu (via vuu)
//---------------------------------------
Mtbl unjj = srdrdt*srdrdt + srstdrdp*srstdrdp ;
Base_val sauve_base = vuu.base ;
vuu = - d2uudxdx * dxdr * dxdr * unjj
+ 2. * dxdr * ( sr2drdt * d2uudtdx
+ sr2stdrdp * std2uudpdx ) ;
vuu.set_base(sauve_base) ;
vuu += dxdr * ( lapr_tp + dxdr * (
dxdr * unjj * d2rdx2
- 2. * ( sr2drdt * d2rdtdx + sr2stdrdp * sstd2rdpdx ) )
) * duudx ;
vuu.set_base(sauve_base) ;
uu.mult_r() ;
uu.mult_r() ;
//====================================================================
// Computation of the effective source s^J of the ``affine''
// Poisson equation
//====================================================================
uu.filtre_r(nrm6) ;
// uu.filtre_phi(1) ;
// uu.filtre_theta(1) ;
ssj = source + uu ;
ssj = (1-relax) * ssj + relax * ssjm1 ;
(ssj.set_spectral_va()).set_base((source.get_spectral_va()).base) ;
//====================================================================
// Resolution of the ``affine'' Poisson equation
//====================================================================
mpaff.poisson_angu(ssj, par_nul, uu) ;
tdiff = diffrel(vuu, vuujm1) ;
diff = max(tdiff) ;
cout << " step " << niter << " : " ;
for (int l=0; l<nz; l++) {
cout << tdiff(l) << " " ;
}
cout << endl ;
//=================================
// Updates for the next iteration
//=================================
vuujm1 = vuu ;
ssjm1 = ssj ;
niter++ ;
} // End of iteration
while ( (diff > precis) && (niter < nitermax) ) ;
//==========================================================================
//==========================================================================
// End of iteration
//==========================================================================
//==========================================================================
uu.set_dzpuis( source.get_dzpuis() ) ; // dzpuis unchanged
}
}
|