binaire_constr.C

00001 /*
00002  * Methods of class Binaire for estimating the error in the Hamiltionian
00003  *  and momentum constraints
00004  *
00005  * (see file binaire.h for documentation).
00006  */
00007 
00008 /*
00009  *   Copyright (c) 2000-2001 Eric Gourgoulhon
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 
00030 char binaire_constr_C[] = "$Header: /cvsroot/Lorene/C++/Source/Binaire/binaire_constr.C,v 1.2 2004/03/25 10:28:59 j_novak Exp $" ;
00031 
00032 /*
00033  * $Id: binaire_constr.C,v 1.2 2004/03/25 10:28:59 j_novak Exp $
00034  * $Log: binaire_constr.C,v $
00035  * Revision 1.2  2004/03/25 10:28:59  j_novak
00036  * All LORENE's units are now defined in the namespace Unites (in file unites.h).
00037  *
00038  * Revision 1.1.1.1  2001/11/20 15:19:30  e_gourgoulhon
00039  * LORENE
00040  *
00041  * Revision 2.1  2000/03/13  17:05:34  eric
00042  * *** empty log message ***
00043  *
00044  * Revision 2.0  2000/03/13  14:26:08  eric
00045  * *** empty log message ***
00046  *
00047  *
00048  * $Header: /cvsroot/Lorene/C++/Source/Binaire/binaire_constr.C,v 1.2 2004/03/25 10:28:59 j_novak Exp $
00049  *
00050  */
00051 
00052 // Headers C
00053 #include "math.h"
00054 
00055 // Headers Lorene
00056 #include "binaire.h"
00057 #include "unites.h"
00058 
00059 
00060 
00061         //----------------------------------------------//
00062         //      Hamiltonian constraint      //
00063         //----------------------------------------------//
00064 
00065 double Binaire::ham_constr() const {
00066     
00067   using namespace Unites ;
00068 
00069     if (p_ham_constr == 0x0) {      // A new computation is required
00070     
00071 
00072     Tenseur lap_alpha1( star1.get_mp() ) ; 
00073     Tenseur lap_alpha2( star2.get_mp() ) ; 
00074 
00075     Tenseur source1( star1.get_mp() ) ; 
00076     Tenseur source2( star2.get_mp() ) ; 
00077 
00078     Tenseur* p_lap_alpha[2] ; 
00079     Tenseur* p_source[2] ; 
00080     p_lap_alpha[0] = &lap_alpha1 ; 
00081     p_lap_alpha[1] = &lap_alpha2 ; 
00082     p_source[0] = &source1 ; 
00083     p_source[1] = &source2 ; 
00084 
00085 
00086     // Computation of the l.h.s. and r.h.s. of the Hamiltonian
00087     // constraint in each star. 
00088     // -------------------------------------------------------
00089     
00090     double som = 0 ; 
00091     
00092     for (int i=0; i<2; i++) {
00093         
00094         // Laplacian of alpha = ln(A) 
00095         // --------------------------
00096 
00097         Tenseur alpha_auto = et[i]->get_beta_auto() 
00098                  - et[i]->get_logn_auto() ; 
00099                  
00100         *(p_lap_alpha[i]) = alpha_auto().laplacien() ; 
00101         
00102         // Right-hand-side of the Hamiltonian constraint
00103         // ---------------------------------------------
00104         
00105         const Tenseur& a_car = et[i]->get_a_car() ; 
00106         const Tenseur& ener_euler = et[i]->get_ener_euler() ; 
00107 
00108         Tenseur d_alpha_auto = et[i]->get_d_beta_auto() 
00109                  - et[i]->get_d_logn_auto() ; 
00110         
00111         Tenseur d_alpha_comp = et[i]->get_d_beta_comp() 
00112                  - et[i]->get_d_logn_comp() ; 
00113         
00114         const Tenseur& akcar_auto = et[i]->get_akcar_auto() ; 
00115         const Tenseur& akcar_comp = et[i]->get_akcar_comp() ; 
00116         
00117         *(p_source[i]) = - qpig * a_car * ener_euler 
00118                  - 0.25 * ( akcar_auto + akcar_comp ) 
00119                  - 0.5 * 
00120                 (   flat_scalar_prod(d_alpha_auto, d_alpha_auto)
00121                       + flat_scalar_prod(d_alpha_auto, d_alpha_comp)
00122                 ) ;
00123 
00124         // Relative difference
00125         // -------------------
00126         Tbl diff = diffrel( (*(p_lap_alpha[i]))(), (*(p_source[i]))() ) ; 
00127         
00128         cout << 
00129         "Binaire::ham_constr : relative difference Lap(alpha) <-> source : "
00130         << endl << diff << endl ; 
00131         
00132         som += max( abs(diff) ) ; 
00133 
00134     }
00135 
00136     
00137     // Total error
00138     // -----------
00139     p_ham_constr = new double ; 
00140 
00141     *p_ham_constr = 0.5 * som  ; 
00142         
00143     }
00144         
00145     return *p_ham_constr ; 
00146     
00147 }
00148 
00149 
00150         //----------------------------------------------//
00151         //      Momentum constraint     //
00152         //----------------------------------------------//
00153 
00154 const Tbl& Binaire::mom_constr() const {
00155 
00156   using namespace Unites ;
00157 
00158     if (p_mom_constr == 0x0) {      // A new computation is required
00159     
00160     Tenseur divk1( star1.get_mp(), 1, CON, ref_triad ) ; 
00161     Tenseur divk2( star2.get_mp(), 1, CON, ref_triad ) ; 
00162 
00163     Tenseur source1( star1.get_mp(), 1, CON, ref_triad ) ; 
00164     Tenseur source2( star2.get_mp(), 1, CON, ref_triad ) ; 
00165 
00166     Tenseur* p_divk[2] ; 
00167     Tenseur* p_source[2] ; 
00168     p_divk[0] = &divk1 ; 
00169     p_divk[1] = &divk2 ; 
00170     p_source[0] = &source1 ; 
00171     p_source[1] = &source2 ; 
00172 
00173 
00174     // Computation of the l.h.s. and r.h.s. of the momentum
00175     // constraint in each star. 
00176     // -------------------------------------------------------
00177     
00178     double somx = 0 ; 
00179     double somy = 0 ; 
00180     double somz = 0 ; 
00181     
00182     for (int i=0; i<2; i++) {
00183     
00184         // (flat space) divergence of K^{ij}
00185         // ---------------------------------
00186         
00187         const Tenseur& a_car = et[i]->get_a_car() ; 
00188         Tenseur kij_auto = et[i]->get_tkij_auto() / a_car ; 
00189         
00190         kij_auto.dec2_dzpuis() ; // dzpuis : 2 --> 0 
00191                      // so that in the external domain, kij_auto
00192                      // contains now exactly K^{ij}
00193     
00194         // The gradient of K^{ij} is computed on the local triad:
00195         kij_auto.change_triad( (et[i]->get_mp()).get_bvect_cart() ) ; 
00196     
00197         *(p_divk[i]) = contract( kij_auto.gradient(), 0, 1) ; 
00198         
00199         // Back to the Reference triad : 
00200         p_divk[i]->change_triad( ref_triad ) ; 
00201         kij_auto.change_triad( ref_triad ) ; 
00202     
00203         // Right-hand-side of the momentum constraint
00204         // ------------------------------------------
00205         
00206         const Tenseur& u_euler = et[i]->get_u_euler() ; 
00207         const Tenseur& ener_euler = et[i]->get_ener_euler() ; 
00208         const Tenseur& press = et[i]->get_press() ; 
00209     
00210         
00211         Tenseur d_alpha =   et[i]->get_d_beta_auto()    
00212                   - et[i]->get_d_logn_auto() 
00213                   + et[i]->get_d_beta_comp()    
00214                   - et[i]->get_d_logn_comp() ; 
00215                   
00216         *(p_source[i]) = 2 * qpig * (ener_euler + press) * u_euler
00217                  - 5 * contract(kij_auto, 1, d_alpha, 0) ; 
00218 
00219         // Relative differences
00220         // --------------------
00221         Tbl diffx = diffrel( (*(p_divk[i]))(0), (*(p_source[i]))(0)) ;
00222         Tbl diffy = diffrel( (*(p_divk[i]))(1), (*(p_source[i]))(1)) ;
00223         Tbl diffz = diffrel( (*(p_divk[i]))(2), (*(p_source[i]))(2)) ;
00224 
00225         cout << "Binaire::mom_constr : norme div(K) : " << endl ;
00226         cout << "X component : " << norme( (*(p_divk[i]))(0) ) << endl ;  
00227         cout << "Y component : " << norme( (*(p_divk[i]))(1) ) << endl ;  
00228         cout << "Z component : " << norme( (*(p_divk[i]))(2) ) << endl ;  
00229     
00230         cout << "Binaire::mom_constr : norme source : " << endl ;
00231         cout << "X component : " << norme( (*(p_source[i]))(0) ) << endl ;  
00232         cout << "Y component : " << norme( (*(p_source[i]))(1) ) << endl ;  
00233         cout << "Z component : " << norme( (*(p_source[i]))(2) ) << endl ;  
00234     
00235     
00236         cout << 
00237         "Binaire::mom_constr : rel. diff. div(K) <-> source : "
00238         << endl ;
00239         cout << "X component : " << diffx  << endl ;  
00240         cout << "Y component : " << diffy  << endl ;  
00241         cout << "Z component : " << diffz  << endl ;  
00242     
00243     
00244         somx += max( abs(diffx) ) ;    
00245         somy += max( abs(diffy) ) ;    
00246         somz += max( abs(diffz) ) ;    
00247     }   
00248     
00249     // Total error
00250     // -----------
00251 
00252     p_mom_constr = new Tbl(3) ; 
00253     p_mom_constr->set_etat_qcq() ;
00254     
00255     p_mom_constr->set(0) = 0.5 * somx ;  
00256     p_mom_constr->set(1) = 0.5 * somy ;  
00257     p_mom_constr->set(2) = 0.5 * somz ; 
00258     
00259     
00260     }    
00261     
00262     return *p_mom_constr ;     
00263 
00264 }

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