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