sym_tensor_trans.C

00001 /*
00002  *  Methods of class Sym_tensor_trans
00003  *
00004  *   (see file sym_tensor.h for documentation)
00005  *
00006  */
00007 
00008 /*
00009  *   Copyright (c) 2003-2004 Eric Gourgoulhon & Jerome Novak
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 sym_tensor_trans_C[] = "$Header: /cvsroot/Lorene/C++/Source/Tensor/sym_tensor_trans.C,v 1.16 2008/12/03 10:20:00 j_novak Exp $" ;
00031 
00032 /*
00033  * $Id: sym_tensor_trans.C,v 1.16 2008/12/03 10:20:00 j_novak Exp $
00034  * $Log: sym_tensor_trans.C,v $
00035  * Revision 1.16  2008/12/03 10:20:00  j_novak
00036  * Modified output.
00037  *
00038  * Revision 1.15  2006/09/15 08:48:01  j_novak
00039  * Suppression of some messages in the optimized version.
00040  *
00041  * Revision 1.14  2005/01/03 12:37:08  j_novak
00042  * Sym_tensor_trans::trace_from_det_one : modified the test on hijtt to
00043  * be compatible with older compilers.
00044  *
00045  * Revision 1.13  2005/01/03 08:36:36  f_limousin
00046  * Come back to the previous version.
00047  *
00048  * Revision 1.12  2005/01/03 08:13:26  f_limousin
00049  * The first argument of the function trace_from_det_one(...) is now
00050  * a Sym_tensor_trans instead of a Sym_tensor_tt (because of a
00051  * compilation error with some compilators).
00052  *
00053  * Revision 1.11  2004/12/28 14:21:48  j_novak
00054  * Added the method Sym_tensor_trans::trace_from_det_one
00055  *
00056  * Revision 1.10  2004/05/25 15:07:12  f_limousin
00057  * Add parameters in argument of the function tt_part for the case
00058  * of a Map_et.
00059  *
00060  * Revision 1.9  2004/03/30 14:01:19  j_novak
00061  * Copy constructors and operator= now copy the "derived" members.
00062  *
00063  * Revision 1.8  2004/03/30 08:01:16  j_novak
00064  * Better treatment of dzpuis in mutators.
00065  *
00066  * Revision 1.7  2004/03/29 16:13:07  j_novak
00067  * New methods set_longit_trans and set_tt_trace .
00068  *
00069  * Revision 1.6  2004/03/03 13:22:14  j_novak
00070  * The case where dzpuis = 0 is treated in tt_part().
00071  *
00072  * Revision 1.5  2004/02/18 18:48:39  e_gourgoulhon
00073  * Method trace() renamed the_trace() to avoid any confusion with
00074  * the new method Tensor::trace().
00075  *
00076  * Revision 1.4  2004/02/09 12:57:13  e_gourgoulhon
00077  * First implementation of method tt_part().
00078  *
00079  * Revision 1.3  2004/01/04 20:52:45  e_gourgoulhon
00080  * Added assignement (operator=) to a Tensor_sym.
00081  *
00082  * Revision 1.2  2003/10/28 21:24:52  e_gourgoulhon
00083  * Added new methods trace() and tt_part().
00084  *
00085  * Revision 1.1  2003/10/27 10:50:54  e_gourgoulhon
00086  * First version.
00087  *
00088  *
00089  *
00090  * $Header: /cvsroot/Lorene/C++/Source/Tensor/sym_tensor_trans.C,v 1.16 2008/12/03 10:20:00 j_novak Exp $
00091  *
00092  */
00093 
00094 // Headers C
00095 #include <stdlib.h>
00096 
00097 // Headers Lorene
00098 #include "metric.h"
00099 #include "param.h"
00100 
00101             //--------------//
00102             // Constructors //
00103             //--------------//
00104 
00105 // Standard constructor 
00106 // --------------------
00107 Sym_tensor_trans::Sym_tensor_trans(const Map& map, const Base_vect& triad_i,
00108         const Metric& met) 
00109     : Sym_tensor(map, CON, triad_i),
00110       met_div(&met) {
00111                 
00112     set_der_0x0() ;
00113 
00114 }
00115 
00116 // Copy constructor
00117 // ----------------
00118 Sym_tensor_trans::Sym_tensor_trans (const Sym_tensor_trans& source)
00119     : Sym_tensor(source), 
00120       met_div(source.met_div) {
00121     
00122     set_der_0x0() ;
00123 
00124     if (source.p_trace != 0x0) p_trace = new Scalar( *(source.p_trace) ) ; 
00125     if (source.p_tt != 0x0) p_tt = new Sym_tensor_tt( *(source.p_tt) ) ; 
00126     
00127 }   
00128 
00129 
00130 // Constructor from a file
00131 // -----------------------
00132 Sym_tensor_trans::Sym_tensor_trans(const Map& mapping, const Base_vect& triad_i, 
00133     const Metric& met, FILE* fd) 
00134     : Sym_tensor(mapping, triad_i, fd),
00135       met_div(&met) {
00136 
00137     set_der_0x0() ;
00138 }
00139 
00140             //--------------//
00141             //  Destructor  //
00142             //--------------//
00143 
00144 Sym_tensor_trans::~Sym_tensor_trans() {
00145 
00146   Sym_tensor_trans::del_deriv() ;   // in order not to follow the virtual aspect
00147                                     // of del_deriv()
00148 
00149 }
00150 
00151 
00152 
00153             //-------------------//
00154             // Memory managment  //
00155             //-------------------//
00156 
00157 void Sym_tensor_trans::del_deriv() const {
00158 
00159     if (p_trace != 0x0) delete p_trace ; 
00160     if (p_tt != 0x0) delete p_tt ; 
00161     
00162     set_der_0x0() ;
00163     Sym_tensor::del_deriv() ;
00164 
00165 }
00166 
00167 void Sym_tensor_trans::set_der_0x0() const {
00168 
00169     p_trace = 0x0 ; 
00170     p_tt = 0x0 ; 
00171 
00172 }
00173 
00174 
00175             //--------------//
00176             //  Assignment  //
00177             //--------------//
00178 
00179 void Sym_tensor_trans::operator=(const Sym_tensor_trans& source) {
00180     
00181     // Assignment of quantities common to all the derived classes of Sym_tensor
00182     Sym_tensor::operator=(source) ; 
00183 
00184     // Assignment of proper quantities of class Sym_tensor_trans
00185     assert(met_div == source.met_div) ; 
00186     
00187     del_deriv() ; 
00188     
00189     if (source.p_trace != 0x0) p_trace = new Scalar( *(source.p_trace) ) ; 
00190     if (source.p_tt != 0x0) p_tt = new Sym_tensor_tt( *(source.p_tt) ) ; 
00191     
00192 }
00193 
00194 
00195 void Sym_tensor_trans::operator=(const Sym_tensor& source) {
00196     
00197     // Assignment of quantities common to all the derived classes of Sym_tensor
00198     Sym_tensor::operator=(source) ; 
00199 
00200     // The metric which was set by the constructor is kept
00201     
00202     del_deriv() ;   
00203 }
00204 
00205 
00206 void Sym_tensor_trans::operator=(const Tensor_sym& source) {
00207     
00208     // Assignment of quantities common to all the derived classes of Sym_tensor
00209     Sym_tensor::operator=(source) ; 
00210 
00211     // The metric which was set by the constructor is kept
00212     
00213     del_deriv() ;   
00214 }
00215 
00216 
00217 
00218 void Sym_tensor_trans::operator=(const Tensor& source) {
00219     
00220     // Assignment of quantities common to all the derived classes of Sym_tensor
00221     Sym_tensor::operator=(source) ; 
00222 
00223     // The metric which was set by the constructor is kept
00224     
00225     del_deriv() ;   
00226 }
00227 
00228 void Sym_tensor_trans::set_tt_trace(const Sym_tensor_tt& htt, 
00229                     const Scalar& htrace, Param* par ) {
00230   
00231   assert (met_div == &htt.get_met_div() ) ;
00232 
00233   assert (htrace.check_dzpuis(4)) ;
00234 
00235   Scalar pot (*mp) ;
00236   if (dynamic_cast<const Map_af*>(mp) != 0x0) {
00237       pot = htrace.poisson() ;
00238   }
00239   else {
00240       pot = 0. ;
00241       htrace.poisson(*par, pot) ;
00242   }
00243 
00244   Sym_tensor tmp = (pot.derive_con(*met_div)).derive_con(*met_div) ; 
00245   tmp.dec_dzpuis() ;  
00246         
00247   *this = htrace * met_div->con() ; 
00248   dec_dzpuis(2) ; // this has now dzpuis = 2
00249   *this = htt + 0.5 * ( *this - tmp ) ;
00250   
00251   del_deriv() ;
00252 
00253   p_trace = new Scalar( htrace ) ;
00254   p_tt = new Sym_tensor_tt( htt ) ;
00255 
00256 }
00257 
00258 
00259             //-----------------------------//
00260             //    Computational methods    //
00261             //-----------------------------//
00262 
00263 const Scalar& Sym_tensor_trans::the_trace() const {
00264 
00265     if (p_trace == 0x0) {   // a new computation is necessary
00266         
00267         assert( (type_indice(0)==CON) && (type_indice(1)==CON) ) ; 
00268         p_trace = new Scalar( trace(*met_div) ) ; 
00269         
00270     }
00271     
00272     return *p_trace ; 
00273 
00274 }
00275 
00276 
00277 const Sym_tensor_tt& Sym_tensor_trans::tt_part(Param* par) const {
00278   
00279   if (p_tt == 0x0) {   // a new computation is necessary
00280 
00281     int dzp = the_trace().get_dzpuis() ;
00282 
00283     assert((dzp == 0) || (dzp == 4)) ;
00284 
00285     p_tt = new Sym_tensor_tt(*mp, *triad, *met_div) ; 
00286 
00287     Scalar pot (*mp) ;        
00288     if (dynamic_cast<const Map_af*>(mp) != 0x0) {
00289     pot =  the_trace().poisson() ; 
00290     }
00291     else {
00292     pot = 0. ;
00293     the_trace().poisson(*par, pot) ; 
00294     }
00295 
00296     Sym_tensor tmp = (pot.derive_con(*met_div)).derive_con(*met_div) ; 
00297     (dzp == 4) ? tmp.inc_dzpuis() : tmp.dec_dzpuis(3) ;  //## to be improved ?
00298         
00299     *p_tt = *this - 0.5 * ( the_trace() * met_div->con() - tmp ) ; 
00300         
00301   }
00302     
00303   return *p_tt ; 
00304 
00305 }
00306 
00307 
00308 void Sym_tensor_trans::trace_from_det_one(const Sym_tensor_tt& hijtt, 
00309                        double precis, int it_max) {
00310     
00311 #ifndef NDEBUG
00312   const Sym_tensor_trans* ptmp = 
00313       dynamic_cast<const Sym_tensor_trans*>(&hijtt) ;
00314   assert (ptmp != 0x0) ;
00315   assert (ptmp != this) ;
00316   for (int i=0; i<hijtt.get_n_comp(); i++)
00317       assert(hijtt.cmp[i]->check_dzpuis(2)) ;
00318 #endif
00319     assert( (precis > 0.) && (it_max > 0) ) ;
00320     assert (met_div == &hijtt.get_met_div() ) ;
00321     
00322     Sym_tensor_trans& hij = *this ;
00323     hij = hijtt ; //initialization
00324 
00325     // The trace h = f_{ij} h^{ij} :
00326     Scalar htrace(*mp) ;
00327         
00328     // Value of h at previous step of the iterative procedure below :
00329     Scalar htrace_prev(*mp) ;
00330     htrace_prev.set_etat_zero() ;   // initialisation to zero
00331     
00332     for (int it=0; it<=it_max; it++) {
00333       
00334         // Trace h from the condition det(f^{ij} + h^{ij}) = det f^{ij} :
00335       
00336         htrace = hij(1,1) * hij(2,3) * hij(2,3) 
00337         + hij(2,2) * hij(1,3) * hij(1,3) + hij(3,3) * hij(1,2) * hij(1,2)
00338         - 2.* hij(1,2) * hij(1,3) * hij(2,3) 
00339             - hij(1,1) * hij(2,2) * hij(3,3) ;
00340         
00341         htrace.dec_dzpuis(2) ; // dzpuis: 6 --> 4
00342         
00343     htrace += hij(1,2) * hij(1,2) + hij(1,3) * hij(1,3) 
00344                     + hij(2,3) * hij(2,3) - hij(1,1) * hij(2,2) 
00345                     - hij(1,1) * hij(3,3) - hij(2,2) * hij(3,3) ;
00346 
00347         // New value of hij from htrace and hijtt (obtained by solving 
00348         //    the Poisson equation for Phi) : 
00349 
00350         set_tt_trace(hijtt, htrace) ; 
00351 
00352         double diff = max(max(abs(htrace - htrace_prev))) ;
00353 #ifndef NDEBUG
00354         cout << "Sym_tensor_trans::trace_from_det_one : " 
00355          << "iteration : " << it << " convergence on trace(h): " << diff << endl ;
00356 #endif
00357         if (diff < precis) break ;
00358         else htrace_prev = htrace ;
00359 
00360         if (it == it_max) {
00361             cout << "Sym_tensor_trans::trace_from_det_one : convergence not reached \n" ;
00362             cout << "  for the required accuracy (" << precis << ") ! " << endl ;
00363             abort() ;
00364         }
00365     }
00366 
00367 }
00368 
00369 
00370 

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