base_vect_cart.C

00001 /*
00002  *  Methods of class Base_vect_cart
00003  *
00004  *   (see file base_vect.h for documentation)
00005  *
00006  */
00007 
00008 /*
00009  *   Copyright (c) 2000-2002 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 base_vect_cart_C[] = "$Header: /cvsroot/Lorene/C++/Source/Base_vect/base_vect_cart.C,v 1.6 2005/04/06 08:15:03 p_grandclement Exp $" ;
00031 
00032 /*
00033  * $Id: base_vect_cart.C,v 1.6 2005/04/06 08:15:03 p_grandclement Exp $
00034  * $Log: base_vect_cart.C,v $
00035  * Revision 1.6  2005/04/06 08:15:03  p_grandclement
00036  * Correction of change_triad when using sym tensors...
00037  *
00038  * Revision 1.5  2002/10/16 14:36:31  j_novak
00039  * Reorganization of #include instructions of standard C++, in order to
00040  * use experimental version 3 of gcc.
00041  *
00042  * Revision 1.4  2002/07/03 12:31:08  j_novak
00043  * cartesian<->spherical triad change for valence 2 Tenseur added (not completely tested)
00044  *
00045  * Revision 1.3  2002/01/15 09:09:49  e_gourgoulhon
00046  * Suppression of cout printing in the comparison operator
00047  *
00048  * Revision 1.2  2001/12/04 21:27:52  e_gourgoulhon
00049  *
00050  * All writing/reading to a binary file are now performed according to
00051  * the big endian convention, whatever the system is big endian or
00052  * small endian, thanks to the functions fwrite_be and fread_be
00053  *
00054  * Revision 1.1.1.1  2001/11/20 15:19:28  e_gourgoulhon
00055  * LORENE
00056  *
00057  * Revision 2.6  2000/09/12  12:15:15  eric
00058  * Fonction change_basis : ajout du cas spherique --> cartesiennes
00059  *  (appel des fonctions Map::comp_*_from_spherical).
00060  *
00061  * Revision 2.5  2000/02/10  17:04:13  eric
00062  * *** empty log message ***
00063  *
00064  * Revision 2.4  2000/02/10  15:38:51  eric
00065  * Premiere version de change_basis.
00066  *
00067  * Revision 2.3  2000/02/09  13:24:29  eric
00068  * REFONTE COMPLETE DE LA CLASSE
00069  * L'identification n'est plus base sur un membre statique (numero
00070  * d'instance) mais sur les caracteres physiques (rot_phi, etc...)
00071  * Ajout des constructeurs par copie et lecture de fichier.
00072  *
00073  * Revision 2.2  2000/01/10  15:43:29  eric
00074  * Methode change_basis.
00075  *
00076  * Revision 2.1  2000/01/10  13:27:32  eric
00077  * Ajout de la fonction set_rot_phi.
00078  *
00079  * Revision 2.0  2000/01/10  12:43:29  eric
00080  * *** empty log message ***
00081  *
00082  *
00083  * $Header: /cvsroot/Lorene/C++/Source/Base_vect/base_vect_cart.C,v 1.6 2005/04/06 08:15:03 p_grandclement Exp $
00084  *
00085  */
00086 
00087 // Headers C
00088 #include <math.h>
00089 #include <stdlib.h>
00090 
00091 // Headers Lorene
00092 #include "headcpp.h"
00093 #include "base_vect.h"
00094 #include "tenseur.h"
00095 #include "utilitaires.h"
00096 
00097             //--------------//
00098             // Constructors //
00099             //--------------//
00100 
00101 // Standard constructor without name
00102 // ---------------------------------
00103 Base_vect_cart::Base_vect_cart(double rot_phi_i) 
00104                   : rot_phi(rot_phi_i) {
00105     
00106     set_align() ;     
00107 }
00108 
00109 
00110 
00111 // Standard constructor with name
00112 // ------------------------------
00113 Base_vect_cart::Base_vect_cart(double rot_phi_i, const char* name_i)  
00114             : Base_vect(name_i), 
00115               rot_phi(rot_phi_i) {
00116     
00117     set_align() ;     
00118 }
00119 
00120 
00121 // Copy constructor
00122 // ----------------
00123 Base_vect_cart::Base_vect_cart(const Base_vect_cart& bi) 
00124                   : Base_vect(bi), 
00125                     rot_phi(bi.rot_phi) {
00126     
00127     set_align() ;     
00128 }
00129 
00130 // Constructor from file
00131 // ---------------------
00132 Base_vect_cart::Base_vect_cart(FILE* fich) 
00133                    : Base_vect(fich) {
00134         
00135     fread_be(&rot_phi, sizeof(double), 1, fich) ;       
00136 
00137     set_align() ;     
00138 }
00139 
00140 
00141             //--------------//
00142             //  Destructor  //
00143             //--------------//
00144 
00145 Base_vect_cart::~Base_vect_cart(){
00146     
00147     // does nothing
00148         
00149 }
00150 
00151  
00152             //--------------//
00153             //   Mutators   //
00154             //--------------//
00155 
00156 // Assignment 
00157 //-----------
00158 void Base_vect_cart::operator=(const Base_vect_cart& bi) {
00159     
00160     set_name(bi.name) ; 
00161     
00162     rot_phi = bi.rot_phi ;
00163     
00164     set_align() ;     
00165     
00166 }
00167 
00168 
00169 
00170 // Sets the value of the indicator align
00171 //--------------------------------------
00172 void Base_vect_cart::set_align() {
00173 
00174     if (rot_phi == double(0)) {
00175         align = 1 ; 
00176     }
00177     else{
00178     if (rot_phi == M_PI) {
00179         align = - 1 ; 
00180     }
00181     else{
00182 
00183         if (fabs(rot_phi) < 1.e-14) {
00184         cout << 
00185         "WARNING : Base_vect_cart::set_align : " << endl ; 
00186         cout << "   rot_phi is close to zero !" << endl ;
00187         arrete() ; 
00188         }
00189         
00190         if (fabs(rot_phi - M_PI) < 1.e-14) {
00191         cout << 
00192         "WARNING : Base_vect_cart::set_align : " << endl ; 
00193         cout << "   rot_phi is close to Pi !" << endl ;
00194         arrete() ; 
00195         }
00196         
00197         align = 0 ; 
00198         
00199     }
00200 
00201     }
00202 
00203 }
00204 
00205 void Base_vect_cart::set_rot_phi(double rot_phi_i) {
00206     
00207     rot_phi = rot_phi_i ;
00208      
00209     set_align() ;   
00210 }
00211 
00212             //-----------------------//
00213             //  Comparison operator  //
00214             //-----------------------//
00215 
00216 
00217 bool Base_vect_cart::operator==(const Base_vect& bi) const {
00218     
00219     bool resu = true ; 
00220     
00221     if ( bi.identify() != identify() ) {
00222     // cout << "The second Base_vect is not of type Base_vect_cart !" << endl ;
00223     resu = false ; 
00224     }
00225     else{
00226     
00227     const Base_vect_cart& bic = dynamic_cast<const Base_vect_cart&>( bi ) ; 
00228 
00229     if (bic.rot_phi != rot_phi) {
00230         cout 
00231         << "The two Base_vect_cart have different rot_phi : " << rot_phi 
00232         << " <-> " << bic.rot_phi << endl ; 
00233         resu = false ; 
00234     }
00235 
00236     
00237     }
00238     
00239     return resu ; 
00240     
00241 }
00242 
00243             //------------//
00244             //  Outputs   //
00245             //------------//
00246 
00247 void Base_vect_cart::sauve(FILE* fich) const {
00248 
00249     Base_vect::sauve(fich) ; 
00250     
00251     fwrite_be(&rot_phi, sizeof(double), 1, fich) ;  
00252    
00253 }
00254 
00255 ostream& Base_vect_cart::operator>>(ostream & ost) const {
00256     
00257     ost << "Azimuthal angle with respect to the Absolute frame : " 
00258     << rot_phi << endl ; 
00259     
00260     return ost ;
00261 
00262 }
00263 
00264 
00265 
00266 
00267 
00268 
00269             //--------------------------------------//
00270             //      Change of basis         //
00271             //--------------------------------------//
00272 
00273 void Base_vect_cart::change_basis(Tenseur& ti) const {
00274 
00275 
00276     assert(ti.get_etat() != ETATNONDEF) ; 
00277 
00278     const Base_vect* triad_i = ti.get_triad() ; 
00279 
00280     assert(triad_i != 0x0) ; 
00281     
00282     if (ti.get_etat() == ETATZERO) {
00283     ti.set_triad(*this) ; 
00284     return ; 
00285     }
00286     
00287     assert(ti.get_etat() == ETATQCQ) ; 
00288     
00289     const Base_vect_cart* bvc = dynamic_cast<const Base_vect_cart*>(triad_i) ; 
00290     const Base_vect_spher* bvs = dynamic_cast<const Base_vect_spher*>(triad_i) ; 
00291     
00292     // ---------------------------------------------
00293     // Case where the input triad is a Cartesian one
00294     // ---------------------------------------------
00295     if (bvc != 0x0) {   
00296     assert(bvs == 0x0) ; 
00297     
00298     int ind = align * (bvc->align) ; 
00299     
00300     Tenseur copie (ti) ;
00301     
00302     switch (ind) {
00303         
00304         case 1 : {  // the two basis are aligned : nothing to do
00305             // -----------------------------------------
00306         
00307         break ;         
00308         }
00309         
00310         case - 1 : {    // the two basis are anti-aligned 
00311                 // ------------------------------
00312         
00313         switch (ti.get_valence()) {
00314             
00315             case 1 : {  // vector
00316             ti.set(0) = - ti(0) ;    // V^x --> - V^x
00317             ti.set(1) = - ti(1) ;    // V^y --> - V^y
00318                          // V^z unchanged
00319             break ;     
00320             }
00321             
00322             case 2 : { // rank 2 tensor
00323             ti.set(0, 2) = - copie(0, 2) ; // {xz} --> - {xz}
00324             ti.set(1, 2) = - copie(1, 2) ; // {yz} --> - {yz}
00325             ti.set(2, 0) = - copie(2, 0) ; // {zx} --> - {zx}
00326             ti.set(2, 1) = - copie(2, 1) ; // {zy} --> - {zy}
00327                     // all other components are unchanged
00328             break ; 
00329             }
00330             
00331             default : {
00332             cout << 
00333             "Base_vect_cart::change_basis : the case of valence "
00334             << ti.get_valence() << " is not treated !" << endl ;
00335             abort() ; 
00336             break ; 
00337             }
00338         }
00339         break ;         
00340         }           // end of case ind = -1
00341         
00342         case 0 : {  // the two basis have not a special relative orientation
00343             // -----------------------------------------------------
00344         cout << 
00345         "Base_vect_cart::change_basis : general value of rot_phi "
00346         << " not contemplated yet, sorry !" << endl ;
00347         abort() ; 
00348         break ;         
00349         }
00350         
00351         default : {     // error
00352         cout << 
00353         "Base_vect_cart::change_basis : unexpected value of ind !" << endl ;
00354         cout << "  ind = " << ind << endl ; 
00355         abort() ; 
00356         break ;         
00357         }
00358     }
00359 
00360     }   // end of the Cartesian basis case
00361 
00362 
00363     // ---------------------------------------------
00364     // Case where the input triad is a spherical one
00365     // ---------------------------------------------
00366     if (bvs != 0x0) {   
00367 
00368     assert(bvc == 0x0) ; 
00369     
00370     switch (ti.get_valence()) {
00371             
00372         case 1 : {  // vector
00373         
00374         // The triads should be the same as that associated 
00375         // with the mapping :
00376         const Map* mp = ti.get_mp() ; 
00377         assert( *this == mp->get_bvect_cart() ) ; 
00378         assert( *bvs == mp->get_bvect_spher() ) ; 
00379 
00380         Cmp vr = ti(0) ; 
00381         Cmp vt = ti(1) ; 
00382         Cmp vp = ti(2) ; 
00383         
00384         mp->comp_x_from_spherical(vr, vt, vp, ti.set(0)) ; 
00385         mp->comp_y_from_spherical(vr, vt, vp, ti.set(1)) ; 
00386         mp->comp_z_from_spherical(vr, vt, ti.set(2)) ; 
00387         
00388         break ;     
00389         }
00390             
00391         case 2 : {  
00392         
00393         // The triads should be the same as that associated 
00394         // with the mapping :
00395         const Map* mp = ti.get_mp() ; 
00396         assert( *this == mp->get_bvect_cart() ) ; 
00397         assert( *bvs == mp->get_bvect_spher() ) ; 
00398         //Only for double-covariant tensors
00399         for (int i=0; i<2; i++) 
00400           assert(ti.get_type_indice(i) == COV) ;  
00401 
00402         // Temporary storage of the components
00403         // the Base_vect *this is not valid...
00404         Tenseur tmp(*mp, 2, COV, *this) ;
00405         tmp.allocate_all() ;
00406         for (int i=0; i<3; i++) {
00407           mp->comp_x_from_spherical(ti(0,i), ti(1,i), ti(2,i)
00408                         , tmp.set(0,i) ) ; 
00409           mp->comp_y_from_spherical(ti(0,i), ti(1,i), ti(2,i)
00410                         , tmp.set(1,i) ) ; 
00411           mp->comp_z_from_spherical(ti(0,i), ti(1,i), tmp.set(2,i) ) ;
00412         }
00413         for (int i=0; i<3; i++) {
00414           mp->comp_x_from_spherical(tmp(i,0), tmp(i,1), tmp(i,2)
00415                         , ti.set(i,0) ) ; 
00416           mp->comp_y_from_spherical(tmp(i,0), tmp(i,1), tmp(i,2)
00417                         , ti.set(i,1) ) ; 
00418           mp->comp_z_from_spherical(tmp(i,0), tmp(i,1), ti.set(i,2) ) ;
00419         }
00420         
00421         
00422         break ;     
00423         }
00424             
00425         default : {
00426         cout << 
00427         "Base_vect_cart::change_basis : the case of valence "
00428         << ti.get_valence() << " is not treated !" << endl ;
00429         abort() ; 
00430         break ; 
00431         }
00432     }
00433     
00434     
00435     }   // end of the spherical basis case
00436 
00437     ti.set_triad(*this) ; 
00438 
00439 } 

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