1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
|
/*
* Methods for changing the triad of a Tensor
*
*/
/*
* Copyright (c) 2003 Eric Gourgoulhon & Jerome Novak
*
* This file is part of LORENE.
*
* LORENE is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* LORENE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LORENE; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
char tensor_change_triad_C[] = "$Header: /cvsroot/Lorene/C++/Source/Tensor/tensor_change_triad.C,v 1.9 2014/10/13 08:53:44 j_novak Exp $" ;
/*
* $Id: tensor_change_triad.C,v 1.9 2014/10/13 08:53:44 j_novak Exp $
* $Log: tensor_change_triad.C,v $
* Revision 1.9 2014/10/13 08:53:44 j_novak
* Lorene classes and functions now belong to the namespace Lorene.
*
* Revision 1.8 2014/10/06 15:13:20 j_novak
* Modified #include directives to use c++ syntax.
*
* Revision 1.7 2005/09/15 15:51:26 j_novak
* The "rotation" (change of triad) methods take now Scalars as default
* arguments.
*
* Revision 1.6 2005/02/03 14:31:37 f_limousin
* Correction of an error in the case Cartesian --> Cartesian for
* a Sym_tensor. Now the components of the tensor are modified
* using a temporary.
*
* Revision 1.5 2003/10/28 21:29:08 e_gourgoulhon
* -- Read-only access to the components performed via operator()(int, int)
* instead of set(int, int).
* -- Corrected index range in the case Cartesian -> Cartesian.
*
* Revision 1.4 2003/10/27 10:50:24 e_gourgoulhon
* Added the case of a twice contravariant tensor in the assert.
*
* Revision 1.3 2003/10/06 14:25:51 j_novak
* Added a test #ifndef... to prevent a warning
*
* Revision 1.2 2003/10/05 21:12:19 e_gourgoulhon
* - Modified some assert.
* - Corrected bug on index range in line 200.
*
* Revision 1.1 2003/09/29 12:52:57 j_novak
* Methods for changing the triad are implemented.
*
*
* $Header: /cvsroot/Lorene/C++/Source/Tensor/tensor_change_triad.C,v 1.9 2014/10/13 08:53:44 j_novak Exp $
*
*/
// C headers
#include <cassert>
// Lorene headers
#include "tensor.h"
namespace Lorene {
void Tensor::change_triad(const Base_vect& new_triad) {
assert (valence == 2) ;
assert(triad != 0x0) ;
const Base_vect_cart* nbvc = dynamic_cast<const Base_vect_cart*>(&new_triad) ;
#ifndef NDEBUG
const Base_vect_spher* nbvs
= dynamic_cast<const Base_vect_spher*>(&new_triad) ;
#endif
assert((nbvc != 0x0) || (nbvs != 0x0)) ;
const Base_vect_cart* bvc = dynamic_cast<const Base_vect_cart*>(triad) ;
const Base_vect_spher* bvs = dynamic_cast<const Base_vect_spher*>(triad) ;
assert((bvc != 0x0) || (bvs != 0x0)) ;
// ---------------------------------------------
// Case where the input triad is a Cartesian one
// ---------------------------------------------
if (nbvc != 0x0) {
assert(nbvs == 0x0) ;
// -----------------------------
// Case cartesian -> cartesian
// -----------------------------
if (bvc != 0x0) { // The old triad is a cartesian one
assert(bvs == 0x0) ;
int ind = nbvc->get_align() * (bvc->get_align()) ;
switch (ind) {
case 1 : { // the two bases are aligned : nothing to do
// -----------------------------------------
break ;
}
case - 1 : { // the two bases are anti-aligned
// ------------------------------
Tensor copie (*this) ;
set(1, 3) = - copie(1, 3) ; // {xz} --> - {xz}
set(2, 3) = - copie(2, 3) ; // {yz} --> - {yz}
set(3, 1) = - copie(3, 1) ; // {zx} --> - {zx}
set(3, 2) = - copie(3, 2) ; // {zy} --> - {zy}
// all other components are unchanged
break ;
}
case 0 : { // the two basis have not a special relative orientation
// -----------------------------------------------------
cout <<
"Tensor::change_basis : general value of rot_phi "
<< " not contemplated yet, sorry !" << endl ;
abort() ;
break ;
}
default : { // error
cout <<
"Tensor::change_basis : unexpected value of ind !" << endl ;
cout << " ind = " << ind << endl ;
abort() ;
break ;
}
}
} // end of the cart -> cart basis case
// -----------------------------
// Case spherical -> cartesian
// -----------------------------
if (bvs != 0x0) { // The old triad is a spherical one
assert(bvc == 0x0) ;
// The triads should be the same as that associated
// with the mapping :
assert( *nbvc == mp->get_bvect_cart() ) ;
assert( *bvs == mp->get_bvect_spher() ) ;
// Only for double-covariant tensors or double-contravariant tensors
assert( ( (type_indice(0)==COV) && (type_indice(1)==COV) ) ||
( (type_indice(0)==CON) && (type_indice(1)==CON) ) ) ;
#ifndef NDEBUG
int nz = mp->get_mg()->get_nzone() ;
for (int i=0; i<nz; i++) {
assert( mp->get_mg()->get_np(i) >= 4) ;
assert( mp->get_mg()->get_nt(i) >= 5) ;
}
#endif
// Temporary storage of the components
// the Base_vect *this is not valid...
Tensor tmp(*mp, 2, COV, *triad) ;
for (int i=1; i<=3; i++) {
mp->comp_x_from_spherical(operator()(1,i), operator()(2,i),
operator()(3,i), tmp.set(1,i)) ;
mp->comp_y_from_spherical(operator()(1,i), operator()(2,i),
operator()(3,i), tmp.set(2,i)) ;
mp->comp_z_from_spherical(operator()(1,i), operator()(2,i), tmp.set(3,i) ) ;
}
for (int i=1; i<=3; i++) {
mp->comp_x_from_spherical(tmp(i,1), tmp(i,2), tmp(i,3), set(i,1)) ;
mp->comp_y_from_spherical(tmp(i,1), tmp(i,2), tmp(i,3), set(i,2)) ;
mp->comp_z_from_spherical(tmp(i,1), tmp(i,2), set(i,3)) ;
}
}// End of the spher -> cart case
} // End of the case of cartesian new triad
// ---------------------------------------------
// Case where the new triad is a spherical one
// ---------------------------------------------
else {
assert(nbvc == 0x0) ;
// ---------------------------------
// Case cartesian -> spherical
// ---------------------------------
if (bvc != 0x0) { // The old triad is a cartesian one
assert(bvs == 0x0) ;
// The triads should be the same as that associated
// with the mapping :
assert( *nbvs == mp->get_bvect_spher() ) ;
assert( *bvc == mp->get_bvect_cart() ) ;
// Only for double-covariant tensors or double-contravariant tensors
assert( ( (type_indice(0)==COV) && (type_indice(1)==COV) ) ||
( (type_indice(0)==CON) && (type_indice(1)==CON) ) ) ;
#ifndef NDEBUG
int nz = mp->get_mg()->get_nzone() ;
for (int i=0; i<nz; i++) {
assert( mp->get_mg()->get_np(i) >= 4) ;
assert( mp->get_mg()->get_nt(i) >= 5) ;
}
#endif
// Temporary storage of the components
Tensor tmp(*mp, 2, COV, *triad) ;
for (int i=1; i<=3; i++) {
mp->comp_r_from_cartesian(operator()(1,i), operator()(2,i),
operator()(3,i), tmp.set(1,i)) ;
mp->comp_t_from_cartesian(operator()(1,i), operator()(2,i),
operator()(3,i), tmp.set(2,i)) ;
mp->comp_p_from_cartesian(operator()(1,i), operator()(2,i), tmp.set(3,i)) ;
}
for (int i=1; i<=3; i++) {
mp->comp_r_from_cartesian(tmp(i,1), tmp(i,2), tmp(i,3), set(i,1)) ;
mp->comp_t_from_cartesian(tmp(i,1), tmp(i,2), tmp(i,3), set(i,2)) ;
mp->comp_p_from_cartesian(tmp(i,1), tmp(i,2), set(i,3)) ;
}
} // end of the case cart -> spher
// ------------------------------------
// Case spherical -> spherical
// ------------------------------------
if (bvs != 0x0) {
assert(bvc == 0x0) ;
cout << "Tensor::change_triad : case not treated yet !" << endl ;
abort() ;
} // end of the spher->spher basis case
} // End of the case of spherical new triad
triad = &new_triad ;
}
}
|