LORENE
map_log.C
1 /*
2  * Methods of class Map_log
3  *
4  * (see file map.h for documentation)
5  *
6  */
7 
8 /*
9  * Copyright (c) 2004 Philippe Grandclement
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 
31 
32 /*
33  * $Id: map_log.C,v 1.4 2016/12/05 16:17:58 j_novak Exp $
34  * $Log: map_log.C,v $
35  * Revision 1.4 2016/12/05 16:17:58 j_novak
36  * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
37  *
38  * Revision 1.3 2014/10/13 08:53:05 j_novak
39  * Lorene classes and functions now belong to the namespace Lorene.
40  *
41  * Revision 1.2 2014/10/06 15:13:13 j_novak
42  * Modified #include directives to use c++ syntax.
43  *
44  * Revision 1.1 2004/06/22 08:49:58 p_grandclement
45  * Addition of everything needed for using the logarithmic mapping
46  *
47  *
48  * $Header: /cvsroot/Lorene/C++/Source/Map/map_log.C,v 1.4 2016/12/05 16:17:58 j_novak Exp $
49  *
50  */
51 
52 // headers C
53 #include <cmath>
54 
55 // headers Lorene
56 #include "itbl.h"
57 #include "tbl.h"
58 #include "coord.h"
59 #include "grilles.h"
60 #include "map.h"
61 
62 
63  //---------------//
64  // Constructeurs //
65  //---------------//
66 
67 // Constructor from a grid
68 // -----------------------
69 namespace Lorene {
70 Map_log::Map_log (const Mg3d& mgrille, const Tbl& bornes, const Itbl& typevar) :
71  Map_radial(mgrille), alpha (mgrille.get_nzone()), beta (mgrille.get_nzone()),
72  type_var(typevar)
73 
74 {
75  // Les bornes
76  int nzone = mg->get_nzone() ;
77 
79  beta.set_etat_qcq() ;
80 
81  for (int l=0 ; l<nzone ; l++) {
82  switch (type_var(l)) {
83  case AFFINE: {
84  switch (mg->get_type_r(l)) {
85  case RARE: {
86  alpha.set(l) = bornes(l+1) - bornes(l) ;
87  beta.set(l) = bornes(l) ;
88  break ;
89  }
90 
91  case FIN: {
92  alpha.set(l) = (bornes(l+1) - bornes(l)) * .5 ;
93  beta.set(l) = (bornes(l+1) + bornes(l)) * .5 ;
94  break ;
95  }
96 
97  case UNSURR: {
98  double umax = 1./bornes(l) ;
99  double umin = 1./bornes(l+1) ;
100  alpha.set(l) = (umin - umax) * .5 ; // u est une fonction decroissante
101  beta.set(l) = (umin + umax) * .5 ; // de l'indice i en r
102  break ;
103  }
104 
105  default: {
106  cout << "Map_log::Map_log: unkown type_r ! " << endl ;
107  abort () ;
108  break ;
109  }
110 
111  }
112  break ;
113  }
114  case LOG:{
115  switch (mg->get_type_r(l)) {
116  case FIN: {
117  alpha.set(l) = (log(bornes(l+1)) - log(bornes(l))) * .5 ;
118  beta.set(l) = (log(bornes(l+1)) + log(bornes(l))) * .5 ;
119  break ;
120  }
121 
122  default: {
123  cout << "Map_log::Map_log: unkown type_r ! " << endl ;
124  abort () ;
125  break ;
126  }
127  }
128  break ;
129  }
130 
131  default: {
132  cout << "Map_log::Map_log: unkown type_r ! " << endl ;
133  abort () ;
134  break ;
135  }
136  }
137  }
138 
139  set_coord() ;
140 }
141 
142 Map_log::Map_log (const Map_log& so) : Map_radial (*so.mg), alpha(so.alpha), beta(so.beta),
143  type_var(so.type_var) {
144  set_coord() ;
145 }
146 
147 
148 Map_log::Map_log (const Mg3d& mgrille, FILE* fd) : Map_radial (mgrille, fd),
149  alpha (mgrille.get_nzone()),
150  beta (mgrille.get_nzone()),
151  type_var (mgrille.get_nzone()) {
152  Tbl alpha_lu (fd) ;
153  Tbl beta_lu (fd) ;
154  Itbl type_lu (fd) ;
155 
156  alpha = alpha_lu ;
157  beta = beta_lu ;
158  type_var = type_lu ;
159 
160  set_coord() ;
161 }
162 
164 
165 // Sauvegarde :
166 void Map_log::sauve(FILE* fd) const {
167 
168  Map_radial::sauve(fd) ;
169  alpha.sauve(fd) ;
170  beta.sauve(fd) ;
171  type_var.sauve(fd) ;
172 }
173 
174 // Comparison operator :
175 bool Map_log::operator==(const Map& mpi) const {
176 
177  // Precision of the comparison
178  double precis = 1e-10 ;
179  bool resu = true ;
180 
181  // Dynamic cast pour etre sur meme Map...
182  const Map_log* mp0 = dynamic_cast<const Map_log*>(&mpi) ;
183  if (mp0 == 0x0)
184  resu = false ;
185  else {
186  if (*mg != *(mpi.get_mg()))
187  resu = false ;
188 
189  if (fabs(ori_x-mpi.get_ori_x()) > precis) resu = false ;
190  if (fabs(ori_y-mpi.get_ori_y()) > precis) resu = false ;
191  if (fabs(ori_z-mpi.get_ori_z()) > precis) resu = false ;
192 
193  if (bvect_spher != mpi.get_bvect_spher()) resu = false ;
194  if (bvect_cart != mpi.get_bvect_cart()) resu = false ;
195 
196  if (diffrelmax (alpha, mp0->alpha) > precis) resu = false ;
197  if (diffrelmax (beta, mp0->beta) > precis) resu = false ;
198  if (diffrelmax(type_var, mp0->type_var) > precis) resu = false ;
199  }
200 
201  return resu ;
202 }
203  //------------//
204  // Impression //
205  //------------//
206 
207 ostream & Map_log::operator>>(ostream & ost) const {
208 
209  ost << "Log mapping (class Map_log)" << endl ;
210  int nz = mg->get_nzone() ;
211  for (int l=0; l<nz; l++) {
212  ost << " Domain #" << l << " ; Variable type " ;
213  if (type_var(l) == AFFINE)
214  ost << "affine : " ;
215  if (type_var(l) == LOG)
216  ost << "log : " ;
217  ost << "alpha_l = " << alpha(l)
218  << " , beta_l = " << beta(l) << endl ;
219  }
220 
221 
222  ost << " Coord r : " ;
223  for (int l=0; l<nz; l++) {
224  int nrm1 = mg->get_nr(l) - 1 ;
225  ost << " " << (+r)(l, 0, 0, nrm1) ;
226  }
227  ost << endl ;
228 
229  return ost ;
230 }
231 
232 // Affectation to a affine mapping :
233 void Map_log::operator=(const Map_af& mpi) {
234 
235  assert(mpi.get_mg() == mg) ;
236 
237  set_ori( mpi.get_ori_x(), mpi.get_ori_y(), mpi.get_ori_z() ) ;
238 
239  set_rot_phi( mpi.get_rot_phi() ) ;
240 
241  // The members bvect_spher and bvect_cart are treated by the functions
242  // set_ori and set_rot_phi.
243 
244  for (int l=0; l<mg->get_nzone(); l++){
245  alpha.set(l) = mpi.get_alpha()[l] ;
246  beta.set(l) = mpi.get_beta()[l] ;
247  }
248 
249  type_var = AFFINE ;
250 
251  reset_coord() ;
252  set_coord() ;
253 }
254 
255 
256  //-------------------------------------------------//
257  // Assignement of the Coord building functions //
258  //-------------------------------------------------//
259 
260 void Map_log::set_coord(){
261 
262  // ... Coord's introduced by the base class Map :
263  r.set(this, map_log_fait_r) ;
264  tet.set(this, map_log_fait_tet) ;
265  phi.set(this, map_log_fait_phi) ;
266  sint.set(this, map_log_fait_sint) ;
267  cost.set(this, map_log_fait_cost) ;
268  sinp.set(this, map_log_fait_sinp) ;
269  cosp.set(this, map_log_fait_cosp) ;
270 
271  x.set(this, map_log_fait_x) ;
272  y.set(this, map_log_fait_y) ;
273  z.set(this, map_log_fait_z) ;
274 
275  xa.set(this, map_log_fait_xa) ;
276  ya.set(this, map_log_fait_ya) ;
277  za.set(this, map_log_fait_za) ;
278 
279  // ... Coord's introduced by the base class Map_radial :
280  xsr.set(this, map_log_fait_xsr) ;
281  dxdr.set(this, map_log_fait_dxdr) ;
282  drdt.set(this, map_log_fait_drdt) ;
283  stdrdp.set(this, map_log_fait_stdrdp) ;
284  srdrdt.set(this, map_log_fait_srdrdt) ;
285  srstdrdp.set(this, map_log_fait_srstdrdp) ;
286  sr2drdt.set(this, map_log_fait_sr2drdt) ;
287  sr2stdrdp.set(this, map_log_fait_sr2stdrdp) ;
288  d2rdx2.set(this, map_log_fait_d2rdx2) ;
289  lapr_tp.set(this, map_log_fait_lapr_tp) ;
290  d2rdtdx.set(this, map_log_fait_d2rdtdx) ;
291  sstd2rdpdx.set(this, map_log_fait_sstd2rdpdx) ;
292  sr2d2rdt2.set(this, map_log_fait_sr2d2rdt2) ;
293 
294  // ... Coord's introduced by the base Map_log itself
295  dxdlnr.set(this, map_log_fait_dxdlnr) ;
296 }
297 }
Coord xa
Absolute x coordinate.
Definition: map.h:748
Tbl beta
Array (size: mg->nzone ) of the values of in each domain.
Definition: map.h:3624
virtual bool operator==(const Map &) const
Comparison operator (egality)
Definition: map_log.C:175
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
Cmp log(const Cmp &)
Neperian logarithm.
Definition: cmp_math.C:299
Coord sr2stdrdp
in the nucleus and in the non-compactified shells; \ in the compactified outer domain.
Definition: map.h:1629
const double * get_alpha() const
Returns the pointer on the array alpha.
Definition: map_af.C:607
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
const Mg3d * get_mg() const
Gives the Mg3d on which the mapping is defined.
Definition: map.h:783
double & set(int i)
Read/write of a particular element (index i) (1D case)
Definition: tbl.h:301
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
Basic integer array class.
Definition: itbl.h:122
virtual ostream & operator>>(ostream &) const
Operator >>
Definition: map_log.C:207
double get_rot_phi() const
Returns the angle between the x –axis and X –axis.
Definition: map.h:793
void set(const Map *mp, Mtbl *(*construct)(const Map *))
Semi-constructor from a mapping and a method.
Definition: coord.C:137
Itbl type_var
Array (size: mg->nzone ) of the type of variable in each domain.
Definition: map.h:3628
Coord srstdrdp
in the nucleus and in the non-compactified shells; \ in the compactified outer domain.
Definition: map.h:1613
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
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition: tbl.C:364
Coord sint
Definition: map.h:739
Coord dxdlnr
Same as dxdr if the domains where the description is affine and where it is logarithmic.
Definition: map.h:3636
Coord stdrdp
in the nucleus and in the non-compactified shells; \ in the compactified external domain (CED)...
Definition: map.h:1597
virtual void operator=(const Map_af &mpa)
Assignment to an affine mapping.
Definition: map_log.C:233
Coord dxdr
in the nucleus and in the non-compactified shells; \ in the compactified outer domain.
Definition: map.h:1581
Logarithmic radial mapping.
Definition: map.h:3616
double ori_y
Absolute coordinate y of the origin.
Definition: map.h:697
const double * get_beta() const
Returns the pointer on the array beta.
Definition: map_af.C:611
void sauve(FILE *) const
Save in a file.
Definition: itbl.C:229
double ori_z
Absolute coordinate z of the origin.
Definition: map.h:698
Tbl alpha
Array (size: mg->nzone ) of the values of in each domain.
Definition: map.h:3622
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
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
Coord drdt
in the nucleus and in the non-compactified shells; \ in the compactified external domain (CED)...
Definition: map.h:1589
Map_log(const Mg3d &mgrille, const Tbl &r_limits, const Itbl &typevar)
Standard Constructor.
Definition: map_log.C:70
friend Mtbl * map_log_fait_r(const Map *)
< Not implemented
Definition: map_log_fait.C:60
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
Coord y
y coordinate centered on the grid
Definition: map.h:745
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
void sauve(FILE *) const
Save in a file.
Definition: tbl.C:329
virtual void reset_coord()
Resets all the member Coords.
Definition: map_radial.C:129
Basic array class.
Definition: tbl.h:164
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_log()
Destructor.
Definition: map_log.C:163
virtual void sauve(FILE *) const
Save in a file.
Definition: map_log.C:166
Coord z
z coordinate centered on the grid
Definition: map.h:746
Tbl diffrelmax(const Cmp &a, const Cmp &b)
Relative difference between two Cmp (max version).
Definition: cmp_math.C:542
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
Coord cost
Definition: map.h:740