base_val_theta_funct.C

00001 /*
00002  * Method of the class Base_val to get the values of the theta basis functions
00003  *  at the theta collocation points.
00004  *
00005  * (see file base_val.h for the documentation)
00006  */
00007 
00008 /*
00009  *   Copyright (c) 1999-2001 Eric Gourgoulhon
00010  *   Copyright (c) 2001 Jerome Novak
00011  *
00012  *   This file is part of LORENE.
00013  *
00014  *   LORENE is free software; you can redistribute it and/or modify
00015  *   it under the terms of the GNU General Public License as published by
00016  *   the Free Software Foundation; either version 2 of the License, or
00017  *   (at your option) any later version.
00018  *
00019  *   LORENE is distributed in the hope that it will be useful,
00020  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022  *   GNU General Public License for more details.
00023  *
00024  *   You should have received a copy of the GNU General Public License
00025  *   along with LORENE; if not, write to the Free Software
00026  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00027  *
00028  */
00029 
00030 
00031 char base_val_theta_funct_C[] = "$Header: /cvsroot/Lorene/C++/Source/Base_val/base_val_theta_funct.C,v 1.7 2009/10/08 16:20:13 j_novak Exp $" ;
00032 
00033 /*
00034  * $Id: base_val_theta_funct.C,v 1.7 2009/10/08 16:20:13 j_novak Exp $
00035  * $Log: base_val_theta_funct.C,v $
00036  * Revision 1.7  2009/10/08 16:20:13  j_novak
00037  * Addition of new bases T_COS and T_SIN.
00038  *
00039  * Revision 1.6  2007/10/23 17:15:12  j_novak
00040  * Added the bases T_COSSIN_C and T_COSSIN_S
00041  *
00042  * Revision 1.5  2006/05/30 08:30:12  n_vasset
00043  * Implementation of sine-like bases (T_SIN_P, T_SIN_I, T_COSSIN_SI, etc...).
00044  *
00045  * Revision 1.4  2005/05/27 14:54:59  j_novak
00046  * Added new bases T_COSSIN_CI and T_COS_I
00047  *
00048  * Revision 1.3  2004/11/23 15:08:01  m_forot
00049  * Added the bases for the cases without any equatorial symmetry
00050  * (T_COSSIN_C, T_COSSIN_S, T_LEG, R_CHEBPI_P, R_CHEBPI_I).
00051  *
00052  * Revision 1.2  2002/10/16 14:36:30  j_novak
00053  * Reorganization of #include instructions of standard C++, in order to
00054  * use experimental version 3 of gcc.
00055  *
00056  * Revision 1.1.1.1  2001/11/20 15:19:28  e_gourgoulhon
00057  * LORENE
00058  *
00059  * Revision 1.3  2001/11/16  09:28:35  novak
00060  * The case nt=1 is treated separately
00061  *
00062  * Revision 1.2  1999/12/29 10:49:47  eric
00063  * Mehtode const.
00064  *
00065  * Revision 1.1  1999/12/28  12:58:35  eric
00066  * Initial revision
00067  *
00068  *
00069  * $Header: /cvsroot/Lorene/C++/Source/Base_val/base_val_theta_funct.C,v 1.7 2009/10/08 16:20:13 j_novak Exp $
00070  *
00071  */
00072 
00073 // Headers C
00074 #include <stdlib.h>
00075 #include <math.h>
00076 
00077 
00078 // Headers Lorene
00079 #include "base_val.h"
00080 #include "type_parite.h"
00081 #include "tbl.h"
00082 
00083 // Local prototypes
00084 void theta_funct_pas_prevu(int, double*) ;
00085 void theta_funct_cos(int, double*) ;
00086 void theta_funct_sin(int, double*) ;
00087 void theta_funct_cos_p(int, double*) ;
00088 void theta_funct_cos_i(int, double*) ;
00089 void theta_funct_sin_p(int, double*) ;
00090 void theta_funct_sin_i(int, double*) ;
00091 void theta_funct_cossin_cp(int, double*) ;
00092 void theta_funct_cossin_ci(int, double*) ;
00093 void theta_funct_cossin_sp(int, double*) ;
00094 void theta_funct_cossin_si(int, double*) ;
00095 void theta_funct_cossin_c(int, double*) ;
00096 void theta_funct_cossin_s(int, double*) ;
00097 
00098 //************************************************************************
00099 //  user interface : method Base_val::theta_functions
00100 //************************************************************************
00101 
00102 const Tbl& Base_val::theta_functions(int l, int nt) const {
00103     
00104     const int nmax = 20 ;       // maximum number of couples (base_t, nt) 
00105     static int nb_done = 0 ;        // number of Tbl already computed
00106     static int base_t_done[nmax] ;  // theta bases already treated
00107     static int nt_done[nmax] ;      // number of points already treated
00108     static Tbl* tab[nmax] ;     // result for couples (base_t, nt)
00109     
00110     static void(*vbasecol[MAX_BASE])(int, double*) ;  // computation routines
00111     static int dim2[MAX_BASE] ;          // dim(2) of the Tbl's
00112 
00113     static int premier_appel = 1 ;
00114 
00115     // Initializations at first call
00116     // -----------------------------
00117     if (premier_appel == 1) {
00118 
00119     premier_appel = 0 ;
00120 
00121     for (int i=0 ; i<MAX_BASE ; i++) {
00122         vbasecol[i] = theta_funct_pas_prevu ;
00123         dim2[i] = 0 ; 
00124     }
00125 
00126     vbasecol[T_COS >> TRA_T] = theta_funct_cos ;
00127     vbasecol[T_SIN >> TRA_T] = theta_funct_sin ;
00128     vbasecol[T_COS_P >> TRA_T] = theta_funct_cos_p ;
00129     vbasecol[T_COS_I >> TRA_T] = theta_funct_cos_i ;
00130     vbasecol[T_SIN_I >> TRA_T] = theta_funct_sin_i ;
00131     vbasecol[T_SIN_P >> TRA_T] = theta_funct_sin_p ;
00132     vbasecol[T_COSSIN_CP >> TRA_T] = theta_funct_cossin_cp ;
00133     vbasecol[T_COSSIN_CI >> TRA_T] = theta_funct_cossin_ci ;
00134     vbasecol[T_COSSIN_SP >> TRA_T] = theta_funct_cossin_sp ;
00135     vbasecol[T_COSSIN_SI >> TRA_T] = theta_funct_cossin_si ;
00136     vbasecol[T_COSSIN_C >> TRA_T] = theta_funct_cossin_c ;
00137     vbasecol[T_COSSIN_S >> TRA_T] = theta_funct_cossin_s ;
00138 
00139     dim2[T_COS >> TRA_T] = 1 ;
00140     dim2[T_SIN >> TRA_T] = 1 ;
00141     dim2[T_COS_P >> TRA_T] = 1 ;
00142     dim2[T_COS_I >> TRA_T] = 1 ;
00143     dim2[T_SIN_P >> TRA_T] = 1 ;
00144     dim2[T_SIN_I >> TRA_T] = 1 ;
00145     dim2[T_COSSIN_CP >> TRA_T] = 2 ;
00146     dim2[T_COSSIN_CI >> TRA_T] = 2 ;
00147     dim2[T_COSSIN_SP >> TRA_T] = 2 ;
00148     dim2[T_COSSIN_SI >> TRA_T] = 2 ;
00149     dim2[T_COSSIN_C >> TRA_T] = 2 ;
00150     dim2[T_COSSIN_S >> TRA_T] = 2 ;
00151 
00152     }
00153 
00154     // Computation 
00155     // -----------
00156 
00157     int base_t = ( b[l] & MSQ_T ) >> TRA_T ;
00158 
00159     // Has this couple (base_t, nt) been previously considered ?
00160     // ---------------------------------------------------------
00161     int index = -1 ; 
00162     for (int i=0; i<nb_done; i++) {
00163     if ( (base_t_done[i] == base_t) && (nt_done[i] == nt) ) {
00164         index = i ; 
00165     }
00166     }
00167     
00168     // If not, a new computation must be performed 
00169     // -------------------------------------------
00170     if (index == -1) {
00171     if ( nb_done >= nmax ) {
00172         cout << "Base_val::theta_functions :  nb_done >= nmax ! " << endl ; 
00173         abort() ; 
00174     }
00175     
00176     index = nb_done ; 
00177 
00178     tab[index] = new Tbl( dim2[base_t], nt, nt ) ; 
00179     (tab[index])->set_etat_qcq() ; 
00180 
00181     vbasecol[base_t](nt, (tab[index])->t ) ; 
00182     
00183     base_t_done[index] = base_t ; 
00184     nt_done[index] = nt ;
00185     nb_done++ ;
00186     
00187     }  // end of the case where the computation had to be done
00188 
00189 
00190     return *(tab[index]) ;
00191     
00192 }
00193 
00194 
00195 //************************************************************************
00196 //  computational subroutines
00197 //************************************************************************
00198 
00199 //====================================
00200 //  Unknown case
00201 //====================================
00202 
00203 void theta_funct_pas_prevu(int, double*) {
00204     
00205     cout << "Base_val::theta_functions : theta basis not implemented !" 
00206      << endl ; 
00207     abort() ; 
00208     
00209 }
00210 
00211 //==============================================
00212 //  Basis cos(j*theta)  T_COS
00213 //==============================================
00214 
00215 void theta_funct_cos(int nt, double* ff) {
00216 
00217     double xx = ( nt > 1 ? M_PI / double(nt-1) : 0.) ;
00218 
00219     for (int i = 0; i < nt ; i++ ) {
00220     for (int j = 0; j < nt ; j++ ) {
00221         double theta = xx*j ;
00222         ff[nt*i+ j] = cos(i * theta);   
00223     }
00224     }
00225 
00226 }
00227 
00228 //==============================================
00229 //  Basis sin(j* theta)  T_SIN
00230 //==============================================
00231 
00232 void theta_funct_sin(int nt, double* ff) {
00233 
00234     double xx = ( nt > 1 ? M_PI / double(nt-1) : 0.) ;
00235 
00236     for (int i = 0; i < nt ; i++ ) {
00237     for (int j = 0; j < nt ; j++ ) {
00238         double theta = xx*j ;
00239         ff[nt*i+ j] = sin(i * theta);   
00240     }
00241     }
00242 
00243 }
00244 
00245 //==============================================
00246 //  Basis cos(2*j* theta)  T_COS_P
00247 //==============================================
00248 
00249 void theta_funct_cos_p(int nt, double* ff) {
00250 
00251     double xx = ( nt > 1 ? M_PI / double(2*(nt-1)) : 0.) ;
00252 
00253     for (int i = 0; i < nt ; i++ ) {
00254     for (int j = 0; j < nt ; j++ ) {
00255         double theta = xx*j ;
00256         ff[nt*i+ j] = cos(2*i * theta); 
00257     }
00258     }
00259 
00260 }
00261 
00262 //==============================================
00263 //  Basis cos((2*j+1)* theta)  T_COS_I
00264 //==============================================
00265 
00266 void theta_funct_cos_i(int nt, double* ff) {
00267 
00268     double xx = ( nt > 1 ? M_PI / double(2*(nt-1)) : 0.) ;
00269 
00270     for (int i = 0; i < nt ; i++ ) {
00271     for (int j = 0; j < nt ; j++ ) {
00272         double theta = xx*j ;
00273         ff[nt*i+ j] = cos((2*i+1) * theta); 
00274     }
00275     }
00276 
00277 }
00278 
00279 //==============================================
00280 //  Basis sin(2*j* theta)  T_SIN_P
00281 //==============================================
00282 
00283 void theta_funct_sin_p(int nt, double* ff) {
00284 
00285     double xx = ( nt > 1 ? M_PI / double(2*(nt-1)) : 0.) ;
00286 
00287     for (int i = 0; i < nt ; i++ ) {
00288     for (int j = 0; j < nt ; j++ ) {
00289         double theta = xx*j ;
00290         ff[nt*i+ j] = sin(2*i * theta); 
00291     }
00292     }
00293 
00294 }
00295 
00296 //==============================================
00297 //  Basis sin((2*j+1)* theta)  T_SIN_I
00298 //==============================================
00299 
00300 void theta_funct_sin_i(int nt, double* ff) {
00301 
00302     double xx = ( nt > 1 ? M_PI / double(2*(nt-1)) : 0.) ;
00303 
00304     for (int i = 0; i < nt ; i++ ) {
00305     for (int j = 0; j < nt ; j++ ) {
00306         double theta = xx*j ;
00307         ff[nt*i+ j] = sin((2*i+1) * theta); 
00308     }
00309     }
00310 
00311 }
00312 
00313 //===========================================================
00314 //  Basis cos(2*j* theta)/sin((2*j+1) theta)   T_COSSIN_CP
00315 //===========================================================
00316 
00317 void theta_funct_cossin_cp(int nt, double* ff) {
00318     
00319     int nt2 = nt*nt ;
00320 
00321     double xx = ( nt > 1 ? M_PI / double(2*(nt-1)) : 0.) ;
00322 
00323     // cos(2i theta_j)
00324     // ---------------
00325     for (int i = 0; i < nt ; i++ ) {
00326     for (int j = 0; j < nt ; j++ ) {
00327         double theta = xx*j ;
00328         ff[nt*i+ j] = cos(2*i * theta); 
00329     }
00330     }
00331     
00332     // sin((2i+1) theta_j)
00333     // -------------------
00334 
00335     for (int i = 0; i < nt-1 ; i++ ) {
00336     for (int j = 0; j < nt ; j++ ) {
00337         double theta = xx*j ;
00338         ff[nt2+nt*i+ j] = sin((2*i+1) * theta); 
00339     }
00340     }
00341     
00342     for (int j = 0; j < nt ; j++ ) {
00343     ff[nt2+nt*(nt-1) + j] = 0 ; 
00344     }
00345     
00346     
00347 }
00348 
00349 //===========================================================
00350 //  Basis cos((2*j+1)* theta)/sin(2*j*theta)   T_COSSIN_CI
00351 //===========================================================
00352 
00353 void theta_funct_cossin_ci(int nt, double* ff) {
00354     
00355     int nt2 = nt*nt ;
00356 
00357     double xx = ( nt > 1 ? M_PI / double(2*(nt-1)) : 0.) ;
00358 
00359     // cos((2i+1) theta_j)
00360     // ---------------
00361     for (int i = 0; i < nt ; i++ ) {
00362     for (int j = 0; j < nt ; j++ ) {
00363         double theta = xx*j ;
00364         ff[nt*i+ j] = cos((2*i+1) * theta); 
00365     }
00366     }
00367     
00368     // sin(2i theta_j)
00369     // -------------------
00370 
00371     for (int i = 0; i < nt-1 ; i++ ) {
00372     for (int j = 0; j < nt ; j++ ) {
00373         double theta = xx*j ;
00374         ff[nt2+nt*i+ j] = sin(2*i * theta); 
00375     }
00376     }
00377     
00378     for (int j = 0; j < nt ; j++ ) {
00379     ff[nt2+nt*(nt-1) + j] = 0 ; 
00380     }
00381     
00382     
00383 }
00384 
00385 
00386 //===========================================================
00387 //  Basis sin(2*j* theta)/cos((2*j+1) theta)   T_COSSIN_SP
00388 //===========================================================
00389 
00390 void theta_funct_cossin_sp(int nt, double* ff) {
00391     
00392     int nt2 = nt*nt ;
00393 
00394     double xx = ( nt > 1 ? M_PI / double(2*(nt-1)) : 0.) ;
00395 
00396     // sin(2i theta_j)
00397     // ---------------
00398     for (int i = 0; i < nt ; i++ ) {
00399     for (int j = 0; j < nt ; j++ ) {
00400         double theta = xx*j ;
00401         ff[nt*i+ j] = sin(2*i * theta); 
00402     }
00403     }
00404     
00405     // cos((2i+1) theta_j)
00406     // -------------------
00407 
00408     for (int i = 0; i < nt-1 ; i++ ) {
00409     for (int j = 0; j < nt ; j++ ) {
00410         double theta = xx*j ;
00411         ff[nt2+nt*i+ j] = cos((2*i+1) * theta); 
00412     }
00413     }
00414     
00415     for (int j = 0; j < nt ; j++ ) {
00416     ff[nt2+nt*(nt-1) + j] = 0 ; 
00417     }
00418     
00419     
00420 }
00421 
00422 //===========================================================
00423 //  Basis sin((2*j+1)* theta)/cos(2*j*theta)   T_COSSIN_SI
00424 //===========================================================
00425 
00426 void theta_funct_cossin_si(int nt, double* ff) {
00427     
00428     int nt2 = nt*nt ;
00429 
00430     double xx = ( nt > 1 ? M_PI / double(2*(nt-1)) : 0.) ;
00431 
00432     // sin((2i+1) theta_j)
00433     // ---------------
00434     for (int i = 0; i < nt ; i++ ) {
00435     for (int j = 0; j < nt ; j++ ) {
00436         double theta = xx*j ;
00437         ff[nt*i+ j] = sin((2*i+1) * theta); 
00438     }
00439     }
00440     
00441     // cos(2i theta_j)
00442     // -------------------
00443 
00444     for (int i = 0; i < nt-1 ; i++ ) {
00445     for (int j = 0; j < nt ; j++ ) {
00446         double theta = xx*j ;
00447         ff[nt2+nt*i+ j] = cos(2*i * theta); 
00448     }
00449     }
00450     
00451     for (int j = 0; j < nt ; j++ ) {
00452     ff[nt2+nt*(nt-1) + j] = 0 ; 
00453     }
00454     
00455     
00456 }
00457 
00458 //===========================================================
00459 //  Basis cos(j* theta)/sin(j*theta)   T_COSSIN_C
00460 //===========================================================
00461 
00462 void theta_funct_cossin_c(int nt, double* ff) {
00463     
00464     int nt2 = nt*nt ;
00465 
00466     double xx = ( nt > 1 ? M_PI / double(nt-1) : 0.) ;
00467 
00468     // cos(i theta_j)
00469     // ---------------
00470     for (int i = 0; i < nt ; i++ ) {
00471     for (int j = 0; j < nt ; j++ ) {
00472         double theta = xx*j ;
00473         ff[nt*i+ j] = cos(i * theta);   
00474     }
00475     }
00476     
00477     // sin(i theta_j)
00478     // -------------------
00479 
00480     for (int i = 0; i < nt-1 ; i++ ) {
00481     for (int j = 0; j < nt ; j++ ) {
00482         double theta = xx*j ;
00483         ff[nt2+nt*i+ j] = sin(i * theta);   
00484     }
00485     }
00486     
00487     for (int j = 0; j < nt ; j++ ) {
00488     ff[nt2+nt*(nt-1) + j] = 0 ; 
00489     }
00490     
00491     
00492 }
00493 
00494 //===========================================================
00495 //  Basis sin(j* theta)/cos(j*theta)   T_COSSIN_S
00496 //===========================================================
00497 
00498 void theta_funct_cossin_s(int nt, double* ff) {
00499     
00500     int nt2 = nt*nt ;
00501 
00502     double xx = ( nt > 1 ? M_PI / double(nt-1) : 0.) ;
00503 
00504     // sin(i theta_j)
00505     // ---------------
00506     for (int i = 0; i < nt-1 ; i++ ) {
00507     for (int j = 0; j < nt ; j++ ) {
00508         double theta = xx*j ;
00509         ff[nt*i+ j] = sin(i * theta);   
00510     }
00511     }
00512 
00513     for (int j = 0; j < nt ; j++ ) {
00514     ff[nt*(nt-1) + j] = 0 ; 
00515     }
00516     
00517     // cos(i theta_j)
00518     // -------------------
00519 
00520     for (int i = 0; i < nt ; i++ ) {
00521     for (int j = 0; j < nt ; j++ ) {
00522         double theta = xx*j ;
00523         ff[nt2+nt*i+ j] = cos(i * theta);   
00524     }
00525     }
00526            
00527 }
00528 

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