tensor_change_triad.C

00001 /*
00002  *  Methods for changing the triad of a Tensor
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 tensor_change_triad_C[] = "$Header: /cvsroot/Lorene/C++/Source/Tensor/tensor_change_triad.C,v 1.7 2005/09/15 15:51:26 j_novak Exp $" ;
00027 
00028 
00029 /*
00030  * $Id: tensor_change_triad.C,v 1.7 2005/09/15 15:51:26 j_novak Exp $
00031  * $Log: tensor_change_triad.C,v $
00032  * Revision 1.7  2005/09/15 15:51:26  j_novak
00033  * The "rotation" (change of triad) methods take now Scalars as default
00034  * arguments.
00035  *
00036  * Revision 1.6  2005/02/03 14:31:37  f_limousin
00037  * Correction of an error in the case Cartesian --> Cartesian for
00038  * a Sym_tensor. Now the components of the tensor are modified
00039  * using a temporary.
00040  *
00041  * Revision 1.5  2003/10/28 21:29:08  e_gourgoulhon
00042  * -- Read-only access to the components performed via operator()(int, int)
00043  *     instead of set(int, int).
00044  * -- Corrected index range in the case Cartesian -> Cartesian.
00045  *
00046  * Revision 1.4  2003/10/27 10:50:24  e_gourgoulhon
00047  * Added the case of a twice contravariant tensor in the assert.
00048  *
00049  * Revision 1.3  2003/10/06 14:25:51  j_novak
00050  * Added a test #ifndef... to prevent a warning
00051  *
00052  * Revision 1.2  2003/10/05 21:12:19  e_gourgoulhon
00053  * - Modified some assert.
00054  * - Corrected bug on index range in line 200.
00055  *
00056  * Revision 1.1  2003/09/29 12:52:57  j_novak
00057  * Methods for changing the triad are implemented.
00058  *
00059  *
00060  * $Header: /cvsroot/Lorene/C++/Source/Tensor/tensor_change_triad.C,v 1.7 2005/09/15 15:51:26 j_novak Exp $
00061  *
00062  */
00063 
00064 // C headers
00065 #include <assert.h>
00066 
00067 // Lorene headers
00068 #include "tensor.h"
00069 
00070 void Tensor::change_triad(const Base_vect& new_triad) {
00071 
00072   assert (valence == 2) ;
00073   assert(triad != 0x0) ; 
00074   
00075   const Base_vect_cart* nbvc = dynamic_cast<const Base_vect_cart*>(&new_triad) ; 
00076 #ifndef NDEBUG
00077   const Base_vect_spher* nbvs 
00078     = dynamic_cast<const Base_vect_spher*>(&new_triad) ; 
00079 #endif
00080 
00081   assert((nbvc != 0x0) || (nbvs != 0x0)) ;
00082    
00083   const Base_vect_cart* bvc = dynamic_cast<const Base_vect_cart*>(triad) ; 
00084   const Base_vect_spher* bvs = dynamic_cast<const Base_vect_spher*>(triad) ; 
00085     
00086   assert((bvc != 0x0) || (bvs != 0x0)) ;
00087 
00088   // ---------------------------------------------
00089   // Case where the input triad is a Cartesian one
00090   // ---------------------------------------------
00091   if (nbvc != 0x0) {
00092     assert(nbvs == 0x0) ;
00093     
00094     // -----------------------------
00095     // Case cartesian -> cartesian
00096     // -----------------------------
00097     if (bvc != 0x0) {   // The old triad is a cartesian one
00098       assert(bvs == 0x0) ; 
00099       
00100       int ind = nbvc->get_align() * (bvc->get_align()) ; 
00101       
00102       switch (ind) {
00103     
00104       case 1 : {    // the two bases are aligned : nothing to do
00105             // -----------------------------------------
00106     
00107     break ;         
00108       }
00109     
00110       case - 1 : {    // the two bases are anti-aligned 
00111     // ------------------------------
00112 
00113       Tensor copie (*this) ;
00114 
00115       set(1, 3) = - copie(1, 3) ; // {xz} --> - {xz}
00116       set(2, 3) = - copie(2, 3) ; // {yz} --> - {yz}
00117       set(3, 1) = - copie(3, 1) ; // {zx} --> - {zx}
00118       set(3, 2) = - copie(3, 2) ; // {zy} --> - {zy}
00119       // all other components are unchanged
00120       break ; 
00121       }
00122       case 0 : {    // the two basis have not a special relative orientation
00123             // -----------------------------------------------------
00124     cout << 
00125         "Tensor::change_basis : general value of rot_phi "
00126          << " not contemplated yet, sorry !" << endl ;
00127     abort() ; 
00128     break ;         
00129       }
00130         
00131       default : {       // error
00132     cout << 
00133       "Tensor::change_basis : unexpected value of ind !" << endl ;
00134     cout << "  ind = " << ind << endl ; 
00135     abort() ; 
00136     break ;         
00137       }
00138       }
00139 
00140     }   // end of the cart -> cart basis case
00141     
00142 
00143     // -----------------------------
00144     // Case spherical -> cartesian
00145     // -----------------------------
00146     if (bvs != 0x0) {   // The old triad is a spherical one
00147 
00148       assert(bvc == 0x0) ; 
00149       
00150       // The triads should be the same as that associated 
00151       // with the mapping :
00152       assert( *nbvc == mp->get_bvect_cart() ) ; 
00153       assert( *bvs == mp->get_bvect_spher() ) ; 
00154 
00155       // Only for double-covariant tensors or double-contravariant tensors
00156       assert( ( (type_indice(0)==COV) && (type_indice(1)==COV) ) ||
00157           ( (type_indice(0)==CON) && (type_indice(1)==CON) ) ) ;  
00158 #ifndef NDEBUG
00159       int nz = mp->get_mg()->get_nzone() ;
00160       for (int i=0; i<nz; i++) {
00161       assert( mp->get_mg()->get_np(i) >= 4) ;
00162       assert( mp->get_mg()->get_nt(i) >= 5) ;
00163       }
00164 #endif
00165       // Temporary storage of the components
00166       // the Base_vect *this is not valid...
00167       Tensor tmp(*mp, 2, COV, *triad) ;
00168       for (int i=1; i<=3; i++) { 
00169     mp->comp_x_from_spherical(operator()(1,i), operator()(2,i), 
00170                   operator()(3,i), tmp.set(1,i)) ; 
00171     mp->comp_y_from_spherical(operator()(1,i), operator()(2,i), 
00172                   operator()(3,i), tmp.set(2,i)) ; 
00173     mp->comp_z_from_spherical(operator()(1,i), operator()(2,i), tmp.set(3,i) ) ;
00174       }
00175       for (int i=1; i<=3; i++) {
00176     mp->comp_x_from_spherical(tmp(i,1), tmp(i,2), tmp(i,3), set(i,1)) ;
00177     mp->comp_y_from_spherical(tmp(i,1), tmp(i,2), tmp(i,3), set(i,2)) ;
00178     mp->comp_z_from_spherical(tmp(i,1), tmp(i,2), set(i,3)) ;
00179       } 
00180       
00181     }// End of the spher -> cart case
00182   } // End of the case of cartesian new triad
00183 
00184   // ---------------------------------------------
00185   // Case where the new triad is a spherical one
00186   // ---------------------------------------------
00187   else {
00188 
00189     assert(nbvc == 0x0) ;
00190 
00191     // ---------------------------------
00192     //     Case cartesian -> spherical 
00193     // ---------------------------------
00194     if (bvc != 0x0) {   // The old triad is a cartesian one
00195       assert(bvs == 0x0) ; 
00196       
00197       // The triads should be the same as that associated 
00198       // with the mapping :
00199       assert( *nbvs == mp->get_bvect_spher() ) ; 
00200       assert( *bvc == mp->get_bvect_cart() ) ; 
00201 
00202       // Only for double-covariant tensors or double-contravariant tensors
00203       assert( ( (type_indice(0)==COV) && (type_indice(1)==COV) ) ||
00204           ( (type_indice(0)==CON) && (type_indice(1)==CON) ) ) ;  
00205 #ifndef NDEBUG
00206       int nz = mp->get_mg()->get_nzone() ;
00207       for (int i=0; i<nz; i++) {
00208       assert( mp->get_mg()->get_np(i) >= 4) ;
00209       assert( mp->get_mg()->get_nt(i) >= 5) ;
00210       }
00211 #endif
00212       
00213       // Temporary storage of the components
00214       Tensor tmp(*mp, 2, COV, *triad) ;
00215       for (int i=1; i<=3; i++) {
00216     mp->comp_r_from_cartesian(operator()(1,i), operator()(2,i), 
00217                   operator()(3,i), tmp.set(1,i)) ; 
00218     mp->comp_t_from_cartesian(operator()(1,i), operator()(2,i), 
00219                   operator()(3,i), tmp.set(2,i)) ; 
00220     mp->comp_p_from_cartesian(operator()(1,i), operator()(2,i), tmp.set(3,i)) ;
00221       }
00222       for (int i=1; i<=3; i++) {
00223     mp->comp_r_from_cartesian(tmp(i,1), tmp(i,2), tmp(i,3), set(i,1)) ; 
00224     mp->comp_t_from_cartesian(tmp(i,1), tmp(i,2), tmp(i,3), set(i,2)) ; 
00225     mp->comp_p_from_cartesian(tmp(i,1), tmp(i,2), set(i,3)) ;
00226       }
00227     }   // end of the  case cart -> spher
00228 
00229 
00230     // ------------------------------------
00231     //      Case spherical -> spherical
00232     // ------------------------------------
00233     if (bvs != 0x0) {   
00234       
00235       assert(bvc == 0x0) ; 
00236       
00237       cout << "Tensor::change_triad : case not treated yet !" << endl ;
00238       abort() ; 
00239     }   // end of the spher->spher basis case
00240 
00241   } //  End of the case of spherical new triad
00242 
00243   triad = &new_triad ;
00244 
00245 }

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