lagsht_testsuite.cc 39.7 KB
Newer Older
1 2
#include <stdlib.h>
#include <iostream>
3
#include <iomanip>      // std::setprecision
4
#include <fstream>
5
#include <sstream>
6 7 8 9 10 11 12 13
#include <string.h>
#include <limits>       // std::numeric_limits
#include <string>
#include <typeinfo>
using namespace std;

#include "lagsht_exceptions.h"
#include "lagsht_utils.h" //getMemorySize
14
#include "walltimer.h"    //timing
15
#include <omp.h>          //OpenMP for sampling
16 17

#include "lagSphericTransform.h"
Jean-Eric Campagne's avatar
Jean-Eric Campagne committed
18 19
#include "laguerre2bessel.h"

20 21 22 23 24 25 26 27 28
//Test FFT
#include <vector>
#include <algorithm>
#include <functional>
#include <math.h>
#include <fftw3.h>



29 30
using namespace LagSHT;

31
#define DEBUG 10
32 33
//JEC 12/1/16: alpha becomes double instead of int

34 35 36 37 38
//-------- Parameters set in the main and  used in the different test functions
struct PARAM {
  int Lmax;
  int N;
  r_8 R;
39
  int Pmax;
40
  int spin;
41 42
  //  int alpha;
  double alpha;
43 44 45
  string geometry;
  int ntheta;
  int nphi;
46 47 48
  string clenshawDir;
  string jlnpDir;
  bool recomputeJlnp;
49 50 51 52 53 54 55 56 57 58 59 60
} param ; 

//simple random generator (taken from sharp_testsuite
static double drand (double min, double max, int *state){
  *state = (((*state) * 1103515245) + 12345) & 0x7fffffff;
  return min + (max-min)*(*state)/(0x7fffffff+1.0);
}//rand


//----------------------------------------------------
void TestBasic() {

61
  // to access some general parameters... use param.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88



  cout << " ___________  BASIC TEST _____________ " << endl;
  

  cout << " sizeof(double): " << sizeof(r_8) << " bytes" 
       << " min " << std::numeric_limits<r_8>::min() << "-ln(min): " << -log(std::numeric_limits<r_8>::min()) 
       << " max " << std::numeric_limits<r_8>::max()  
       << " min exp_10 " << std::numeric_limits<r_8>::min_exponent10
       << " max exp_10 " << std::numeric_limits<r_8>::max_exponent10  
       <<  endl;
  


  cout << " sizeof(long double): " << sizeof(r_16) << " bytes" 
       << " min " << std::numeric_limits<r_16>::min() <<  "-ln(min): " << -logl(std::numeric_limits<r_16>::min()) 
       << " max " << std::numeric_limits<r_16>::max()  
       << " min exp_10 " << std::numeric_limits<r_16>::min_exponent10
       << " max exp_10 " << std::numeric_limits<r_16>::max_exponent10  
       <<  endl;
}//TestBasic

//----------------
void LaguerreQuadrature() {

  int N = param.N;
89 90
  //  int alpha = param.alpha;
  double alpha = param.alpha;
91 92 93 94 95

  cout << " ___________  LaguerreQuadrature  TEST _____________ " << endl;

  LaguerreFuncQuad lagFunc(N,alpha);
  cout << "N = " << lagFunc.GetOrder() << " alpha = " << lagFunc.GetAlpha() << endl;
96 97
  vector<r_8> nodes;
  vector<r_8> weights;
98 99
  lagFunc.QuadWeightNodes(nodes,weights);

100 101 102 103 104 105 106 107
  {
    char buff1[80], buff2[80];
    ofstream ofs1, ofs2;
    sprintf(buff1,"lagNodes-%d-Func.txt",N);
    sprintf(buff2,"lagWeights-%d-Func.txt",N);
    ofs1.open(buff1,ofstream::out);
    ofs2.open(buff2,ofstream::out);
    for (int i=0;i<N;i++){
108 109
      ofs1 << setprecision(20) << nodes[i] << endl;
      ofs2 << setprecision(20) << weights[i] << endl;
110
    }
111 112
  }

113

114 115 116 117 118 119
}//LaguerreQuadrature

//--------------------------------------
void MultiLaguerreTransformSdtAlone() {
  int N = param.N;
  r_8 R  = param.R;
120
  r_8 alpha = param.alpha; //JEC 12/1/16 to be tested with alpha =/= 2 (eg. alpha = 0)
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140

  cout << " ___________   MultiLaguerreTransformSdtAlone  TEST _____________ " << endl;

  //    Timer tm("Test 3 (r_16)");
      
  int mapSize=2; //this is the stride
      
  int Ntot = N*mapSize;

#if DEBUG >= 1
  cout << "Start random generation...." << endl;
#endif
  vector< complex<r_8> > fnOrig(Ntot);
  int state=1234567 + 8912 ; //random seed
  for(int i=0;i<Ntot;i++){
    r_8 rv = drand(-1,1,&state);
    r_8 iv = drand(-1,1,&state);
    fnOrig[i] = complex<r_8>(rv,iv);
  }
#if DEBUG >=2 
141
  std::copy(fnOrig.begin(), fnOrig.end(), std::ostream_iterator< complex<r_8> >(std::cout, " "));
142 143
#endif
    
144
  LaguerreTransform trans(N,R,alpha);  //JEC 12/1/16 add alpha
145 146 147 148 149 150 151 152

  vector< complex<r_8> > fi(Ntot);
#if DEBUG >= 1
  cout << "Start MultiSynthesis...." << endl;
#endif
  trans.MultiSynthesis(fnOrig,fi,mapSize);
    
#if DEBUG >=2 
153
  std::copy(fi.begin(), fi.end(), std::ostream_iterator< complex<r_8> >(std::cout, " "));
154 155 156 157 158 159 160
#endif

  vector< complex<r_8> > fn(Ntot);
  trans.MultiAnalysis(fi,fn,mapSize);

  r_8 err_abs(0.);
  r_8 err_rel(0.);
161
  int imax=-1;
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
  for(int i=0;i<Ntot;i++){
    if(i<10)cout << "("<<i<<"): " << fnOrig[i] << " <-> " << fi[i] << " <-> "  
		 << fn[i] << endl;
    complex<r_8> cdiff = (fnOrig[i] -  fn[i]) * conj(fnOrig[i] -  fn[i]);
    r_16 diff = sqrt(cdiff.real());
    if(diff>err_abs){ 
      err_abs = diff;
      imax = i;
    }
    complex<r_8> foriCAbs = fnOrig[i]*conj(fnOrig[i]);
    r_8 foriAbs = sqrt(foriCAbs.real());
    r_8 relatdiff = diff/foriAbs;
	
    if((relatdiff)>err_rel) err_rel = relatdiff;
  }
  cout << " >>>>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<<<<<<<<<" << endl; 
  cout << "r_16 Err. Max. " << err_abs << " [" << imax << "], Err. Rel. " << err_rel << endl;
  cout << " >>>>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<<<<<<<<<" << endl; 
  

}//MultiLaguerreTransformSdtAlone

