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// -----------------------
69namespace Lorene {
70Map_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
78 alpha.set_etat_qcq() ;
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
142Map_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
148Map_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 :
166void Map_log::sauve(FILE* fd) const {
167
169 alpha.sauve(fd) ;
170 beta.sauve(fd) ;
171 type_var.sauve(fd) ;
172}
173
174// Comparison operator :
175bool 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
207ostream & 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 :
233void 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
260void 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}
void set(const Map *mp, Mtbl *(*construct)(const Map *))
Semi-constructor from a mapping and a method.
Definition coord.C:137
Basic integer array class.
Definition itbl.h:122
Affine radial mapping.
Definition map.h:2042
const double * get_beta() const
Returns the pointer on the array beta.
Definition map_af.C:608
const double * get_alpha() const
Returns the pointer on the array alpha.
Definition map_af.C:604
Itbl type_var
Array (size: mg->nzone ) of the type of variable in each domain.
Definition map.h:3615
virtual void sauve(FILE *) const
Save in a file.
Definition map_log.C:166
Tbl alpha
Array (size: mg->nzone ) of the values of in each domain.
Definition map.h:3609
virtual ostream & operator>>(ostream &) const
Operator >>.
Definition map_log.C:207
Map_log(const Mg3d &mgrille, const Tbl &r_limits, const Itbl &typevar)
Standard Constructor.
Definition map_log.C:70
virtual ~Map_log()
Destructor.
Definition map_log.C:163
Coord dxdlnr
Same as dxdr if the domains where the description is affine and where it is logarithmic.
Definition map.h:3623
virtual void operator=(const Map_af &mpa)
Assignment to an affine mapping.
Definition map_log.C:233
virtual bool operator==(const Map &) const
Comparison operator (egality).
Definition map_log.C:175
Tbl beta
Array (size: mg->nzone ) of the values of in each domain.
Definition map.h:3611
Coord d2rdx2
in the nucleus and in the non-compactified shells; \ in the compactified outer domain.
Definition map.h:1634
Coord sr2drdt
in the nucleus and in the non-compactified shells; \ in the compactified outer domain.
Definition map.h:1615
Coord srstdrdp
in the nucleus and in the non-compactified shells; \ in the compactified outer domain.
Definition map.h:1607
Coord d2rdtdx
in the nucleus and in the non-compactified shells; \ in the compactified outer domain.
Definition map.h:1655
Coord sstd2rdpdx
in the nucleus and in the non-compactified shells; \ in the compactified outer domain.
Definition map.h:1663
virtual void reset_coord()
Resets all the member Coords.
Definition map_radial.C:129
Coord lapr_tp
in the nucleus and in the non-compactified shells; \ in the compactified outer domain.
Definition map.h:1646
Coord sr2stdrdp
in the nucleus and in the non-compactified shells; \ in the compactified outer domain.
Definition map.h:1623
Coord drdt
in the nucleus and in the non-compactified shells; \ in the compactified external domain (CED).
Definition map.h:1583
Coord srdrdt
in the nucleus and in the non-compactified shells; \ in the compactified outer domain.
Definition map.h:1599
Map_radial(const Mg3d &mgrid)
Constructor from a grid (protected to make Map_radial an abstract class).
Definition map_radial.C:92
Coord xsr
in the nucleus; \ 1/R in the non-compactified shells; \ in the compactified outer domain.
Definition map.h:1564
virtual void sauve(FILE *) const
Save in a file.
Definition map_radial.C:119
Coord dxdr
in the nucleus and in the non-compactified shells; \ in the compactified outer domain.
Definition map.h:1575
Coord sr2d2rdt2
in the nucleus and in the non-compactified shells; \ in the compactified outer domain.
Definition map.h:1672
Coord stdrdp
in the nucleus and in the non-compactified shells; \ in the compactified external domain (CED).
Definition map.h:1591
Multi-domain grid.
Definition grilles.h:279
Basic array class.
Definition tbl.h:161
Tbl diffrelmax(const Cmp &a, const Cmp &b)
Relative difference between two Cmp (max version).
Definition cmp_math.C:542
Cmp log(const Cmp &)
Neperian logarithm.
Definition cmp_math.C:299
Base_vect_spher bvect_spher
Base class for coordinate mappings.
Definition map.h:701
Lorene prototypes.
Definition app_hor.h:67
Coord z
z coordinate centered on the grid
Definition map.h:740
Base_vect_cart bvect_cart
Cartesian basis associated with the coordinates (x,y,z) of the mapping, i.e.
Definition map.h:709
Coord cost
Definition map.h:734
Coord y
y coordinate centered on the grid
Definition map.h:739
Coord cosp
Definition map.h:736
Map(const Mg3d &)
Constructor from a multi-domain 3D grid.
Definition map.C:142
Coord phi
coordinate centered on the grid
Definition map.h:732
Coord tet
coordinate centered on the grid
Definition map.h:731
void set_rot_phi(double phi0)
Sets a new rotation angle.
Coord x
x coordinate centered on the grid
Definition map.h:738
Coord xa
Absolute x coordinate.
Definition map.h:742
Coord za
Absolute z coordinate.
Definition map.h:744
void set_ori(double xa0, double ya0, double za0)
Sets a new origin.
Coord sinp
Definition map.h:735
Coord r
r coordinate centered on the grid
Definition map.h:730
Coord ya
Absolute y coordinate.
Definition map.h:743
Coord sint
Definition map.h:733