Debian Codegraph @

C++/Source/Base_vect/base_vect_cart.C

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