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// -----------------------
51namespace Lorene {
52Map_star::Map_star(const Mg3d& mgrille, const double* bornes) : 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// -----------------------
59Map_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// ----------------
109Map_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// ---------------------
118Map_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
131
132 //-------------//
133 // Assignement //
134 //-------------//
135
136// From another Map_star
137// -------------------
138
139void 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
155void Map_star::operator=(const Map_af & mpi) {
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 :
201bool 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
238 return alpha ;
239}
240const Valeur& Map_star::get_beta() const {
241 return beta ;
242}
243
244 //------------//
245 // Sauvegarde //
246 //------------//
247
248void 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
261ostream & 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
307void 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
324void Map_star::set_beta(const Tbl& beta0, int l) {
325
326 assert(l>=0) ;
327 assert(l<mg->get_nzone()) ;
328
329 int Nt = mg->get_nt(l) ;
330 int Np = mg->get_np(l) ;
331 for (int k=0; k<Np; k++)
332 for (int j=0; j<Nt; j++){
333 beta.set(l, k, j, 0) = beta0(k,j) ; // beta0 must represent the values of the radius.
334 }
335 reset_coord() ;
336
337}
338
339
340
341}
Affine radial mapping.
Definition map.h:2042
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
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_star.C:237
void set_alpha(const Tbl &alpha0, int l)
Modifies the value of in domain no. l.
Definition map_star.C:307
virtual void sauve(FILE *) const
Save in a file.
Definition map_star.C:248
Map_star(const Mg3d &mgrille, const double *r_limits)
Standard Constructor.
Definition map_star.C:52
friend Mtbl * map_star_fait_r(const Map *)
< Not implemented
virtual ostream & operator>>(ostream &) const
Operator >>.
Definition map_star.C:261
virtual void operator=(const Map_af &)
Assignment to an affine mapping.
Definition map_star.C:155
Valeur alpha
Array (size: mg->nzone*Nt*Np ) of the values of in each domain.
Definition map.h:3924
void set_coord()
Assignment of the building functions to the member Coords.
Definition map_star.C:165
virtual ~Map_star()
Destructor.
Definition map_star.C:128
virtual bool operator==(const Map &) const
Comparison operator (egality).
Definition map_star.C:201
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
Tbl & set(int l)
Read/write of the value in a given domain (configuration space).
Definition valeur.h:373
Tbl max(const Cmp &)
Maximum values of a Cmp in each domain.
Definition cmp_math.C:438
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.