LORENE
base_vect_spher.C
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 
31 
32 /*
33  * $Id: base_vect_spher.C,v 1.8 2016/12/05 16:17:44 j_novak Exp $
34  * $Log: base_vect_spher.C,v $
35  * Revision 1.8 2016/12/05 16:17:44 j_novak
36  * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
37  *
38  * Revision 1.7 2014/10/13 08:52:39 j_novak
39  * Lorene classes and functions now belong to the namespace Lorene.
40  *
41  * Revision 1.6 2014/10/06 15:12:57 j_novak
42  * Modified #include directives to use c++ syntax.
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.5 2000/09/19 16:09:40 phil
64  * *** empty log message ***
65  *
66  * Revision 2.4 2000/09/19 15:33:23 phil
67  * ajout passage de cartesinne en spherique
68  *
69  * Revision 2.3 2000/02/09 13:24:47 eric
70  * REFONTE COMPLETE DE LA CLASSE
71  * L'identification n'est plus base sur un membre statique (numero
72  * d'instance) mais sur les caracteres physiques (rot_phi, etc...)
73  * Ajout des membres ori_x, ori_y, ori_z
74  * Ajout des constructeurs par copie et lecture de fichier.
75  *
76  * Revision 2.2 2000/01/10 15:43:57 eric
77  * Methode change_basis.
78  *
79  * Revision 2.1 2000/01/10 13:27:09 eric
80  * Ajout de la fonction set_rot_phi.
81  *
82  * Revision 2.0 2000/01/10 12:43:33 eric
83  * *** empty log message ***
84  *
85  *
86  * $Header: /cvsroot/Lorene/C++/Source/Base_vect/base_vect_spher.C,v 1.8 2016/12/05 16:17:44 j_novak Exp $
87  *
88  */
89 
90 // Headers C
91 #include <cmath>
92 #include <cstdlib>
93 
94 // Headers Lorene
95 #include "base_vect.h"
96 #include "tenseur.h"
97 #include "utilitaires.h"
98 
99  //--------------//
100  // Constructors //
101  //--------------//
102 
103 // Standard constructor without name
104 // ---------------------------------
105 namespace Lorene {
106 Base_vect_spher::Base_vect_spher(double xa0, double ya0, double za0,
107  double rot_phi_i)
108  : ori_x(xa0),
109  ori_y(ya0),
110  ori_z(za0),
111  rot_phi(rot_phi_i) {}
112 
113 
114 
115 
116 
117 // Standard constructor with name
118 // ------------------------------
119 Base_vect_spher::Base_vect_spher(double xa0, double ya0, double za0,
120  double rot_phi_i, const char* name_i)
121  : Base_vect(name_i),
122  ori_x(xa0),
123  ori_y(ya0),
124  ori_z(za0),
125  rot_phi(rot_phi_i) {}
126 
127 // Copy constructor
128 // ----------------
130  : Base_vect(bi),
131  ori_x(bi.ori_x),
132  ori_y(bi.ori_y),
133  ori_z(bi.ori_z),
134  rot_phi(bi.rot_phi) {}
135 
136 // Constructor from file
137 // ---------------------
139  : Base_vect(fich) {
140 
141  fread_be(&ori_x, sizeof(double), 1, fich) ;
142  fread_be(&ori_y, sizeof(double), 1, fich) ;
143  fread_be(&ori_z, sizeof(double), 1, fich) ;
144  fread_be(&rot_phi, sizeof(double), 1, fich) ;
145 
146 }
147 
148 
149  //--------------//
150  // Destructor //
151  //--------------//
152 
154 
155  // does nothing
156 
157 }
158 
159  //--------------//
160  // Mutators //
161  //--------------//
162 
163 // Assignment
164 //-----------
166 
167  set_name(bi.name) ;
168 
169  ori_x = bi.ori_x ;
170  ori_y = bi.ori_y ;
171  ori_z = bi.ori_z ;
172  rot_phi = bi.rot_phi ;
173 
174 }
175 
176 // Change of the elements
177 // ----------------------
178 void Base_vect_spher::set_ori(double xa0, double ya0, double za0) {
179 
180  ori_x = xa0 ;
181  ori_y = ya0 ;
182  ori_z = za0 ;
183 
184 }
185 
186 
187 void Base_vect_spher::set_rot_phi(double rot_phi_i) {
188 
189  rot_phi = rot_phi_i ;
190 
191 }
192 
193  //-----------------------//
194  // Comparison operator //
195  //-----------------------//
196 
197 
198 bool Base_vect_spher::operator==(const Base_vect& bi) const {
199 
200  bool resu = true ;
201 
202  if ( bi.identify() != identify() ) {
203  // cout << "The second Base_vect is not of type Base_vect_spher !" << endl ;
204  resu = false ;
205  }
206  else{
207 
208  const Base_vect_spher& bis = dynamic_cast<const Base_vect_spher&>( bi ) ;
209 
210  if (bis.ori_x != ori_x) {
211  cout
212  << "The two Base_vect_spher have different X origin : " << ori_x
213  << " <-> " << bis.ori_x << endl ;
214  resu = false ;
215  }
216 
217  if (bis.ori_y != ori_y) {
218  cout
219  << "The two Base_vect_spher have different Y origin : " << ori_y
220  << " <-> " << bis.ori_y << endl ;
221  resu = false ;
222  }
223 
224  if (bis.ori_z != ori_z) {
225  cout
226  << "The two Base_vect_spher have different Z origin : " << ori_z
227  << " <-> " << bis.ori_z << endl ;
228  resu = false ;
229  }
230 
231  if (bis.rot_phi != rot_phi) {
232  cout
233  << "The two Base_vect_spher have different rot_phi : " << rot_phi
234  << " <-> " << bis.rot_phi << endl ;
235  resu = false ;
236  }
237 
238 
239  }
240 
241  return resu ;
242 
243 }
244 
245  //------------//
246  // Outputs //
247  //------------//
248 
249 void Base_vect_spher::sauve(FILE* fich) const {
250 
251  Base_vect::sauve(fich) ;
252 
253  fwrite_be(&ori_x, sizeof(double), 1, fich) ;
254  fwrite_be(&ori_y, sizeof(double), 1, fich) ;
255  fwrite_be(&ori_z, sizeof(double), 1, fich) ;
256  fwrite_be(&rot_phi, sizeof(double), 1, fich) ;
257 
258 }
259 
260 ostream& Base_vect_spher::operator>>(ostream & ost) const {
261 
262  ost << "Absolute coordinates (X,Y,Z) of the origin : "
263  << ori_x << " " << ori_y << " " << ori_z << endl ;
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  // Change of basis //
277  //--------------------------------------//
278 
280 
281 
282  assert(ti.get_etat() != ETATNONDEF) ;
283 
284  const Base_vect* triad_i = ti.get_triad() ;
285 
286  assert(triad_i != 0x0) ;
287 
288  if (ti.get_etat() == ETATZERO) {
289  ti.set_triad(*this) ;
290  return ;
291  }
292 
293  assert(ti.get_etat() == ETATQCQ) ;
294 
295  const Base_vect_cart* bvc = dynamic_cast<const Base_vect_cart*>(triad_i) ;
296  const Base_vect_spher* bvs = dynamic_cast<const Base_vect_spher*>(triad_i) ;
297 
298  // ---------------------------------------------
299  // Case where the input triad is a Cartesian one
300  // ---------------------------------------------
301  if (bvc != 0x0) {
302  assert(bvs == 0x0) ;
303 
304  switch (ti.get_valence()) {
305 
306  case 1 : { // vector
307 
308  // The triads should be the same as that associated
309  // with the mapping :
310  const Map* mp = ti.get_mp() ;
311  assert( *this == mp->get_bvect_spher() ) ;
312  assert( *bvc == mp->get_bvect_cart() ) ;
313 
314  Cmp vx = ti(0) ;
315  Cmp vy = ti(1) ;
316  Cmp vz = ti(2) ;
317 
318  mp->comp_r_from_cartesian(vx, vy, vz, ti.set(0)) ;
319  mp->comp_t_from_cartesian(vx, vy, vz, ti.set(1)) ;
320  mp->comp_p_from_cartesian(vx, vy, ti.set(2)) ;
321 
322  break ;
323  }
324 
325  case 2 : {
326 
327  // The triads should be the same as that associated
328  // with the mapping :
329  const Map* mp = ti.get_mp() ;
330  assert( *this == mp->get_bvect_spher() ) ;
331  assert( *bvc == mp->get_bvect_cart() ) ;
332  //Only for double-covariant tensors
333  for (int i=0; i<2; i++)
334  assert(ti.get_type_indice(i) == COV) ;
335 
336  // Temporary storage of the components
337  // the Base_vect *this is not valid...
338  Tenseur tmp(*mp, 2, COV, *this) ;
339  tmp.allocate_all() ;
340  for (int i=0; i<3; i++) {
341  mp->comp_r_from_cartesian(ti(0,i), ti(1,i), ti(2,i)
342  , tmp.set(0,i) ) ;
343  mp->comp_t_from_cartesian(ti(0,i), ti(1,i), ti(2,i)
344  , tmp.set(1,i) ) ;
345  mp->comp_p_from_cartesian(ti(0,i), ti(1,i), tmp.set(2,i) ) ;
346  }
347  for (int i=0; i<3; i++) {
348  mp->comp_r_from_cartesian(tmp(i,0), tmp(i,1), tmp(i,2)
349  , ti.set(i,0) ) ;
350  mp->comp_t_from_cartesian(tmp(i,0), tmp(i,1), tmp(i,2)
351  , ti.set(i,1) ) ;
352  mp->comp_p_from_cartesian(tmp(i,0), tmp(i,1), ti.set(i,2) ) ;
353  }
354 
355 
356  break ;
357  }
358 
359  default : {
360  cout <<
361  "Base_vect_sphere::change_basis : the case of valence "
362  << ti.get_valence() << " is not treated !" << endl ;
363  abort() ;
364  break ;
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  cout << "Base_vect_spher::change_basis : case not treated yet !" << endl ;
378  abort() ;
379  } // end of the spherical basis case
380 
381  ti.set_triad(*this) ;
382 }
383 }
double ori_y
Absolute coordinate Y of the origin.
Definition: base_vect.h:314
void set_ori(double xa0, double ya0, double za0)
Sets a new origin.
int get_type_indice(int i) const
Returns the type of the index number i .
Definition: tenseur.h:729
void operator=(const Base_vect_spher &)
Assignment to another Base_vect_spher.
Component of a tensorial field *** DEPRECATED : use class Scalar instead ***.
Definition: cmp.h:446
Base_vect_spher(double xa0, double ya0, double za0, double rot_phi_i)
Standard constructor.
void set_triad(const Base_vect &new_triad)
Assigns a new vectorial basis (triad) of decomposition.
Definition: tenseur.C:690
const Base_vect_spher & get_bvect_spher() const
Returns the orthonormal vectorial basis associated with the coordinates of the mapping.
Definition: map.h:801
double rot_phi
Angle between the x –axis and the absolute frame X –axis.
Definition: base_vect.h:318
Lorene prototypes.
Definition: app_hor.h:67
virtual void comp_p_from_cartesian(const Scalar &v_x, const Scalar &v_y, Scalar &v_p) const =0
Computes the Spherical component (with respect to bvect_spher ) of a vector given by its cartesian c...
virtual void sauve(FILE *) const
Save in a file.
Definition: base_vect.C:153
Base class for coordinate mappings.
Definition: map.h:688
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...
Vectorial bases (triads) with respect to which the tensorial components are defined.
Definition: base_vect.h:105
int get_valence() const
Returns the valence.
Definition: tenseur.h:713
virtual bool operator==(const Base_vect &) const
Comparison operator (egality)
virtual void comp_t_from_cartesian(const Scalar &v_x, const Scalar &v_y, const Scalar &v_z, Scalar &v_t) const =0
Computes the Spherical component (with respect to bvect_spher ) of a vector given by its cartesian c...
Cmp & set()
Read/write for a scalar (see also operator=(const Cmp&) ).
Definition: tenseur.C:840
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 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 void sauve(FILE *) const
Save in a file.
char name[100]
Name of the basis.
Definition: base_vect.h:110
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
virtual ~Base_vect_spher()
Destructor.
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
virtual ostream & operator>>(ostream &) const
Operator >>
virtual void comp_r_from_cartesian(const Scalar &v_x, const Scalar &v_y, const Scalar &v_z, Scalar &v_r) const =0
Computes the Spherical r component (with respect to bvect_spher ) of a vector given by its cartesian ...
double ori_z
Absolute coordinate Z of the origin.
Definition: base_vect.h:315
double ori_x
Absolute coordinate X of the origin.
Definition: base_vect.h:313
virtual void change_basis(Tenseur &) const
Change the basis in which the components of a tensor are expressed.
void set_name(const char *name_i)
Sets the basis name.
Definition: base_vect.C:137
Tensor handling *** DEPRECATED : use class Tensor instead ***.
Definition: tenseur.h:304
virtual int identify() const
Returns a number to identify the sub-classe of Base_vect the object belongs to.