00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 char base_vect_cart_C[] = "$Header: /cvsroot/Lorene/C++/Source/Base_vect/base_vect_cart.C,v 1.6 2005/04/06 08:15:03 p_grandclement Exp $" ;
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088 #include <math.h>
00089 #include <stdlib.h>
00090
00091
00092 #include "headcpp.h"
00093 #include "base_vect.h"
00094 #include "tenseur.h"
00095 #include "utilitaires.h"
00096
00097
00098
00099
00100
00101
00102
00103 Base_vect_cart::Base_vect_cart(double rot_phi_i)
00104 : rot_phi(rot_phi_i) {
00105
00106 set_align() ;
00107 }
00108
00109
00110
00111
00112
00113 Base_vect_cart::Base_vect_cart(double rot_phi_i, const char* name_i)
00114 : Base_vect(name_i),
00115 rot_phi(rot_phi_i) {
00116
00117 set_align() ;
00118 }
00119
00120
00121
00122
00123 Base_vect_cart::Base_vect_cart(const Base_vect_cart& bi)
00124 : Base_vect(bi),
00125 rot_phi(bi.rot_phi) {
00126
00127 set_align() ;
00128 }
00129
00130
00131
00132 Base_vect_cart::Base_vect_cart(FILE* fich)
00133 : Base_vect(fich) {
00134
00135 fread_be(&rot_phi, sizeof(double), 1, fich) ;
00136
00137 set_align() ;
00138 }
00139
00140
00141
00142
00143
00144
00145 Base_vect_cart::~Base_vect_cart(){
00146
00147
00148
00149 }
00150
00151
00152
00153
00154
00155
00156
00157
00158 void Base_vect_cart::operator=(const Base_vect_cart& bi) {
00159
00160 set_name(bi.name) ;
00161
00162 rot_phi = bi.rot_phi ;
00163
00164 set_align() ;
00165
00166 }
00167
00168
00169
00170
00171
00172 void Base_vect_cart::set_align() {
00173
00174 if (rot_phi == double(0)) {
00175 align = 1 ;
00176 }
00177 else{
00178 if (rot_phi == M_PI) {
00179 align = - 1 ;
00180 }
00181 else{
00182
00183 if (fabs(rot_phi) < 1.e-14) {
00184 cout <<
00185 "WARNING : Base_vect_cart::set_align : " << endl ;
00186 cout << " rot_phi is close to zero !" << endl ;
00187 arrete() ;
00188 }
00189
00190 if (fabs(rot_phi - M_PI) < 1.e-14) {
00191 cout <<
00192 "WARNING : Base_vect_cart::set_align : " << endl ;
00193 cout << " rot_phi is close to Pi !" << endl ;
00194 arrete() ;
00195 }
00196
00197 align = 0 ;
00198
00199 }
00200
00201 }
00202
00203 }
00204
00205 void Base_vect_cart::set_rot_phi(double rot_phi_i) {
00206
00207 rot_phi = rot_phi_i ;
00208
00209 set_align() ;
00210 }
00211
00212
00213
00214
00215
00216
00217 bool Base_vect_cart::operator==(const Base_vect& bi) const {
00218
00219 bool resu = true ;
00220
00221 if ( bi.identify() != identify() ) {
00222
00223 resu = false ;
00224 }
00225 else{
00226
00227 const Base_vect_cart& bic = dynamic_cast<const Base_vect_cart&>( bi ) ;
00228
00229 if (bic.rot_phi != rot_phi) {
00230 cout
00231 << "The two Base_vect_cart have different rot_phi : " << rot_phi
00232 << " <-> " << bic.rot_phi << endl ;
00233 resu = false ;
00234 }
00235
00236
00237 }
00238
00239 return resu ;
00240
00241 }
00242
00243
00244
00245
00246
00247 void Base_vect_cart::sauve(FILE* fich) const {
00248
00249 Base_vect::sauve(fich) ;
00250
00251 fwrite_be(&rot_phi, sizeof(double), 1, fich) ;
00252
00253 }
00254
00255 ostream& Base_vect_cart::operator>>(ostream & ost) const {
00256
00257 ost << "Azimuthal angle with respect to the Absolute frame : "
00258 << rot_phi << endl ;
00259
00260 return ost ;
00261
00262 }
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273 void Base_vect_cart::change_basis(Tenseur& ti) const {
00274
00275
00276 assert(ti.get_etat() != ETATNONDEF) ;
00277
00278 const Base_vect* triad_i = ti.get_triad() ;
00279
00280 assert(triad_i != 0x0) ;
00281
00282 if (ti.get_etat() == ETATZERO) {
00283 ti.set_triad(*this) ;
00284 return ;
00285 }
00286
00287 assert(ti.get_etat() == ETATQCQ) ;
00288
00289 const Base_vect_cart* bvc = dynamic_cast<const Base_vect_cart*>(triad_i) ;
00290 const Base_vect_spher* bvs = dynamic_cast<const Base_vect_spher*>(triad_i) ;
00291
00292
00293
00294
00295 if (bvc != 0x0) {
00296 assert(bvs == 0x0) ;
00297
00298 int ind = align * (bvc->align) ;
00299
00300 Tenseur copie (ti) ;
00301
00302 switch (ind) {
00303
00304 case 1 : {
00305
00306
00307 break ;
00308 }
00309
00310 case - 1 : {
00311
00312
00313 switch (ti.get_valence()) {
00314
00315 case 1 : {
00316 ti.set(0) = - ti(0) ;
00317 ti.set(1) = - ti(1) ;
00318
00319 break ;
00320 }
00321
00322 case 2 : {
00323 ti.set(0, 2) = - copie(0, 2) ;
00324 ti.set(1, 2) = - copie(1, 2) ;
00325 ti.set(2, 0) = - copie(2, 0) ;
00326 ti.set(2, 1) = - copie(2, 1) ;
00327
00328 break ;
00329 }
00330
00331 default : {
00332 cout <<
00333 "Base_vect_cart::change_basis : the case of valence "
00334 << ti.get_valence() << " is not treated !" << endl ;
00335 abort() ;
00336 break ;
00337 }
00338 }
00339 break ;
00340 }
00341
00342 case 0 : {
00343
00344 cout <<
00345 "Base_vect_cart::change_basis : general value of rot_phi "
00346 << " not contemplated yet, sorry !" << endl ;
00347 abort() ;
00348 break ;
00349 }
00350
00351 default : {
00352 cout <<
00353 "Base_vect_cart::change_basis : unexpected value of ind !" << endl ;
00354 cout << " ind = " << ind << endl ;
00355 abort() ;
00356 break ;
00357 }
00358 }
00359
00360 }
00361
00362
00363
00364
00365
00366 if (bvs != 0x0) {
00367
00368 assert(bvc == 0x0) ;
00369
00370 switch (ti.get_valence()) {
00371
00372 case 1 : {
00373
00374
00375
00376 const Map* mp = ti.get_mp() ;
00377 assert( *this == mp->get_bvect_cart() ) ;
00378 assert( *bvs == mp->get_bvect_spher() ) ;
00379
00380 Cmp vr = ti(0) ;
00381 Cmp vt = ti(1) ;
00382 Cmp vp = ti(2) ;
00383
00384 mp->comp_x_from_spherical(vr, vt, vp, ti.set(0)) ;
00385 mp->comp_y_from_spherical(vr, vt, vp, ti.set(1)) ;
00386 mp->comp_z_from_spherical(vr, vt, ti.set(2)) ;
00387
00388 break ;
00389 }
00390
00391 case 2 : {
00392
00393
00394
00395 const Map* mp = ti.get_mp() ;
00396 assert( *this == mp->get_bvect_cart() ) ;
00397 assert( *bvs == mp->get_bvect_spher() ) ;
00398
00399 for (int i=0; i<2; i++)
00400 assert(ti.get_type_indice(i) == COV) ;
00401
00402
00403
00404 Tenseur tmp(*mp, 2, COV, *this) ;
00405 tmp.allocate_all() ;
00406 for (int i=0; i<3; i++) {
00407 mp->comp_x_from_spherical(ti(0,i), ti(1,i), ti(2,i)
00408 , tmp.set(0,i) ) ;
00409 mp->comp_y_from_spherical(ti(0,i), ti(1,i), ti(2,i)
00410 , tmp.set(1,i) ) ;
00411 mp->comp_z_from_spherical(ti(0,i), ti(1,i), tmp.set(2,i) ) ;
00412 }
00413 for (int i=0; i<3; i++) {
00414 mp->comp_x_from_spherical(tmp(i,0), tmp(i,1), tmp(i,2)
00415 , ti.set(i,0) ) ;
00416 mp->comp_y_from_spherical(tmp(i,0), tmp(i,1), tmp(i,2)
00417 , ti.set(i,1) ) ;
00418 mp->comp_z_from_spherical(tmp(i,0), tmp(i,1), ti.set(i,2) ) ;
00419 }
00420
00421
00422 break ;
00423 }
00424
00425 default : {
00426 cout <<
00427 "Base_vect_cart::change_basis : the case of valence "
00428 << ti.get_valence() << " is not treated !" << endl ;
00429 abort() ;
00430 break ;
00431 }
00432 }
00433
00434
00435 }
00436
00437 ti.set_triad(*this) ;
00438
00439 }