| 1 |
/* |
| 2 |
* Methods of class Base_vect_spher |
| 3 |
* |
| 4 |
* (see file base_vect.h for documentation) |
| 5 |
* |
| 6 |
*/ |
| 7 |
|
| 8 |
/* |
| 9 |
* Copyright (c) 2000-2002 Eric Gourgoulhon |
| 10 |
* Copyright (c) 2000-2001 Philippe Grandclement |
| 11 |
* |
| 12 |
* This file is part of LORENE. |
| 13 |
* |
| 14 |
* LORENE is free software; you can redistribute it and/or modify |
| 15 |
* it under the terms of the GNU General Public License as published by |
| 16 |
* the Free Software Foundation; either version 2 of the License, or |
| 17 |
* (at your option) any later version. |
| 18 |
* |
| 19 |
* LORENE is distributed in the hope that it will be useful, |
| 20 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 |
* GNU General Public License for more details. |
| 23 |
* |
| 24 |
* You should have received a copy of the GNU General Public License |
| 25 |
* along with LORENE; if not, write to the Free Software |
| 26 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 27 |
* |
| 28 |
*/ |
| 29 |
|
| 30 |
char base_vect_spher_C[] = "$Header: /cvsroot/Lorene/C++/Source/Base_vect/base_vect_spher.C,v 1.7 2014/10/13 08:52:39 j_novak Exp $" ; |
| 31 |
|
| 32 |
/* |
| 33 |
* $Id: base_vect_spher.C,v 1.7 2014/10/13 08:52:39 j_novak Exp $ |
| 34 |
* $Log: base_vect_spher.C,v $ |
| 35 |
* Revision 1.7 2014/10/13 08:52:39 j_novak |
| 36 |
* Lorene classes and functions now belong to the namespace Lorene. |
| 37 |
* |
| 38 |
* Revision 1.6 2014/10/06 15:12:57 j_novak |
| 39 |
* Modified #include directives to use c++ syntax. |
| 40 |
* |
| 41 |
* Revision 1.5 2002/10/16 14:36:31 j_novak |
| 42 |
* Reorganization of #include instructions of standard C++, in order to |
| 43 |
* use experimental version 3 of gcc. |
| 44 |
* |
| 45 |
* Revision 1.4 2002/07/03 12:31:08 j_novak |
| 46 |
* cartesian<->spherical triad change for valence 2 Tenseur added (not completely tested) |
| 47 |
* |
| 48 |
* Revision 1.3 2002/01/15 09:09:49 e_gourgoulhon |
| 49 |
* Suppression of cout printing in the comparison operator |
| 50 |
* |
| 51 |
* Revision 1.2 2001/12/04 21:27:52 e_gourgoulhon |
| 52 |
* |
| 53 |
* All writing/reading to a binary file are now performed according to |
| 54 |
* the big endian convention, whatever the system is big endian or |
| 55 |
* small endian, thanks to the functions fwrite_be and fread_be |
| 56 |
* |
| 57 |
* Revision 1.1.1.1 2001/11/20 15:19:28 e_gourgoulhon |
| 58 |
* LORENE |
| 59 |
* |
| 60 |
* Revision 2.5 2000/09/19 16:09:40 phil |
| 61 |
* *** empty log message *** |
| 62 |
* |
| 63 |
* Revision 2.4 2000/09/19 15:33:23 phil |
| 64 |
* ajout passage de cartesinne en spherique |
| 65 |
* |
| 66 |
* Revision 2.3 2000/02/09 13:24:47 eric |
| 67 |
* REFONTE COMPLETE DE LA CLASSE |
| 68 |
* L'identification n'est plus base sur un membre statique (numero |
| 69 |
* d'instance) mais sur les caracteres physiques (rot_phi, etc...) |
| 70 |
* Ajout des membres ori_x, ori_y, ori_z |
| 71 |
* Ajout des constructeurs par copie et lecture de fichier. |
| 72 |
* |
| 73 |
* Revision 2.2 2000/01/10 15:43:57 eric |
| 74 |
* Methode change_basis. |
| 75 |
* |
| 76 |
* Revision 2.1 2000/01/10 13:27:09 eric |
| 77 |
* Ajout de la fonction set_rot_phi. |
| 78 |
* |
| 79 |
* Revision 2.0 2000/01/10 12:43:33 eric |
| 80 |
* *** empty log message *** |
| 81 |
* |
| 82 |
* |
| 83 |
* $Header: /cvsroot/Lorene/C++/Source/Base_vect/base_vect_spher.C,v 1.7 2014/10/13 08:52:39 j_novak Exp $ |
| 84 |
* |
| 85 |
*/ |
| 86 |
|
| 87 |
// Headers C |
| 88 |
#include <cmath> |
| 89 |
#include <cstdlib> |
| 90 |
|
| 91 |
// Headers Lorene |
| 92 |
#include "base_vect.h" |
| 93 |
#include "tenseur.h" |
| 94 |
#include "utilitaires.h" |
| 95 |
|
| 96 |
//--------------// |
| 97 |
// Constructors // |
| 98 |
//--------------// |
| 99 |
|
| 100 |
// Standard constructor without name |
| 101 |
// --------------------------------- |
| 102 |
namespace Lorene { |
| 103 |
Base_vect_spher::Base_vect_spher(double xa0, double ya0, double za0, |
| 104 |
double rot_phi_i) |
| 105 |
: ori_x(xa0), |
| 106 |
ori_y(ya0), |
| 107 |
ori_z(za0), |
| 108 |
rot_phi(rot_phi_i) {} |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
// Standard constructor with name |
| 115 |
// ------------------------------ |
| 116 |
Base_vect_spher::Base_vect_spher(double xa0, double ya0, double za0, |
| 117 |
double rot_phi_i, const char* name_i) |
| 118 |
: Base_vect(name_i), |
| 119 |
ori_x(xa0), |
| 120 |
ori_y(ya0), |
| 121 |
ori_z(za0), |
| 122 |
rot_phi(rot_phi_i) {} |
| 123 |
|
| 124 |
// Copy constructor |
| 125 |
// ---------------- |
| 126 |
Base_vect_spher::Base_vect_spher(const Base_vect_spher& bi) |
| 127 |
: Base_vect(bi), |
| 128 |
ori_x(bi.ori_x), |
| 129 |
ori_y(bi.ori_y), |
| 130 |
ori_z(bi.ori_z), |
| 131 |
rot_phi(bi.rot_phi) {} |
| 132 |
|
| 133 |
// Constructor from file |
| 134 |
// --------------------- |
| 135 |
Base_vect_spher::Base_vect_spher(FILE* fich) |
| 136 |
: Base_vect(fich) { |
| 137 |
|
| 138 |
fread_be(&ori_x, sizeof(double), 1, fich) ; |
| 139 |
fread_be(&ori_y, sizeof(double), 1, fich) ; |
| 140 |
fread_be(&ori_z, sizeof(double), 1, fich) ; |
| 141 |
fread_be(&rot_phi, sizeof(double), 1, fich) ; |
| 142 |
|
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
//--------------// |
| 147 |
// Destructor // |
| 148 |
//--------------// |
| 149 |
|
| 150 |
Base_vect_spher::~Base_vect_spher(){ |
| 151 |
|
| 152 |
// does nothing |
| 153 |
|
| 154 |
} |
| 155 |
|
| 156 |
//--------------// |
| 157 |
// Mutators // |
| 158 |
//--------------// |
| 159 |
|
| 160 |
// Assignment |
| 161 |
//----------- |
| 162 |
void Base_vect_spher::operator=(const Base_vect_spher& bi) { |
| 163 |
|
| 164 |
set_name(bi.name) ; |
| 165 |
|
| 166 |
ori_x = bi.ori_x ; |
| 167 |
ori_y = bi.ori_y ; |
| 168 |
ori_z = bi.ori_z ; |
| 169 |
rot_phi = bi.rot_phi ; |
| 170 |
|
| 171 |
} |
| 172 |
|
| 173 |
// Change of the elements |
| 174 |
// ---------------------- |
| 175 |
void Base_vect_spher::set_ori(double xa0, double ya0, double za0) { |
| 176 |
|
| 177 |
ori_x = xa0 ; |
| 178 |
ori_y = ya0 ; |
| 179 |
ori_z = za0 ; |
| 180 |
|
| 181 |
} |
| 182 |
|
| 183 |
|
| 184 |
void Base_vect_spher::set_rot_phi(double rot_phi_i) { |
| 185 |
|
| 186 |
rot_phi = rot_phi_i ; |
| 187 |
|
| 188 |
} |
| 189 |
|
| 190 |
//-----------------------// |
| 191 |
// Comparison operator // |
| 192 |
//-----------------------// |
| 193 |
|
| 194 |
|
| 195 |
bool Base_vect_spher::operator==(const Base_vect& bi) const { |
| 196 |
|
| 197 |
bool resu = true ; |
| 198 |
|
| 199 |
if ( bi.identify() != identify() ) { |
| 200 |
// cout << "The second Base_vect is not of type Base_vect_spher !" << endl ; |
| 201 |
resu = false ; |
| 202 |
} |
| 203 |
else{ |
| 204 |
|
| 205 |
const Base_vect_spher& bis = dynamic_cast<const Base_vect_spher&>( bi ) ; |
| 206 |
|
| 207 |
if (bis.ori_x != ori_x) { |
| 208 |
cout |
| 209 |
<< "The two Base_vect_spher have different X origin : " << ori_x |
| 210 |
<< " <-> " << bis.ori_x << endl ; |
| 211 |
resu = false ; |
| 212 |
} |
| 213 |
|
| 214 |
if (bis.ori_y != ori_y) { |
| 215 |
cout |
| 216 |
<< "The two Base_vect_spher have different Y origin : " << ori_y |
| 217 |
<< " <-> " << bis.ori_y << endl ; |
| 218 |
resu = false ; |
| 219 |
} |
| 220 |
|
| 221 |
if (bis.ori_z != ori_z) { |
| 222 |
cout |
| 223 |
<< "The two Base_vect_spher have different Z origin : " << ori_z |
| 224 |
<< " <-> " << bis.ori_z << endl ; |
| 225 |
resu = false ; |
| 226 |
} |
| 227 |
|
| 228 |
if (bis.rot_phi != rot_phi) { |
| 229 |
cout |
| 230 |
<< "The two Base_vect_spher have different rot_phi : " << rot_phi |
| 231 |
<< " <-> " << bis.rot_phi << endl ; |
| 232 |
resu = false ; |
| 233 |
} |
| 234 |
|
| 235 |
|
| 236 |
} |
| 237 |
|
| 238 |
return resu ; |
| 239 |
|
| 240 |
} |
| 241 |
|
| 242 |
//------------// |
| 243 |
// Outputs // |
| 244 |
//------------// |
| 245 |
|
| 246 |
void Base_vect_spher::sauve(FILE* fich) const { |
| 247 |
|
| 248 |
Base_vect::sauve(fich) ; |
| 249 |
|
| 250 |
fwrite_be(&ori_x, sizeof(double), 1, fich) ; |
| 251 |
fwrite_be(&ori_y, sizeof(double), 1, fich) ; |
| 252 |
fwrite_be(&ori_z, sizeof(double), 1, fich) ; |
| 253 |
fwrite_be(&rot_phi, sizeof(double), 1, fich) ; |
| 254 |
|
| 255 |
} |
| 256 |
|
| 257 |
ostream& Base_vect_spher::operator>>(ostream & ost) const { |
| 258 |
|
| 259 |
ost << "Absolute coordinates (X,Y,Z) of the origin : " |
| 260 |
<< ori_x << " " << ori_y << " " << ori_z << endl ; |
| 261 |
ost << "Azimuthal angle with respect to the Absolute frame : " |
| 262 |
<< rot_phi << endl ; |
| 263 |
|
| 264 |
return ost ; |
| 265 |
|
| 266 |
} |
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
//--------------------------------------// |
| 273 |
// Change of basis // |
| 274 |
//--------------------------------------// |
| 275 |
|
| 276 |
void Base_vect_spher::change_basis(Tenseur& ti) const { |
| 277 |
|
| 278 |
|
| 279 |
assert(ti.get_etat() != ETATNONDEF) ; |
| 280 |
|
| 281 |
const Base_vect* triad_i = ti.get_triad() ; |
| 282 |
|
| 283 |
assert(triad_i != 0x0) ; |
| 284 |
|
| 285 |
if (ti.get_etat() == ETATZERO) { |
| 286 |
ti.set_triad(*this) ; |
| 287 |
return ; |
| 288 |
} |
| 289 |
|
| 290 |
assert(ti.get_etat() == ETATQCQ) ; |
| 291 |
|
| 292 |
const Base_vect_cart* bvc = dynamic_cast<const Base_vect_cart*>(triad_i) ; |
| 293 |
const Base_vect_spher* bvs = dynamic_cast<const Base_vect_spher*>(triad_i) ; |
| 294 |
|
| 295 |
// --------------------------------------------- |
| 296 |
// Case where the input triad is a Cartesian one |
| 297 |
// --------------------------------------------- |
| 298 |
if (bvc != 0x0) { |
| 299 |
assert(bvs == 0x0) ; |
| 300 |
|
| 301 |
switch (ti.get_valence()) { |
| 302 |
|
| 303 |
case 1 : { // vector |
| 304 |
|
| 305 |
// The triads should be the same as that associated |
| 306 |
// with the mapping : |
| 307 |
const Map* mp = ti.get_mp() ; |
| 308 |
assert( *this == mp->get_bvect_spher() ) ; |
| 309 |
assert( *bvc == mp->get_bvect_cart() ) ; |
| 310 |
|
| 311 |
Cmp vx = ti(0) ; |
| 312 |
Cmp vy = ti(1) ; |
| 313 |
Cmp vz = ti(2) ; |
| 314 |
|
| 315 |
mp->comp_r_from_cartesian(vx, vy, vz, ti.set(0)) ; |
| 316 |
mp->comp_t_from_cartesian(vx, vy, vz, ti.set(1)) ; |
| 317 |
mp->comp_p_from_cartesian(vx, vy, ti.set(2)) ; |
| 318 |
|
| 319 |
break ; |
| 320 |
} |
| 321 |
|
| 322 |
case 2 : { |
| 323 |
|
| 324 |
// The triads should be the same as that associated |
| 325 |
// with the mapping : |
| 326 |
const Map* mp = ti.get_mp() ; |
| 327 |
assert( *this == mp->get_bvect_spher() ) ; |
| 328 |
assert( *bvc == mp->get_bvect_cart() ) ; |
| 329 |
//Only for double-covariant tensors |
| 330 |
for (int i=0; i<2; i++) |
| 331 |
assert(ti.get_type_indice(i) == COV) ; |
| 332 |
|
| 333 |
// Temporary storage of the components |
| 334 |
// the Base_vect *this is not valid... |
| 335 |
Tenseur tmp(*mp, 2, COV, *this) ; |
| 336 |
tmp.allocate_all() ; |
| 337 |
for (int i=0; i<3; i++) { |
| 338 |
mp->comp_r_from_cartesian(ti(0,i), ti(1,i), ti(2,i) |
| 339 |
, tmp.set(0,i) ) ; |
| 340 |
mp->comp_t_from_cartesian(ti(0,i), ti(1,i), ti(2,i) |
| 341 |
, tmp.set(1,i) ) ; |
| 342 |
mp->comp_p_from_cartesian(ti(0,i), ti(1,i), tmp.set(2,i) ) ; |
| 343 |
} |
| 344 |
for (int i=0; i<3; i++) { |
| 345 |
mp->comp_r_from_cartesian(tmp(i,0), tmp(i,1), tmp(i,2) |
| 346 |
, ti.set(i,0) ) ; |
| 347 |
mp->comp_t_from_cartesian(tmp(i,0), tmp(i,1), tmp(i,2) |
| 348 |
, ti.set(i,1) ) ; |
| 349 |
mp->comp_p_from_cartesian(tmp(i,0), tmp(i,1), ti.set(i,2) ) ; |
| 350 |
} |
| 351 |
|
| 352 |
|
| 353 |
break ; |
| 354 |
} |
| 355 |
|
| 356 |
default : { |
| 357 |
cout << |
| 358 |
"Base_vect_sphere::change_basis : the case of valence " |
| 359 |
<< ti.get_valence() << " is not treated !" << endl ; |
| 360 |
abort() ; |
| 361 |
break ; |
| 362 |
} |
| 363 |
} |
| 364 |
} // end of the Cartesian basis case |
| 365 |
|
| 366 |
|
| 367 |
// --------------------------------------------- |
| 368 |
// Case where the input triad is a spherical one |
| 369 |
// --------------------------------------------- |
| 370 |
if (bvs != 0x0) { |
| 371 |
|
| 372 |
assert(bvc == 0x0) ; |
| 373 |
|
| 374 |
cout << "Base_vect_spher::change_basis : case not treated yet !" << endl ; |
| 375 |
abort() ; |
| 376 |
} // end of the spherical basis case |
| 377 |
|
| 378 |
ti.set_triad(*this) ; |
| 379 |
} |
| 380 |
} |