map_af_integ.C

00001 /*
00002  *  Method of the class Map_af for computing the integral of a Cmp over
00003  *  all space.
00004  */
00005 
00006 /*
00007  *   Copyright (c) 1999-2003 Eric Gourgoulhon
00008  *
00009  *   This file is part of LORENE.
00010  *
00011  *   LORENE is free software; you can redistribute it and/or modify
00012  *   it under the terms of the GNU General Public License as published by
00013  *   the Free Software Foundation; either version 2 of the License, or
00014  *   (at your option) any later version.
00015  *
00016  *   LORENE is distributed in the hope that it will be useful,
00017  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *   GNU General Public License for more details.
00020  *
00021  *   You should have received a copy of the GNU General Public License
00022  *   along with LORENE; if not, write to the Free Software
00023  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024  *
00025  */
00026 
00027 
00028 char map_af_integ_C[] = "$Header: /cvsroot/Lorene/C++/Source/Map/map_af_integ.C,v 1.7 2009/10/08 16:20:47 j_novak Exp $" ;
00029 
00030 /*
00031  * $Id: map_af_integ.C,v 1.7 2009/10/08 16:20:47 j_novak Exp $
00032  * $Log: map_af_integ.C,v $
00033  * Revision 1.7  2009/10/08 16:20:47  j_novak
00034  * Addition of new bases T_COS and T_SIN.
00035  *
00036  * Revision 1.6  2008/08/27 08:48:05  jl_cornou
00037  * Added R_JACO02 case
00038  *
00039  * Revision 1.5  2007/10/05 15:56:19  j_novak
00040  * Addition of new bases for the non-symmetric case in theta.
00041  *
00042  * Revision 1.4  2003/12/19 16:21:43  j_novak
00043  * Shadow hunt
00044  *
00045  * Revision 1.3  2003/10/19 19:58:15  e_gourgoulhon
00046  * Access to Base_val::b now via Base_val::get_b().
00047  *
00048  * Revision 1.2  2003/10/15 10:35:27  e_gourgoulhon
00049  * Changed cast (double *) into static_cast<double*>.
00050  *
00051  * Revision 1.1.1.1  2001/11/20 15:19:27  e_gourgoulhon
00052  * LORENE
00053  *
00054  * Revision 1.2  2000/01/28  16:09:37  eric
00055  * Remplacement du ci.get_dzpuis() == 4 par ci.check_dzpuis(4).
00056  *
00057  * Revision 1.1  1999/12/09  10:45:43  eric
00058  * Initial revision
00059  *
00060  *
00061  * $Header: /cvsroot/Lorene/C++/Source/Map/map_af_integ.C,v 1.7 2009/10/08 16:20:47 j_novak Exp $
00062  *
00063  */
00064 
00065 // Headers C
00066 #include <stdlib.h>
00067 #include <math.h>
00068 
00069 
00070 // Headers Lorene
00071 #include "map.h"
00072 #include "cmp.h"
00073 
00074 Tbl* Map_af::integrale(const Cmp& ci) const {
00075 
00076     static double* cx_tcp = 0 ;     // Coefficients theta, dev. en cos(2l theta)
00077     static double* cx_rrp = 0 ;     // Coefficients r rare, dev. en T_{2i}
00078     static double* cx_rf_x2 = 0 ;   // Coefficients r fin, int. en r^2
00079     static double* cx_rf_x = 0 ;    // Coefficients r fin, int en r
00080     static double* cx_rf = 0 ;      // Coefficients r fin, int en cst.
00081 
00082     static int nt_cp_pre = 0 ;
00083     static int nr_p_pre = 0 ;
00084     static int nr_f_pre = 0 ;
00085 
00086     assert(ci.get_etat() != ETATNONDEF) ; 
00087 
00088     int nz = mg->get_nzone() ; 
00089     
00090     Tbl* resu = new Tbl(nz) ;
00091     
00092     if (ci.get_etat() == ETATZERO) {
00093     resu->annule_hard() ; 
00094     return resu ; 
00095     }
00096     
00097     assert( ci.get_etat() == ETATQCQ ) ; 
00098     
00099     (ci.va).coef() ;    // The spectral coefficients are required
00100     
00101     const Mtbl_cf* p_mti = (ci.va).c_cf ; 
00102 
00103     assert( ci.check_dzpuis(4) ) ;      // dzpuis must be equal to 4  
00104     
00105     assert(p_mti->get_etat() == ETATQCQ) ; 
00106 
00107     resu->set_etat_qcq() ;  // Allocates the memory for the array of double
00108 
00109     // Loop of the various domains
00110     // ---------------------------
00111     for (int l=0 ; l<nz ; l++) {
00112     
00113     const Tbl* p_tbi = p_mti->t[l] ; 
00114     
00115     if ( p_tbi->get_etat() == ETATZERO ) {
00116         resu->t[l] = 0 ; 
00117     }
00118     else {      // Case where the computation must be done
00119     
00120         assert( p_tbi->get_etat() == ETATQCQ ) ; 
00121     
00122         int nt = mg->get_nt(l) ; 
00123         int nr = mg->get_nr(l) ;
00124         
00125         int base = (p_mti->base).get_b(l) ; 
00126         int base_r = base & MSQ_R ;
00127         int base_t = base & MSQ_T ;
00128         int base_p = base & MSQ_P ;
00129         
00130         // ----------------------------------
00131         // Integration on theta -> array in r
00132         // ----------------------------------
00133 
00134         double* s_tr = new double[nr] ; // Partial integral on theta 
00135         double* x_spec = p_tbi->t ; // Pointer on the spectral coefficients
00136         
00137         switch (base_t) {
00138         
00139         case T_COS_P: case T_COSSIN_CP: {
00140             if (nt > nt_cp_pre) {  // Initialization of factors for summation
00141             nt_cp_pre = nt ;
00142             cx_tcp 
00143                 = static_cast<double*>(realloc(cx_tcp, nt*sizeof(double))) ;
00144             for (int j=0 ; j<nt ; j++) {
00145                 cx_tcp[j] = 2./(1. - 4.*j*j) ;  // Factor 2 symmetry
00146             }
00147             }
00148             
00149             // Summation : 
00150             for (int i=0 ; i<nr ; i++) s_tr[i] = 0 ;
00151             for (int j=0 ; j<nt ; j++) {
00152             for (int i=0 ; i<nr ; i++) {
00153                 s_tr[i] += cx_tcp[j] * x_spec[i] ;
00154             }
00155             x_spec += nr ;  // Next theta
00156             }
00157             break ;
00158         }
00159         case T_COSSIN_C: case T_COS: {
00160             // Summation : 
00161             for (int i=0 ; i<nr ; i++) s_tr[i] = 0 ;
00162             for (int j=0 ; j<nt ; j++) {
00163             if ((j%2)==0)
00164                 for (int i=0 ; i<nr ; i++) {
00165                 s_tr[i] += (2. / (1.-j*j)) * x_spec[i] ;
00166                 }
00167             x_spec += nr ;  // Next theta
00168             }
00169             break ;         
00170         }
00171         default: {
00172             cout << "Map_af::integrale: unknown theta basis ! " << endl ;
00173             abort () ;
00174             break ;
00175         }
00176             
00177         }   // End of the various cases on base_t
00178 
00179         // ----------------
00180         // Integration on r
00181         // ----------------
00182 
00183         double som = 0 ;
00184         double som_x2 = 0;
00185         double som_x = 0 ;
00186         double som_c = 0 ;
00187     
00188         switch(base_r) {
00189         case R_CHEBP: case R_CHEBPIM_P: case R_CHEBPI_P :{
00190         assert(beta[l] == 0) ;
00191         if (nr > nr_p_pre) {  // Initialization of factors for summation
00192             nr_p_pre = nr ;
00193             cx_rrp = static_cast<double*>(realloc(cx_rrp, nr*sizeof(double))) ;
00194             for (int i=0 ; i<nr ; i++) {
00195             cx_rrp[i] = (3. - 4.*i*i) / 
00196                     (9. - 40. * i*i + 16. * i*i*i*i) ;
00197             }
00198         }
00199         
00200         for (int i=0 ; i<nr ; i++) {
00201             som += cx_rrp[i] * s_tr[i] ;
00202         }
00203         double rmax = alpha[l] ;
00204         som *= rmax*rmax*rmax ;
00205         break ;
00206         }
00207         
00208         case R_CHEB: {
00209         if (nr > nr_f_pre) {  // Initialization of factors for summation
00210             nr_f_pre = nr ;
00211             cx_rf_x2 = static_cast<double*>(realloc(cx_rf_x2, nr*sizeof(double))) ;
00212             cx_rf_x  = static_cast<double*>(realloc(cx_rf_x, nr*sizeof(double))) ;
00213             cx_rf    = static_cast<double*>(realloc(cx_rf, nr*sizeof(double))) ;
00214             for (int i=0 ; i<nr ; i +=2 ) {
00215             cx_rf_x2[i] = 2.*(3. - i*i)/(9. - 10. * i*i + i*i*i*i) ;
00216             cx_rf_x[i] = 0 ;
00217             cx_rf[i] = 2./(1. - i*i) ;
00218             }
00219             for (int i=1 ; i<nr ; i +=2 ) {
00220             cx_rf_x2[i] = 0 ;
00221             cx_rf_x[i] = 2./(4. - i*i) ;
00222             cx_rf[i] = 0 ;
00223             }
00224         }
00225         
00226         for (int i=0 ; i<nr ; i +=2 ) {
00227             som_x2 += cx_rf_x2[i] * s_tr[i] ;
00228         }
00229         for (int i=1 ; i<nr ; i +=2 ) {
00230             som_x += cx_rf_x[i] * s_tr[i] ;
00231         }
00232         for (int i=0 ; i<nr ; i +=2 ) {
00233             som_c += cx_rf[i] * s_tr[i] ;
00234         }
00235         double a = alpha[l] ;
00236         double b = beta[l] ;
00237         som = a*a*a * som_x2 + 2.*a*a*b * som_x + a*b*b * som_c ;
00238         break ;
00239         }
00240 
00241         case R_JACO02: {
00242         if (nr > nr_f_pre) {  // Initialization of factors for summation
00243             nr_f_pre = nr ;
00244             cx_rf_x2 = static_cast<double*>(realloc(cx_rf_x2, nr*sizeof(double))) ;
00245             cx_rf_x  = static_cast<double*>(realloc(cx_rf_x, nr*sizeof(double))) ;
00246             cx_rf    = static_cast<double*>(realloc(cx_rf, nr*sizeof(double))) ;
00247             double signe = 1 ;
00248             for (int i=0 ; i<nr ; i +=1 ) {
00249             cx_rf_x2[i] = 0 ;
00250             cx_rf_x[i] = 2*signe/double(i+1)/double(i+2);
00251             cx_rf[i] = 2*signe ;
00252             signe = - signe ;
00253             }
00254             cx_rf_x2[0] = double(8)/double(3) ;
00255         }
00256         
00257         for (int i=0 ; i<nr ; i +=1 ) {
00258             som_x2 += cx_rf_x2[i] * s_tr[i] ;
00259         }
00260         for (int i=1 ; i<nr ; i +=1 ) {
00261             som_x += cx_rf_x[i] * s_tr[i] ;
00262         }
00263         for (int i=0 ; i<nr ; i +=1 ) {
00264             som_c += cx_rf[i] * s_tr[i] ;
00265         }
00266         double a = alpha[l] ;
00267         double b = beta[l] ;
00268         assert(b == a) ;
00269         som = a*a*a * som_x2 + 2.*a*a*(b-a) * som_x + a*(b-a)*(b-a) * som_c ;
00270         break ;
00271         }
00272         
00273         case R_CHEBU: {
00274         assert(beta[l] == - alpha[l]) ;
00275         if (nr > nr_f_pre) {  // Initialization of factors for summation
00276             nr_f_pre = nr ;
00277             cx_rf    = static_cast<double*>(realloc(cx_rf, nr*sizeof(double))) ;
00278             for (int i=0 ; i<nr ; i +=2 ) {
00279             cx_rf[i] = 2./(1. - i*i) ;
00280             }
00281             for (int i=1 ; i<nr ; i +=2 ) {
00282             cx_rf[i] = 0 ;
00283             }
00284         }
00285         
00286         for (int i=0 ; i<nr ; i +=2 ) {
00287             som_c += cx_rf[i] * s_tr[i] ;
00288         }
00289         som = - alpha[l] * som_c ;
00290         break ;
00291         }
00292 
00293 
00294         default: {
00295         cout << "Map_af::integrale: unknown r basis ! " << endl ;
00296         abort () ;
00297         break ;
00298         }
00299         
00300         }   // End of the various cases on base_r
00301         
00302         // ------------------
00303         // Integration on phi
00304         // ------------------
00305 
00306         switch (base_p) {
00307 
00308         case P_COSSIN: {
00309         som *= 2. * M_PI ;
00310         break ;
00311         }
00312         
00313         case P_COSSIN_P: {
00314         som *= 2. * M_PI ;
00315         break ;
00316         }
00317         
00318         default: {
00319         cout << "Map_af::integrale: unknown phi basis ! " << endl ;
00320         abort () ;
00321         break ;
00322         }
00323         
00324         }   // End of the various cases on base_p
00325 
00326         // Final result for this domain:
00327         // ----------------------------
00328            
00329         resu->t[l] = som ; 
00330         delete [] s_tr ;
00331 
00332     }   // End of the case where the computation must be done
00333     
00334     
00335     }   // End of the loop onto the domains
00336         
00337     return resu ;
00338     
00339 }

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