//---------------------------------------
void MultiSphericalLaguerreTransform() {

187
  r_8 alpha = param.alpha;  //JEC 13/1/16
188
  int Nmax = param.N;
189
  int Lmax = param.Lmax;
190
  r_8 Rmax = param.R;
191 192 193
  string geometry = param.geometry;
  int ntheta = param.ntheta;
  int nphi = param.nphi;
194 195 196 197


  cout << " ___________  MultiSphericalLaguerreTransform   TEST _____________ " << endl;

198 199
  tstack_push("data input");

200 201
  int state = 1234567 + 8912 ; //random seed

202 203 204 205 206 207
  LaguerreSphericalTransform sphlagtrans(geometry,
					 Lmax,
					 -1,
					 Nmax,
					 Rmax,
					 ntheta,
208 209
					 nphi,
					 alpha
210
					 );
211

212 213 214

  int Nalm = sphlagtrans.GetSphericalGeometry()->Nalm();
  int Nshell = sphlagtrans.GetOrder();
215
  int Ntot = Nshell * Nalm; //total number of Coefficients of the Spherical Laguerre transform
216
  int Npix =  sphlagtrans.GetSphericalGeometry()->Npix();
217
  int NpTot=  Nshell * Npix; //totoal number of 3D-pixels
218

219 220 221
  cout << "Verif: Ntheta, Nphi, Npix, Nptot, Nalm, Nshell, Ntot: "
       << sphlagtrans.GetSphericalGeometry()->NTheta() << " "
       << sphlagtrans.GetSphericalGeometry()->NPhi() << " "
222 223 224 225 226
       <<  Npix << " "
       <<  NpTot << " "
       <<  Nalm << " "
       <<  Nshell << " "
       <<  Ntot << endl;
227

228 229 230 231 232 233 234
  unsigned int maxmemsize =  getMemorySize()/1e6;
  unsigned int estimateMem = 8*((uint_8)(NpTot+2*Ntot))/1e6;
  cout << "Estimate usage memory: " << estimateMem << " MBytes" << endl;
  if ( estimateMem > (0.9*maxmemsize) ) {
    cout << ">>>>> Warning: estimate Mem " << estimateMem <<" MB > 90\% "<< maxmemsize << " MB" << endl;
  }//test memory

235 236
  vector< complex<r_8> > flmnOrig(Ntot);
  int id=-1;
237
  for(int n=0;n<Nmax;n++){ //on each shell
238 239 240 241 242 243 244 245 246 247 248
    for(int m=0;m<Lmax;m++){ //Warning the filling of alm is adapted for libsharp memory
      for(int l=m;l<Lmax;l++){
	id++;
	r_8 rv = drand(-1,1,&state);
	r_8 iv = (m==0) ? 0.0 : drand(-1,1,&state);
	flmnOrig[id] = complex<r_8>(rv,iv);	    
      }//end l-loop
    }//end m-loop
  }//end loop on shell

#if DEBUG >=2 
249
  std::copy(flmnOrig.begin(), flmnOrig.end(), std::ostream_iterator< complex<r_8> >(std::cout, " "));
250 251
#endif
      
252 253 254 255
  
  tstack_pop("data input");
  tstack_push("processing");
  tstack_push("processing part Synthesis");
256 257 258 259 260 261

#if DEBUG >= 1
  cout << "Main:Synthesis r_8 function..." << endl;
#endif
  vector<r_8> fijk(NpTot);
  sphlagtrans.Synthesis(flmnOrig,fijk);
262
#if DEBUG >= 2
263
  for (int i=0; i<NpTot; i++){
264
    cout << "fijk("<<i<<"): " << fijk[i] << endl;
265
  }
266
#endif
267 268 269 270
  
  tstack_pop("processing part Synthesis");
  tstack_push("processing part Analysis");
  
271 272 273 274 275 276
#if DEBUG >= 1
  cout << "Main:Analysis r_8 function..." << endl;
#endif
  vector< complex<r_8> > flmn(Ntot);
  sphlagtrans.Analysis(fijk,flmn);
    
277 278 279
  tstack_pop("processing part Analysis");
  tstack_pop("processing");  

280 281 282 283 284 285


  cout << "Error analysis..." << endl;

  r_8 err_abs(0.);
  r_8 err_rel(0.);
286
  int imax = -1;
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
  for(int i=0;i<Ntot;i++){
    if(i>(Ntot-9)) cout << "(" << i << ") : flnm Orig " <<  flmnOrig[i] << " <-> flmn Rec " <<  flmn[i] << endl;

    complex<r_8> cdiff = (flmnOrig[i] -  flmn[i]) * conj(flmnOrig[i] -  flmn[i]);
    r_16 diff = sqrt(cdiff.real());
    if(diff>err_abs){ 
      err_abs = diff;
      imax = i;
    }
    complex<r_8> foriCAbs = flmnOrig[i]*conj(flmnOrig[i]);
    r_8 foriAbs = sqrt(foriCAbs.real());
    r_8 relatdiff = diff/foriAbs;
	
    if((relatdiff)>err_rel) err_rel = relatdiff;

  }
  cout << " >>>>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<<<<<<<<<" << endl; 
304
  cout << "Err. Max. " << err_abs << " [" << imax << "], Err. Rel. " << err_rel << endl;
305 306 307 308 309
  cout << " >>>>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<<<<<<<<<" << endl; 


}//MultiSphericalLaguerreTransform

