binary_dirac.C

00001 /*
00002  * Methods of Bin_star::dirac_gauge
00003  *
00004  * (see file star.h for documentation)
00005  *
00006  */
00007 
00008 /*
00009  *   Copyright (c) 2005 Francois Limousin
00010  *
00011  *   This file is part of LORENE.
00012  *
00013  *   LORENE is free software; you can redistribute it and/or modify
00014  *   it under the terms of the GNU General Public License as published by
00015  *   the Free Software Foundation; either version 2 of the License, or
00016  *   (at your option) any later version.
00017  *
00018  *   LORENE is distributed in the hope that it will be useful,
00019  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  *   GNU General Public License for more details.
00022  *
00023  *   You should have received a copy of the GNU General Public License
00024  *   along with LORENE; if not, write to the Free Software
00025  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026  *
00027  */
00028 
00029 char binary_dirac_C[] = "$Header: /cvsroot/Lorene/C++/Source/Binary/binary_dirac.C,v 1.2 2006/04/11 14:25:15 f_limousin Exp $" ;
00030 
00031 /*
00032  * $Id: binary_dirac.C,v 1.2 2006/04/11 14:25:15 f_limousin Exp $
00033  * $Log: binary_dirac.C,v $
00034  * Revision 1.2  2006/04/11 14:25:15  f_limousin
00035  * New version of the code : improvement of the computation of some
00036  * critical sources, estimation of the dirac gauge, helical symmetry...
00037  *
00038  * Revision 1.1  2005/11/08 20:17:01  f_limousin
00039  * Function used to impose Dirac gauge during an iteration.
00040  *
00041  *
00042  * $Header: /cvsroot/Lorene/C++/Source/Binary/binary_dirac.C,v 1.2 2006/04/11 14:25:15 f_limousin Exp $ *
00043  */
00044 
00045 
00046 // Headers Lorene
00047 #include "tenseur.h"
00048 #include "binary.h"
00049 #include "star.h"
00050 #include "graphique.h"
00051 #include "utilitaires.h"
00052 #include "param.h"
00053 
00054 
00055 void Binary::dirac_gauge() {
00056 
00057     int nz = star1.mp.get_mg()->get_nzone() ;
00058     int nr = star1.mp.get_mg()->get_nr(0);
00059     int nt = star1.mp.get_mg()->get_nt(0);
00060     int np = star1.mp.get_mg()->get_np(0);
00061 
00062     // Importations 
00063     // ------------
00064 
00065     // Star 1
00066 
00067     star1.hij_comp.set_triad(star1.mp.get_bvect_cart()) ;
00068     Sym_tensor comp_hij1(star2.hij_auto) ;
00069     comp_hij1.change_triad(star2.mp.get_bvect_cart()) ;
00070     comp_hij1.change_triad(star1.mp.get_bvect_cart()) ;
00071 
00072     assert ( *(star1.hij_comp.get_triad()) == *(comp_hij1.get_triad())) ;
00073 
00074     for(int i=1; i<=3; i++) 
00075     for(int j=i; j<=3; j++) {
00076             star1.hij_comp.set(i,j).set_etat_qcq() ;
00077         star1.hij_comp.set(i,j).import( (comp_hij1)(i,j) ) ;
00078     }
00079     star1.hij_comp.std_spectral_base() ;//set the bases for spectral expansions
00080 
00081      for(int i=1; i<=3; i++) 
00082     for(int j=i; j<=3; j++)    
00083         star1.hij.set(i,j) = star1.hij_auto(i,j) + star1.hij_comp(i,j) ;
00084 
00085     // Star 2
00086 
00087     star2.hij_comp.set_triad(star2.mp.get_bvect_cart()) ;
00088     Sym_tensor comp_hij2(star1.hij_auto) ;
00089     comp_hij2.change_triad(star1.mp.get_bvect_cart()) ;
00090     comp_hij2.change_triad(star2.mp.get_bvect_cart()) ;
00091 
00092     assert ( *(star2.hij_comp.get_triad()) == *(comp_hij2.get_triad())) ;
00093 
00094     for(int i=1; i<=3; i++) 
00095     for(int j=i; j<=3; j++) {
00096             star2.hij_comp.set(i,j).set_etat_qcq() ;
00097         star2.hij_comp.set(i,j).import( (comp_hij2)(i,j) ) ;
00098     }
00099     star2.hij_comp.std_spectral_base() ;//set the bases for spectral expansions
00100 
00101      for(int i=1; i<=3; i++) 
00102     for(int j=i; j<=3; j++)    
00103         star2.hij.set(i,j) = star2.hij_auto(i,j) + star2.hij_comp(i,j) ;
00104      
00105      // -----------------------------------------
00106      // Resolution of the Poisson equation for xi
00107      // -----------------------------------------
00108 
00109      cout << "Function Binary::dirac_gauge()" << endl ;
00110 
00111      // Star 1
00112      // ----------
00113 
00114      int mermax = 50 ;
00115      double precis = 1e-5 ;
00116      double precis_poisson = 1e-14 ;
00117      double relax_poisson = 1.5 ;
00118      int mer_poisson = 4 ;
00119 
00120      Scalar rr1 (star1.mp) ;     
00121      rr1 = star1.mp.r ;
00122      Scalar rr2 (star2.mp) ;     
00123      rr2 = star2.mp.r ;
00124 
00125      Vector xi1(star1.mp, CON, star1.mp.get_bvect_cart()) ;
00126      xi1.set(1) = 0. ;
00127      xi1.set(2) = 0. ;
00128      xi1.set(3) = 0. ;
00129      xi1.std_spectral_base() ;
00130      Vector xi1_old(xi1) ;
00131      
00132      Scalar ssjm1_xi11 (xi1(1)) ;
00133      Scalar ssjm1_xi12 (xi1(2)) ;
00134      Scalar ssjm1_xi13 (xi1(3)) ;
00135 
00136 
00137      for(int mer=0; mer<mermax; mer++){
00138 
00139        xi1_old = xi1 ;
00140 
00141        // Function exp(-(r-r_0)^2/sigma^2)
00142        // --------------------------------
00143        
00144        double r0_1 = star1.mp.val_r(nz-2, 1, 0, 0) ;
00145        double sigma = 3.*r0_1 ;
00146          
00147        Scalar ff1 (star1.mp) ;
00148        ff1 = exp( -(rr1 - r0_1)*(rr1 - r0_1)/sigma/sigma ) ;
00149        for (int ii=0; ii<nz-1; ii++)
00150        ff1.set_domain(ii) = 1. ;
00151        ff1.set_outer_boundary(nz-1, 0) ;
00152        ff1.std_spectral_base() ;
00153        
00154        // Source 
00155        
00156        Vector source_xi1 (star1.hij.divergence(star1.flat)) ;
00157        source_xi1.inc_dzpuis() ;    // dzpuis = 3
00158      
00159        double lambda = 0. ;
00160        Vector source_reg1 = - (1./3. - lambda) * xi1.divergence(star1.flat)
00161      .derive_con(star1.flat)  ;
00162        source_xi1 += source_reg1 ; 
00163    
00164        // Resolution of the Poisson equations
00165   
00166        Cmp ssjm1xi11 (ssjm1_xi11) ;
00167        Cmp ssjm1xi12 (ssjm1_xi12) ;
00168        Cmp ssjm1xi13 (ssjm1_xi13) ;
00169        ssjm1xi11.set_etat_qcq() ;
00170        ssjm1xi12.set_etat_qcq() ;
00171        ssjm1xi13.set_etat_qcq() ;
00172 
00173        Param par_xi11 ;
00174        int niter ;
00175        par_xi11.add_int(mer_poisson,  0) ;  // maximum number of iterations
00176        par_xi11.add_double(relax_poisson,  0) ; // relaxation parameter
00177        par_xi11.add_double(precis_poisson, 1) ; // required precision
00178        par_xi11.add_int_mod(niter, 0) ; // number of iterations actually used 
00179        par_xi11.add_cmp_mod(ssjm1xi11) ; 
00180  
00181        Param par_xi12 ;
00182        par_xi12.add_int(mer_poisson,  0) ;  // maximum number of iterations
00183        par_xi12.add_double(relax_poisson,  0) ; // relaxation parameter
00184        par_xi12.add_double(precis_poisson, 1) ; // required precision
00185        par_xi12.add_int_mod(niter, 0) ; // number of iterations actually used 
00186        par_xi12.add_cmp_mod(ssjm1xi12) ; 
00187 
00188        Param par_xi13 ;
00189        par_xi13.add_int(mer_poisson,  0) ;  // maximum number of iterations
00190        par_xi13.add_double(relax_poisson,  0) ; // relaxation parameter
00191        par_xi13.add_double(precis_poisson, 1) ; // required precision
00192        par_xi13.add_int_mod(niter, 0) ; // number of iterations actually used 
00193        par_xi13.add_cmp_mod(ssjm1xi13) ; 
00194   
00195        source_xi1(1).poisson(par_xi11, xi1.set(1)) ;
00196        source_xi1(2).poisson(par_xi12, xi1.set(2)) ;
00197        source_xi1(3).poisson(par_xi13, xi1.set(3)) ;
00198 
00199        ssjm1_xi11 = ssjm1xi11 ;
00200        ssjm1_xi12 = ssjm1xi12 ;
00201        ssjm1_xi13 = ssjm1xi13 ;
00202 
00203        // Check: has the equation for xi been correctly solved ?
00204        // --------------------------------------------------------------
00205 
00206        Vector lap_xi1 = (xi1.derive_con(star1.flat)).divergence(star1.flat) 
00207      + lambda* xi1.divergence(star1.flat).derive_con(star1.flat) ;
00208 
00209        Tbl tdiff_xi1_x = diffrel(lap_xi1(1), source_xi1(1)) ; 
00210        Tbl tdiff_xi1_y = diffrel(lap_xi1(2), source_xi1(2)) ; 
00211        Tbl tdiff_xi1_z = diffrel(lap_xi1(3), source_xi1(3)) ; 
00212        
00213        cout << 
00214      "Relative error in the resolution of the equation for xi1 : "
00215         << endl ; 
00216        cout << "x component : " ;
00217        for (int l=0; l<nz; l++) {
00218      cout << tdiff_xi1_x(l) << "  " ; 
00219     }
00220        cout << endl ;
00221        cout << "y component : " ;
00222        for (int l=0; l<nz; l++) {
00223      cout << tdiff_xi1_y(l) << "  " ; 
00224        }
00225        cout << endl ;
00226        cout << "z component : " ;
00227        for (int l=0; l<nz; l++) {
00228      cout << tdiff_xi1_z(l) << "  " ; 
00229        }
00230        cout << endl ;
00231        
00232        
00233        double erreur = 0 ;
00234        Tbl diff (diffrelmax (xi1_old(1), xi1(1))) ;
00235        for (int i=1 ; i<nz ; i++)
00236      if (diff(i) > erreur)
00237        erreur = diff(i) ;
00238        
00239        cout << "Step : " << mer << " Difference : " << erreur << endl ;
00240        cout << "-------------------------------------" << endl ;
00241        if (erreur < precis)
00242      mer = mermax ;
00243 
00244      }
00245 
00246      // Star 2
00247      // ----------
00248 
00249      Vector xi2(star2.mp, CON, star2.mp.get_bvect_cart()) ;
00250      xi2.set(1) = 0. ;
00251      xi2.set(2) = 0. ;
00252      xi2.set(3) = 0. ;
00253      xi2.std_spectral_base() ;
00254      Vector xi2_old(xi2) ;
00255      
00256      Scalar ssjm1_xi21 (xi2(1)) ;
00257      Scalar ssjm1_xi22 (xi2(2)) ;
00258      Scalar ssjm1_xi23 (xi2(3)) ;
00259 
00260 
00261      for(int mer=0; mer<mermax; mer++){
00262 
00263        xi2_old = xi2 ;
00264 
00265        // Function exp(-(r-r_0)^2/sigma^2)
00266        // --------------------------------
00267        
00268        double r0_2 = star2.mp.val_r(nz-2, 1, 0, 0) ;
00269        double sigma = 3.*r0_2 ;
00270          
00271        Scalar ff2 (star2.mp) ;
00272        ff2 = exp( -(rr2 - r0_2)*(rr2 - r0_2)/sigma/sigma ) ;
00273        for (int ii=0; ii<nz-1; ii++)
00274        ff2.set_domain(ii) = 1. ;
00275        ff2.set_outer_boundary(nz-1, 0) ;
00276        ff2.std_spectral_base() ;
00277     
00278        // Source
00279 
00280        Vector source_xi2 (star2.hij.divergence(star2.flat)) ;
00281        source_xi2.inc_dzpuis() ;    // dzpuis = 3
00282      
00283        double lambda = 0. ;
00284        Vector source_reg2 = - (1./3. - lambda) * xi2.divergence(star2.flat)
00285      .derive_con(star2.flat)  ;
00286        source_xi2 += source_reg2 ;
00287 
00288        // Resolution of the Poisson equations
00289 
00290        Cmp ssjm1xi21 (ssjm1_xi21) ;
00291        Cmp ssjm1xi22 (ssjm1_xi22) ;
00292        Cmp ssjm1xi23 (ssjm1_xi23) ;
00293        ssjm1xi21.set_etat_qcq() ;
00294        ssjm1xi22.set_etat_qcq() ;
00295        ssjm1xi23.set_etat_qcq() ;
00296 
00297        Param par_xi21 ;
00298        int niter ;
00299        par_xi21.add_int(mer_poisson,  0) ;  // maximum number of iterations
00300        par_xi21.add_double(relax_poisson,  0) ; // relaxation parameter
00301        par_xi21.add_double(precis_poisson, 1) ; // required precision
00302        par_xi21.add_int_mod(niter, 0) ; // number of iterations actually used 
00303        par_xi21.add_cmp_mod(ssjm1xi21) ; 
00304  
00305        Param par_xi22 ;
00306        par_xi22.add_int(mer_poisson,  0) ;  // maximum number of iterations
00307        par_xi22.add_double(relax_poisson,  0) ; // relaxation parameter
00308        par_xi22.add_double(precis_poisson, 1) ; // required precision
00309        par_xi22.add_int_mod(niter, 0) ; // number of iterations actually used 
00310        par_xi22.add_cmp_mod(ssjm1xi22) ; 
00311 
00312        Param par_xi23 ;
00313        par_xi23.add_int(mer_poisson,  0) ;  // maximum number of iterations
00314        par_xi23.add_double(relax_poisson,  0) ; // relaxation parameter
00315        par_xi23.add_double(precis_poisson, 1) ; // required precision
00316        par_xi23.add_int_mod(niter, 0) ; // number of iterations actually used 
00317        par_xi23.add_cmp_mod(ssjm1xi23) ; 
00318   
00319        source_xi2(1).poisson(par_xi21, xi2.set(1)) ;
00320        source_xi2(2).poisson(par_xi22, xi2.set(2)) ;
00321        source_xi2(3).poisson(par_xi23, xi2.set(3)) ;
00322 
00323        ssjm1_xi21 = ssjm1xi21 ;
00324        ssjm1_xi22 = ssjm1xi22 ;
00325        ssjm1_xi23 = ssjm1xi23 ;
00326 
00327        // Check: has the equation for xi been correctly solved ?
00328        // --------------------------------------------------------------
00329 
00330        Vector lap_xi2 = (xi2.derive_con(star2.flat)).divergence(star2.flat) 
00331      + lambda* xi2.divergence(star2.flat).derive_con(star2.flat) ;
00332       
00333        Tbl tdiff_xi2_x = diffrel(lap_xi2(1), source_xi2(1)) ; 
00334        Tbl tdiff_xi2_y = diffrel(lap_xi2(2), source_xi2(2)) ; 
00335        Tbl tdiff_xi2_z = diffrel(lap_xi2(3), source_xi2(3)) ; 
00336        
00337        cout << 
00338      "Relative error in the resolution of the equation for xi2 : "
00339         << endl ; 
00340        cout << "x component : " ;
00341        for (int l=0; l<nz; l++) {
00342      cout << tdiff_xi2_x(l) << "  " ; 
00343     }
00344        cout << endl ;
00345        cout << "y component : " ;
00346        for (int l=0; l<nz; l++) {
00347      cout << tdiff_xi2_y(l) << "  " ; 
00348        }
00349        cout << endl ;
00350        cout << "z component : " ;
00351        for (int l=0; l<nz; l++) {
00352      cout << tdiff_xi2_z(l) << "  " ; 
00353        }
00354        cout << endl ;
00355  
00356 
00357        double erreur = 0 ;
00358        Tbl diff (diffrelmax (xi2_old(1), xi2(1))) ;
00359        for (int i=1 ; i<nz ; i++)
00360      if (diff(i) > erreur)
00361        erreur = diff(i) ;
00362        
00363        cout << "Step : " << mer << " Difference : " << erreur << endl ;
00364        cout << "-------------------------------------" << endl ;
00365        if (erreur < precis)
00366      mer = mermax ;
00367 
00368      }
00369 
00370      // -----------------------------
00371      // Computation of the new metric
00372      // -----------------------------
00373 
00374      // Star 1
00375      // -------
00376 
00377      Sym_tensor guu_dirac1 (star1.mp, CON, star1.mp.get_bvect_cart()) ;
00378      guu_dirac1 = star1.gamma.con().derive_lie(xi1) ;
00379      guu_dirac1.dec_dzpuis(2) ;
00380      guu_dirac1 = guu_dirac1 + star1.gamma.con() ;
00381      star1.gamma = guu_dirac1 ;
00382      
00383      Sym_tensor gtilde_con1(star1.mp, CON, star1.mp.get_bvect_cart()) ;
00384      Sym_tensor hij_dirac1(star1.mp, CON, star1.mp.get_bvect_cart()) ;
00385 
00386      gtilde_con1 = pow(star1.gamma.determinant(), 1./3.) * guu_dirac1 ;
00387      gtilde_con1.std_spectral_base() ;
00388      for(int i=1; i<=3; i++) 
00389        for(int j=i; j<=3; j++)
00390        hij_dirac1.set(i,j) = gtilde_con1(i,j) - star1.flat.con()(i,j) ;
00391 
00392      
00393      star1.gtilde = gtilde_con1 ;
00394      star1.psi4 = pow(star1.gamma.determinant(), 1./3.) ;
00395      star1.psi4.std_spectral_base() ;
00396      
00397      cout << "norme de h_uu avant :" << endl ;
00398      for (int i=1; i<=3; i++)
00399      for (int j=1; j<=i; j++) {
00400          cout << "  Comp. " << i << " " << j << " :  " ;
00401          for (int l=0; l<nz; l++){
00402          cout << norme(star1.hij(i,j)/(nr*nt*np))(l) << " " ;
00403          }
00404          cout << endl ;
00405      }
00406      cout << endl ;
00407 
00408      cout << "norme de h_uu en jauge de dirac :" << endl ;
00409      for (int i=1; i<=3; i++)
00410      for (int j=1; j<=i; j++) {
00411          cout << "  Comp. " << i << " " << j << " :  " ;
00412          for (int l=0; l<nz; l++){
00413          cout << norme(hij_dirac1(i,j)/(nr*nt*np))(l) << " " ;
00414          }
00415          cout << endl ;
00416      }
00417      cout << endl ;
00418      
00419 
00420      // Check of the Dirac gauge
00421      // ------------------------
00422      
00423      Vector hh_dirac (star1.hij.divergence(star1.flat)) ;
00424      cout << "For comparaison H^i before computation = " << endl 
00425       << norme(hh_dirac(1))/(nr*nt*np) 
00426       << endl 
00427       << norme(hh_dirac(2))/(nr*nt*np) 
00428       << endl 
00429       << norme(hh_dirac(3))/(nr*nt*np) 
00430       << endl ; 
00431      
00432      Vector hh_dirac_new (hij_dirac1.divergence(star1.flat)) ;
00433      cout << "Vector H^i after the computation" << endl ;
00434      for (int i=1; i<=3; i++){
00435        cout << "  Comp. " << i << " : " << norme(hh_dirac_new(i)
00436                          /(nr*nt*np)) << endl ;
00437      }
00438 
00439      star1.hij_auto = star1.hij_auto + (hij_dirac1 - star1.hij) * 
00440        star1.decouple ;
00441      star1.hij_comp = star1.hij_comp + (hij_dirac1 - star1.hij) * 
00442        (1 - star1.decouple) ;
00443      star1.hij = hij_dirac1 ;
00444 
00445 
00446      // Star 2
00447      // -------
00448 
00449      Sym_tensor guu_dirac2 (star2.mp, CON, star2.mp.get_bvect_cart()) ;
00450      guu_dirac2 = star2.gamma.con().derive_lie(xi2) ;
00451      guu_dirac2.dec_dzpuis(2) ;
00452      guu_dirac2 = guu_dirac2 + star2.gamma.con() ;
00453      star2.gamma = guu_dirac2 ;
00454      
00455      Sym_tensor gtilde_con2(star2.mp, CON, star2.mp.get_bvect_cart()) ;
00456      Sym_tensor hij_dirac2(star2.mp, CON, star2.mp.get_bvect_cart()) ;
00457 
00458      gtilde_con2 = pow(star2.gamma.determinant(), 1./3.) * guu_dirac2 ;
00459      gtilde_con2.std_spectral_base() ;
00460      for(int i=1; i<=3; i++) 
00461        for(int j=i; j<=3; j++)
00462        hij_dirac2.set(i,j) = gtilde_con2(i,j) - star2.flat.con()(i,j) ;
00463 
00464      
00465      star2.gtilde = gtilde_con2 ;
00466      star2.psi4 = pow(star2.gamma.determinant(), 1./3.) ;
00467      star2.psi4.std_spectral_base() ;
00468      
00469 
00470      star2.hij_auto = star2.hij_auto + (hij_dirac2 - star2.hij) * 
00471        star2.decouple ;
00472      star2.hij_comp = star2.hij_comp + (hij_dirac2 - star2.hij) * 
00473        (1 - star2.decouple) ;
00474      star2.hij = hij_dirac2 ;
00475 
00476      //arrete() ;
00477 }

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