LORENE
vector_change_triad.C
1 /*
2  * Methods for changing the triad of a Vector
3  *
4  */
5 
6 /*
7  * Copyright (c) 2003 Eric Gourgoulhon & Jerome Novak
8  *
9  * This file is part of LORENE.
10  *
11  * LORENE is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License version 2
13  * as published by the Free Software Foundation.
14  *
15  * LORENE is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with LORENE; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23  *
24  */
25 
26 
27 
28 
29 /*
30  * $Id: vector_change_triad.C,v 1.10 2016/12/05 16:18:18 j_novak Exp $
31  * $Log: vector_change_triad.C,v $
32  * Revision 1.10 2016/12/05 16:18:18 j_novak
33  * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
34  *
35  * Revision 1.9 2014/10/13 08:53:44 j_novak
36  * Lorene classes and functions now belong to the namespace Lorene.
37  *
38  * Revision 1.8 2014/10/06 15:13:20 j_novak
39  * Modified #include directives to use c++ syntax.
40  *
41  * Revision 1.7 2010/01/26 16:47:10 e_gourgoulhon
42  * Suppressed the assert on np >= 4 (too strong ?).
43  *
44  * Revision 1.6 2005/09/15 15:51:26 j_novak
45  * The "rotation" (change of triad) methods take now Scalars as default
46  * arguments.
47  *
48  * Revision 1.5 2005/02/03 14:34:19 f_limousin
49  * Improvement of the case Cartesian --> Cartesian to be consistent
50  * with Tensor::change_triad(Base_vect&).
51  *
52  * Revision 1.4 2003/10/28 21:27:54 e_gourgoulhon
53  * -- Read-only access to the components performed by operator()(int) instead of
54  * set(int ).
55  * -- Corrected index range in the Cartesian->Cartesian case.
56  *
57  * Revision 1.3 2003/10/06 14:25:51 j_novak
58  * Added a test #ifndef... to prevent a warning
59  *
60  * Revision 1.2 2003/10/03 14:41:31 e_gourgoulhon
61  * Changed some assert.
62  *
63  * Revision 1.1 2003/09/29 12:52:57 j_novak
64  * Methods for changing the triad are implemented.
65  *
66  *
67  * $Header: /cvsroot/Lorene/C++/Source/Tensor/vector_change_triad.C,v 1.10 2016/12/05 16:18:18 j_novak Exp $
68  *
69  */
70 
71 // C headers
72 #include <cassert>
73 
74 // Lorene headers
75 #include "tensor.h"
76 
77 namespace Lorene {
78 void Vector::change_triad(const Base_vect& new_triad) {
79 
80  assert(triad != 0x0) ;
81 
82  const Base_vect_cart* nbvc = dynamic_cast<const Base_vect_cart*>(&new_triad) ;
83 #ifndef NDEBUG
84  const Base_vect_spher* nbvs
85  = dynamic_cast<const Base_vect_spher*>(&new_triad) ;
86 #endif
87 
88  assert((nbvc != 0x0) || (nbvs != 0x0)) ;
89 
90  const Base_vect_cart* bvc = dynamic_cast<const Base_vect_cart*>(triad) ;
91  const Base_vect_spher* bvs = dynamic_cast<const Base_vect_spher*>(triad) ;
92 
93  assert((bvc != 0x0) || (bvs != 0x0)) ;
94 
95  // ---------------------------------------------
96  // Case where the input triad is a Cartesian one
97  // ---------------------------------------------
98  if (nbvc != 0x0) {
99  assert(nbvs == 0x0) ;
100 
101  // -----------------------------
102  // Case cartesian -> cartesian
103  // -----------------------------
104  if (bvc != 0x0) { // The old triad is a cartesian one
105  assert(bvs == 0x0) ;
106 
107  int ind = nbvc->get_align() * (bvc->get_align()) ;
108 
109  switch (ind) {
110 
111  case 1 : { // the two bases are aligned : nothing to do
112  // -----------------------------------------
113  break ;
114  }
115 
116  case - 1 : { // the two bases are anti-aligned
117  Vector copie (*this) ;
118 
119  set(1) = - copie(1) ; // V^x --> - V^x
120  set(2) = - copie(2) ; // V^y --> - V^y
121  // V^z unchanged
122  break ;
123  }
124 
125  case 0 : { // the two basis have not a special relative orientation
126  // -----------------------------------------------------
127  cout <<
128  "Vector::change_basis : general value of rot_phi "
129  << " not contemplated yet, sorry !" << endl ;
130  abort() ;
131  break ;
132  }
133 
134  default : { // error
135  cout <<
136  "Vector::change_basis : unexpected value of ind !" << endl ;
137  cout << " ind = " << ind << endl ;
138  abort() ;
139  break ;
140  }
141  }
142 
143  } // end of the cart -> cart basis case
144 
145 
146  // -----------------------------
147  // Case spherical -> cartesian
148  // -----------------------------
149  if (bvs != 0x0) { // The old triad is a spherical one
150 
151  assert(bvc == 0x0) ;
152 
153  // The triads should be the same as that associated
154  // with the mapping :
155  assert( *nbvc == mp->get_bvect_cart() ) ;
156  assert( *bvs == mp->get_bvect_spher() ) ;
157 #ifndef NDEBUG
158  int nz = mp->get_mg()->get_nzone() ;
159  for (int i=0; i<nz; i++) {
160 //## assert( mp->get_mg()->get_np(i) >= 4) ;
161  assert( mp->get_mg()->get_nt(i) >= 5) ;
162  }
163 #endif
164  Scalar res1(*mp) ;
165  Scalar res2(*mp) ;
166 
167  mp->comp_x_from_spherical(*cmp[0], *cmp[1], *cmp[2], res1) ;
168  mp->comp_y_from_spherical(*cmp[0], *cmp[1], *cmp[2], res2) ;
169  mp->comp_z_from_spherical(*cmp[0], *cmp[1], set(3)) ;
170 
171  set(1) = res1 ;
172  set(2) = res2 ;
173 
174  }// End of the spher -> cart case
175  } // End of the case of cartesian new triad
176 
177  // ---------------------------------------------
178  // Case where the new triad is a spherical one
179  // ---------------------------------------------
180  else {
181 
182  assert(nbvc == 0x0) ;
183 
184  // ---------------------------------
185  // Case cartesian -> spherical
186  // ---------------------------------
187  if (bvc != 0x0) { // The old triad is a cartesian one
188  assert(bvs == 0x0) ;
189 
190  // The triads should be the same as that associated
191  // with the mapping :
192  assert( *nbvs == mp->get_bvect_spher() ) ;
193  assert( *bvc == mp->get_bvect_cart() ) ;
194 #ifndef NDEBUG
195  int nz = mp->get_mg()->get_nzone() ;
196  for (int i=0; i<nz; i++) {
197 //## assert( mp->get_mg()->get_np(i) >= 4) ;
198  assert( mp->get_mg()->get_nt(i) >= 5) ;
199  }
200 #endif
201  Scalar res1(*mp) ;
202  Scalar res2(*mp) ;
203 
204  mp->comp_r_from_cartesian(*cmp[0], *cmp[1], *cmp[2], res1) ;
205  mp->comp_t_from_cartesian(*cmp[0], *cmp[1], *cmp[2], res2) ;
206  mp->comp_p_from_cartesian(*cmp[0], *cmp[1], set(3)) ;
207 
208  set(1) = res1 ;
209  set(2) = res2 ;
210  } // end of the case cart -> spher
211 
212 
213  // ------------------------------------
214  // Case spherical -> spherical
215  // ------------------------------------
216  if (bvs != 0x0) {
217 
218  assert(bvc == 0x0) ;
219 
220  cout << "Vector::change_triad : case not treated yet !" << endl ;
221  abort() ;
222  } // end of the spher->spher basis case
223 
224  } // End of the case of spherical new triad
225 
226  triad = &new_triad ;
227 
228 }
229 }
int get_align() const
Returns the indicator of alignment with respect to the absolute frame.
Definition: base_vect.h:285
const Base_vect_spher & get_bvect_spher() const
Returns the orthonormal vectorial basis associated with the coordinates of the mapping.
Definition: map.h:795
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...
const Mg3d * get_mg() const
Gives the Mg3d on which the mapping is defined.
Definition: map.h:777
Tensor field of valence 0 (or component of a tensorial field).
Definition: scalar.h:393
const Base_vect * triad
Vectorial basis (triad) with respect to which the tensor components are defined.
Definition: tensor.h:309
virtual void change_triad(const Base_vect &)
Sets a new vectorial basis (triad) of decomposition and modifies the components accordingly.
Tensor field of valence 1.
Definition: vector.h:188
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 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...
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...
Scalar ** cmp
Array of size n_comp of pointers onto the components.
Definition: tensor.h:321
int get_nzone() const
Returns the number of domains.
Definition: grilles.h:465
Cartesian vectorial bases (triads).
Definition: base_vect.h:201
Spherical orthonormal vectorial bases (triads).
Definition: base_vect.h:308
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:803
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 ...
int get_nt(int l) const
Returns the number of points in the co-latitude direction ( ) in domain no. l.
Definition: grilles.h:474
const Map *const mp
Mapping on which the numerical values at the grid points are defined.
Definition: tensor.h:301
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...