310 311 312
//---------------------------------------
void SpinMultiSphericalLaguerreTransform() {

313
  r_8 alpha = param.alpha;  
314 315 316 317 318 319
  int Nmax = param.N;
  int Lmax = param.Lmax;
  r_8 Rmax = param.R;
  string geometry = param.geometry;
  int ntheta = param.ntheta;
  int nphi = param.nphi;
320
  int spin = param.spin; //JEC 18/1/16
321

322 323 324
  if(spin == 0)  
    throw LagSHTError("WARNING: spin =0 : use test MultiSphericalLaguerreTransform"); 

325
  cout << " ___________  SpinMultiSphericalLaguerreTransform   TEST _____________ " << endl;
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347

  tstack_push("data input");

  int state = 1234567 + 8912 ; //random seed

  LaguerreSphericalTransform sphlagtrans(geometry,
					 Lmax,
					 -1,
					 Nmax,
					 Rmax,
					 ntheta,
					 nphi,
					 alpha
					 );


  int Nalm = sphlagtrans.GetSphericalGeometry()->Nalm();
  int Nshell = sphlagtrans.GetOrder();
  int Ntot = Nshell * Nalm; //total number of Coefficients of the Spherical Laguerre transform
  int Npix =  sphlagtrans.GetSphericalGeometry()->Npix();
  int NpTot=  Nshell * Npix; //totoal number of 3D-pixels

348 349 350 351

  cout << "Verif: Ntheta, Nphi, Npix, Nptot, Nalm, Nshell, Ntot: "
       << sphlagtrans.GetSphericalGeometry()->NTheta() << " "
       << sphlagtrans.GetSphericalGeometry()->NPhi() << " "
352 353 354 355 356 357
       <<  Npix << " "
       <<  NpTot << " "
       <<  Nalm << " "
       <<  Nshell << " "
       <<  Ntot << endl;

358 359 360 361 362 363 364 365 366

  unsigned int maxmemsize =  getMemorySize()/1e6;
  unsigned int estimateMem = 2*8*((uint_8)(NpTot+2*Ntot))/1e6;
  cout << "Estimate usage memory: " << estimateMem << " MBytes" << endl;
  if ( estimateMem > (0.9*maxmemsize) ) {
    cout << ">>>>> Warning: estimate Mem " << estimateMem <<" MB > 90\% "<< maxmemsize << " MB" << endl;
  }//test memory


367 368
  vector< complex<r_8> > ElmnOrig(Ntot);
  vector< complex<r_8> > BlmnOrig(Ntot);
Jean-Eric Campagne's avatar
Jean-Eric Campagne committed
369 370
  int id
=-1;
371

372 373 374 375
  for(int n=0;n<Nmax;n++){ //on each shell
    for(int m=0;m<Lmax;m++){ //Warning the filling of alm is adapted for libsharp memory
      for(int l=m;l<Lmax;l++){
	id++;
376 377
	r_8 rv = (l<abs(spin)) ? 0.0 : drand(-1,1,&state);
	r_8 iv = (m==0 || l<abs(spin)) ? 0.0 : drand(-1,1,&state);
378
	ElmnOrig[id] = complex<r_8>(rv,iv);	    
379 380
	rv = (l<abs(spin)) ? 0.0 : drand(-1,1,&state);
	iv = (m==0 || l<abs(spin)) ? 0.0 : drand(-1,1,&state);
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
	BlmnOrig[id] = complex<r_8>(rv,iv);	    
      }//end l-loop
    }//end m-loop
  }//end loop on shell

#if DEBUG >=2 
  std::copy(ElmnOrig.begin(), ElmnOrig.end(), std::ostream_iterator< complex<r_8> >(std::cout, " "));
  std::copy(BlmnOrig.begin(), BlmnOrig.end(), std::ostream_iterator< complex<r_8> >(std::cout, " "));
#endif
      
  
  tstack_pop("data input");
  tstack_push("processing");
  tstack_push("processing part Synthesis");

#if DEBUG >= 1
  cout << "Main:Synthesis complex function..." << endl;
#endif
  vector<r_8> fijk_re; //NpTot
  vector<r_8> fijk_im;
401 402
//   vector< complex<r_8> > Elmk; //calcul intermediaire
//   vector< complex<r_8> > Blmk;
403

404 405
//  sphlagtrans.Synthesis(ElmnOrig, BlmnOrig, spin, fijk_re, fijk_im, Elmk, Blmk);
  sphlagtrans.Synthesis(ElmnOrig, BlmnOrig, spin, fijk_re, fijk_im);
406
#if DEBUG >= 2
407 408 409
  for (int i=0; i<NpTot; i++){
    cout << "fijk("<<i<<"): " << fijk_re[i] << ", " << fijk_im[i] << endl;
  }
410
#endif
411 412 413 414 415 416 417
  
  tstack_pop("processing part Synthesis");
  tstack_push("processing part Analysis");
  
#if DEBUG >= 1
  cout << "Main:Analysis complex function..." << endl;
#endif
418 419
  vector< complex<r_8> > Elmn(Ntot);
  vector< complex<r_8> > Blmn(Ntot);
420

421 422
//   vector< complex<r_8> > Elmk_ana;
//   vector< complex<r_8> > Blmk_ana;
423

424 425
//  sphlagtrans.Analysis(fijk_re, fijk_im, spin, Elmn, Blmn, Elmk_ana, Blmk_ana);
  sphlagtrans.Analysis(fijk_re, fijk_im, spin, Elmn, Blmn);
426 427 428 429 430 431 432 433 434 435 436
    
  tstack_pop("processing part Analysis");
  tstack_pop("processing");  


  cout << "Error analysis..." << endl;

  r_8 err_abs(0.);
  r_8 err_rel(0.);
  int imax = -1;
  for(int i=0;i<Ntot;i++){
Jean-Eric Campagne's avatar
Jean-Eric Campagne committed
437
    if(i>(Ntot-9)) {
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462
      cout << "(" << i << ") : Elnm Orig " <<  ElmnOrig[i] << " <-> Elmn Rec " <<  Elmn[i] << endl;
      cout << "............  Blnm Orig " <<  BlmnOrig[i] << " <-> Blmn Rec " <<  Blmn[i] << endl;
    }

    complex<r_8> cdiff = ((ElmnOrig[i] -  Elmn[i]) * conj(ElmnOrig[i] -  Elmn[i])
			  + (BlmnOrig[i] -  Blmn[i]) * conj(BlmnOrig[i] -  Blmn[i]))/2. ;
    r_16 diff = sqrt(cdiff.real());
    if(diff>err_abs){ 
      err_abs = diff;
      imax = i;
    }
    complex<r_8> foriCAbs = (ElmnOrig[i]*conj(ElmnOrig[i]) + BlmnOrig[i]*conj(BlmnOrig[i]))/2. ;
    r_8 foriAbs = sqrt(foriCAbs.real());
    r_8 relatdiff = diff/foriAbs;
	
    if((relatdiff)>err_rel) err_rel = relatdiff;

  }
  cout << " >>>>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<<<<<<<<<" << endl; 
  cout << "Err. Max. " << err_abs << " [" << imax << "], Err. Rel. " << err_rel << endl;
  cout << " >>>>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<<<<<<<<<" << endl; 


}//SpinMultiSphericalLaguerreTransform

