map.C

00001 /*
00002  *  Methods of class Map
00003  *
00004  *   (see file map.h for documentation)
00005  *
00006  */
00007 
00008 /*
00009  *   Copyright (c) 1999-2003 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 map_C[] = "$Header: /cvsroot/Lorene/C++/Source/Map/map.C,v 1.9 2008/09/29 13:23:51 j_novak Exp $" ;
00031 
00032 
00033 /*
00034  * $Id: map.C,v 1.9 2008/09/29 13:23:51 j_novak Exp $
00035  * $Log: map.C,v $
00036  * Revision 1.9  2008/09/29 13:23:51  j_novak
00037  * Implementation of the angular mapping associated with an affine
00038  * mapping. Things must be improved to take into account the domain index.
00039  *
00040  * Revision 1.8  2004/01/29 08:50:03  p_grandclement
00041  * Modification of Map::operator==(const Map&) and addition of the surface
00042  * integrales using Scalar.
00043  *
00044  * Revision 1.7  2003/12/30 22:53:23  e_gourgoulhon
00045  * Added methods flat_met_spher() and flat_met_cart() to get
00046  * flat metric associated with the coordinates described by the mapping.
00047  *
00048  * Revision 1.6  2003/10/15 10:30:46  e_gourgoulhon
00049  * Map::set_ori: changed x,y,z to xo,yo,zo not to shadow Coord's x,y,z
00050  * Map::set_rot_phi: changed phi to newphi not to shadow Coord phi.
00051  *
00052  * Revision 1.5  2003/06/20 14:45:06  f_limousin
00053  * Add operator==
00054  *
00055  * Revision 1.4  2002/10/16 14:36:40  j_novak
00056  * Reorganization of #include instructions of standard C++, in order to
00057  * use experimental version 3 of gcc.
00058  *
00059  * Revision 1.3  2002/05/22 12:44:04  f_limousin
00060  * Added print of ori_x, ori_y, ori_z and rot_phi in operator<<.
00061  *
00062  * Revision 1.2  2001/12/04 21:27:53  e_gourgoulhon
00063  *
00064  * All writing/reading to a binary file are now performed according to
00065  * the big endian convention, whatever the system is big endian or
00066  * small endian, thanks to the functions fwrite_be and fread_be
00067  *
00068  * Revision 1.1.1.1  2001/11/20 15:19:27  e_gourgoulhon
00069  * LORENE
00070  *
00071  * Revision 2.12  2000/02/11  14:26:54  eric
00072  * *** empty log message ***
00073  *
00074  * Revision 2.11  2000/02/11  13:38:23  eric
00075  * Ajout de la fonction convert_absolute.
00076  *
00077  * Revision 2.10  2000/02/09  13:25:29  eric
00078  * Mise en conformite avec le nouveau constructeur de Base_vect_spher
00079  * (passage des arguments ori_x, ori_y et ori_z).
00080  *
00081  * Revision 2.9  2000/01/12  12:54:53  eric
00082  * Ajout du Cmp null, *p_cmp_zero, et de la methode associee cmp_zero().
00083  *
00084  * Revision 2.8  2000/01/10  13:28:47  eric
00085  * Ajout des bases vectorielles associees aux coordonnees :
00086  *  membres bvect_spher et bvect_cart.
00087  *
00088  * Revision 2.7  1999/11/24  14:39:34  eric
00089  * Appel de reset_coord() dans les fonctions set_ori et set_rot_phi.
00090  *
00091  * Revision 2.6  1999/11/22  10:35:36  eric
00092  * Fonction del_coord() rebaptisee reset_coord().
00093  *
00094  * Revision 2.5  1999/10/15  14:12:29  eric
00095  * Suppression de l'appel a del_coord() dans le destructeur de Map.
00096  *
00097  * Revision 2.4  1999/10/15  09:23:04  eric
00098  * *** empty log message ***
00099  *
00100  * Revision 2.3  1999/10/14  14:26:51  eric
00101  * Depoussierage.
00102  * Documentation.
00103  *
00104  * Revision 2.2  1999/03/01  16:57:13  eric
00105  * Operateur <<
00106  *
00107  * Revision 2.1  1999/03/01  14:57:52  eric
00108  * *** empty log message ***
00109  *
00110  * Revision 2.0  1999/02/15  10:42:45  hyc
00111  * *** empty log message ***
00112  *
00113  * $Header: /cvsroot/Lorene/C++/Source/Map/map.C,v 1.9 2008/09/29 13:23:51 j_novak Exp $
00114  *
00115  */
00116 
00117 // headers C
00118 #include <math.h>
00119     
00120 // headers Lorene
00121 #include "map.h"
00122 #include "cmp.h"
00123 #include "metric.h"
00124 #include "utilitaires.h"
00125 
00126             //---------------//
00127             // Constructeurs //
00128             //---------------//
00129 
00130 // Constructor from a grid
00131 // -----------------------
00132 Map::Map(const Mg3d& mgi) : mg(&mgi), 
00133                 ori_x(0), ori_y(0), ori_z(0), rot_phi(0), 
00134                 bvect_spher(ori_x, ori_y, ori_z, rot_phi, 
00135                     "Mapping orthonormal spherical basis"), 
00136                 bvect_cart(rot_phi, "Mapping Cartesian basis"),
00137                             p_flat_met_spher(0x0), 
00138                             p_flat_met_cart(0x0),
00139                 p_mp_angu(0x0)
00140 {
00141         // The Coord's are constructed by the default Coord constructor
00142     
00143     // The null Cmp : 
00144     p_cmp_zero = new Cmp(this) ; 
00145     p_cmp_zero->set_etat_zero() ; 
00146 }
00147 
00148 // Copy constructor 
00149 // ----------------
00150 Map::Map(const Map& mp) : mg(mp.mg), 
00151               ori_x(mp.ori_x), ori_y(mp.ori_y), ori_z(mp.ori_z), 
00152               rot_phi(mp.rot_phi),
00153               bvect_spher(ori_x, ori_y, ori_z, rot_phi, 
00154                       "Mapping orthonormal spherical basis"), 
00155               bvect_cart(rot_phi, "Mapping Cartesian basis"), 
00156                           p_flat_met_spher(0x0), 
00157                           p_flat_met_cart(0x0),
00158               p_mp_angu(0x0) 
00159 {
00160         // The Coord's are constructed by the default Coord constructor
00161 
00162     // The null Cmp : 
00163     p_cmp_zero = new Cmp(this) ; 
00164     p_cmp_zero->set_etat_zero() ; 
00165 }
00166     
00167 // Constructor from file
00168 // ---------------------
00169 Map::Map(const Mg3d& mgi, FILE* fd) : mg(&mgi), 
00170                       bvect_spher(0., 0., 0., 0., 
00171                     "Mapping orthonormal spherical basis"), 
00172                       bvect_cart(0., "Mapping Cartesian basis"), 
00173                                       p_flat_met_spher(0x0), 
00174                                       p_flat_met_cart(0x0),
00175                       p_mp_angu(0x0) 
00176 {
00177     Mg3d* mg_tmp = new Mg3d(fd) ;   // la multi-grille d'origine
00178     if (*mg != *mg_tmp) {
00179     cout << "Map::Map(const Mg3d&, FILE*): grid not consistent !" 
00180          << endl ;
00181     abort() ;
00182     }
00183     delete mg_tmp ;
00184     
00185     fread_be(&ori_x, sizeof(double), 1, fd) ;       // ori_x
00186     fread_be(&ori_y, sizeof(double), 1, fd) ;       // ori_y
00187     fread_be(&ori_z, sizeof(double), 1, fd) ;       // ori_z
00188     fread_be(&rot_phi, sizeof(double), 1, fd) ;     // rot_phi
00189 
00190     bvect_spher.set_ori(ori_x, ori_y, ori_z) ; 
00191     bvect_spher.set_rot_phi(rot_phi) ; 
00192     bvect_cart.set_rot_phi(rot_phi) ; 
00193 
00194     // The Coord's are constructed by the default Coord constructor
00195     
00196     // The null Cmp : 
00197     p_cmp_zero = new Cmp(this) ; 
00198     p_cmp_zero->set_etat_zero() ; 
00199 }
00200 
00201             //--------------//
00202             // Destructeurs //
00203             //--------------//
00204 
00205 // Destructeur
00206 Map::~Map() {
00207     if (p_flat_met_spher != 0x0) delete p_flat_met_spher ;
00208     if (p_flat_met_cart != 0x0) delete p_flat_met_cart ;
00209     if (p_mp_angu != 0x0) delete p_mp_angu ;
00210     delete p_cmp_zero ;
00211 }
00212 
00213             //------------//
00214             // Sauvegarde //
00215             //------------//
00216 
00217 void Map::sauve(FILE* fd) const {
00218 
00219     mg->sauve(fd) ;             // la multi-grille
00220 
00221     fwrite_be(&ori_x, sizeof(double), 1, fd) ;      // ori_x
00222     fwrite_be(&ori_y, sizeof(double), 1, fd) ;      // ori_y
00223     fwrite_be(&ori_z, sizeof(double), 1, fd) ;      // ori_z
00224     fwrite_be(&rot_phi, sizeof(double), 1, fd) ;        // rot_phi
00225 }
00226     
00227             //------------//
00228             // Impression //
00229             //------------//
00230 
00231 // Operateurs <<
00232 ostream& operator<<(ostream& o, const Map & cv)  {
00233   o << "Absolute coordinates of the mapping origin: " << endl ;
00234   o << "  X_0, Y_0, Z_0 : " << cv.get_ori_x() << "  "
00235     <<  cv.get_ori_y() << "  " << cv.get_ori_z() << endl ; 
00236   o << "Rotation angle between the x-axis and X-axis : " 
00237     << cv.get_rot_phi() << endl ;   
00238     cv >> o ;
00239     return o ;
00240 }
00241     
00242             //-------------------//
00243             // Methodes diverses //
00244             //-------------------//
00245 
00246 void Map::set_ori(double xo, double yo, double zo) {
00247     ori_x = xo ;
00248     ori_y = yo ;
00249     ori_z = zo ;
00250 
00251     bvect_spher.set_ori(ori_x, ori_y, ori_z) ; 
00252     
00253     reset_coord() ;  // Mise a jour des Coords 
00254 }
00255 
00256 void Map::set_rot_phi(double newphi) {
00257 
00258     rot_phi = newphi ;
00259 
00260     bvect_spher.set_rot_phi(rot_phi) ; 
00261     bvect_cart.set_rot_phi(rot_phi) ; 
00262 
00263     reset_coord() ;  // Mise a jour des Coords 
00264 
00265 }
00266 
00267 // Gestion de la memoire
00268 // ---------------------
00269 void Map::reset_coord() {
00270 
00271     // Coordonnees spheriques centrees sur la grille : 
00272      r.del_t() ;
00273      tet.del_t() ;
00274      phi.del_t() ;
00275      sint.del_t() ;
00276      cost.del_t() ;
00277      sinp.del_t() ;
00278      cosp.del_t() ;
00279 
00280     // Coordonnees cartesiennes centrees sur la grille : 
00281      x.del_t() ;
00282      y.del_t() ;
00283      z.del_t() ;
00284 
00285     // Coordonnees cartesiennes "absolues" : 
00286      xa.del_t() ;
00287      ya.del_t() ;
00288      za.del_t() ;
00289 }
00290 
00291 
00292 // Conversion coordonnees (X,Y,Z) --> (r, theta, phi)
00293 // --------------------------------------------------
00294 
00295 void Map::convert_absolute(double xx, double yy, double zz, 
00296                double& rr, double& theta, double& pphi) const {
00297 
00298     // Cartesian coordinates aligned with the absolute ones but centered
00299     // on the mapping origin : 
00300     double x1 = xx - ori_x ;
00301     double y1 = yy - ori_y ;
00302     double z1 = zz - ori_z ;
00303  
00304     // Spherical coordinates :          
00305     double rho2 = x1*x1 + y1*y1 ; 
00306     double rho = sqrt( rho2 ) ;
00307     rr = sqrt(rho2 + z1*z1) ;
00308     theta = atan2(rho, z1) ;
00309     pphi = atan2(y1, x1) - rot_phi ;        // (rotation)
00310     if (pphi < 0) pphi += 2*M_PI ;
00311              
00312 }
00313 
00314 const Metric_flat& Map::flat_met_spher() const {
00315 
00316     if (p_flat_met_spher == 0x0) {
00317         p_flat_met_spher = new Metric_flat(*this, bvect_spher) ; 
00318     }
00319     
00320     return *p_flat_met_spher ;
00321 
00322 } 
00323 
00324 const Metric_flat& Map::flat_met_cart() const {
00325 
00326     if (p_flat_met_cart == 0x0) {
00327         p_flat_met_cart = new Metric_flat(*this, bvect_cart) ; 
00328     }
00329     
00330     return *p_flat_met_cart ;
00331 
00332 } 
00333 
00334 
00335 
00336 
00337 
00338 
00339 
00340 
00341 
00342 
00343 

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