init_data.C

00001 /*
00002  *  Method of class Hor_isol to compute valid initial data for standard boundary 
00003  *   conditions
00004  *
00005  *    (see file isol_hor.h for documentation).
00006  *
00007  */
00008 
00009 /*
00010  *   Copyright (c) 2004  Jose Luis Jaramillo
00011  *
00012  *   This file is part of LORENE.
00013  *
00014  *   LORENE is free software; you can redistribute it and/or modify
00015  *   it under the terms of the GNU General Public License version 2
00016  *   as published by the Free Software Foundation.
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 init_data_C[] = "$Header: /cvsroot/Lorene/C++/Source/Isol_hor/init_data.C,v 1.28 2008/08/19 06:42:00 j_novak Exp $" ;
00030 
00031 /*
00032  * $Id: init_data.C,v 1.28 2008/08/19 06:42:00 j_novak Exp $
00033  * $Log: init_data.C,v $
00034  * Revision 1.28  2008/08/19 06:42:00  j_novak
00035  * Minor modifications to avoid warnings with gcc 4.3. Most of them concern
00036  * cast-type operations, and constant strings that must be defined as const char*
00037  *
00038  * Revision 1.27  2006/02/22 17:02:04  f_limousin
00039  * Removal of warnings
00040  *
00041  * Revision 1.26  2006/02/22 16:29:55  jl_jaramillo
00042  * corrections on the relaxation and boundary conditions
00043  *
00044  * Revision 1.24  2006/01/18 09:04:27  f_limousin
00045  * Minor modifs (warnings and errors at the compilation with gcc-3.4)
00046  *
00047  * Revision 1.23  2006/01/16 17:13:40  jl_jaramillo
00048  * function for solving the spherical case
00049  *
00050  * Revision 1.22  2005/11/02 16:09:44  jl_jaramillo
00051  * changes in boundary_nn_Dir_lapl
00052  *
00053  * Revision 1.21  2005/10/24 16:44:40  jl_jaramillo
00054  * Cook boundary condition ans minot bound of kss
00055  *
00056  * Revision 1.20  2005/10/21 16:20:55  jl_jaramillo
00057  * Version for the paper JaramL05
00058  *
00059  * Revision 1.19  2005/07/08 13:15:23  f_limousin
00060  * Improvements of boundary_vv_cart(), boundary_nn_lapl().
00061  * Add a fonction to compute the departure of axisymmetry.
00062  *
00063  * Revision 1.18  2005/06/09 08:05:32  f_limousin
00064  * Implement a new function sol_elliptic_boundary() and
00065  * Vector::poisson_boundary(...) which solve the vectorial poisson
00066  * equation (method 6) with an inner boundary condition.
00067  *
00068  * Revision 1.17  2005/05/12 14:48:07  f_limousin
00069  * New boundary condition for the lapse : boundary_nn_lapl().
00070  *
00071  * Revision 1.16  2005/04/08 12:16:52  f_limousin
00072  * Function set_psi(). And dependance in phi.
00073  *
00074  * Revision 1.15  2005/04/03 19:48:22  f_limousin
00075  * Implementation of set_psi(psi_in). And minor changes to avoid warnings.
00076  *
00077  * Revision 1.14  2005/04/02 15:49:21  f_limousin
00078  * New choice (Lichnerowicz) for aaquad. New member data nz.
00079  *
00080  * Revision 1.13  2005/03/31 09:45:31  f_limousin
00081  * New functions compute_ww(...) and aa_kerr_ww().
00082  *
00083  * Revision 1.12  2005/03/24 16:50:28  f_limousin
00084  * Add parameters solve_shift and solve_psi in par_isol.d and in function
00085  * init_dat(...). Implement Isolhor::kerr_perturb().
00086  *
00087  * Revision 1.11  2005/03/22 13:25:36  f_limousin
00088  * Small changes. The angular velocity and A^{ij} are computed
00089  * with a differnet sign.
00090  *
00091  * Revision 1.10  2005/03/09 10:18:08  f_limousin
00092  * Save K_{ij}s^is^j in a file. Add solve_lapse in a file
00093  *
00094  * Revision 1.9  2005/03/06 16:56:13  f_limousin
00095  * The computation of A^{ij} is no more necessary here thanks to the new
00096  * function Isol_hor::aa().
00097  *
00098  * Revision 1.8  2005/03/04 17:04:57  jl_jaramillo
00099  * Addition of boost to the shift after solving the shift equation
00100  *
00101  * Revision 1.7  2005/03/03 10:03:55  f_limousin
00102  * The boundary conditions for the lapse, psi and shift are now
00103  * parameters (in file par_hor.d).
00104  *
00105  * Revision 1.6  2004/12/22 18:15:30  f_limousin
00106  * Many different changes.
00107  *
00108  * Revision 1.5  2004/11/08 14:51:21  f_limousin
00109  * A regularisation for the computation of A^{ij } is done in the
00110  * case lapse equal to zero on the horizon.
00111  *
00112  * Revision 1.1  2004/10/29 12:54:53  jl_jaramillo
00113  * First version
00114  *
00115  * Revision 1.4  2004/10/01 16:47:51  f_limousin
00116  * Case \alpha=0 included
00117  *
00118  * Revision 1.3  2004/09/28 16:10:05  f_limousin
00119  * Many improvements. Now the resolution for the shift is working !
00120  *
00121  * Revision 1.1  2004/09/09 16:41:50  f_limousin
00122  * First version
00123  *
00124  *
00125  * $Header: /cvsroot/Lorene/C++/Source/Isol_hor/init_data.C,v 1.28 2008/08/19 06:42:00 j_novak Exp $
00126  *
00127  */
00128 
00129 // C++ headers
00130 #include "headcpp.h"
00131 
00132 // C headers
00133 #include <stdlib.h>
00134 #include <assert.h>
00135 
00136 // Lorene headers
00137 #include "isol_hor.h"
00138 #include "metric.h"
00139 #include "unites.h"
00140 #include "graphique.h"
00141 #include "cmp.h"
00142 #include "tenseur.h"
00143 #include "utilitaires.h"
00144 #include "param.h"
00145 
00146 void Isol_hor::init_data(int bound_nn, double lim_nn, int bound_psi, 
00147              int bound_beta, int solve_lapse, int solve_psi,
00148              int solve_shift, double precis, 
00149              double relax_nn, double relax_psi,  double relax_beta, int niter) {
00150 
00151     using namespace Unites ;
00152    
00153     // Initialisations
00154     // ---------------
00155     double ttime = the_time[jtime] ;    
00156 
00157     ofstream conv("resconv.d") ; 
00158     ofstream kss("kss.d") ;
00159     conv << " # diff_nn   diff_psi   diff_beta " << endl ;
00160 
00161     // Iteration
00162     // ---------
00163 //    double relax_nn_fin = relax_nn ;
00164 //    double relax_psi_fin = relax_psi ;
00165 //    double relax_beta_fin = relax_beta ;
00166     
00167 
00168     for (int mer=0; mer<niter; mer++) {
00169     
00170     //=========================================================
00171     // Boundary conditions and resolution of elliptic equations
00172     //=========================================================
00173 
00174     // Resolution of the Poisson equation for the lapse
00175     // ------------------------------------------------
00176       
00177       double relax_init = 0.05 ;
00178       double relax_speed = 0.005 ;
00179 
00180       double corr =  1 - (1 - relax_init) * exp (- relax_speed *  mer) ;
00181      
00182       //      relax_nn = relax_nn_fin - ( relax_nn_fin - relax_init ) * exp (- relax_speed *  mer) ;
00183       //      relax_psi = relax_psi_fin - ( relax_psi_fin - relax_init ) * exp (- relax_speed *  mer) ;
00184       //      relax_beta = relax_beta_fin - ( relax_beta_fin - relax_init ) * exp (- relax_speed *  mer) ;
00185 
00186       cout << "nn = " << mer << " corr = " << corr << endl ;
00187 
00188 
00189 
00190       cout << " relax_nn = " << relax_nn << endl ;
00191       cout << " relax_psi = " << relax_psi << endl ;
00192       cout << " relax_beta = " << relax_beta << endl ;
00193       
00194 
00195     Scalar sou_nn (source_nn()) ;
00196     Scalar nn_jp1 (mp) ;
00197     if (solve_lapse == 1) {
00198         Valeur nn_bound (mp.get_mg()-> get_angu()) ;
00199 
00200         switch (bound_nn) {
00201         
00202         case 0 : {
00203             nn_bound = boundary_nn_Dir(lim_nn) ;
00204             nn_jp1 = sou_nn.poisson_dirichlet(nn_bound, 0) + 1. ;
00205             break ;
00206         }
00207         case 1 : {
00208             nn_bound = boundary_nn_Neu_eff(lim_nn) ;
00209             nn_jp1 = sou_nn.poisson_neumann(nn_bound, 0) + 1. ;
00210             break ;
00211         }
00212         case 2 : {
00213             nn_bound = boundary_nn_Dir_eff(lim_nn) ;
00214             nn_jp1 = sou_nn.poisson_dirichlet(nn_bound, 0) + 1. ;
00215             break ;
00216         }
00217         case 3 : {
00218             nn_bound = boundary_nn_Neu_kk(mer) ;
00219             nn_jp1 = sou_nn.poisson_neumann(nn_bound, 0) + 1. ;
00220             break ;
00221         }
00222         case 4 : {
00223             nn_bound = boundary_nn_Dir_kk() ;
00224             nn_jp1 = sou_nn.poisson_dirichlet(nn_bound, 0) + 1. ;
00225             break ;
00226         }
00227         case 5 : {
00228             nn_bound = boundary_nn_Dir_lapl(mer) ;
00229             nn_jp1 = sou_nn.poisson_dirichlet(nn_bound, 0) + 1. ;
00230             break ;
00231         }
00232         case 6 : {
00233             nn_bound = boundary_nn_Neu_Cook() ;
00234             nn_jp1 = sou_nn.poisson_neumann(nn_bound, 0) + 1. ;
00235             break ;
00236         }
00237           
00238 
00239 
00240 
00241         default : {
00242             cout <<"Unexpected type of boundary conditions for the lapse!" 
00243              << endl 
00244              << "  bound_nn = " << bound_nn << endl ; 
00245             abort() ;
00246             break ; 
00247         }
00248             
00249         } // End of switch  
00250         
00251     // Test:
00252         maxabs(nn_jp1.laplacian() - sou_nn,
00253            "Absolute error in the resolution of the equation for N") ;
00254         
00255         // Relaxation (relax=1 -> new ; relax=0 -> old )  
00256         if (mer==0)
00257         n_evol.update(nn_jp1, jtime, ttime) ; 
00258         else
00259         nn_jp1 = relax_nn * nn_jp1 + (1 - relax_nn) * nn() ;
00260     }
00261         
00262         
00263     // Resolution of the Poisson equation for Psi
00264     // ------------------------------------------
00265     
00266     Scalar sou_psi (source_psi()) ;
00267     Scalar psi_jp1 (mp) ;
00268     if (solve_psi == 1) {
00269         Valeur psi_bound (mp.get_mg()-> get_angu()) ;
00270         
00271         switch (bound_psi) {
00272         
00273         case 0 : {
00274             psi_bound = boundary_psi_app_hor() ;
00275             psi_jp1 = sou_psi.poisson_neumann(psi_bound, 0) + 1. ;
00276             break ;
00277         }
00278         case 1 : {
00279             psi_bound = boundary_psi_Neu_spat() ;
00280             psi_jp1 = sou_psi.poisson_neumann(psi_bound, 0) + 1. ;
00281             break ;
00282         }
00283         case 2 : { 
00284             psi_bound = boundary_psi_Dir_spat() ;
00285             psi_jp1 = sou_psi.poisson_dirichlet(psi_bound, 0) + 1. ;
00286             break ;
00287         }
00288         case 3 : {
00289             psi_bound = boundary_psi_Neu_evol() ;
00290             psi_jp1 = sou_psi.poisson_neumann(psi_bound, 0) + 1. ;
00291             break ;
00292         }
00293         case 4 : {
00294             psi_bound = boundary_psi_Dir_evol() ;
00295             psi_jp1 = sou_psi.poisson_dirichlet(psi_bound, 0) + 1. ;
00296             break ;
00297         }
00298         case 5 : {
00299             psi_bound = boundary_psi_Dir() ;
00300             psi_jp1 = sou_psi.poisson_dirichlet(psi_bound, 0) + 1. ;
00301             break ;
00302         }
00303         default : {
00304             cout <<"Unexpected type of boundary conditions for psi!" 
00305              << endl 
00306              << "  bound_psi = " << bound_psi << endl ; 
00307             abort() ;
00308             break ; 
00309         }
00310             
00311         } // End of switch  
00312 
00313         // Test:
00314         maxabs(psi_jp1.laplacian() - sou_psi,
00315            "Absolute error in the resolution of the equation for Psi") ;  
00316         // Relaxation (relax=1 -> new ; relax=0 -> old )  
00317         psi_jp1 = relax_psi * psi_jp1 + (1 - relax_psi) * psi() ;
00318     }
00319     
00320     // Resolution of the vector Poisson equation for the shift
00321     //--------------------------------------------------------- 
00322 
00323     // Source
00324 
00325     Vector beta_jp1(beta()) ;
00326 
00327     if (solve_shift == 1) {
00328         Vector source_vector ( source_beta() ) ;
00329         double lambda = 0; //1./3.;
00330         Vector source_reg = - (1./3. - lambda) * beta().divergence(ff)
00331         .derive_con(ff) ;
00332         source_reg.inc_dzpuis() ;
00333         source_vector = source_vector + source_reg ;
00334 
00335         
00336        // CARTESIAN CASE 
00337        // #################################
00338 
00339         // Boundary values
00340                 
00341         Valeur boundary_x (mp.get_mg()-> get_angu()) ;
00342         Valeur boundary_y (mp.get_mg()-> get_angu()) ;
00343         Valeur boundary_z (mp.get_mg()-> get_angu()) ; 
00344         
00345         switch (bound_beta) {
00346         
00347         case 0 : {
00348           boundary_x = boundary_beta_x(omega) ;
00349           boundary_y = boundary_beta_y(omega) ;
00350           boundary_z = boundary_beta_z() ;
00351             break ;
00352         }
00353         case 1 : {
00354             boundary_x = boundary_vv_x(omega) ;
00355             boundary_y = boundary_vv_y(omega) ;
00356             boundary_z = boundary_vv_z(omega) ;
00357             break ;
00358         }
00359         default : {
00360             cout <<"Unexpected type of boundary conditions for psi!" 
00361              << endl 
00362              << "  bound_psi = " << bound_psi << endl ; 
00363             abort() ;
00364             break ; 
00365         }
00366         } // End of switch  
00367 
00368         if (boost_x != 0.) 
00369         boundary_x -= beta_boost_x() ;
00370         if (boost_z != 0.) 
00371         boundary_z -= beta_boost_z() ;
00372         
00373         // Resolution
00374         //-----------
00375         
00376         double precision = 1e-8 ;
00377         poisson_vect_boundary(lambda, source_vector, beta_jp1, boundary_x, 
00378                   boundary_y, boundary_z, 0, precision, 20) ;
00379         
00380 
00381 /*      
00382         // SPHERICAL CASE 
00383         // #################################
00384 
00385         // Boundary values
00386 
00387         Valeur boundary_r (mp.get_mg()-> get_angu()) ;
00388         Valeur boundary_t (mp.get_mg()-> get_angu()) ;
00389         Valeur boundary_p (mp.get_mg()-> get_angu()) ; 
00390         
00391         switch (bound_beta) {
00392         
00393         case 0 : {
00394           boundary_r = boundary_beta_r() ;
00395           boundary_t = boundary_beta_theta() ;
00396           boundary_p = boundary_beta_phi(omega) ;
00397             break ;
00398         }
00399         case 1 : {
00400             boundary_r = boundary_vv_x(omega) ;
00401             boundary_t = boundary_vv_y(omega) ;
00402             boundary_p = boundary_vv_z(omega) ;
00403             break ;
00404         }
00405         default : {
00406             cout <<"Unexpected type of boundary conditions for psi!" 
00407              << endl 
00408              << "  bound_psi = " << bound_psi << endl ; 
00409             abort() ;
00410             break ; 
00411         }
00412         } // End of switch  
00413 
00414         // Resolution
00415         //-----------
00416         
00417         beta_jp1 = source_vector.poisson_dirichlet(lambda, boundary_r,
00418                   boundary_t, boundary_p, 0) ;
00419         
00420 
00421         des_meridian(beta_jp1(1), 1.0000001, 10., "beta_r", 0) ;
00422         des_meridian(beta_jp1(2), 1.0000001, 10., "beta_t", 1) ;
00423         des_meridian(beta_jp1(3), 1.0000001, 10., "beta_p", 2) ;
00424         arrete() ;
00425         // #########################
00426         // End of spherical case
00427         // #########################
00428 
00429 
00430 */
00431         // Test
00432         source_vector.dec_dzpuis() ;
00433         maxabs(beta_jp1.derive_con(ff).divergence(ff) 
00434            + lambda * beta_jp1.divergence(ff)
00435            .derive_con(ff) - source_vector,
00436            "Absolute error in the resolution of the equation for beta") ;  
00437         
00438         cout << endl ;
00439             
00440         // Boost
00441         // -----
00442         
00443         Vector boost_vect(mp, CON, mp.get_bvect_cart()) ;
00444         if (boost_x != 0.) {
00445         boost_vect.set(1) = boost_x ;
00446         boost_vect.set(2) = 0. ;
00447         boost_vect.set(3) = 0. ;
00448         boost_vect.std_spectral_base() ;
00449         boost_vect.change_triad(mp.get_bvect_spher()) ;
00450         beta_jp1 = beta_jp1 + boost_vect ;
00451         }
00452         
00453         if (boost_z != 0.) {
00454         boost_vect.set(1) = boost_z ;
00455         boost_vect.set(2) = 0. ;
00456         boost_vect.set(3) = 0. ;
00457         boost_vect.std_spectral_base() ;
00458         boost_vect.change_triad(mp.get_bvect_spher()) ;
00459         beta_jp1 = beta_jp1 + boost_vect ;
00460         }
00461         
00462         // Relaxation (relax=1 -> new ; relax=0 -> old )  
00463         beta_jp1 = relax_beta * beta_jp1 + (1 - relax_beta) * beta() ;
00464     }
00465         
00466     //===========================================
00467     //      Convergence control
00468     //===========================================
00469     
00470     double diff_nn, diff_psi, diff_beta ;
00471     diff_nn = 1.e-16 ;
00472     diff_psi = 1.e-16 ;
00473     diff_beta = 1.e-16 ;
00474     if (solve_lapse == 1)
00475       diff_nn = max( diffrel(nn(), nn_jp1) ) ;   
00476     if (solve_psi == 1)
00477       diff_psi = max( diffrel(psi(), psi_jp1) ) ; 
00478     if (solve_shift == 1)
00479       diff_beta = max( maxabs(beta_jp1 - beta()) ) ; 
00480     
00481     cout << "step = " << mer << " :  diff_psi = " << diff_psi 
00482          << "  diff_nn = " << diff_nn 
00483          << "  diff_beta = " << diff_beta << endl ;
00484     cout << "----------------------------------------------" << endl ;
00485     if ((diff_psi<precis) && (diff_nn<precis) && (diff_beta<precis))
00486         break ; 
00487     
00488     if (mer>0) {conv << mer << "  " << log10(diff_nn) << " " << log10(diff_psi) 
00489              << " " << log10(diff_beta) << endl ; } ;
00490     
00491     //=============================================
00492     //      Updates for next step 
00493     //=============================================
00494     
00495     
00496     if (solve_psi == 1)
00497         set_psi(psi_jp1) ; 
00498     if (solve_lapse == 1)
00499         n_evol.update(nn_jp1, jtime, ttime) ; 
00500     if (solve_shift == 1)
00501         beta_evol.update(beta_jp1, jtime, ttime) ;  
00502 
00503     if (solve_shift == 1)
00504       update_aa() ;
00505 
00506     // Saving ok K_{ij}s^is^j
00507     // -----------------------
00508     
00509     Scalar kkss (contract(k_dd(), 0, 1, gam().radial_vect()*
00510                   gam().radial_vect(), 0, 1)) ;
00511     double max_kss = kkss.val_grid_point(1, 0, 0, 0) ;
00512     double min_kss = kkss.val_grid_point(1, 0, 0, 0) ;
00513     
00514     Scalar aaLss (pow(psi(), 6) * kkss) ;
00515     double max_aaLss = aaLss.val_grid_point(1, 0, 0, 0) ;
00516     double min_aaLss = aaLss.val_grid_point(1, 0, 0, 0) ;
00517     
00518     Scalar hh_tilde (contract(met_gamt.radial_vect().derive_cov(met_gamt), 0, 1)) ;
00519     double max_hh_tilde = hh_tilde.val_grid_point(1, 0, 0, 0) ;
00520     double min_hh_tilde = hh_tilde.val_grid_point(1, 0, 0, 0) ;
00521     
00522     
00523     int nnp = mp.get_mg()->get_np(1) ;
00524     int nnt = mp.get_mg()->get_nt(1) ;
00525     for (int k=0 ; k<nnp ; k++)
00526       for (int j=0 ; j<nnt ; j++){
00527         if (kkss.val_grid_point(1, k, j, 0) > max_kss)
00528           max_kss = kkss.val_grid_point(1, k, j, 0) ;
00529         if (kkss.val_grid_point(1, k, j, 0) < min_kss)
00530           min_kss = kkss.val_grid_point(1, k, j, 0) ;
00531 
00532         if (aaLss.val_grid_point(1, k, j, 0) > max_aaLss)
00533           max_aaLss = aaLss.val_grid_point(1, k, j, 0) ;
00534         if (aaLss.val_grid_point(1, k, j, 0) < min_aaLss)
00535           min_aaLss = aaLss.val_grid_point(1, k, j, 0) ;
00536         
00537         if (hh_tilde.val_grid_point(1, k, j, 0) > max_hh_tilde)
00538           max_hh_tilde = hh_tilde.val_grid_point(1, k, j, 0) ;
00539         if (hh_tilde.val_grid_point(1, k, j, 0) < min_hh_tilde)
00540           min_hh_tilde = hh_tilde.val_grid_point(1, k, j, 0) ;
00541         
00542       }
00543     
00544     
00545     kss << mer << " " << max_kss << " " << min_kss << " " << max_aaLss << " " << min_aaLss
00546         << " " <<  -1 * max_hh_tilde << " "  << -1 * min_hh_tilde << endl ;
00547     }
00548     
00549     conv.close() ;   
00550     kss.close() ;
00551 
00552 } 
00553 
00554 
00555 /*
00556 
00557 void Isol_hor::init_data_loop(int bound_nn, double lim_nn, int bound_psi, 
00558              int bound_beta, int solve_lapse, int solve_psi,
00559                   int solve_shift, double precis, double precis_loop, 
00560              double relax_nn, double relax_psi,  double relax_beta, double relax_loop, int niter) {
00561 
00562     using namespace Unites ;
00563    
00564     // Initialisations
00565     // ---------------
00566     double ttime = the_time[jtime] ;    
00567 
00568     ofstream conv("resconv.d") ; 
00569     ofstream kss("kss.d") ;
00570     conv << " # diff_nn   diff_psi   diff_beta " << endl ;
00571 
00572     // Iteration
00573     // ---------
00574     for (int mer=0; mer<niter; mer++) {
00575     
00576     //=========================================================
00577     // Boundary conditions and resolution of elliptic equations
00578     //=========================================================
00579 
00580     // Resolution of the Poisson equation for the lapse
00581     // ------------------------------------------------
00582 
00583 
00584 
00585     Scalar sou_nn (source_nn()) ;
00586     Scalar nn_jp1 (mp) ;
00587     if (solve_lapse == 1) {
00588         Valeur nn_bound (mp.get_mg()-> get_angu()) ;
00589 
00590         switch (bound_nn) {
00591         
00592         case 0 : {
00593             nn_bound = boundary_nn_Dir(lim_nn) ;
00594             nn_jp1 = sou_nn.poisson_dirichlet(nn_bound, 0) + 1. ;
00595             break ;
00596         }
00597         case 1 : {
00598             nn_bound = boundary_nn_Neu_eff(lim_nn) ;
00599             nn_jp1 = sou_nn.poisson_neumann(nn_bound, 0) + 1. ;
00600             break ;
00601         }
00602         case 2 : {
00603             nn_bound = boundary_nn_Dir_eff(lim_nn) ;
00604             nn_jp1 = sou_nn.poisson_dirichlet(nn_bound, 0) + 1. ;
00605             break ;
00606         }
00607         case 3 : {
00608             nn_bound = boundary_nn_Neu_kk() ;
00609             nn_jp1 = sou_nn.poisson_neumann(nn_bound, 0) + 1. ;
00610             break ;
00611         }
00612         case 4 : {
00613             nn_bound = boundary_nn_Dir_kk() ;
00614             nn_jp1 = sou_nn.poisson_dirichlet(nn_bound, 0) + 1. ;
00615             break ;
00616         }
00617         case 5 : {
00618             nn_bound = boundary_nn_Dir_lapl(mer) ;
00619             nn_jp1 = sou_nn.poisson_dirichlet(nn_bound, 0) + 1. ;
00620             break ;
00621         }
00622         case 6 : {
00623             nn_bound = boundary_nn_Neu_Cook() ;
00624             nn_jp1 = sou_nn.poisson_neumann(nn_bound, 0) + 1. ;
00625             break ;
00626         }
00627           
00628 
00629 
00630 
00631         default : {
00632             cout <<"Unexpected type of boundary conditions for the lapse!" 
00633              << endl 
00634              << "  bound_nn = " << bound_nn << endl ; 
00635             abort() ;
00636             break ; 
00637         }
00638             
00639         } // End of switch  
00640         
00641     // Test:
00642         maxabs(nn_jp1.laplacian() - sou_nn,
00643            "Absolute error in the resolution of the equation for N") ;
00644         
00645         // Relaxation (relax=1 -> new ; relax=0 -> old )  
00646         if (mer==0)
00647         n_evol.update(nn_jp1, jtime, ttime) ; 
00648         else
00649         nn_jp1 = relax_nn * nn_jp1 + (1 - relax_nn) * nn() ;
00650     }
00651         
00652         
00653     // Resolution of the Poisson equation for Psi
00654     // ------------------------------------------
00655     
00656     Scalar sou_psi (source_psi()) ;
00657     Scalar psi_jp1 (mp) ;
00658     if (solve_psi == 1) {
00659         Valeur psi_bound (mp.get_mg()-> get_angu()) ;
00660         
00661         switch (bound_psi) {
00662         
00663         case 0 : {
00664             psi_bound = boundary_psi_app_hor() ;
00665             psi_jp1 = sou_psi.poisson_neumann(psi_bound, 0) + 1. ;
00666             break ;
00667         }
00668         case 1 : {
00669             psi_bound = boundary_psi_Neu_spat() ;
00670             psi_jp1 = sou_psi.poisson_neumann(psi_bound, 0) + 1. ;
00671             break ;
00672         }
00673         case 2 : { 
00674             psi_bound = boundary_psi_Dir_spat() ;
00675             psi_jp1 = sou_psi.poisson_dirichlet(psi_bound, 0) + 1. ;
00676             break ;
00677         }
00678         case 3 : {
00679             psi_bound = boundary_psi_Neu_evol() ;
00680             psi_jp1 = sou_psi.poisson_neumann(psi_bound, 0) + 1. ;
00681             break ;
00682         }
00683         case 4 : {
00684             psi_bound = boundary_psi_Dir_evol() ;
00685             psi_jp1 = sou_psi.poisson_dirichlet(psi_bound, 0) + 1. ;
00686             break ;
00687         }
00688         case 5 : {
00689             psi_bound = boundary_psi_Dir() ;
00690             psi_jp1 = sou_psi.poisson_dirichlet(psi_bound, 0) + 1. ;
00691             break ;
00692         }
00693         default : {
00694             cout <<"Unexpected type of boundary conditions for psi!" 
00695              << endl 
00696              << "  bound_psi = " << bound_psi << endl ; 
00697             abort() ;
00698             break ; 
00699         }
00700             
00701         } // End of switch  
00702 
00703         // Test:
00704         maxabs(psi_jp1.laplacian() - sou_psi,
00705            "Absolute error in the resolution of the equation for Psi") ;  
00706         // Relaxation (relax=1 -> new ; relax=0 -> old )  
00707         psi_jp1 = relax_psi * psi_jp1 + (1 - relax_psi) * psi() ;
00708     }
00709     
00710     // Resolution of the vector Poisson equation for the shift
00711     //--------------------------------------------------------- 
00712 
00713     // Source
00714 
00715     Vector beta_j(beta()) ;
00716 
00717     if (solve_shift == 1) {
00718       
00719         double lambda = 1./3.;
00720         Vector beta_jp1 (beta()) ;
00721         double thresh_loop = 1;
00722         int n_loop = 0 ;
00723 
00724         while( thresh_loop > precis_loop ){
00725                           
00726           Vector source_vector ( source_beta() ) ;
00727           Vector source_reg = - (1./3. - lambda) * beta().divergence(ff)
00728         .derive_con(ff) ;
00729           source_reg.inc_dzpuis() ;
00730           source_vector = source_vector + source_reg ;
00731 
00732         
00733 
00734           // Boundary values
00735           // ===============
00736 
00737           Valeur boundary_x (mp.get_mg()-> get_angu()) ;
00738           Valeur boundary_y (mp.get_mg()-> get_angu()) ;
00739           Valeur boundary_z (mp.get_mg()-> get_angu()) ; 
00740           
00741           switch (bound_beta) {
00742         
00743           case 0 : {
00744         boundary_x = boundary_beta_x(omega) ;
00745         boundary_y = boundary_beta_y(omega) ;
00746         boundary_z = boundary_beta_z() ;
00747         break ;
00748           }
00749           case 1 : {
00750         boundary_x = boundary_vv_x(omega) ;
00751         boundary_y = boundary_vv_y(omega) ;
00752         boundary_z = boundary_vv_z(omega) ;
00753         break ;
00754           }
00755           default : {
00756         cout <<"Unexpected type of boundary conditions for beta!" 
00757              << endl 
00758              << "  bound_beta = " << bound_beta << endl ; 
00759         abort() ;
00760         break ; 
00761           }
00762           } // End of switch  
00763 
00764           if (boost_x != 0.) 
00765         boundary_x -= beta_boost_x() ;
00766           if (boost_z != 0.) 
00767         boundary_z -= beta_boost_z() ;
00768           
00769           // Resolution
00770           //-----------
00771         
00772           double precision = 1e-8 ;
00773           poisson_vect_boundary(lambda, source_vector, beta_jp1, boundary_x, 
00774                     boundary_y, boundary_z, 0, precision, 20) ;
00775                   
00776           // Test
00777           source_vector.dec_dzpuis() ;
00778           maxabs(beta_jp1.derive_con(ff).divergence(ff) 
00779              + lambda * beta_jp1.divergence(ff)
00780              .derive_con(ff) - source_vector,
00781              "Absolute error in the resolution of the equation for beta") ;  
00782           
00783           cout << endl ;
00784             
00785           
00786         
00787           // Relaxation_loop (relax=1 -> new ; relax=0 -> old )
00788           beta_jp1 = relax_loop * beta_jp1 + (1 - relax_loop) * beta() ;
00789         
00790 
00791           // Convergence loop
00792           //=================
00793           
00794           double diff_beta_loop ;
00795           diff_beta_loop = 1.e-16 ;
00796           if (solve_shift == 1)
00797         diff_beta_loop = max( maxabs(beta_jp1 - beta()) ) ; 
00798           cout << "step_loop = " << n_loop << 
00799            << "  diff_beta_loop = " << diff_beta_loop << endl ;
00800           cout << "----------------------------------------------" << endl ;
00801           thresh_loop = diff_beta_loop ;
00802           
00803           //Update loop
00804           //===========
00805           beta_evol.update(beta_jp1, jtime, ttime) ;    
00806           update_aa() ;
00807           n_loop += 1 ;       
00808 
00809           // End internal loop
00810         }
00811 
00812         // Test for resolution of beta at this setp mer is already done in the internal loop
00813 
00814         // Relaxation beta (relax=1 -> new ; relax=0 -> old )
00815           beta_jp1 = relax_beta * beta_jp1 + (1 - relax_loop) * beta_j ;
00816                 
00817     }
00818 
00819 
00820     //===========================================
00821     //      Convergence control
00822     //===========================================
00823     
00824     double diff_nn, diff_psi, diff_beta ;
00825     diff_nn = 1.e-16 ;
00826     diff_psi = 1.e-16 ;
00827     diff_beta = 1.e-16 ;
00828     if (solve_lapse == 1)
00829       diff_nn = max( diffrel(nn(), nn_jp1) ) ;   
00830     if (solve_psi == 1)
00831       diff_psi = max( diffrel(psi(), psi_jp1) ) ; 
00832     if (solve_shift == 1)
00833       diff_beta = max( maxabs(beta_jp1 - beta_j) ) ; 
00834     
00835     cout << "step = " << mer << " :  diff_psi = " << diff_psi 
00836          << "  diff_nn = " << diff_nn 
00837          << "  diff_beta = " << diff_beta << endl ;
00838     cout << "----------------------------------------------" << endl ;
00839     if ((diff_psi<precis) && (diff_nn<precis) && (diff_beta<precis))
00840         break ; 
00841     
00842     if (mer>0) {conv << mer << "  " << log10(diff_nn) << " " << log10(diff_psi) 
00843              << " " << log10(diff_beta) << endl ; } ;
00844     
00845     //=============================================
00846     //      Updates for next step 
00847     //=============================================
00848     
00849     
00850     if (solve_psi == 1)
00851         set_psi(psi_jp1) ; 
00852     if (solve_lapse == 1)
00853         n_evol.update(nn_jp1, jtime, ttime) ; 
00854     if (solve_shift == 1)
00855         beta_evol.update(beta_jp1, jtime, ttime) ;  
00856 
00857     if (solve_shift == 1)
00858       update_aa() ;
00859 
00860     // Saving ok K_{ij}s^is^j
00861     // -----------------------
00862     
00863     Scalar kkss (contract(k_dd(), 0, 1, gam().radial_vect()*
00864                   gam().radial_vect(), 0, 1)) ;
00865     double max_kss = kkss.val_grid_point(1, 0, 0, 0) ;
00866     double min_kss = kkss.val_grid_point(1, 0, 0, 0) ;
00867     
00868     Scalar aaLss (pow(psi(), 6) * kkss) ;
00869     double max_aaLss = aaLss.val_grid_point(1, 0, 0, 0) ;
00870     double min_aaLss = aaLss.val_grid_point(1, 0, 0, 0) ;
00871     
00872     Scalar hh_tilde (contract(met_gamt.radial_vect().derive_cov(met_gamt), 0, 1)) ;
00873     double max_hh_tilde = hh_tilde.val_grid_point(1, 0, 0, 0) ;
00874     double min_hh_tilde = hh_tilde.val_grid_point(1, 0, 0, 0) ;
00875     
00876     
00877     int nnp = mp.get_mg()->get_np(1) ;
00878     int nnt = mp.get_mg()->get_nt(1) ;
00879     for (int k=0 ; k<nnp ; k++)
00880       for (int j=0 ; j<nnt ; j++){
00881         if (kkss.val_grid_point(1, k, j, 0) > max_kss)
00882           max_kss = kkss.val_grid_point(1, k, j, 0) ;
00883         if (kkss.val_grid_point(1, k, j, 0) < min_kss)
00884           min_kss = kkss.val_grid_point(1, k, j, 0) ;
00885 
00886         if (aaLss.val_grid_point(1, k, j, 0) > max_aaLss)
00887           max_aaLss = aaLss.val_grid_point(1, k, j, 0) ;
00888         if (aaLss.val_grid_point(1, k, j, 0) < min_aaLss)
00889           min_aaLss = aaLss.val_grid_point(1, k, j, 0) ;
00890         
00891         if (hh_tilde.val_grid_point(1, k, j, 0) > max_hh_tilde)
00892           max_hh_tilde = hh_tilde.val_grid_point(1, k, j, 0) ;
00893         if (hh_tilde.val_grid_point(1, k, j, 0) < min_hh_tilde)
00894           min_hh_tilde = hh_tilde.val_grid_point(1, k, j, 0) ;
00895         
00896       }
00897     
00898     
00899     kss << mer << " " << max_kss << " " << min_kss << " " << max_aaLss << " " << min_aaLss
00900         << " " <<  -1 * max_hh_tilde << " "  << -1 * min_hh_tilde << endl ;
00901     }
00902     
00903     conv.close() ;   
00904     kss.close() ;
00905 
00906 } 
00907 
00908 
00909 */
00910 
00911 
00912 
00913 
00914 
00915 void Isol_hor::init_data_spher(int bound_nn, double lim_nn, int bound_psi, 
00916              int bound_beta, int solve_lapse, int solve_psi,
00917              int solve_shift, double precis, 
00918              double relax, int niter) {
00919 
00920     using namespace Unites ;
00921    
00922     // Initialisations
00923     // ---------------
00924     double ttime = the_time[jtime] ;    
00925 
00926     ofstream conv("resconv.d") ; 
00927     ofstream kss("kss.d") ;
00928     conv << " # diff_nn   diff_psi   diff_beta " << endl ;
00929 
00930     // Iteration
00931     // ---------
00932     for (int mer=0; mer<niter; mer++) {
00933 
00934       
00935       //       des_meridian(psi(), 1, 10., "psi", 0) ;
00936       //       des_meridian(b_tilde(), 1, 10., "b_tilde", 1) ;
00937       //       des_meridian(nn(), 1, 10., "nn", 2) ;
00938       //       arrete() ;
00939       
00940 
00941       //========
00942       // Sources
00943       //========
00944 
00945       // Useful functions
00946       // ----------------
00947        Vector tem_vect (beta() ) ;
00948        Scalar dif_b = b_tilde() - tem_vect.set(1) ;
00949        //       cout << "dif_b = " << dif_b << endl ;   
00950        //       arrete() ;
00951        
00952        Scalar dbdr ( b_tilde().dsdr() ) ;
00953 
00954        Scalar bsr (b_tilde()) ;
00955        bsr.div_r() ;
00956        bsr.inc_dzpuis(2) ;
00957 
00958        Scalar bsr2 ( bsr) ;
00959        bsr2.div_r() ;
00960        bsr2.inc_dzpuis(2)  ;
00961       
00962        Scalar psisr (psi()) ;
00963        psisr.div_r() ;
00964        psisr.inc_dzpuis(2) ;
00965 
00966       
00967      
00968        // Source Psi
00969        // ----------
00970        Scalar source_psi_spher(mp) ;
00971        source_psi_spher = -1./12. * psi4()*psi()/(nn() * nn()) * (dbdr - bsr) * (dbdr - bsr)   ;
00972        
00973        // Source N
00974        //---------
00975        Scalar source_nn_spher(mp) ;
00976        source_nn_spher = 2./3. * psi4() /nn() * (dbdr - bsr) * (dbdr - bsr)   
00977      - 2 * ln_psi().dsdr() * nn().dsdr() ;
00978        
00979        // Source b_tilde
00980       //---------------
00981        Scalar source_btilde_spher(mp) ;
00982        
00983        Scalar tmp ( -1./3. * (dbdr + 2 * bsr).dsdr() ) ;
00984        tmp.std_spectral_base() ;
00985        tmp.inc_dzpuis() ;       
00986 
00987        source_btilde_spher = tmp + 2 * bsr2  
00988                              + 4./3. * (dbdr - bsr) * ( nn().dsdr()/nn()  - 6 * psi().dsdr()/psi() ) ;
00989     
00990        Scalar source_btilde_trun(mp) ;
00991        
00992        source_btilde_trun = tmp +
00993      4./3. * (dbdr - bsr) * ( nn().dsdr()/nn()  - 6 * psi().dsdr()/psi() ) ;
00994        
00995 
00996        //       Scalar diff_dbeta ( (dbdr + 2 * bsr).dsdr() -  beta().divergence(ff).derive_con(ff)(1) ) ;
00997        
00998 
00999     
01000        // Parallel calculation
01001        //---------------------
01002        
01003        Scalar sourcepsi (source_psi()) ;
01004        Scalar sourcenn (source_nn()) ;
01005        
01006        Vector sourcebeta (source_beta()) ;
01007        Vector source_reg =  1./3. * beta().divergence(ff).derive_con(ff) ;
01008        source_reg.inc_dzpuis() ;
01009        sourcebeta -=  source_reg ;
01010        Scalar source_btilde (sourcebeta(1) ) ;
01011        
01012        //       Scalar diff_div =  source_reg(1) + tmp ;   ;
01013        
01014        Scalar mag_sou_psi ( source_psi_spher ) ;
01015        mag_sou_psi.dec_dzpuis(4) ;
01016        Scalar mag_sou_nn ( source_nn_spher ) ;
01017        mag_sou_nn.dec_dzpuis(4) ;
01018        Scalar mag_sou_btilde ( source_btilde_trun ) ;
01019        mag_sou_btilde.dec_dzpuis(4) ;
01020     
01021        Scalar diff_sou_psi ( source_psi_spher - sourcepsi) ;
01022        diff_sou_psi.dec_dzpuis(4) ;
01023        Scalar diff_sou_nn ( source_nn_spher - sourcenn) ;
01024        diff_sou_nn.dec_dzpuis(4) ;
01025        Scalar diff_sou_btilde ( source_btilde_trun - source_btilde) ;
01026        diff_sou_btilde.dec_dzpuis(4) ;
01027        
01028        /*
01029        cout << "dzpuis mag_btilde =" << mag_sou_btilde.get_dzpuis()<<endl  ;
01030        des_meridian(diff_sou_psi, 1, 10., "diff_psi", 0) ;
01031        des_meridian(diff_sou_nn, 1, 10., "diff_nn", 1) ;
01032        des_meridian(diff_sou_btilde, 1, 10., "diff_btilde", 2) ;
01033        des_meridian(mag_sou_psi, 1, 10., "mag_psi", 3) ;
01034        des_meridian(mag_sou_nn, 1, 10., "mag_nn", 4) ;
01035        des_meridian(mag_sou_btilde, 1, 10., "mag_btilde", 5) ;
01036        //       des_meridian(diff_dbeta, 1, 10., "diff_dbeta", 6) ;
01037        
01038        arrete() ;
01039        */
01040 
01041       
01042        //====================
01043        // Boundary conditions
01044        //====================
01045        
01046        // To avoid warnings;
01047        bound_nn = 1 ; lim_nn = 1. ; bound_psi = 1 ; bound_beta = 1 ;
01048 
01049        double kappa_0 = 0.2 - 1. ;
01050        
01051        Scalar kappa (mp) ;
01052        kappa = kappa_0 ;
01053        kappa.std_spectral_base() ;
01054        kappa.inc_dzpuis(2) ;
01055        
01056        
01057        int nnp = mp.get_mg()->get_np(1) ;
01058        int nnt = mp.get_mg()->get_nt(1) ;
01059        
01060        
01061        Valeur psi_bound (mp.get_mg()-> get_angu()) ;
01062        Valeur nn_bound (mp.get_mg()-> get_angu()) ;
01063        Valeur btilde_bound (mp.get_mg()-> get_angu()) ;
01064        psi_bound = 1. ; // Juste pour affecter dans espace des configs ;
01065        nn_bound = 1. ; // Juste pour affecter dans espace des configs ;
01066        btilde_bound = 1. ; // Juste pour affecter dans espace des configs ;
01067        
01068        Scalar tmp_psi = -1./4. * (2 * psisr +  
01069                   2./3. * psi4()/(psi() * nn()) * (dbdr - bsr) ) ;
01070        
01071        Scalar tmp_nn = kappa ; //+ 2./3. * psi() * psi() * (dbdr - bsr)   ;
01072        
01073        Scalar tmp_btilde = nn() / (psi() * psi()) ;
01074         
01075 
01076        for (int k=0 ; k<nnp ; k++)
01077      for (int j=0 ; j<nnt ; j++){
01078        psi_bound.set(0, k, j, 0) = tmp_psi.val_grid_point(1, k, j, 0) ;       // BC Psi
01079        nn_bound.set(0, k, j, 0) = tmp_nn.val_grid_point(1, k, j, 0) ;         // BC N
01080        btilde_bound.set(0, k, j, 0) = tmp_btilde.val_grid_point(1, k, j, 0) ; // BC b_tilde
01081      }
01082        
01083        psi_bound.std_base_scal() ;
01084        nn_bound.std_base_scal() ;
01085        btilde_bound.std_base_scal() ;
01086        
01087        
01088        //=================================
01089        // Resolution of elliptic equations
01090        //=================================
01091        
01092        // Resolution of the Poisson equation for Psi
01093        // ------------------------------------------
01094        Scalar psi_jp1 (mp) ;
01095        if (solve_psi == 1) {
01096      
01097     psi_jp1 = source_psi_spher.poisson_neumann(psi_bound, 0) + 1. ;
01098     
01099     // Test:
01100     maxabs(psi_jp1.laplacian() -  source_psi_spher,
01101            "Absolute error in the resolution of the equation for Psi") ;  
01102     // Relaxation (relax=1 -> new ; relax=0 -> old )  
01103     psi_jp1 = relax * psi_jp1 + (1 - relax) * psi() ;
01104        }
01105        
01106       // Resolution of the Poisson equation for the lapse
01107       // ------------------------------------------------
01108        Scalar nn_jp1 (mp) ;
01109        if (solve_lapse == 1) {
01110      
01111      nn_jp1 = source_nn_spher.poisson_dirichlet(nn_bound, 0) + 1. ;
01112     
01113      // Test:
01114      maxabs(nn_jp1.laplacian() - source_nn_spher,
01115         "Absolute error in the resolution of the equation for N") ;
01116      
01117      // Relaxation (relax=1 -> new ; relax=0 -> old )  
01118      if (mer==0)
01119       n_evol.update(nn_jp1, jtime, ttime) ; 
01120      else
01121        nn_jp1 = relax * nn_jp1 + (1 - relax) * nn() ;
01122      
01123        }
01124        
01125        // Resolution of the Poisson equation for b_tilde
01126       // ----------------------------------------------
01127        Scalar btilde_jp1 (mp) ;
01128        if (solve_shift == 1) {
01129      
01130     btilde_jp1 = source_btilde_spher.poisson_dirichlet(btilde_bound, 0)  ;
01131     
01132     // Test:
01133     maxabs(btilde_jp1.laplacian() - source_btilde_spher,
01134            "Absolute error in the resolution of the equation for btilde") ;  
01135     // Relaxation (relax=1 -> new ; relax=0 -> old )  
01136     btilde_jp1 = relax * btilde_jp1 + (1 - relax) * b_tilde() ;
01137        }
01138        
01139         
01140        //===========================================
01141        //      Convergence control
01142        //===========================================
01143        
01144        double diff_nn, diff_psi, diff_btilde ;
01145        diff_nn = 1.e-16 ;
01146     diff_psi = 1.e-16 ;
01147     diff_btilde = 1.e-16 ;
01148     if (solve_lapse == 1)
01149       diff_nn = max( diffrel(nn(), nn_jp1) ) ;   
01150     if (solve_psi == 1)
01151       diff_psi = max( diffrel(psi(), psi_jp1) ) ; 
01152     if (solve_shift == 1)
01153       diff_btilde = max( diffrel(btilde_jp1, b_tilde()) ) ; 
01154     
01155     cout << "step = " << mer << " :  diff_psi = " << diff_psi 
01156          << "  diff_nn = " << diff_nn 
01157          << "  diff_btilde = " << diff_btilde << endl ;
01158     cout << "----------------------------------------------" << endl ;
01159     if ((diff_psi<precis) && (diff_nn<precis) && (diff_btilde<precis))
01160       break ; 
01161     
01162     if (mer>0) {conv << mer << "  " << log10(diff_nn) << " " << log10(diff_psi) 
01163              << " " << log10(diff_btilde) << endl ; } ;
01164     
01165     //=============================================
01166     //      Updates for next step 
01167     //=============================================
01168     
01169     
01170     if (solve_psi == 1)
01171       set_psi(psi_jp1) ; 
01172     if (solve_lapse == 1)
01173       n_evol.update(nn_jp1, jtime, ttime) ; 
01174     if (solve_shift == 1)
01175      { 
01176        Vector beta_jp1 (btilde_jp1 * tgam().radial_vect()) ;
01177        cout <<  tgam().radial_vect() << endl ;
01178        beta_evol.update(beta_jp1, jtime, ttime) ;   
01179      }
01180     if (solve_shift == 1 || solve_lapse == 1)
01181       {
01182         update_aa() ;
01183       }
01184 
01185     // Saving ok K_{ij}s^is^j
01186     // -----------------------
01187     
01188     Scalar kkss (contract(k_dd(), 0, 1, gam().radial_vect()*
01189                   gam().radial_vect(), 0, 1)) ;
01190     double max_kss = kkss.val_grid_point(1, 0, 0, 0) ;
01191     double min_kss = kkss.val_grid_point(1, 0, 0, 0) ;
01192     
01193     Scalar aaLss (pow(psi(), 6) * kkss) ;
01194     double max_aaLss = aaLss.val_grid_point(1, 0, 0, 0) ;
01195     double min_aaLss = aaLss.val_grid_point(1, 0, 0, 0) ;
01196     
01197     Scalar hh_tilde (contract(met_gamt.radial_vect().derive_cov(met_gamt), 0, 1)) ;
01198     double max_hh_tilde = hh_tilde.val_grid_point(1, 0, 0, 0) ;
01199     double min_hh_tilde = hh_tilde.val_grid_point(1, 0, 0, 0) ;
01200     
01201     
01202 
01203     for (int k=0 ; k<nnp ; k++)
01204       for (int j=0 ; j<nnt ; j++){
01205         if (kkss.val_grid_point(1, k, j, 0) > max_kss)
01206           max_kss = kkss.val_grid_point(1, k, j, 0) ;
01207         if (kkss.val_grid_point(1, k, j, 0) < min_kss)
01208           min_kss = kkss.val_grid_point(1, k, j, 0) ;
01209 
01210         if (aaLss.val_grid_point(1, k, j, 0) > max_aaLss)
01211           max_aaLss = aaLss.val_grid_point(1, k, j, 0) ;
01212         if (aaLss.val_grid_point(1, k, j, 0) < min_aaLss)
01213           min_aaLss = aaLss.val_grid_point(1, k, j, 0) ;
01214         
01215         if (hh_tilde.val_grid_point(1, k, j, 0) > max_hh_tilde)
01216           max_hh_tilde = hh_tilde.val_grid_point(1, k, j, 0) ;
01217         if (hh_tilde.val_grid_point(1, k, j, 0) < min_hh_tilde)
01218           min_hh_tilde = hh_tilde.val_grid_point(1, k, j, 0) ;
01219         
01220       }
01221     
01222     
01223     kss << mer << " " << max_kss << " " << min_kss << " " << max_aaLss << " " << min_aaLss
01224         << " " <<  -1 * max_hh_tilde << " "  << -1 * min_hh_tilde << endl ;
01225     }
01226     
01227     conv.close() ;   
01228     kss.close() ;
01229 
01230 } 
01231 
01232 
01233 
01234 void Isol_hor::init_data_alt(int, double, int, 
01235              int, int solve_lapse, int solve_psi,
01236              int solve_shift, double precis, 
01237              double relax, int niter) {
01238 
01239     using namespace Unites ;
01240    
01241     // Initialisations
01242     // ---------------
01243     double ttime = the_time[jtime] ;    
01244 
01245     ofstream conv("resconv.d") ; 
01246     ofstream kss("kss.d") ;
01247     conv << " # diff_nn   diff_psi   diff_beta " << endl ;
01248 
01249     Scalar psi_j (psi()) ;
01250     Scalar nn_j (nn()) ;
01251     Scalar btilde_j (b_tilde()) ;    
01252     Scalar diffb (  btilde_j - b_tilde() ) ;
01253     Scalar theta_j (beta().divergence(ff)) ;
01254     theta_j.dec_dzpuis(2) ;
01255     Scalar chi_j (b_tilde()) ;
01256     chi_j.mult_r() ;
01257 
01258    
01259     // Iteration
01260     // ---------
01261 
01262     for (int mer=0; mer<niter; mer++) {
01263 
01264       
01265       des_meridian(psi_j, 1, 10., "psi", 0) ;
01266       des_meridian(nn_j, 1, 10., "nn", 1) ;
01267       des_meridian(theta_j, 1, 10., "Theta", 2) ;
01268       des_meridian(chi_j, 1, 10., "chi", 3) ;
01269       arrete() ;
01270 
01271 
01272       //========
01273       // Sources
01274       //========
01275 
01276       // Useful functions
01277       // ----------------
01278       
01279        Scalar psisr (psi_j) ;
01280        psisr.div_r() ;
01281        psisr.inc_dzpuis(2) ;
01282 
01283        Scalar dchidr ( chi_j.dsdr() ) ;
01284        
01285        Scalar chisr (chi_j) ;
01286        chisr.div_r() ;
01287        chisr.inc_dzpuis(2) ;
01288       
01289        Scalar rdthetadr (theta_j.dsdr() ) ;
01290        rdthetadr.mult_r() ;
01291        rdthetadr.inc_dzpuis(2) ;
01292 
01293        Scalar theta_dz4 (theta_j) ;
01294        theta_dz4.inc_dzpuis(4) ; 
01295 
01296        Scalar dbmb (dchidr - 2 * chisr) ;
01297        dbmb.div_r() ;
01298      
01299 
01300        // Source Psi
01301        // ----------
01302        Scalar source_psi_spher(mp) ;
01303 
01304        source_psi_spher = -1./12. * psi_j*psi_j*psi_j*psi_j*psi_j/(nn_j * nn_j) 
01305          * dbmb *dbmb ; 
01306 
01307        
01308        // Source N
01309        //---------
01310        Scalar source_nn_spher(mp) ;
01311        source_nn_spher = 2./3. * psi_j*psi_j*psi_j*psi_j/nn_j * dbmb *dbmb
01312      - 2 * psi_j.dsdr()/psi_j * nn_j.dsdr() ;
01313 
01314       
01315        //====================
01316        // Boundary conditions
01317        //====================
01318        double kappa_0 = 0.2 - 1. ;
01319        
01320        Scalar kappa (mp) ;
01321        kappa = kappa_0 ;
01322        kappa.std_spectral_base() ;
01323        kappa.inc_dzpuis(2) ;
01324        
01325        int nnp = mp.get_mg()->get_np(1) ;
01326        int nnt = mp.get_mg()->get_nt(1) ;
01327        
01328        Valeur psi_bound (mp.get_mg()-> get_angu()) ;
01329        Valeur nn_bound (mp.get_mg()-> get_angu()) ;
01330 
01331        psi_bound = 1. ; // Juste pour affecter dans espace des configs ;
01332        nn_bound = 1. ; // Juste pour affecter dans espace des configs ;
01333 
01334        //psi
01335 
01336        Scalar tmp_psi = -1./4. * (2 * psisr +  
01337                   2./3. * psi_j*psi_j*psi_j/ nn_j * dbmb ) ;
01338 
01339        //       tmp_psi = 2./3. * psi_j*psi_j*psi_j/ nn_j * (dchidr - 2 * chisr) ;
01340        //       tmp_psi.div_r() ; 
01341        //       tmp_psi =  -1./4. * (2 * psisr + tmp_psi) ;
01342        
01343        //nn
01344        Scalar tmp_nn = kappa ; //+ 2./3. * psi_j*psi_j * dbmb ;
01345       
01346 
01347 
01348        for (int k=0 ; k<nnp ; k++)
01349      for (int j=0 ; j<nnt ; j++){
01350        psi_bound.set(0, k, j, 0) = tmp_psi.val_grid_point(1, k, j, 0) ;       // BC Psi
01351        nn_bound.set(0, k, j, 0) = tmp_nn.val_grid_point(1, k, j, 0) ;         // BC N
01352      }
01353        
01354        psi_bound.std_base_scal() ;
01355        nn_bound.std_base_scal() ;
01356 
01357 
01358        
01359        //=================================
01360        // Resolution of elliptic equations
01361        //=================================
01362        
01363        // Resolution of the Poisson equation for Psi
01364        // ------------------------------------------
01365        Scalar psi_jp1 (mp) ;
01366        if (solve_psi == 1) {
01367      
01368     psi_jp1 = source_psi_spher.poisson_neumann(psi_bound, 0) + 1. ;
01369     
01370     // Test:
01371     maxabs(psi_jp1.laplacian() -  source_psi_spher,
01372            "Absolute error in the resolution of the equation for Psi") ;  
01373     // Relaxation (relax=1 -> new ; relax=0 -> old )  
01374     psi_jp1 = relax * psi_jp1 + (1 - relax) * psi_j ;
01375        }
01376        
01377       // Resolution of the Poisson equation for the lapse
01378       // ------------------------------------------------
01379        Scalar nn_jp1 (mp) ;
01380        if (solve_lapse == 1) {
01381      
01382      nn_jp1 = source_nn_spher.poisson_dirichlet(nn_bound, 0) + 1. ;
01383     
01384      // Test:
01385      maxabs(nn_jp1.laplacian() - source_nn_spher,
01386         "Absolute error in the resolution of the equation for N") ;
01387      
01388      // Relaxation (relax=1 -> new ; relax=0 -> old )  
01389      if (mer==0)
01390       n_evol.update(nn_jp1, jtime, ttime) ; 
01391      else
01392        nn_jp1 = relax * nn_jp1 + (1 - relax) * nn_j ;
01393      
01394        }
01395 
01396 
01397        // Resolution for chi and Theta
01398        // ----------------------------
01399        Scalar theta_jp1 (mp) ;
01400        Scalar chi_jp1 (mp) ;
01401 
01402        if (solve_shift == 1) {
01403 
01404      // Initialisations loop on theta/chi
01405      Scalar theta_i(theta_j) ;
01406      Scalar chi_i(chi_j) ;
01407 
01408        
01409      // Iteration in theta/chi
01410      for (int i=0 ; i<niter ; i++) {
01411 
01412        des_meridian(theta_i, 1, 10., "Theta", 2) ;
01413        des_meridian(chi_i, 1, 10., "chi", 3) ;
01414        arrete() ;
01415 
01416 
01417 
01418        //Sources
01419        
01420        // Source_theta
01421        //-------------
01422        Scalar source_theta_spher(mp) ;
01423        source_theta_spher =  (dbmb * (nn_j.dsdr()/nn_j - 6 * psi_j.dsdr()/psi_j)).dsdr() ; 
01424        source_theta_spher.dec_dzpuis() ;
01425        
01426        // Source chi
01427        //-----------
01428        Scalar source_chi_spher(mp) ;
01429        source_chi_spher = 4./3. * (dchidr - 2 * chisr) * ( nn_j.dsdr()/nn_j  - 6 * psi_j.dsdr()/psi_j ) 
01430          - 1./3. * rdthetadr + 2 * theta_dz4 ;
01431     
01432        //Boundaries
01433        Valeur theta_bound (mp.get_mg()-> get_angu()) ;
01434        Valeur chi_bound (mp.get_mg()-> get_angu()) ;
01435        
01436        theta_bound = 1. ; // Juste pour affecter dans espace des configs ;
01437        chi_bound = 1. ; // Juste pour affecter dans espace des configs ;
01438 
01439        //theta
01440        Scalar tmp_theta = dchidr ;
01441        tmp_theta.dec_dzpuis(2) ;
01442        tmp_theta += nn_j/(psi_j*psi_j)  ;
01443        tmp_theta.div_r() ;
01444        
01445        //chi
01446        Scalar tmp_chi = nn_j/(psi_j*psi_j) ;
01447        tmp_chi.mult_r() ;
01448        
01449        for (int k=0 ; k<nnp ; k++)
01450          for (int j=0 ; j<nnt ; j++){
01451            theta_bound.set(0, k, j, 0) = tmp_theta.val_grid_point(1, k, j, 0) ;       // BC Theta
01452            chi_bound.set(0, k, j, 0) = tmp_chi.val_grid_point(1, k, j, 0) ;       // BC chi    
01453          }
01454        theta_bound.std_base_scal() ;
01455        chi_bound.std_base_scal() ;       
01456        
01457        //Resolution equations
01458        Scalar theta_ip1(mp) ;
01459        Scalar chi_ip1(mp) ;
01460        
01461        theta_ip1 = source_theta_spher.poisson_dirichlet(theta_bound, 0)  ;
01462        chi_ip1 = source_chi_spher.poisson_dirichlet(chi_bound, 0)  ;
01463        
01464        // Test:
01465        maxabs(theta_ip1.laplacian() - source_theta_spher,
01466           "Absolute error in the resolution of the equation for Theta") ;  
01467        maxabs(chi_ip1.laplacian() - source_chi_spher,
01468           "Absolute error in the resolution of the equation for chi") ;
01469        
01470        // Relaxation (relax=1 -> new ; relax=0 -> old )  
01471        theta_ip1 = relax * theta_ip1 + (1 - relax) * theta_i ;
01472        chi_ip1 = relax * chi_ip1 + (1 - relax) * chi_i ;
01473        
01474        // Convergence control of loop in theta/chi
01475          double diff_theta_int, diff_chi_int, int_precis ;
01476          diff_theta_int = 1.e-16 ;
01477          diff_chi_int = 1.e-16 ;
01478          int_precis = 1.e-3 ;
01479 
01480          diff_theta_int = max( diffrel(theta_ip1, theta_i) ) ; 
01481          diff_chi_int = max( diffrel(chi_ip1, chi_i) ) ; 
01482 
01483     
01484          cout << "internal step = " << i 
01485          << "  diff_theta_int = " << diff_theta_int  
01486          << "  diff_chi_int = " << diff_chi_int <<  endl ;
01487          cout << "----------------------------------------------" << endl ;
01488          if ((diff_theta_int<int_precis) &&  (diff_chi_int<int_precis))
01489            {
01490          theta_jp1 = theta_ip1 ;
01491          chi_jp1 = chi_ip1 ;
01492          break ; 
01493            }
01494          // Updates of internal loop in theta/chi
01495          theta_i = theta_ip1 ;
01496          chi_i = chi_ip1 ;
01497      }
01498        }
01499     
01500         
01501        //===========================================
01502        //      Convergence control
01503        //===========================================
01504        
01505        double diff_nn, diff_psi, diff_theta, diff_chi ;
01506        diff_nn = 1.e-16 ;
01507        diff_psi = 1.e-16 ;
01508        diff_theta = 1.e-16 ;
01509        diff_chi = 1.e-16 ;
01510 
01511     if (solve_lapse == 1)
01512       diff_nn = max( diffrel(nn_j, nn_jp1) ) ;   
01513     if (solve_psi == 1)
01514       diff_psi = max( diffrel(psi_j, psi_jp1) ) ; 
01515     if (solve_shift == 1)
01516       diff_theta = max( diffrel(theta_jp1, theta_j) ) ; 
01517     if (solve_shift == 1)
01518       diff_chi = max( diffrel(chi_jp1, chi_j) ) ; 
01519 
01520     
01521     cout << "step = " << mer << " :  diff_psi = " << diff_psi 
01522          << "  diff_nn = " << diff_nn 
01523          << "  diff_theta = " << diff_theta  
01524          << "  diff_chi = " << diff_chi <<  endl ;
01525     cout << "----------------------------------------------" << endl ;
01526     if ((diff_psi<precis) && (diff_nn<precis) && (diff_theta<precis) &&  (diff_chi<precis))
01527       break ; 
01528     
01529     if (mer>0) {conv << mer << "  " << log10(diff_nn) << " " << log10(diff_psi) 
01530              << " " << log10(diff_theta) 
01531                  << " " << log10(diff_chi) << endl ;  } ;
01532     
01533     //=============================================
01534     //      Updates for next step 
01535     //=============================================
01536     
01537     
01538     if (solve_psi == 1)
01539       set_psi(psi_jp1) ; 
01540       psi_j = psi_jp1 ; 
01541     if (solve_lapse == 1)
01542       n_evol.update(nn_jp1, jtime, ttime) ; 
01543       nn_j = nn_jp1 ;
01544     if (solve_shift == 1)
01545       {
01546         theta_j = theta_jp1 ;
01547         chi_j = chi_jp1 ;
01548         chi_jp1.mult_r() ;
01549         Vector beta_jp1 (chi_jp1 * tgam().radial_vect()) ;
01550         beta_evol.update(beta_jp1, jtime, ttime) ;  
01551       }
01552 
01553     if (solve_shift == 1 || solve_lapse == 1)
01554       {
01555         update_aa() ;
01556       }
01557 
01558     // Saving ok K_{ij}s^is^j
01559     // -----------------------
01560     
01561     Scalar kkss (contract(k_dd(), 0, 1, gam().radial_vect()*
01562                   gam().radial_vect(), 0, 1)) ;
01563     double max_kss = kkss.val_grid_point(1, 0, 0, 0) ;
01564     double min_kss = kkss.val_grid_point(1, 0, 0, 0) ;
01565     
01566     Scalar aaLss (pow(psi(), 6) * kkss) ;
01567     double max_aaLss = aaLss.val_grid_point(1, 0, 0, 0) ;
01568     double min_aaLss = aaLss.val_grid_point(1, 0, 0, 0) ;
01569     
01570     Scalar hh_tilde (contract(met_gamt.radial_vect().derive_cov(met_gamt), 0, 1)) ;
01571     double max_hh_tilde = hh_tilde.val_grid_point(1, 0, 0, 0) ;
01572     double min_hh_tilde = hh_tilde.val_grid_point(1, 0, 0, 0) ;
01573     
01574     
01575 
01576     for (int k=0 ; k<nnp ; k++)
01577       for (int j=0 ; j<nnt ; j++){
01578         if (kkss.val_grid_point(1, k, j, 0) > max_kss)
01579           max_kss = kkss.val_grid_point(1, k, j, 0) ;
01580         if (kkss.val_grid_point(1, k, j, 0) < min_kss)
01581           min_kss = kkss.val_grid_point(1, k, j, 0) ;
01582 
01583         if (aaLss.val_grid_point(1, k, j, 0) > max_aaLss)
01584           max_aaLss = aaLss.val_grid_point(1, k, j, 0) ;
01585         if (aaLss.val_grid_point(1, k, j, 0) < min_aaLss)
01586           min_aaLss = aaLss.val_grid_point(1, k, j, 0) ;
01587         
01588         if (hh_tilde.val_grid_point(1, k, j, 0) > max_hh_tilde)
01589           max_hh_tilde = hh_tilde.val_grid_point(1, k, j, 0) ;
01590         if (hh_tilde.val_grid_point(1, k, j, 0) < min_hh_tilde)
01591           min_hh_tilde = hh_tilde.val_grid_point(1, k, j, 0) ;
01592         
01593       }
01594     
01595     
01596     kss << mer << " " << max_kss << " " << min_kss << " " << max_aaLss << " " << min_aaLss
01597         << " " <<  -1 * max_hh_tilde << " "  << -1 * min_hh_tilde << endl ;
01598     }
01599     
01600     conv.close() ;   
01601     kss.close() ;
01602 
01603 } 
01604 
01605 
01606 

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