463 464 465 466 467 468 469 470 471 472
//-------------------------------------------------------------
void TestJlnpComputation() {

  int Nmax = param.N;
  int Lmax = param.Lmax;
  int Pmax = param.Pmax;
  r_8 Rmax = param.R;
  string geometry = param.geometry;
  int ntheta = param.ntheta;
  int nphi = param.nphi;
473 474 475
  string clenshawDir = param.clenshawDir;
  string jlnpDir = param.jlnpDir;
  bool recomputeJlnp = param.recomputeJlnp;
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492

  cout << " ______________ TestJlnpComputation  START ___________ " << endl;
  LaguerreSphericalTransform sphlagtrans(geometry,
					 Lmax,
					 -1,
					 Nmax,
					 Rmax,
					 ntheta,
					 nphi
					 );

  
  BaseGeometry* sphere = sphlagtrans.GetSphericalGeometry();
  LaguerreTransform* lagTrans = sphlagtrans.GetLagTransform();


  tstack_push("Ctor lag2bess");
493
  recomputeJlnp = true;
494 495 496 497 498 499 500
  Laguerre2Bessel lag2bess(sphere,lagTrans,Nmax,Pmax,Rmax,
			   clenshawDir,jlnpDir,recomputeJlnp);
  tstack_pop("Ctor lag2bess");

  cout << " ______________ TestJlnpComputation  End  ___________ " << endl;

}
501 502 503 504



//---------------------------------------------------------------------------------
505
// void TestJlnpComputationByFFTAdaptative() {
506 507 508 509 510 511 512 513
//   int Nmax = param.N;
//   int Lmax = param.Lmax;
//   int Pmax = param.Pmax;
//   r_8 Rmax = param.R;
//   string geometry = param.geometry;
//   int ntheta = param.ntheta;
//   int nphi = param.nphi;
//   double alpha = param.alpha;
514 515

//   string jlnpDir = param.jlnpDir;
516 517
//   string clenshawDir = param.clenshawDir;
 
518
//   cout << " ______________ TestJlnpComputation FFT Adaptative START ___________ " << endl;
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553
//   LaguerreSphericalTransform sphlagtrans(geometry,
// 					 Lmax,
// 					 -1,
// 					 Nmax,
// 					 Rmax,
// 					 ntheta,
// 					 nphi
// 					 );


//   tstack_push("Ctors....");  
//   LaguerreTransform* lagTrans = sphlagtrans.GetLagTransform();
//   Bessel jnu(Lmax,std::max(Pmax,Nmax));  //the max is here just in case Nmax =/= Pmax


//   r_8 tau = lagTrans->GetTau();
//   r_8 rNm1 = Rmax / tau; // R = r[N-1] with N the original transform value. Todo (lagTrans_->GetNodes()).back()

//   cout << "(JEC) ComputeJInteg Facts START " << endl;

//   vector<r_8> facts(Nmax); //sqrt(n!/(n+alpha)!) the normalization
//   facts[0] = 1.0/sqrt(boost::math::tgamma(alpha+1.0)); //1/sqrt(alpha)!       
//   for(int n=1;n<Nmax;n++) facts[n] = facts[n-1]*sqrt(((r_8)n)/((r_8)(n+alpha)) );

//   cout << "(JEC) ComputeJInteg Facts END " << endl;

//   cout << "(JEC) ComputeJInteg  integUpperBound START " << endl;


//   tstack_pop("Ctors....");  
  

//   tstack_push("Bounds init...");  

//   vector<r_8> integUpperBound(Nmax);
554 555
//   integUpperBound[0] = min(100.,rNm1); //this is the case of L_0^{\alpha}(x) =1 with no root
//   integUpperBound[1] = min(120.,rNm1); //this is the case of L_1^{\alpha}(x) =1+alpha-x with single root = 1/(1+alpha)
556 557 558 559 560 561 562 563 564 565
//   for (int n=2;n<Nmax;n++){
//     LaguerreFuncQuad lag(n,alpha);
//     vector<r_8> nodes;
//     vector<r_8> weights;
//     lag.QuadWeightNodes(nodes,weights);
//     integUpperBound[n] = nodes[n-1] + 5*(nodes[n-1]-nodes[n-2]); //upper bound from Laguerre function end point, may be modified by Bessel part later
//   }
//   tstack_pop("Bounds init...");  

//   cout << "(JEC) ComputeJInteg  integUpperBound END " << endl;
566

567

568 569 570 571 572 573 574 575 576 577 578
//   tstack_push("Common FFTW Plan init...");  

//   cout << "(JEC) Plan Init START" << endl;

//   //Try a common order for K & J function this make the FFTW plan for once
//   int iOrdGen = 8; //initial 
//   int nOrdGen=pow(2.,(r_8)iOrdGen)-1; //the -1 is just to use FFTW with 2^iOrdGen 
//   vector<r_8> VecDCT1(nOrdGen+1,0.);  //but for  FFTW_REDFT00 it is requiered n+1... see FFTW doc
//   FFTPlanning planJK(nOrdGen,VecDCT1);

//   cout << "(JEC) Plan Init END" << endl;
579

580 581 582 583 584 585 586 587 588 589
//   cout << "(JEC) Plan Inverse Init START" << endl;

//   //Unique Product plan
//   int nOrdProd= 2*nOrdGen+1; //order max of product is 2*nOrdGen but to get a power of 2 for the FFT I add 1.
//   vector<r_8> VecDCT1Inv(nOrdProd+1,0.);
//   FFTPlanning planInv(nOrdProd,VecDCT1Inv);

//   cout << "(JEC) Plan Inverse Init END" << endl;

//   tstack_pop("Common FFTW Plan init...");  
590
  
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626
//   tstack_push("Common CC weights init...");  

//   cout << "(JEC) CC weights START" << endl;

//   //Clenshow-Curtis single quadratuer weight
//   vector<r_8> wCC(nOrdProd+1,0);
//   FFTPlanning planCC(nOrdProd, wCC);

//   ClenshawCurtisWeightsFast(nOrdProd+1,planCC,wCC);
// #if DEBVEC>0
//   VectorDebug("DCT CCurtis W [0,10]: ",wCC,0,10);
//   VectorDebug("DCT CCurtis W [last-10,last]: ",wCC,nOrdProd-11,nOrdProd+1);
// #endif



//   cout << "(JEC) CC weights END" << endl;

