grille_val.C

00001 /*
00002  * Methods for the class Grille_val, and its derivative classes.
00003  *
00004  * See the file grille_val.h for documentation
00005  *
00006  */
00007 
00008 /*
00009  *   Copyright (c) 2001 Jerome Novak
00010  *
00011  *   This file is part of LORENE.
00012  *
00013  *   LORENE is free software; you can redistribute it and/or modify
00014  *   it under the terms of the GNU General Public License as published by
00015  *   the Free Software Foundation; either version 2 of the License, or
00016  *   (at your option) any later version.
00017  *
00018  *   LORENE is distributed in the hope that it will be useful,
00019  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  *   GNU General Public License for more details.
00022  *
00023  *   You should have received a copy of the GNU General Public License
00024  *   along with LORENE; if not, write to the Free Software
00025  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026  *
00027  */
00028 
00029 
00030 char Grille_val_C[] = "$Header: /cvsroot/Lorene/C++/Source/Valencia/grille_val.C,v 1.5 2008/02/18 13:53:48 j_novak Exp $" ;
00031 
00032 /*
00033  * $Id: grille_val.C,v 1.5 2008/02/18 13:53:48 j_novak Exp $
00034  * $Log: grille_val.C,v $
00035  * Revision 1.5  2008/02/18 13:53:48  j_novak
00036  * Removal of special indentation instructions.
00037  *
00038  * Revision 1.4  2003/12/19 15:05:14  j_novak
00039  * Trying to avoid shadowed variables
00040  *
00041  * Revision 1.3  2003/10/03 16:17:17  j_novak
00042  * Corrected some const qualifiers
00043  *
00044  * Revision 1.2  2001/12/04 21:27:54  e_gourgoulhon
00045  *
00046  * All writing/reading to a binary file are now performed according to
00047  * the big endian convention, whatever the system is big endian or
00048  * small endian, thanks to the functions fwrite_be and fread_be
00049  *
00050  * Revision 1.1  2001/11/22 13:41:54  j_novak
00051  * Added all source files for manipulating Valencia type objects and making
00052  * interpolations to and from Meudon grids.
00053  *
00054  *
00055  * $Header: /cvsroot/Lorene/C++/Source/Valencia/grille_val.C,v 1.5 2008/02/18 13:53:48 j_novak Exp $
00056  *
00057  */
00058 
00059 // Fichier includes
00060 #include "grille_val.h"
00061 #include "utilitaires.h"
00062 
00063             //---------------//
00064             // Constructeurs //
00065             //---------------//
00066 
00067 // Fonction auxilliaire
00068 Tbl* Grille_val::fait_grille1D(const double rmin, const double rmax, const
00069                    int n) 
00070 {
00071   assert(rmin<rmax) ;
00072   Tbl* resu = new Tbl(n) ;
00073   double step = (rmax - rmin)/double(n-1) ;
00074   resu->set_etat_qcq() ;
00075   for (int i=0; i<n; i++) resu->set(i) = rmin + i*step ;
00076   return resu ;
00077 }
00078 
00079 // Constructeur 1D
00080 Grille_val::Grille_val(const double izrmin, const double izrmax, const
00081                int n1, const int fantome): 
00082   dim(n1), nfantome(fantome), type_t(SYM), type_p(SYM)
00083 {
00084   assert (n1 > 0) ;
00085   zrmin = new double(izrmin) ;
00086   zrmax = new double(izrmax) ;
00087   double amin = ((n1 + nfantome - 0.5)*izrmin -
00088          (nfantome-0.5)*izrmax) / n1 ;
00089   double amax = ((n1 + nfantome - 0.5)*izrmax -
00090          (nfantome-0.5)*izrmin) / n1 ;
00091   zr = fait_grille1D(amin, amax, n1+2*fantome) ;
00092   amin = ((n1 + nfantome)*izrmin - nfantome*izrmax) / n1 ;
00093   amax = ((n1 + nfantome)*izrmax - nfantome*izrmin) / n1 ;
00094   zri = fait_grille1D(amin, amax, n1+2*fantome+1) ;
00095 }
00096 
00097 // Constructeur 2D
00098 Grille_val::Grille_val(const double izrmin, const double izrmax, const
00099                int n2, const int n1, const int itype_t, 
00100                const int fantome): 
00101   dim(n2,n1), nfantome(fantome), type_t(itype_t), type_p(SYM)
00102 
00103 {
00104   zrmin = new double(izrmin) ;
00105   zrmax = new double(izrmax) ;
00106   double amin = ((n1 + nfantome - 0.5)*izrmin -
00107          (nfantome-0.5)*izrmax) / n1 ;
00108   double amax = ((n1 + nfantome - 0.5)*izrmax -
00109          (nfantome-0.5)*izrmin) / n1 ;
00110   zr = fait_grille1D(amin, amax, n1+2*fantome) ;
00111   amin = ((n1 + nfantome)*izrmin - nfantome*izrmax) / n1 ;
00112   amax = ((n1 + nfantome)*izrmax - nfantome*izrmin) / n1 ;
00113   zri = fait_grille1D(amin, amax, n1+2*fantome+1) ;
00114   
00115 }
00116 
00117 // Constructeur 3D
00118 Grille_val::Grille_val(const double izrmin, const double izrmax, 
00119                const int n3, const int n2, const int n1, 
00120                const int itype_t, const int itype_p, 
00121                const int fantome ): dim(n3,n2,n1), nfantome(fantome), 
00122   type_t(itype_t), type_p(itype_p) 
00123 {
00124   zrmin = new double(izrmin) ;
00125   zrmax = new double(izrmax) ;
00126   double amin = ((n1 + nfantome - 0.5)*izrmin -
00127          (nfantome-0.5)*izrmax) / n1 ;
00128   double amax = ((n1 + nfantome - 0.5)*izrmax -
00129          (nfantome-0.5)*izrmin) / n1 ;
00130   zr = fait_grille1D(amin, amax, n1+2*fantome) ;
00131   amin = ((n1 + nfantome)*izrmin - nfantome*izrmax) / n1 ;
00132   amax = ((n1 + nfantome)*izrmax - nfantome*izrmin) / n1 ;
00133   zri = fait_grille1D(amin, amax, n1+2*fantome+1) ;
00134 }
00135 
00136 
00137 // Constructeur par recopie
00138 Grille_val::Grille_val(const Grille_val & titi): dim(titi.dim), 
00139   nfantome(titi.nfantome), type_t(titi.type_t), type_p(titi.type_p)
00140 {
00141   assert(titi.zr != 0x0) ;
00142   assert(titi.zri != 0x0) ;
00143   assert(titi.zrmin != 0x0) ;
00144   assert(titi.zrmax != 0x0) ;
00145   zr = new Tbl(*titi.zr) ;
00146   zri = new Tbl(*titi.zri) ;
00147   zrmin = new double(*titi.zrmin) ;
00148   zrmax = new double(*titi.zrmax) ;
00149 
00150 }
00151     
00152 // Depuis un fichier
00153 Grille_val::Grille_val(FILE* fd):dim(fd) {
00154 
00155   fread_be(&nfantome, sizeof(int), 1, fd) ;     
00156   fread_be(&type_t, sizeof(int), 1, fd) ;       
00157   fread_be(&type_p, sizeof(int), 1, fd) ;       
00158   
00159   double amin, amax ;
00160   fread_be(&amin, sizeof(double), 1, fd) ;      
00161   fread_be(&amax, sizeof(double), 1, fd) ;      
00162   zrmin = new double(amin) ;
00163   zrmax = new double(amax) ;
00164   zr = new Tbl(fd) ;
00165   zri = new Tbl(fd) ;
00166   
00167 }
00168 
00169             //--------------//
00170             // Destructeurs //
00171             //--------------//
00172 
00173 // Destructeur
00174 Grille_val::~Grille_val() {
00175 
00176   assert(zr != 0x0) ;
00177   assert(zri != 0x0) ;
00178   assert(zrmin != 0x0) ; 
00179   assert(zrmax != 0x0) ; 
00180   delete zr ;
00181   delete zri ;
00182   delete zrmin ;
00183   delete zrmax ; 
00184 
00185 }
00186 
00187             //-------------//
00188             // Affectation //
00189             //-------------//
00190 
00191 // Depuis une autre Grille_val
00192 void Grille_val::operator=(const Grille_val & titi) {
00193 
00194   dim = titi.dim ;
00195   nfantome = titi.nfantome ;
00196   type_t = titi.type_t ;
00197   type_p = titi.type_p ;
00198 
00199   assert(titi.zr != 0x0) ;
00200   assert(titi.zri != 0x0) ;
00201   assert(titi.zrmin != 0x0) ;
00202   assert(titi.zrmax != 0x0) ;
00203   
00204   for (int i=0; i<dim.dim[0]+2*nfantome; i++) 
00205     zr->t[i] = titi.zr->t[i] ;
00206   for (int i=0; i<dim.dim[0] + 2*nfantome + 1; i++) 
00207     zri->t[i] = titi.zri->t[i] ;
00208   *zrmin = *titi.zrmin ;
00209   *zrmax = *titi.zrmax ;
00210 }
00211     
00212             //------------//
00213             // Sauvegarde //
00214             //------------//
00215 
00216 // Sauve dans un fchier
00217 void Grille_val::sauve(FILE* fd) const {
00218 
00219   dim.sauve(fd) ;
00220   fwrite_be(&nfantome, sizeof(int), 1, fd) ;        
00221   fwrite_be(&type_t, sizeof(int), 1, fd) ;      
00222   fwrite_be(&type_p, sizeof(int), 1, fd) ;      
00223   
00224   fwrite_be(zrmin, sizeof(double), 1, fd) ;     
00225   fwrite_be(zrmax, sizeof(double), 1, fd) ;     
00226   
00227   zr->sauve(fd) ; zri->sauve(fd) ;
00228 
00229 }
00230     
00231             //------------//
00232             // Impression //
00233             //------------//
00234 
00235 // Operateurs <<
00236 ostream& operator<<(ostream& o, const Grille_val & titi) {
00237   titi >> o ;
00238   return o ;
00239 }
00240 
00241 ostream& Grille_val::operator>>(ostream& o) const {
00242   int ndim = dim.ndim ;
00243   int nfant = nfantome ;
00244   o.precision(4);
00245   o.setf(ios::showpoint);
00246   o << "*** Grille_val " << ndim << "D" << "   size: " ; 
00247   for (int i = 0; i<ndim-1; i++) {
00248     o << dim.dim[ndim-1-i] ;
00249     if (ndim-i == 3) o << " x " ;
00250     if (ndim-i == 2) o << " x " ;
00251   } 
00252   o << dim.dim[0] << endl ;
00253   o << nfant << " hidden cells on each side " << endl ;
00254   return o ;
00255 }
00256     
00257             //------------------------------------//
00258             //      class Gval_cart       //
00259             //------------------------------------//
00260 
00261 /*********************************************************************
00262  *
00263  *         Cartesian grid for Godunov-type integration schemes
00264  *
00265  *********************************************************************/
00266 
00267             //---------------//
00268             // Constructeurs //
00269             //---------------//
00270 
00271 // Constructeur 1D
00272 Gval_cart::Gval_cart(const double izmin, const double izmax, const int nz,
00273              const int fantome)
00274   :Grille_val(izmin, izmax, nz, fantome), 
00275   xmin(0x0), xmax(0x0),
00276   ymin(0x0), ymax(0x0),
00277   x(0x0), xi(0x0),
00278   y(0x0), yi(0x0){
00279 }
00280 
00281 // Constructeur 2D
00282 Gval_cart::Gval_cart(const double ixmin, const double ixmax, const 
00283              double izmin, const double izmax, const int nx, 
00284              const int nz, const int itype_t, const int fantome)
00285   :Grille_val(izmin, izmax, nx, nz, itype_t, fantome),
00286    ymin(0x0), ymax(0x0),
00287    y(0x0), yi(0x0) 
00288 {
00289   assert ( (type_t!=SYM) || (izmin >= double(0)) ) ;
00290   
00291   xmin = new double(ixmin) ;
00292   xmax = new double(ixmax) ;
00293   double amin = ((nx + nfantome - 0.5)*ixmin -
00294       (nfantome-0.5)*ixmax) / nx ;
00295   double amax = ((nx + nfantome - 0.5)*ixmax -
00296       (nfantome-0.5)*ixmin) / nx ;
00297   x = fait_grille1D(amin, amax, nx+2*fantome) ;
00298   amin = ((nx + nfantome)*ixmin - nfantome*ixmax) / nx ;
00299   amax = ((nx + nfantome)*ixmax - nfantome*ixmin) / nx ;
00300   xi = fait_grille1D(amin, amax, nx+2*fantome+1) ;
00301   
00302 }
00303   
00304 // Constructeur 3D
00305 Gval_cart::Gval_cart(const double iymin, const double iymax, 
00306              const double ixmin, const double ixmax, const 
00307              double izmin, const double izmax, const int ny,
00308              const int nx, const int nz, const int itype_t, 
00309              const int itype_p, const int fantome)
00310   :Grille_val(izmin, izmax, ny, nx, nz, itype_t, itype_p, fantome)
00311 {
00312   assert ( (type_t!=SYM) || (izmin >= double(0)) ) ;
00313   assert ( (type_p!=SYM) || (iymin >= double(0)) ) ; 
00314   
00315   xmin = new double(ixmin) ;
00316   xmax = new double(ixmax) ;
00317   double amin = ((nx + nfantome - 0.5)*ixmin -
00318       (nfantome-0.5)*ixmax) / nx ;
00319   double amax = ((nx + nfantome - 0.5)*ixmax -
00320       (nfantome-0.5)*ixmin) / nx ;
00321   x = fait_grille1D(amin, amax, nx+2*fantome) ;
00322   amin = ((nx + nfantome)*ixmin - nfantome*ixmax) / nx ;
00323   amax = ((nx + nfantome)*ixmax - nfantome*ixmin) / nx ;
00324   xi = fait_grille1D(amin, amax, nx+2*fantome+1) ;
00325   
00326   ymin = new double(iymin) ;
00327   ymax = new double(iymax) ;
00328   amin = ((ny + nfantome - 0.5)*iymin -
00329       (nfantome-0.5)*iymax) / ny ;
00330   amax = ((ny + nfantome - 0.5)*iymax -
00331       (nfantome-0.5)*iymin) / ny ;
00332   y = fait_grille1D(amin, amax, ny+2*fantome) ;
00333   amin = ((ny + nfantome)*iymin - nfantome*iymax) / ny ;
00334   amax = ((ny + nfantome)*iymax - nfantome*iymin) / ny ;
00335   yi = fait_grille1D(amin, amax, ny+2*fantome+1) ;
00336  
00337 }
00338 
00339 // Constructeur par recopie
00340 Gval_cart::Gval_cart(const Gval_cart& titi)
00341   :Grille_val(titi) 
00342 {
00343   if (titi.x != 0x0) x = new Tbl(*titi.x) ;
00344   if (titi.xi != 0x0) xi = new Tbl(*titi.xi) ;
00345   if (titi.xmin != 0x0) xmin = new double(*titi.xmin) ;
00346   if (titi.xmax != 0x0) xmax = new double(*titi.xmax) ;
00347   if (titi.y != 0x0) y = new Tbl(*titi.y) ;
00348   if (titi.yi != 0x0) yi = new Tbl(*titi.yi) ;
00349   if (titi.ymin != 0x0) ymin = new double(*titi.ymin) ;
00350   if (titi.ymax != 0x0) ymax = new double(*titi.ymax) ;
00351 
00352 }
00353    
00354 // Depuis un fichier
00355 Gval_cart::Gval_cart(FILE* fd)
00356   : Grille_val(fd)
00357 {
00358   double amin, amax ;
00359   if (dim.ndim >= 2) {
00360     fread_be(&amin, sizeof(double), 1, fd) ;        
00361     fread_be(&amax, sizeof(double), 1, fd) ;        
00362     xmin = new double(amin) ;
00363     xmax = new double(amax) ;
00364     x = new Tbl(fd) ;
00365     xi = new Tbl(fd) ;
00366   }
00367   if (dim.ndim >= 3) {
00368     fread_be(&amin, sizeof(double), 1, fd) ;        
00369     fread_be(&amax, sizeof(double), 1, fd) ;        
00370     ymin = new double(amin) ;
00371     ymax = new double(amax) ;
00372     y = new Tbl(fd) ;
00373     yi = new Tbl(fd) ;
00374   }
00375 }
00376   
00377 
00378             //--------------//
00379             // Destructeurs //
00380             //--------------//
00381 
00382 // Destructeur
00383 Gval_cart::~Gval_cart() {
00384 
00385   if (x != 0x0) delete x ;
00386   if (xi != 0x0) delete xi ;
00387   if (xmin != 0x0) delete xmin ;
00388   if (xmax != 0x0) delete xmax ; 
00389   if (y != 0x0) delete y ;
00390   if (yi != 0x0) delete yi ;
00391   if (ymin != 0x0) delete ymin ;
00392   if (ymax != 0x0) delete ymax ; 
00393   
00394 }
00395 
00396             //-------------//
00397             // Affectation //
00398             //-------------//
00399 
00400 // Depuis une autre Grille_val
00401 void Gval_cart::operator=(const Gval_cart& titi) {
00402 
00403   Grille_val::operator=(titi) ;
00404 
00405   if (titi.x != 0x0) *x = *titi.x ;
00406   if (titi.xi != 0x0) *xi = *titi.xi ;
00407   if (titi.xmin != 0x0) *xmin = *titi.xmin ;
00408   if (titi.xmax != 0x0) *xmax = *titi.xmax ;
00409   if (titi.y != 0x0) *y = *titi.y ;
00410   if (titi.yi != 0x0) *yi = *titi.yi ;
00411   if (titi.ymin != 0x0) *ymin = *titi.ymin ;
00412   if (titi.ymax != 0x0) *ymax = *titi.ymax ;
00413 }
00414 
00415             //------------//
00416             // Sauvegarde //
00417             //------------//
00418 
00419 // save onto a file
00420 void Gval_cart::sauve(FILE* fd) const {
00421 
00422   Grille_val::sauve(fd) ;
00423 
00424   if (dim.ndim >= 2) {
00425     fwrite_be(xmin, sizeof(double), 1, fd) ;        
00426     fwrite_be(xmax, sizeof(double), 1, fd) ;        
00427     x->sauve(fd) ; xi->sauve(fd) ;
00428   }
00429   if (dim.ndim >= 3) {
00430     fwrite_be(ymin, sizeof(double), 1, fd) ;        
00431     fwrite_be(ymax, sizeof(double), 1, fd) ;        
00432     y->sauve(fd) ; yi->sauve(fd) ;
00433   }
00434 
00435 }
00436     
00437 
00438             //------------//
00439             // Impression //
00440             //------------//
00441 
00442 // Operateurs <<
00443 ostream& Gval_cart::operator>>(ostream& o) const {
00444 
00445   int ndim = dim.ndim;
00446   Grille_val::operator>>(o) ;
00447 
00448   o << "*** Cartesian grid ***" << endl ;
00449 
00450   switch (ndim) {
00451 
00452   case 1 : {
00453     o << "Z nodes: " << endl ;
00454     for (int i=0; i<dim.dim[0]; i++) {
00455       o << zr->set(i+nfantome) << " " ;
00456     }
00457     o << endl ;
00458     break ;
00459   }
00460   
00461   
00462   case 2 : {
00463     o << "X nodes: " << endl ;
00464     for (int j=0 ; j<dim.dim[1] ; j++) {
00465       o << " " << x->set(j+nfantome) ;
00466     }
00467     o << endl ;
00468     
00469     o << "Z nodes: " << endl ;
00470     
00471     for (int i=0 ; i<dim.dim[0] ; i++) {
00472       o << " " << zr->set(i+nfantome) ;
00473     }
00474     o << endl ;
00475     break ;    
00476   }
00477   
00478   case 3 : {
00479     o << "Y nodes: " << endl ;
00480     for (int k=0 ; k<dim.dim[2] ; k++) {
00481       o << " " << y->set(k+nfantome) ;
00482     }
00483     o << endl ;
00484 
00485     o << "X nodes: " << endl ;
00486     for (int j=0 ; j<dim.dim[1] ; j++) {
00487       o << " " << x->set(j+nfantome) ;
00488     }
00489     o << endl ;
00490     
00491     o << "Z nodes: " << endl ;
00492     
00493     for (int i=0 ; i<dim.dim[0] ; i++) {
00494       o << " " << zr->set(i+nfantome) ;
00495     }
00496     o << endl ;
00497     break ;
00498   }
00499   
00500   default : {
00501     cout << "operator>> Gval_cart : unexpected dimension !" << endl ;
00502     cout << " ndim = " << ndim << endl ;        
00503     abort() ;
00504     break ;
00505   }
00506   }
00507   
00508   return o ;
00509 }
00510             //------------------------------------//
00511             //      class Gval_spher      //
00512             //------------------------------------//
00513 
00514 /*********************************************************************
00515  *
00516  *         Spherical grids for Godunov-type integration schemes
00517  *
00518  *********************************************************************/
00519 
00520             //---------------//
00521             // Constructeurs //
00522             //---------------//
00523 
00524 // Constructeur 1D
00525 Gval_spher::Gval_spher(const double irmin, const double irmax, const int nr,
00526              const int fantome)
00527   :Grille_val(irmin, irmax, nr, fantome), 
00528   tet(0x0), teti(0x0),
00529   phi(0x0), phii(0x0){
00530   assert(irmin>=double(0)) ;
00531 }
00532 
00533 // Constructeur 2D
00534 Gval_spher::Gval_spher(const double irmin, const double irmax, const int nt, 
00535              const int nr, const int itype_t, const int fantome)
00536   :Grille_val(irmin, irmax, nt, nr, itype_t, fantome),
00537    phi(0x0), phii(0x0) 
00538 {
00539   assert (irmin >= double(0)) ;
00540   
00541   double tetmin = 0. ;
00542   double tetmax = (type_t == SYM ? M_PI_2 : M_PI) ;
00543   double amin = ((nt + nfantome - 0.5)*tetmin -
00544       (nfantome-0.5)*tetmax) / nt ;
00545   double amax = ((nt + nfantome - 0.5)*tetmax -
00546       (nfantome-0.5)*tetmin) / nt ;
00547   tet = fait_grille1D(amin, amax, nt+2*fantome) ;
00548   amin = ((nt + nfantome)*tetmin - nfantome*tetmax) / nt ;
00549   amax = ((nt + nfantome)*tetmax - nfantome*tetmin) / nt ;
00550   teti = fait_grille1D(amin, amax, nt+2*fantome+1) ;
00551   
00552 }
00553   
00554 // Constructeur 3D
00555 Gval_spher::Gval_spher(const double irmin, const double irmax, const int np,
00556              const int nt, const int nr, const int itype_t, 
00557              const int itype_p, const int fantome)
00558   :Grille_val(irmin, irmax, np, nt, nr, itype_t, itype_p, fantome)
00559 {
00560   assert (irmin >= double(0))  ;
00561   
00562 
00563   double tetmin = 0. ;
00564   double tetmax = (type_t == SYM ? M_PI_2 : M_PI) ;
00565   double amin = ((nt + nfantome - 0.5)*tetmin -
00566       (nfantome-0.5)*tetmax) / nt ;
00567   double amax = ((nt + nfantome - 0.5)*tetmax -
00568       (nfantome-0.5)*tetmin) / nt ;
00569   tet = fait_grille1D(amin, amax, nt+2*fantome) ;
00570   amin = ((nt + nfantome)*tetmin - nfantome*tetmax) / nt ;
00571   amax = ((nt + nfantome)*tetmax - nfantome*tetmin) / nt ;
00572   teti = fait_grille1D(amin, amax, nt+2*fantome+1) ;
00573   
00574   double phimin = 0. ;
00575   double phimax = ( type_p == SYM ? M_PI : 2.*M_PI) ; //??? a verifier!
00576   amin = ((np + nfantome - 0.5)*phimin -
00577       (nfantome-0.5)*phimax) / np ;
00578   amax = ((np + nfantome - 0.5)*phimax -
00579       (nfantome-0.5)*phimin) / np ;
00580   phi = fait_grille1D(amin, amax, np+2*fantome) ;
00581   amin = ((np + nfantome)*phimin - nfantome*phimax) / np ;
00582   amax = ((np + nfantome)*phimax - nfantome*phimin) / np ;
00583   phii = fait_grille1D(amin, amax, np+2*fantome+1) ;
00584  
00585 }
00586 
00587 // Constructeur par recopie
00588 Gval_spher::Gval_spher(const Gval_spher& titi)
00589   :Grille_val(titi) 
00590 {
00591   if (titi.tet != 0x0) tet = new Tbl(*titi.tet) ;
00592   if (titi.teti != 0x0) teti = new Tbl(*titi.teti) ;
00593   if (titi.phi != 0x0) phi = new Tbl(*titi.phi) ;
00594   if (titi.phii != 0x0) phii = new Tbl(*titi.phii) ;
00595 
00596 }
00597    
00598 // Depuis un fichier
00599 Gval_spher::Gval_spher(FILE* fd)
00600   : Grille_val(fd)
00601 {
00602   if (dim.ndim >= 2) {
00603     tet = new Tbl(fd) ;
00604     teti = new Tbl(fd) ;
00605   }
00606   if (dim.ndim >= 3) {
00607     phi = new Tbl(fd) ;
00608     phii = new Tbl(fd) ;
00609   }
00610 }
00611   
00612             //--------------//
00613             // Destructeurs //
00614             //--------------//
00615 
00616 // Destructeur
00617 Gval_spher::~Gval_spher() {
00618 
00619   if (tet != 0x0) delete tet ;
00620   if (teti != 0x0) delete teti ;
00621   if (phi != 0x0) delete phi ;
00622   if (phii != 0x0) delete phii ;
00623   
00624 }
00625 
00626             //-------------//
00627             // Affectation //
00628             //-------------//
00629 
00630 // Depuis une autre Grille_val
00631 void Gval_spher::operator=(const Gval_spher& titi) {
00632 
00633   Grille_val::operator=(titi) ;
00634 
00635   if (titi.tet != 0x0) *tet = *titi.tet ;
00636   if (titi.teti != 0x0) *teti = *titi.teti ;
00637   if (titi.phi != 0x0) *phi = *titi.phi ;
00638   if (titi.phii != 0x0) *phii = *titi.phii ;
00639 }
00640 
00641             //------------//
00642             // Sauvegarde //
00643             //------------//
00644 
00645 // save onto a file
00646 void Gval_spher::sauve(FILE* fd) const {
00647 
00648   Grille_val::sauve(fd) ;
00649 
00650   if (dim.ndim >= 2) {
00651     tet->sauve(fd) ; 
00652     teti->sauve(fd) ;
00653   }
00654   if (dim.ndim >= 3) {
00655     phi->sauve(fd) ; 
00656     phii->sauve(fd) ;
00657   }
00658 
00659 }
00660     
00661             //------------//
00662             // Impression //
00663             //------------//
00664 
00665 // Operateurs <<
00666 ostream& Gval_spher::operator>>(ostream& o) const {
00667 
00668   int ndim = dim.ndim;
00669   Grille_val::operator>>(o) ;
00670 
00671   o << "*** Spherical grid ***" << endl ;
00672 
00673   switch (ndim) {
00674 
00675   case 1 : {
00676     o << "R nodes: " << endl ;
00677     for (int i=0; i<dim.dim[0]; i++) {
00678       o << zr->set(i+nfantome) << " " ;
00679     }
00680     o << endl ;
00681     break ;
00682   }
00683   
00684   
00685   case 2 : {
00686     o << "THETA nodes: " << endl ;
00687     for (int j=0 ; j<dim.dim[1] ; j++) {
00688       o << " " << tet->set(j+nfantome) ;
00689     }
00690     o << endl ;
00691     
00692     o << "R nodes: " << endl ;
00693     
00694     for (int i=0 ; i<dim.dim[0] ; i++) {
00695       o << " " << zr->set(i+nfantome) ;
00696     }
00697     o << endl ;
00698     break ;    
00699   }
00700   
00701   case 3 : {
00702     o << "PHI nodes: " << endl ;
00703     for (int k=0 ; k<dim.dim[2] ; k++) {
00704       o << " " << phi->set(k+nfantome) ;
00705     }
00706     o << endl ;
00707 
00708     o << "THETA nodes: " << endl ;
00709     for (int j=0 ; j<dim.dim[1] ; j++) {
00710       o << " " << tet->set(j+nfantome) ;
00711     }
00712     o << endl ;
00713     
00714     o << "R nodes: " << endl ;
00715     
00716     for (int i=0 ; i<dim.dim[0] ; i++) {
00717       o << " " << zr->set(i+nfantome) ;
00718     }
00719     o << endl ;
00720     break ;
00721   }
00722   
00723   default : {
00724     cout << "operator>> Gval_spher : unexpected dimension !" << endl ;
00725     cout << " ndim = " << ndim << endl ;        
00726     abort() ;
00727     break ;
00728   }
00729   }
00730   
00731   return o ;
00732 }

Generated on Tue Feb 7 01:35:17 2012 for LORENE by  doxygen 1.4.6