| 1 |
/* |
| 2 |
* Methods for the class Grille_val, and its derivative classes. |
| 3 |
* |
| 4 |
* See the file grille_val.h for documentation |
| 5 |
* |
| 6 |
*/ |
| 7 |
|
| 8 |
/* |
| 9 |
* Copyright (c) 2001 Jerome Novak |
| 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 |
char Grille_val_C[] = "$Header: /cvsroot/Lorene/C++/Source/Valencia/grille_val.C,v 1.7 2014/10/13 08:53:48 j_novak Exp $" ; |
| 31 |
|
| 32 |
/* |
| 33 |
* $Id: grille_val.C,v 1.7 2014/10/13 08:53:48 j_novak Exp $ |
| 34 |
* $Log: grille_val.C,v $ |
| 35 |
* Revision 1.7 2014/10/13 08:53:48 j_novak |
| 36 |
* Lorene classes and functions now belong to the namespace Lorene. |
| 37 |
* |
| 38 |
* Revision 1.6 2013/07/15 13:14:41 j_novak |
| 39 |
* Correcting copy constructor and operator = |
| 40 |
* |
| 41 |
* Revision 1.5 2008/02/18 13:53:48 j_novak |
| 42 |
* Removal of special indentation instructions. |
| 43 |
* |
| 44 |
* Revision 1.4 2003/12/19 15:05:14 j_novak |
| 45 |
* Trying to avoid shadowed variables |
| 46 |
* |
| 47 |
* Revision 1.3 2003/10/03 16:17:17 j_novak |
| 48 |
* Corrected some const qualifiers |
| 49 |
* |
| 50 |
* Revision 1.2 2001/12/04 21:27:54 e_gourgoulhon |
| 51 |
* |
| 52 |
* All writing/reading to a binary file are now performed according to |
| 53 |
* the big endian convention, whatever the system is big endian or |
| 54 |
* small endian, thanks to the functions fwrite_be and fread_be |
| 55 |
* |
| 56 |
* Revision 1.1 2001/11/22 13:41:54 j_novak |
| 57 |
* Added all source files for manipulating Valencia type objects and making |
| 58 |
* interpolations to and from Meudon grids. |
| 59 |
* |
| 60 |
* |
| 61 |
* $Header: /cvsroot/Lorene/C++/Source/Valencia/grille_val.C,v 1.7 2014/10/13 08:53:48 j_novak Exp $ |
| 62 |
* |
| 63 |
*/ |
| 64 |
|
| 65 |
// Fichier includes |
| 66 |
#include "grille_val.h" |
| 67 |
#include "utilitaires.h" |
| 68 |
|
| 69 |
//---------------// |
| 70 |
// Constructeurs // |
| 71 |
//---------------// |
| 72 |
|
| 73 |
// Fonction auxilliaire |
| 74 |
namespace Lorene { |
| 75 |
Tbl* Grille_val::fait_grille1D(const double rmin, const double rmax, const |
| 76 |
int n) |
| 77 |
{ |
| 78 |
assert(rmin<rmax) ; |
| 79 |
Tbl* resu = new Tbl(n) ; |
| 80 |
double step = (rmax - rmin)/double(n-1) ; |
| 81 |
resu->set_etat_qcq() ; |
| 82 |
for (int i=0; i<n; i++) resu->set(i) = rmin + i*step ; |
| 83 |
return resu ; |
| 84 |
} |
| 85 |
|
| 86 |
// Constructeur 1D |
| 87 |
Grille_val::Grille_val(const double izrmin, const double izrmax, const |
| 88 |
int n1, const int fantome): |
| 89 |
dim(n1), nfantome(fantome), type_t(SYM), type_p(SYM) |
| 90 |
{ |
| 91 |
assert (n1 > 0) ; |
| 92 |
zrmin = new double(izrmin) ; |
| 93 |
zrmax = new double(izrmax) ; |
| 94 |
double amin = ((n1 + nfantome - 0.5)*izrmin - |
| 95 |
(nfantome-0.5)*izrmax) / n1 ; |
| 96 |
double amax = ((n1 + nfantome - 0.5)*izrmax - |
| 97 |
(nfantome-0.5)*izrmin) / n1 ; |
| 98 |
zr = fait_grille1D(amin, amax, n1+2*fantome) ; |
| 99 |
amin = ((n1 + nfantome)*izrmin - nfantome*izrmax) / n1 ; |
| 100 |
amax = ((n1 + nfantome)*izrmax - nfantome*izrmin) / n1 ; |
| 101 |
zri = fait_grille1D(amin, amax, n1+2*fantome+1) ; |
| 102 |
} |
| 103 |
|
| 104 |
// Constructeur 2D |
| 105 |
Grille_val::Grille_val(const double izrmin, const double izrmax, const |
| 106 |
int n2, const int n1, const int itype_t, |
| 107 |
const int fantome): |
| 108 |
dim(n2,n1), nfantome(fantome), type_t(itype_t), type_p(SYM) |
| 109 |
|
| 110 |
{ |
| 111 |
zrmin = new double(izrmin) ; |
| 112 |
zrmax = new double(izrmax) ; |
| 113 |
double amin = ((n1 + nfantome - 0.5)*izrmin - |
| 114 |
(nfantome-0.5)*izrmax) / n1 ; |
| 115 |
double amax = ((n1 + nfantome - 0.5)*izrmax - |
| 116 |
(nfantome-0.5)*izrmin) / n1 ; |
| 117 |
zr = fait_grille1D(amin, amax, n1+2*fantome) ; |
| 118 |
amin = ((n1 + nfantome)*izrmin - nfantome*izrmax) / n1 ; |
| 119 |
amax = ((n1 + nfantome)*izrmax - nfantome*izrmin) / n1 ; |
| 120 |
zri = fait_grille1D(amin, amax, n1+2*fantome+1) ; |
| 121 |
|
| 122 |
} |
| 123 |
|
| 124 |
// Constructeur 3D |
| 125 |
Grille_val::Grille_val(const double izrmin, const double izrmax, |
| 126 |
const int n3, const int n2, const int n1, |
| 127 |
const int itype_t, const int itype_p, |
| 128 |
const int fantome ): dim(n3,n2,n1), nfantome(fantome), |
| 129 |
type_t(itype_t), type_p(itype_p) |
| 130 |
{ |
| 131 |
zrmin = new double(izrmin) ; |
| 132 |
zrmax = new double(izrmax) ; |
| 133 |
double amin = ((n1 + nfantome - 0.5)*izrmin - |
| 134 |
(nfantome-0.5)*izrmax) / n1 ; |
| 135 |
double amax = ((n1 + nfantome - 0.5)*izrmax - |
| 136 |
(nfantome-0.5)*izrmin) / n1 ; |
| 137 |
zr = fait_grille1D(amin, amax, n1+2*fantome) ; |
| 138 |
amin = ((n1 + nfantome)*izrmin - nfantome*izrmax) / n1 ; |
| 139 |
amax = ((n1 + nfantome)*izrmax - nfantome*izrmin) / n1 ; |
| 140 |
zri = fait_grille1D(amin, amax, n1+2*fantome+1) ; |
| 141 |
} |
| 142 |
|
| 143 |
|
| 144 |
// Constructeur par recopie |
| 145 |
Grille_val::Grille_val(const Grille_val & titi): dim(titi.dim), |
| 146 |
nfantome(titi.nfantome), type_t(titi.type_t), type_p(titi.type_p) |
| 147 |
{ |
| 148 |
assert(titi.zr != 0x0) ; |
| 149 |
assert(titi.zri != 0x0) ; |
| 150 |
assert(titi.zrmin != 0x0) ; |
| 151 |
assert(titi.zrmax != 0x0) ; |
| 152 |
zr = new Tbl(*titi.zr) ; |
| 153 |
zri = new Tbl(*titi.zri) ; |
| 154 |
zrmin = new double(*titi.zrmin) ; |
| 155 |
zrmax = new double(*titi.zrmax) ; |
| 156 |
|
| 157 |
} |
| 158 |
|
| 159 |
// Depuis un fichier |
| 160 |
Grille_val::Grille_val(FILE* fd):dim(fd) { |
| 161 |
|
| 162 |
fread_be(&nfantome, sizeof(int), 1, fd) ; |
| 163 |
fread_be(&type_t, sizeof(int), 1, fd) ; |
| 164 |
fread_be(&type_p, sizeof(int), 1, fd) ; |
| 165 |
|
| 166 |
double amin, amax ; |
| 167 |
fread_be(&amin, sizeof(double), 1, fd) ; |
| 168 |
fread_be(&amax, sizeof(double), 1, fd) ; |
| 169 |
zrmin = new double(amin) ; |
| 170 |
zrmax = new double(amax) ; |
| 171 |
zr = new Tbl(fd) ; |
| 172 |
zri = new Tbl(fd) ; |
| 173 |
|
| 174 |
} |
| 175 |
|
| 176 |
//--------------// |
| 177 |
// Destructeurs // |
| 178 |
//--------------// |
| 179 |
|
| 180 |
// Destructeur |
| 181 |
Grille_val::~Grille_val() { |
| 182 |
|
| 183 |
assert(zr != 0x0) ; |
| 184 |
assert(zri != 0x0) ; |
| 185 |
assert(zrmin != 0x0) ; |
| 186 |
assert(zrmax != 0x0) ; |
| 187 |
delete zr ; |
| 188 |
delete zri ; |
| 189 |
delete zrmin ; |
| 190 |
delete zrmax ; |
| 191 |
|
| 192 |
} |
| 193 |
|
| 194 |
//-------------// |
| 195 |
// Affectation // |
| 196 |
//-------------// |
| 197 |
|
| 198 |
// Depuis une autre Grille_val |
| 199 |
void Grille_val::operator=(const Grille_val & titi) { |
| 200 |
|
| 201 |
dim = titi.dim ; |
| 202 |
nfantome = titi.nfantome ; |
| 203 |
type_t = titi.type_t ; |
| 204 |
type_p = titi.type_p ; |
| 205 |
|
| 206 |
assert(titi.zr != 0x0) ; |
| 207 |
assert(titi.zri != 0x0) ; |
| 208 |
assert(titi.zrmin != 0x0) ; |
| 209 |
assert(titi.zrmax != 0x0) ; |
| 210 |
|
| 211 |
for (int i=0; i<dim.dim[0]+2*nfantome; i++) |
| 212 |
zr->t[i] = titi.zr->t[i] ; |
| 213 |
for (int i=0; i<dim.dim[0] + 2*nfantome + 1; i++) |
| 214 |
zri->t[i] = titi.zri->t[i] ; |
| 215 |
*zrmin = *titi.zrmin ; |
| 216 |
*zrmax = *titi.zrmax ; |
| 217 |
} |
| 218 |
|
| 219 |
//------------// |
| 220 |
// Sauvegarde // |
| 221 |
//------------// |
| 222 |
|
| 223 |
// Sauve dans un fchier |
| 224 |
void Grille_val::sauve(FILE* fd) const { |
| 225 |
|
| 226 |
dim.sauve(fd) ; |
| 227 |
fwrite_be(&nfantome, sizeof(int), 1, fd) ; |
| 228 |
fwrite_be(&type_t, sizeof(int), 1, fd) ; |
| 229 |
fwrite_be(&type_p, sizeof(int), 1, fd) ; |
| 230 |
|
| 231 |
fwrite_be(zrmin, sizeof(double), 1, fd) ; |
| 232 |
fwrite_be(zrmax, sizeof(double), 1, fd) ; |
| 233 |
|
| 234 |
zr->sauve(fd) ; zri->sauve(fd) ; |
| 235 |
|
| 236 |
} |
| 237 |
|
| 238 |
//------------// |
| 239 |
// Impression // |
| 240 |
//------------// |
| 241 |
|
| 242 |
// Operateurs << |
| 243 |
ostream& operator<<(ostream& o, const Grille_val & titi) { |
| 244 |
titi >> o ; |
| 245 |
return o ; |
| 246 |
} |
| 247 |
|
| 248 |
ostream& Grille_val::operator>>(ostream& o) const { |
| 249 |
int ndim = dim.ndim ; |
| 250 |
int nfant = nfantome ; |
| 251 |
o.precision(4); |
| 252 |
o.setf(ios::showpoint); |
| 253 |
o << "*** Grille_val " << ndim << "D" << " size: " ; |
| 254 |
for (int i = 0; i<ndim-1; i++) { |
| 255 |
o << dim.dim[ndim-1-i] ; |
| 256 |
if (ndim-i == 3) o << " x " ; |
| 257 |
if (ndim-i == 2) o << " x " ; |
| 258 |
} |
| 259 |
o << dim.dim[0] << endl ; |
| 260 |
o << nfant << " hidden cells on each side " << endl ; |
| 261 |
return o ; |
| 262 |
} |
| 263 |
|
| 264 |
//------------------------------------// |
| 265 |
// class Gval_cart // |
| 266 |
//------------------------------------// |
| 267 |
|
| 268 |
/********************************************************************* |
| 269 |
* |
| 270 |
* Cartesian grid for Godunov-type integration schemes |
| 271 |
* |
| 272 |
*********************************************************************/ |
| 273 |
|
| 274 |
//---------------// |
| 275 |
// Constructeurs // |
| 276 |
//---------------// |
| 277 |
|
| 278 |
// Constructeur 1D |
| 279 |
Gval_cart::Gval_cart(const double izmin, const double izmax, const int nz, |
| 280 |
const int fantome) |
| 281 |
:Grille_val(izmin, izmax, nz, fantome), |
| 282 |
xmin(0x0), xmax(0x0), |
| 283 |
ymin(0x0), ymax(0x0), |
| 284 |
x(0x0), xi(0x0), |
| 285 |
y(0x0), yi(0x0){ |
| 286 |
} |
| 287 |
|
| 288 |
// Constructeur 2D |
| 289 |
Gval_cart::Gval_cart(const double ixmin, const double ixmax, const |
| 290 |
double izmin, const double izmax, const int nx, |
| 291 |
const int nz, const int itype_t, const int fantome) |
| 292 |
:Grille_val(izmin, izmax, nx, nz, itype_t, fantome), |
| 293 |
ymin(0x0), ymax(0x0), |
| 294 |
y(0x0), yi(0x0) |
| 295 |
{ |
| 296 |
assert ( (type_t!=SYM) || (izmin >= double(0)) ) ; |
| 297 |
|
| 298 |
xmin = new double(ixmin) ; |
| 299 |
xmax = new double(ixmax) ; |
| 300 |
double amin = ((nx + nfantome - 0.5)*ixmin - |
| 301 |
(nfantome-0.5)*ixmax) / nx ; |
| 302 |
double amax = ((nx + nfantome - 0.5)*ixmax - |
| 303 |
(nfantome-0.5)*ixmin) / nx ; |
| 304 |
x = fait_grille1D(amin, amax, nx+2*fantome) ; |
| 305 |
amin = ((nx + nfantome)*ixmin - nfantome*ixmax) / nx ; |
| 306 |
amax = ((nx + nfantome)*ixmax - nfantome*ixmin) / nx ; |
| 307 |
xi = fait_grille1D(amin, amax, nx+2*fantome+1) ; |
| 308 |
|
| 309 |
} |
| 310 |
|
| 311 |
// Constructeur 3D |
| 312 |
Gval_cart::Gval_cart(const double iymin, const double iymax, |
| 313 |
const double ixmin, const double ixmax, const |
| 314 |
double izmin, const double izmax, const int ny, |
| 315 |
const int nx, const int nz, const int itype_t, |
| 316 |
const int itype_p, const int fantome) |
| 317 |
:Grille_val(izmin, izmax, ny, nx, nz, itype_t, itype_p, fantome) |
| 318 |
{ |
| 319 |
assert ( (type_t!=SYM) || (izmin >= double(0)) ) ; |
| 320 |
assert ( (type_p!=SYM) || (iymin >= double(0)) ) ; |
| 321 |
|
| 322 |
xmin = new double(ixmin) ; |
| 323 |
xmax = new double(ixmax) ; |
| 324 |
double amin = ((nx + nfantome - 0.5)*ixmin - |
| 325 |
(nfantome-0.5)*ixmax) / nx ; |
| 326 |
double amax = ((nx + nfantome - 0.5)*ixmax - |
| 327 |
(nfantome-0.5)*ixmin) / nx ; |
| 328 |
x = fait_grille1D(amin, amax, nx+2*fantome) ; |
| 329 |
amin = ((nx + nfantome)*ixmin - nfantome*ixmax) / nx ; |
| 330 |
amax = ((nx + nfantome)*ixmax - nfantome*ixmin) / nx ; |
| 331 |
xi = fait_grille1D(amin, amax, nx+2*fantome+1) ; |
| 332 |
|
| 333 |
ymin = new double(iymin) ; |
| 334 |
ymax = new double(iymax) ; |
| 335 |
amin = ((ny + nfantome - 0.5)*iymin - |
| 336 |
(nfantome-0.5)*iymax) / ny ; |
| 337 |
amax = ((ny + nfantome - 0.5)*iymax - |
| 338 |
(nfantome-0.5)*iymin) / ny ; |
| 339 |
y = fait_grille1D(amin, amax, ny+2*fantome) ; |
| 340 |
amin = ((ny + nfantome)*iymin - nfantome*iymax) / ny ; |
| 341 |
amax = ((ny + nfantome)*iymax - nfantome*iymin) / ny ; |
| 342 |
yi = fait_grille1D(amin, amax, ny+2*fantome+1) ; |
| 343 |
|
| 344 |
} |
| 345 |
|
| 346 |
// Constructeur par recopie |
| 347 |
Gval_cart::Gval_cart(const Gval_cart& titi) |
| 348 |
:Grille_val(titi) |
| 349 |
{ |
| 350 |
if (titi.x != 0x0) x = new Tbl(*titi.x) ; |
| 351 |
if (titi.xi != 0x0) xi = new Tbl(*titi.xi) ; |
| 352 |
if (titi.xmin != 0x0) xmin = new double(*titi.xmin) ; |
| 353 |
if (titi.xmax != 0x0) xmax = new double(*titi.xmax) ; |
| 354 |
if (titi.y != 0x0) y = new Tbl(*titi.y) ; |
| 355 |
if (titi.yi != 0x0) yi = new Tbl(*titi.yi) ; |
| 356 |
if (titi.ymin != 0x0) ymin = new double(*titi.ymin) ; |
| 357 |
if (titi.ymax != 0x0) ymax = new double(*titi.ymax) ; |
| 358 |
|
| 359 |
} |
| 360 |
|
| 361 |
// Depuis un fichier |
| 362 |
Gval_cart::Gval_cart(FILE* fd) |
| 363 |
: Grille_val(fd) |
| 364 |
{ |
| 365 |
double amin, amax ; |
| 366 |
if (dim.ndim >= 2) { |
| 367 |
fread_be(&amin, sizeof(double), 1, fd) ; |
| 368 |
fread_be(&amax, sizeof(double), 1, fd) ; |
| 369 |
xmin = new double(amin) ; |
| 370 |
xmax = new double(amax) ; |
| 371 |
x = new Tbl(fd) ; |
| 372 |
xi = new Tbl(fd) ; |
| 373 |
} |
| 374 |
if (dim.ndim >= 3) { |
| 375 |
fread_be(&amin, sizeof(double), 1, fd) ; |
| 376 |
fread_be(&amax, sizeof(double), 1, fd) ; |
| 377 |
ymin = new double(amin) ; |
| 378 |
ymax = new double(amax) ; |
| 379 |
y = new Tbl(fd) ; |
| 380 |
yi = new Tbl(fd) ; |
| 381 |
} |
| 382 |
} |
| 383 |
|
| 384 |
|
| 385 |
//--------------// |
| 386 |
// Destructeurs // |
| 387 |
//--------------// |
| 388 |
|
| 389 |
// Destructeur |
| 390 |
Gval_cart::~Gval_cart() { |
| 391 |
|
| 392 |
if (x != 0x0) delete x ; |
| 393 |
if (xi != 0x0) delete xi ; |
| 394 |
if (xmin != 0x0) delete xmin ; |
| 395 |
if (xmax != 0x0) delete xmax ; |
| 396 |
if (y != 0x0) delete y ; |
| 397 |
if (yi != 0x0) delete yi ; |
| 398 |
if (ymin != 0x0) delete ymin ; |
| 399 |
if (ymax != 0x0) delete ymax ; |
| 400 |
|
| 401 |
} |
| 402 |
|
| 403 |
//-------------// |
| 404 |
// Affectation // |
| 405 |
//-------------// |
| 406 |
|
| 407 |
// Depuis une autre Grille_val |
| 408 |
void Gval_cart::operator=(const Gval_cart& titi) { |
| 409 |
|
| 410 |
Grille_val::operator=(titi) ; |
| 411 |
|
| 412 |
if (titi.x != 0x0) *x = *titi.x ; |
| 413 |
if (titi.xi != 0x0) *xi = *titi.xi ; |
| 414 |
if (titi.xmin != 0x0) *xmin = *titi.xmin ; |
| 415 |
if (titi.xmax != 0x0) *xmax = *titi.xmax ; |
| 416 |
if (titi.y != 0x0) *y = *titi.y ; |
| 417 |
if (titi.yi != 0x0) *yi = *titi.yi ; |
| 418 |
if (titi.ymin != 0x0) *ymin = *titi.ymin ; |
| 419 |
if (titi.ymax != 0x0) *ymax = *titi.ymax ; |
| 420 |
} |
| 421 |
|
| 422 |
//------------// |
| 423 |
// Sauvegarde // |
| 424 |
//------------// |
| 425 |
|
| 426 |
// save onto a file |
| 427 |
void Gval_cart::sauve(FILE* fd) const { |
| 428 |
|
| 429 |
Grille_val::sauve(fd) ; |
| 430 |
|
| 431 |
if (dim.ndim >= 2) { |
| 432 |
fwrite_be(xmin, sizeof(double), 1, fd) ; |
| 433 |
fwrite_be(xmax, sizeof(double), 1, fd) ; |
| 434 |
x->sauve(fd) ; xi->sauve(fd) ; |
| 435 |
} |
| 436 |
if (dim.ndim >= 3) { |
| 437 |
fwrite_be(ymin, sizeof(double), 1, fd) ; |
| 438 |
fwrite_be(ymax, sizeof(double), 1, fd) ; |
| 439 |
y->sauve(fd) ; yi->sauve(fd) ; |
| 440 |
} |
| 441 |
|
| 442 |
} |
| 443 |
|
| 444 |
|
| 445 |
//------------// |
| 446 |
// Impression // |
| 447 |
//------------// |
| 448 |
|
| 449 |
// Operateurs << |
| 450 |
ostream& Gval_cart::operator>>(ostream& o) const { |
| 451 |
|
| 452 |
int ndim = dim.ndim; |
| 453 |
Grille_val::operator>>(o) ; |
| 454 |
|
| 455 |
o << "*** Cartesian grid ***" << endl ; |
| 456 |
|
| 457 |
switch (ndim) { |
| 458 |
|
| 459 |
case 1 : { |
| 460 |
o << "Z nodes: " << endl ; |
| 461 |
for (int i=0; i<dim.dim[0]; i++) { |
| 462 |
o << zr->set(i+nfantome) << " " ; |
| 463 |
} |
| 464 |
o << endl ; |
| 465 |
break ; |
| 466 |
} |
| 467 |
|
| 468 |
|
| 469 |
case 2 : { |
| 470 |
o << "X nodes: " << endl ; |
| 471 |
for (int j=0 ; j<dim.dim[1] ; j++) { |
| 472 |
o << " " << x->set(j+nfantome) ; |
| 473 |
} |
| 474 |
o << endl ; |
| 475 |
|
| 476 |
o << "Z nodes: " << endl ; |
| 477 |
|
| 478 |
for (int i=0 ; i<dim.dim[0] ; i++) { |
| 479 |
o << " " << zr->set(i+nfantome) ; |
| 480 |
} |
| 481 |
o << endl ; |
| 482 |
break ; |
| 483 |
} |
| 484 |
|
| 485 |
case 3 : { |
| 486 |
o << "Y nodes: " << endl ; |
| 487 |
for (int k=0 ; k<dim.dim[2] ; k++) { |
| 488 |
o << " " << y->set(k+nfantome) ; |
| 489 |
} |
| 490 |
o << endl ; |
| 491 |
|
| 492 |
o << "X nodes: " << endl ; |
| 493 |
for (int j=0 ; j<dim.dim[1] ; j++) { |
| 494 |
o << " " << x->set(j+nfantome) ; |
| 495 |
} |
| 496 |
o << endl ; |
| 497 |
|
| 498 |
o << "Z nodes: " << endl ; |
| 499 |
|
| 500 |
for (int i=0 ; i<dim.dim[0] ; i++) { |
| 501 |
o << " " << zr->set(i+nfantome) ; |
| 502 |
} |
| 503 |
o << endl ; |
| 504 |
break ; |
| 505 |
} |
| 506 |
|
| 507 |
default : { |
| 508 |
cout << "operator>> Gval_cart : unexpected dimension !" << endl ; |
| 509 |
cout << " ndim = " << ndim << endl ; |
| 510 |
abort() ; |
| 511 |
break ; |
| 512 |
} |
| 513 |
} |
| 514 |
|
| 515 |
return o ; |
| 516 |
} |
| 517 |
//------------------------------------// |
| 518 |
// class Gval_spher // |
| 519 |
//------------------------------------// |
| 520 |
|
| 521 |
/********************************************************************* |
| 522 |
* |
| 523 |
* Spherical grids for Godunov-type integration schemes |
| 524 |
* |
| 525 |
*********************************************************************/ |
| 526 |
|
| 527 |
//---------------// |
| 528 |
// Constructeurs // |
| 529 |
//---------------// |
| 530 |
|
| 531 |
// Constructeur 1D |
| 532 |
Gval_spher::Gval_spher(const double irmin, const double irmax, const int nr, |
| 533 |
const int fantome) |
| 534 |
:Grille_val(irmin, irmax, nr, fantome), |
| 535 |
tet(0x0), teti(0x0), |
| 536 |
phi(0x0), phii(0x0){ |
| 537 |
assert(irmin>=double(0)) ; |
| 538 |
} |
| 539 |
|
| 540 |
// Constructeur 2D |
| 541 |
Gval_spher::Gval_spher(const double irmin, const double irmax, const int nt, |
| 542 |
const int nr, const int itype_t, const int fantome) |
| 543 |
:Grille_val(irmin, irmax, nt, nr, itype_t, fantome), |
| 544 |
phi(0x0), phii(0x0) |
| 545 |
{ |
| 546 |
assert (irmin >= double(0)) ; |
| 547 |
|
| 548 |
double tetmin = 0. ; |
| 549 |
double tetmax = (type_t == SYM ? M_PI_2 : M_PI) ; |
| 550 |
double amin = ((nt + nfantome - 0.5)*tetmin - |
| 551 |
(nfantome-0.5)*tetmax) / nt ; |
| 552 |
double amax = ((nt + nfantome - 0.5)*tetmax - |
| 553 |
(nfantome-0.5)*tetmin) / nt ; |
| 554 |
tet = fait_grille1D(amin, amax, nt+2*fantome) ; |
| 555 |
amin = ((nt + nfantome)*tetmin - nfantome*tetmax) / nt ; |
| 556 |
amax = ((nt + nfantome)*tetmax - nfantome*tetmin) / nt ; |
| 557 |
teti = fait_grille1D(amin, amax, nt+2*fantome+1) ; |
| 558 |
|
| 559 |
} |
| 560 |
|
| 561 |
// Constructeur 3D |
| 562 |
Gval_spher::Gval_spher(const double irmin, const double irmax, const int np, |
| 563 |
const int nt, const int nr, const int itype_t, |
| 564 |
const int itype_p, const int fantome) |
| 565 |
:Grille_val(irmin, irmax, np, nt, nr, itype_t, itype_p, fantome) |
| 566 |
{ |
| 567 |
assert (irmin >= double(0)) ; |
| 568 |
|
| 569 |
|
| 570 |
double tetmin = 0. ; |
| 571 |
double tetmax = (type_t == SYM ? M_PI_2 : M_PI) ; |
| 572 |
double amin = ((nt + nfantome - 0.5)*tetmin - |
| 573 |
(nfantome-0.5)*tetmax) / nt ; |
| 574 |
double amax = ((nt + nfantome - 0.5)*tetmax - |
| 575 |
(nfantome-0.5)*tetmin) / nt ; |
| 576 |
tet = fait_grille1D(amin, amax, nt+2*fantome) ; |
| 577 |
amin = ((nt + nfantome)*tetmin - nfantome*tetmax) / nt ; |
| 578 |
amax = ((nt + nfantome)*tetmax - nfantome*tetmin) / nt ; |
| 579 |
teti = fait_grille1D(amin, amax, nt+2*fantome+1) ; |
| 580 |
|
| 581 |
double phimin = 0. ; |
| 582 |
double phimax = ( type_p == SYM ? M_PI : 2.*M_PI) ; //??? a verifier! |
| 583 |
amin = ((np + nfantome - 0.5)*phimin - |
| 584 |
(nfantome-0.5)*phimax) / np ; |
| 585 |
amax = ((np + nfantome - 0.5)*phimax - |
| 586 |
(nfantome-0.5)*phimin) / np ; |
| 587 |
phi = fait_grille1D(amin, amax, np+2*fantome) ; |
| 588 |
amin = ((np + nfantome)*phimin - nfantome*phimax) / np ; |
| 589 |
amax = ((np + nfantome)*phimax - nfantome*phimin) / np ; |
| 590 |
phii = fait_grille1D(amin, amax, np+2*fantome+1) ; |
| 591 |
|
| 592 |
} |
| 593 |
|
| 594 |
// Constructeur par recopie |
| 595 |
Gval_spher::Gval_spher(const Gval_spher& titi) |
| 596 |
:Grille_val(titi), tet(0x0), teti(0x0), phi(0x0), phii(0x0) |
| 597 |
{ |
| 598 |
if (titi.tet != 0x0) tet = new Tbl(*titi.tet) ; |
| 599 |
if (titi.teti != 0x0) teti = new Tbl(*titi.teti) ; |
| 600 |
if (titi.phi != 0x0) phi = new Tbl(*titi.phi) ; |
| 601 |
if (titi.phii != 0x0) phii = new Tbl(*titi.phii) ; |
| 602 |
|
| 603 |
} |
| 604 |
|
| 605 |
// Depuis un fichier |
| 606 |
Gval_spher::Gval_spher(FILE* fd) |
| 607 |
: Grille_val(fd) |
| 608 |
{ |
| 609 |
if (dim.ndim >= 2) { |
| 610 |
tet = new Tbl(fd) ; |
| 611 |
teti = new Tbl(fd) ; |
| 612 |
} |
| 613 |
if (dim.ndim >= 3) { |
| 614 |
phi = new Tbl(fd) ; |
| 615 |
phii = new Tbl(fd) ; |
| 616 |
} |
| 617 |
} |
| 618 |
|
| 619 |
//--------------// |
| 620 |
// Destructeurs // |
| 621 |
//--------------// |
| 622 |
|
| 623 |
// Destructeur |
| 624 |
Gval_spher::~Gval_spher() { |
| 625 |
|
| 626 |
if (tet != 0x0) delete tet ; |
| 627 |
if (teti != 0x0) delete teti ; |
| 628 |
if (phi != 0x0) delete phi ; |
| 629 |
if (phii != 0x0) delete phii ; |
| 630 |
|
| 631 |
} |
| 632 |
|
| 633 |
//-------------// |
| 634 |
// Affectation // |
| 635 |
//-------------// |
| 636 |
|
| 637 |
// Depuis une autre Grille_val |
| 638 |
void Gval_spher::operator=(const Gval_spher& titi) { |
| 639 |
|
| 640 |
Grille_val::operator=(titi) ; |
| 641 |
|
| 642 |
if (titi.tet != 0x0) { |
| 643 |
if (tet == 0x0) |
| 644 |
tet = new Tbl(*titi.tet) ; |
| 645 |
else |
| 646 |
*tet = *titi.tet ; |
| 647 |
} |
| 648 |
else { |
| 649 |
if (tet != 0x0) delete tet ; |
| 650 |
tet = 0x0 ; |
| 651 |
} |
| 652 |
if (titi.teti != 0x0) { |
| 653 |
if (teti == 0x0) |
| 654 |
teti = new Tbl(*titi.teti) ; |
| 655 |
else |
| 656 |
*teti = *titi.teti ; |
| 657 |
} |
| 658 |
else { |
| 659 |
if (teti != 0x0) delete teti ; |
| 660 |
teti = 0x0 ; |
| 661 |
} |
| 662 |
if (titi.phi != 0x0) { |
| 663 |
if (phi == 0x0) |
| 664 |
phi = new Tbl(*titi.phi) ; |
| 665 |
else |
| 666 |
*phi = *titi.phi ; |
| 667 |
} |
| 668 |
else { |
| 669 |
if (phi != 0x0) delete phi ; |
| 670 |
phi = 0x0 ; |
| 671 |
} |
| 672 |
if (titi.phii != 0x0) { |
| 673 |
if (phii == 0x0) |
| 674 |
phii = new Tbl(*titi.phii) ; |
| 675 |
else |
| 676 |
*phii = *titi.phii ; |
| 677 |
} |
| 678 |
else { |
| 679 |
if (phii != 0x0) delete phii ; |
| 680 |
phii = 0x0 ; |
| 681 |
} |
| 682 |
} |
| 683 |
|
| 684 |
//------------// |
| 685 |
// Sauvegarde // |
| 686 |
//------------// |
| 687 |
|
| 688 |
// save onto a file |
| 689 |
void Gval_spher::sauve(FILE* fd) const { |
| 690 |
|
| 691 |
Grille_val::sauve(fd) ; |
| 692 |
|
| 693 |
if (dim.ndim >= 2) { |
| 694 |
tet->sauve(fd) ; |
| 695 |
teti->sauve(fd) ; |
| 696 |
} |
| 697 |
if (dim.ndim >= 3) { |
| 698 |
phi->sauve(fd) ; |
| 699 |
phii->sauve(fd) ; |
| 700 |
} |
| 701 |
|
| 702 |
} |
| 703 |
|
| 704 |
//------------// |
| 705 |
// Impression // |
| 706 |
//------------// |
| 707 |
|
| 708 |
// Operateurs << |
| 709 |
ostream& Gval_spher::operator>>(ostream& o) const { |
| 710 |
|
| 711 |
int ndim = dim.ndim; |
| 712 |
Grille_val::operator>>(o) ; |
| 713 |
|
| 714 |
o << "*** Spherical grid ***" << endl ; |
| 715 |
|
| 716 |
switch (ndim) { |
| 717 |
|
| 718 |
case 1 : { |
| 719 |
o << "R nodes: " << endl ; |
| 720 |
for (int i=0; i<dim.dim[0]; i++) { |
| 721 |
o << zr->set(i+nfantome) << " " ; |
| 722 |
} |
| 723 |
o << endl ; |
| 724 |
break ; |
| 725 |
} |
| 726 |
|
| 727 |
|
| 728 |
case 2 : { |
| 729 |
o << "THETA nodes: " << endl ; |
| 730 |
for (int j=0 ; j<dim.dim[1] ; j++) { |
| 731 |
o << " " << tet->set(j+nfantome) ; |
| 732 |
} |
| 733 |
o << endl ; |
| 734 |
|
| 735 |
o << "R nodes: " << endl ; |
| 736 |
|
| 737 |
for (int i=0 ; i<dim.dim[0] ; i++) { |
| 738 |
o << " " << zr->set(i+nfantome) ; |
| 739 |
} |
| 740 |
o << endl ; |
| 741 |
break ; |
| 742 |
} |
| 743 |
|
| 744 |
case 3 : { |
| 745 |
o << "PHI nodes: " << endl ; |
| 746 |
for (int k=0 ; k<dim.dim[2] ; k++) { |
| 747 |
o << " " << phi->set(k+nfantome) ; |
| 748 |
} |
| 749 |
o << endl ; |
| 750 |
|
| 751 |
o << "THETA nodes: " << endl ; |
| 752 |
for (int j=0 ; j<dim.dim[1] ; j++) { |
| 753 |
o << " " << tet->set(j+nfantome) ; |
| 754 |
} |
| 755 |
o << endl ; |
| 756 |
|
| 757 |
o << "R nodes: " << endl ; |
| 758 |
|
| 759 |
for (int i=0 ; i<dim.dim[0] ; i++) { |
| 760 |
o << " " << zr->set(i+nfantome) ; |
| 761 |
} |
| 762 |
o << endl ; |
| 763 |
break ; |
| 764 |
} |
| 765 |
|
| 766 |
default : { |
| 767 |
cout << "operator>> Gval_spher : unexpected dimension !" << endl ; |
| 768 |
cout << " ndim = " << ndim << endl ; |
| 769 |
abort() ; |
| 770 |
break ; |
| 771 |
} |
| 772 |
} |
| 773 |
|
| 774 |
return o ; |
| 775 |
} |
| 776 |
} |