//   tstack_pop("Common CC weights init...");  

//   stringstream ss; ss << "Adap-OMP-FFTClass-jlnp-L"<<Lmax<<"-N"<<Nmax<<"-P"<<Pmax<<".txt";
//   std::ofstream ofs;
//   string fname(jlnpDir+"/"+ss.str());
//   ofs.open (fname.c_str(), std::ofstream::out);

//   for(int p=0;p<Pmax;p++){
//     //for(int p=0;p<10;p++){
    
    
//     for(int l=0; l<Lmax; l++){
//       //for(int l=0; l<10; l++){

//       r_8 qlp = jnu(l,p);

//       r_8 klptau = qlp/rNm1; 
//       JBess jFunc(l,klptau);
627
  
628 629
//       r_8 intLowBound = (l<=10)? 0.0: 0.5*l/klptau;
//       r_8 ql2scaled = jnu(l,1)/klptau;   //  the 2nd BesselRoot rescaled
630 631 632
  


633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696
//       for (int n=0; n<Nmax; n++) {
// 	//for (int n=0; n<10; n++) {
  
// 	r_8 intUppBound = std::max(integUpperBound[n], ql2scaled);
	
// #if DEBUG>10

// 	cout << "lowBnd, uppBnd: " << setprecision(30) 
// 	     << intLowBound << ", " << intUppBound 
// 	     << setprecision(6)
// 	     << endl;
// 	cout << "l,n,p,klptau: " 
// 	     << l << ", " 
// 	     << n << ", " 
// 	     << p << ", " 
// 	     << klptau << endl;
// #endif
  
// 	tstack_push("Integral Computation...");
  
// 	tstack_push("Reconfigure FFT planning");
	
// 	//estimate if one needs to reconfigure the FFT plan
// 	int nJ = EstimChebyshevOrdSpherBessel(l,klptau,intLowBound,intUppBound);
// 	int nK =0;
// 	{
// 	  LaguerreFuncQuad lag(n,alpha);
// 	  vector<r_8> nodes;
// 	  vector<r_8> weights;
// 	  lag.QuadWeightNodes(nodes,weights);
// 	  nK = EstimChebyshevOrdLagFunc(nodes,intLowBound,intUppBound);
// 	}
// 	int newiOrdGen=max(nJ,nK);

// 	if (newiOrdGen>iOrdGen) {
// 	  //destroy old and create new plan
// 	  iOrdGen = newiOrdGen;

// 	  cout << "(JEC) new order : " <<  newiOrdGen << " lnp = " 
// 	       << l << " "
// 	       << n << " "
// 	       << p << " "
// 	       << endl;

// 	  planJK.DestroyPlan();
// 	  nOrdGen=pow(2.,(r_8)iOrdGen)-1;
// 	  VecDCT1.resize(nOrdGen+1); //here NO RE-INITIALIZATION to specific value 
// 	  planJK.CreatePlan(nOrdGen,VecDCT1);
	  
// 	  planInv.DestroyPlan();
// 	  nOrdProd= 2*nOrdGen+1;
// 	  VecDCT1Inv.resize(nOrdProd+1);
// 	  planInv.CreatePlan(nOrdProd,VecDCT1Inv);

// 	  planCC.DestroyPlan();
// 	  wCC.resize(nOrdProd+1);
// 	  planCC.CreatePlan(nOrdProd, wCC);

// 	  //recompute Clenshaw-Curtis weights
// 	  ClenshawCurtisWeightsFast(nOrdProd+1,planCC,wCC);
// 	}
	
// 	tstack_pop("Reconfigure FFT planning");

697

698
// 	tstack_push("Chebyshev J...");  
699

700 701 702 703 704 705 706 707 708

// 	//Get Chebyshev coeff of Bessel
// 	//  int iOrdJ = 8; int nOrdJ=pow(2.,(r_8)iOrdJ);
// 	int nOrdJ = nOrdGen; //USE COMMON dimension
// 	vector<r_8> coefJ(nOrdJ+1,0.);
// 	{
// 	  tstack_push("Chebyshev J SAMPLING...");  
// 	  fill(VecDCT1.begin(), VecDCT1.end(), 0.0); //may be unusefull here
// 	  ChebyshevSampling(nOrdJ,VecDCT1,jFunc,intLowBound,intUppBound);
709 710

// #if DEBVEC>0
711
// 	  VectorDebug("Sampling J-func",VecDCT1,0,10);
712
// #endif
713 714
// 	  tstack_pop("Chebyshev J SAMPLING...");  
// 	  tstack_push("Chebyshev J FFT...");  
715

716 717
// 	  ChebyshevCoeffFFT(nOrdJ,planJK, VecDCT1);
// 	  copy(VecDCT1.begin(),VecDCT1.end(),coefJ.begin());
718

719
// 	  tstack_pop("Chebyshev J FFT...");  
720 721

// #if DEBVEC>0
722
// 	  VectorDebug("Che J-func",coefJ,0,10);
723
// #endif
724 725 726
// 	}

// 	tstack_pop("Chebyshev J...");  
727

728 729

// 	tstack_push("Chebyshev K...");  
730
  
731 732 733 734 735 736 737 738 739 740
// 	//Get Chebyshev coeff of Laguerre Func
// 	//  int iOrdK = 6; int nOrdK = pow(2.,(r_8)iOrdK);
// 	int nOrdK =  nOrdGen; //USE COMMON dimension
// 	vector<r_8> coefK(nOrdK+1,0.);
// 	{
// 	  tstack_push("Chebyshev K SAMPLING..."); 
// 	  LaguerreFuncQuad* Ln = new LaguerreFuncQuad(n, alpha);
// 	  KLag kLagFunc(Ln, facts[n]);
// 	  fill(VecDCT1.begin(), VecDCT1.end(), 0.0); //may be unusefull here
// 	  ChebyshevSampling(nOrdK,VecDCT1,kLagFunc,intLowBound,intUppBound);
741 742

// #if DEBVEC>0
743
// 	  VectorDebug("Sampling K-func",VecDCT1,0,10);
744
// #endif
745 746 747 748
// 	  tstack_pop("Chebyshev K SAMPLING..."); 
// 	  tstack_push("Chebyshev K FFT..."); 
// 	  ChebyshevCoeffFFT(nOrdK, planJK, VecDCT1);
// 	  copy(VecDCT1.begin(),VecDCT1.end(),coefK.begin());
749

750
// 	  tstack_pop("Chebyshev K FFT..."); 
751
// #if DEBVEC>0
752
// 	  VectorDebug("Che K-func",coefK,0,10);
753 754
// #endif

