tbl_val_interp.C

00001 /*
00002  * Methods for making interpolations with Godunov-type arrays.
00003  *
00004  * See the file tbl_val.h for documentation
00005  *
00006  */
00007 
00008 /*
00009  *   Copyright (c) 2001 Jerome Novak
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 
00030 char TBL_VAL_INTER_C[] = "$Header: /cvsroot/Lorene/C++/Source/Valencia/tbl_val_interp.C,v 1.10 2007/12/21 10:46:29 j_novak Exp $" ;
00031 
00032 /*
00033  * $Id: tbl_val_interp.C,v 1.10 2007/12/21 10:46:29 j_novak Exp $
00034  * $Log: tbl_val_interp.C,v $
00035  * Revision 1.10  2007/12/21 10:46:29  j_novak
00036  * In "from_spectral..." functions: better treatment of ETATZERO case.
00037  *
00038  * Revision 1.9  2007/11/02 16:49:12  j_novak
00039  * Suppression of intermediate array for spectral summation.
00040  *
00041  * Revision 1.8  2005/06/23 13:40:08  j_novak
00042  * The tests on the number of dimensions have been changed to handle better the
00043  * axisymmetric case.
00044  *
00045  * Revision 1.7  2005/06/22 09:11:17  lm_lin
00046  *
00047  * Grid wedding: convert from the old C++ object "Cmp" to "Scalar".
00048  *
00049  * Revision 1.6  2003/12/19 15:05:15  j_novak
00050  * Trying to avoid shadowed variables
00051  *
00052  * Revision 1.5  2003/10/03 16:17:17  j_novak
00053  * Corrected some const qualifiers
00054  *
00055  * Revision 1.4  2002/11/13 11:22:57  j_novak
00056  * Version "provisoire" de l'interpolation (sommation depuis la grille
00057  * spectrale) aux interfaces de la grille de Valence.
00058  *
00059  * Revision 1.3  2002/10/16 14:37:15  j_novak
00060  * Reorganization of #include instructions of standard C++, in order to
00061  * use experimental version 3 of gcc.
00062  *
00063  * Revision 1.2  2001/11/23 16:03:07  j_novak
00064  *
00065  *  minor modifications on the grid check.
00066  *
00067  * Revision 1.1  2001/11/22 13:41:54  j_novak
00068  * Added all source files for manipulating Valencia type objects and making
00069  * interpolations to and from Meudon grids.
00070  *
00071  *
00072  * $Header: /cvsroot/Lorene/C++/Source/Valencia/tbl_val_interp.C,v 1.10 2007/12/21 10:46:29 j_novak Exp $
00073  *
00074  */
00075 
00076 // headers C
00077 #include <math.h>
00078 
00079 // headers Lorene
00080 #include "headcpp.h"
00081 #include "tbl_val.h"
00082 
00083 
00084 Scalar Tbl_val::to_spectral(const Map& mp, const int lmax, const int lmin, 
00085                  int type_inter) const {
00086 
00087   assert(etat != ETATNONDEF) ;
00088   assert( gval->compatible(&mp, lmax, lmin) ) ;
00089   Scalar resu(mp) ;
00090 
00091   if (etat == ETATZERO) {
00092     resu.annule(lmin, lmax-1) ;
00093     return resu ;
00094   }
00095   else {
00096     int nzin = lmax - lmin ;
00097     int dim_spec = 1 ;
00098     const Mg3d* mgrid = mp.get_mg() ;
00099     for (int i=lmin; i<lmax; i++) {
00100       if ((mgrid->get_nt(i) > 1)&&(dim_spec==1)) dim_spec = 2; 
00101       if (mgrid->get_np(i) > 1) dim_spec = 3;
00102     }
00103     const Coord& rr = mp.r ;
00104     
00105     int* ntet = new int[nzin] ;
00106     int ntetmax = 1 ;
00107     int* nphi = new int[nzin] ;
00108     int nphimax = 1 ;
00109     for (int i=lmin; i<lmax; i++) {
00110       int tmp = mgrid->get_np(i) ;
00111       nphi[i-lmin] = tmp ;
00112       nphimax = (tmp > nphimax ? tmp : nphimax) ;
00113       tmp = mgrid->get_nt(i) ;
00114       ntet[i-lmin] = tmp ;
00115       ntetmax = (tmp > ntetmax ? tmp : ntetmax) ;
00116     }
00117     if (dim_spec > 1) {
00118       for (int i=lmin; i<lmax; i++) {
00119     if ((nphimax % nphi[i-lmin]) != 0) {
00120     cout << "Tbl_val::to_spectral: The numbers of points in phi" << endl ;
00121     cout << "in the different domains of Meudon grid are not" << endl;
00122     cout << "well defined; see the documentation." << endl ;
00123     abort() ;
00124     }
00125     assert((ntet[i-lmin]-1) > 0) ;
00126     if (((ntetmax-1) % (ntet[i-lmin]-1)) != 0) {
00127     cout <<"Tbl_val::to_spectral: The numbers of points in theta"<< endl ;
00128     cout << "in the different domains of Meudon grid are not" << endl;
00129     cout << "well defined; see the documentation." << endl ;
00130     abort() ;
00131     }
00132       }
00133     }
00134     
00135     resu.allocate_all() ;
00136     if (lmin>0) resu.annule(0,lmin-1) ;
00137     if (lmax < mgrid->get_nzone()) resu.annule(lmax, mgrid->get_nzone()-1) ;
00138     
00139     int fant = gval->get_fantome() ;
00140     int flag = 1 ; 
00141     int nrarr = 0 ;
00142     for (int l=lmin; l<lmax; l++) nrarr += mgrid->get_nr(l) -1 ;
00143     nrarr++ ;
00144     switch (dim_spec) {
00145       
00146     case 1: {
00147       int tsize = dim->dim[0] + 2*fant ;
00148       Tbl fdep(tsize) ; 
00149       fdep.set_etat_qcq() ;
00150       for (int i=0; i<tsize; i++) fdep.set(i) = t[i] ;
00151       Tbl farr(nrarr) ;
00152       Tbl rarr(nrarr) ;
00153       rarr.set_etat_qcq() ;
00154       int inum = 0 ;
00155       for (int l=lmin; l<lmax; l++) {
00156     for (int i=0; i<mgrid->get_nr(l); i++) {
00157       rarr.set(inum) = (+rr)(l,0,0,i) ;
00158       inum++ ;
00159     }
00160     inum--;
00161       }
00162       farr = gval->interpol1(*gval->zr, rarr, fdep, flag, type_inter) ;
00163       inum = 0 ;
00164       for (int l=lmin; l<lmax; l++) {
00165     for (int i=0; i<mgrid->get_nr(l); i++) {
00166       resu.set_grid_point(l,0,0,i) = farr(inum) ;
00167     inum++ ;
00168     }
00169     inum--;
00170       }
00171       break ;
00172     }
00173 
00174     case 2: {
00175       int tsizex = dim->dim[1] + 2*fant ;
00176       int tsizez = dim->dim[0] + 2*fant ;
00177       Tbl fdep(tsizex, tsizez) ;
00178       fdep.set_etat_qcq() ;
00179       for (int j=0; j<tsizex; j++) {
00180     for (int i=0; i<tsizez; i++) {
00181       int l = tsizez*j + i ;
00182       fdep.t[l] = t[l] ;
00183     }
00184       }
00185       Tbl farr(ntetmax, nrarr) ;
00186       Tbl rarr(nrarr) ;
00187       rarr.set_etat_qcq() ;
00188       Tbl tetarr(ntetmax) ;
00189       tetarr.set_etat_qcq() ;
00190       int ltmax = 0 ;
00191       int inum = 0 ;
00192       for (int l=lmin; l<lmax; l++) {
00193     if (ntetmax == ntet[l-lmin]) ltmax = l ;
00194     for (int i=0; i<mgrid->get_nr(l); i++) {
00195       rarr.set(inum) = (+rr)(l,0,0,i) ;
00196       inum++ ;
00197     }
00198     inum--;
00199       }
00200       const Coord& tet = mp.tet ;
00201       for (int j=0; j<ntetmax; j++) 
00202     tetarr.set(j) = (+tet)(ltmax,0,j,0) ;
00203       farr = gval->interpol2(fdep, rarr, tetarr, type_inter) ;
00204       inum = 0 ;
00205       for (int l=lmin; l<lmax; l++) {
00206     for (int j=0; j<ntet[l-lmin]; j++) {
00207       int itet = (ntetmax-1)/(ntet[l-lmin]-1)*j ;
00208       for (int i=0; i<mgrid->get_nr(l); i++) {
00209         resu.set_grid_point(l,0,j,i) = farr(itet,inum) ;
00210         inum++ ;
00211       }
00212       inum -= mgrid->get_nr(l) ;
00213     }
00214     inum += mgrid->get_nr(l) - 1;
00215       }
00216       break ;
00217     }
00218     
00219     case 3: {
00220       if (type_inter == 0) {
00221     cout << "The use of routine INSMTS is not well suited" << endl ;
00222     cout << "for 3D interpolation." << endl ;
00223     //  abort() ;
00224       }
00225       int tsizey = dim->dim[2] + 2*fant ;
00226       int tsizex = dim->dim[1] + 2*fant ;
00227       int tsizez = dim->dim[0] + 2*fant ;
00228       Tbl fdep(tsizey, tsizex, tsizez) ;
00229       fdep.set_etat_qcq() ;
00230       for (int k=0; k<tsizey; k++) {
00231     for (int j=0; j<tsizex; j++) {
00232       for (int i=0; i<tsizez; i++) {
00233         int l = (k*tsizex+j)*tsizez+i ;
00234         fdep.t[l] = t[l];
00235       }
00236     }
00237       }
00238       Tbl farr(nphimax, ntetmax, nrarr) ;
00239       Tbl rarr(nrarr) ;
00240       rarr.set_etat_qcq() ;
00241       Tbl tetarr(ntetmax) ;
00242       tetarr.set_etat_qcq() ;
00243       Tbl phiarr(nphimax) ;
00244       phiarr.set_etat_qcq() ;
00245       int lpmax = 0 ;
00246       int ltmax = 0 ;
00247       int inum = 0 ;
00248       for (int l=lmin; l<lmax; l++) {
00249     if (ntetmax == ntet[l-lmin]) ltmax = l ;
00250     if (nphimax == nphi[l-lmin]) lpmax = l ;
00251     for (int i=0; i<mgrid->get_nr(l); i++) {
00252       rarr.set(inum) = (+rr)(l,0,0,i) ;
00253       inum++ ;
00254     }
00255     inum-- ;
00256       }
00257       const Coord& tet = mp.tet ;
00258       const Coord& phi = mp.phi ;
00259       for (int k=0; k<nphimax; k++) {
00260       phiarr.set(k) = (+phi)(lpmax,k,0,0) ;
00261       }
00262       for (int j=0; j<ntetmax; j++) 
00263     tetarr.set(j) = (+tet)(ltmax,0,j,0) ;
00264       farr = gval->interpol3(fdep, rarr, tetarr, phiarr, type_inter) ;
00265       inum = 0 ;
00266       for (int l=lmin; l<lmax; l++) {
00267     for (int k=0; k<nphi[l-lmin]; k++) {
00268       int iphi = (nphimax-1)/(nphi[l-lmin]-1)*k ;
00269       for (int j=0; j<ntet[l-lmin]; j++) {
00270         int itet = (ntetmax-1)/(ntet[l-lmin]-1)*j ;
00271         for (int i=0; i<mgrid->get_nr(l); i++) {
00272           resu.set_grid_point(l,k,j,i) = farr(iphi,itet,inum) ;
00273           inum++ ;
00274         }
00275         inum -= mgrid->get_nr(l) ;
00276       }
00277     }
00278     inum += mgrid->get_nr(l) - 1 ;
00279       }
00280       break ;
00281     }
00282     
00283     default:
00284       cout << "Tbl_val::to_spectral:Strange error..." << endl ;
00285       abort() ;
00286       break ;
00287       
00288     }
00289     
00290     delete [] ntet ;
00291     delete [] nphi ;
00292     return resu ;
00293   }
00294 }
00295 
00296 void Tbl_val::from_spectral(const Scalar& meudon, int lmax, int lmin,
00297                 bool interfr, bool interft)
00298 {
00299   assert(meudon.get_etat() != ETATNONDEF) ;
00300 #ifndef NDEBUG
00301   const Map& mp = meudon.get_mp() ;
00302 #endif
00303   assert( gval->contenue_dans(mp, lmax, lmin) ) ;
00304   if (lmin < 0) {
00305       cout << "Tbl_val::from_spectral() : " << endl ;
00306       cout << "lmin, lmax : " << lmin << ", " << lmax << endl ;
00307   }
00308 
00309   if (meudon.get_etat() == ETATZERO) {
00310     annule_hard() ;
00311     return ;
00312   }
00313   else {
00314     assert(meudon.get_etat() == ETATQCQ) ;
00315     set_etat_qcq() ;
00316 
00317     switch (gval->get_ndim()) {
00318       
00319     case 1: {
00320       gval->somme_spectrale1(meudon, t, get_taille()) ;
00321     break ;
00322     }
00323     
00324     case 2: {
00325       gval->somme_spectrale2(meudon, t, get_taille()) ;
00326       if (interfr) {
00327     delete [] tzri ;
00328     const Gval_spher* gvs = dynamic_cast<const Gval_spher*>(gval) ; //## A modifier
00329     assert (gvs != 0x0) ;
00330     tzri = gvs->somme_spectrale2ri(meudon) ;
00331       }
00332       if (interft) {
00333     delete [] txti ;
00334     const Gval_spher* gvs = dynamic_cast<const Gval_spher*>(gval) ; //## A modifier
00335     assert (gvs != 0x0) ;
00336     txti = gvs->somme_spectrale2ti(meudon) ;
00337       }
00338       break ;
00339     }
00340     
00341     case 3: {
00342       gval->somme_spectrale3(meudon, t, get_taille()) ;
00343       break ;
00344     }
00345     
00346     default:
00347       cout << "Tbl_val::from_spectral:Strange error..." << endl ;
00348       abort() ;
00349       break ;
00350       
00351     }    
00352     return ;
00353   }
00354 }
00355 
00356 
00357 
00358 
00359 
00360 
00361 
00362 
00363 
00364 
00365 
00366 
00367 
00368 
00369 

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