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 char vector_change_triad_C[] = "$Header: /cvsroot/Lorene/C++/Source/Tensor/vector_change_triad.C,v 1.9 2014/10/13 08:53:44 j_novak Exp $" ;
27 
28 
29 /*
30  * $Id: vector_change_triad.C,v 1.9 2014/10/13 08:53:44 j_novak Exp $
31  * $Log: vector_change_triad.C,v $
32  * Revision 1.9 2014/10/13 08:53:44 j_novak
33  * Lorene classes and functions now belong to the namespace Lorene.
34  *
35  * Revision 1.8 2014/10/06 15:13:20 j_novak
36  * Modified #include directives to use c++ syntax.
37  *
38  * Revision 1.7 2010/01/26 16:47:10 e_gourgoulhon
39  * Suppressed the assert on np >= 4 (too strong ?).
40  *
41  * Revision 1.6 2005/09/15 15:51:26 j_novak
42  * The "rotation" (change of triad) methods take now Scalars as default
43  * arguments.
44  *
45  * Revision 1.5 2005/02/03 14:34:19 f_limousin
46  * Improvement of the case Cartesian --> Cartesian to be consistent
47  * with Tensor::change_triad(Base_vect&).
48  *
49  * Revision 1.4 2003/10/28 21:27:54 e_gourgoulhon
50  * -- Read-only access to the components performed by operator()(int) instead of
51  * set(int ).
52  * -- Corrected index range in the Cartesian->Cartesian case.
53  *
54  * Revision 1.3 2003/10/06 14:25:51 j_novak
55  * Added a test #ifndef... to prevent a warning
56  *
57  * Revision 1.2 2003/10/03 14:41:31 e_gourgoulhon
58  * Changed some assert.
59  *
60  * Revision 1.1 2003/09/29 12:52:57 j_novak
61  * Methods for changing the triad are implemented.
62  *
63  *
64  * $Header: /cvsroot/Lorene/C++/Source/Tensor/vector_change_triad.C,v 1.9 2014/10/13 08:53:44 j_novak Exp $
65  *
66  */
67 
68 // C headers
69 #include <cassert>
70 
71 // Lorene headers
72 #include "tensor.h"
73 
74 namespace Lorene {
75 void Vector::change_triad(const Base_vect& new_triad) {
76 
77  assert(triad != 0x0) ;
78 
79  const Base_vect_cart* nbvc = dynamic_cast<const Base_vect_cart*>(&new_triad) ;
80 #ifndef NDEBUG
81  const Base_vect_spher* nbvs
82  = dynamic_cast<const Base_vect_spher*>(&new_triad) ;
83 #endif
84 
85  assert((nbvc != 0x0) || (nbvs != 0x0)) ;
86 
87  const Base_vect_cart* bvc = dynamic_cast<const Base_vect_cart*>(triad) ;
88  const Base_vect_spher* bvs = dynamic_cast<const Base_vect_spher*>(triad) ;
89 
90  assert((bvc != 0x0) || (bvs != 0x0)) ;
91 
92  // ---------------------------------------------
93  // Case where the input triad is a Cartesian one
94  // ---------------------------------------------
95  if (nbvc != 0x0) {
96  assert(nbvs == 0x0) ;
97 
98  // -----------------------------
99  // Case cartesian -> cartesian
100  // -----------------------------
101  if (bvc != 0x0) { // The old triad is a cartesian one
102  assert(bvs == 0x0) ;
103 
104  int ind = nbvc->get_align() * (bvc->get_align()) ;
105 
106  switch (ind) {
107 
108  case 1 : { // the two bases are aligned : nothing to do
109  // -----------------------------------------
110  break ;
111  }
112 
113  case - 1 : { // the two bases are anti-aligned
114  Vector copie (*this) ;
115 
116  set(1) = - copie(1) ; // V^x --> - V^x
117  set(2) = - copie(2) ; // V^y --> - V^y
118  // V^z unchanged
119  break ;
120  }
121 
122  case 0 : { // the two basis have not a special relative orientation
123  // -----------------------------------------------------
124  cout <<
125  "Vector::change_basis : general value of rot_phi "
126  << " not contemplated yet, sorry !" << endl ;
127  abort() ;
128  break ;
129  }
130 
131  default : { // error
132  cout <<
133  "Vector::change_basis : unexpected value of ind !" << endl ;
134  cout << " ind = " << ind << endl ;
135  abort() ;
136  break ;
137  }
138  }
139 
140  } // end of the cart -> cart basis case
141 
142 
143  // -----------------------------
144  // Case spherical -> cartesian
145  // -----------------------------
146  if (bvs != 0x0) { // The old triad is a spherical one
147 
148  assert(bvc == 0x0) ;
149 
150  // The triads should be the same as that associated
151  // with the mapping :
152  assert( *nbvc == mp->get_bvect_cart() ) ;
153  assert( *bvs == mp->get_bvect_spher() ) ;
154 #ifndef NDEBUG
155  int nz = mp->get_mg()->get_nzone() ;
156  for (int i=0; i<nz; i++) {
157 //## assert( mp->get_mg()->get_np(i) >= 4) ;
158  assert( mp->get_mg()->get_nt(i) >= 5) ;
159  }
160 #endif
161  Scalar res1(*mp) ;
162  Scalar res2(*mp) ;
163 
164  mp->comp_x_from_spherical(*cmp[0], *cmp[1], *cmp[2], res1) ;
165  mp->comp_y_from_spherical(*cmp[0], *cmp[1], *cmp[2], res2) ;
166  mp->comp_z_from_spherical(*cmp[0], *cmp[1], set(3)) ;
167 
168  set(1) = res1 ;
169  set(2) = res2 ;
170 
171  }// End of the spher -> cart case
172  } // End of the case of cartesian new triad
173 
174  // ---------------------------------------------
175  // Case where the new triad is a spherical one
176  // ---------------------------------------------
177  else {
178 
179  assert(nbvc == 0x0) ;
180 
181  // ---------------------------------
182  // Case cartesian -> spherical
183  // ---------------------------------
184  if (bvc != 0x0) { // The old triad is a cartesian one
185  assert(bvs == 0x0) ;
186 
187  // The triads should be the same as that associated
188  // with the mapping :
189  assert( *nbvs == mp->get_bvect_spher() ) ;
190  assert( *bvc == mp->get_bvect_cart() ) ;
191 #ifndef NDEBUG
192  int nz = mp->get_mg()->get_nzone() ;
193  for (int i=0; i<nz; i++) {
194 //## assert( mp->get_mg()->get_np(i) >= 4) ;
195  assert( mp->get_mg()->get_nt(i) >= 5) ;
196  }
197 #endif
198  Scalar res1(*mp) ;
199  Scalar res2(*mp) ;
200 
201  mp->comp_r_from_cartesian(*cmp[0], *cmp[1], *cmp[2], res1) ;
202  mp->comp_t_from_cartesian(*cmp[0], *cmp[1], *cmp[2], res2) ;
203  mp->comp_p_from_cartesian(*cmp[0], *cmp[1], set(3)) ;
204 
205  set(1) = res1 ;
206  set(2) = res2 ;
207  } // end of the case cart -> spher
208 
209 
210  // ------------------------------------
211  // Case spherical -> spherical
212  // ------------------------------------
213  if (bvs != 0x0) {
214 
215  assert(bvc == 0x0) ;
216 
217  cout << "Vector::change_triad : case not treated yet !" << endl ;
218  abort() ;
219  } // end of the spher->spher basis case
220 
221  } // End of the case of spherical new triad
222 
223  triad = &new_triad ;
224 
225 }
226 }
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:783
Lorene prototypes.
Definition: app_hor.h:64
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:765
Tensor field of valence 0 (or component of a tensorial field).
Definition: scalar.h:387
const Base_vect * triad
Vectorial basis (triad) with respect to which the tensor components are defined.
Definition: tensor.h:303
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:315
int get_nzone() const
Returns the number of domains.
Definition: grilles.h:448
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:791
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:457
const Map *const mp
Mapping on which the numerical values at the grid points are defined.
Definition: tensor.h:295
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...