755 756 757
// 	  delete Ln;
// 	}
// 	tstack_pop("Chebyshev K...");  
758 759
  

760 761 762 763 764
// 	tstack_push("Chebyshev Product...");  

// 	//Product size
// 	//   int nOrdProd = nOrdJ*nOrdK;
// 	//perform Inverse Chebyshev transform in the new basis
765

766 767 768 769 770 771 772
// 	tstack_push("Inverse Chebyshev J...");  

// 	vector<r_8>coefJExt(nOrdProd+1,0.); 
// 	fill(VecDCT1Inv.begin(), VecDCT1Inv.end(), 0.0);
// 	copy(coefJ.begin(),coefJ.end(),VecDCT1Inv.begin());  //make the VecDCT1Inv[0:nOrdJ-1] = coefJ; then VecDCT1Inv is comleted by 0
// 	InverseChebyshevCoeffFFT(nOrdProd,planInv,VecDCT1Inv);
// 	copy(VecDCT1Inv.begin(), VecDCT1Inv.end(), coefJExt.begin());
773 774

// #if DEBVEC>0
775
// 	VectorDebug("Inv Che J",coefJExt,0,10);
776 777
// #endif

778 779 780 781 782 783 784 785
// 	tstack_pop("Inverse Chebyshev J...");  
// 	tstack_push("Inverse Chebyshev K...");  

// 	vector<r_8>coefKExt(nOrdProd+1,0.); 
// 	fill(VecDCT1Inv.begin(), VecDCT1Inv.end(), 0.0);
// 	copy(coefK.begin(),coefK.end(),VecDCT1Inv.begin());
// 	InverseChebyshevCoeffFFT(nOrdProd,planInv,VecDCT1Inv);
// 	copy(VecDCT1Inv.begin(), VecDCT1Inv.end(), coefKExt.begin());
786 787

// #if DEBVEC>0
788
// 	VectorDebug("Inv Che K",coefKExt,0,10);
789 790
// #endif

791 792 793 794 795 796 797 798 799 800
// 	tstack_pop("Inverse Chebyshev K...");  


// 	tstack_push("Inverse Chebyshev J*K...");  

// 	vector<r_8>invCoefProd(nOrdProd+1,0.); //is there an in-place product?
// 	transform(coefJExt.begin(),coefJExt.end(),
// 		  coefKExt.begin(),
// 		  invCoefProd.begin(),
// 		  multiplies<r_8>());
801 802

// #if DEBVEC>0
803
// 	VectorDebug("Inv Che Prod",invCoefProd,0,10);
804 805
// #endif
  
806 807
// 	tstack_pop("Inverse Chebyshev J*K...");  
// 	tstack_pop("Chebyshev Product...");  
808
  
809 810 811 812 813 814 815 816
// 	//Compute integral
// 	tstack_push("CC quadrature...");
// 	r_8 integral = inner_product(invCoefProd.begin(),invCoefProd.end(),wCC.begin(),0.);
// 	integral *= (intUppBound - intLowBound)/2.0; //the 2 division comme from CC quadrature weights definition in [-1,1];
// 	tstack_pop("CC quadrature...");

// #if CHECK_BY_CCQUAD>0
// 	cout << "Integral via FFT               = " << setprecision(20) << integral <<  setprecision(6) << endl;
817
// #endif
818 819 820 821
// 	ofs <<l<<" "
// 	    <<n<<" "
//  	    <<p<< " " << setprecision(30) << integral 
// 	    << endl;
822

823
// 	tstack_pop("Integral Computation...");
824 825


826 827
// #if CHECK_BY_CCQUAD>0
// 	tstack_push("Recursive CC quadrature");
828
 
829 830 831 832 833
// 	typedef  ClenshawCurtisQuadrature<double> Integrator_t;
// 	string clenshawFile = clenshawDir+"/ClenshawCurtisRuleData-40.txt";
// 	Integrator_t theQuad(40,clenshawFile,false); //false=do not recompute the weights and nodes of the quadrature
// 	Quadrature<r_8,Integrator_t>::values_t integ_val;
// 	r_8 tol4Integral = 1e-10;
834
  
835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857
// 	LaguerreFuncQuad* Ln = new LaguerreFuncQuad(n, alpha);
// 	IntFunc1D f(l,klptau,Ln);
// 	theQuad.SetFuncBounded(f,intLowBound,intUppBound);
// 	integ_val = theQuad.GlobalAdapStrat(tol4Integral);
// 	delete Ln;
// 	tstack_pop("Recursive CC quadrature");

// 	cout << "Integral via Recursive CC Quad = " 
// 	     << setprecision(20) 
// 	     << integ_val.first * sqrt(2.0/M_PI) * facts[n]
// 	     << setprecision(6) 
// 	     << endl;
// #endif

//       }//n-loop
//     }//l-loop
//   }//p-loop

//   //file to save computations
//   ofs.close();

//   cout << " ______________ TestJlnpComputation FFT Adaptative START ___________ " << endl;

858

859
// }//TestJlnpComputationByFFTAdaptative
860

861

