vector_change_triad.C

00001 /*
00002  *  Methods for changing the triad of a Vector
00003  *
00004  */
00005 
00006 /*
00007  *   Copyright (c) 2003  Eric Gourgoulhon & Jerome Novak
00008  *
00009  *   This file is part of LORENE.
00010  *
00011  *   LORENE is free software; you can redistribute it and/or modify
00012  *   it under the terms of the GNU General Public License version 2
00013  *   as published by the Free Software Foundation.
00014  *
00015  *   LORENE is distributed in the hope that it will be useful,
00016  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *   GNU General Public License for more details.
00019  *
00020  *   You should have received a copy of the GNU General Public License
00021  *   along with LORENE; if not, write to the Free Software
00022  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  *
00024  */
00025 
00026 char vector_change_triad_C[] = "$Header: /cvsroot/Lorene/C++/Source/Tensor/vector_change_triad.C,v 1.7 2010/01/26 16:47:10 e_gourgoulhon Exp $" ;
00027 
00028 
00029 /*
00030  * $Id: vector_change_triad.C,v 1.7 2010/01/26 16:47:10 e_gourgoulhon Exp $
00031  * $Log: vector_change_triad.C,v $
00032  * Revision 1.7  2010/01/26 16:47:10  e_gourgoulhon
00033  * Suppressed the assert on np >= 4 (too strong ?).
00034  *
00035  * Revision 1.6  2005/09/15 15:51:26  j_novak
00036  * The "rotation" (change of triad) methods take now Scalars as default
00037  * arguments.
00038  *
00039  * Revision 1.5  2005/02/03 14:34:19  f_limousin
00040  * Improvement of the case Cartesian --> Cartesian to be consistent
00041  * with Tensor::change_triad(Base_vect&).
00042  *
00043  * Revision 1.4  2003/10/28 21:27:54  e_gourgoulhon
00044  * -- Read-only access to the components performed by operator()(int) instead of
00045  *     set(int ).
00046  * -- Corrected index range in the Cartesian->Cartesian case.
00047  *
00048  * Revision 1.3  2003/10/06 14:25:51  j_novak
00049  * Added a test #ifndef... to prevent a warning
00050  *
00051  * Revision 1.2  2003/10/03 14:41:31  e_gourgoulhon
00052  * Changed some assert.
00053  *
00054  * Revision 1.1  2003/09/29 12:52:57  j_novak
00055  * Methods for changing the triad are implemented.
00056  *
00057  *
00058  * $Header: /cvsroot/Lorene/C++/Source/Tensor/vector_change_triad.C,v 1.7 2010/01/26 16:47:10 e_gourgoulhon Exp $
00059  *
00060  */
00061 
00062 // C headers
00063 #include <assert.h>
00064 
00065 // Lorene headers
00066 #include "tensor.h"
00067 
00068 void Vector::change_triad(const Base_vect& new_triad) {
00069 
00070   assert(triad != 0x0) ; 
00071   
00072   const Base_vect_cart* nbvc = dynamic_cast<const Base_vect_cart*>(&new_triad) ; 
00073 #ifndef NDEBUG
00074   const Base_vect_spher* nbvs 
00075     = dynamic_cast<const Base_vect_spher*>(&new_triad) ; 
00076 #endif
00077 
00078   assert((nbvc != 0x0) || (nbvs != 0x0)) ;
00079    
00080   const Base_vect_cart* bvc = dynamic_cast<const Base_vect_cart*>(triad) ; 
00081   const Base_vect_spher* bvs = dynamic_cast<const Base_vect_spher*>(triad) ; 
00082     
00083   assert((bvc != 0x0) || (bvs != 0x0)) ;
00084 
00085   // ---------------------------------------------
00086   // Case where the input triad is a Cartesian one
00087   // ---------------------------------------------
00088   if (nbvc != 0x0) {
00089     assert(nbvs == 0x0) ;
00090     
00091     // -----------------------------
00092     // Case cartesian -> cartesian
00093     // -----------------------------
00094     if (bvc != 0x0) {   // The old triad is a cartesian one
00095       assert(bvs == 0x0) ; 
00096       
00097       int ind = nbvc->get_align() * (bvc->get_align()) ; 
00098       
00099       switch (ind) {
00100     
00101       case 1 : {    // the two bases are aligned : nothing to do
00102             // -----------------------------------------
00103     break ;         
00104       }
00105     
00106       case - 1 : {    // the two bases are anti-aligned 
00107       Vector copie (*this) ;
00108       
00109     set(1) = - copie(1) ;    // V^x --> - V^x
00110     set(2) = - copie(2) ;    // V^y --> - V^y
00111                              // V^z unchanged
00112     break ; 
00113       }
00114 
00115       case 0 : {    // the two basis have not a special relative orientation
00116             // -----------------------------------------------------
00117     cout << 
00118       "Vector::change_basis : general value of rot_phi "
00119          << " not contemplated yet, sorry !" << endl ;
00120     abort() ; 
00121     break ;         
00122       }
00123     
00124       default : {       // error
00125     cout << 
00126       "Vector::change_basis : unexpected value of ind !" << endl ;
00127     cout << "  ind = " << ind << endl ; 
00128     abort() ; 
00129     break ;         
00130       }
00131       }
00132       
00133     }   // end of the cart -> cart basis case
00134     
00135 
00136     // -----------------------------
00137     // Case spherical -> cartesian
00138     // -----------------------------
00139     if (bvs != 0x0) {   // The old triad is a spherical one
00140 
00141       assert(bvc == 0x0) ; 
00142       
00143       // The triads should be the same as that associated 
00144       // with the mapping :
00145       assert( *nbvc == mp->get_bvect_cart() ) ; 
00146       assert( *bvs == mp->get_bvect_spher() ) ; 
00147 #ifndef NDEBUG
00148       int nz = mp->get_mg()->get_nzone() ;
00149       for (int i=0; i<nz; i++) {
00150 //##      assert( mp->get_mg()->get_np(i) >= 4) ;
00151       assert( mp->get_mg()->get_nt(i) >= 5) ;
00152       }
00153 #endif
00154       Scalar res1(*mp) ;
00155       Scalar res2(*mp) ;
00156         
00157       mp->comp_x_from_spherical(*cmp[0], *cmp[1], *cmp[2], res1) ; 
00158       mp->comp_y_from_spherical(*cmp[0], *cmp[1], *cmp[2], res2) ; 
00159       mp->comp_z_from_spherical(*cmp[0], *cmp[1], set(3)) ; 
00160     
00161       set(1) = res1 ;
00162       set(2) = res2 ;
00163       
00164     }// End of the spher -> cart case
00165   } // End of the case of cartesian new triad
00166 
00167   // ---------------------------------------------
00168   // Case where the new triad is a spherical one
00169   // ---------------------------------------------
00170   else {
00171 
00172     assert(nbvc == 0x0) ;
00173 
00174     // ---------------------------------
00175     //     Case cartesian -> spherical 
00176     // ---------------------------------
00177     if (bvc != 0x0) {   // The old triad is a cartesian one
00178       assert(bvs == 0x0) ; 
00179       
00180       // The triads should be the same as that associated 
00181       // with the mapping :
00182       assert( *nbvs == mp->get_bvect_spher() ) ; 
00183       assert( *bvc == mp->get_bvect_cart() ) ; 
00184 #ifndef NDEBUG
00185       int nz = mp->get_mg()->get_nzone() ;
00186       for (int i=0; i<nz; i++) {
00187 //##      assert( mp->get_mg()->get_np(i) >= 4) ;
00188       assert( mp->get_mg()->get_nt(i) >= 5) ;
00189       }
00190 #endif
00191       Scalar res1(*mp) ;
00192       Scalar res2(*mp) ;
00193         
00194       mp->comp_r_from_cartesian(*cmp[0], *cmp[1], *cmp[2], res1) ; 
00195       mp->comp_t_from_cartesian(*cmp[0], *cmp[1], *cmp[2], res2) ; 
00196       mp->comp_p_from_cartesian(*cmp[0], *cmp[1], set(3)) ; 
00197 
00198       set(1) = res1 ;
00199       set(2) = res2 ;
00200     }   // end of the  case cart -> spher
00201 
00202     
00203     // ------------------------------------
00204     //      Case spherical -> spherical
00205     // ------------------------------------
00206     if (bvs != 0x0) {   
00207       
00208       assert(bvc == 0x0) ; 
00209       
00210       cout << "Vector::change_triad : case not treated yet !" << endl ;
00211       abort() ; 
00212     }   // end of the spher->spher basis case
00213 
00214   } //  End of the case of spherical new triad
00215 
00216   triad = &new_triad ;
00217 
00218 }

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