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 char et_bin_equilibrium_C[] = "$Header: /cvsroot/Lorene/C++/Source/Etoile/et_bin_equilibrium.C,v 1.12 2009/06/15 09:25:18 k_taniguchi Exp $" ;
00032
00033
00034
00035
00036
00037
00038
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
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166 #include <math.h>
00167
00168
00169 #include "etoile.h"
00170 #include "param.h"
00171 #include "eos.h"
00172
00173 #include "graphique.h"
00174 #include "utilitaires.h"
00175 #include "unites.h"
00176
00177 void Etoile_bin::equilibrium(double ent_c,
00178 int mermax, int mermax_poisson,
00179 double relax_poisson, int mermax_potvit,
00180 double relax_potvit, double thres_adapt,
00181 const Tbl& fact_resize, Tbl& diff, const Tbl* pent_limit ) {
00182
00183
00184
00185
00186
00187 using namespace Unites ;
00188
00189
00190
00191
00192 const Mg3d* mg = mp.get_mg() ;
00193 int nz = mg->get_nzone() ;
00194
00195
00196 Map_et& mp_et = dynamic_cast<Map_et&>(mp) ;
00197
00198
00199 int l_b = nzet - 1 ;
00200 int i_b = mg->get_nr(l_b) - 1 ;
00201 int k_b ;
00202 int j_b ;
00203
00204
00205 double ent_b = 0 ;
00206
00207
00208
00209
00210 double& diff_ent = diff.set(0) ;
00211 double& diff_vel_pot = diff.set(1) ;
00212 double& diff_logn = diff.set(2) ;
00213 double& diff_beta = diff.set(3) ;
00214 double& diff_shift_x = diff.set(4) ;
00215 double& diff_shift_y = diff.set(5) ;
00216 double& diff_shift_z = diff.set(6) ;
00217
00218
00219
00220
00221 Param par_adapt ;
00222 int nitermax = 100 ;
00223 int niter ;
00224 int adapt_flag = 1 ;
00225
00226
00227
00228 int nz_search = nzet ;
00229
00230
00231 double precis_secant = 1.e-14 ;
00232 double alpha_r ;
00233 double reg_map = 1. ;
00234
00235 par_adapt.add_int(nitermax, 0) ;
00236
00237 par_adapt.add_int(nzet, 1) ;
00238
00239
00240 par_adapt.add_int(nz_search, 2) ;
00241
00242 par_adapt.add_int(adapt_flag, 3) ;
00243
00244
00245 par_adapt.add_int(j_b, 4) ;
00246
00247 par_adapt.add_int(k_b, 5) ;
00248
00249
00250 par_adapt.add_int_mod(niter, 0) ;
00251
00252
00253 par_adapt.add_double(precis_secant, 0) ;
00254
00255
00256 par_adapt.add_double(reg_map, 1) ;
00257
00258 par_adapt.add_double(alpha_r, 2) ;
00259
00260
00261
00262 Tbl ent_limit(nzet) ;
00263 if (pent_limit != 0x0) ent_limit = *pent_limit ;
00264
00265 par_adapt.add_tbl(ent_limit, 0) ;
00266
00267
00268
00269
00270
00271 double precis_poisson = 1.e-16 ;
00272
00273 Param par_poisson1 ;
00274
00275 par_poisson1.add_int(mermax_poisson, 0) ;
00276 par_poisson1.add_double(relax_poisson, 0) ;
00277 par_poisson1.add_double(precis_poisson, 1) ;
00278 par_poisson1.add_int_mod(niter, 0) ;
00279 par_poisson1.add_cmp_mod( ssjm1_logn ) ;
00280
00281
00282
00283
00284 Param par_poisson2 ;
00285
00286 par_poisson2.add_int(mermax_poisson, 0) ;
00287 par_poisson2.add_double(relax_poisson, 0) ;
00288 par_poisson2.add_double(precis_poisson, 1) ;
00289 par_poisson2.add_int_mod(niter, 0) ;
00290 par_poisson2.add_cmp_mod( ssjm1_beta ) ;
00291
00292
00293
00294
00295
00296 Param par_poisson_vect ;
00297
00298 par_poisson_vect.add_int(mermax_poisson, 0) ;
00299 par_poisson_vect.add_double(relax_poisson, 0) ;
00300 par_poisson_vect.add_double(precis_poisson, 1) ;
00301 par_poisson_vect.add_cmp_mod( ssjm1_khi ) ;
00302 par_poisson_vect.add_tenseur_mod( ssjm1_wshift ) ;
00303 par_poisson_vect.add_int_mod(niter, 0) ;
00304
00305
00306
00307
00308
00309
00310 Tenseur pot_ext = logn_comp + pot_centri + loggam ;
00311
00312
00313
00314
00315 Tenseur ent_jm1 = ent ;
00316
00317 Tenseur source(mp) ;
00318
00319
00320 Tenseur source_shift(mp, 1, CON, ref_triad) ;
00321
00322
00323
00324
00325
00326
00327 for(int mer=0 ; mer<mermax ; mer++ ) {
00328
00329 cout << "-----------------------------------------------" << endl ;
00330 cout << "step: " << mer << endl ;
00331 cout << "diff_ent = " << diff_ent << endl ;
00332
00333
00334
00335
00336
00337
00338 if (irrotational) {
00339 diff_vel_pot = velocity_potential(mermax_potvit,
00340 precis_poisson, relax_potvit) ;
00341
00342 }
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352 double logn_auto_c = logn_auto()(0, 0, 0, 0) ;
00353 double pot_ext_c = pot_ext()(0, 0, 0, 0) ;
00354
00355
00356
00357
00358
00359 double alpha_r2 = 0 ;
00360 for (int k=0; k<mg->get_np(l_b); k++) {
00361 for (int j=0; j<mg->get_nt(l_b); j++) {
00362
00363 double pot_ext_b = pot_ext()(l_b, k, j, i_b) ;
00364 double logn_auto_b = logn_auto()(l_b, k, j, i_b) ;
00365
00366
00367
00368 double alpha_r2_jk = ( ent_c - ent_b + pot_ext_c - pot_ext_b) /
00369 ( logn_auto_b - logn_auto_c ) ;
00370
00371
00372
00373
00374 if (alpha_r2_jk > alpha_r2) {
00375 alpha_r2 = alpha_r2_jk ;
00376 k_b = k ;
00377 j_b = j ;
00378 }
00379
00380 }
00381 }
00382
00383 alpha_r = sqrt(alpha_r2) ;
00384
00385 cout << "k_b, j_b, alpha_r: " << k_b << " " << j_b << " "
00386 << alpha_r << endl ;
00387
00388
00389
00390
00391 logn_auto = alpha_r2 * logn_auto ;
00392 logn_auto_regu = alpha_r2 * logn_auto_regu ;
00393 logn_auto_c = logn_auto()(0, 0, 0, 0) ;
00394
00395
00396
00397
00398
00399
00400
00401 (logn_auto().va).smooth(nzet, (logn_auto.set()).va) ;
00402
00403
00404
00405
00406
00407
00408
00409 ent = (ent_c + logn_auto_c + pot_ext_c) - logn_auto - pot_ext ;
00410
00411 (ent().va).smooth(nzet, (ent.set()).va) ;
00412
00413
00414
00415
00416
00417
00418
00419
00420 double dent_eq = ent().dsdr().val_point(ray_eq(),M_PI/2.,0.) ;
00421 double dent_pole = ent().dsdr().val_point(ray_pole(),0.,0.) ;
00422 double rap_dent = fabs( dent_eq / dent_pole ) ;
00423 cout << "| dH/dr_eq / dH/dr_pole | = " << rap_dent << endl ;
00424
00425 if ( rap_dent < thres_adapt ) {
00426 adapt_flag = 0 ;
00427 cout << "******* FROZEN MAPPING *********" << endl ;
00428 }
00429 else{
00430 adapt_flag = 1 ;
00431
00432 }
00433
00434
00435 if (pent_limit == 0x0) {
00436 ent_limit.set_etat_qcq() ;
00437 for (int l=0; l<nzet; l++) {
00438 ent_limit.set(l) = ent()(l, k_b, j_b, i_b) ;
00439 }
00440 ent_limit.set(nzet-1) = ent_b ;
00441 }
00442
00443 Map_et mp_prev = mp_et ;
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486 mp.adapt(ent(), par_adapt) ;
00487
00488
00489
00490
00491 double rr_in_1 = mp.val_r(nzet, -1., M_PI/2., 0.) ;
00492
00493
00494 double rr_out_nm2 = mp.val_r(nz-2, 1., M_PI/2., 0.) ;
00495
00496 mp.resize(nz-2, rr_in_1/rr_out_nm2 * fact_resize(1)) ;
00497
00498
00499 double rr_out_nm3 = mp.val_r(nz-3, 1., M_PI/2., 0.) ;
00500
00501 mp.resize(nz-3, rr_in_1/rr_out_nm3 * fact_resize(0)) ;
00502
00503 if (nz > nzet+3) {
00504
00505
00506 double rr_out_nm3_new = mp.val_r(nz-3, 1., M_PI/2., 0.) ;
00507
00508 for (int i=nzet-1; i<nz-4; i++) {
00509
00510 double rr_out_i = mp.val_r(i, 1., M_PI/2., 0.) ;
00511
00512 double rr_mid = rr_out_i
00513 + (rr_out_nm3_new - rr_out_i) / double(nz - 3 - i) ;
00514
00515 double rr_2timesi = 2. * rr_out_i ;
00516
00517 if (rr_2timesi < rr_mid) {
00518
00519 double rr_out_ip1 = mp.val_r(i+1, 1., M_PI/2., 0.) ;
00520
00521 mp.resize(i+1, rr_2timesi / rr_out_ip1) ;
00522
00523 }
00524 else {
00525
00526 double rr_out_ip1 = mp.val_r(i+1, 1., M_PI/2., 0.) ;
00527
00528 mp.resize(i+1, rr_mid / rr_out_ip1) ;
00529
00530 }
00531
00532 }
00533
00534 }
00535
00536
00537
00538
00539
00540
00541 mp_prev.homothetie(alpha_r) ;
00542
00543 mp.reevaluate_symy(&mp_prev, nzet+1, ent.set()) ;
00544
00545
00546
00547 double ent_s_max = -1 ;
00548 int k_s_max = -1 ;
00549 int j_s_max = -1 ;
00550 for (int k=0; k<mg->get_np(l_b); k++) {
00551 for (int j=0; j<mg->get_nt(l_b); j++) {
00552 double xx = fabs( ent()(l_b, k, j, i_b) ) ;
00553 if (xx > ent_s_max) {
00554 ent_s_max = xx ;
00555 k_s_max = k ;
00556 j_s_max = j ;
00557 }
00558 }
00559 }
00560 cout << "Max. abs(enthalpy) at the boundary between domains nzet-1"
00561 << " and nzet : " << endl ;
00562 cout << " " << ent_s_max << " reached for k = " << k_s_max <<
00563 " and j = " << j_s_max << endl ;
00564
00565
00566
00567
00568
00569 equation_of_state() ;
00570
00571
00572
00573
00574
00575
00576 hydro_euler() ;
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587 if (relativistic) {
00588 source = qpig * a_car % (ener_euler + s_euler)
00589 + akcar_auto + akcar_comp
00590 - flat_scalar_prod_desal(d_logn_auto,
00591 d_beta_auto + d_beta_comp) ;
00592
00593 }
00594 else {
00595 source = qpig * nbar ;
00596 }
00597
00598 source.set_std_base() ;
00599
00600
00601
00602
00603 source().poisson(par_poisson1, logn_auto.set()) ;
00604
00605
00606
00607
00608 logn_auto_regu = logn_auto ;
00609
00610
00611
00612
00613 Tbl tdiff_logn = diffrel(logn_auto().laplacien(), source()) ;
00614 cout <<
00615 "Relative error in the resolution of the equation for logn_auto : "
00616 << endl ;
00617 for (int l=0; l<nz; l++) {
00618 cout << tdiff_logn(l) << " " ;
00619 }
00620 cout << endl ;
00621 diff_logn = max(abs(tdiff_logn)) ;
00622
00623
00624 if (relativistic) {
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634 source = qpig * a_car % s_euler
00635 + .75 * ( akcar_auto + akcar_comp )
00636 - .5 * flat_scalar_prod_desal(d_logn_auto,
00637 d_logn_auto + d_logn_comp)
00638 - .5 * flat_scalar_prod_desal(d_beta_auto,
00639 d_beta_auto + d_beta_comp) ;
00640
00641 source.set_std_base() ;
00642
00643
00644
00645
00646 source().poisson(par_poisson2, beta_auto.set()) ;
00647
00648
00649
00650
00651 Tbl tdiff_beta = diffrel(beta_auto().laplacien(), source()) ;
00652 cout <<
00653 "Relative error in the resolution of the equation for beta_auto : "
00654 << endl ;
00655 for (int l=0; l<nz; l++) {
00656 cout << tdiff_beta(l) << " " ;
00657 }
00658 cout << endl ;
00659 diff_beta = max(abs(tdiff_beta)) ;
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669 Tenseur vtmp = 6. * ( d_beta_auto + d_beta_comp )
00670 -8. * ( d_logn_auto + d_logn_comp ) ;
00671
00672 source_shift = (-4.*qpig) * nnn % a_car % (ener_euler + press)
00673 % u_euler
00674 + nnn % flat_scalar_prod_desal(tkij_auto, vtmp) ;
00675
00676 source_shift.set_std_base() ;
00677
00678
00679
00680
00681
00682
00683 for (int i=0; i<3; i++) {
00684
00685 if (source_shift(i).get_etat() != ETATZERO)
00686 source_shift.set(i).filtre(4) ;
00687
00688 }
00689
00690
00691
00692
00693 source_shift.change_triad( mp.get_bvect_cart() ) ;
00694
00695 for (int i=0; i<3; i++) {
00696 if(source_shift(i).dz_nonzero()) {
00697 assert( source_shift(i).get_dzpuis() == 4 ) ;
00698 }
00699 else{
00700 (source_shift.set(i)).set_dzpuis(4) ;
00701 }
00702 }
00703
00704
00705
00706
00707 double lambda_shift = double(1) / double(3) ;
00708
00709 source_shift.poisson_vect(lambda_shift, par_poisson_vect,
00710 shift_auto, w_shift, khi_shift) ;
00711
00712
00713
00714
00715
00716
00717 Tenseur divn = contract(shift_auto.gradient(), 0, 1) ;
00718 divn.dec2_dzpuis() ;
00719
00720
00721 Tenseur graddivn = divn.gradient() ;
00722 graddivn.inc2_dzpuis() ;
00723
00724
00725 Tenseur lap_shift(mp, 1, CON, mp.get_bvect_cart() ) ;
00726 lap_shift.set_etat_qcq() ;
00727 for (int i=0; i<3; i++) {
00728 lap_shift.set(i) = shift_auto(i).laplacien()
00729 + lambda_shift * graddivn(i) ;
00730 }
00731
00732 Tbl tdiff_shift_x = diffrel(lap_shift(0), source_shift(0)) ;
00733 Tbl tdiff_shift_y = diffrel(lap_shift(1), source_shift(1)) ;
00734 Tbl tdiff_shift_z = diffrel(lap_shift(2), source_shift(2)) ;
00735
00736 cout <<
00737 "Relative error in the resolution of the equation for shift_auto : "
00738 << endl ;
00739 cout << "x component : " ;
00740 for (int l=0; l<nz; l++) {
00741 cout << tdiff_shift_x(l) << " " ;
00742 }
00743 cout << endl ;
00744 cout << "y component : " ;
00745 for (int l=0; l<nz; l++) {
00746 cout << tdiff_shift_y(l) << " " ;
00747 }
00748 cout << endl ;
00749 cout << "z component : " ;
00750 for (int l=0; l<nz; l++) {
00751 cout << tdiff_shift_z(l) << " " ;
00752 }
00753 cout << endl ;
00754
00755 diff_shift_x = max(abs(tdiff_shift_x)) ;
00756 diff_shift_y = max(abs(tdiff_shift_y)) ;
00757 diff_shift_z = max(abs(tdiff_shift_z)) ;
00758
00759
00760
00761
00762
00763
00764
00765 shift_auto.change_triad( ref_triad ) ;
00766
00767
00768 }
00769
00770
00771 if (nzet > 1) {
00772 cout.precision(10) ;
00773
00774 for (int ltrans = 0; ltrans < nzet-1; ltrans++) {
00775 cout << endl << "Values at boundary between domains no. " << ltrans << " and " << ltrans+1 << " for theta = pi/2 and phi = 0 :" << endl ;
00776
00777 double rt1 = mp.val_r(ltrans, 1., M_PI/2, 0.) ;
00778 double rt2 = mp.val_r(ltrans+1, -1., M_PI/2, 0.) ;
00779 cout << " Coord. r [km] (left, right, rel. diff) : "
00780 << rt1 / km << " " << rt2 / km << " " << (rt2 - rt1)/rt1 << endl ;
00781
00782 int ntm1 = mg->get_nt(ltrans) - 1;
00783 int nrm1 = mg->get_nr(ltrans) - 1 ;
00784 double ent1 = ent()(ltrans, 0, ntm1, nrm1) ;
00785 double ent2 = ent()(ltrans+1, 0, ntm1, 0) ;
00786 cout << " Enthalpy (left, right, rel. diff) : "
00787 << ent1 << " " << ent2 << " " << (ent2-ent1)/ent1 << endl ;
00788
00789 double press1 = press()(ltrans, 0, ntm1, nrm1) ;
00790 double press2 = press()(ltrans+1, 0, ntm1, 0) ;
00791 cout << " Pressure (left, right, rel. diff) : "
00792 << press1 << " " << press2 << " " << (press2-press1)/press1 << endl ;
00793
00794 double nb1 = nbar()(ltrans, 0, ntm1, nrm1) ;
00795 double nb2 = nbar()(ltrans+1, 0, ntm1, 0) ;
00796 cout << " Baryon density (left, right, rel. diff) : "
00797 << nb1 << " " << nb2 << " " << (nb2-nb1)/nb1 << endl ;
00798 }
00799 }
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813 Tbl diff_ent_tbl = diffrel( ent(), ent_jm1() ) ;
00814 diff_ent = diff_ent_tbl(0) ;
00815 for (int l=1; l<nzet; l++) {
00816 diff_ent += diff_ent_tbl(l) ;
00817 }
00818 diff_ent /= nzet ;
00819
00820
00821 ent_jm1 = ent ;
00822
00823
00824 }
00825
00826
00827
00828
00829
00830
00831 }