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// -----------------------
51namespace Lorene {
52Map_eps::Map_eps(const Mg3d& mgrille, const double* bornes) : 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// -----------------------
59Map_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// ----------------
115Map_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// ---------------------
124Map_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
145void 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
161void Map_eps::operator=(const Map_af & mpi) {
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 :
207bool 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
244 return alpha ;
245}
246const Valeur& Map_eps::get_beta() const {
247 return beta ;
248}
249
250 //------------//
251 // Sauvegarde //
252 //------------//
253
254void 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
267ostream & 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
314void 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
331void Map_eps::set_alpha(const Valeur& alpha0) {
332
333 alpha = alpha0 ;
334 alpha.std_base_scal() ;
335
336 reset_coord() ;
337
338}
339
340void Map_eps::set_beta(const Valeur& beta0) {
341
342 beta = beta0 ;
343 beta.std_base_scal() ;
344
345 reset_coord() ;
346
347}
348
349void 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}
3D grid class in one domain.
Definition grilles.h:200
double * phi
Array of values of at the np collocation points.
Definition grilles.h:219
double * tet
Array of values of at the nt collocation points.
Definition grilles.h:217
Affine radial mapping.
Definition map.h:2042
Map_eps(const Mg3d &mgrille, const double *r_limits)
Standard Constructor.
Definition map_eps.C:52
virtual void sauve(FILE *) const
Save in a file.
Definition map_eps.C:254
virtual ~Map_eps()
Destructor.
Definition map_eps.C:134
void set_alpha(const Tbl &alpha0, int l)
Modifies the value of in domain no. l.
Definition map_eps.C:314
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.
const Valeur & get_alpha() const
Returns the reference on the Tbl alpha.
Definition map_eps.C:243
friend Mtbl * map_eps_fait_r(const Map *)
< Not implemented
void set_coord()
Assignment of the building functions to the member Coords.
Definition map_eps.C:171
virtual void operator=(const Map_af &)
Assignment to an affine mapping.
Definition map_eps.C:161
virtual bool operator==(const Map &) const
Comparison operator (egality).
Definition map_eps.C:207
double aa
Array (size: mg->nzone*Nt*Np ) of the values of in each domain.
Definition map.h:4217
virtual ostream & operator>>(ostream &) const
Operator >>.
Definition map_eps.C:267
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
Values and coefficients of a (real-value) function.
Definition valeur.h:297
void std_base_scal()
Sets the bases for spectral expansions (member base ) to the standard ones for a scalar.
Definition valeur.C:827
Cmp sqrt(const Cmp &)
Square root.
Definition cmp_math.C:223
Cmp sin(const Cmp &)
Sine.
Definition cmp_math.C:72
Tbl max(const Cmp &)
Maximum values of a Cmp in each domain.
Definition cmp_math.C:438
Cmp pow(const Cmp &, int)
Power .
Definition cmp_math.C:351
Cmp cos(const Cmp &)
Cosine.
Definition cmp_math.C:97
Cmp abs(const Cmp &)
Absolute value.
Definition cmp_math.C:413
Base_vect_spher bvect_spher
Base class for coordinate mappings.
Definition map.h:701
void c_est_pas_fait(const char *)
Helpful function to say something is not implemented yet.
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
Standard units of space, time and mass.