Changeset 3285 in Sophya for trunk/Cosmo/SimLSS/cosmocalc.cc
- Timestamp:
- Jul 29, 2007, 9:01:31 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cosmo/SimLSS/cosmocalc.cc
r3267 r3285 106 106 void CosmoCalc::SetInteg(double dperc,double dzinc,double dzmax,unsigned short order) 107 107 { 108 _dperc = fabs(dperc); 109 110 _dzinc = fabs(dzinc); 111 if(_dzinc>_zmax/5.) _dzinc = _zmax/5.; // Protection against big dzinc 112 113 _dzmax = fabs(dzmax); 108 _dperc = dperc; _dzinc = dzinc; _dzmax = dzmax; 109 110 if(_dperc<=0.) _dperc = 0.01; 111 112 if(_dzinc<=0.) _dzinc = _zmax/100.; 113 if(_dzinc>=_zmax/2.) _dzinc = _zmax/2.; // Protection against big dzinc 114 115 if(_dzmax<=0.) _dzmax = _zmax; 114 116 if(_dzmax<_dzinc) _dzmax = _dzinc; 115 117 … … 119 121 120 122 _computespl=true; 123 } 124 125 126 void CosmoCalc::PrtInteg(void) 127 { 128 printf("CosmoCalc::PrtInteg: dperc=%g dzinc=%g dzmax=%g glorder=%hu\n",_dperc,_dzinc,_dzmax,_glorder); 121 129 } 122 130 … … 369 377 if(_usespline) { 370 378 if( (!_computespl) && (z==_zold) ) return _integval; 371 if(z>_zmax) {_zmax = z ; _computespl = true;}379 if(z>_zmax) {_zmax = z+_dzmax; _computespl = true;} 372 380 if(_computespl) Init_Spline(); 373 381 _integval = _spline->CSplineInt(z); … … 392 400 //-- Look for intervalles and integrate 393 401 vector<double> x,y; 402 x.push_back(0.); y.push_back(0.); 394 403 double zbas=0., fbas = Integrand(zbas); 395 x.push_back(zbas); y.push_back(0.); 396 for(double z=_dzinc;z<_zmax+_dzinc && zbas<_zmax;z+=_dzinc) { 404 for(double z=_dzinc;;z+=_dzinc) { 397 405 double f = Integrand(z); 398 bool doit = false;399 406 //cout<<fbas<<","<<f<<" : "<<fabs(f-fbas)<<" >? "<<_dperc*fabs(fbas)<<endl; 400 if( fabs(f-fbas)>_dperc*fabs(fbas) ) doit = true; 401 if( z-zbas>_dzmax ) doit = true; 402 if( z>_zmax ) {doit = true; z=_zmax;} 403 if( ! doit ) continue; 404 x.push_back(z); 405 double sum = 0., dz = z-zbas; 406 for(unsigned short i=0;i<_glorder;i++) sum += _wgausl[i]*Integrand(zbas+_xgausl[i]*dz); 407 y.push_back(sum*dz); 408 //cout<<"...set... "<<zbas<<","<<z<<" , "<<fbas<<","<<f<<endl; 409 zbas = z; 410 fbas = f; 407 if( z>_zmax || z-zbas>_dzmax || fabs(f-fbas)>_dperc*fabs(fbas) ) { 408 double sum=0., dz=z-zbas; 409 for(unsigned short i=0;i<_glorder;i++) sum += _wgausl[i]*Integrand(zbas+_xgausl[i]*dz); 410 x.push_back(z); y.push_back(sum*dz); 411 //cout<<"...set... "<<zbas<<","<<z<<" , "<<fbas<<","<<f<<endl; 412 zbas = z; fbas = f; 413 if( z>_zmax ) break; 414 } 415 } 416 417 //-- Protection car il faut au moins 4 points pour un spline cubique 418 if(x.size()<4) { 419 x.resize(0); y.resize(0); 420 x.push_back(0.); y.push_back(0.); 421 for(int i=1;i<4;i++) { 422 x.push_back(i*_zmax/3.); 423 double sum=0., dz=x[i]-x[i-1]; 424 for(unsigned short i=0;i<_glorder;i++) sum += _wgausl[i]*Integrand(x[i-1]+_xgausl[i]*dz); 425 y.push_back(sum*dz); 426 } 411 427 } 412 428 … … 420 436 if(i!=0) _yspl[i] += _yspl[i-1]; 421 437 } 438 439 #if 1 440 cout<<"CosmoCalc::Init_Spline called: (zmax="<<_zmax<<") _nspl="<<_nspl<<endl; 441 int n = (_nspl>5)? 5: _nspl; 442 cout<<_nspl<<"..."; 443 for(int i=0;i<n;i++) cout<<_xspl[i]<<" ("<<_yspl[i]<<") "; 444 cout<<"\n... "; 445 n = (_nspl<5)? 0: _nspl-5; 446 for(int i=n;i<_nspl;i++) cout<<_xspl[i]<<" ("<<_yspl[i]<<") "; 447 cout<<endl; 448 #endif 449 422 450 double yp1 = Integrand(_xspl[0]); 423 451 double ypn = Integrand(_xspl[_nspl-1]); … … 426 454 _computespl = false; 427 455 428 cout<<"CosmoCalc::Init_Spline called: (zmax="<<_zmax<<") _nspl="<<_nspl<<endl;429 for(int i=0;i<(10<_nspl?10:_nspl);i++) cout<<_xspl[i]<<" ";430 cout<<" ... "<<_xspl[_nspl-1]<<endl;431 432 456 return _nspl; 433 457 }
Note:
See TracChangeset
for help on using the changeset viewer.