op_primr.C

00001 /*
00002  *  Computation of primitive in a single domain 
00003  *
00004  *
00005  */
00006 
00007 /*
00008  *   Copyright (c) 2004  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 version 2
00014  *   as published by the Free Software Foundation.
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 char op_primr_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Operators/op_primr.C,v 1.7 2007/12/21 13:59:02 j_novak Exp $" ;
00028 
00029 /*
00030  * $Id: op_primr.C,v 1.7 2007/12/21 13:59:02 j_novak Exp $
00031  * $Log: op_primr.C,v $
00032  * Revision 1.7  2007/12/21 13:59:02  j_novak
00033  * Suppression of call to pow(-1, something).
00034  *
00035  * Revision 1.6  2007/12/11 15:28:18  jl_cornou
00036  * Jacobi(0,2) polynomials partially implemented
00037  *
00038  * Revision 1.5  2006/05/17 15:01:16  j_novak
00039  * Treatment of the case nr = 1 and R_CHEB
00040  *
00041  * Revision 1.4  2004/11/23 15:16:01  m_forot
00042  *
00043  * Added the bases for the cases without any equatorial symmetry
00044  *  (T_COSSIN_C, T_COSSIN_S, T_LEG, R_CHEBPI_P, R_CHEBPI_I).
00045  *
00046  * Revision 1.3  2004/10/12 09:58:24  j_novak
00047  * Better memory management.
00048  *
00049  * Revision 1.2  2004/06/14 15:24:57  e_gourgoulhon
00050  * First operationnal version (tested).
00051  *
00052  * Revision 1.1  2004/06/13 21:33:13  e_gourgoulhon
00053  * First version.
00054  *
00055  *
00056  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Operators/op_primr.C,v 1.7 2007/12/21 13:59:02 j_novak Exp $
00057  *
00058  */
00059 
00060 
00061 // C headers
00062 #include <stdlib.h>
00063 #include <math.h>
00064 
00065 // Lorene headers
00066 #include "tbl.h"
00067 
00068 // Unexpected case
00069 //----------------
00070 void _primr_pas_prevu(const Tbl&, int bin, const Tbl&, Tbl&, int&, Tbl& ) {
00071 
00072     cout << "Unexpected basis in primr : basis = " << hex << bin << endl ; 
00073     abort() ;  
00074 
00075 }
00076 
00077 // case R_CHEB
00078 //------------
00079 void _primr_r_cheb(const Tbl& tin, int bin, const Tbl& valm1, Tbl& tout, 
00080         int& bout, Tbl& valp1) {
00081 
00082     assert(tin.dim == tout.dim) ;   
00083 
00084     // Output spectral basis
00085     bout = bin ; 
00086 
00087     // Number of coefficients
00088     int nr = tin.get_dim(0) ;       
00089     int nt = tin.get_dim(1) ;       
00090     int np = tin.get_dim(2) - 2 ;
00091     int borne_phi = np + 1 ; 
00092     if (np == 1) borne_phi = 1 ; 
00093     
00094     // Case of a zero input or pure angular grid
00095     // -----------------------------------------
00096     if ((tin.get_etat() == ETATZERO)||(nr == 1)) {
00097         if (valm1.get_etat() == ETATZERO) {
00098             tout.set_etat_zero() ; 
00099             valp1.set_etat_zero() ;
00100             return ; 
00101         }
00102         else {
00103             assert(valm1.get_etat() == ETATQCQ) ; 
00104             tout.set_etat_qcq() ; 
00105             valp1.set_etat_qcq() ; 
00106             double* xco = tout.t ;  
00107             for (int k=0 ; k< borne_phi ; k++) {
00108             if (k==1) {     // jump over the coefficient of sin(0*phi) 
00109                 xco += nr*nt ;
00110             }
00111             else {
00112                 for (int j=0 ; j<nt ; j++) {
00113                         xco[0] = valm1(k,j) ;  // constant value = boundary value
00114                         for (int i=1; i<nr; i++) xco[i] = 0 ; 
00115                         valp1.set(k,j) = xco[0]  ;
00116                     xco += nr ;
00117                     }
00118                 }
00119             }
00120             return ; 
00121         }
00122     }
00123 
00124     // Case of a non-zero input
00125     // ------------------------
00126 
00127     assert(tin.get_etat() == ETATQCQ ) ; 
00128     tout.annule_hard() ; 
00129     valp1.annule_hard() ; 
00130     
00131     const double* xci = tin.t ; 
00132     double* xco = tout.t ;  
00133 
00134     for (int k=0 ; k< borne_phi ; k++) {
00135         if (k==1) {     // jump over the coefficient of sin(0*phi) 
00136             xci += nr*nt ;
00137             xco += nr*nt ;
00138         }
00139         else {
00140             for (int j=0 ; j<nt ; j++) {
00141             
00142                 xco[1] = xci[0] - 0.5 * xci[2] ; // special case i = 1
00143 
00144                 for (int i=2; i<nr-2; i++) {
00145                     xco[i] = (xci[i-1] - xci[i+1]) / double(2*i) ; 
00146                 }
00147                 
00148                 xco[nr-2] = xci[nr-3] / double(2*nr - 4) ; 
00149                 xco[nr-1] = xci[nr-2] / double(2*nr - 2) ; 
00150 
00151                 // Determination of the T_0 coefficient by matching with
00152                 // provided value at xi = - 1 : 
00153                 double som = - xco[1] ; 
00154                 for (int i=2; i<nr; i+=2) som += xco[i] ; 
00155                 for (int i=3; i<nr; i+=2) som -= xco[i] ; 
00156                 xco[0] = valm1(k,j) - som ;                 
00157 
00158                 // Value of primitive at xi = + 1 : 
00159                 som = xco[0] ; 
00160                 for (int i=1; i<nr; i++) som += xco[i] ;
00161                 valp1.set(k,j) = som ; 
00162                 
00163                 xci += nr ;
00164                 xco += nr ;
00165             }   // end of theta loop
00166         }   
00167     }   // end of phi loop
00168 
00169 }
00170 
00171 
00172 
00173 // case R_CHEBP
00174 //-------------
00175 void _primr_r_chebp(const Tbl& tin, int bin, const Tbl&, Tbl& tout, 
00176         int& bout, Tbl& valp1) {
00177 
00178     assert(tin.dim == tout.dim) ;   
00179 
00180     // Output spectral basis
00181     int base_t = bin & MSQ_T ;
00182     int base_p = bin & MSQ_P ;
00183     bout = base_p | base_t | R_CHEBI ;
00184 
00185     // Number of coefficients
00186     int nr = tin.get_dim(0) ;       
00187     int nt = tin.get_dim(1) ;       
00188     int np = tin.get_dim(2) - 2 ;
00189     int borne_phi = np + 1 ; 
00190     if (np == 1) borne_phi = 1 ; 
00191         
00192     // Case of a zero input
00193     // --------------------
00194     if (tin.get_etat() == ETATZERO) {
00195         tout.set_etat_zero() ; 
00196         valp1.set_etat_zero() ; 
00197         return ; 
00198     }
00199 
00200     // Case of a non-zero input
00201     // ------------------------
00202 
00203     assert(tin.get_etat() == ETATQCQ ) ; 
00204     tout.annule_hard() ; 
00205     valp1.annule_hard() ; 
00206     
00207     const double* xci = tin.t ; 
00208     double* xco = tout.t ;  
00209 
00210     for (int k=0 ; k< borne_phi ; k++) {
00211         if (k==1) {     // jump over the coefficient of sin(0*phi) 
00212             xci += nr*nt ;
00213             xco += nr*nt ;
00214         }
00215         else {
00216             for (int j=0 ; j<nt ; j++) {
00217             
00218                 xco[0] = xci[0] - 0.5*xci[1] ; // special case i = 0
00219 
00220                 for (int i=1; i<nr-2; i++) {
00221                     xco[i] = (xci[i] - xci[i+1]) / double(4*i+2) ; 
00222                 }
00223                 
00224                 xco[nr-2] = xci[nr-2] / double(4*nr - 6) ; 
00225                 xco[nr-1] = 0 ; 
00226 
00227                 // Value of primitive at xi = + 1 : 
00228                 double som = xco[0] ; 
00229                 for (int i=1; i<nr; i++) som += xco[i] ;
00230                 valp1.set(k,j) = som ; 
00231                 
00232                 xci += nr ;
00233                 xco += nr ;
00234             }   // end of theta loop
00235         }   
00236     }   // end of phi loop
00237 
00238 }
00239 
00240 
00241 // case R_CHEBI
00242 //-------------
00243 void _primr_r_chebi(const Tbl& tin, int bin, const Tbl& val0, Tbl& tout, 
00244         int& bout, Tbl& valp1) {
00245 
00246     assert(tin.dim == tout.dim) ;   
00247 
00248     // Output spectral basis
00249     int base_t = bin & MSQ_T ;
00250     int base_p = bin & MSQ_P ;
00251     bout = base_p | base_t | R_CHEBP ;
00252 
00253     // Number of coefficients
00254     int nr = tin.get_dim(0) ;       
00255     int nt = tin.get_dim(1) ;       
00256     int np = tin.get_dim(2) - 2 ;
00257     int borne_phi = np + 1 ; 
00258     if (np == 1) borne_phi = 1 ; 
00259     
00260 
00261     // Case of a zero input
00262     // --------------------
00263     if (tin.get_etat() == ETATZERO) {
00264         if (val0.get_etat() == ETATZERO) {
00265             tout.set_etat_zero() ; 
00266             valp1.set_etat_zero() ; 
00267             return ; 
00268         }
00269         else {
00270             assert(val0.get_etat() == ETATQCQ) ; 
00271             tout.annule_hard() ; 
00272             valp1.annule_hard() ; 
00273             double* xco = tout.t ;  
00274             for (int k=0 ; k< borne_phi ; k++) {
00275             if (k==1) {     // jump over the coefficient of sin(0*phi) 
00276                 xco += nr*nt ;
00277             }
00278             else {
00279                 for (int j=0 ; j<nt ; j++) {
00280                         xco[0] = val0(k,j) ;  // constant value = boundary value
00281                         for (int i=1; i<nr; i++) xco[i] = 0 ; 
00282                         valp1.set(k,j) = xco[0]  ;
00283                     xco += nr ;
00284                     }
00285                 }
00286             }
00287             return ; 
00288         }
00289     }
00290 
00291     // Case of a non-zero input
00292     // ------------------------
00293 
00294     assert(tin.get_etat() == ETATQCQ ) ; 
00295     tout.annule_hard() ; 
00296     valp1.annule_hard() ; 
00297     
00298     const double* xci = tin.t ; 
00299     double* xco = tout.t ;  
00300 
00301     for (int k=0 ; k< borne_phi ; k++) {
00302         if (k==1) {     // jump over the coefficient of sin(0*phi) 
00303             xci += nr*nt ;
00304             xco += nr*nt ;
00305         }
00306         else {
00307             for (int j=0 ; j<nt ; j++) {
00308             
00309                 for (int i=1; i<nr-1; i++) {
00310                     xco[i] = (xci[i-1] - xci[i]) / double(4*i) ; 
00311                 }
00312                 
00313                 xco[nr-1] = xci[nr-2] / double(4*nr - 4) ; 
00314 
00315                 // Determination of the T_0 coefficient by maching with
00316                 // provided value at xi = 0 : 
00317                 double som = - xco[1] ; 
00318                 for (int i=2; i<nr; i+=2) som += xco[i] ; 
00319                 for (int i=3; i<nr; i+=2) som -= xco[i] ; 
00320                 xco[0] = val0(k,j) - som ;                 
00321 
00322                 // Value of primitive at xi = + 1 : 
00323                 som = xco[0] ; 
00324                 for (int i=1; i<nr; i++) som += xco[i] ;
00325                 valp1.set(k,j) = som ; 
00326 
00327                 xci += nr ;
00328                 xco += nr ;
00329             }   // end of theta loop
00330         }   
00331     }   // end of phi loop
00332 
00333 }
00334 
00335 
00336 
00337 // case R_CHEBPIM_P
00338 //-----------------
00339 void _primr_r_chebpim_p(const Tbl& tin, int bin, const Tbl& val0, Tbl& tout, 
00340         int& bout, Tbl& valp1) {
00341 
00342     assert(tin.dim == tout.dim) ;   
00343 
00344     // Output spectral basis
00345     int base_t = bin & MSQ_T ;
00346     int base_p = bin & MSQ_P ;
00347     bout = base_p | base_t | R_CHEBPIM_I ;
00348 
00349     // Number of coefficients
00350     int nr = tin.get_dim(0) ;       
00351     int nt = tin.get_dim(1) ;       
00352     int np = tin.get_dim(2) - 2 ;
00353     
00354 
00355     // Case of a zero input
00356     // --------------------
00357     if (tin.get_etat() == ETATZERO) {
00358         if (val0.get_etat() == ETATZERO) {
00359             tout.set_etat_zero() ; 
00360             valp1.set_etat_zero() ; 
00361             return ; 
00362         }
00363         else {
00364             assert(val0.get_etat() == ETATQCQ) ; 
00365             tout.annule_hard() ; 
00366             valp1.annule_hard() ; 
00367             double* xco = tout.t ;  
00368 
00369             // m even part 
00370             for (int k=0 ; k<np+1 ; k += 4) {
00371             int auxiliaire = (k==np) ? 1 : 2 ; // to avoid the last coef
00372             for (int kmod=0 ; kmod<auxiliaire ; kmod++) {
00373                 if ((k==0) && (kmod == 1)) {     // jump over the coefficient of sin(0*phi) 
00374                     xco += nr*nt ;
00375                 }
00376                 else {
00377                     for (int j=0 ; j<nt ; j++) {
00378                             assert( val0(k+kmod,j) == double(0) ) ; 
00379                             for (int i=0; i<nr; i++) xco[i] = 0 ; 
00380                             valp1.set(k+kmod,j) = 0. ;
00381                         xco += nr ;
00382                         }
00383                     }
00384                 }
00385                 xco += 2*nr*nt ;    // next even m
00386             }
00387             
00388             // m odd part
00389             xco = tout.t + 2*nr*nt ; 
00390             for (int k=2 ; k<np+1 ; k += 4) {
00391             int auxiliaire = (k==np) ? 1 : 2 ; // to avoid the last coef
00392             for (int kmod=0 ; kmod<auxiliaire ; kmod++) {
00393                 for (int j=0 ; j<nt ; j++) {
00394                         xco[0] = val0(k+kmod,j) ;  // constant value = boundary value
00395                         for (int i=1; i<nr; i++) xco[i] = 0 ; 
00396                         valp1.set(k+kmod,j) = xco[0] ;
00397                     xco += nr ;
00398                     }
00399                 }
00400                 xco += 2*nr*nt ;    // next odd m
00401             }
00402             return ; 
00403         }
00404     }
00405 
00406     // Case of a non-zero input
00407     // ------------------------
00408 
00409     assert(tin.get_etat() == ETATQCQ ) ; 
00410     tout.annule_hard() ; 
00411     valp1.annule_hard() ; 
00412     
00413     const double* xci = tin.t ; 
00414     double* xco = tout.t ;  
00415 
00416     // m even part 
00417     // -----------
00418     for (int k=0 ; k<np+1 ; k += 4) {
00419         int auxiliaire = (k==np) ? 1 : 2 ; // to avoid the last coef
00420         for (int kmod=0 ; kmod<auxiliaire ; kmod++) {
00421             if ((k==0) && (kmod == 1)) {     // jump over the coefficient of sin(0*phi) 
00422                 xci += nr*nt ;
00423                 xco += nr*nt ;
00424             }
00425             else {
00426                 for (int j=0 ; j<nt ; j++) {
00427                     xco[0] = xci[0] - 0.5*xci[1] ; // special case i = 0
00428 
00429                     for (int i=1; i<nr-2; i++) {
00430                         xco[i] = (xci[i] - xci[i+1]) / double(4*i+2) ; 
00431                     }
00432                 
00433                     xco[nr-2] = xci[nr-2] / double(4*nr - 6) ; 
00434                     xco[nr-1] = 0 ; 
00435 
00436                     // Value of primitive at xi = + 1 : 
00437                     double som = xco[0] ; 
00438                     for (int i=1; i<nr; i++) som += xco[i] ;
00439                     valp1.set(k+kmod,j) = som ; 
00440                 
00441                     xci += nr ;
00442                     xco += nr ;
00443                 }   // end of theta loop
00444                     
00445             }
00446         }
00447         xci += 2*nr*nt ;    // next even m
00448         xco += 2*nr*nt ;    // 
00449     }
00450 
00451     // m odd part 
00452     // ----------
00453     xci = tin.t + 2*nr*nt ;
00454     xco = tout.t + 2*nr*nt ;
00455     for (int k=2 ; k<np+1 ; k += 4) {
00456         int auxiliaire = (k==np) ? 1 : 2 ; // to avoid the last coef
00457         for (int kmod=0 ; kmod<auxiliaire ; kmod++) {
00458             for (int j=0 ; j<nt ; j++) {
00459             
00460                 for (int i=1; i<nr-1; i++) {
00461                     xco[i] = (xci[i-1] - xci[i]) / double(4*i) ; 
00462                 }
00463                 
00464                 xco[nr-1] = xci[nr-2] / double(4*nr - 4) ; 
00465 
00466                 // Determination of the T_0 coefficient by maching with
00467                 // provided value at xi = 0 : 
00468                 double som = - xco[1] ; 
00469                 for (int i=2; i<nr; i+=2) som += xco[i] ; 
00470                 for (int i=3; i<nr; i+=2) som -= xco[i] ; 
00471                 xco[0] = val0(k+kmod,j) - som ;                 
00472 
00473                 // Value of primitive at xi = + 1 : 
00474                 som = xco[0] ; 
00475                 for (int i=1; i<nr; i++) som += xco[i] ;
00476                 valp1.set(k+kmod,j) = som ; 
00477                 
00478                 xci += nr ;
00479                 xco += nr ;
00480             }   // end of theta loop
00481         }
00482         xci += 2*nr*nt ;    // next odd m
00483         xco += 2*nr*nt ;    // 
00484     }
00485 
00486 
00487 }
00488 
00489 
00490 
00491 // case R_CHEBPIM_I
00492 //-----------------
00493 void _primr_r_chebpim_i(const Tbl& tin, int bin, const Tbl& val0, Tbl& tout, 
00494         int& bout, Tbl& valp1) {
00495 
00496     assert(tin.dim == tout.dim) ;   
00497 
00498     // Output spectral basis
00499     int base_t = bin & MSQ_T ;
00500     int base_p = bin & MSQ_P ;
00501     bout = base_p | base_t | R_CHEBPIM_P ;
00502 
00503     // Number of coefficients
00504     int nr = tin.get_dim(0) ;       
00505     int nt = tin.get_dim(1) ;       
00506     int np = tin.get_dim(2) - 2 ;
00507     
00508 
00509     // Case of a zero input
00510     // --------------------
00511     if (tin.get_etat() == ETATZERO) {
00512         if (val0.get_etat() == ETATZERO) {
00513             tout.set_etat_zero() ; 
00514             valp1.set_etat_zero() ; 
00515             return ; 
00516         }
00517         else {
00518             assert(val0.get_etat() == ETATQCQ) ; 
00519             tout.annule_hard() ; 
00520             valp1.annule_hard() ; 
00521             double* xco = tout.t ;  
00522 
00523             // m odd part 
00524             for (int k=0 ; k<np+1 ; k += 4) {
00525             int auxiliaire = (k==np) ? 1 : 2 ; // to avoid the last coef
00526             for (int kmod=0 ; kmod<auxiliaire ; kmod++) {
00527                 if ((k==0) && (kmod == 1)) {     // jump over the coefficient of sin(0*phi) 
00528                     xco += nr*nt ;
00529                 }
00530                 else {
00531                     for (int j=0 ; j<nt ; j++) {
00532                             xco[0] = val0(k+kmod,j) ;  // constant value = boundary value
00533                             for (int i=1; i<nr; i++) xco[i] = 0 ; 
00534                             valp1.set(k+kmod,j) = xco[0] ;
00535                         xco += nr ;
00536                         }
00537                     }
00538                 }
00539                 xco += 2*nr*nt ;    // next odd m
00540             }
00541             
00542             // m even part
00543             xco = tout.t + 2*nr*nt ; 
00544             for (int k=2 ; k<np+1 ; k += 4) {
00545             int auxiliaire = (k==np) ? 1 : 2 ; // to avoid the last coef
00546             for (int kmod=0 ; kmod<auxiliaire ; kmod++) {
00547                     for (int j=0 ; j<nt ; j++) {
00548                             assert( val0(k+kmod,j) == double(0) ) ; 
00549                             for (int i=0; i<nr; i++) xco[i] = 0 ; 
00550                             valp1.set(k+kmod,j) = 0. ;
00551                         xco += nr ;
00552                         }
00553                 }
00554                 xco += 2*nr*nt ;    // next even m
00555             }
00556             return ; 
00557         }
00558     }
00559 
00560     // Case of a non-zero input
00561     // ------------------------
00562 
00563     assert(tin.get_etat() == ETATQCQ ) ; 
00564     tout.annule_hard() ; 
00565     valp1.annule_hard() ; 
00566     
00567     const double* xci = tin.t ; 
00568     double* xco = tout.t ;  
00569 
00570     // m odd part 
00571     // ----------
00572     for (int k=0 ; k<np+1 ; k += 4) {
00573         int auxiliaire = (k==np) ? 1 : 2 ; // to avoid the last coef
00574         for (int kmod=0 ; kmod<auxiliaire ; kmod++) {
00575             if ((k==0) && (kmod == 1)) {     // jump over the coefficient of sin(0*phi) 
00576                 xci += nr*nt ;
00577                 xco += nr*nt ;
00578             }
00579             else {
00580                 for (int j=0 ; j<nt ; j++) {
00581             
00582                     for (int i=1; i<nr-1; i++) {
00583                         xco[i] = (xci[i-1] - xci[i]) / double(4*i) ; 
00584                     }
00585                 
00586                     xco[nr-1] = xci[nr-2] / double(4*nr - 4) ; 
00587 
00588                     // Determination of the T_0 coefficient by maching with
00589                     // provided value at xi = 0 : 
00590                     double som = - xco[1] ; 
00591                     for (int i=2; i<nr; i+=2) som += xco[i] ; 
00592                     for (int i=3; i<nr; i+=2) som -= xco[i] ; 
00593                     xco[0] = val0(k+kmod,j) - som ;                 
00594 
00595                     // Value of primitive at xi = + 1 : 
00596                     som = xco[0] ; 
00597                     for (int i=1; i<nr; i++) som += xco[i] ;
00598                     valp1.set(k+kmod,j) = som ; 
00599                 
00600                     xci += nr ;
00601                     xco += nr ;
00602                 }   // end of theta loop                    
00603             }
00604         }
00605         xci += 2*nr*nt ;    // next odd m
00606         xco += 2*nr*nt ;    // 
00607     }
00608 
00609     // m even part 
00610     // -----------
00611     xci = tin.t + 2*nr*nt ;
00612     xco = tout.t + 2*nr*nt ;
00613     for (int k=2 ; k<np+1 ; k += 4) {
00614         int auxiliaire = (k==np) ? 1 : 2 ; // to avoid the last coef
00615         for (int kmod=0 ; kmod<auxiliaire ; kmod++) {
00616 
00617             for (int j=0 ; j<nt ; j++) {
00618                 xco[0] = xci[0] - 0.5*xci[1] ; // special case i = 0
00619 
00620                 for (int i=1; i<nr-2; i++) {
00621                     xco[i] = (xci[i] - xci[i+1]) / double(4*i+2) ; 
00622                 }
00623                 
00624                 xco[nr-2] = xci[nr-2] / double(4*nr - 6) ; 
00625                 xco[nr-1] = 0 ; 
00626 
00627                 // Value of primitive at xi = + 1 : 
00628                 double som = xco[0] ; 
00629                 for (int i=1; i<nr; i++) som += xco[i] ;
00630                 valp1.set(k+kmod,j) = som ; 
00631                 
00632                 xci += nr ;
00633                 xco += nr ;
00634             }   // end of theta loop
00635 
00636         }
00637         xci += 2*nr*nt ;    // next even m
00638         xco += 2*nr*nt ;    // 
00639     }
00640 
00641 
00642 }
00643 
00644 // case R_CHEBPI_P
00645 //-------------
00646 void _primr_r_chebpi_p(const Tbl& tin, int bin, const Tbl& val0, Tbl& tout, 
00647         int& bout, Tbl& valp1) {
00648 
00649     assert(tin.dim == tout.dim) ;   
00650 
00651     // Output spectral basis
00652     int base_t = bin & MSQ_T ;
00653     int base_p = bin & MSQ_P ;
00654     bout = base_p | base_t | R_CHEBPI_I ;
00655 
00656     // Number of coefficients
00657     int nr = tin.get_dim(0) ;       
00658     int nt = tin.get_dim(1) ;       
00659     int np = tin.get_dim(2) - 2 ;
00660     int borne_phi = np + 1 ; 
00661     if (np == 1) borne_phi = 1 ; 
00662       
00663 
00664      // Case of a zero input
00665     // --------------------
00666     if (tin.get_etat() == ETATZERO) {
00667         if (val0.get_etat() == ETATZERO) {
00668             tout.set_etat_zero() ; 
00669             valp1.set_etat_zero() ; 
00670             return ; 
00671         }
00672         else {
00673             assert(val0.get_etat() == ETATQCQ) ; 
00674             tout.annule_hard() ; 
00675             valp1.annule_hard() ; 
00676             double* xco = tout.t ;  
00677             for (int k=0 ; k< borne_phi ; k++) {
00678             if (k==1) {     // jump over the coefficient of sin(0*phi) 
00679                 xco += nr*nt ;
00680             }
00681             else {
00682                 for (int j=0 ; j<nt ; j++) {
00683               int l = j%2;
00684               if(l==0){
00685             for (int i=0; i<nr; i++) xco[i] = 0 ; 
00686             valp1.set(k,j) = 0. ;
00687               } else {
00688                         xco[0] = val0(k,j) ;  // constant value = boundary value
00689                         for (int i=1; i<nr; i++) xco[i] = 0 ; 
00690                         valp1.set(k,j) = xco[0]  ;
00691               }
00692               xco += nr ;
00693                     }
00694                 }
00695             }
00696             return ; 
00697         }
00698     }
00699    
00700     // Case of a non-zero input
00701     // ------------------------
00702 
00703     assert(tin.get_etat() == ETATQCQ ) ; 
00704     tout.annule_hard() ; 
00705     valp1.annule_hard() ; 
00706     
00707     const double* xci = tin.t ; 
00708     double* xco = tout.t ;  
00709 
00710     for (int k=0 ; k< borne_phi ; k++) {
00711         if (k==1) {     // jump over the coefficient of sin(0*phi) 
00712             xci += nr*nt ;
00713             xco += nr*nt ;
00714         }
00715         else {
00716             for (int j=0 ; j<nt ; j++) {
00717 
00718             int l = j%2;
00719         if(l==0){
00720           xco[0] = xci[0] - 0.5*xci[1] ; // special case i = 0
00721           
00722           for (int i=1; i<nr-2; i++) {
00723                     xco[i] = (xci[i] - xci[i+1]) / double(4*i+2) ; 
00724           }
00725           
00726           xco[nr-2] = xci[nr-2] / double(4*nr - 6) ; 
00727           xco[nr-1] = 0 ; 
00728           
00729           // Value of primitive at xi = + 1 : 
00730           double som = xco[0] ; 
00731           for (int i=1; i<nr; i++) som += xco[i] ;
00732           valp1.set(k,j) = som ;
00733         } else {
00734           for (int i=1; i<nr-1; i++) {
00735                     xco[i] = (xci[i-1] - xci[i]) / double(4*i) ; 
00736           }
00737           
00738           xco[nr-1] = xci[nr-2] / double(4*nr - 4) ; 
00739           
00740           // Determination of the T_0 coefficient by maching with
00741           // provided value at xi = 0 : 
00742           double som = - xco[1] ; 
00743           for (int i=2; i<nr; i+=2) som += xco[i] ; 
00744           for (int i=3; i<nr; i+=2) som -= xco[i] ; 
00745           xco[0] = val0(k,j) - som ;                 
00746           
00747           // Value of primitive at xi = + 1 : 
00748           som = xco[0] ; 
00749           for (int i=1; i<nr; i++) som += xco[i] ;
00750           valp1.set(k,j) = som ; 
00751                 }
00752                 xci += nr ;
00753                 xco += nr ;
00754             }   // end of theta loop
00755         }   
00756     }   // end of phi loop
00757 
00758 }
00759 // case R_CHEBPI_I
00760 //-------------
00761 void _primr_r_chebpi_i(const Tbl& tin, int bin, const Tbl& val0, Tbl& tout, 
00762         int& bout, Tbl& valp1) {
00763 
00764     assert(tin.dim == tout.dim) ;   
00765 
00766     // Output spectral basis
00767     int base_t = bin & MSQ_T ;
00768     int base_p = bin & MSQ_P ;
00769     bout = base_p | base_t | R_CHEBPI_P ;
00770 
00771     // Number of coefficients
00772     int nr = tin.get_dim(0) ;       
00773     int nt = tin.get_dim(1) ;       
00774     int np = tin.get_dim(2) - 2 ;
00775     int borne_phi = np + 1 ; 
00776     if (np == 1) borne_phi = 1 ; 
00777       
00778 
00779      // Case of a zero input
00780     // --------------------
00781     if (tin.get_etat() == ETATZERO) {
00782         if (val0.get_etat() == ETATZERO) {
00783             tout.set_etat_zero() ; 
00784             valp1.set_etat_zero() ; 
00785             return ; 
00786         }
00787         else {
00788             assert(val0.get_etat() == ETATQCQ) ; 
00789             tout.annule_hard() ; 
00790             valp1.annule_hard() ; 
00791             double* xco = tout.t ;  
00792             for (int k=0 ; k< borne_phi ; k++) {
00793             if (k==1) {     // jump over the coefficient of sin(0*phi) 
00794                 xco += nr*nt ;
00795             }
00796             else {
00797                 for (int j=0 ; j<nt ; j++) {
00798               int l = j%2;
00799               if(l==1){
00800             for (int i=0; i<nr; i++) xco[i] = 0 ; 
00801             valp1.set(k,j) = 0. ;
00802               } else {
00803                         xco[0] = val0(k,j) ;  // constant value = boundary value
00804                         for (int i=1; i<nr; i++) xco[i] = 0 ; 
00805                         valp1.set(k,j) = xco[0]  ;
00806               }
00807               xco += nr ;
00808                     }
00809                 }
00810             }
00811             return ; 
00812         }
00813     }
00814    
00815     // Case of a non-zero input
00816     // ------------------------
00817 
00818     assert(tin.get_etat() == ETATQCQ ) ; 
00819     tout.annule_hard() ; 
00820     valp1.annule_hard() ; 
00821     
00822     const double* xci = tin.t ; 
00823     double* xco = tout.t ;  
00824 
00825     for (int k=0 ; k< borne_phi ; k++) {
00826         if (k==1) {     // jump over the coefficient of sin(0*phi) 
00827             xci += nr*nt ;
00828             xco += nr*nt ;
00829         }
00830         else {
00831             for (int j=0 ; j<nt ; j++) {
00832 
00833             int l = j%2;
00834         if(l==1){
00835           xco[0] = xci[0] - 0.5*xci[1] ; // special case i = 0
00836           
00837           for (int i=1; i<nr-2; i++) {
00838                     xco[i] = (xci[i] - xci[i+1]) / double(4*i+2) ; 
00839           }
00840           
00841           xco[nr-2] = xci[nr-2] / double(4*nr - 6) ; 
00842           xco[nr-1] = 0 ; 
00843           
00844           // Value of primitive at xi = + 1 : 
00845           double som = xco[0] ; 
00846           for (int i=1; i<nr; i++) som += xco[i] ;
00847           valp1.set(k,j) = som ;
00848         } else {
00849           for (int i=1; i<nr-1; i++) {
00850                     xco[i] = (xci[i-1] - xci[i]) / double(4*i) ; 
00851           }
00852           
00853           xco[nr-1] = xci[nr-2] / double(4*nr - 4) ; 
00854           
00855           // Determination of the T_0 coefficient by maching with
00856           // provided value at xi = 0 : 
00857           double som = - xco[1] ; 
00858           for (int i=2; i<nr; i+=2) som += xco[i] ; 
00859           for (int i=3; i<nr; i+=2) som -= xco[i] ; 
00860           xco[0] = val0(k,j) - som ;                 
00861           
00862           // Value of primitive at xi = + 1 : 
00863           som = xco[0] ; 
00864           for (int i=1; i<nr; i++) som += xco[i] ;
00865           valp1.set(k,j) = som ; 
00866                 }
00867                 xci += nr ;
00868                 xco += nr ;
00869             }   // end of theta loop
00870         }   
00871     }   // end of phi loop
00872 
00873 }
00874 
00875 
00876 // case R_JACO02
00877 //------------
00878 void _primr_r_jaco02(const Tbl& tin, int bin, const Tbl& valm1, Tbl& tout, 
00879         int& bout, Tbl& valp1) {
00880 
00881     assert(tin.dim == tout.dim) ;   
00882 
00883     // Output spectral basis
00884     bout = bin ; 
00885 
00886     // Number of coefficients
00887     int nr = tin.get_dim(0) ;       
00888     int nt = tin.get_dim(1) ;       
00889     int np = tin.get_dim(2) - 2 ;
00890     int borne_phi = np + 1 ; 
00891     if (np == 1) borne_phi = 1 ; 
00892     
00893     // Case of a zero input or pure angular grid
00894     // -----------------------------------------
00895     if ((tin.get_etat() == ETATZERO)||(nr == 1)) {
00896         if (valm1.get_etat() == ETATZERO) {
00897             tout.set_etat_zero() ; 
00898             valp1.set_etat_zero() ;
00899             return ; 
00900         }
00901         else {
00902             assert(valm1.get_etat() == ETATQCQ) ; 
00903             tout.set_etat_qcq() ; 
00904             valp1.set_etat_qcq() ; 
00905             double* xco = tout.t ;  
00906             for (int k=0 ; k< borne_phi ; k++) {
00907             if (k==1) {     // jump over the coefficient of sin(0*phi) 
00908                 xco += nr*nt ;
00909             }
00910             else {
00911                 for (int j=0 ; j<nt ; j++) {
00912                         xco[0] = valm1(k,j) ;  // constant value = boundary value
00913                         for (int i=1; i<nr; i++) xco[i] = 0 ; 
00914                         valp1.set(k,j) = xco[0]  ;
00915                     xco += nr ;
00916                     }
00917                 }
00918             }
00919             return ; 
00920         }
00921     }
00922 
00923     // Case of a non-zero input
00924     // ------------------------
00925 
00926     assert(tin.get_etat() == ETATQCQ ) ; 
00927     tout.annule_hard() ; 
00928     valp1.annule_hard() ; 
00929     
00930     const double* xci = tin.t ; 
00931     double* xco = tout.t ;  
00932 
00933     for (int k=0 ; k< borne_phi ; k++) {
00934         if (k==1) {     // jump over the coefficient of sin(0*phi) 
00935             xci += nr*nt ;
00936             xco += nr*nt ;
00937         }
00938         else {
00939             for (int j=0 ; j<nt ; j++) {
00940             
00941                 for (int i=1; i<nr-1; i++) {
00942                     xco[i] = (i+2)/double((i+1)*(2*i+1))*xci[i-1] - xci[i]/double((i+1)*(i+2)) - (i+1)/double((i+2)*(2*i+5))*xci[i+1] ; 
00943                 }
00944                 xco[nr-1] = (nr+1)/double((nr)*(2*nr-1))*xci[nr-2] - xci[nr-1]/double((nr)*(nr+1)); 
00945 
00946                 // Determination of the J_0 coefficient by matching with
00947                 // provided value at xi = - 1 : 
00948 
00949                 double som = -3*xco[1] ; 
00950                 for (int i=2; i<nr; i++) {
00951             int signe = (i%2 == 0 ? 1 : -1) ; 
00952             som += xco[i]*signe*(i+1)*(i+2)/double(2) ; 
00953         }
00954                 xco[0] = valm1(k,j) - som ;                 
00955 
00956                 // Value of primitive at xi = + 1 : 
00957                 som = xco[0] ; 
00958                 for (int i=1; i<nr; i++) som += xco[i] ;
00959                 valp1.set(k,j) = som ; 
00960                 
00961                 xci += nr ;
00962                 xco += nr ;
00963             }   // end of theta loop
00964         }   
00965     }   // end of phi loop
00966 
00967 }
00968 
00969 
00970 
00971 
00972 
00973 
00974 
00975 
00976 
00977 
00978 
00979 
00980 
00981 
00982 
00983 
00984 
00985 
00986 
00987  

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