LORENE
map_eps.C
1 /*
2  * Methods of class Map_eps
3  *
4  * (see file map.h for documentation)
5  *
6  */
7 
8 
9 /*
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 // headers C++
31 #include <stdexcept>
32 
33 // headers C
34 #include <cmath>
35 
36 // headers Lorene
37 #include "valeur.h"
38 #include "map.h"
39 #include "utilitaires.h"
40 #include "proto.h"
41 #include "unites.h"
42 
43 
44 
45  //---------------//
46  // Constructeurs //
47  //---------------//
48 
49 // Constructor from a grid
50 // -----------------------
51 namespace Lorene {
52 Map_eps::Map_eps(const Mg3d& mgrille, const double*) : Map_radial(mgrille),alpha(mgrille.get_angu()),beta(mgrille.get_angu())
53 {
54  c_est_pas_fait("Map_eps::Map_eps(const Mg3d&, const double*)") ;
55 }
56 
57 // Constructor from a grid
58 // -----------------------
59 Map_eps::Map_eps(const Mg3d& mgrille, double a, double b, double c) : Map_radial(mgrille),aa(a),bb(b),cc(c),alpha(mgrille.get_angu()),beta(mgrille.get_angu())
60 {
61  assert(aa > 0.) ;
62  assert(bb > 0.) ;
63  assert(cc > 0.) ;
64  // Les coordonnees et les derivees du changement de variable
65  set_coord() ;
66 
67  // Allocate memory
68  alpha.annule_hard() ;
69  beta.annule_hard() ;
70 
71  // Les bornes
72  int nzone = mg->get_nzone() ;
73  assert(nzone==1) ; // Only one zone thank you
74  const Grille3d* g = mg->get_grille3d(0) ;
75 
76  for (int l=0 ; l<nzone ; l++) {
77  for (int k=0 ; k<mg->get_np(l); k++){
78  for (int j=0; j<mg->get_nt(l); j++){
79  switch (mg->get_type_r(l)) {
80  case RARE: {
81  double theta = (g->tet)[j] ;
82  double pphi = (g->phi)[k] ;
83  alpha.set(l,k,j,0) = 1/sqrt(pow(cos(pphi)*sin(theta)/a, 2.) + pow(sin(pphi)*sin(theta)/b, 2.) + pow(cos(theta)/c, 2.)) ;
84  beta.set(l) = 0. ;
85  break ;
86  }
87 
88  case FIN: {
89  cout << "Warning ! No shell allowed !" << endl;
90  abort() ;
91  break ;
92  }
93 
94  case UNSURR: {
95  cout << "Warning ! No compactified domain allowed !" << endl;
96  abort() ;
97  break ;
98  }
99 
100  default: {
101  cout << "Map_eps::Map_eps: unkown type_r ! " << endl ;
102  abort () ;
103  break ;
104  }
105  }
106  alpha.std_base_scal() ;
107  beta.std_base_scal() ;
108  }
109  }
110  } // Fin de la boucle sur zone
111 }
112 
113 // Copy constructor
114 // ----------------
115 Map_eps::Map_eps(const Map_eps& mp) : Map_radial(mp),alpha(mp.alpha),beta(mp.beta)
116 {
117  // Les coordonnees et les derivees du changement de variable
118  set_coord() ;
119 }
120 
121 
122 // Constructor from file
123 // ---------------------
124 Map_eps::Map_eps(const Mg3d& mgi, FILE* fd) : Map_radial(mgi, fd),alpha(*mgi.get_angu(), fd),beta(*mgi.get_angu(), fd)
125 {
126  // Les coordonnees et les derivees du changement de variable
127  set_coord() ;
128 }
129 
130  //--------------//
131  // Destructeurs //
132  //--------------//
133 
135 
136 }
137 
138  //-------------//
139  // Assignement //
140  //-------------//
141 
142 // From another Map_eps
143 // -------------------
144 
145 void Map_eps::operator=(const Map_eps & mpi) {
146 
147  assert(mpi.mg == mg) ;
148 
149  set_ori( mpi.ori_x, mpi.ori_y, mpi.ori_z ) ;
150 
151  set_rot_phi( mpi.rot_phi ) ;
152 
153  alpha = mpi.alpha ;
154  beta = mpi.beta ;
155 
156  reset_coord() ;
157 }
158 
159 //Assignment to a Map_af.
160 
161 void Map_eps::operator=(const Map_af &) {
162 
163  c_est_pas_fait("Map_eps::operator=(const Map_af)") ;
164 }
165 
166 
167  //-------------------------------------------------//
168  // Assignement of the Coord building functions //
169  //-------------------------------------------------//
170 
172 
173  // ... Coord's introduced by the base class Map :
174  r.set(this, map_eps_fait_r) ;
175  tet.set(this, map_eps_fait_tet) ;
176  phi.set(this, map_eps_fait_phi) ;
177  sint.set(this, map_eps_fait_sint) ;
178  cost.set(this, map_eps_fait_cost) ;
179  sinp.set(this, map_eps_fait_sinp) ;
180  cosp.set(this, map_eps_fait_cosp) ;
181 
182  x.set(this, map_eps_fait_x) ;
183  y.set(this, map_eps_fait_y) ;
184  z.set(this, map_eps_fait_z) ;
185 
186  xa.set(this, map_eps_fait_xa) ;
187  ya.set(this, map_eps_fait_ya) ;
188  za.set(this, map_eps_fait_za) ;
189 
190  // ... Coord's introduced by the base class Map_radial :
191  xsr.set(this, map_eps_fait_xsr) ;
192  dxdr.set(this, map_eps_fait_dxdr) ;
193  drdt.set(this, map_eps_fait_drdt) ;
194  stdrdp.set(this, map_eps_fait_stdrdp) ;
195  srdrdt.set(this, map_eps_fait_srdrdt) ;
196  srstdrdp.set(this, map_eps_fait_srstdrdp) ;
197  sr2drdt.set(this, map_eps_fait_sr2drdt) ;
198  sr2stdrdp.set(this, map_eps_fait_sr2stdrdp) ;
199  d2rdx2.set(this, map_eps_fait_d2rdx2) ;
200  lapr_tp.set(this, map_eps_fait_lapr_tp) ;
201  d2rdtdx.set(this, map_eps_fait_d2rdtdx) ;
202  sstd2rdpdx.set(this, map_eps_fait_sstd2rdpdx) ;
203  sr2d2rdt2.set(this, map_eps_fait_sr2d2rdt2) ;
204 
205 }
206 // Comparison operator :
207 bool Map_eps::operator==(const Map& mpi) const {
208 
209  // Precision of the comparison
210  double precis = 1e-10 ;
211  bool resu = true ;
212 
213  // Dynamic cast pour etre sur meme Map...
214  const Map_eps* mp0 = dynamic_cast<const Map_eps*>(&mpi) ;
215  if (mp0 == 0x0)
216  resu = false ;
217  else {
218  if (*mg != *(mpi.get_mg()))
219  resu = false ;
220 
221  if (fabs(ori_x-mpi.get_ori_x()) > precis) resu = false ;
222  if (fabs(ori_y-mpi.get_ori_y()) > precis) resu = false ;
223  if (fabs(ori_z-mpi.get_ori_z()) > precis) resu = false ;
224 
225  if (bvect_spher != mpi.get_bvect_spher()) resu = false ;
226  if (bvect_cart != mpi.get_bvect_cart()) resu = false ;
227 
228  int nz = mg->get_nzone() ;
229  for (int i=0 ; i<nz ; i++) {
230  if (max(abs(alpha(i)-mp0->alpha(i))/abs(alpha(i))) > precis)
231  resu = false ;
232  }
233  }
234 
235  return resu ;
236 }
237 
238 
239  //--------------------------------------//
240  // Extraction of the mapping parameters //
241  //--------------------------------------//
242 
243 const Valeur& Map_eps::get_alpha() const {
244  return alpha ;
245 }
246 const Valeur& Map_eps::get_beta() const {
247  return beta ;
248 }
249 
250  //------------//
251  // Sauvegarde //
252  //------------//
253 
254 void Map_eps::sauve(FILE* fd) const {
255 
256  Map_radial::sauve(fd) ;
257 
258  alpha.sauve(fd) ; //May not be enough to save everything...
259  beta.sauve(fd) ;
260 
261 }
262 
263  //------------//
264  // Impression //
265  //------------//
266 
267 ostream & Map_eps::operator>>(ostream & ost) const {
268 
269  using namespace Unites ;
270 
271  ost << "Ellipsoidal mapping (class Map_eps)" << endl ;
272  ost << "Parameters of the ellipsoid: (x-axis) a = " << aa << " (y-axis) b = " << bb << " (z-axis) c = " << cc << endl;
273  int nz = mg->get_nzone() ;
274  for (int l=0; l<nz; l++) {
275  for (int k=0 ; k<mg->get_np(l); k++){
276  for (int j=0; j<mg->get_nt(l); j++){
277  ost << " Domain #" << l << " grid point index in theta : " << j << " phi : " << k << '\n' << " : alpha(l,k,j) = " << alpha(l,k,j,0)
278  << '\n' << " : beta(l,k,j) = " << beta(l,k,j,0)
279  << endl ;
280  }
281  }
282  }
283 
284  ost << endl << " Values of r at the outer boundary of each domain [km] :"
285  << endl ;
286  ost << " val_r : " ;
287  for (int l=0; l<nz; l++) {
288  for (int k=0 ; k<mg->get_np(l); k++){
289  for (int j=0; j<mg->get_nt(l); j++){
290  ost << " " << val_r(l, 1., (+tet)(l,k,j,0), (+phi)(l,k,j,0)) / km ;
291  }
292  }
293  }
294  ost << endl ;
295 
296  ost << " Coord r : " ;
297  for (int l=0; l<nz; l++) {
298  for (int k=0 ; k<mg->get_np(l); k++){
299  for (int j=0; j<mg->get_nt(l); j++){
300  int nrm1 = mg->get_nr(l) - 1 ;
301  ost << " " << (+r)(l, k, j, nrm1) / km ;
302  }
303  }
304  }
305  ost << endl ;
306 
307  return ost ;
308 }
309 
310  //------------------------------------------//
311  // Modification of the mapping parameters //
312  //------------------------------------------//
313 
314 void Map_eps::set_alpha(const Tbl& alpha0, int l) {
315 
316  assert(l>=0) ;
317  assert(l<mg->get_nzone()) ;
318 
319  int Nt = mg->get_nt(l) ;
320  int Np = mg->get_np(l) ;
321  for (int k=0; k<Np; k++)
322  for (int j=0; j<Nt; j++){
323  alpha.set(l, k, j, 0) = alpha0(k,j) ; // alpha0 must represent the values of the radius.
324  }
325 
326 
327  reset_coord() ;
328 
329 }
330 
331 void Map_eps::set_alpha(const Valeur& alpha0) {
332 
333  alpha = alpha0 ;
334  alpha.std_base_scal() ;
335 
336  reset_coord() ;
337 
338 }
339 
340 void Map_eps::set_beta(const Valeur& beta0) {
341 
342  beta = beta0 ;
343  beta.std_base_scal() ;
344 
345  reset_coord() ;
346 
347 }
348 
349 void Map_eps::set_beta(const Tbl& beta0, int l) {
350 
351  assert(l>=0) ;
352  assert(l<mg->get_nzone()) ;
353 
354  int Nt = mg->get_nt(l) ;
355  int Np = mg->get_np(l) ;
356  for (int k=0; k<Np; k++)
357  for (int j=0; j<Nt; j++){
358  beta.set(l, k, j, 0) = beta0(k,j) ; // beta0 must represent the values of the radius.
359  }
360  reset_coord() ;
361 
362 }
363 
364 
365 
366 }
virtual ostream & operator>>(ostream &) const
Operator >>
Definition: map_eps.C:267
Coord xa
Absolute x coordinate.
Definition: map.h:748
Coord d2rdx2
in the nucleus and in the non-compactified shells; \ in the compactified outer domain.
Definition: map.h:1640
const Grille3d * get_grille3d(int l) const
Returns a pointer on the 3D mono-grid for domain no. l.
Definition: grilles.h:517
Coord sr2d2rdt2
in the nucleus and in the non-compactified shells; \ in the compactified outer domain.
Definition: map.h:1678
Coord sr2stdrdp
in the nucleus and in the non-compactified shells; \ in the compactified outer domain.
Definition: map.h:1629
friend Mtbl * map_eps_fait_r(const Map *)
< Not implemented
Definition: map_eps_fait.C:43
int get_np(int l) const
Returns the number of points in the azimuthal direction ( ) in domain no. l.
Definition: grilles.h:479
Cmp sqrt(const Cmp &)
Square root.
Definition: cmp_math.C:223
void set_rot_phi(double phi0)
Sets a new rotation angle.
Definition: map.C:266
double get_ori_y() const
Returns the y coordinate of the origin.
Definition: map.h:788
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
Standard units of space, time and mass.
void annule_hard()
Sets the Valeur to zero in a hard way.
Definition: valeur.C:726
const Mg3d * get_mg() const
Gives the Mg3d on which the mapping is defined.
Definition: map.h:783
double * phi
Array of values of at the np collocation points.
Definition: grilles.h:219
Coord sr2drdt
in the nucleus and in the non-compactified shells; \ in the compactified outer domain.
Definition: map.h:1621
Base class for coordinate mappings.
Definition: map.h:688
double get_ori_x() const
Returns the x coordinate of the origin.
Definition: map.h:786
virtual void operator=(const Map_af &)
Assignment to an affine mapping.
Definition: map_eps.C:161
Values and coefficients of a (real-value) function.
Definition: valeur.h:297
void set_alpha(const Tbl &alpha0, int l)
Modifies the value of in domain no. l.
Definition: map_eps.C:314
void set(const Map *mp, Mtbl *(*construct)(const Map *))
Semi-constructor from a mapping and a method.
Definition: coord.C:137
Map_eps(const Mg3d &mgrille, const double *r_limits)
Standard Constructor.
Definition: map_eps.C:52
Cmp cos(const Cmp &)
Cosine.
Definition: cmp_math.C:97
virtual bool operator==(const Map &) const
Comparison operator (egality)
Definition: map_eps.C:207
Coord srstdrdp
in the nucleus and in the non-compactified shells; \ in the compactified outer domain.
Definition: map.h:1613
void std_base_scal()
Sets the bases for spectral expansions (member base ) to the standard ones for a scalar.
Definition: valeur.C:827
Coord tet
coordinate centered on the grid
Definition: map.h:737
void set_ori(double xa0, double ya0, double za0)
Sets a new origin.
Definition: map.C:256
Coord phi
coordinate centered on the grid
Definition: map.h:738
Coord sint
Definition: map.h:739
Coord stdrdp
in the nucleus and in the non-compactified shells; \ in the compactified external domain (CED)...
Definition: map.h:1597
void sauve(FILE *) const
Save in a file.
Definition: valeur.C:478
Coord dxdr
in the nucleus and in the non-compactified shells; \ in the compactified outer domain.
Definition: map.h:1581
const Valeur & get_alpha() const
Returns the reference on the Tbl alpha.
Definition: map_eps.C:243
double ori_y
Absolute coordinate y of the origin.
Definition: map.h:697
double * tet
Array of values of at the nt collocation points.
Definition: grilles.h:217
double ori_z
Absolute coordinate z of the origin.
Definition: map.h:698
Base class for pure radial mappings.
Definition: map.h:1557
Coord sinp
Definition: map.h:741
int get_nzone() const
Returns the number of domains.
Definition: grilles.h:465
Tbl max(const Cmp &)
Maximum values of a Cmp in each domain.
Definition: cmp_math.C:438
Coord sstd2rdpdx
in the nucleus and in the non-compactified shells; \ in the compactified outer domain.
Definition: map.h:1669
void set_coord()
Assignment of the building functions to the member Coords.
Definition: map_eps.C:171
virtual void sauve(FILE *) const
Save in a file.
Definition: map_radial.C:119
Coord xsr
in the nucleus; \ 1/R in the non-compactified shells; \ in the compactified outer domain...
Definition: map.h:1570
Cmp pow(const Cmp &, int)
Power .
Definition: cmp_math.C:351
Coord drdt
in the nucleus and in the non-compactified shells; \ in the compactified external domain (CED)...
Definition: map.h:1589
virtual void sauve(FILE *) const
Save in a file.
Definition: map_eps.C:254
virtual ~Map_eps()
Destructor.
Definition: map_eps.C:134
int get_nr(int l) const
Returns the number of points in the radial direction ( ) in domain no. l.
Definition: grilles.h:469
Coord ya
Absolute y coordinate.
Definition: map.h:749
const Mg3d * mg
Pointer on the multi-grid Mgd3 on which this is defined.
Definition: map.h:694
Multi-domain grid.
Definition: grilles.h:279
double ori_x
Absolute coordinate x of the origin.
Definition: map.h:696
Affine radial mapping.
Definition: map.h:2048
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 c_est_pas_fait(const char *)
Helpful function to say something is not implemented yet.
Coord y
y coordinate centered on the grid
Definition: map.h:745
Cmp abs(const Cmp &)
Absolute value.
Definition: cmp_math.C:413
Coord za
Absolute z coordinate.
Definition: map.h:750
Coord lapr_tp
in the nucleus and in the non-compactified shells; \ in the compactified outer domain.
Definition: map.h:1652
Coord cosp
Definition: map.h:742
virtual double val_r(int l, double xi, double theta, double pphi) const
Returns the value of the radial coordinate r for a given in a given domain.
Coord x
x coordinate centered on the grid
Definition: map.h:744
Base_vect_spher bvect_spher
Orthonormal vectorial basis associated with the coordinates of the mapping.
Definition: map.h:707
double get_ori_z() const
Returns the z coordinate of the origin.
Definition: map.h:790
virtual void reset_coord()
Resets all the member Coords.
Definition: map_radial.C:129
Cmp sin(const Cmp &)
Sine.
Definition: cmp_math.C:72
Basic array class.
Definition: tbl.h:164
int get_nt(int l) const
Returns the number of points in the co-latitude direction ( ) in domain no. l.
Definition: grilles.h:474
int get_type_r(int l) const
Returns the type of sampling in the radial direction in domain no.
Definition: grilles.h:491
Coord srdrdt
in the nucleus and in the non-compactified shells; \ in the compactified outer domain.
Definition: map.h:1605
double aa
Array (size: mg->nzone*Nt*Np ) of the values of in each domain.
Definition: map_star.h:329
Coord z
z coordinate centered on the grid
Definition: map.h:746
double rot_phi
Angle between the x –axis and X –axis.
Definition: map.h:699
3D grid class in one domain.
Definition: grilles.h:200
Base_vect_cart bvect_cart
Cartesian basis associated with the coordinates (x,y,z) of the mapping, i.e.
Definition: map.h:715
Coord r
r coordinate centered on the grid
Definition: map.h:736
Coord d2rdtdx
in the nucleus and in the non-compactified shells; \ in the compactified outer domain.
Definition: map.h:1661
Tbl & set(int l)
Read/write of the value in a given domain (configuration space).
Definition: valeur.h:373
Coord cost
Definition: map.h:740