mg3d.C

00001 /*
00002  * Methods of class Mg3d
00003  *
00004  */
00005 
00006 /*
00007  *   Copyright (c) 1999-2000 Jean-Alain Marck
00008  *   Copyright (c) 1999-2001 Eric Gourgoulhon
00009  *
00010  *   This file is part of LORENE.
00011  *
00012  *   LORENE is free software; you can redistribute it and/or modify
00013  *   it under the terms of the GNU General Public License as published by
00014  *   the Free Software Foundation; either version 2 of the License, or
00015  *   (at your option) any later version.
00016  *
00017  *   LORENE is distributed in the hope that it will be useful,
00018  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  *   GNU General Public License for more details.
00021  *
00022  *   You should have received a copy of the GNU General Public License
00023  *   along with LORENE; if not, write to the Free Software
00024  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025  *
00026  */
00027 
00028 
00029 char mg3d_C[] = "$Header: /cvsroot/Lorene/C++/Source/Mg3d/mg3d.C,v 1.15 2012/01/17 10:37:42 j_penner Exp $" ;
00030 
00031 /*
00032  * $Id: mg3d.C,v 1.15 2012/01/17 10:37:42 j_penner Exp $
00033  * $Log: mg3d.C,v $
00034  * Revision 1.15  2012/01/17 10:37:42  j_penner
00035  * added a constructor that treats all domains as type FIN
00036  *
00037  * Revision 1.14  2008/08/19 06:42:00  j_novak
00038  * Minor modifications to avoid warnings with gcc 4.3. Most of them concern
00039  * cast-type operations, and constant strings that must be defined as const char*
00040  *
00041  * Revision 1.13  2007/12/11 15:28:15  jl_cornou
00042  * Jacobi(0,2) polynomials partially implemented
00043  *
00044  * Revision 1.12  2006/05/17 13:17:03  j_novak
00045  * New member g_angu_1dom, the one-domain angular grid associated with the
00046  * current grid.
00047  *
00048  * Revision 1.11  2005/10/07 08:47:21  j_novak
00049  * Addition of the pointer g_non_axi on a grid, with at least 5 points in the
00050  * theta direction and 4 in the phi one (for tensor rotations).
00051  *
00052  * Revision 1.10  2004/07/06 13:36:29  j_novak
00053  * Added methods for desaliased product (operator |) only in r direction.
00054  *
00055  * Revision 1.9  2003/10/27 16:21:54  e_gourgoulhon
00056  * Treated the special case nz=1 in the simplified constructor.
00057  *
00058  * Revision 1.8  2003/06/20 14:50:15  f_limousin
00059  * Add the operator==
00060  *
00061  * Revision 1.7  2003/06/18 08:45:27  j_novak
00062  * In class Mg3d: added the member get_radial, returning only a radial grid
00063  * For dAlembert solver: the way the coefficients of the operator are defined has been changed.
00064  *
00065  * Revision 1.6  2002/10/16 14:36:42  j_novak
00066  * Reorganization of #include instructions of standard C++, in order to
00067  * use experimental version 3 of gcc.
00068  *
00069  * Revision 1.5  2002/05/07 07:36:03  e_gourgoulhon
00070  * Compatibilty with xlC compiler on IBM SP2:
00071  *    suppressed the parentheses around argument of instruction new:
00072  *  e.g.   t = new (Tbl *[nzone])  -->   t = new Tbl*[nzone]
00073  *
00074  * Revision 1.4  2001/12/12 09:23:46  e_gourgoulhon
00075  * Parameter compact added to the simplified constructor of class Mg3d
00076  *
00077  * Revision 1.3  2001/12/11 06:48:30  e_gourgoulhon
00078  * Addition of the simplified constructor
00079  *
00080  * Revision 1.2  2001/12/04 21:27:54  e_gourgoulhon
00081  *
00082  * All writing/reading to a binary file are now performed according to
00083  * the big endian convention, whatever the system is big endian or
00084  * small endian, thanks to the functions fwrite_be and fread_be
00085  *
00086  * Revision 1.1.1.1  2001/11/20 15:19:27  e_gourgoulhon
00087  * LORENE
00088  *
00089  * Revision 2.10  2001/05/26  14:50:46  eric
00090  * *** empty log message ***
00091  *
00092  * Revision 2.9  2001/05/26  13:25:59  eric
00093  * Ajout du membre g_twice (grille double pour le desaliasing)
00094  * Modif de la declaration de g_angu (pointeur mutable)
00095  *   g_twice et g_angu ne sont calcules que si necessaire (cad si
00096  *   on appelle la fonction get_twice() ou get_angu()).
00097  *
00098  * Revision 2.8  2000/03/22  13:38:51  eric
00099  * Remplacement des iendl par endl dans <<
00100  *
00101  * Revision 2.7  1999/10/12  15:04:29  eric
00102  * *** empty log message ***
00103  *
00104  * Revision 2.6  1999/10/12  15:03:30  eric
00105  * *** empty log message ***
00106  *
00107  * Revision 2.5  1999/09/30  14:58:16  eric
00108  * Operator!= declare const
00109  *
00110  * Revision 2.4  1999/09/30  14:12:04  eric
00111  * sauve declaree const.
00112  *
00113  * Revision 2.3  1999/09/30  12:52:52  eric
00114  * Depoussierage.
00115  * Documentation.
00116  *
00117  * Revision 2.2  1999/03/01  14:35:21  eric
00118  * Modif affichage (operator<<)
00119  *
00120  *
00121  * $Header: /cvsroot/Lorene/C++/Source/Mg3d/mg3d.C,v 1.15 2012/01/17 10:37:42 j_penner Exp $
00122  *
00123  */
00124 
00125 // C Headers
00126 #include <stdlib.h>
00127 #include <assert.h>
00128 
00129 // Lorene headers
00130 #include "grilles.h"
00131 #include "type_parite.h"
00132 #include "utilitaires.h"
00133 
00134         //--------------//
00135         // Multi-grille //
00136         //--------------//
00137 
00138 
00139 //=============================================================================
00140 //    General constructor
00141 //=============================================================================
00142 
00143 
00144 Mg3d::Mg3d(int nz,
00145     int nbr[], int typr[], int nbt[], int typt, int nbp[], int typp)
00146     : nzone(nz), type_t(typt), type_p(typp)
00147 {
00148 
00149     // Type d'echantillonnage dans chaque zone
00150     type_r = new int[nz];
00151     for (int i=0 ; i<nz ; i++) {
00152     type_r[i] = typr[i];
00153     }
00154 
00155     // Nombre de points
00156     nr = new int[nz];
00157     nt = new int[nz];
00158     np = new int[nz];
00159     for (int i=0 ; i<nz ; i++) {
00160     nr[i] = nbr[i] ;
00161     nt[i] = nbt[i] ;
00162     np[i] = nbp[i] ;
00163     }
00164 
00165     // Les grilles
00166     // -----------
00167     g = new Grille3d*[nz] ;
00168 
00169     for (int i=0; i<nz; i++) {
00170 
00171     //... Echantillonnage selon le type demande:
00172     switch (type_p) {
00173 //----------------------------------------------------------------------------
00174     case NONSYM :    // echantillonnage en phi sur [0, 2 pi[
00175 //----------------------------------------------------------------------------
00176         switch (type_t) {
00177         case SYM :    // echantillonnage en theta sur [0,pi/2]
00178             switch (type_r[i]) {
00179             case FIN :    // echantillonnage fin
00180                 g[i] = new
00181                  Grille3d_feq(nbr[i], nbt[i], nbp[i]) ;
00182                 break ;
00183             case FINJAC :   // echantillonnage fin avec Jacobi
00184                 g[i] = new
00185                  Grille3d_fjeq(nbr[i], nbt[i], nbp[i]) ;
00186                 break ;
00187             case RARE :    // echantillonnage rarefie
00188                 g[i] = new
00189                  Grille3d_req(nbr[i], nbt[i], nbp[i]) ;
00190                 break ;
00191             case UNSURR :    // echantillonnage fin en 1/r
00192                 g[i] = new
00193                  Grille3d_ieq(nbr[i], nbt[i], nbp[i]) ;
00194                 break ;
00195 
00196             default :
00197             cout << "Mg3d::Mg3d : Le cas type_p = " << type_p
00198                  << " , type_t = " << type_t
00199                  << " et type_r = " << type_r[i] << endl ;
00200             cout << "n'est pas prevu !" << endl ;
00201             abort() ;
00202             
00203             }   // fin des differents types d'echantillonnage en r
00204             break ;  // fin du cas type_t = SYM et type_p = NONSYM
00205 
00206         case NONSYM :    // echantillonnage en theta sur [0,pi]
00207             switch (type_r[i]) {
00208             case FIN :    // echantillonnage fin
00209                 g[i] = new
00210                  Grille3d_f(nbr[i], nbt[i], nbp[i]) ;
00211                 break ;
00212             case FINJAC :   // echantillonnage fin avec Jacobi
00213                 g[i] = new 
00214                  Grille3d_fj(nbr[i], nbt[i], nbp[i]) ;
00215                 break ;
00216             case RARE :    // echantillonnage rarefie
00217                 g[i] = new
00218                  Grille3d_r(nbr[i], nbt[i], nbp[i]) ;
00219                 break ;
00220             case UNSURR :    // echantillonnage fin en 1/r
00221                 g[i] = new
00222                  Grille3d_i(nbr[i], nbt[i], nbp[i]) ;
00223                 break ;
00224 
00225             default :
00226             cout << "Mg3d::Mg3d : Le cas type_p = " << type_p
00227                  << " , type_t = " << type_t
00228                  << " et type_r = " << type_r[i] << endl ;
00229             cout << "n'est pas prevu !" << endl ;
00230             abort() ;
00231             
00232             }   // fin des differents types d'echantillonnage en r
00233             break ;  // fin du cas type_t = NONSYM et type_p = NONSYM
00234 
00235         default :
00236             cout << "Mg3d::Mg3d : Le cas type_p = " << type_p
00237              << " et type_t = " << type_t <<
00238                 " n'est pas prevu !" << endl ;
00239             abort() ;
00240         
00241         }  // fin des differents types d'echantillonnage en theta
00242         break ; // fin du cas type_p = NONSYM
00243 
00244 //----------------------------------------------------------------------------
00245     case SYM :    // echantillonnage en phi sur [0,pi[
00246 //----------------------------------------------------------------------------
00247         switch (type_t) {
00248         case SYM :    // echantillonnage en theta sur [0,pi/2]
00249             switch (type_r[i]) {
00250             case FIN :    // echantillonnage fin
00251                 g[i] = new
00252                  Grille3d_fs(nbr[i], nbt[i], nbp[i]) ;
00253                 break ;
00254             case FINJAC :    // echantillonnage fin avec Jacobi
00255                 g[i] = new
00256                  Grille3d_fjs(nbr[i], nbt[i], nbp[i]) ;
00257                 break ;
00258             case RARE :    // echantillonnage rarefie
00259                 g[i] = new
00260                  Grille3d_rs(nbr[i], nbt[i], nbp[i]) ;
00261                 break ;
00262             case UNSURR :    // echantillonnage fin en 1/r
00263                 g[i] = new
00264                  Grille3d_is(nbr[i], nbt[i], nbp[i]) ;
00265                 break ;
00266 
00267             default :
00268             cout << "Mg3d::Mg3d : Le cas type_p = " << type_p
00269                  << " , type_t = " << type_t
00270                  << " et type_r = " << type_r[i] << endl ;
00271             cout << "n'est pas prevu !" << endl ;
00272             abort() ;
00273             
00274             }   // fin des differents types d'echantillonnage en r
00275             break ;  // fin du cas type_t = SYM et type_p = SYM
00276 
00277         case NONSYM :    // echantillonnage en theta sur [0,pi/2]
00278             switch (type_r[i]) {
00279             case FIN :    // echantillonnage fin
00280                 g[i] = new
00281                  Grille3d_f2p(nbr[i], nbt[i], nbp[i]) ;
00282                 break ;
00283             case FINJAC :   // echantillonnage fin avec Jacobi
00284                 g[i] = new
00285                  Grille3d_fj2p(nbr[i], nbt[i], nbp[i]) ;
00286                 break ;
00287             case RARE :    // echantillonnage rarefie
00288                 g[i] = new
00289                  Grille3d_r2p(nbr[i], nbt[i], nbp[i]) ;
00290                 break ;
00291             case UNSURR :    // echantillonnage fin en 1/r
00292                 g[i] = new
00293                  Grille3d_i2p(nbr[i], nbt[i], nbp[i]) ;
00294                 break ;
00295 
00296             default :
00297             cout << "Mg3d::Mg3d : Le cas type_p = " << type_p
00298                  << " , type_t = " << type_t
00299                  << " et type_r = " << type_r[i] << endl ;
00300             cout << "n'est pas prevu !" << endl ;
00301             abort() ;
00302             
00303             }   // fin des differents types d'echantillonnage en r
00304             break ;  // fin du cas type_t = NONSYM et type_p = SYM
00305 
00306         default :
00307             cout << "Mg3d::Mg3d : Le cas type_p = " << type_p
00308              << " et type_t = " << type_t <<
00309                 " n'est pas prevu !" << endl ;
00310             abort() ;
00311         
00312         }  // fin des differents types d'echantillonnage en theta
00313         break ; // fin du cas type_p = SYM
00314 
00315 //----------------------------------------------------------------------------
00316     default :
00317 //----------------------------------------------------------------------------
00318         cout << "Mg3d::Mg3d : Le cas type_p = " << type_p
00319          << " n'est pas prevu !" << endl ;
00320         abort() ;
00321     }   // fin des differents types d'echantillonnage en phi
00322 }   // fin de la boucle sur les zones
00323 
00324     // Pointers on derived grids initiated to 0x0:
00325     // -------------------------------------------
00326 
00327     set_deriv_0x0() ;
00328 
00329 
00330 }
00331 
00332 //=============================================================================
00333 //    Simplified constructor
00334 //=============================================================================
00335 
00336 Mg3d::Mg3d(int nz, int nbr, int nbt, int nbp, int typt, int typp, 
00337        bool compact)
00338             : nzone(nz),
00339               type_t(typt),
00340               type_p(typp)   {
00341 
00342     // Type of r sampling in each domain: 
00343     type_r = new int[nz];
00344     type_r[0] = RARE ;
00345     for (int l=1; l<nz-1; l++) {
00346     type_r[l] = FIN ;
00347     }
00348     if (nz > 1) {
00349         type_r[nz-1] = compact ? UNSURR : FIN ;
00350     }
00351 
00352     // Same number of points in all domains:
00353     nr = new int[nz];
00354     nt = new int[nz];
00355     np = new int[nz];
00356     for (int l=0 ; l<nz ; l++) {
00357         nr[l] = nbr ;
00358         nt[l] = nbt ;
00359         np[l] = nbp ;
00360     }
00361 
00362     // Les grilles
00363     // -----------
00364     g = new Grille3d*[nz] ;
00365 
00366     for (int i=0; i<nz; i++) {
00367 
00368     //... Echantillonnage selon le type demande:
00369     switch (type_p) {
00370 //----------------------------------------------------------------------------
00371     case NONSYM :    // echantillonnage en phi sur [0, 2 pi[
00372 //----------------------------------------------------------------------------
00373         switch (type_t) {
00374         case SYM :    // echantillonnage en theta sur [0,pi/2]
00375             switch (type_r[i]) {
00376             case FIN :    // echantillonnage fin
00377                 g[i] = new
00378                  Grille3d_feq(nr[i], nt[i], np[i]) ;
00379                 break ;
00380             case RARE :    // echantillonnage rarefie
00381                 g[i] = new
00382                  Grille3d_req(nr[i], nt[i], np[i]) ;
00383                 break ;
00384             case UNSURR :    // echantillonnage fin en 1/r
00385                 g[i] = new
00386                  Grille3d_ieq(nr[i], nt[i], np[i]) ;
00387                 break ;
00388 
00389             default :
00390             cout << "Mg3d::Mg3d : Le cas type_p = " << type_p
00391                  << " , type_t = " << type_t
00392                  << " et type_r = " << type_r[i] << endl ;
00393             cout << "n'est pas prevu !" << endl ;
00394             abort() ;
00395             
00396             }   // fin des differents types d'echantillonnage en r
00397             break ;  // fin du cas type_t = SYM et type_p = NONSYM
00398 
00399         case NONSYM :    // echantillonnage en theta sur [0,pi]
00400             switch (type_r[i]) {
00401             case FIN :    // echantillonnage fin
00402                 g[i] = new
00403                  Grille3d_f(nr[i], nt[i], np[i]) ;
00404                 break ;
00405             case RARE :    // echantillonnage rarefie
00406                 g[i] = new
00407                  Grille3d_r(nr[i], nt[i], np[i]) ;
00408                 break ;
00409             case UNSURR :    // echantillonnage fin en 1/r
00410                 g[i] = new
00411                  Grille3d_i(nr[i], nt[i], np[i]) ;
00412                 break ;
00413 
00414             default :
00415             cout << "Mg3d::Mg3d : Le cas type_p = " << type_p
00416                  << " , type_t = " << type_t
00417                  << " et type_r = " << type_r[i] << endl ;
00418             cout << "n'est pas prevu !" << endl ;
00419             abort() ;
00420             
00421             }   // fin des differents types d'echantillonnage en r
00422             break ;  // fin du cas type_t = NONSYM et type_p = NONSYM
00423 
00424         default :
00425             cout << "Mg3d::Mg3d : Le cas type_p = " << type_p
00426              << " et type_t = " << type_t <<
00427                 " n'est pas prevu !" << endl ;
00428             abort() ;
00429         
00430         }  // fin des differents types d'echantillonnage en theta
00431         break ; // fin du cas type_p = NONSYM
00432 
00433 //----------------------------------------------------------------------------
00434     case SYM :    // echantillonnage en phi sur [0,pi[
00435 //----------------------------------------------------------------------------
00436         switch (type_t) {
00437         case SYM :    // echantillonnage en theta sur [0,pi/2]
00438             switch (type_r[i]) {
00439             case FIN :    // echantillonnage fin
00440                 g[i] = new
00441                  Grille3d_fs(nr[i], nt[i], np[i]) ;
00442                 break ;
00443             case RARE :    // echantillonnage rarefie
00444                 g[i] = new
00445                  Grille3d_rs(nr[i], nt[i], np[i]) ;
00446                 break ;
00447             case UNSURR :    // echantillonnage fin en 1/r
00448                 g[i] = new
00449                  Grille3d_is(nr[i], nt[i], np[i]) ;
00450                 break ;
00451 
00452             default :
00453             cout << "Mg3d::Mg3d : Le cas type_p = " << type_p
00454                  << " , type_t = " << type_t
00455                  << " et type_r = " << type_r[i] << endl ;
00456             cout << "n'est pas prevu !" << endl ;
00457             abort() ;
00458             
00459             }   // fin des differents types d'echantillonnage en r
00460             break ;  // fin du cas type_t = SYM et type_p = SYM
00461 
00462         case NONSYM :    // echantillonnage en theta sur [0,pi/2]
00463             switch (type_r[i]) {
00464             case FIN :    // echantillonnage fin
00465                 g[i] = new
00466                  Grille3d_f2p(nr[i], nt[i], np[i]) ;
00467                 break ;
00468             case RARE :    // echantillonnage rarefie
00469                 g[i] = new
00470                  Grille3d_r2p(nr[i], nt[i], np[i]) ;
00471                 break ;
00472             case UNSURR :    // echantillonnage fin en 1/r
00473                 g[i] = new
00474                  Grille3d_i2p(nr[i], nt[i], np[i]) ;
00475                 break ;
00476 
00477             default :
00478             cout << "Mg3d::Mg3d : Le cas type_p = " << type_p
00479                  << " , type_t = " << type_t
00480                  << " et type_r = " << type_r[i] << endl ;
00481             cout << "n'est pas prevu !" << endl ;
00482             abort() ;
00483             
00484             }   // fin des differents types d'echantillonnage en r
00485             break ;  // fin du cas type_t = NONSYM et type_p = SYM
00486 
00487         default :
00488             cout << "Mg3d::Mg3d : Le cas type_p = " << type_p
00489              << " et type_t = " << type_t <<
00490                 " n'est pas prevu !" << endl ;
00491             abort() ;
00492         
00493         }  // fin des differents types d'echantillonnage en theta
00494         break ; // fin du cas type_p = SYM
00495 
00496 //----------------------------------------------------------------------------
00497     default :
00498 //----------------------------------------------------------------------------
00499         cout << "Mg3d::Mg3d : Le cas type_p = " << type_p
00500          << " n'est pas prevu !" << endl ;
00501         abort() ;
00502     }   // fin des differents types d'echantillonnage en phi
00503 }   // fin de la boucle sur les zones
00504 
00505     // Pointers on derived grids initiated to 0x0:
00506     // -------------------------------------------
00507 
00508     set_deriv_0x0() ;
00509     
00510 }
00511 
00512 //=============================================================================
00513 //    Simplified shell constructor
00514 //    Note: This does not handle the nucleus or the CED!
00515 //=============================================================================
00516 
00517 Mg3d::Mg3d(int nz, int nbr, int nbt, int nbp, int typt, int typp)
00518             : nzone(nz),
00519               type_t(typt),
00520               type_p(typp)   {
00521 
00522     // Type of r sampling in each domain: 
00523     type_r = new int[nz];
00524     for (int l=0; l<nz; l++) {
00525     type_r[l] = FIN ;
00526     }
00527 
00528     // Same number of points in all domains:
00529     nr = new int[nz];
00530     nt = new int[nz];
00531     np = new int[nz];
00532     for (int l=0 ; l<nz ; l++) {
00533         nr[l] = nbr ;
00534         nt[l] = nbt ;
00535         np[l] = nbp ;
00536     }
00537 
00538     // Les grilles
00539     // -----------
00540     g = new Grille3d*[nz] ;
00541 
00542     for (int i=0; i<nz; i++) {
00543 
00544     //... Echantillonnage selon le type demande:
00545     switch (type_p) {
00546 //----------------------------------------------------------------------------
00547     case NONSYM :    // echantillonnage en phi sur [0, 2 pi[
00548 //----------------------------------------------------------------------------
00549         switch (type_t) {
00550         case SYM :    // echantillonnage en theta sur [0,pi/2]
00551             switch (type_r[i]) {
00552             case FIN :    // echantillonnage fin
00553                 g[i] = new
00554                  Grille3d_feq(nr[i], nt[i], np[i]) ;
00555                 break ;
00556             default :
00557             cout << "Mg3d::Mg3d : Le cas type_p = " << type_p
00558                  << " , type_t = " << type_t
00559                  << " et type_r = " << type_r[i] << endl ;
00560             cout << "n'est pas prevu !" << endl ;
00561             abort() ;
00562             
00563             }   // fin des differents types d'echantillonnage en r
00564             break ;  // fin du cas type_t = SYM et type_p = NONSYM
00565 
00566         case NONSYM :    // echantillonnage en theta sur [0,pi]
00567             switch (type_r[i]) {
00568             case FIN :    // echantillonnage fin
00569                 g[i] = new
00570                  Grille3d_f(nr[i], nt[i], np[i]) ;
00571                 break ;
00572             default :
00573             cout << "Mg3d::Mg3d : Le cas type_p = " << type_p
00574                  << " , type_t = " << type_t
00575                  << " et type_r = " << type_r[i] << endl ;
00576             cout << "n'est pas prevu !" << endl ;
00577             abort() ;
00578             
00579             }   // fin des differents types d'echantillonnage en r
00580             break ;  // fin du cas type_t = NONSYM et type_p = NONSYM
00581 
00582         default :
00583             cout << "Mg3d::Mg3d : Le cas type_p = " << type_p
00584              << " et type_t = " << type_t <<
00585                 " n'est pas prevu !" << endl ;
00586             abort() ;
00587         
00588         }  // fin des differents types d'echantillonnage en theta
00589         break ; // fin du cas type_p = NONSYM
00590 
00591 //----------------------------------------------------------------------------
00592     case SYM :    // echantillonnage en phi sur [0,pi[
00593 //----------------------------------------------------------------------------
00594         switch (type_t) {
00595         case SYM :    // echantillonnage en theta sur [0,pi/2]
00596             switch (type_r[i]) {
00597             case FIN :    // echantillonnage fin
00598                 g[i] = new
00599                  Grille3d_fs(nr[i], nt[i], np[i]) ;
00600                 break ;
00601             default :
00602             cout << "Mg3d::Mg3d : Le cas type_p = " << type_p
00603                  << " , type_t = " << type_t
00604                  << " et type_r = " << type_r[i] << endl ;
00605             cout << "n'est pas prevu !" << endl ;
00606             abort() ;
00607             
00608             }   // fin des differents types d'echantillonnage en r
00609             break ;  // fin du cas type_t = SYM et type_p = SYM
00610 
00611         case NONSYM :    // echantillonnage en theta sur [0,pi/2]
00612             switch (type_r[i]) {
00613             case FIN :    // echantillonnage fin
00614                 g[i] = new
00615                  Grille3d_f2p(nr[i], nt[i], np[i]) ;
00616                 break ;
00617             default :
00618             cout << "Mg3d::Mg3d : Le cas type_p = " << type_p
00619                  << " , type_t = " << type_t
00620                  << " et type_r = " << type_r[i] << endl ;
00621             cout << "n'est pas prevu !" << endl ;
00622             abort() ;
00623             
00624             }   // fin des differents types d'echantillonnage en r
00625             break ;  // fin du cas type_t = NONSYM et type_p = SYM
00626 
00627         default :
00628             cout << "Mg3d::Mg3d : Le cas type_p = " << type_p
00629              << " et type_t = " << type_t <<
00630                 " n'est pas prevu !" << endl ;
00631             abort() ;
00632         
00633         }  // fin des differents types d'echantillonnage en theta
00634         break ; // fin du cas type_p = SYM
00635 
00636 //----------------------------------------------------------------------------
00637     default :
00638 //----------------------------------------------------------------------------
00639         cout << "Mg3d::Mg3d : Le cas type_p = " << type_p
00640          << " n'est pas prevu !" << endl ;
00641         abort() ;
00642     }   // fin des differents types d'echantillonnage en phi
00643 }   // fin de la boucle sur les zones
00644 
00645     // Pointers on derived grids initiated to 0x0:
00646     // -------------------------------------------
00647 
00648     set_deriv_0x0() ;
00649     
00650 }
00651 
00652 
00653 //=============================================================================
00654 //    Constructor from a file
00655 //=============================================================================
00656 
00657 /*
00658  * Construction a partir d'un fichier.
00659  * Cette facon de faire est abominable. Cependant je ne vois pas comment
00660  * faire autrement... j.a.
00661  */
00662 Mg3d::Mg3d(FILE* fd)
00663 {
00664     // Lecture sur le fichier
00665     fread_be(&nzone, sizeof(int), 1, fd) ;      // nzone
00666     nr = new int[nzone] ;
00667     fread_be(nr, sizeof(int), nzone, fd) ;      // nr
00668     nt = new int[nzone] ;
00669     fread_be(nt, sizeof(int), nzone, fd) ;      // nt
00670     np = new int[nzone] ;
00671     fread_be(np, sizeof(int), nzone, fd) ;      // np
00672     type_r = new int[nzone] ;
00673     fread_be(type_r, sizeof(int), nzone, fd) ;  // type_r
00674     fread_be(&type_t, sizeof(int), 1, fd) ; // type_t
00675     fread_be(&type_p, sizeof(int), 1, fd) ; // type_p
00676 
00677     // Les grilles
00678     // -----------
00679 
00680     g = new Grille3d*[nzone] ;
00681 
00682     for (int i=0; i<nzone; i++) {
00683 
00684     //... Echantillonnage selon le type demande:
00685     switch (type_p) {
00686 //----------------------------------------------------------------------------
00687     case NONSYM :    // echantillonnage en phi sur [0, 2 pi[
00688 //----------------------------------------------------------------------------
00689         switch (type_t) {
00690         case SYM :    // echantillonnage en theta sur [0,pi/2]
00691             switch (type_r[i]) {
00692             case FIN :    // echantillonnage fin
00693                 g[i] = new
00694                  Grille3d_feq(nr[i], nt[i], np[i]) ;
00695                 break ;
00696             case FINJAC :    // echantillonage fin avec Jacobi
00697                 g[i] = new
00698                  Grille3d_fjeq(nr[i], nt[i], np[i]);
00699                 break ;
00700             case RARE :    // echantillonnage rarefie
00701                 g[i] = new
00702                  Grille3d_req(nr[i], nt[i], np[i]) ;
00703                 break ;
00704             case UNSURR :    // echantillonnage fin en 1/r
00705                 g[i] = new
00706                  Grille3d_ieq(nr[i], nt[i], np[i]) ;
00707                 break ;
00708 
00709             default :
00710             cout << "Mg3d::Mg3d : Le cas type_p = " << type_p
00711                  << " , type_t = " << type_t
00712                  << " et type_r = " << type_r[i] << endl ;
00713             cout << "n'est pas prevu !" << endl ;
00714             abort() ;
00715             
00716             }   // fin des differents types d'echantillonnage en r
00717             break ;  // fin du cas type_t = SYM et type_p = NONSYM
00718 
00719         case NONSYM :    // echantillonnage en theta sur [0,pi]
00720             switch (type_r[i]) {
00721             case FIN :    // echantillonnage fin
00722                 g[i] = new
00723                  Grille3d_f(nr[i], nt[i], np[i]) ;
00724                 break ;
00725             case FINJAC :    // echantillonnage fin avec Jacobi
00726                 g[i] = new
00727                  Grille3d_fj(nr[i], nt[i], np[i]) ;
00728                 break ;
00729             case RARE :    // echantillonnage rarefie
00730                 g[i] = new
00731                  Grille3d_r(nr[i], nt[i], np[i]) ;
00732                 break ;
00733             case UNSURR :    // echantillonnage fin en 1/r
00734                 g[i] = new
00735                  Grille3d_i(nr[i], nt[i], np[i]) ;
00736                 break ;
00737 
00738             default :
00739             cout << "Mg3d::Mg3d : Le cas type_p = " << type_p
00740                  << " , type_t = " << type_t
00741                  << " et type_r = " << type_r[i] << endl ;
00742             cout << "n'est pas prevu !" << endl ;
00743             abort() ;
00744             
00745             }   // fin des differents types d'echantillonnage en r
00746             break ;  // fin du cas type_t = NONSYM et type_p = NONSYM
00747 
00748         default :
00749             cout << "Mg3d::Mg3d : Le cas type_p = " << type_p
00750              << " et type_t = " << type_t <<
00751                 " n'est pas prevu !" << endl ;
00752             abort() ;
00753         
00754         }  // fin des differents types d'echantillonnage en theta
00755         break ; // fin du cas type_p = NONSYM
00756 
00757 //----------------------------------------------------------------------------
00758     case SYM :    // echantillonnage en phi sur [0,pi[
00759 //----------------------------------------------------------------------------
00760         switch (type_t) {
00761         case SYM :    // echantillonnage en theta sur [0,pi/2]
00762             switch (type_r[i]) {
00763             case FIN :    // echantillonnage fin
00764                 g[i] = new
00765                  Grille3d_fs(nr[i], nt[i], np[i]) ;
00766                 break ;
00767             case FINJAC :    // echantillonnage fin avec Jacobi
00768                 g[i] = new
00769                  Grille3d_fjs(nr[i], nt[i], np[i]) ;
00770                 break ;
00771             case RARE :    // echantillonnage rarefie
00772                 g[i] = new
00773                  Grille3d_rs(nr[i], nt[i], np[i]) ;
00774                 break ;
00775             case UNSURR :    // echantillonnage fin en 1/r
00776                 g[i] = new
00777                  Grille3d_is(nr[i], nt[i], np[i]) ;
00778                 break ;
00779 
00780             default :
00781             cout << "Mg3d::Mg3d : Le cas type_p = " << type_p
00782                  << " , type_t = " << type_t
00783                  << " et type_r = " << type_r[i] << endl ;
00784             cout << "n'est pas prevu !" << endl ;
00785             abort() ;
00786             
00787             }   // fin des differents types d'echantillonnage en r
00788             break ;  // fin du cas type_t = SYM et type_p = SYM
00789 
00790         case NONSYM :    // echantillonnage en theta sur [0,pi/2]
00791             switch (type_r[i]) {
00792             case FIN :    // echantillonnage fin
00793                 g[i] = new
00794                  Grille3d_f2p(nr[i], nt[i], np[i]) ;
00795                 break ;
00796             case FINJAC :     // echantillonnage fin avec Jacobi
00797                 g[i] = new
00798                  Grille3d_fj2p(nr[i], nt[i], np[i]);
00799                 break ;
00800             case RARE :    // echantillonnage rarefie
00801                 g[i] = new
00802                  Grille3d_r2p(nr[i], nt[i], np[i]) ;
00803                 break ;
00804             case UNSURR :    // echantillonnage fin en 1/r
00805                 g[i] = new
00806                  Grille3d_i2p(nr[i], nt[i], np[i]) ;
00807                 break ;
00808 
00809             default :
00810             cout << "Mg3d::Mg3d : Le cas type_p = " << type_p
00811                  << " , type_t = " << type_t
00812                  << " et type_r = " << type_r[i] << endl ;
00813             cout << "n'est pas prevu !" << endl ;
00814             abort() ;
00815             
00816             }   // fin des differents types d'echantillonnage en r
00817             break ;  // fin du cas type_t = NONSYM et type_p = SYM
00818 
00819         default :
00820             cout << "Mg3d::Mg3d : Le cas type_p = " << type_p
00821              << " et type_t = " << type_t <<
00822                 " n'est pas prevu !" << endl ;
00823             abort() ;
00824         
00825         }  // fin des differents types d'echantillonnage en theta
00826         break ; // fin du cas type_p = SYM
00827 
00828 //----------------------------------------------------------------------------
00829     default :
00830 //----------------------------------------------------------------------------
00831         cout << "Mg3d::Mg3d : Le cas type_p = " << type_p
00832          << " n'est pas prevu !" << endl ;
00833         abort() ;
00834     }   // fin des differents types d'echantillonnage en phi
00835 }   // fin de la boucle sur les zones
00836 
00837     // Pointers on derived grids initiated to 0x0:
00838     // -------------------------------------------
00839 
00840     set_deriv_0x0() ;
00841 
00842 }
00843 
00844 
00845 // Destructeur
00846 // -----------
00847 Mg3d::~Mg3d() {
00848 
00849     del_deriv() ;   // Deletes the derived quantities
00850 
00851     delete [] nr ;
00852     delete [] nt ;
00853     delete [] np ;
00854     delete [] type_r ;
00855     for (int i=0 ; i<nzone ; i++) {
00856     delete g[i] ;
00857     }
00858     delete [] g ;
00859 
00860 }
00861 
00862 //==================================================================
00863 //  Write in a file
00864 //==================================================================
00865 
00866 void Mg3d::sauve(FILE* fd) const {  
00867         fwrite_be(&nzone, sizeof(int), 1, fd) ; // nzone
00868         fwrite_be(nr, sizeof(int), nzone, fd) ; // nr
00869         fwrite_be(nt, sizeof(int), nzone, fd) ; // nt
00870         fwrite_be(np, sizeof(int), nzone, fd) ; // np
00871         fwrite_be(type_r, sizeof(int), nzone, fd) ; // type_r
00872         fwrite_be(&type_t, sizeof(int), 1, fd) ;    // type_t
00873         fwrite_be(&type_p, sizeof(int), 1, fd) ;    // type_p
00874 }
00875 
00876 
00877 
00878 
00879         //--------------------------//
00880         // Surcharge des operateurs //
00881         //--------------------------//
00882 
00883 // Operateur <<
00884 ostream& operator<<(ostream& o, const Mg3d& g) {
00885     const char* tr[4] ;
00886     tr[FIN] = "FIN" ; tr[RARE] = "RARE" ; tr[UNSURR] = "UNSURR" ; tr[FINJAC] = "FINJAC" ;
00887     const char* tang[2] ;
00888     tang[NONSYM] = "NONSYM" ; tang[SYM] = "SYM" ;
00889     o << "Number of domains: " << g.nzone << endl ;
00890     for (int i=0 ; i< g.nzone ; i++) {
00891     o << "  Domain #" << i << ": "
00892     << "nr = " << g.nr[i] << ", " << tr[g.type_r[i]] << "; "
00893     << "nt = " << g.nt[i] << ", " << tang[g.type_t] << "; "
00894     << "np = " << g.np[i] << ", " << tang[g.type_p] << endl ;
00895     }
00896     o << endl ;
00897     return o ;
00898 }
00899 
00900 // Operateur !=
00901 bool Mg3d::operator!=(const Mg3d & titi) const {
00902 
00903     if (nzone != titi.nzone) return true ;   // C'est vrai que c'est faux...
00904 
00905     for (int i=0 ; i<nzone ; i++) {
00906     if (nr[i] != titi.nr[i]) return true ;
00907     if (nt[i] != titi.nt[i]) return true ;
00908     if (np[i] != titi.np[i]) return true ;
00909 
00910     if (type_r[i] != titi.type_r[i]) return true ;
00911     }
00912 
00913     if (type_t != titi.type_t) return true ;
00914     if (type_p != titi.type_p) return true ;
00915 
00916     // C'est faux que c'est vrai...
00917     return false ;
00918 }
00919 
00920 
00921             //----------------------------------//
00922             // Management of derived quantities //
00923             //----------------------------------//
00924 
00925 void Mg3d::del_deriv() const {
00926 
00927     if (g_angu != 0x0) delete g_angu ;
00928     if (g_angu_1dom != 0x0) delete g_angu_1dom ;
00929     if (g_radial != 0x0) delete g_radial ;
00930     if (g_twice != 0x0) delete g_twice ;
00931     if (g_plus_half != 0x0) delete g_plus_half ;
00932     if (g_non_axi != 0x0) delete g_non_axi ;
00933 
00934     set_deriv_0x0() ;
00935 
00936 }
00937 
00938 void Mg3d::set_deriv_0x0() const {
00939 
00940     g_angu = 0x0 ;
00941     g_angu_1dom = 0x0 ;
00942     g_radial = 0x0 ;
00943     g_twice = 0x0 ;
00944     g_plus_half = 0x0 ;
00945     g_non_axi = 0x0 ;
00946 }
00947 
00948 
00949                 //--------------//
00950                 // Angular grid //
00951                 //--------------//
00952 
00953 const Mg3d* Mg3d::get_angu() const {
00954 
00955     if (g_angu == 0x0) {      // The construction is required
00956 
00957     int* nbr_angu = new int[nzone] ;
00958     for (int i=0 ; i<nzone ; i++) {
00959         nbr_angu[i] = 1 ;
00960     }
00961     g_angu = new Mg3d(nzone, nbr_angu, type_r, nt, type_t, np, type_p) ;
00962     delete [] nbr_angu ;
00963     }
00964 
00965     return g_angu ;
00966 
00967 }
00968     
00969                 //-----------------------------//
00970                 // Angular grid for one domain //
00971                 //-----------------------------//
00972 
00973 const Mg3d* Mg3d::get_angu_1dom() const {
00974 
00975     if (g_angu_1dom == 0x0) {     // The construction is required
00976     int* nbr_angu = new int(1) ;
00977     int* nbt_angu = new int(nt[0]) ;
00978     int* nbp_angu = new int(np[0]) ;
00979     int* type_r_angu = new int(FIN) ;
00980     
00981     g_angu_1dom = new Mg3d(1, nbr_angu, type_r_angu, nbt_angu, type_t, 
00982                    nbp_angu, type_p) ;
00983     delete nbr_angu ;
00984     delete nbt_angu ;
00985     delete nbp_angu ;
00986     delete type_r_angu ;
00987     }
00988 
00989     return g_angu_1dom ;
00990 
00991 }
00992     
00993                 //--------------//
00994                 //  Radial grid //
00995                 //--------------//
00996 
00997 const Mg3d* Mg3d::get_radial() const {
00998 
00999     if (g_radial == 0x0) {    // The construction is required
01000 
01001     int* nbr_radial = new int[nzone] ;
01002     for (int i=0 ; i<nzone ; i++) {
01003         nbr_radial[i] = 1 ;
01004     }
01005     g_radial = new Mg3d(nzone, nr, type_r, nbr_radial, SYM, nbr_radial, 
01006               SYM) ;
01007     delete [] nbr_radial ;
01008     }
01009 
01010     return g_radial ;
01011 
01012 }
01013     
01014           //--------------------------------------//
01015           // Grid with twice the number of points //
01016           //--------------------------------------//
01017 
01018 const Mg3d* Mg3d::get_twice() const {
01019 
01020     if (g_twice == 0x0) {     // The construction is required
01021 
01022     int* nbr = new int[nzone] ;
01023     int* nbt = new int[nzone] ;
01024     int* nbp = new int[nzone] ;
01025 
01026     for (int l=0; l<nzone; l++) {
01027         if (nr[l] == 1) {
01028         nbr[l] = 1 ;
01029         }
01030         else {
01031         nbr[l] = 2*nr[l] - 1 ;
01032         }
01033 
01034         if (nt[l] == 1) {
01035         nbt[l] = 1 ;
01036         }
01037         else {
01038         nbt[l] = 2*nt[l] - 1 ;
01039         }
01040     
01041         if (np[l] == 1) {
01042         nbp[l] = 1 ;
01043         }
01044         else {
01045         nbp[l] = 2*np[l] ;
01046         }
01047     }
01048 
01049     g_twice = new Mg3d(nzone, nbr, type_r, nbt, type_t, nbp, type_p) ;
01050 
01051     delete [] nbr ;
01052     delete [] nbt ;
01053     delete [] nbp ;
01054 
01055     }
01056 
01057     return g_twice ;
01058 
01059 }
01060     
01061 
01062           //--------------------------------------//
01063           // Grid with 50% additional points in r //
01064           //--------------------------------------//
01065 
01066 const Mg3d* Mg3d::plus_half() const {
01067 
01068   if (g_plus_half == 0x0) {   // The construction is required
01069 
01070     int* nbr = new int[nzone] ;
01071     
01072     for (int l=0; l<nzone; l++) {
01073       if (nr[l] == 1) 
01074     nbr[l] = 1 ;
01075       else 
01076     nbr[l] = (3*nr[l])/2  ;
01077     }
01078     
01079     g_plus_half = new Mg3d(nzone, nbr, type_r, nt, type_t, np, type_p) ;
01080 
01081     delete [] nbr ;
01082 
01083 
01084   }
01085 
01086   return g_plus_half ;
01087 
01088 }
01089     
01090           //----------------------------------------------//
01091           // Grid for rotations (5/4 points in theta/phi) //
01092           //----------------------------------------------//
01093 
01094 const Mg3d* Mg3d::get_non_axi() const {
01095 
01096   if (g_non_axi == 0x0) {     // The construction is required
01097 
01098     int* nbt = new int[nzone] ;
01099     int* nbp = new int[nzone] ;
01100     
01101     for (int l=0; l<nzone; l++) {
01102       if (nt[l] < 5)   
01103       nbt[l] = 5 ;
01104       else
01105       nbt[l] = nt[l] ;
01106       if (np[l] < 4)
01107       nbp[l] = 4 ;
01108       else
01109       nbp[l] = np[l] ;
01110     }
01111     
01112     g_non_axi = new Mg3d(nzone, nr, type_r, nbt, type_t, nbp, type_p) ;
01113 
01114     delete [] nbt ;
01115     delete [] nbp ;
01116 
01117 
01118   }
01119 
01120   return g_non_axi ;
01121 
01122 }
01123     
01124 
01125 bool Mg3d::operator==(const Mg3d& mgi) const {
01126   
01127   bool resu = true ;
01128 
01129   if (mgi.get_nzone() != nzone) {
01130     resu = false ;
01131   }
01132   else {
01133     for (int i=0; i<nzone; i++) {
01134       if (mgi.get_nr(i) != nr[i]) resu = false ;
01135       if (mgi.get_np(i) != np[i]) resu = false ;
01136       if (mgi.get_nt(i) != nt[i]) resu = false ;
01137       if (mgi.get_type_r(i) != type_r[i]) resu =false ;
01138     }
01139   }
01140   
01141   if (mgi.get_type_t() != type_t) resu = false ;
01142   if (mgi.get_type_p() != type_p) resu = false ;
01143 
01144   return resu ;
01145 
01146 }

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