base_val_phi_funct.C

00001 /*
00002  * Method of the class Base_val to get the values of the phi basis functions
00003  *  at the phi collocation points.
00004  *
00005  * (see file base_val.h for the documentation)
00006  */
00007 
00008 /*
00009  *   Copyright (c) 1999-2001 Eric Gourgoulhon
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 char base_val_phi_funct_C[] = "$Header: /cvsroot/Lorene/C++/Source/Base_val/base_val_phi_funct.C,v 1.4 2012/01/17 14:44:35 j_penner Exp $" ;
00030 
00031 /*
00032  * $Id: base_val_phi_funct.C,v 1.4 2012/01/17 14:44:35 j_penner Exp $
00033  * $Log: base_val_phi_funct.C,v $
00034  * Revision 1.4  2012/01/17 14:44:35  j_penner
00035  * Modified phi variables to only use 16 integers in arrays
00036  *
00037  * Revision 1.3  2006/05/30 13:06:12  n_vasset
00038  *   Implemented function P_COSSIN_I in base_val_phi_funct.C
00039  *
00040  * Revision 1.2  2002/10/16 14:36:30  j_novak
00041  * Reorganization of #include instructions of standard C++, in order to
00042  * use experimental version 3 of gcc.
00043  *
00044  * Revision 1.1.1.1  2001/11/20 15:19:28  e_gourgoulhon
00045  * LORENE
00046  *
00047  * Revision 1.2  1999/12/29  10:49:35  eric
00048  * Methode const.
00049  *
00050  * Revision 1.1  1999/12/28  12:58:29  eric
00051  * Initial revision
00052  *
00053  *
00054  * $Header: /cvsroot/Lorene/C++/Source/Base_val/base_val_phi_funct.C,v 1.4 2012/01/17 14:44:35 j_penner Exp $
00055  *
00056  */
00057 
00058 // Headers C
00059 #include <stdlib.h>
00060 #include <math.h>
00061 
00062 
00063 // Headers Lorene
00064 #include "headcpp.h"
00065 #include "base_val.h"
00066 #include "type_parite.h"
00067 #include "tbl.h"
00068 
00069 // Local prototypes
00070 void phi_funct_pas_prevu(int, double*) ;
00071 void phi_funct_cossin(int, double*) ;
00072 void phi_funct_cossin_p(int, double*) ;
00073 void phi_funct_cossin_i(int, double*) ;
00074 
00075 //************************************************************************
00076 //  user interface : method Base_val::phi_functions
00077 //************************************************************************
00078 
00079 const Tbl& Base_val::phi_functions(int l, int np) const {
00080     
00081     const int nmax = 20 ;       // maximum number of couples (base_p, np) 
00082     static int nb_done = 0 ;        // number of Tbl already computed
00083     static int base_p_done[nmax] ;  // phi bases already treated
00084     static int np_done[nmax] ;      // number of points already treated
00085     static Tbl* tab[nmax] ;     // result for couples (base_p, np)
00086     
00087     static void(*vbasecol[MAX_BASE_2])(int, double*) ;  // computation routines
00088 
00089     static int premier_appel = 1 ;
00090 
00091     // Initializations at first call
00092     // -----------------------------
00093     if (premier_appel == 1) {
00094 
00095     premier_appel = 0 ;
00096 
00097     for (int i=0 ; i<MAX_BASE_2 ; i++) {
00098         vbasecol[i] = phi_funct_pas_prevu ;
00099     }
00100 
00101     vbasecol[P_COSSIN >> TRA_P] = phi_funct_cossin ;
00102     vbasecol[P_COSSIN_P >> TRA_P] = phi_funct_cossin_p ;
00103         vbasecol[P_COSSIN_I >> TRA_P] = phi_funct_cossin_p ;
00104 
00105     }
00106 
00107     // Computation 
00108     // -----------
00109 
00110     int base_p = ( b[l] & MSQ_P ) >> TRA_P ;
00111 
00112     // Has this couple (base_p, np) been previously considered ?
00113     // ---------------------------------------------------------
00114     int index = -1 ; 
00115     for (int i=0; i<nb_done; i++) {
00116     if ( (base_p_done[i] == base_p) && (np_done[i] == np) ) {
00117         index = i ; 
00118     }
00119     }
00120     
00121     // If not, a new computation must be performed 
00122     // -------------------------------------------
00123     if (index == -1) {
00124     if ( nb_done >= nmax ) {
00125         cout << "Base_val::phi_functions :  nb_done >= nmax ! " << endl ; 
00126         abort() ; 
00127     }
00128     
00129     index = nb_done ; 
00130 
00131     tab[index] = new Tbl( np+1, np ) ; 
00132     (tab[index])->set_etat_qcq() ; 
00133 
00134     vbasecol[base_p](np, (tab[index])->t ) ; 
00135     
00136     base_p_done[index] = base_p ; 
00137     np_done[index] = np ;
00138     nb_done++ ;
00139     
00140     }  // end of the case where the computation had to be done
00141 
00142 
00143     return *(tab[index]) ;
00144     
00145 }
00146 
00147 
00148 //************************************************************************
00149 //  computational subroutines
00150 //************************************************************************
00151 
00152 //====================================
00153 //  Unknown case
00154 //====================================
00155 
00156 void phi_funct_pas_prevu(int, double*) {
00157     
00158     cout << "Base_val::phi_functions : phi basis not implemented !" 
00159      << endl ; 
00160     abort() ; 
00161     
00162 }
00163 
00164 //==============================================
00165 //  Basis P_COSSIN
00166 //==============================================
00167 
00168 void phi_funct_cossin(int np, double* ff) {
00169 
00170     double xx = 2.*M_PI / double(np) ;
00171 
00172     for (int i = 0; i < np-1 ; i+=2 ) {
00173     int m = i/2 ;
00174     for (int k = 0; k < np ; k++ ) {
00175         double phi = xx*k ;
00176         ff[np*i + k] = cos(m * phi) ;   
00177         ff[np*(i+1) + k] = sin(m * phi) ;   
00178     }
00179     }
00180 
00181     for (int k = 0; k < np ; k++ ) {
00182     double phi = xx*k ;
00183     ff[np*np + k] = cos(np/2 * phi) ;   
00184     }
00185 
00186 }
00187 
00188 //==============================================
00189 //  Basis P_COSSIN_P
00190 //==============================================
00191 
00192 void phi_funct_cossin_p(int np, double* ff) {
00193     
00194     double xx = M_PI/double(np) ;
00195     
00196     for (int i = 0; i < np+1 ; i+=2 ) {
00197     for (int k = 0; k < np ; k++ ) {
00198         double phi = xx*k ;
00199         ff[np*i+ k] = cos(i * phi); 
00200     }
00201     }
00202 
00203     for (int i = 1; i < np ; i+=2 ) {
00204     for (int k = 0; k < np ; k++ ) {
00205         double phi = xx*k ;
00206         ff[np*i+ k] = sin((i-1) * phi); 
00207     }
00208     }
00209 
00210     
00211 }
00212 
00213 //==============================================
00214 //  Basis P_COSSIN_I
00215 //==============================================
00216 
00217 void phi_funct_cossin_i(int np, double* ff) {
00218     
00219     double xx = M_PI/double(np) ;
00220     
00221     for (int i = 0; i < np+1 ; i+=2 ) {
00222     for (int k = 0; k < np ; k++ ) {
00223         double phi = xx*k ;
00224         ff[np*i+ k] = sin(i * phi); 
00225     }
00226     }
00227 
00228     for (int i = 1; i < np ; i+=2 ) {
00229     for (int k = 0; k < np ; k++ ) {
00230         double phi = xx*k ;
00231         ff[np*i+ k] = cos((i-1) * phi); 
00232     }
00233     }
00234 
00235     
00236 }
00237 

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