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