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 char et_bin_nsbh_equilibrium_C[] = "$Header: /cvsroot/Lorene/C++/Source/Etoile/et_bin_nsbh_equilibrium.C,v 1.11 2008/09/26 08:38:45 p_grandclement Exp $" ;
00030
00031
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 #include <math.h>
00078
00079
00080 #include "etoile.h"
00081 #include "map.h"
00082 #include "nbr_spx.h"
00083 #include "et_bin_nsbh.h"
00084 #include "param.h"
00085
00086 #include "graphique.h"
00087 #include "utilitaires.h"
00088 #include "unites.h"
00089
00090 void Et_bin_nsbh::equilibrium_nsbh(bool adapt, double ent_c, int& niter, int mermax,
00091 int mermax_poisson, double relax_poisson,
00092 int mermax_potvit, double relax_potvit,
00093 Tbl& diff) {
00094
00095
00096
00097 using namespace Unites ;
00098
00099
00100
00101
00102 const Mg3d* mg = mp.get_mg() ;
00103 int nz = mg->get_nzone() ;
00104
00105
00106 Map_et& mp_et = dynamic_cast<Map_et&>(mp) ;
00107
00108
00109
00110 double& diff_ent = diff.set(0) ;
00111 double& diff_vel_pot = diff.set(1) ;
00112 double& diff_lapse = diff.set(2) ;
00113 double& diff_confpsi = diff.set(3) ;
00114 double& diff_shift_x = diff.set(4) ;
00115 double& diff_shift_y = diff.set(5) ;
00116 double& diff_shift_z = diff.set(6) ;
00117
00118
00119
00120
00121 double precis_poisson = 1.e-16 ;
00122
00123 Param par_poisson1 ;
00124 par_poisson1.add_int(mermax_poisson, 0) ;
00125 par_poisson1.add_double(relax_poisson, 0) ;
00126 par_poisson1.add_double(precis_poisson, 1) ;
00127 par_poisson1.add_int_mod(niter, 0) ;
00128 par_poisson1.add_cmp_mod( ssjm1_lapse ) ;
00129
00130
00131
00132
00133 Param par_poisson2 ;
00134 par_poisson2.add_int(mermax_poisson, 0) ;
00135 par_poisson2.add_double(relax_poisson, 0) ;
00136 par_poisson2.add_double(precis_poisson, 1) ;
00137 par_poisson2.add_int_mod(niter, 0) ;
00138 par_poisson2.add_cmp_mod( ssjm1_confpsi ) ;
00139
00140
00141
00142
00143 Param par_poisson_vect ;
00144 par_poisson_vect.add_int(mermax_poisson, 0) ;
00145
00146 par_poisson_vect.add_double(relax_poisson, 0) ;
00147 par_poisson_vect.add_double(precis_poisson, 1) ;
00148 par_poisson_vect.add_cmp_mod( ssjm1_khi ) ;
00149 par_poisson_vect.add_tenseur_mod( ssjm1_wshift ) ;
00150 par_poisson_vect.add_int_mod(niter, 0) ;
00151
00152
00153 Param par_adapt ;
00154 int nitermax = 100 ;
00155 int niter_adapt ;
00156 int adapt_flag = (adapt) ? 1 : 0 ;
00157 int nz_search = nzet + 1 ;
00158 double precis_secant = 1.e-14 ;
00159 double alpha_r ;
00160 double reg_map = 1. ;
00161 int k_b ;
00162 int j_b ;
00163 Tbl ent_limit(nzet) ;
00164
00165 par_adapt.add_int(nitermax, 0) ;
00166 par_adapt.add_int(nzet, 1) ;
00167 par_adapt.add_int(nz_search, 2) ;
00168 par_adapt.add_int(adapt_flag, 3) ;
00169 par_adapt.add_int(j_b, 4) ;
00170 par_adapt.add_int(k_b, 5) ;
00171 par_adapt.add_int_mod(niter_adapt, 0) ;
00172 par_adapt.add_double(precis_secant, 0) ;
00173 par_adapt.add_double(reg_map, 1) ;
00174 par_adapt.add_double(alpha_r, 2) ;
00175 par_adapt.add_tbl(ent_limit, 0) ;
00176
00177
00178
00179
00180
00181
00182 Tenseur ent_jm1 = ent ;
00183 Tenseur source(mp) ;
00184
00185 Tenseur source_shift(mp, 1, CON, ref_triad) ;
00186
00187
00188
00189
00190
00191
00192 for(int mer=0 ; mer<mermax ; mer++ ) {
00193
00194 cout << "-----------------------------------------------" << endl ;
00195 cout << "step: " << mer << endl ;
00196 cout << "diff_ent = " << diff_ent << endl ;
00197
00198
00199
00200
00201
00202 if (irrotational) {
00203 diff_vel_pot = velocity_potential(mermax_potvit, precis_poisson,
00204 relax_potvit) ;
00205 }
00206
00207
00208
00209
00210
00211 int nt = mg->get_nt(nzet-1) ;
00212 int np = mg->get_np(nzet-1) ;
00213 int nr = mg->get_nr(nzet-1) ;
00214
00215
00216 double hc = exp(ent_c) ;
00217 double gamma_c = exp(loggam())(0,0,0,0) ;
00218 double gamma_0_c = exp(-pot_centri())(0,0,0,0) ;
00219 double n_auto_c = n_auto()(0,0,0,0) ;
00220 double n_comp_c = n_comp()(0,0,0,0) ;
00221
00222 double alpha_square = 0 ;
00223 double constante = 0;
00224 for (int k=0; k<np; k++) {
00225 for (int j=0; j<nt; j++) {
00226
00227
00228 double gamma_b = exp(loggam())(nzet-1,k,j,nr-1) ;
00229 double gamma_0_b = exp(-pot_centri())(nzet-1,k,j,nr-1) ;
00230 double n_auto_b = n_auto()(nzet-1,k,j,nr-1) ;
00231 double n_comp_b = n_comp()(nzet-1,k,j,nr-1) ;
00232
00233
00234 double alpha_square_courant = (gamma_0_c*gamma_b*n_comp_b - hc*gamma_c*gamma_0_b*n_comp_c) /
00235 (hc*gamma_c*gamma_0_b*n_auto_c-gamma_0_c*gamma_b*n_auto_b) ;
00236 double constante_courant = gamma_b*(n_comp_b+alpha_square_courant*n_auto_b)/gamma_0_b ;
00237
00238 if (alpha_square_courant > alpha_square) {
00239 alpha_square = alpha_square_courant ;
00240 k_b = k ;
00241 j_b = j ;
00242 constante = constante_courant ;
00243 }
00244 }
00245 }
00246
00247 alpha_r = sqrt(alpha_square) ;
00248 cout << "Adaptation : " << k_b << " " << j_b << " " << alpha_r << endl ;
00249
00250
00251 Tenseur potentiel (constante*exp(-loggam-pot_centri)/(n_auto*alpha_square+n_comp)) ;
00252 potentiel.set_std_base() ;
00253 for (int l=nzet+1 ; l<nz ; l++)
00254 potentiel.set().va.set(l) = 1 ;
00255
00256 Map_et mp_prev = mp_et ;
00257 ent = log(potentiel) ;
00258 ent.set_std_base() ;
00259 ent().va.smooth(nzet, (ent.set().va)) ;
00260
00261 ent_limit.set_etat_qcq() ;
00262 for (int l=0; l<nzet; l++) {
00263 ent_limit.set(l) = ent()(l, k_b, j_b, nr-1) ;
00264 }
00265
00266
00267 mp.adapt(ent(), par_adapt, 4) ;
00268 mp_prev.homothetie(alpha_r) ;
00269
00270 for (int l=nzet ; l<nz-1 ; l++)
00271 mp.resize(l, 1./alpha_r) ;
00272 mp.reevaluate_symy (&mp_prev, nzet, ent.set()) ;
00273
00274
00275
00276
00277
00278 equation_of_state() ;
00279
00280
00281
00282
00283
00284 hydro_euler() ;
00285
00286
00287
00288
00289
00290
00291
00292 Tbl diff_ent_tbl = diffrel( ent(), ent_jm1() ) ;
00293 diff_ent = diff_ent_tbl(0) ;
00294 for (int l=1; l<nzet; l++) {
00295 diff_ent += diff_ent_tbl(l) ;
00296 }
00297 diff_ent /= nzet ;
00298
00299 ent_jm1 = ent ;
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310 Tenseur confpsi_q = pow(confpsi, 4.) ;
00311 Tenseur confpsi_c = pow(confpsi, 5.) ;
00312
00313 if (relativistic) {
00314 Tenseur tmp = flat_scalar_prod(tkij_tot, tkij_auto) ;
00315 Tenseur kk (mp) ;
00316 kk = 0 ;
00317 Tenseur tmp2(mp) ;
00318 tmp2.set_etat_qcq() ;
00319 for (int i=0 ; i<3 ; i++) {
00320 tmp2.set() = tmp(i, i) ;
00321 kk = kk + tmp2 ;
00322 }
00323
00324 source = qpig * nnn * confpsi_q * (ener_euler + s_euler)
00325 + nnn * confpsi_q * kk
00326 - 2.*flat_scalar_prod(d_confpsi_auto+d_confpsi_comp, d_n_auto) /
00327 confpsi ;
00328 }
00329 else {
00330 cout <<
00331 "WARNING : Et_bin_nsbh is for the relativistic calculation"
00332 << endl ;
00333 abort() ;
00334 }
00335
00336 source.set_std_base() ;
00337
00338
00339
00340 Cmp n_auto_old (n_auto()) ;
00341 source().poisson(par_poisson1, n_auto.set()) ;
00342 n_auto.set() = n_auto() + 0.5 ;
00343
00344
00345
00346
00347 Tbl tdiff_lapse = diffrel(n_auto(), n_auto_old) ;
00348 cout <<
00349 "Relative difference on n_auto : "
00350 << endl ;
00351 for (int l=0; l<nz; l++) {
00352 cout << tdiff_lapse(l) << " " ;
00353 }
00354 cout << endl ;
00355 diff_lapse = max(abs(tdiff_lapse)) ;
00356
00357 if (relativistic) {
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368 Tenseur tmp = flat_scalar_prod(tkij_tot, tkij_auto) ;
00369 Tenseur kk (mp) ;
00370 kk = 0 ;
00371 Tenseur tmp2(mp) ;
00372 tmp2.set_etat_qcq() ;
00373 for (int i=0 ; i<3 ; i++) {
00374 tmp2.set() = tmp(i, i) ;
00375 kk = kk + tmp2 ;
00376 }
00377
00378 source = -0.5 * qpig * confpsi_c * ener_euler
00379 - 0.125 * confpsi_c * kk ;
00380
00381 source.set_std_base() ;
00382
00383
00384
00385 Cmp psi_old (confpsi_auto()) ;
00386 source().poisson(par_poisson2, confpsi_auto.set()) ;
00387 confpsi_auto.set() = confpsi_auto() + 0.5 ;
00388
00389
00390
00391
00392
00393 Tbl tdiff_confpsi = diffrel(confpsi_auto(), psi_old) ;
00394 cout <<
00395 "Relative difference on confpsi_auto : "
00396 << endl ;
00397 for (int l=0; l<nz; l++) {
00398 cout << tdiff_confpsi(l) << " " ;
00399 }
00400 cout << endl ;
00401 diff_confpsi = max(abs(tdiff_confpsi)) ;
00402
00403
00404
00405
00406
00407
00408
00409
00410 Tenseur vtmp = d_n_auto -6. * nnn * d_confpsi_auto / confpsi ;
00411 source_shift = 4.*qpig * nnn *confpsi_q *(ener_euler + press)
00412 * u_euler ;
00413 if (tkij_tot.get_etat() != ETATZERO)
00414 source_shift = source_shift + 2.* flat_scalar_prod(tkij_tot, vtmp) ;
00415 source_shift.set_std_base() ;
00416
00417
00418
00419 for (int i=0 ; i<3 ; i++)
00420 if (source_shift(i).get_etat() != ETATZERO)
00421 source_shift.set(i).va.coef_i() ;
00422
00423 for (int i=0; i<3; i++)
00424 if ((source_shift(i).get_etat() != ETATZERO) && (source_shift(i).va.c->t[nz-1]->get_etat() != ETATZERO))
00425 source_shift.set(i).filtre(4) ;
00426 for (int i=0; i<3; i++) {
00427 if(source_shift(i).dz_nonzero()) {
00428 assert( source_shift(i).get_dzpuis() == 4 ) ;
00429 }
00430 else{
00431 (source_shift.set(i)).set_dzpuis(4) ;
00432 }
00433 }
00434
00435
00436
00437 double lambda_shift = double(1) / double(3) ;
00438
00439 source_shift.change_triad(mp.get_bvect_cart()) ;
00440 Tenseur shift_old (shift_auto) ;
00441 source_shift.poisson_vect_oohara(lambda_shift, par_poisson_vect,
00442 shift_auto, khi_shift) ;
00443 shift_auto.change_triad(ref_triad) ;
00444
00445
00446
00447
00448
00449
00450 Tbl tdiff_shift_x = diffrel(shift_auto(0), shift_old(0)) ;
00451 Tbl tdiff_shift_y = diffrel(shift_auto(1), shift_old(1)) ;
00452 Tbl tdiff_shift_z = diffrel(shift_auto(2), shift_old(2)) ;
00453
00454 cout <<
00455 "Relative difference on shift_auto : "
00456 << endl ;
00457 cout << "x component : " ;
00458 for (int l=0; l<nz; l++) {
00459 cout << tdiff_shift_x(l) << " " ;
00460 }
00461 cout << endl ;
00462 cout << "y component : " ;
00463 for (int l=0; l<nz; l++) {
00464 cout << tdiff_shift_y(l) << " " ;
00465 }
00466 cout << endl ;
00467 cout << "z component : " ;
00468 for (int l=0; l<nz; l++) {
00469 cout << tdiff_shift_z(l) << " " ;
00470 }
00471 cout << endl ;
00472
00473 diff_shift_x = max(abs(tdiff_shift_x)) ;
00474 diff_shift_y = max(abs(tdiff_shift_y)) ;
00475 diff_shift_z = max(abs(tdiff_shift_z)) ;
00476 }
00477
00478
00479 }
00480
00481
00482
00483
00484 }
00485
00486
00487 void Et_bin_nsbh::equilibrium_nsbh (double, int, int, double,
00488 int, double, double, const Tbl&, Tbl&) {
00489
00490 cout << "Not implemented !" << endl ;
00491 abort() ;
00492 }