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