LORENE
base_vect_cart.C
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 
31 
32 /*
33  * $Id: base_vect_cart.C,v 1.9 2016/12/05 16:17:44 j_novak Exp $
34  * $Log: base_vect_cart.C,v $
35  * Revision 1.9 2016/12/05 16:17:44 j_novak
36  * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
37  *
38  * Revision 1.8 2014/10/13 08:52:39 j_novak
39  * Lorene classes and functions now belong to the namespace Lorene.
40  *
41  * Revision 1.7 2014/10/06 15:12:57 j_novak
42  * Modified #include directives to use c++ syntax.
43  *
44  * Revision 1.6 2005/04/06 08:15:03 p_grandclement
45  * Correction of change_triad when using sym tensors...
46  *
47  * Revision 1.5 2002/10/16 14:36:31 j_novak
48  * Reorganization of #include instructions of standard C++, in order to
49  * use experimental version 3 of gcc.
50  *
51  * Revision 1.4 2002/07/03 12:31:08 j_novak
52  * cartesian<->spherical triad change for valence 2 Tenseur added (not completely tested)
53  *
54  * Revision 1.3 2002/01/15 09:09:49 e_gourgoulhon
55  * Suppression of cout printing in the comparison operator
56  *
57  * Revision 1.2 2001/12/04 21:27:52 e_gourgoulhon
58  *
59  * All writing/reading to a binary file are now performed according to
60  * the big endian convention, whatever the system is big endian or
61  * small endian, thanks to the functions fwrite_be and fread_be
62  *
63  * Revision 1.1.1.1 2001/11/20 15:19:28 e_gourgoulhon
64  * LORENE
65  *
66  * Revision 2.6 2000/09/12 12:15:15 eric
67  * Fonction change_basis : ajout du cas spherique --> cartesiennes
68  * (appel des fonctions Map::comp_*_from_spherical).
69  *
70  * Revision 2.5 2000/02/10 17:04:13 eric
71  * *** empty log message ***
72  *
73  * Revision 2.4 2000/02/10 15:38:51 eric
74  * Premiere version de change_basis.
75  *
76  * Revision 2.3 2000/02/09 13:24:29 eric
77  * REFONTE COMPLETE DE LA CLASSE
78  * L'identification n'est plus base sur un membre statique (numero
79  * d'instance) mais sur les caracteres physiques (rot_phi, etc...)
80  * Ajout des constructeurs par copie et lecture de fichier.
81  *
82  * Revision 2.2 2000/01/10 15:43:29 eric
83  * Methode change_basis.
84  *
85  * Revision 2.1 2000/01/10 13:27:32 eric
86  * Ajout de la fonction set_rot_phi.
87  *
88  * Revision 2.0 2000/01/10 12:43:29 eric
89  * *** empty log message ***
90  *
91  *
92  * $Header: /cvsroot/Lorene/C++/Source/Base_vect/base_vect_cart.C,v 1.9 2016/12/05 16:17:44 j_novak Exp $
93  *
94  */
95 
96 // Headers C
97 #include <cmath>
98 #include <cstdlib>
99 
100 // Headers Lorene
101 #include "headcpp.h"
102 #include "base_vect.h"
103 #include "tenseur.h"
104 #include "utilitaires.h"
105 
106  //--------------//
107  // Constructors //
108  //--------------//
109 
110 // Standard constructor without name
111 // ---------------------------------
112 namespace Lorene {
114  : rot_phi(rot_phi_i) {
115 
116  set_align() ;
117 }
118 
119 
120 
121 // Standard constructor with name
122 // ------------------------------
123 Base_vect_cart::Base_vect_cart(double rot_phi_i, const char* name_i)
124  : Base_vect(name_i),
125  rot_phi(rot_phi_i) {
126 
127  set_align() ;
128 }
129 
130 
131 // Copy constructor
132 // ----------------
134  : Base_vect(bi),
135  rot_phi(bi.rot_phi) {
136 
137  set_align() ;
138 }
139 
140 // Constructor from file
141 // ---------------------
143  : Base_vect(fich) {
144 
145  fread_be(&rot_phi, sizeof(double), 1, fich) ;
146 
147  set_align() ;
148 }
149 
150 
151  //--------------//
152  // Destructor //
153  //--------------//
154 
156 
157  // does nothing
158 
159 }
160 
161 
162  //--------------//
163  // Mutators //
164  //--------------//
165 
166 // Assignment
167 //-----------
169 
170  set_name(bi.name) ;
171 
172  rot_phi = bi.rot_phi ;
173 
174  set_align() ;
175 
176 }
177 
178 
179 
180 // Sets the value of the indicator align
181 //--------------------------------------
183 
184  if (rot_phi == double(0)) {
185  align = 1 ;
186  }
187  else{
188  if (rot_phi == M_PI) {
189  align = - 1 ;
190  }
191  else{
192 
193  if (fabs(rot_phi) < 1.e-14) {
194  cout <<
195  "WARNING : Base_vect_cart::set_align : " << endl ;
196  cout << " rot_phi is close to zero !" << endl ;
197  arrete() ;
198  }
199 
200  if (fabs(rot_phi - M_PI) < 1.e-14) {
201  cout <<
202  "WARNING : Base_vect_cart::set_align : " << endl ;
203  cout << " rot_phi is close to Pi !" << endl ;
204  arrete() ;
205  }
206 
207  align = 0 ;
208 
209  }
210 
211  }
212 
213 }
214 
215 void Base_vect_cart::set_rot_phi(double rot_phi_i) {
216 
217  rot_phi = rot_phi_i ;
218 
219  set_align() ;
220 }
221 
222  //-----------------------//
223  // Comparison operator //
224  //-----------------------//
225 
226 
227 bool Base_vect_cart::operator==(const Base_vect& bi) const {
228 
229  bool resu = true ;
230 
231  if ( bi.identify() != identify() ) {
232  // cout << "The second Base_vect is not of type Base_vect_cart !" << endl ;
233  resu = false ;
234  }
235  else{
236 
237  const Base_vect_cart& bic = dynamic_cast<const Base_vect_cart&>( bi ) ;
238 
239  if (bic.rot_phi != rot_phi) {
240  cout
241  << "The two Base_vect_cart have different rot_phi : " << rot_phi
242  << " <-> " << bic.rot_phi << endl ;
243  resu = false ;
244  }
245 
246 
247  }
248 
249  return resu ;
250 
251 }
252 
253  //------------//
254  // Outputs //
255  //------------//
256 
257 void Base_vect_cart::sauve(FILE* fich) const {
258 
259  Base_vect::sauve(fich) ;
260 
261  fwrite_be(&rot_phi, sizeof(double), 1, fich) ;
262 
263 }
264 
265 ostream& Base_vect_cart::operator>>(ostream & ost) const {
266 
267  ost << "Azimuthal angle with respect to the Absolute frame : "
268  << rot_phi << endl ;
269 
270  return ost ;
271 
272 }
273 
274 
275 
276 
277 
278 
279  //--------------------------------------//
280  // Change of basis //
281  //--------------------------------------//
282 
284 
285 
286  assert(ti.get_etat() != ETATNONDEF) ;
287 
288  const Base_vect* triad_i = ti.get_triad() ;
289 
290  assert(triad_i != 0x0) ;
291 
292  if (ti.get_etat() == ETATZERO) {
293  ti.set_triad(*this) ;
294  return ;
295  }
296 
297  assert(ti.get_etat() == ETATQCQ) ;
298 
299  const Base_vect_cart* bvc = dynamic_cast<const Base_vect_cart*>(triad_i) ;
300  const Base_vect_spher* bvs = dynamic_cast<const Base_vect_spher*>(triad_i) ;
301 
302  // ---------------------------------------------
303  // Case where the input triad is a Cartesian one
304  // ---------------------------------------------
305  if (bvc != 0x0) {
306  assert(bvs == 0x0) ;
307 
308  int ind = align * (bvc->align) ;
309 
310  Tenseur copie (ti) ;
311 
312  switch (ind) {
313 
314  case 1 : { // the two basis are aligned : nothing to do
315  // -----------------------------------------
316 
317  break ;
318  }
319 
320  case - 1 : { // the two basis are anti-aligned
321  // ------------------------------
322 
323  switch (ti.get_valence()) {
324 
325  case 1 : { // vector
326  ti.set(0) = - ti(0) ; // V^x --> - V^x
327  ti.set(1) = - ti(1) ; // V^y --> - V^y
328  // V^z unchanged
329  break ;
330  }
331 
332  case 2 : { // rank 2 tensor
333  ti.set(0, 2) = - copie(0, 2) ; // {xz} --> - {xz}
334  ti.set(1, 2) = - copie(1, 2) ; // {yz} --> - {yz}
335  ti.set(2, 0) = - copie(2, 0) ; // {zx} --> - {zx}
336  ti.set(2, 1) = - copie(2, 1) ; // {zy} --> - {zy}
337  // all other components are unchanged
338  break ;
339  }
340 
341  default : {
342  cout <<
343  "Base_vect_cart::change_basis : the case of valence "
344  << ti.get_valence() << " is not treated !" << endl ;
345  abort() ;
346  break ;
347  }
348  }
349  break ;
350  } // end of case ind = -1
351 
352  case 0 : { // the two basis have not a special relative orientation
353  // -----------------------------------------------------
354  cout <<
355  "Base_vect_cart::change_basis : general value of rot_phi "
356  << " not contemplated yet, sorry !" << endl ;
357  abort() ;
358  break ;
359  }
360 
361  default : { // error
362  cout <<
363  "Base_vect_cart::change_basis : unexpected value of ind !" << endl ;
364  cout << " ind = " << ind << endl ;
365  abort() ;
366  break ;
367  }
368  }
369 
370  } // end of the Cartesian basis case
371 
372 
373  // ---------------------------------------------
374  // Case where the input triad is a spherical one
375  // ---------------------------------------------
376  if (bvs != 0x0) {
377 
378  assert(bvc == 0x0) ;
379 
380  switch (ti.get_valence()) {
381 
382  case 1 : { // vector
383 
384  // The triads should be the same as that associated
385  // with the mapping :
386  const Map* mp = ti.get_mp() ;
387  assert( *this == mp->get_bvect_cart() ) ;
388  assert( *bvs == mp->get_bvect_spher() ) ;
389 
390  Cmp vr = ti(0) ;
391  Cmp vt = ti(1) ;
392  Cmp vp = ti(2) ;
393 
394  mp->comp_x_from_spherical(vr, vt, vp, ti.set(0)) ;
395  mp->comp_y_from_spherical(vr, vt, vp, ti.set(1)) ;
396  mp->comp_z_from_spherical(vr, vt, ti.set(2)) ;
397 
398  break ;
399  }
400 
401  case 2 : {
402 
403  // The triads should be the same as that associated
404  // with the mapping :
405  const Map* mp = ti.get_mp() ;
406  assert( *this == mp->get_bvect_cart() ) ;
407  assert( *bvs == mp->get_bvect_spher() ) ;
408  //Only for double-covariant tensors
409  for (int i=0; i<2; i++)
410  assert(ti.get_type_indice(i) == COV) ;
411 
412  // Temporary storage of the components
413  // the Base_vect *this is not valid...
414  Tenseur tmp(*mp, 2, COV, *this) ;
415  tmp.allocate_all() ;
416  for (int i=0; i<3; i++) {
417  mp->comp_x_from_spherical(ti(0,i), ti(1,i), ti(2,i)
418  , tmp.set(0,i) ) ;
419  mp->comp_y_from_spherical(ti(0,i), ti(1,i), ti(2,i)
420  , tmp.set(1,i) ) ;
421  mp->comp_z_from_spherical(ti(0,i), ti(1,i), tmp.set(2,i) ) ;
422  }
423  for (int i=0; i<3; i++) {
424  mp->comp_x_from_spherical(tmp(i,0), tmp(i,1), tmp(i,2)
425  , ti.set(i,0) ) ;
426  mp->comp_y_from_spherical(tmp(i,0), tmp(i,1), tmp(i,2)
427  , ti.set(i,1) ) ;
428  mp->comp_z_from_spherical(tmp(i,0), tmp(i,1), ti.set(i,2) ) ;
429  }
430 
431 
432  break ;
433  }
434 
435  default : {
436  cout <<
437  "Base_vect_cart::change_basis : the case of valence "
438  << ti.get_valence() << " is not treated !" << endl ;
439  abort() ;
440  break ;
441  }
442  }
443 
444 
445  } // end of the spherical basis case
446 
447  ti.set_triad(*this) ;
448 
449 }
450 }
double rot_phi
Angle between the x –axis and the absolute frame X –axis.
Definition: base_vect.h:207
int get_type_indice(int i) const
Returns the type of the index number i .
Definition: tenseur.h:729
Component of a tensorial field *** DEPRECATED : use class Scalar instead ***.
Definition: cmp.h:446
virtual ~Base_vect_cart()
Destructor.
void set_triad(const Base_vect &new_triad)
Assigns a new vectorial basis (triad) of decomposition.
Definition: tenseur.C:690
void set_rot_phi(double rot_phi_i)
Sets a new value to the angle rot_phi between the x –axis and the absolute frame X –axis...
const Base_vect_spher & get_bvect_spher() const
Returns the orthonormal vectorial basis associated with the coordinates of the mapping.
Definition: map.h:801
Lorene prototypes.
Definition: app_hor.h:67
int align
Indicator of alignment with respect to the absolute frame: \ align = 1 : basis aligned with the absol...
Definition: base_vect.h:217
virtual void sauve(FILE *) const
Save in a file.
Definition: base_vect.C:153
Base class for coordinate mappings.
Definition: map.h:688
Vectorial bases (triads) with respect to which the tensorial components are defined.
Definition: base_vect.h:105
virtual void comp_x_from_spherical(const Scalar &v_r, const Scalar &v_theta, const Scalar &v_phi, Scalar &v_x) const =0
Computes the Cartesian x component (with respect to bvect_cart ) of a vector given by its spherical c...
virtual void change_basis(Tenseur &) const
Change the basis in which the components of a tensor are expressed.
int get_valence() const
Returns the valence.
Definition: tenseur.h:713
Cmp & set()
Read/write for a scalar (see also operator=(const Cmp&) ).
Definition: tenseur.C:840
virtual void comp_z_from_spherical(const Scalar &v_r, const Scalar &v_theta, Scalar &v_z) const =0
Computes the Cartesian z component (with respect to bvect_cart ) of a vector given by its spherical c...
const Map * get_mp() const
Returns pointer on the mapping.
Definition: tenseur.h:702
const Base_vect * get_triad() const
Returns the vectorial basis (triad) on which the components are defined.
Definition: tenseur.h:707
virtual void sauve(FILE *) const
Save in a file.
virtual ostream & operator>>(ostream &) const
Operator >>
virtual int identify() const =0
Returns a number to identify the sub-classe of Base_vect the object belongs to.
int get_etat() const
Returns the logical state.
Definition: tenseur.h:710
int fwrite_be(const int *aa, int size, int nb, FILE *fich)
Writes integer(s) into a binary file according to the big endian convention.
Definition: fwrite_be.C:73
virtual bool operator==(const Base_vect &) const
Comparison operator (egality)
char name[100]
Name of the basis.
Definition: base_vect.h:110
virtual int identify() const
Returns a number to identify the sub-classe of Base_vect the object belongs to.
Cartesian vectorial bases (triads).
Definition: base_vect.h:201
Spherical orthonormal vectorial bases (triads).
Definition: base_vect.h:308
int fread_be(int *aa, int size, int nb, FILE *fich)
Reads integer(s) from a binary file according to the big endian convention.
Definition: fread_be.C:72
Base_vect_cart(double rot_phi_i)
Standard constructor.
void allocate_all()
Sets the logical state to ETATQCQ (ordinary state) and performs the memory allocation of all the elem...
Definition: tenseur.C:673
const Base_vect_cart & get_bvect_cart() const
Returns the Cartesian basis associated with the coordinates (x,y,z) of the mapping, i.e.
Definition: map.h:809
void arrete(int a=0)
Setting a stop point in a code.
Definition: arrete.C:64
void set_name(const char *name_i)
Sets the basis name.
Definition: base_vect.C:137
virtual void comp_y_from_spherical(const Scalar &v_r, const Scalar &v_theta, const Scalar &v_phi, Scalar &v_y) const =0
Computes the Cartesian y component (with respect to bvect_cart ) of a vector given by its spherical c...
Tensor handling *** DEPRECATED : use class Tensor instead ***.
Definition: tenseur.h:304
void set_align()
Computes align from the value of rot_phi.
void operator=(const Base_vect_cart &)
Assignment to another Base_vect_cart.