| 1 |
/* |
| 2 |
* Member function of the Cmp class for initiating a Cmp from a Cmp defined |
| 3 |
* on another mapping. |
| 4 |
*/ |
| 5 |
|
| 6 |
/* |
| 7 |
* Copyright (c) 1999-2001 Eric Gourgoulhon |
| 8 |
* |
| 9 |
* This file is part of LORENE. |
| 10 |
* |
| 11 |
* LORENE is free software; you can redistribute it and/or modify |
| 12 |
* it under the terms of the GNU General Public License as published by |
| 13 |
* the Free Software Foundation; either version 2 of the License, or |
| 14 |
* (at your option) any later version. |
| 15 |
* |
| 16 |
* LORENE is distributed in the hope that it will be useful, |
| 17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 |
* GNU General Public License for more details. |
| 20 |
* |
| 21 |
* You should have received a copy of the GNU General Public License |
| 22 |
* along with LORENE; if not, write to the Free Software |
| 23 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 24 |
* |
| 25 |
*/ |
| 26 |
|
| 27 |
|
| 28 |
char cmp_import_C[] = "$Header: /cvsroot/Lorene/C++/Source/Cmp/cmp_import.C,v 1.3 2014/10/13 08:52:47 j_novak Exp $" ; |
| 29 |
|
| 30 |
/* |
| 31 |
* $Id: cmp_import.C,v 1.3 2014/10/13 08:52:47 j_novak Exp $ |
| 32 |
* $Log: cmp_import.C,v $ |
| 33 |
* Revision 1.3 2014/10/13 08:52:47 j_novak |
| 34 |
* Lorene classes and functions now belong to the namespace Lorene. |
| 35 |
* |
| 36 |
* Revision 1.2 2014/10/06 15:13:03 j_novak |
| 37 |
* Modified #include directives to use c++ syntax. |
| 38 |
* |
| 39 |
* Revision 1.1.1.1 2001/11/20 15:19:27 e_gourgoulhon |
| 40 |
* LORENE |
| 41 |
* |
| 42 |
* Revision 1.4 2000/02/28 16:46:42 eric |
| 43 |
* Version entierement refondue: utilisation de align. |
| 44 |
* |
| 45 |
* Revision 1.3 2000/02/07 12:32:39 eric |
| 46 |
* L'appel d'annule n'est effectue que si nzet < nz_a. |
| 47 |
* |
| 48 |
* Revision 1.2 1999/12/16 14:33:04 eric |
| 49 |
* L'argument precis de Map::val_lax est desormais un Param et non plus |
| 50 |
* un Tbl. |
| 51 |
* |
| 52 |
* Revision 1.1 1999/12/08 12:38:51 eric |
| 53 |
* Initial revision |
| 54 |
* |
| 55 |
* |
| 56 |
* $Header: /cvsroot/Lorene/C++/Source/Cmp/cmp_import.C,v 1.3 2014/10/13 08:52:47 j_novak Exp $ |
| 57 |
* |
| 58 |
*/ |
| 59 |
|
| 60 |
// Headers C |
| 61 |
#include <cmath> |
| 62 |
|
| 63 |
// Headers Lorene |
| 64 |
#include "cmp.h" |
| 65 |
#include "param.h" |
| 66 |
#include "nbr_spx.h" |
| 67 |
|
| 68 |
//-------------------------------// |
| 69 |
// Importation in all domains // |
| 70 |
//-------------------------------// |
| 71 |
|
| 72 |
namespace Lorene { |
| 73 |
void Cmp::import(const Cmp& ci) { |
| 74 |
|
| 75 |
int nz = mp->get_mg()->get_nzone() ; |
| 76 |
|
| 77 |
import(nz, ci) ; |
| 78 |
|
| 79 |
} |
| 80 |
|
| 81 |
//--------------------------------------// |
| 82 |
// Importation in inner domains only // |
| 83 |
//--------------------------------------// |
| 84 |
|
| 85 |
void Cmp::import(int nzet, const Cmp& cm_d) { |
| 86 |
|
| 87 |
const Map* mp_d = cm_d.mp ; // Departure mapping |
| 88 |
|
| 89 |
// Trivial case : mappings identical ! |
| 90 |
// ----------------------------------- |
| 91 |
|
| 92 |
if (mp_d == mp) { |
| 93 |
*this = cm_d ; |
| 94 |
return ; |
| 95 |
} |
| 96 |
|
| 97 |
// Relative orientation of the two mappings |
| 98 |
// ---------------------------------------- |
| 99 |
|
| 100 |
int align_rel = (mp->get_bvect_cart()).get_align() |
| 101 |
* (mp_d->get_bvect_cart()).get_align() ; |
| 102 |
|
| 103 |
switch (align_rel) { |
| 104 |
|
| 105 |
case 1 : { // the two mappings have aligned Cartesian axis |
| 106 |
import_align(nzet, cm_d) ; |
| 107 |
break ; |
| 108 |
} |
| 109 |
|
| 110 |
case -1 : { // the two mappings have anti-aligned Cartesian axis |
| 111 |
import_anti(nzet, cm_d) ; |
| 112 |
break ; |
| 113 |
} |
| 114 |
|
| 115 |
case 0 : { // general case |
| 116 |
import_gal(nzet, cm_d) ; |
| 117 |
break ; |
| 118 |
} |
| 119 |
|
| 120 |
default : { |
| 121 |
cout << "Cmp::import : unexpected value of align_rel : " |
| 122 |
<< align_rel << endl ; |
| 123 |
abort() ; |
| 124 |
break ; |
| 125 |
} |
| 126 |
|
| 127 |
} |
| 128 |
|
| 129 |
} |
| 130 |
|
| 131 |
//--------------------------------------// |
| 132 |
// General case (axis not aligned) // |
| 133 |
//--------------------------------------// |
| 134 |
|
| 135 |
|
| 136 |
void Cmp::import_gal(int nzet, const Cmp& cm_d) { |
| 137 |
|
| 138 |
const Map* mp_d = cm_d.mp ; // Departure mapping |
| 139 |
|
| 140 |
// Trivial case : mappings identical ! |
| 141 |
// ----------------------------------- |
| 142 |
|
| 143 |
if (mp_d == mp) { |
| 144 |
*this = cm_d ; |
| 145 |
return ; |
| 146 |
} |
| 147 |
|
| 148 |
// Another trivial case : null Cmp |
| 149 |
// ------------------------------- |
| 150 |
|
| 151 |
if (cm_d.etat == ETATZERO) { |
| 152 |
set_etat_zero() ; |
| 153 |
return ; |
| 154 |
} |
| 155 |
|
| 156 |
// Protections |
| 157 |
// ----------- |
| 158 |
|
| 159 |
assert(cm_d.etat != ETATNONDEF) ; |
| 160 |
|
| 161 |
if (cm_d.dzpuis != 0) { |
| 162 |
cout << |
| 163 |
"Cmp::import : the dzpuis of the Cmp to be imported must be zero !" |
| 164 |
<< endl ; |
| 165 |
abort() ; |
| 166 |
} |
| 167 |
|
| 168 |
|
| 169 |
const Mg3d* mg_a = mp->get_mg() ; |
| 170 |
int nz_a = mg_a->get_nzone() ; |
| 171 |
assert(nzet <= nz_a) ; |
| 172 |
|
| 173 |
|
| 174 |
// General case : |
| 175 |
// ------------- |
| 176 |
assert(cm_d.etat == ETATQCQ) ; |
| 177 |
const Valeur& va_d = cm_d.va ; |
| 178 |
va_d.coef() ; // The coefficients are required |
| 179 |
|
| 180 |
|
| 181 |
// Preparations for storing the result in *this |
| 182 |
// -------------------------------------------- |
| 183 |
del_t() ; // delete all previously computed derived quantities |
| 184 |
|
| 185 |
set_etat_qcq() ; // Set the state to ETATQCQ |
| 186 |
|
| 187 |
va.set_etat_c_qcq() ; // Allocates the memory for the Mtbl va.c |
| 188 |
// if it does not exist already |
| 189 |
va.c->set_etat_qcq() ; // Allocates the memory for the Tbl's in each |
| 190 |
// domain if they do not exist already |
| 191 |
|
| 192 |
|
| 193 |
// Absolute coordinates of the origin of the Departure mapping |
| 194 |
double xo_d = mp_d->get_ori_x() ; |
| 195 |
double yo_d = mp_d->get_ori_y() ; |
| 196 |
double zo_d = mp_d->get_ori_z() ; |
| 197 |
|
| 198 |
// Orientation relative to the Absolute frame of the Departure mapping |
| 199 |
double rot_phi_d = mp_d->get_rot_phi() ; |
| 200 |
|
| 201 |
// Orientation relative to the Absolute frame of the Arrival mapping |
| 202 |
double rot_phi_a = mp->get_rot_phi() ; |
| 203 |
|
| 204 |
// r, theta, phi, X, Y and Z on the Arrival mapping |
| 205 |
// update of the corresponding Coord's if necessary |
| 206 |
|
| 207 |
if ( (mp->r).c == 0x0 ) (mp->r).fait() ; |
| 208 |
if ( (mp->tet).c == 0x0 ) (mp->tet).fait() ; |
| 209 |
if ( (mp->phi).c == 0x0 ) (mp->phi).fait() ; |
| 210 |
if ( (mp->xa).c == 0x0 ) (mp->xa).fait() ; |
| 211 |
if ( (mp->ya).c == 0x0 ) (mp->ya).fait() ; |
| 212 |
if ( (mp->za).c == 0x0 ) (mp->za).fait() ; |
| 213 |
|
| 214 |
const Mtbl* mr_a = (mp->r).c ; |
| 215 |
const Mtbl* mtet_a = (mp->tet).c ; |
| 216 |
const Mtbl* mphi_a = (mp->phi).c ; |
| 217 |
const Mtbl* mxa_a = (mp->xa).c ; |
| 218 |
const Mtbl* mya_a = (mp->ya).c ; |
| 219 |
const Mtbl* mza_a = (mp->za).c ; |
| 220 |
|
| 221 |
Param par_precis ; // Required precision in the method Map::val_lx |
| 222 |
int nitermax = 100 ; // Maximum number of iteration in the secant method |
| 223 |
int niter ; |
| 224 |
double precis = 1e-15 ; // Absolute precision in the secant method |
| 225 |
par_precis.add_int(nitermax) ; |
| 226 |
par_precis.add_int_mod(niter) ; |
| 227 |
par_precis.add_double(precis) ; |
| 228 |
|
| 229 |
|
| 230 |
// Loop of the Arrival domains where the computation is to be performed |
| 231 |
// -------------------------------------------------------------------- |
| 232 |
|
| 233 |
for (int l=0; l < nzet; l++) { |
| 234 |
|
| 235 |
int nr = mg_a->get_nr(l) ; |
| 236 |
int nt = mg_a->get_nt(l) ; |
| 237 |
int np = mg_a->get_np(l) ; |
| 238 |
|
| 239 |
|
| 240 |
const double* pr_a = mr_a->t[l]->t ; // Pointer on the values of r |
| 241 |
const double* ptet_a = mtet_a->t[l]->t ; // Pointer on the values of theta |
| 242 |
const double* pphi_a = mphi_a->t[l]->t ; // Pointer on the values of phi |
| 243 |
const double* pxa_a = mxa_a->t[l]->t ; // Pointer on the values of X |
| 244 |
const double* pya_a = mya_a->t[l]->t ; // Pointer on the values of Y |
| 245 |
const double* pza_a = mza_a->t[l]->t ; // Pointer on the values of Z |
| 246 |
|
| 247 |
(va.c->t[l])->set_etat_qcq() ; // Allocates the array of double to |
| 248 |
// store the result |
| 249 |
double* ptx = (va.c->t[l])->t ; // Pointer on the allocated array |
| 250 |
|
| 251 |
|
| 252 |
// Loop on all the grid points in the considered arrival domain: |
| 253 |
|
| 254 |
for (int k=0 ; k<np ; k++) { |
| 255 |
for (int j=0 ; j<nt ; j++) { |
| 256 |
for (int i=0 ; i<nr ; i++) { |
| 257 |
|
| 258 |
double r = *pr_a ; |
| 259 |
double rd, tetd, phid ; |
| 260 |
if (r == __infinity) { |
| 261 |
rd = r ; |
| 262 |
tetd = *ptet_a ; |
| 263 |
phid = *pphi_a + rot_phi_a - rot_phi_d ; |
| 264 |
if (phid < 0) phid += 2*M_PI ; |
| 265 |
} |
| 266 |
else { |
| 267 |
// Coordinates in a Cartesian frame centered on |
| 268 |
// the Departure mapping and whose axes are |
| 269 |
// parallel to those of the Absolue Frame |
| 270 |
double xd = *pxa_a - xo_d ; |
| 271 |
double yd = *pya_a - yo_d ; |
| 272 |
double zd = *pza_a - zo_d ; |
| 273 |
|
| 274 |
// Spherical coordinates on the Departure mapping |
| 275 |
double rhod2 = xd*xd + yd*yd ; |
| 276 |
double rhod = sqrt( rhod2 ) ; |
| 277 |
rd = sqrt(rhod2 + zd*zd) ; |
| 278 |
tetd = atan2(rhod, zd) ; |
| 279 |
phid = atan2(yd, xd) - rot_phi_d ; // (rotation) |
| 280 |
if (phid < 0) phid += 2*M_PI ; |
| 281 |
} |
| 282 |
|
| 283 |
|
| 284 |
// NB: to increase the efficiency, the method Cmp::val_point |
| 285 |
// is not invoked; the method Mtbl_cf::val_point is |
| 286 |
// called directly instead. |
| 287 |
|
| 288 |
// Value of the grid coordinates (l,xi) corresponding to |
| 289 |
// (rd,tetd,phid) : |
| 290 |
|
| 291 |
int ld ; // domain index |
| 292 |
double xxd ; // radial coordinate xi in [0,1] or [-1,1] |
| 293 |
mp_d->val_lx(rd, tetd, phid, par_precis, ld, xxd) ; |
| 294 |
|
| 295 |
// Value of the Departure Cmp at the obtained point: |
| 296 |
*ptx = va_d.c_cf->val_point(ld, xxd, tetd, phid) ; |
| 297 |
|
| 298 |
// Next point : |
| 299 |
ptx++ ; |
| 300 |
pr_a++ ; |
| 301 |
ptet_a++ ; |
| 302 |
pphi_a++ ; |
| 303 |
pxa_a++ ; |
| 304 |
pya_a++ ; |
| 305 |
pza_a++ ; |
| 306 |
|
| 307 |
} |
| 308 |
} |
| 309 |
} |
| 310 |
|
| 311 |
|
| 312 |
} // End of the loop on the Arrival domains |
| 313 |
|
| 314 |
// In the remaining domains, *this is set to zero: |
| 315 |
// ---------------------------------------------- |
| 316 |
|
| 317 |
if (nzet < nz_a) { |
| 318 |
annule(nzet, nz_a - 1) ; |
| 319 |
} |
| 320 |
|
| 321 |
// Treatment of dzpuis |
| 322 |
// ------------------- |
| 323 |
|
| 324 |
|
| 325 |
set_dzpuis(0) ; |
| 326 |
|
| 327 |
} |
| 328 |
|
| 329 |
|
| 330 |
//-----------------------------------------// |
| 331 |
// Case of Cartesian axis anti-aligned // |
| 332 |
//-----------------------------------------// |
| 333 |
|
| 334 |
|
| 335 |
void Cmp::import_anti(int nzet, const Cmp& cm_d) { |
| 336 |
|
| 337 |
// Trivial case : null Cmp |
| 338 |
// ------------------------ |
| 339 |
|
| 340 |
if (cm_d.etat == ETATZERO) { |
| 341 |
set_etat_zero() ; |
| 342 |
return ; |
| 343 |
} |
| 344 |
|
| 345 |
const Map* mp_d = cm_d.mp ; // Departure mapping |
| 346 |
|
| 347 |
// Protections |
| 348 |
// ----------- |
| 349 |
int align = (mp->get_bvect_cart()).get_align() ; |
| 350 |
|
| 351 |
assert( align * (mp_d->get_bvect_cart()).get_align() == -1 ) ; |
| 352 |
|
| 353 |
assert(cm_d.etat == ETATQCQ) ; |
| 354 |
|
| 355 |
if (cm_d.dzpuis != 0) { |
| 356 |
cout << |
| 357 |
"Cmp::import : the dzpuis of the Cmp to be imported must be zero !" |
| 358 |
<< endl ; |
| 359 |
abort() ; |
| 360 |
} |
| 361 |
|
| 362 |
|
| 363 |
const Mg3d* mg_a = mp->get_mg() ; |
| 364 |
int nz_a = mg_a->get_nzone() ; |
| 365 |
assert(nzet <= nz_a) ; |
| 366 |
|
| 367 |
const Valeur& va_d = cm_d.va ; |
| 368 |
va_d.coef() ; // The coefficients are required |
| 369 |
|
| 370 |
|
| 371 |
// Preparations for storing the result in *this |
| 372 |
// -------------------------------------------- |
| 373 |
del_t() ; // delete all previously computed derived quantities |
| 374 |
|
| 375 |
set_etat_qcq() ; // Set the state to ETATQCQ |
| 376 |
|
| 377 |
va.set_etat_c_qcq() ; // Allocates the memory for the Mtbl va.c |
| 378 |
// if it does not exist already |
| 379 |
va.c->set_etat_qcq() ; // Allocates the memory for the Tbl's in each |
| 380 |
// domain if they do not exist already |
| 381 |
|
| 382 |
|
| 383 |
// Departure (x,y,z) coordinates of the origin of the Arrival mapping : |
| 384 |
|
| 385 |
double xx_a, yy_a, zz_a ; |
| 386 |
if (align == 1) { |
| 387 |
xx_a = mp_d->get_ori_x() - mp->get_ori_x() ; |
| 388 |
yy_a = mp_d->get_ori_y() - mp->get_ori_y() ; |
| 389 |
} |
| 390 |
else { |
| 391 |
xx_a = mp->get_ori_x() - mp_d->get_ori_x() ; |
| 392 |
yy_a = mp->get_ori_y() - mp_d->get_ori_y() ; |
| 393 |
} |
| 394 |
zz_a = mp->get_ori_z() - mp_d->get_ori_z() ; |
| 395 |
|
| 396 |
|
| 397 |
// r, theta, phi, x, y and z on the Arrival mapping |
| 398 |
// update of the corresponding Coord's if necessary |
| 399 |
|
| 400 |
if ( (mp->r).c == 0x0 ) (mp->r).fait() ; |
| 401 |
if ( (mp->tet).c == 0x0 ) (mp->tet).fait() ; |
| 402 |
if ( (mp->phi).c == 0x0 ) (mp->phi).fait() ; |
| 403 |
if ( (mp->x).c == 0x0 ) (mp->x).fait() ; |
| 404 |
if ( (mp->y).c == 0x0 ) (mp->y).fait() ; |
| 405 |
if ( (mp->z).c == 0x0 ) (mp->z).fait() ; |
| 406 |
|
| 407 |
const Mtbl* mr_a = (mp->r).c ; |
| 408 |
const Mtbl* mtet_a = (mp->tet).c ; |
| 409 |
const Mtbl* mphi_a = (mp->phi).c ; |
| 410 |
const Mtbl* mx_a = (mp->x).c ; |
| 411 |
const Mtbl* my_a = (mp->y).c ; |
| 412 |
const Mtbl* mz_a = (mp->z).c ; |
| 413 |
|
| 414 |
Param par_precis ; // Required precision in the method Map::val_lx |
| 415 |
int nitermax = 100 ; // Maximum number of iteration in the secant method |
| 416 |
int niter ; |
| 417 |
double precis = 1e-15 ; // Absolute precision in the secant method |
| 418 |
par_precis.add_int(nitermax) ; |
| 419 |
par_precis.add_int_mod(niter) ; |
| 420 |
par_precis.add_double(precis) ; |
| 421 |
|
| 422 |
|
| 423 |
// Loop of the Arrival domains where the computation is to be performed |
| 424 |
// -------------------------------------------------------------------- |
| 425 |
|
| 426 |
for (int l=0; l < nzet; l++) { |
| 427 |
|
| 428 |
int nr = mg_a->get_nr(l) ; |
| 429 |
int nt = mg_a->get_nt(l) ; |
| 430 |
int np = mg_a->get_np(l) ; |
| 431 |
|
| 432 |
|
| 433 |
const double* pr_a = mr_a->t[l]->t ; // Pointer on the values of r |
| 434 |
const double* ptet_a = mtet_a->t[l]->t ; // Pointer on the values of theta |
| 435 |
const double* pphi_a = mphi_a->t[l]->t ; // Pointer on the values of phi |
| 436 |
const double* px_a = mx_a->t[l]->t ; // Pointer on the values of X |
| 437 |
const double* py_a = my_a->t[l]->t ; // Pointer on the values of Y |
| 438 |
const double* pz_a = mz_a->t[l]->t ; // Pointer on the values of Z |
| 439 |
|
| 440 |
(va.c->t[l])->set_etat_qcq() ; // Allocates the array of double to |
| 441 |
// store the result |
| 442 |
double* ptx = (va.c->t[l])->t ; // Pointer on the allocated array |
| 443 |
|
| 444 |
|
| 445 |
// Loop on all the grid points in the considered arrival domain: |
| 446 |
|
| 447 |
for (int k=0 ; k<np ; k++) { |
| 448 |
for (int j=0 ; j<nt ; j++) { |
| 449 |
for (int i=0 ; i<nr ; i++) { |
| 450 |
|
| 451 |
double r = *pr_a ; |
| 452 |
double rd, tetd, phid ; |
| 453 |
if (r == __infinity) { |
| 454 |
rd = r ; |
| 455 |
tetd = *ptet_a ; |
| 456 |
phid = *pphi_a + M_PI ; |
| 457 |
if (phid < 0) phid += 2*M_PI ; |
| 458 |
} |
| 459 |
else { |
| 460 |
|
| 461 |
// Cartesian coordinates on the Departure mapping |
| 462 |
double xd = - *px_a + xx_a ; |
| 463 |
double yd = - *py_a + yy_a ; |
| 464 |
double zd = *pz_a + zz_a ; |
| 465 |
|
| 466 |
// Spherical coordinates on the Departure mapping |
| 467 |
double rhod2 = xd*xd + yd*yd ; |
| 468 |
double rhod = sqrt( rhod2 ) ; |
| 469 |
rd = sqrt(rhod2 + zd*zd) ; |
| 470 |
tetd = atan2(rhod, zd) ; |
| 471 |
phid = atan2(yd, xd) ; |
| 472 |
if (phid < 0) phid += 2*M_PI ; |
| 473 |
} |
| 474 |
|
| 475 |
|
| 476 |
// NB: to increase the efficiency, the method Cmp::val_point |
| 477 |
// is not invoked; the method Mtbl_cf::val_point is |
| 478 |
// called directly instead. |
| 479 |
|
| 480 |
// Value of the grid coordinates (l,xi) corresponding to |
| 481 |
// (rd,tetd,phid) : |
| 482 |
|
| 483 |
int ld ; // domain index |
| 484 |
double xxd ; // radial coordinate xi in [0,1] or [-1,1] |
| 485 |
mp_d->val_lx(rd, tetd, phid, par_precis, ld, xxd) ; |
| 486 |
|
| 487 |
// Value of the Departure Cmp at the obtained point: |
| 488 |
*ptx = va_d.c_cf->val_point(ld, xxd, tetd, phid) ; |
| 489 |
|
| 490 |
// Next point : |
| 491 |
ptx++ ; |
| 492 |
pr_a++ ; |
| 493 |
ptet_a++ ; |
| 494 |
pphi_a++ ; |
| 495 |
px_a++ ; |
| 496 |
py_a++ ; |
| 497 |
pz_a++ ; |
| 498 |
|
| 499 |
} |
| 500 |
} |
| 501 |
} |
| 502 |
|
| 503 |
|
| 504 |
} // End of the loop on the Arrival domains |
| 505 |
|
| 506 |
// In the remaining domains, *this is set to zero: |
| 507 |
// ---------------------------------------------- |
| 508 |
|
| 509 |
if (nzet < nz_a) { |
| 510 |
annule(nzet, nz_a - 1) ; |
| 511 |
} |
| 512 |
|
| 513 |
// Treatment of dzpuis |
| 514 |
// ------------------- |
| 515 |
|
| 516 |
|
| 517 |
set_dzpuis(0) ; |
| 518 |
|
| 519 |
} |
| 520 |
|
| 521 |
|
| 522 |
//-------------------------------------// |
| 523 |
// Case of aligned Cartesian axis // |
| 524 |
//-------------------------------------// |
| 525 |
|
| 526 |
|
| 527 |
void Cmp::import_align(int nzet, const Cmp& cm_d) { |
| 528 |
|
| 529 |
// Trivial case : null Cmp |
| 530 |
// ------------------------ |
| 531 |
|
| 532 |
if (cm_d.etat == ETATZERO) { |
| 533 |
set_etat_zero() ; |
| 534 |
return ; |
| 535 |
} |
| 536 |
|
| 537 |
const Map* mp_d = cm_d.mp ; // Departure mapping |
| 538 |
|
| 539 |
// Protections |
| 540 |
// ----------- |
| 541 |
int align = (mp->get_bvect_cart()).get_align() ; |
| 542 |
|
| 543 |
assert( align * (mp_d->get_bvect_cart()).get_align() == 1 ) ; |
| 544 |
|
| 545 |
assert(cm_d.etat == ETATQCQ) ; |
| 546 |
|
| 547 |
if (cm_d.dzpuis != 0) { |
| 548 |
cout << |
| 549 |
"Cmp::import : the dzpuis of the Cmp to be imported must be zero !" |
| 550 |
<< endl ; |
| 551 |
abort() ; |
| 552 |
} |
| 553 |
|
| 554 |
|
| 555 |
const Mg3d* mg_a = mp->get_mg() ; |
| 556 |
int nz_a = mg_a->get_nzone() ; |
| 557 |
assert(nzet <= nz_a) ; |
| 558 |
|
| 559 |
const Valeur& va_d = cm_d.va ; |
| 560 |
va_d.coef() ; // The coefficients are required |
| 561 |
|
| 562 |
|
| 563 |
// Preparations for storing the result in *this |
| 564 |
// -------------------------------------------- |
| 565 |
del_t() ; // delete all previously computed derived quantities |
| 566 |
|
| 567 |
set_etat_qcq() ; // Set the state to ETATQCQ |
| 568 |
|
| 569 |
va.set_etat_c_qcq() ; // Allocates the memory for the Mtbl va.c |
| 570 |
// if it does not exist already |
| 571 |
va.c->set_etat_qcq() ; // Allocates the memory for the Tbl's in each |
| 572 |
// domain if they do not exist already |
| 573 |
|
| 574 |
|
| 575 |
// Departure (x,y,z) coordinates of the origin of the Arrival mapping : |
| 576 |
|
| 577 |
double xx_a, yy_a, zz_a ; |
| 578 |
if (align == 1) { |
| 579 |
xx_a = mp->get_ori_x() - mp_d->get_ori_x() ; |
| 580 |
yy_a = mp->get_ori_y() - mp_d->get_ori_y() ; |
| 581 |
} |
| 582 |
else { |
| 583 |
xx_a = mp_d->get_ori_x() - mp->get_ori_x() ; |
| 584 |
yy_a = mp_d->get_ori_y() - mp->get_ori_y() ; |
| 585 |
} |
| 586 |
zz_a = mp->get_ori_z() - mp_d->get_ori_z() ; |
| 587 |
|
| 588 |
|
| 589 |
// r, theta, phi, x, y and z on the Arrival mapping |
| 590 |
// update of the corresponding Coord's if necessary |
| 591 |
|
| 592 |
if ( (mp->r).c == 0x0 ) (mp->r).fait() ; |
| 593 |
if ( (mp->tet).c == 0x0 ) (mp->tet).fait() ; |
| 594 |
if ( (mp->phi).c == 0x0 ) (mp->phi).fait() ; |
| 595 |
if ( (mp->x).c == 0x0 ) (mp->x).fait() ; |
| 596 |
if ( (mp->y).c == 0x0 ) (mp->y).fait() ; |
| 597 |
if ( (mp->z).c == 0x0 ) (mp->z).fait() ; |
| 598 |
|
| 599 |
const Mtbl* mr_a = (mp->r).c ; |
| 600 |
const Mtbl* mtet_a = (mp->tet).c ; |
| 601 |
const Mtbl* mphi_a = (mp->phi).c ; |
| 602 |
const Mtbl* mx_a = (mp->x).c ; |
| 603 |
const Mtbl* my_a = (mp->y).c ; |
| 604 |
const Mtbl* mz_a = (mp->z).c ; |
| 605 |
|
| 606 |
Param par_precis ; // Required precision in the method Map::val_lx |
| 607 |
int nitermax = 100 ; // Maximum number of iteration in the secant method |
| 608 |
int niter ; |
| 609 |
double precis = 1e-15 ; // Absolute precision in the secant method |
| 610 |
par_precis.add_int(nitermax) ; |
| 611 |
par_precis.add_int_mod(niter) ; |
| 612 |
par_precis.add_double(precis) ; |
| 613 |
|
| 614 |
|
| 615 |
// Loop of the Arrival domains where the computation is to be performed |
| 616 |
// -------------------------------------------------------------------- |
| 617 |
|
| 618 |
for (int l=0; l < nzet; l++) { |
| 619 |
|
| 620 |
int nr = mg_a->get_nr(l) ; |
| 621 |
int nt = mg_a->get_nt(l) ; |
| 622 |
int np = mg_a->get_np(l) ; |
| 623 |
|
| 624 |
|
| 625 |
const double* pr_a = mr_a->t[l]->t ; // Pointer on the values of r |
| 626 |
const double* ptet_a = mtet_a->t[l]->t ; // Pointer on the values of theta |
| 627 |
const double* pphi_a = mphi_a->t[l]->t ; // Pointer on the values of phi |
| 628 |
const double* px_a = mx_a->t[l]->t ; // Pointer on the values of X |
| 629 |
const double* py_a = my_a->t[l]->t ; // Pointer on the values of Y |
| 630 |
const double* pz_a = mz_a->t[l]->t ; // Pointer on the values of Z |
| 631 |
|
| 632 |
(va.c->t[l])->set_etat_qcq() ; // Allocates the array of double to |
| 633 |
// store the result |
| 634 |
double* ptx = (va.c->t[l])->t ; // Pointer on the allocated array |
| 635 |
|
| 636 |
|
| 637 |
// Loop on all the grid points in the considered arrival domain: |
| 638 |
|
| 639 |
for (int k=0 ; k<np ; k++) { |
| 640 |
for (int j=0 ; j<nt ; j++) { |
| 641 |
for (int i=0 ; i<nr ; i++) { |
| 642 |
|
| 643 |
double r = *pr_a ; |
| 644 |
double rd, tetd, phid ; |
| 645 |
if (r == __infinity) { |
| 646 |
rd = r ; |
| 647 |
tetd = *ptet_a ; |
| 648 |
phid = *pphi_a ; |
| 649 |
} |
| 650 |
else { |
| 651 |
|
| 652 |
// Cartesian coordinates on the Departure mapping |
| 653 |
double xd = *px_a + xx_a ; |
| 654 |
double yd = *py_a + yy_a ; |
| 655 |
double zd = *pz_a + zz_a ; |
| 656 |
|
| 657 |
// Spherical coordinates on the Departure mapping |
| 658 |
double rhod2 = xd*xd + yd*yd ; |
| 659 |
double rhod = sqrt( rhod2 ) ; |
| 660 |
rd = sqrt(rhod2 + zd*zd) ; |
| 661 |
tetd = atan2(rhod, zd) ; |
| 662 |
phid = atan2(yd, xd) ; |
| 663 |
if (phid < 0) phid += 2*M_PI ; |
| 664 |
} |
| 665 |
|
| 666 |
|
| 667 |
// NB: to increase the efficiency, the method Cmp::val_point |
| 668 |
// is not invoked; the method Mtbl_cf::val_point is |
| 669 |
// called directly instead. |
| 670 |
|
| 671 |
// Value of the grid coordinates (l,xi) corresponding to |
| 672 |
// (rd,tetd,phid) : |
| 673 |
|
| 674 |
int ld ; // domain index |
| 675 |
double xxd ; // radial coordinate xi in [0,1] or [-1,1] |
| 676 |
mp_d->val_lx(rd, tetd, phid, par_precis, ld, xxd) ; |
| 677 |
|
| 678 |
// Value of the Departure Cmp at the obtained point: |
| 679 |
*ptx = va_d.c_cf->val_point(ld, xxd, tetd, phid) ; |
| 680 |
|
| 681 |
// Next point : |
| 682 |
ptx++ ; |
| 683 |
pr_a++ ; |
| 684 |
ptet_a++ ; |
| 685 |
pphi_a++ ; |
| 686 |
px_a++ ; |
| 687 |
py_a++ ; |
| 688 |
pz_a++ ; |
| 689 |
|
| 690 |
} |
| 691 |
} |
| 692 |
} |
| 693 |
|
| 694 |
|
| 695 |
} // End of the loop on the Arrival domains |
| 696 |
|
| 697 |
// In the remaining domains, *this is set to zero: |
| 698 |
// ---------------------------------------------- |
| 699 |
|
| 700 |
if (nzet < nz_a) { |
| 701 |
annule(nzet, nz_a - 1) ; |
| 702 |
} |
| 703 |
|
| 704 |
// Treatment of dzpuis |
| 705 |
// ------------------- |
| 706 |
|
| 707 |
|
| 708 |
set_dzpuis(0) ; |
| 709 |
|
| 710 |
} |
| 711 |
} |