Jean-Eric Campagne's avatar
Jean-Eric Campagne committed
862 863 864 865 866 867 868
//-------------------------------------------------------------
void TestLaguerre2Bessel() {

  //Todo introduce Pmax !

  int Nmax = param.N;
  int Lmax = param.Lmax;
869
  int Pmax = param.Pmax;
Jean-Eric Campagne's avatar
Jean-Eric Campagne committed
870 871 872 873
  r_8 Rmax = param.R;
  string geometry = param.geometry;
  int ntheta = param.ntheta;
  int nphi = param.nphi;
874 875 876 877
  string clenshawDir = param.clenshawDir;   //JEC 23/11/15
  string jlnpDir = param.jlnpDir;           //       "
  bool recomputeJlnp = param.recomputeJlnp; //       "

Jean-Eric Campagne's avatar
Jean-Eric Campagne committed
878 879 880

  cout << " ______________ TestLaguerre2Bessel TEST ___________ " << endl;
  
881 882
   cout << "tstack 1 Start" <<endl;
   tstack_push("data input");
Jean-Eric Campagne's avatar
Jean-Eric Campagne committed
883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917

  int state = 1234567 + 8912 ; //random seed

  LaguerreSphericalTransform sphlagtrans(geometry,
					 Lmax,
					 -1,
					 Nmax,
					 Rmax,
					 ntheta,
					 nphi
					 );

  
  BaseGeometry* sphere = sphlagtrans.GetSphericalGeometry();
  LaguerreTransform* lagTrans = sphlagtrans.GetLagTransform();

  int Nalm = sphere->Nalm();
  int Nshell = sphlagtrans.GetOrder();
  int Ntot = Nshell * Nalm; //total number of Coefficients of the Spherical Laguerre transform
  int Npix =  sphere->Npix();
  int NpTot=  Nshell * Npix; //totoal number of 3D-pixels

  cout << "Verif: Npix, Nptot, Nalm, Nshell, Ntot: "
       <<  Npix << " "
       <<  NpTot << " "
       <<  Nalm << " "
       <<  Nshell << " "
       <<  Ntot << endl;

  vector< complex<r_8> > flmnOrig(Ntot);
  int id=-1;
  for(int n=0;n<Nmax;n++){ //on each shell
    for(int m=0;m<Lmax;m++){ //Warning the filling of alm is adapted for libsharp memory
      for(int l=m;l<Lmax;l++){
	id++;
918 919 920 921 922 923
	
	//verif
	int idLag =  n*Nalm + l+m*Lmax-m*(m+1)/2 ;
	if(id != idLag)
	  throw LagSHTError("ERROR: FLag index error"); 

Jean-Eric Campagne's avatar
Jean-Eric Campagne committed
924 925 926 927 928 929 930 931
	r_8 rv = drand(-1,1,&state);
	r_8 iv = (m==0) ? 0.0 : drand(-1,1,&state);
	flmnOrig[id] = complex<r_8>(rv,iv);	    
      }//end l-loop
    }//end m-loop
  }//end loop on shell

#if DEBUG >=2 
932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948
  cout << "F-Lag coeff orig ......... START " << endl;
  //  std::copy(flmnOrig.begin(), flmnOrig.end(), std::ostream_iterator< complex<r_8> >(std::cout, "\n"));
  
  for(int l=0; l<Lmax; l++){
    for (int m=0; m<=l; m++) {
      int almoff7 = l+m*Lmax-m*(m+1)/2;
      for (int n=0; n<Nmax; n++){
	int idLag =  n*Nalm + almoff7;
	cout << l << " " 
	     << m << " "
	     << n << " "
	     << setprecision(12) << flmnOrig[idLag] << endl;
      }
    }
  }
  
  cout << "F-Lag coeff orig ......... END " << endl;
Jean-Eric Campagne's avatar
Jean-Eric Campagne committed
949 950 951 952 953 954 955 956 957 958
#endif
        
  cout << "tstack 1 End" <<endl;
  tstack_pop("data input");


  cout << "tstack 2 Start" <<endl;
  tstack_push("processing");
  cout << "tstack 2a Start" <<endl;
  tstack_push("Init Laguerre 2 Bessel");
959 960
  Laguerre2Bessel lag2bess(sphere,lagTrans,Nmax,Pmax,Rmax,
			   clenshawDir,jlnpDir,recomputeJlnp);
Jean-Eric Campagne's avatar
Jean-Eric Campagne committed
961 962
  cout << "tstack 2a End" <<endl;
  tstack_pop("Init Laguerre 2 Bessel");
963

Jean-Eric Campagne's avatar
Jean-Eric Campagne committed
964 965 966 967
  cout << "tstack 2b Start" <<endl;
  tstack_push("Compute Fourier-Bessel coeffs.");

  vector< complex<r_8> > FBlmp(Nalm*Pmax);
968
  lag2bess.Lag2BessCoeff(flmnOrig,FBlmp);
969 970 971 972 973
#if DEBUG >=2 
  cout << "F-Bessel coeff ......... START " << endl;
  std::copy(FBlmp.begin(), FBlmp.end(), std::ostream_iterator< complex<r_8> >(std::cout, "\n"));
  cout << "F-Bessel coeff ......... END " << endl;
#endif
Jean-Eric Campagne's avatar
Jean-Eric Campagne committed
974 975 976 977 978 979 980
  cout << "tstack 2b End" <<endl;
  tstack_pop("Compute Fourier-Bessel coeffs.");
  

  cout << "tstack 2c Start" <<endl;
  tstack_push("Compute Alm(rk) from FB coeffs.");
  vector< complex<r_8> > FBalmk;
981
  vector<r_8> fFBijk;
Jean-Eric Campagne's avatar
Jean-Eric Campagne committed
982 983 984 985 986 987
  lag2bess.Synthesis(FBlmp,FBalmk,fFBijk);
  cout << "tstack 2c End" <<endl;
  tstack_pop("Compute Alm(rk) from FB coeffs.");
  

  cout << "tstack 2d Start" <<endl;
988
  tstack_push("Compute Alm(rk) from FL coeffs.");
Jean-Eric Campagne's avatar
Jean-Eric Campagne committed
989 990 991
  vector< complex<r_8> > FLalmk;
  vector<r_8> fFLijk;
  sphlagtrans.Synthesis(flmnOrig,fFLijk,FLalmk);
992 993 994 995 996 997
#if DEBUG >=2 
  cout << "F-Lag fijk coeff ......... START " << endl;
  std::copy(fFLijk.begin(), fFLijk.end(), std::ostream_iterator< complex<r_8> >(std::cout, "\n"));
  cout << "F-Lag fijk coeff ......... END " << endl;
#endif

Jean-Eric Campagne's avatar
Jean-Eric Campagne committed
998
  cout << "tstack 2d End" <<endl;
999
  tstack_pop("Compute Alm(rk) from FL coeffs.");
Jean-Eric Campagne's avatar
Jean-Eric Campagne committed
1000
  
1001
  cout << "tstack 2 End" <<endl;
1002

1003 1004 1005
  tstack_pop("processing");


1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035
  //verif F-Laguerre part
  tstack_push("F-L Analysis verif");
  vector< complex<r_8> > flmn(Ntot);
  sphlagtrans.Analysis(fFLijk,flmn);
  {
    r_8 err_abs(0.);
    r_8 err_rel(0.);
    int imax = -1;
    for(int i=0;i<Ntot;i++){
      
      complex<r_8> cdiff = (flmnOrig[i] -  flmn[i]) * conj(flmnOrig[i] -  flmn[i]);
      r_16 diff = sqrt(cdiff.real());
      if(diff>err_abs){ 
	err_abs = diff;
	imax = i;
      }
      complex<r_8> foriCAbs = flmnOrig[i]*conj(flmnOrig[i]);
      r_8 foriAbs = sqrt(foriCAbs.real());
      r_8 relatdiff = diff/foriAbs;
	
      if((relatdiff)>err_rel) err_rel = relatdiff;
    }
    cout << " >>>>>>>>>>>>>>>>>>>>> Fourrier-Laguerre part <<<<<<<<<<<<<<<<<<<<<<<<<<" << endl; 
    cout << "Err. Max. " << err_abs << " [" << imax << "], Err. Rel. " << err_rel << endl;
    cout << " >>>>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<<<<<<<<<" << endl; 
    
  }
  tstack_pop("F-L Analysis verif");


1036 1037
  
  
1038 1039
  {//Check 1b
    cout << "Dump FL or FB reconstructed Cl(r_k)" <<endl;
1040

1041
#if DEBUG >=2 
1042
    std::ofstream ofs;
1043
    ofs.open ("Cli.txt", std::ofstream::out);
1044
#endif
1045 1046 1047
    
    for(int n=0;n<Nmax;n++){
      for(int l=0;l<Lmax;l++){
1048 1049 1050 1051

	r_8 ClFL = 0;
	r_8 ClFB = 0;

1052 1053
	for (int m=0;m<=l;m++) {
	  int id= n*Nalm + l+m*Lmax-m*(m+1)/2; // LagSHT numbering 
1054

1055 1056 1057 1058 1059 1060 1061 1062 1063 1064
	  r_8 almkFL2 = FLalmk[id].real()*FLalmk[id].real() + FLalmk[id].imag()*FLalmk[id].imag();
	  r_8 almkFB2 = FBalmk[id].real()*FBalmk[id].real() + FBalmk[id].imag()*FBalmk[id].imag();

	  ClFL += (m==0) ? almkFL2 : 2*almkFL2;
	  ClFB += (m==0) ? almkFB2 : 2*almkFB2;

	}//m

	ClFL /= (r_8)(2*l+1);
	ClFB /= (r_8)(2*l+1);
1065
#if DEBUG >=2 
1066
	  ofs <<l<<" " << n << " " << setprecision(12) << ClFL << " " << ClFB << endl;
1067
#endif	  
1068

1069 1070
      }//l
    }//n
1071
#if DEBUG >=2 
1072
    ofs.close();
1073
#endif
1074 1075 1076 1077 1078 1079
  }//check 1b





1080

1081
  {//check 2
1082
#if DEBUG >=2 
1083 1084
    std::ofstream ofs;
    ofs.open ("fijk.txt", std::ofstream::out);
1085
#endif
1086 1087
    cout << "Dump FL or FB reconstructed fijk on each shell k" <<endl;

1088
    for (int ish=0;ish<Nshell; ish++){
1089 1090
      r_8 err_abs(0.);
      r_8 err_rel(0.);
1091 1092
      for (int ip=0; ip<Npix; ip++) {
	int id = ish*Npix+ip;
1093
	//	cout << "Shell("<<ish<<") Pix["<<ip<<"] FL fijk = " << fFLijk[id] << " FB fijk = " << fFBijk[id] << endl;
1094 1095

#if DEBUG >=2 
1096
	ofs << ish << " " << ip << " " << setprecision(12) <<  fFLijk[id] << " " << fFBijk[id] << endl;
1097
#endif
1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111
	r_8 diff = fabs(fFLijk[id]-fFBijk[id]);
	if(diff>err_abs){
	  err_abs = diff;
	}
	r_8 relatdiff = diff/ fFLijk[id];
	if(relatdiff>err_rel) err_rel = relatdiff;
      }//loop on px
      
            
      cout << " >>>>>>>>>>>>>>>>>>>>> Shell["<<ish<<"] <<<<<<<<<<<<<<<<<<<<<<<<<<" << endl; 
      cout << "Err. Max. " << err_abs << ", Err. Rel. " << err_rel << endl;
      cout << " >>>>>>>>>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<<<<<<<<<" << endl; 

    }//loop on shell
Jean-Eric Campagne's avatar
Jean-Eric Campagne committed
1112 1113


1114
#if DEBUG >=2 
1115
    ofs.close();
1116
#endif
1117
  }//check 2
Jean-Eric Campagne's avatar
Jean-Eric Campagne committed
1118 1119 1120 1121

  

}//TestLaguerre2Bessel
1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148
//-------------------------------------------------------------

