00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 #include <math.h>
00078
00079
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
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) ;
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) ;
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