bin_ns_bh_coal.C

00001 /*
00002  *   Copyright (c) 2004 Philippe Grandclement
00003  *
00004  *   This file is part of LORENE.
00005  *
00006  *   LORENE is free software; you can redistribute it and/or modify
00007  *   it under the terms of the GNU General Public License as published by
00008  *   the Free Software Foundation; either version 2 of the License, or
00009  *   (at your option) any later version.
00010  *
00011  *   LORENE is distributed in the hope that it will be useful,
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *   GNU General Public License for more details.
00015  *
00016  *   You should have received a copy of the GNU General Public License
00017  *   along with LORENE; if not, write to the Free Software
00018  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 
00022 
00023 char bin_ns_bh_coal_C[] = "$Header: /cvsroot/Lorene/C++/Source/Bin_ns_bh/bin_ns_bh_coal.C,v 1.10 2007/04/24 20:13:53 f_limousin Exp $" ;
00024 
00025 /*
00026  * $Id: bin_ns_bh_coal.C,v 1.10 2007/04/24 20:13:53 f_limousin Exp $
00027  * $Log: bin_ns_bh_coal.C,v $
00028  * Revision 1.10  2007/04/24 20:13:53  f_limousin
00029  * Implementation of Dirichlet and Neumann BC for the lapse
00030  *
00031  * Revision 1.9  2006/09/05 13:39:43  p_grandclement
00032  * update of the bin_ns_bh project
00033  *
00034  * Revision 1.8  2006/06/23 07:09:24  p_grandclement
00035  * Addition of spinning black hole
00036  *
00037  * Revision 1.7  2006/06/01 12:47:52  p_grandclement
00038  * update of the Bin_ns_bh project
00039  *
00040  * Revision 1.6  2006/04/27 09:12:33  p_grandclement
00041  * First try at irrotational black holes
00042  *
00043  * Revision 1.5  2006/04/25 07:21:57  p_grandclement
00044  * Various changes for the NS_BH project
00045  *
00046  * Revision 1.4  2006/03/30 07:33:45  p_grandclement
00047  * *** empty log message ***
00048  *
00049  * Revision 1.3  2005/12/01 12:59:10  p_grandclement
00050  * Files for bin_ns_bh project
00051  *
00052  * Revision 1.2  2005/10/18 13:12:32  p_grandclement
00053  * update of the mixted binary codes
00054  *
00055  * Revision 1.1  2005/08/29 15:10:15  p_grandclement
00056  * Addition of things needed :
00057  *   1) For BBH with different masses
00058  *   2) Provisory files for the mixted binaries (Bh and NS) : THIS IS NOT
00059  *   WORKING YET !!!
00060  *
00061  *
00062  * $Header: /cvsroot/Lorene/C++/Source/Bin_ns_bh/bin_ns_bh_coal.C,v 1.10 2007/04/24 20:13:53 f_limousin Exp $
00063  *
00064  */
00065 
00066 //standard
00067 #include <stdlib.h>
00068 
00069 // Lorene
00070 #include "tenseur.h"
00071 #include "bin_ns_bh.h"
00072 #include "unites.h"
00073 #include "graphique.h"
00074 
00075 void Bin_ns_bh::coal (double precis, double relax, int itemax_equil, 
00076               int itemax_mp_et, double ent_c_init, double seuil_masses,
00077               double dist, double m1, double m2, double spin_cible, 
00078               double scale_ome_local, const int sortie, int bound_nn,
00079               double lim_nn) {
00080     
00081     using namespace Unites ;
00082     
00083     int nz_bh = hole.mp.get_mg()->get_nzone() ;
00084     int nz_ns = star.mp.get_mg()->get_nzone() ;
00085     
00086     // Distance initiale 
00087     double distance = fabs(hole.mp.get_ori_x()-star.mp.get_ori_x()) ;
00088     double mass_ns =  star.mass_g() * ggrav;
00089     double mass_bh =  hole.masse_adm_seul() ;
00090     double axe_pos = star.mp.get_ori_x() ;
00091     double scale_linear = (mass_ns+mass_bh)/2.*distance*omega ;
00092 
00093     char name_iteration[40] ;
00094     char name_correction[40] ;
00095     char name_viriel[40] ;
00096     char name_ome [40] ;
00097     char name_linear[40] ;
00098     char name_axe[40] ;
00099     char name_error_m1[40] ;
00100     char name_error_m2[40] ; 
00101     char name_hor[40] ;
00102     char name_entc[40] ;
00103     char name_dist[40] ;
00104     char name_spin[40] ;
00105     char name_ome_local[40] ;
00106     
00107     sprintf(name_iteration, "ite.dat") ;
00108     sprintf(name_correction, "cor.dat") ;
00109     sprintf(name_viriel, "vir.dat") ;
00110     sprintf(name_ome, "ome.dat") ;
00111     sprintf(name_linear, "linear.dat") ;
00112     sprintf(name_axe, "axe.dat") ;
00113     sprintf(name_error_m1, "error_m_bh.dat") ;
00114     sprintf(name_error_m2, "error_m_ns.dat") ;
00115     sprintf(name_hor, "hor.dat") ;
00116     sprintf(name_entc, "entc.dat") ;
00117     sprintf(name_dist, "distance.dat") ;
00118     sprintf(name_spin, "spin.dat") ;
00119     sprintf(name_ome_local, "ome_local.dat") ;
00120     
00121     ofstream fiche_iteration(name_iteration) ;
00122     fiche_iteration.precision(8) ; 
00123 
00124     ofstream fiche_correction(name_correction) ;
00125     fiche_correction.precision(8) ; 
00126     
00127     ofstream fiche_viriel(name_viriel) ;
00128     fiche_viriel.precision(8) ; 
00129     
00130     ofstream fiche_ome(name_ome) ;
00131     fiche_ome.precision(8) ; 
00132    
00133     ofstream fiche_linear(name_linear) ;
00134     fiche_linear.precision(8) ; 
00135      
00136     ofstream fiche_axe(name_axe) ;
00137     fiche_axe.precision(8) ; 
00138     
00139     ofstream fiche_error_m1 (name_error_m1) ;
00140     fiche_error_m1.precision(8) ;
00141       
00142     ofstream fiche_error_m2 (name_error_m2) ;
00143     fiche_error_m2.precision(8) ;
00144     
00145     ofstream fiche_hor (name_hor) ;
00146     fiche_hor.precision(8) ;
00147       
00148     ofstream fiche_entc (name_entc) ;
00149     fiche_entc.precision(8) ; 
00150     
00151     ofstream fiche_dist (name_dist) ;
00152     fiche_dist.precision(8) ;
00153     
00154     ofstream fiche_spin (name_spin) ;
00155     fiche_spin.precision(8) ;
00156     
00157     ofstream fiche_ome_local (name_ome_local) ;
00158     fiche_ome_local.precision(8) ;
00159     
00160     bool loop = true ;     
00161     bool search_masses = false ;
00162     double ent_c = ent_c_init ;
00163     
00164     Cmp shift_bh_old (hole.mp) ;
00165     Cmp shift_ns_old (star.mp) ;
00166     
00167     double erreur = 1 ;
00168     
00169     int conte = 0 ;
00170     
00171     double old_mass_ns ;
00172     mass_ns = star.mass_b() ;
00173     double spin_old ;
00174     double spin = 1;
00175     bool adapt = true ;
00176 
00177     while (loop) {
00178       
00179       spin_old = spin ;
00180         spin = hole.local_momentum() ;
00181         if (sortie !=0) {
00182             fiche_ome_local << conte << " " << hole.omega_local << endl ;
00183         fiche_spin << conte << " " << spin/m1/m1 << endl ;
00184         }
00185         
00186     double conv_spin = fabs(spin-spin_old) ;
00187         double error_spin = spin - spin_cible ;
00188     double rel_diff_spin = (spin_cible==0) ? fabs(error_spin) : 
00189       fabs(error_spin)/spin_cible ;
00190     if  ((conv_spin*2<rel_diff_spin) && (search_masses) && 
00191          hole.get_rot_state() != COROT) {
00192         double func = scale_ome_local*log((2+error_spin)/(2+2*error_spin));
00193         hole.set_omega_local(hole.omega_local+func) ;
00194     }
00195 
00196     old_mass_ns = mass_ns ;
00197     
00198     if (hole.get_shift_auto().get_etat() != ETATZERO)
00199         shift_bh_old = hole.get_shift_auto()(0) ;
00200     else
00201         shift_bh_old = 0 ;
00202         
00203     if (star.get_shift_auto().get_etat() != ETATZERO)
00204         shift_ns_old = star.get_shift_auto()(0) ;
00205     else
00206         shift_ns_old = 0 ;
00207         
00208     star.kinematics(omega, x_axe) ;
00209         star.fait_d_psi() ;
00210         star.hydro_euler() ;
00211     
00212         Tbl diff (7) ;
00213     diff.set_etat_qcq() ;
00214     int ite ;
00215 
00216 
00217     star.equilibrium_nsbh (adapt, ent_c, ite, itemax_equil, itemax_mp_et, 
00218                    relax, itemax_mp_et, relax, diff) ;
00219 
00220     hole.update_metric(star) ;    
00221     
00222     hole.equilibrium (star, precis, relax, bound_nn, lim_nn) ;
00223         cout << "Apres equilibrium" << endl ;   
00224     
00225         star.update_metric(hole) ;
00226     cout << "Apres star::update_metric" << endl ;
00227     
00228     star.update_metric_der_comp(hole) ;
00229     cout << "Apres star::update_metric_der_comp" << endl ;  
00230     fait_tkij(bound_nn, lim_nn) ;
00231     cout << "Apres Bin_ns_bh::fait_tkij" << endl ;     
00232     
00233     erreur = 0 ;
00234     Tbl diff_bh (diffrelmax (shift_bh_old, hole.get_shift_auto()(0))) ;
00235     for (int i=1 ; i<nz_bh ; i++)
00236         if (diff_bh(i) > erreur)
00237         erreur = diff_bh(i) ;
00238     Tbl diff_ns (diffrelmax (shift_ns_old, star.get_shift_auto()(0))) ;
00239     for (int i=0 ; i<nz_ns ; i++)
00240         if (diff_ns(i) > erreur)
00241         erreur = diff_ns(i) ;
00242     
00243     if (erreur<seuil_masses)
00244         search_masses = true ;
00245         
00246     mass_ns = star.mass_b() ;
00247         
00248     cout << "Avant viriel" << endl ;
00249         double error_viriel = viriel() ;
00250     cout << "Apres viriel" << endl ;
00251     double error_linear = linear_momentum_systeme_inf()(1)/scale_linear ;
00252     cout << "Apres linear" << endl ;
00253     double error_m1 = 1.-sqrt(hole.area()/16./M_PI)/m1 ;
00254     cout << "Apres Mbh" << endl ;
00255     double error_m2 = 1 - mass_ns/m2 ;
00256     cout << "Apres Mns" << endl ;
00257     
00258     if (sortie != 0) {
00259         fiche_iteration << conte << " " << erreur << endl ;
00260         fiche_correction << conte << " " << hole.regul << endl ;
00261         fiche_viriel << conte << " " << error_viriel << endl ;
00262         fiche_linear << conte << " " << error_linear << endl ;
00263         fiche_error_m1 << conte << " " << error_m1 << endl ;
00264         fiche_error_m2 << conte << " " << error_m2 << endl ; 
00265         fiche_hor << conte << " " << hole.mp.val_r(0, 1, 0,0) << endl ;
00266         fiche_entc << conte << " " << ent_c << endl ;
00267         fiche_dist << conte << " " << distance << endl ;    
00268         fiche_ome << conte << " " << omega  << endl ;
00269         fiche_axe << conte << " " << axe_pos << endl ;
00270         }
00271     
00272     // The axis position
00273     double scaling_axe = pow((2+error_linear)/(2+2*error_linear), 0.1) ;
00274     axe_pos *= scaling_axe ;
00275     star.set_mp().set_ori (axe_pos, 0, 0) ;
00276         hole.set_mp().set_ori (-distance + axe_pos, 0, 0) ;
00277 
00278     // Value of omega
00279     double new_ome = star.compute_angul() ;
00280         if (new_ome !=0) {
00281         set_omega(new_ome) ;
00282         if (hole.get_rot_state() == COROT)
00283           hole.set_omega_local(new_ome) ;
00284     }
00285         
00286     // The right distance
00287     double error_dist = (distance-dist)/dist ;
00288     double scale_d = pow((2+error_dist)/(2+2*error_dist), 0.2) ;
00289     distance *= scale_d ;
00290 
00291     
00292     // Converge to the right masses :
00293     if (search_masses) {
00294         
00295         double scaling_r = pow((2-error_m1)/(2-2*error_m1), 0.25) ;
00296         hole.mp.homothetie_interne(scaling_r) ;
00297         hole.set_rayon(hole.get_rayon()*scaling_r) ;
00298     }
00299     
00300     // The case of the NS :
00301     double convergence = fabs(mass_ns - old_mass_ns)/mass_ns ;
00302     double rel_diff = fabs(error_m2) ;
00303     if ((search_masses) && (convergence*2 < rel_diff)) {
00304           double scaling_ent = pow((2-error_m2)/(2-2*error_m2), 1) ;
00305           ent_c *= scaling_ent ;    
00306         
00307     }
00308 
00309 
00310     
00311     cout << "PAS TOTAL : " << conte << " DIFFERENCE : " << erreur << endl ;
00312     //if (erreur < 1e-4)
00313       //adapt = false ;
00314 
00315     if (erreur < precis)
00316         loop = false ;
00317     conte ++ ;
00318     }
00319     
00320    
00321     fiche_iteration.close() ;
00322     fiche_correction.close() ;
00323     fiche_viriel.close() ;
00324     fiche_ome.close() ;
00325     fiche_linear.close() ;
00326     fiche_axe.close() ;
00327     fiche_error_m1.close() ;
00328     fiche_error_m2.close() ;
00329     fiche_hor.close() ;
00330     fiche_entc.close() ;
00331     fiche_dist.close() ;
00332     fiche_spin.close() ;
00333     fiche_ome_local.close() ;
00334 }

Generated on Tue Feb 7 01:35:14 2012 for LORENE by  doxygen 1.4.6