| 1 |
/* |
| 2 |
* Methods of class Cmp |
| 3 |
* |
| 4 |
* (see file cmp.h for documentation) |
| 5 |
* |
| 6 |
*/ |
| 7 |
|
| 8 |
/* |
| 9 |
* Copyright (c) 1999-2000 Jean-Alain Marck |
| 10 |
* Copyright (c) 1999-2001 Eric Gourgoulhon |
| 11 |
* Copyright (c) 1999-2001 Philippe Grandclement |
| 12 |
* |
| 13 |
* This file is part of LORENE. |
| 14 |
* |
| 15 |
* LORENE is free software; you can redistribute it and/or modify |
| 16 |
* it under the terms of the GNU General Public License as published by |
| 17 |
* the Free Software Foundation; either version 2 of the License, or |
| 18 |
* (at your option) any later version. |
| 19 |
* |
| 20 |
* LORENE is distributed in the hope that it will be useful, |
| 21 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 |
* GNU General Public License for more details. |
| 24 |
* |
| 25 |
* You should have received a copy of the GNU General Public License |
| 26 |
* along with LORENE; if not, write to the Free Software |
| 27 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 28 |
* |
| 29 |
*/ |
| 30 |
|
| 31 |
|
| 32 |
char cmp_C[] = "$Header: /cvsroot/Lorene/C++/Source/Cmp/cmp.C,v 1.10 2014/10/13 08:52:46 j_novak Exp $" ; |
| 33 |
|
| 34 |
|
| 35 |
/* |
| 36 |
* $Id: cmp.C,v 1.10 2014/10/13 08:52:46 j_novak Exp $ |
| 37 |
* $Log: cmp.C,v $ |
| 38 |
* Revision 1.10 2014/10/13 08:52:46 j_novak |
| 39 |
* Lorene classes and functions now belong to the namespace Lorene. |
| 40 |
* |
| 41 |
* Revision 1.9 2014/10/06 15:13:03 j_novak |
| 42 |
* Modified #include directives to use c++ syntax. |
| 43 |
* |
| 44 |
* Revision 1.8 2004/10/11 15:09:01 j_novak |
| 45 |
* The radial manipulation functions take Scalar as arguments, instead of Cmp. |
| 46 |
* Added a conversion operator from Scalar to Cmp. |
| 47 |
* The Cmp radial manipulation function make conversion to Scalar, call to the |
| 48 |
* Map_radial version with a Scalar argument and back. |
| 49 |
* |
| 50 |
* Revision 1.7 2003/10/16 21:39:02 e_gourgoulhon |
| 51 |
* Treated the case ETATUN in the constructor from Scalar. |
| 52 |
* |
| 53 |
* Revision 1.6 2003/10/01 15:49:33 e_gourgoulhon |
| 54 |
* Method Scalar::get_mp() now returns a reference onto a mapping. |
| 55 |
* |
| 56 |
* Revision 1.5 2003/09/24 20:54:24 e_gourgoulhon |
| 57 |
* Added constructor by conversion of a Scalar. |
| 58 |
* |
| 59 |
* Revision 1.4 2003/08/26 09:46:10 j_novak |
| 60 |
* Added the method multipole_spectrum |
| 61 |
* |
| 62 |
* Revision 1.3 2002/10/16 14:36:33 j_novak |
| 63 |
* Reorganization of #include instructions of standard C++, in order to |
| 64 |
* use experimental version 3 of gcc. |
| 65 |
* |
| 66 |
* Revision 1.2 2001/12/04 21:27:53 e_gourgoulhon |
| 67 |
* |
| 68 |
* All writing/reading to a binary file are now performed according to |
| 69 |
* the big endian convention, whatever the system is big endian or |
| 70 |
* small endian, thanks to the functions fwrite_be and fread_be |
| 71 |
* |
| 72 |
* Revision 1.1.1.1 2001/11/20 15:19:27 e_gourgoulhon |
| 73 |
* LORENE |
| 74 |
* |
| 75 |
* Revision 2.36 2000/09/13 12:11:56 eric |
| 76 |
* Ajout de la fonction allocate_all(). |
| 77 |
* |
| 78 |
* Revision 2.35 2000/09/06 09:45:23 keisuke |
| 79 |
* Ajout de l'appel a del_deriv() dans set_etat_qcq() pour le cas |
| 80 |
* ou etat est deja ETATQCQ. |
| 81 |
* |
| 82 |
* Revision 2.34 2000/08/16 10:43:30 eric |
| 83 |
* Suppression de Mtbl_cf::dzpuis. |
| 84 |
* |
| 85 |
* Revision 2.33 2000/08/16 10:30:41 eric |
| 86 |
* Suppression de Mtbl::dzpuis. |
| 87 |
* |
| 88 |
* Revision 2.32 2000/03/07 16:52:58 eric |
| 89 |
* Modif dz_nonzero() : cas etat=ETATQCQ et va.etat=ETATZERO. |
| 90 |
* |
| 91 |
* Revision 2.31 2000/01/28 16:09:21 eric |
| 92 |
* Ajout des fonctions dz_nonzero et check_dzpuis. |
| 93 |
* |
| 94 |
* Revision 2.30 1999/12/22 16:44:28 eric |
| 95 |
* set_etat_zero() : remplacement de l'appel a del_t() par |
| 96 |
* 1/ va.set_etat_zero() ; |
| 97 |
* 2/ del_deriv() ; |
| 98 |
* |
| 99 |
* Revision 2.29 1999/12/10 15:59:14 eric |
| 100 |
* Changement de la place de del_deriv() dans l'affectation |
| 101 |
* (pour permettre l'affectation a des membres derives). |
| 102 |
* Annulation des membres derives. |
| 103 |
* dans la fonction annule(int,int). |
| 104 |
* |
| 105 |
* Revision 2.28 1999/12/09 10:50:01 eric |
| 106 |
* Ajout du membre p_integ. |
| 107 |
* |
| 108 |
* Revision 2.27 1999/12/07 14:53:32 eric |
| 109 |
* Changement ordre des arguments (phi,theta,r) --> (r,theta,phi) |
| 110 |
* dans la routine val_point. |
| 111 |
* |
| 112 |
* Revision 2.26 1999/12/06 16:47:11 eric |
| 113 |
* Ajout de la fonction val_point. |
| 114 |
* |
| 115 |
* Revision 2.25 1999/11/30 16:30:23 eric |
| 116 |
* *** empty log message *** |
| 117 |
* |
| 118 |
* Revision 2.24 1999/11/30 16:26:39 eric |
| 119 |
* Ajout (provisoire) de l'affectation des dzpuis des Mtbl et Mtbl_cf |
| 120 |
* dans set_dzpuis. |
| 121 |
* |
| 122 |
* Revision 2.23 1999/11/29 15:14:48 phil |
| 123 |
* *** empty log message *** |
| 124 |
* |
| 125 |
* Revision 2.22 1999/11/29 12:56:49 eric |
| 126 |
* Introduction des membres p_lap, ind_lap. |
| 127 |
* |
| 128 |
* Revision 2.21 1999/11/26 14:23:17 eric |
| 129 |
* Ajout du membre dzpuis et des fonctions de manipulation associees. |
| 130 |
* |
| 131 |
* Revision 2.20 1999/11/25 16:27:45 eric |
| 132 |
* Reorganisation complete du calcul et stokage des derivees partielles. |
| 133 |
* |
| 134 |
* Revision 2.19 1999/11/23 16:21:02 eric |
| 135 |
* Suppression du membre statique Cmp_Zero. |
| 136 |
* Suppression du constructeur par defaut. |
| 137 |
* |
| 138 |
* Revision 2.18 1999/11/22 16:34:56 eric |
| 139 |
* Ajout du constructeur prive sans argument pour Cmp_Zero. |
| 140 |
* |
| 141 |
* Revision 2.17 1999/11/22 15:41:57 eric |
| 142 |
* Ajout de la fonction annule(int l). |
| 143 |
* |
| 144 |
* Revision 2.16 1999/10/29 08:14:59 eric |
| 145 |
* Ajout de assert( mpi.get_mg() == &mgi ) dans le constructeur |
| 146 |
* par lecture de fichier. |
| 147 |
* |
| 148 |
* Revision 2.15 1999/10/28 09:39:00 eric |
| 149 |
* Ajout de la fonction affiche_seuil. |
| 150 |
* |
| 151 |
* Revision 2.14 1999/10/28 09:01:56 eric |
| 152 |
* Constructeur par lecture de fichier. |
| 153 |
* Ajout de la fonction annule(int, int). |
| 154 |
* |
| 155 |
* Revision 2.13 1999/10/27 15:38:52 eric |
| 156 |
* Suppression du membre c. |
| 157 |
* |
| 158 |
* Revision 2.12 1999/10/27 09:51:46 eric |
| 159 |
* *** empty log message *** |
| 160 |
* |
| 161 |
* Revision 2.11 1999/10/27 08:45:31 eric |
| 162 |
* Introduction du membre Valeur va. |
| 163 |
* Le pointeur Valeur* c est desormais un membre prive constant qui pointe |
| 164 |
* |
| 165 |
* sur va. |
| 166 |
* |
| 167 |
* Revision 2.10 1999/10/22 08:14:32 eric |
| 168 |
* Depoussierage. |
| 169 |
* |
| 170 |
* Revision 2.9 1999/10/18 16:08:15 phil |
| 171 |
* Correction de set_etat_qcq |
| 172 |
* Evite les memory leak |
| 173 |
* |
| 174 |
* Revision 2.8 1999/10/18 15:07:58 eric |
| 175 |
* La fonction membre Valeur::annule() est rebaptisee Valeur::annule_hard(). |
| 176 |
* |
| 177 |
* Revision 2.7 1999/04/09 13:38:58 phil |
| 178 |
* *** empty log message *** |
| 179 |
* |
| 180 |
* Revision 2.6 1999/04/09 13:10:09 phil |
| 181 |
* ajout de cmp = valeur |
| 182 |
* |
| 183 |
* Revision 2.5 1999/03/03 11:16:24 hyc |
| 184 |
* *** empty log message *** |
| 185 |
* |
| 186 |
* |
| 187 |
* $Header: /cvsroot/Lorene/C++/Source/Cmp/cmp.C,v 1.10 2014/10/13 08:52:46 j_novak Exp $ |
| 188 |
* |
| 189 |
*/ |
| 190 |
|
| 191 |
// headers C |
| 192 |
#include <cassert> |
| 193 |
#include <cstdlib> |
| 194 |
#include <cmath> |
| 195 |
|
| 196 |
// headers Lorene |
| 197 |
#include "cmp.h" |
| 198 |
#include "type_parite.h" |
| 199 |
#include "utilitaires.h" |
| 200 |
#include "proto.h" |
| 201 |
|
| 202 |
//---------------// |
| 203 |
// Constructeurs // |
| 204 |
//---------------// |
| 205 |
|
| 206 |
|
| 207 |
namespace Lorene { |
| 208 |
Cmp::Cmp(const Map& mpi) : mp(&mpi), etat(ETATNONDEF), dzpuis(0), |
| 209 |
va(mpi.get_mg()) { |
| 210 |
|
| 211 |
set_der_0x0() ; |
| 212 |
|
| 213 |
} |
| 214 |
|
| 215 |
Cmp::Cmp(const Map* mpi) : mp(mpi), etat(ETATNONDEF), dzpuis(0), |
| 216 |
va(mpi->get_mg()) { |
| 217 |
|
| 218 |
set_der_0x0() ; |
| 219 |
|
| 220 |
} |
| 221 |
|
| 222 |
|
| 223 |
// Copy constructor |
| 224 |
// ---------------- |
| 225 |
Cmp::Cmp(const Cmp& ci) : mp(ci.mp), etat(ci.etat), dzpuis(ci.dzpuis), |
| 226 |
va(ci.va) { |
| 227 |
|
| 228 |
set_der_0x0() ; // On ne recopie pas les derivees |
| 229 |
|
| 230 |
} |
| 231 |
|
| 232 |
// From file |
| 233 |
// --------- |
| 234 |
Cmp::Cmp(const Map& mpi, const Mg3d& mgi, FILE* fd) : mp(&mpi), va(mgi, fd) { |
| 235 |
|
| 236 |
assert( mpi.get_mg() == &mgi ) ; |
| 237 |
|
| 238 |
fread_be(&etat, sizeof(int), 1, fd) ; // L'etat |
| 239 |
fread_be(&dzpuis, sizeof(int), 1, fd) ; // dzpuis |
| 240 |
|
| 241 |
set_der_0x0() ; // Les derivees sont initialisees a zero |
| 242 |
|
| 243 |
} |
| 244 |
|
| 245 |
//--------------// |
| 246 |
// Destructeur // |
| 247 |
//--------------// |
| 248 |
|
| 249 |
// Destructeur |
| 250 |
Cmp::~Cmp() { |
| 251 |
del_t() ; |
| 252 |
} |
| 253 |
|
| 254 |
//-----------------------// |
| 255 |
// Gestion de la memoire // |
| 256 |
//-----------------------// |
| 257 |
|
| 258 |
// Destructeur logique |
| 259 |
void Cmp::del_t() { |
| 260 |
va.del_t() ; |
| 261 |
del_deriv() ; |
| 262 |
etat = ETATNONDEF ; |
| 263 |
} |
| 264 |
|
| 265 |
void Cmp::del_deriv() { |
| 266 |
delete p_dsdr ; p_dsdr = 0x0 ; |
| 267 |
delete p_srdsdt ; p_srdsdt = 0x0 ; |
| 268 |
delete p_srstdsdp ; p_srstdsdp = 0x0 ; |
| 269 |
delete p_dsdx ; p_dsdx = 0x0 ; |
| 270 |
delete p_dsdy ; p_dsdy = 0x0 ; |
| 271 |
delete p_dsdz ; p_dsdz = 0x0 ; |
| 272 |
delete p_lap ; p_lap = 0x0 ; |
| 273 |
delete p_integ ; p_integ = 0x0 ; |
| 274 |
} |
| 275 |
|
| 276 |
void Cmp::set_der_0x0() { |
| 277 |
p_dsdr = 0x0 ; |
| 278 |
p_srdsdt = 0x0 ; |
| 279 |
p_srstdsdp = 0x0 ; |
| 280 |
p_dsdx = 0x0 ; |
| 281 |
p_dsdy = 0x0 ; |
| 282 |
p_dsdz = 0x0 ; |
| 283 |
p_lap = 0x0 ; |
| 284 |
ind_lap = - 1 ; |
| 285 |
p_integ = 0x0 ; |
| 286 |
} |
| 287 |
|
| 288 |
// ETATZERO |
| 289 |
void Cmp::set_etat_zero() { |
| 290 |
if (etat == ETATZERO) return ; |
| 291 |
del_deriv() ; |
| 292 |
va.set_etat_zero() ; |
| 293 |
etat = ETATZERO ; |
| 294 |
} |
| 295 |
|
| 296 |
// ETATNONDEF |
| 297 |
void Cmp::set_etat_nondef() { |
| 298 |
if (etat == ETATNONDEF) return ; |
| 299 |
del_t() ; |
| 300 |
etat = ETATNONDEF ; |
| 301 |
} |
| 302 |
|
| 303 |
// ETATQCQ |
| 304 |
void Cmp::set_etat_qcq() { |
| 305 |
|
| 306 |
if (etat == ETATQCQ) { |
| 307 |
del_deriv() ; |
| 308 |
return ; |
| 309 |
} |
| 310 |
|
| 311 |
// Protection |
| 312 |
assert( (etat == ETATZERO) || (etat == ETATNONDEF) ) ; // sinon... |
| 313 |
|
| 314 |
del_t() ; |
| 315 |
|
| 316 |
// Termine |
| 317 |
etat = ETATQCQ ; |
| 318 |
} |
| 319 |
|
| 320 |
|
| 321 |
// Allocates everything |
| 322 |
// -------------------- |
| 323 |
void Cmp::allocate_all() { |
| 324 |
|
| 325 |
set_etat_qcq() ; |
| 326 |
va.set_etat_c_qcq() ; // allocation in configuration space |
| 327 |
Mtbl* mt = va.c ; |
| 328 |
mt->set_etat_qcq() ; |
| 329 |
for (int l=0; l<mt->get_nzone(); l++) { |
| 330 |
mt->t[l]->set_etat_qcq() ; |
| 331 |
} |
| 332 |
|
| 333 |
} |
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
// ZERO hard |
| 338 |
void Cmp::annule_hard() { |
| 339 |
|
| 340 |
va.annule_hard() ; |
| 341 |
del_deriv() ; |
| 342 |
etat = ETATQCQ ; |
| 343 |
} |
| 344 |
|
| 345 |
// Sets the Cmp to zero in a given domain |
| 346 |
// -------------------------------------- |
| 347 |
|
| 348 |
void Cmp::annule(int l) { |
| 349 |
|
| 350 |
annule(l, l) ; |
| 351 |
} |
| 352 |
|
| 353 |
|
| 354 |
// Sets the Cmp to zero in several domains |
| 355 |
// --------------------------------------- |
| 356 |
|
| 357 |
void Cmp::annule(int l_min, int l_max) { |
| 358 |
|
| 359 |
// Cas particulier: annulation globale : |
| 360 |
if ( (l_min == 0) && (l_max == va.mg->get_nzone()-1) ) { |
| 361 |
set_etat_zero() ; |
| 362 |
return ; |
| 363 |
} |
| 364 |
|
| 365 |
assert( etat != ETATNONDEF ) ; |
| 366 |
|
| 367 |
if ( etat == ETATZERO ) { |
| 368 |
return ; // rien n'a faire si c'est deja zero |
| 369 |
} |
| 370 |
else { |
| 371 |
assert( etat == ETATQCQ ) ; // sinon... |
| 372 |
|
| 373 |
va.annule(l_min, l_max) ; // Annule la Valeur |
| 374 |
|
| 375 |
// Annulation des membres derives |
| 376 |
if (p_dsdr != 0x0) p_dsdr->annule(l_min, l_max) ; |
| 377 |
if (p_srdsdt != 0x0) p_srdsdt->annule(l_min, l_max) ; |
| 378 |
if (p_srstdsdp != 0x0) p_srstdsdp->annule(l_min, l_max) ; |
| 379 |
if (p_dsdx != 0x0) p_dsdx->annule(l_min, l_max) ; |
| 380 |
if (p_dsdy != 0x0) p_dsdy->annule(l_min, l_max) ; |
| 381 |
if (p_dsdz != 0x0) p_dsdz->annule(l_min, l_max) ; |
| 382 |
if (p_lap != 0x0) p_lap->annule(l_min, l_max) ; |
| 383 |
if (p_integ != 0x0) delete p_integ ; |
| 384 |
} |
| 385 |
|
| 386 |
} |
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
//------------// |
| 393 |
// Assignment // |
| 394 |
//------------// |
| 395 |
|
| 396 |
// From Cmp |
| 397 |
// -------- |
| 398 |
void Cmp::operator=(const Cmp& ci) { |
| 399 |
|
| 400 |
assert(&ci != this) ; // pour eviter l'auto-affectation |
| 401 |
|
| 402 |
// Menage general de la Valeur, mais pas des quantites derivees ! |
| 403 |
va.del_t() ; |
| 404 |
|
| 405 |
// Les elements fixes |
| 406 |
mp = ci.mp ; |
| 407 |
dzpuis = ci.dzpuis ; |
| 408 |
|
| 409 |
// La valeur eventuelle |
| 410 |
switch(ci.etat) { |
| 411 |
case ETATNONDEF: { |
| 412 |
set_etat_nondef() ; |
| 413 |
break ; // valeur par defaut |
| 414 |
} |
| 415 |
|
| 416 |
case ETATZERO: { |
| 417 |
set_etat_zero() ; |
| 418 |
break ; |
| 419 |
} |
| 420 |
|
| 421 |
case ETATQCQ: { |
| 422 |
set_etat_qcq() ; |
| 423 |
va = ci.va ; |
| 424 |
|
| 425 |
// On detruit les quantites derivees (seulement lorsque tout est fini !) |
| 426 |
del_deriv() ; |
| 427 |
|
| 428 |
break ; |
| 429 |
} |
| 430 |
|
| 431 |
default: { |
| 432 |
cout << "Unkwown state in Cmp::operator=(const Cmp&) !" |
| 433 |
<< endl ; |
| 434 |
abort() ; |
| 435 |
break ; |
| 436 |
} |
| 437 |
} |
| 438 |
|
| 439 |
} |
| 440 |
|
| 441 |
// From Valeur |
| 442 |
// ----------- |
| 443 |
void Cmp::operator=(const Valeur& vi) { |
| 444 |
|
| 445 |
// Traitement de l'auto-affectation : |
| 446 |
if (&vi == &va) { |
| 447 |
return ; |
| 448 |
} |
| 449 |
|
| 450 |
// Protection |
| 451 |
assert(vi.get_etat() != ETATNONDEF) ; |
| 452 |
|
| 453 |
// Menage general de la Valeur, mais pas des quantites derivees ! |
| 454 |
va.del_t() ; |
| 455 |
|
| 456 |
|
| 457 |
// La valeure eventuelle |
| 458 |
switch(vi.get_etat()) { |
| 459 |
|
| 460 |
case ETATZERO: { |
| 461 |
set_etat_zero() ; |
| 462 |
break ; |
| 463 |
} |
| 464 |
|
| 465 |
case ETATQCQ: { |
| 466 |
set_etat_qcq() ; |
| 467 |
va = vi ; |
| 468 |
|
| 469 |
// On detruit les quantites derivees (seulement lorsque tout est fini !) |
| 470 |
del_deriv() ; |
| 471 |
|
| 472 |
break ; |
| 473 |
} |
| 474 |
|
| 475 |
default: { |
| 476 |
cout << "Unkwown state in Cmp::operator=(const Valeur&) !" << endl ; |
| 477 |
abort() ; |
| 478 |
break ; |
| 479 |
} |
| 480 |
} |
| 481 |
|
| 482 |
} |
| 483 |
|
| 484 |
// From Mtbl |
| 485 |
// --------- |
| 486 |
void Cmp::operator=(const Mtbl& mi) { |
| 487 |
|
| 488 |
// Protection |
| 489 |
assert(mi.get_etat() != ETATNONDEF) ; |
| 490 |
|
| 491 |
assert(&mi != va.c) ; // pour eviter l'auto-affectation |
| 492 |
|
| 493 |
|
| 494 |
// Menage general de la Valeur, mais pas des quantites derivees ! |
| 495 |
va.del_t() ; |
| 496 |
|
| 497 |
// La valeure eventuelle |
| 498 |
switch(mi.get_etat()) { |
| 499 |
case ETATZERO: { |
| 500 |
set_etat_zero() ; |
| 501 |
break ; |
| 502 |
} |
| 503 |
|
| 504 |
case ETATQCQ: { |
| 505 |
set_etat_qcq() ; |
| 506 |
va = mi ; |
| 507 |
|
| 508 |
// On detruit les quantites derivees (seulement lorsque tout est fini !) |
| 509 |
del_deriv() ; |
| 510 |
|
| 511 |
break ; |
| 512 |
} |
| 513 |
|
| 514 |
default: { |
| 515 |
cout << "Unkwown state in Cmp::operator=(const Mtbl&) !" << endl ; |
| 516 |
abort() ; |
| 517 |
break ; |
| 518 |
} |
| 519 |
} |
| 520 |
|
| 521 |
|
| 522 |
} |
| 523 |
|
| 524 |
// From double |
| 525 |
// ----------- |
| 526 |
void Cmp::operator=(double x) { |
| 527 |
|
| 528 |
if (x == double(0)) { |
| 529 |
set_etat_zero() ; |
| 530 |
} |
| 531 |
else { |
| 532 |
set_etat_qcq() ; |
| 533 |
del_deriv() ; |
| 534 |
va = x ; |
| 535 |
} |
| 536 |
|
| 537 |
dzpuis = 0 ; |
| 538 |
} |
| 539 |
|
| 540 |
// From int |
| 541 |
// -------- |
| 542 |
void Cmp::operator=(int n) { |
| 543 |
|
| 544 |
if (n == 0) { |
| 545 |
set_etat_zero() ; |
| 546 |
} |
| 547 |
else { |
| 548 |
set_etat_qcq() ; |
| 549 |
del_deriv() ; |
| 550 |
va = n ; |
| 551 |
} |
| 552 |
|
| 553 |
dzpuis = 0 ; |
| 554 |
|
| 555 |
} |
| 556 |
|
| 557 |
//------------// |
| 558 |
// Sauvegarde // |
| 559 |
//------------// |
| 560 |
|
| 561 |
void Cmp::sauve(FILE* fd) const { |
| 562 |
|
| 563 |
va.sauve(fd) ; // la valeur (en premier pour la construction |
| 564 |
// lors de la lecture du fichier) |
| 565 |
|
| 566 |
fwrite_be(&etat, sizeof(int), 1, fd) ; // l'etat |
| 567 |
fwrite_be(&dzpuis, sizeof(int), 1, fd) ; // dzpuis |
| 568 |
|
| 569 |
} |
| 570 |
|
| 571 |
//------------// |
| 572 |
// Impression // |
| 573 |
//------------// |
| 574 |
|
| 575 |
// Operator << |
| 576 |
// ----------- |
| 577 |
ostream& operator<<(ostream& o, const Cmp& ci) { |
| 578 |
|
| 579 |
switch(ci.etat) { |
| 580 |
case ETATNONDEF: { |
| 581 |
o << "*** Cmp in UNDEFINED STATE" ; |
| 582 |
break ; |
| 583 |
} |
| 584 |
|
| 585 |
case ETATZERO: { |
| 586 |
o << "*** Cmp IDENTICALLY ZERO" ; |
| 587 |
break ; |
| 588 |
} |
| 589 |
|
| 590 |
case ETATQCQ: { |
| 591 |
o << "*** Cmp : " << endl ; |
| 592 |
o << " dzpuis = " << ci.get_dzpuis() << endl ; |
| 593 |
o << ci.va << endl ; |
| 594 |
break ; |
| 595 |
} |
| 596 |
|
| 597 |
default: { |
| 598 |
cout << "operator<<(ostream&, const Cmp&) : unknown state !" |
| 599 |
<< endl ; |
| 600 |
abort() ; |
| 601 |
break ; |
| 602 |
} |
| 603 |
} |
| 604 |
|
| 605 |
// Termine |
| 606 |
return o ; |
| 607 |
} |
| 608 |
|
| 609 |
// affiche_seuil |
| 610 |
//--------------- |
| 611 |
|
| 612 |
void Cmp::affiche_seuil(ostream& ost, int type, int precis, |
| 613 |
double seuil) const { |
| 614 |
ost << "*** Cmp " << endl ; |
| 615 |
|
| 616 |
// Cas particuliers |
| 617 |
//----------------- |
| 618 |
|
| 619 |
if (etat == ETATNONDEF) { |
| 620 |
ost << " state: UNDEFINED" << endl ; |
| 621 |
return ; |
| 622 |
} |
| 623 |
|
| 624 |
if (etat == ETATZERO) { |
| 625 |
ost << " state: ZERO" << endl ; |
| 626 |
return ; |
| 627 |
} |
| 628 |
|
| 629 |
// Cas general : on affiche la Valeur |
| 630 |
//------------ |
| 631 |
|
| 632 |
ost << " dzpuis = " << dzpuis << endl ; |
| 633 |
va.affiche_seuil(ost, type, precis, seuil) ; |
| 634 |
|
| 635 |
} |
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
//------------------------------------// |
| 641 |
// Spectral bases of the Valeur va // |
| 642 |
//------------------------------------// |
| 643 |
|
| 644 |
void Cmp::std_base_scal() { |
| 645 |
|
| 646 |
va.std_base_scal() ; |
| 647 |
|
| 648 |
} |
| 649 |
|
| 650 |
//--------------------------// |
| 651 |
// dzpuis manipulations // |
| 652 |
//--------------------------// |
| 653 |
|
| 654 |
void Cmp::set_dzpuis(int dzi) { |
| 655 |
|
| 656 |
dzpuis = dzi ; |
| 657 |
|
| 658 |
} |
| 659 |
|
| 660 |
bool Cmp::dz_nonzero() const { |
| 661 |
|
| 662 |
assert(etat != ETATNONDEF) ; |
| 663 |
|
| 664 |
const Mg3d* mg = mp->get_mg() ; |
| 665 |
|
| 666 |
int nzm1 = mg->get_nzone() - 1; |
| 667 |
if (mg->get_type_r(nzm1) != UNSURR) { |
| 668 |
return false ; |
| 669 |
} |
| 670 |
|
| 671 |
if (etat == ETATZERO) { |
| 672 |
return false ; |
| 673 |
} |
| 674 |
|
| 675 |
assert(etat == ETATQCQ) ; |
| 676 |
|
| 677 |
if (va.etat == ETATZERO) { |
| 678 |
return false ; |
| 679 |
} |
| 680 |
|
| 681 |
assert(va.etat == ETATQCQ) ; |
| 682 |
|
| 683 |
if (va.c != 0x0) { |
| 684 |
if ( (va.c)->get_etat() == ETATZERO ) { |
| 685 |
return false ; |
| 686 |
} |
| 687 |
|
| 688 |
assert( (va.c)->get_etat() == ETATQCQ ) ; |
| 689 |
if ( (va.c)->t[nzm1]->get_etat() == ETATZERO ) { |
| 690 |
return false ; |
| 691 |
} |
| 692 |
else { |
| 693 |
assert( (va.c)->t[nzm1]->get_etat() == ETATQCQ ) ; |
| 694 |
return true ; |
| 695 |
} |
| 696 |
} |
| 697 |
else{ |
| 698 |
assert(va.c_cf != 0x0) ; |
| 699 |
if ( (va.c_cf)->get_etat() == ETATZERO ) { |
| 700 |
return false ; |
| 701 |
} |
| 702 |
assert( (va.c_cf)->get_etat() == ETATQCQ ) ; |
| 703 |
if ( (va.c_cf)->t[nzm1]->get_etat() == ETATZERO ) { |
| 704 |
return false ; |
| 705 |
} |
| 706 |
else { |
| 707 |
assert( (va.c_cf)->t[nzm1]->get_etat() == ETATQCQ ) ; |
| 708 |
return true ; |
| 709 |
} |
| 710 |
|
| 711 |
} |
| 712 |
|
| 713 |
} |
| 714 |
|
| 715 |
bool Cmp::check_dzpuis(int dzi) const { |
| 716 |
|
| 717 |
if (dz_nonzero()) { // the check must be done |
| 718 |
return (dzpuis == dzi) ; |
| 719 |
} |
| 720 |
else{ |
| 721 |
return true ; |
| 722 |
} |
| 723 |
|
| 724 |
} |
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
//-----------------------------------------------// |
| 729 |
// Value at an arbitrary point // |
| 730 |
//-----------------------------------------------// |
| 731 |
|
| 732 |
double Cmp::val_point(double r, double theta, double phi) const { |
| 733 |
|
| 734 |
assert(etat != ETATNONDEF) ; |
| 735 |
|
| 736 |
if (etat == ETATZERO) { |
| 737 |
return double(0) ; |
| 738 |
} |
| 739 |
|
| 740 |
assert(etat == ETATQCQ) ; |
| 741 |
|
| 742 |
// 1/ Search for the domain and the grid coordinates (xi,theta',phi') |
| 743 |
// which corresponds to the point (r,theta,phi) |
| 744 |
|
| 745 |
int l ; |
| 746 |
double xi ; |
| 747 |
|
| 748 |
mp->val_lx(r, theta, phi, l, xi) ; // call of val_lx with default |
| 749 |
// accuracy parameters |
| 750 |
|
| 751 |
// 2/ Call to the Valeur version |
| 752 |
|
| 753 |
return va.val_point(l, xi, theta, phi) ; |
| 754 |
|
| 755 |
} |
| 756 |
|
| 757 |
|
| 758 |
//-------------------------------------// |
| 759 |
// Multipolar spectrum // |
| 760 |
//-------------------------------------// |
| 761 |
|
| 762 |
Tbl Cmp::multipole_spectrum() { |
| 763 |
assert (etat != ETATNONDEF) ; |
| 764 |
|
| 765 |
const Mg3d* mg = mp->get_mg() ; |
| 766 |
int nzone = mg->get_nzone() ; |
| 767 |
int lmax = 0 ; |
| 768 |
|
| 769 |
for (int lz=0; lz<nzone; lz++) |
| 770 |
lmax = (lmax < 2*mg->get_nt(lz) - 1 ? 2*mg->get_nt(lz) - 1 : lmax) ; |
| 771 |
|
| 772 |
Tbl resu(nzone, lmax) ; |
| 773 |
if (etat == ETATZERO) { |
| 774 |
resu.set_etat_zero() ; |
| 775 |
return resu ; |
| 776 |
} |
| 777 |
|
| 778 |
assert(etat == ETATQCQ) ; |
| 779 |
|
| 780 |
va.coef() ; |
| 781 |
va.ylm() ; |
| 782 |
resu.annule_hard() ; |
| 783 |
const Base_val& base = va.c_cf->base ; |
| 784 |
int m_quant, l_quant, base_r ; |
| 785 |
for (int lz=0; lz<nzone; lz++) |
| 786 |
for (int k=0 ; k<mg->get_np(lz) ; k++) |
| 787 |
for (int j=0 ; j<mg->get_nt(lz) ; j++) { |
| 788 |
if (nullite_plm(j, mg->get_nt(lz), k, mg->get_np(lz), base) == 1) |
| 789 |
{ |
| 790 |
// quantic numbers and spectral bases |
| 791 |
donne_lm(nzone, lz, j, k, base, m_quant, l_quant, base_r) ; |
| 792 |
for (int i=0; i<mg->get_nr(lz); i++) resu.set(lz, l_quant) |
| 793 |
+= fabs((*va.c_cf)(0, k, j, i)) ; |
| 794 |
} |
| 795 |
} |
| 796 |
|
| 797 |
return resu ; |
| 798 |
} |
| 799 |
|
| 800 |
} |