base_val.C

00001 /*
00002  *  Methods of class Base_val
00003  *
00004  *   (see file base_val.h for documentation)
00005  *
00006  */
00007 
00008 /*
00009  *   Copyright (c) 1999-2000 Jean-Alain Marck
00010  *   Copyright (c) 1999-2001 Eric Gourgoulhon
00011  *   Copyright (c) 1999-2001 Philippe Grandclement
00012  *
00013  *   This file is part of LORENE.
00014  *
00015  *   LORENE is free software; you can redistribute it and/or modify
00016  *   it under the terms of the GNU General Public License as published by
00017  *   the Free Software Foundation; either version 2 of the License, or
00018  *   (at your option) any later version.
00019  *
00020  *   LORENE is distributed in the hope that it will be useful,
00021  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023  *   GNU General Public License for more details.
00024  *
00025  *   You should have received a copy of the GNU General Public License
00026  *   along with LORENE; if not, write to the Free Software
00027  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00028  *
00029  */
00030 
00031 
00032 char base_val_C[] = "$Header: /cvsroot/Lorene/C++/Source/Base_val/base_val.C,v 1.14 2012/01/17 14:44:19 j_penner Exp $" ;
00033 
00034 /*
00035  * $Id: base_val.C,v 1.14 2012/01/17 14:44:19 j_penner Exp $
00036  * $Log: base_val.C,v $
00037  * Revision 1.14  2012/01/17 14:44:19  j_penner
00038  * Modified phi variables to only use 16 integers in arrays
00039  *
00040  * Revision 1.13  2009/10/23 12:55:16  j_novak
00041  * New base T_LEG_MI
00042  *
00043  * Revision 1.12  2009/10/08 16:20:13  j_novak
00044  * Addition of new bases T_COS and T_SIN.
00045  *
00046  * Revision 1.11  2008/08/19 06:41:59  j_novak
00047  * Minor modifications to avoid warnings with gcc 4.3. Most of them concern
00048  * cast-type operations, and constant strings that must be defined as const char*
00049  *
00050  * Revision 1.10  2008/02/18 13:53:38  j_novak
00051  * Removal of special indentation instructions.
00052  *
00053  * Revision 1.9  2007/12/11 15:28:09  jl_cornou
00054  * Jacobi(0,2) polynomials partially implemented
00055  *
00056  * Revision 1.8  2004/12/17 13:35:01  m_forot
00057  * Add the case T_LEG
00058  *
00059  * Revision 1.7  2004/11/04 15:19:02  e_gourgoulhon
00060  * operator<< : added names R_CHEBPI_P, R_CHEBPI_I, T_COSSIN_C, T_COSSIN_S.
00061  *
00062  * Revision 1.6  2004/08/24 09:14:41  p_grandclement
00063  * Addition of some new operators, like Poisson in 2d... It now requieres the
00064  * GSL library to work.
00065  *
00066  * Also, the way a variable change is stored by a Param_elliptic is changed and
00067  * no longer uses Change_var but rather 2 Scalars. The codes using that feature
00068  * will requiere some modification. (It should concern only the ones about monopoles)
00069  *
00070  * Revision 1.5  2003/09/16 08:54:09  j_novak
00071  * Addition of the T_LEG_II base (odd in theta, only for odd m) and the
00072  * transformation functions to and from the T_SIN_P base.
00073  *
00074  * Revision 1.4  2002/11/13 15:05:59  j_novak
00075  * Affichage de la base T_COS
00076  *
00077  * Revision 1.3  2002/10/16 14:36:30  j_novak
00078  * Reorganization of #include instructions of standard C++, in order to
00079  * use experimental version 3 of gcc.
00080  *
00081  * Revision 1.2  2001/12/04 21:27:52  e_gourgoulhon
00082  *
00083  * All writing/reading to a binary file are now performed according to
00084  * the big endian convention, whatever the system is big endian or
00085  * small endian, thanks to the functions fwrite_be and fread_be
00086  *
00087  * Revision 1.1.1.1  2001/11/20 15:19:28  e_gourgoulhon
00088  * LORENE
00089  *
00090  * Revision 2.8  2000/09/28  10:20:19  eric
00091  * Affichage: nouvelles bases T_LEG_IP et T_LEG_PI.
00092  *
00093  * Revision 2.7  2000/09/08  10:06:45  eric
00094  * Ajout des methodes set_base_r, etc...
00095  *
00096  * Revision 2.6  1999/12/28  12:57:26  eric
00097  * Reorganisation des headers.
00098  *
00099  * Revision 2.5  1999/10/12  10:02:51  eric
00100  * Implementation de sauve().
00101  * Modif de << : affichage du nom des bases et non plus de leur numero.
00102  *
00103  * Revision 2.4  1999/10/01  15:56:21  eric
00104  * Depoussierage.
00105  * Documentation.
00106  *
00107  * Revision 2.3  1999/09/13  14:57:06  phil
00108  * ajout de l'operateur ==
00109  *
00110  * Revision 2.2  1999/03/02  15:22:23  eric
00111  * Affichage des bases.
00112  *
00113  * Revision 2.1  1999/03/01  14:54:01  eric
00114  * *** empty log message ***
00115  *
00116  * Revision 2.0  1999/02/22  15:19:20  hyc
00117  * *** empty log message ***
00118  *
00119  *
00120  * $Header: /cvsroot/Lorene/C++/Source/Base_val/base_val.C,v 1.14 2012/01/17 14:44:19 j_penner Exp $
00121  *
00122  */
00123 
00124 // Headers C
00125 #include <stdio.h>
00126 #include <assert.h>
00127 
00128 // Headers Lorene
00129 #include "headcpp.h"
00130 #include "type_parite.h"
00131 #include "base_val.h"
00132 #include "utilitaires.h"
00133 
00134 
00135             //---------------//
00136             // Constructeurs //
00137             //---------------//
00138 
00139 // Constructeur
00140 Base_val::Base_val(int n) : nzone(n) {
00141     b = new int[nzone] ;
00142     for (int i=0 ; i<nzone ; i++) {    // Boucle sur les zones
00143     b[i] = NONDEF ;
00144     }
00145 }
00146 
00147 // Copie
00148 Base_val::Base_val(const Base_val & bi) : nzone(bi.nzone) {
00149     b = new int[nzone] ;
00150     for (int i=0 ; i<nzone ; i++) {    // Boucle sur les zones
00151     b[i] = bi.b[i] ;
00152     }
00153 }
00154     
00155 // From file
00156 Base_val::Base_val(FILE* fd) {
00157   fread_be(&nzone, sizeof(int), 1, fd) ;        // nzone
00158   b = new int[nzone] ; 
00159   fread_be(b, sizeof(int), nzone, fd) ;     // b[]
00160 }
00161 
00162             //--------------//
00163             // Destructeurs //
00164             //--------------//
00165 
00166 // Destructeur
00167 Base_val::~Base_val() {
00168     delete [] b ;
00169 }
00170 
00171             //-------------//
00172             // Affectation //
00173             //-------------//
00174 
00175 void Base_val::set_base_r(int l, int base_r) {
00176     
00177     assert( (l>=0) && (l<nzone) ) ; 
00178 
00179     int base_t = b[l] & MSQ_T ;
00180     int base_p = b[l] & MSQ_P ;
00181     b[l] = base_p | base_t | base_r ;
00182     
00183 }
00184 
00185 void Base_val::set_base_t(int base_t) {
00186     
00187     for (int l=0; l<nzone; l++) {
00188     int base_r = b[l] & MSQ_R ;
00189     int base_p = b[l] & MSQ_P ;
00190     b[l] = base_p | base_t | base_r ;
00191     }
00192 }
00193 
00194 void Base_val::set_base_p(int base_p) {
00195     
00196     for (int l=0; l<nzone; l++) {
00197     int base_r = b[l] & MSQ_R ;
00198     int base_t = b[l] & MSQ_T ;
00199     b[l] = base_p | base_t | base_r ;
00200     }
00201 }
00202 
00203 
00204 // From Base_val
00205 void Base_val::operator=(const Base_val & bi) {
00206     // Protection
00207     assert(nzone == bi.nzone) ;
00208     for (int i=0 ; i<nzone ; i++) {    // Boucle sur les zones
00209     b[i] = bi.b[i] ;
00210     }
00211 }
00212     
00213             //------------//
00214             // Sauvegarde //
00215             //------------//
00216 
00217 // Save in a file
00218 void Base_val::sauve(FILE* fd) const {
00219     fwrite_be(&nzone, sizeof(int), 1, fd) ;     // nzone
00220     fwrite_be(b, sizeof(int), nzone, fd) ;              // b[]
00221 }
00222     
00223             //------------//
00224             // Impression //
00225             //------------//
00226 
00227 // Operateurs <<
00228 ostream& operator<<(ostream& o, const Base_val & bi) {
00229   
00230   static bool premier_appel = true ; 
00231   static const char* nom_r[MAX_BASE] ;
00232   static const char* nom_t[MAX_BASE] ;
00233   static const char* nom_p[MAX_BASE_2] ;
00234 
00235   if (premier_appel) {   // First call initializations
00236 
00237     premier_appel = false ;
00238 
00239     for (int i=0; i<MAX_BASE; i++) {
00240       nom_r[i] = "UNDEFINED" ;    
00241       nom_t[i] = "UNDEFINED" ;    
00242       if(i%2==0){
00243       nom_p[i/2] = "UNDEFINED" ;    // saves a loop
00244       }
00245     }
00246 
00247     nom_r[R_CHEB >> TRA_R] =      "R_CHEB     " ; 
00248     nom_r[R_CHEBU >> TRA_R] =     "R_CHEBU    " ; 
00249     nom_r[R_CHEBP >> TRA_R] =     "R_CHEBP    " ; 
00250     nom_r[R_CHEBI >> TRA_R] =     "R_CHEBI    " ; 
00251     nom_r[R_CHEBPIM_P >> TRA_R] = "R_CHEBPIM_P" ; 
00252     nom_r[R_CHEBPIM_I >> TRA_R] = "R_CHEBPIM_I" ; 
00253     nom_r[R_CHEBPI_P >> TRA_R] =  "R_CHEBPI_P " ; 
00254     nom_r[R_CHEBPI_I >> TRA_R] =  "R_CHEBPI_I " ; 
00255     nom_r[R_JACO02 >> TRA_R] =    "R_JACO02   " ;
00256   
00257     nom_t[T_COS >> TRA_T] =       "T_COS      " ; 
00258     nom_t[T_SIN >> TRA_T] =       "T_SIN      " ; 
00259     nom_t[T_COS_P >> TRA_T] =     "T_COS_P    " ; 
00260     nom_t[T_COS_I >> TRA_T] =     "T_COS_I    " ; 
00261     nom_t[T_SIN_P >> TRA_T] =     "T_SIN_P    " ; 
00262     nom_t[T_SIN_I >> TRA_T] =     "T_SIN_I    " ; 
00263     nom_t[T_COSSIN_CP >> TRA_T] = "T_COSSIN_CP" ;
00264     nom_t[T_COSSIN_SI >> TRA_T] = "T_COSSIN_SI" ;
00265     nom_t[T_COSSIN_SP >> TRA_T] = "T_COSSIN_SP" ;
00266     nom_t[T_COSSIN_CI >> TRA_T] = "T_COSSIN_CI" ;
00267     nom_t[T_COSSIN_C >> TRA_T] =  "T_COSSIN_C " ;
00268     nom_t[T_COSSIN_S >> TRA_T] =  "T_COSSIN_S " ;
00269     nom_t[T_LEG >> TRA_T] =       "T_LEG      " ;
00270     nom_t[T_LEG_MP >> TRA_T] =    "T_LEG_MP   " ;
00271     nom_t[T_LEG_MI >> TRA_T] =    "T_LEG_MI   " ;
00272     nom_t[T_LEG_P >> TRA_T] =     "T_LEG_P    " ;
00273     nom_t[T_LEG_PP >> TRA_T] =    "T_LEG_PP   " ;
00274     nom_t[T_LEG_I >> TRA_T] =     "T_LEG_I    " ;
00275     nom_t[T_LEG_IP >> TRA_T] =    "T_LEG_IP   " ;
00276     nom_t[T_LEG_PI >> TRA_T] =    "T_LEG_PI   " ;
00277     nom_t[T_LEG_II >> TRA_T] =    "T_LEG_II   " ;
00278     nom_t[T_CL_COS_P >> TRA_T] =  "T_CL_COS_P " ;
00279     nom_t[T_CL_SIN_P >> TRA_T] =  "T_CL_SIN_P " ;
00280     nom_t[T_CL_COS_I >> TRA_T] =  "T_CL_COS_I " ;
00281     nom_t[T_CL_SIN_I >> TRA_T] =  "T_CL_SIN_I " ;
00282 
00283     nom_p[P_COSSIN >> TRA_P] =    "P_COSSIN   " ;
00284     nom_p[P_COSSIN_P >> TRA_P] =  "P_COSSIN_P " ;
00285     nom_p[P_COSSIN_I >> TRA_P] =  "P_COSSIN_I " ;
00286 
00287 
00288   } // End of first call operations
00289   
00290 
00291     // Intro - Nombre de zones
00292     int nzone = bi.nzone ;
00293     o << "Bases of spectral expansions: "  ;
00294     for (int l=0 ; l<nzone ; l++) {
00295     int base_r = (bi.b[l] & MSQ_R) >> TRA_R ;
00296     int base_t = (bi.b[l] & MSQ_T) >> TRA_T  ;
00297     int base_p = (bi.b[l] & MSQ_P) >> TRA_P ;
00298     o << endl ;
00299     o << "Domain #" << l << " : r: " << nom_r[base_r] 
00300         << ",  theta: " << nom_t[base_t] 
00301         << ",  phi: " << nom_p[base_p] ;
00302     }
00303     o << endl ;
00304 
00305     //Termine
00306     return o ;
00307 }
00308     
00309             //----------------------//
00310             // Manipulation de base //
00311             //----------------------//
00312 
00313 void Base_val::set_base_nondef() {
00314     for (int i=0 ; i<nzone ; i++) {
00315     b[i] = NONDEF ;
00316     }
00317 }
00318             //----------------------//
00319             // operateur logique    //
00320             //----------------------//
00321 
00322 bool Base_val::operator== (const Base_val& c2) const {
00323 
00324     return (*b == *c2.b) ;
00325 }

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