base_vect_spher.C

00001 /*
00002  *  Methods of class Base_vect_spher
00003  *
00004  *   (see file base_vect.h for documentation)
00005  *
00006  */
00007 
00008 /*
00009  *   Copyright (c) 2000-2002 Eric Gourgoulhon
00010  *   Copyright (c) 2000-2001 Philippe Grandclement
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 as published by
00016  *   the Free Software Foundation; either version 2 of the License, or
00017  *   (at your option) any later version.
00018  *
00019  *   LORENE is distributed in the hope that it will be useful,
00020  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022  *   GNU General Public License for more details.
00023  *
00024  *   You should have received a copy of the GNU General Public License
00025  *   along with LORENE; if not, write to the Free Software
00026  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00027  *
00028  */
00029 
00030 char base_vect_spher_C[] = "$Header: /cvsroot/Lorene/C++/Source/Base_vect/base_vect_spher.C,v 1.5 2002/10/16 14:36:31 j_novak Exp $" ;
00031 
00032 /*
00033  * $Id: base_vect_spher.C,v 1.5 2002/10/16 14:36:31 j_novak Exp $
00034  * $Log: base_vect_spher.C,v $
00035  * Revision 1.5  2002/10/16 14:36:31  j_novak
00036  * Reorganization of #include instructions of standard C++, in order to
00037  * use experimental version 3 of gcc.
00038  *
00039  * Revision 1.4  2002/07/03 12:31:08  j_novak
00040  * cartesian<->spherical triad change for valence 2 Tenseur added (not completely tested)
00041  *
00042  * Revision 1.3  2002/01/15 09:09:49  e_gourgoulhon
00043  * Suppression of cout printing in the comparison operator
00044  *
00045  * Revision 1.2  2001/12/04 21:27:52  e_gourgoulhon
00046  *
00047  * All writing/reading to a binary file are now performed according to
00048  * the big endian convention, whatever the system is big endian or
00049  * small endian, thanks to the functions fwrite_be and fread_be
00050  *
00051  * Revision 1.1.1.1  2001/11/20 15:19:28  e_gourgoulhon
00052  * LORENE
00053  *
00054  * Revision 2.5  2000/09/19  16:09:40  phil
00055  * *** empty log message ***
00056  *
00057  * Revision 2.4  2000/09/19  15:33:23  phil
00058  * ajout passage de cartesinne en spherique
00059  *
00060  * Revision 2.3  2000/02/09  13:24:47  eric
00061  * REFONTE COMPLETE DE LA CLASSE
00062  * L'identification n'est plus base sur un membre statique (numero
00063  * d'instance) mais sur les caracteres physiques (rot_phi, etc...)
00064  * Ajout des membres ori_x, ori_y, ori_z
00065  * Ajout des constructeurs par copie et lecture de fichier.
00066  *
00067  * Revision 2.2  2000/01/10  15:43:57  eric
00068  * Methode change_basis.
00069  *
00070  * Revision 2.1  2000/01/10  13:27:09  eric
00071  * Ajout de la fonction set_rot_phi.
00072  *
00073  * Revision 2.0  2000/01/10  12:43:33  eric
00074  * *** empty log message ***
00075  *
00076  *
00077  * $Header: /cvsroot/Lorene/C++/Source/Base_vect/base_vect_spher.C,v 1.5 2002/10/16 14:36:31 j_novak Exp $
00078  *
00079  */
00080 
00081 // Headers C
00082 #include <math.h>
00083 #include <stdlib.h>
00084 
00085 // Headers Lorene
00086 #include "base_vect.h"
00087 #include "tenseur.h"
00088 #include "utilitaires.h"
00089 
00090             //--------------//
00091             // Constructors //
00092             //--------------//
00093 
00094 // Standard constructor without name
00095 // ---------------------------------
00096 Base_vect_spher::Base_vect_spher(double xa0, double ya0, double za0,
00097                  double rot_phi_i) 
00098                 : ori_x(xa0), 
00099                   ori_y(ya0), 
00100                   ori_z(za0), 
00101                   rot_phi(rot_phi_i) {} 
00102 
00103 
00104 
00105 
00106 
00107 // Standard constructor with name
00108 // ------------------------------
00109 Base_vect_spher::Base_vect_spher(double xa0, double ya0, double za0,
00110                  double rot_phi_i, const char* name_i)  
00111                 : Base_vect(name_i), 
00112                   ori_x(xa0), 
00113                   ori_y(ya0), 
00114                   ori_z(za0), 
00115                   rot_phi(rot_phi_i) {} 
00116                 
00117 // Copy constructor
00118 // ----------------
00119 Base_vect_spher::Base_vect_spher(const Base_vect_spher& bi)  
00120                 : Base_vect(bi), 
00121                   ori_x(bi.ori_x), 
00122                   ori_y(bi.ori_y), 
00123                   ori_z(bi.ori_z), 
00124                   rot_phi(bi.rot_phi) {} 
00125 
00126 // Constructor from file
00127 // ---------------------
00128 Base_vect_spher::Base_vect_spher(FILE* fich) 
00129                    : Base_vect(fich) {
00130         
00131     fread_be(&ori_x, sizeof(double), 1, fich) ;     
00132     fread_be(&ori_y, sizeof(double), 1, fich) ;     
00133     fread_be(&ori_z, sizeof(double), 1, fich) ;     
00134     fread_be(&rot_phi, sizeof(double), 1, fich) ;       
00135 
00136 }
00137 
00138 
00139             //--------------//
00140             //  Destructor  //
00141             //--------------//
00142 
00143 Base_vect_spher::~Base_vect_spher(){
00144     
00145     // does nothing
00146         
00147 }
00148 
00149             //--------------//
00150             //   Mutators   //
00151             //--------------//
00152 
00153 // Assignment 
00154 //-----------
00155 void Base_vect_spher::operator=(const Base_vect_spher& bi) {
00156     
00157     set_name(bi.name) ; 
00158     
00159     ori_x = bi.ori_x ; 
00160     ori_y = bi.ori_y ; 
00161     ori_z = bi.ori_z ; 
00162     rot_phi = bi.rot_phi ;
00163     
00164 }
00165 
00166 // Change of the elements
00167 // ----------------------
00168 void Base_vect_spher::set_ori(double xa0, double ya0, double za0) {
00169 
00170     ori_x = xa0 ; 
00171     ori_y = ya0 ; 
00172     ori_z = za0 ; 
00173 
00174 }
00175 
00176 
00177 void Base_vect_spher::set_rot_phi(double rot_phi_i) {
00178     
00179     rot_phi = rot_phi_i ;
00180      
00181 }
00182 
00183             //-----------------------//
00184             //  Comparison operator  //
00185             //-----------------------//
00186 
00187 
00188 bool Base_vect_spher::operator==(const Base_vect& bi) const {
00189     
00190     bool resu = true ; 
00191     
00192     if ( bi.identify() != identify() ) {
00193     // cout << "The second Base_vect is not of type Base_vect_spher !" << endl ;
00194     resu = false ; 
00195     }
00196     else{
00197     
00198     const Base_vect_spher& bis = dynamic_cast<const Base_vect_spher&>( bi ) ; 
00199 
00200     if (bis.ori_x != ori_x) {
00201         cout 
00202         << "The two Base_vect_spher have different X origin : " << ori_x 
00203         << " <-> " << bis.ori_x << endl ; 
00204         resu = false ; 
00205     }
00206 
00207     if (bis.ori_y != ori_y) {
00208         cout 
00209         << "The two Base_vect_spher have different Y origin : " << ori_y 
00210         << " <-> " << bis.ori_y << endl ; 
00211         resu = false ; 
00212     }
00213 
00214     if (bis.ori_z != ori_z) {
00215         cout 
00216         << "The two Base_vect_spher have different Z origin : " << ori_z 
00217         << " <-> " << bis.ori_z << endl ; 
00218         resu = false ; 
00219     }
00220 
00221     if (bis.rot_phi != rot_phi) {
00222         cout 
00223         << "The two Base_vect_spher have different rot_phi : " << rot_phi 
00224         << " <-> " << bis.rot_phi << endl ; 
00225         resu = false ; 
00226     }
00227 
00228     
00229     }
00230     
00231     return resu ; 
00232     
00233 }
00234 
00235             //------------//
00236             //  Outputs   //
00237             //------------//
00238 
00239 void Base_vect_spher::sauve(FILE* fich) const {
00240 
00241     Base_vect::sauve(fich) ; 
00242     
00243     fwrite_be(&ori_x, sizeof(double), 1, fich) ;    
00244     fwrite_be(&ori_y, sizeof(double), 1, fich) ;    
00245     fwrite_be(&ori_z, sizeof(double), 1, fich) ;    
00246     fwrite_be(&rot_phi, sizeof(double), 1, fich) ;  
00247    
00248 }
00249 
00250 ostream& Base_vect_spher::operator>>(ostream & ost) const {
00251     
00252     ost << "Absolute coordinates (X,Y,Z) of the origin : " 
00253     << ori_x << "  " << ori_y << "  " << ori_z << endl ; 
00254     ost << "Azimuthal angle with respect to the Absolute frame : " 
00255     << rot_phi << endl ; 
00256     
00257     return ost ;
00258 
00259 }
00260 
00261 
00262 
00263 
00264 
00265             //--------------------------------------//
00266             //      Change of basis         //
00267             //--------------------------------------//
00268 
00269 void Base_vect_spher::change_basis(Tenseur& ti) const {
00270     
00271 
00272     assert(ti.get_etat() != ETATNONDEF) ; 
00273 
00274     const Base_vect* triad_i = ti.get_triad() ; 
00275 
00276     assert(triad_i != 0x0) ;
00277     
00278     if (ti.get_etat() == ETATZERO) {
00279     ti.set_triad(*this) ; 
00280     return ; 
00281     }
00282     
00283     assert(ti.get_etat() == ETATQCQ) ; 
00284     
00285     const Base_vect_cart* bvc = dynamic_cast<const Base_vect_cart*>(triad_i) ; 
00286     const Base_vect_spher* bvs = dynamic_cast<const Base_vect_spher*>(triad_i) ; 
00287     
00288     // ---------------------------------------------
00289     // Case where the input triad is a Cartesian one
00290     // ---------------------------------------------
00291     if (bvc != 0x0) {   
00292     assert(bvs == 0x0) ; 
00293         
00294     switch (ti.get_valence()) {
00295             
00296         case 1 : {  // vector
00297         
00298         // The triads should be the same as that associated 
00299         // with the mapping :
00300         const Map* mp = ti.get_mp() ; 
00301         assert( *this == mp->get_bvect_spher() ) ; 
00302         assert( *bvc == mp->get_bvect_cart() ) ; 
00303 
00304         Cmp vx = ti(0) ; 
00305         Cmp vy = ti(1) ; 
00306         Cmp vz = ti(2) ; 
00307         
00308         mp->comp_r_from_cartesian(vx, vy, vz, ti.set(0)) ; 
00309         mp->comp_t_from_cartesian(vx, vy, vz, ti.set(1)) ; 
00310         mp->comp_p_from_cartesian(vx, vy, ti.set(2)) ; 
00311         
00312         break ;     
00313         }
00314             
00315         case 2 : {  
00316         
00317         // The triads should be the same as that associated 
00318         // with the mapping :
00319         const Map* mp = ti.get_mp() ; 
00320         assert( *this == mp->get_bvect_spher() ) ; 
00321         assert( *bvc == mp->get_bvect_cart() ) ; 
00322         //Only for double-covariant tensors
00323         for (int i=0; i<2; i++) 
00324           assert(ti.get_type_indice(i) == COV) ;  
00325 
00326         // Temporary storage of the components
00327         // the Base_vect *this is not valid...
00328         Tenseur tmp(*mp, 2, COV, *this) ;
00329         tmp.allocate_all() ;
00330         for (int i=0; i<3; i++) {
00331           mp->comp_r_from_cartesian(ti(0,i), ti(1,i), ti(2,i)
00332                         , tmp.set(0,i) ) ; 
00333           mp->comp_t_from_cartesian(ti(0,i), ti(1,i), ti(2,i)
00334                         , tmp.set(1,i) ) ; 
00335           mp->comp_p_from_cartesian(ti(0,i), ti(1,i), tmp.set(2,i) ) ;
00336         }
00337         for (int i=0; i<3; i++) {
00338           mp->comp_r_from_cartesian(tmp(i,0), tmp(i,1), tmp(i,2)
00339                         , ti.set(i,0) ) ; 
00340           mp->comp_t_from_cartesian(tmp(i,0), tmp(i,1), tmp(i,2)
00341                         , ti.set(i,1) ) ; 
00342           mp->comp_p_from_cartesian(tmp(i,0), tmp(i,1), ti.set(i,2) ) ;
00343         }
00344         
00345         
00346         break ;     
00347         }
00348 
00349         default : {
00350         cout << 
00351         "Base_vect_sphere::change_basis : the case of valence "
00352         << ti.get_valence() << " is not treated !" << endl ;
00353         abort() ; 
00354         break ; 
00355         }
00356     }   
00357     }   // end of the Cartesian basis case
00358 
00359 
00360     // ---------------------------------------------
00361     // Case where the input triad is a spherical one
00362     // ---------------------------------------------
00363     if (bvs != 0x0) {   
00364 
00365     assert(bvc == 0x0) ; 
00366     
00367     cout << "Base_vect_spher::change_basis : case not treated yet !" << endl ;
00368     abort() ; 
00369     }   // end of the spherical basis case
00370 
00371     ti.set_triad(*this) ; 
00372 }

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