void TestPixelization() {

  int Nmax = param.N;
  int Lmax = param.Lmax;
  r_8 Rmax = param.R;
  string geometry = param.geometry;
  int ntheta = param.ntheta;
  int nphi = param.nphi;


  
  LaguerreSphericalTransform lagsht(geometry,
				    Lmax,
				    -1,
				    Nmax,
				    Rmax,
				    ntheta,
				    nphi
				    );
  
  ntheta = lagsht.GetSphericalGeometry()->NTheta(); //identique a Nrings
  nphi   = lagsht.GetSphericalGeometry()->NPhi();

  int state = 1234567 + 8912 ; //random seed
  
1149
  stringstream ss; ss << "pixels-" << geometry << "-L" << Lmax << ".txt";
1150
  std::ofstream ofs (ss.str().c_str(), std::ofstream::out);
1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175

  r_8 dTheta = M_PI/ntheta/2;
  r_8 dPhi   = 2*M_PI/nphi/2;
  
  cout << "half theta Width : " << dTheta << ", half phi Width : " << dPhi << endl; 

  
  int nloop = 100000;

  for (int i=0;i<nloop; i++) {
    r_8 theta_test = drand(0.,M_PI,&state);
    r_8 phi_test = drand(0.,2*M_PI,&state);
    int idx = lagsht.GetSphericalGeometry()->PixIndexSph(theta_test, phi_test);

    r_8 theta_out;
    r_8 phi_out;
    lagsht.GetSphericalGeometry()->PixThetaPhi(idx,theta_out, phi_out);
    
    r_8 dphi = phi_test-phi_out;
    if(dphi>M_PI)dphi=2*M_PI-dphi;

    ofs << theta_test << " " << phi_test << " " << theta_out << " " << phi_out << " " << dphi<< endl;
  }
  
}//TestPixelization
1176 1177 1178 1179 1180 1181 1182

//----------------------------------------------
//               Main 
//----------------------------------------------

int main(int narg, char *arg[]) {

1183
   unsigned int maxmemsize =  getMemorySize()/1e6;
1184 1185
   cout << "Max Memory size: " <<  maxmemsize << " MBytes" <<  endl;

1186
  int N = 128; 
1187
  r_8 R = 1.;
1188
  int Lmax = 128;
1189
  int Pmax = 0;
1190
  int spin = 0;
1191

1192 1193 1194 1195 1196