LORENE
map_star.C
1 /*
2  * Methods of class Map_star
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_star::Map_star(const Mg3d& mgrille, const double*) : Map_radial(mgrille),alpha(mgrille.get_angu()),beta(mgrille.get_angu())
53 {
54  c_est_pas_fait("Map_star::Map_star(const Mg3d&, const double*)") ;
55 }
56 
57 // Constructor from a grid
58 // -----------------------
59 Map_star::Map_star(const Mg3d& mgrille, const Tbl& bornes) : Map_radial(mgrille),alpha(mgrille.get_angu()),beta(mgrille.get_angu())
60 {
61  // Les coordonnees et les derivees du changement de variable
62  set_coord() ;
63 
64  // Allocate memory
65  alpha.annule_hard() ;
66  beta.annule_hard() ;
67 
68  // Les bornes
69  int nzone = mg->get_nzone() ;
70  // assert(nzone==1) ; // To be changed ; nucleus only at the moment
71 
72  for (int l=0 ; l<nzone ; l++) {
73  for (int k=0 ; k<mg->get_np(l); k++){
74  for (int j=0; j<mg->get_nt(l); j++){
75  switch (mg->get_type_r(l)) {
76  case RARE: {
77  alpha.set(l,k,j,0) = bornes(l+1,k,j) ;
78  beta.set(l) = 0 ;
79  break ;
80  }
81 
82  case FIN: {
83  alpha.set(l,k,j,0) = 0.5*(bornes(l+1,k,j) - bornes(l,k,j)) ;
84  beta.set(l,k,j,0) = 0.5*(bornes(l+1,k,j) + bornes(l,k,j)) ;
85  break ;
86  }
87 
88  case UNSURR: {
89  cout << "Warning ! No compactified domain allowed !" << endl;
90  abort() ;
91  break ;
92  }
93 
94  default: {
95  cout << "Map_star::Map_star: unkown type_r ! " << endl ;
96  abort () ;
97  break ;
98  }
99  }
100  alpha.std_base_scal() ;
101  beta.std_base_scal() ;
102  }
103  }
104  } // Fin de la boucle sur zone
105 }
106 
107 // Copy constructor
108 // ----------------
109 Map_star::Map_star(const Map_star& mp) : Map_radial(mp),alpha(mp.alpha),beta(mp.beta)
110 {
111  // Les coordonnees et les derivees du changement de variable
112  set_coord() ;
113 }
114 
115 
116 // Constructor from file
117 // ---------------------
118 Map_star::Map_star(const Mg3d& mgi, FILE* fd) : Map_radial(mgi, fd),alpha(*mgi.get_angu(), fd),beta(*mgi.get_angu(), fd)
119 {
120  // Les coordonnees et les derivees du changement de variable
121  set_coord() ;
122 }
123 
124  //--------------//
125  // Destructeurs //
126  //--------------//
127 
129 
130 }
131 
132  //-------------//
133  // Assignement //
134  //-------------//
135 
136 // From another Map_star
137 // -------------------
138 
139 void Map_star::operator=(const Map_star & mpi) {
140 
141  assert(mpi.mg == mg) ;
142 
143  set_ori( mpi.ori_x, mpi.ori_y, mpi.ori_z ) ;
144 
145  set_rot_phi( mpi.rot_phi ) ;
146 
147  alpha = mpi.alpha ;
148  beta = mpi.beta ;
149 
150  reset_coord() ;
151 }
152 
153 //Assignment to a Map_af.
154 
156 
157  c_est_pas_fait("Map_star::operator=(const Map_af)") ;
158 }
159 
160 
161  //-------------------------------------------------//
162  // Assignement of the Coord building functions //
163  //-------------------------------------------------//
164 
166 
167  // ... Coord's introduced by the base class Map :
168  r.set(this, map_star_fait_r) ;
169  tet.set(this, map_star_fait_tet) ;
170  phi.set(this, map_star_fait_phi) ;
171  sint.set(this, map_star_fait_sint) ;
172  cost.set(this, map_star_fait_cost) ;
173  sinp.set(this, map_star_fait_sinp) ;
174  cosp.set(this, map_star_fait_cosp) ;
175 
176  x.set(this, map_star_fait_x) ;
177  y.set(this, map_star_fait_y) ;
178  z.set(this, map_star_fait_z) ;
179 
180  xa.set(this, map_star_fait_xa) ;
181  ya.set(this, map_star_fait_ya) ;
182  za.set(this, map_star_fait_za) ;
183 
184  // ... Coord's introduced by the base class Map_radial :
185  xsr.set(this, map_star_fait_xsr) ;
186  dxdr.set(this, map_star_fait_dxdr) ;
187  drdt.set(this, map_star_fait_drdt) ;
188  stdrdp.set(this, map_star_fait_stdrdp) ;
189  srdrdt.set(this, map_star_fait_srdrdt) ;
190  srstdrdp.set(this, map_star_fait_srstdrdp) ;
191  sr2drdt.set(this, map_star_fait_sr2drdt) ;
192  sr2stdrdp.set(this, map_star_fait_sr2stdrdp) ;
193  d2rdx2.set(this, map_star_fait_d2rdx2) ;
194  lapr_tp.set(this, map_star_fait_lapr_tp) ;
195  d2rdtdx.set(this, map_star_fait_d2rdtdx) ;
196  sstd2rdpdx.set(this, map_star_fait_sstd2rdpdx) ;
197  sr2d2rdt2.set(this, map_star_fait_sr2d2rdt2) ;
198 
199 }
200 // Comparison operator :
201 bool Map_star::operator==(const Map& mpi) const {
202 
203  // Precision of the comparison
204  double precis = 1e-10 ;
205  bool resu = true ;
206 
207  // Dynamic cast pour etre sur meme Map...
208  const Map_star* mp0 = dynamic_cast<const Map_star*>(&mpi) ;
209  if (mp0 == 0x0)
210  resu = false ;
211  else {
212  if (*mg != *(mpi.get_mg()))
213  resu = false ;
214 
215  if (fabs(ori_x-mpi.get_ori_x()) > precis) resu = false ;
216  if (fabs(ori_y-mpi.get_ori_y()) > precis) resu = false ;
217  if (fabs(ori_z-mpi.get_ori_z()) > precis) resu = false ;
218 
219  if (bvect_spher != mpi.get_bvect_spher()) resu = false ;
220  if (bvect_cart != mpi.get_bvect_cart()) resu = false ;
221 
222  int nz = mg->get_nzone() ;
223  for (int i=0 ; i<nz ; i++) {
224  if (max(abs(alpha(i)-mp0->alpha(i))/abs(alpha(i))) > precis)
225  resu = false ;
226  }
227  }
228 
229  return resu ;
230 }
231 
232 
233  //--------------------------------------//
234  // Extraction of the mapping parameters //
235  //--------------------------------------//
236 
237 const Valeur& Map_star::get_alpha() const {
238  return alpha ;
239 }
240 const Valeur& Map_star::get_beta() const {
241  return beta ;
242 }
243 
244  //------------//
245  // Sauvegarde //
246  //------------//
247 
248 void Map_star::sauve(FILE* fd) const {
249 
250  Map_radial::sauve(fd) ;
251 
252  alpha.sauve(fd) ; //May not be enough to save everything...
253  beta.sauve(fd) ;
254 
255 }
256 
257  //------------//
258  // Impression //
259  //------------//
260 
261 ostream & Map_star::operator>>(ostream & ost) const {
262 
263  using namespace Unites ;
264 
265  ost << "Affine + starlike mapping (class Map_star)" << endl ;
266  int nz = mg->get_nzone() ;
267  for (int l=0; l<nz; l++) {
268  for (int k=0 ; k<mg->get_np(l); k++){
269  for (int j=0; j<mg->get_nt(l); j++){
270  ost << " Domain #" << l << " grid point index in theta : " << j << " phi : " << k << '\n' << " : alpha(l,k,j) = " << alpha(l,k,j,0)
271  << '\n' << " : beta(l,k,j) = " << beta(l,k,j,0)
272  << endl ;
273  }
274  }
275  }
276 
277  ost << endl << " Values of r at the outer boundary of each domain [km] :"
278  << endl ;
279  ost << " val_r : " ;
280  for (int l=0; l<nz; l++) {
281  for (int k=0 ; k<mg->get_np(l); k++){
282  for (int j=0; j<mg->get_nt(l); j++){
283  ost << " " << val_r(l, 1., (+tet)(l,k,j,0), (+phi)(l,k,j,0)) / km ;
284  }
285  }
286  }
287  ost << endl ;
288 
289  ost << " Coord r : " ;
290  for (int l=0; l<nz; l++) {
291  for (int k=0 ; k<mg->get_np(l); k++){
292  for (int j=0; j<mg->get_nt(l); j++){
293  int nrm1 = mg->get_nr(l) - 1 ;
294  ost << " " << (+r)(l, k, j, nrm1) / km ;
295  }
296  }
297  }
298  ost << endl ;
299 
300  return ost ;
301 }
302 
303  //------------------------------------------//
304  // Modification of the mapping parameters //
305  //------------------------------------------//
306 
307 void Map_star::set_alpha(const Tbl& alpha0, int l) {
308 
309  assert(l>=0) ;
310  assert(l<mg->get_nzone()) ;
311 
312  int Nt = mg->get_nt(l) ;
313  int Np = mg->get_np(l) ;
314  for (int k=0; k<Np; k++)
315  for (int j=0; j<Nt; j++){
316  alpha.set(l, k, j, 0) = alpha0(k,j) ; // alpha0 must represent the values of the radius.
317  }
318 
319 
320  reset_coord() ;
321 
322 }
323 
324 void Map_star::set_alpha(const Valeur& alpha0) {
325 
326  alpha = alpha0 ;
327  alpha.std_base_scal() ;
328 
329  reset_coord() ;
330 
331 }
332 
333 void Map_star::set_beta(const Valeur& beta0) {
334 
335  beta = beta0 ;
336  beta.std_base_scal() ;
337 
338  reset_coord() ;
339 
340 }
341 
342 void Map_star::set_beta(const Tbl& beta0, int l) {
343 
344  assert(l>=0) ;
345  assert(l<mg->get_nzone()) ;
346 
347  int Nt = mg->get_nt(l) ;
348  int Np = mg->get_np(l) ;
349  for (int k=0; k<Np; k++)
350  for (int j=0; j<Nt; j++){
351  beta.set(l, k, j, 0) = beta0(k,j) ; // beta0 must represent the values of the radius.
352  }
353  reset_coord() ;
354 
355 }
356 
357 
358 
359 }
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
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
int get_np(int l) const
Returns the number of points in the azimuthal direction ( ) in domain no. l.
Definition: grilles.h:479
virtual bool operator==(const Map &) const
Comparison operator (egality)
Definition: map_star.C:201
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
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
friend Mtbl * map_star_fait_r(const Map *)
< Not implemented
Definition: map_star_fait.C:43
Values and coefficients of a (real-value) function.
Definition: valeur.h:297
void set(const Map *mp, Mtbl *(*construct)(const Map *))
Semi-constructor from a mapping and a method.
Definition: coord.C:137
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
virtual void operator=(const Map_af &)
Assignment to an affine mapping.
Definition: map_star.C:155
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 set_alpha(const Tbl &alpha0, int l)
Modifies the value of in domain no. l.
Definition: map_star.C:307
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
double ori_y
Absolute coordinate y of the origin.
Definition: map.h:697
double ori_z
Absolute coordinate z of the origin.
Definition: map.h:698
Base class for pure radial mappings.
Definition: map.h:1557
Map_star(const Mg3d &mgrille, const double *r_limits)
Standard Constructor.
Definition: map_star.C:52
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
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
const Valeur & get_alpha() const
Returns the reference on the Tbl alpha.
Definition: map_star.C:237
Coord drdt
in the nucleus and in the non-compactified shells; \ in the compactified external domain (CED)...
Definition: map.h:1589
void set_coord()
Assignment of the building functions to the member Coords.
Definition: map_star.C:165
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
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.
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
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
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
virtual ostream & operator>>(ostream &) const
Operator >>
Definition: map_star.C:261
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
virtual ~Map_star()
Destructor.
Definition: map_star.C:128
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
Base_vect_cart bvect_cart
Cartesian basis associated with the coordinates (x,y,z) of the mapping, i.e.
Definition: map.h:715
Valeur alpha
Array (size: mg->nzone*Nt*Np ) of the values of in each domain.
Definition: map_star.h:30
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
virtual void sauve(FILE *) const
Save in a file.
Definition: map_star.C:248
Coord cost
Definition: map.h:740