Changeset 3285 in Sophya for trunk/Cosmo/SimLSS/cosmocalc.cc


Ignore:
Timestamp:
Jul 29, 2007, 9:01:31 PM (18 years ago)
Author:
cmv
Message:

update logique Init_Spline de CosmoCalc cmv 29/07/07

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cosmo/SimLSS/cosmocalc.cc

    r3267 r3285  
    106106void CosmoCalc::SetInteg(double dperc,double dzinc,double dzmax,unsigned short order)
    107107{
    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;
    114116  if(_dzmax<_dzinc) _dzmax = _dzinc;
    115117
     
    119121
    120122  _computespl=true;
     123}
     124
     125
     126void CosmoCalc::PrtInteg(void)
     127{
     128 printf("CosmoCalc::PrtInteg: dperc=%g dzinc=%g dzmax=%g glorder=%hu\n",_dperc,_dzinc,_dzmax,_glorder);
    121129}
    122130
     
    369377  if(_usespline) {
    370378    if( (!_computespl) && (z==_zold) ) return _integval;
    371     if(z>_zmax) {_zmax = z; _computespl = true;}
     379    if(z>_zmax) {_zmax = z+_dzmax; _computespl = true;}
    372380    if(_computespl) Init_Spline();
    373381    _integval = _spline->CSplineInt(z);
     
    392400  //-- Look for intervalles and integrate
    393401  vector<double> x,y;
     402  x.push_back(0.); y.push_back(0.);
    394403  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) {
    397405    double f = Integrand(z);
    398     bool doit = false;
    399406    //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    }
    411427  }
    412428
     
    420436    if(i!=0) _yspl[i] += _yspl[i-1];
    421437  }
     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
    422450  double yp1 = Integrand(_xspl[0]);
    423451  double ypn = Integrand(_xspl[_nspl-1]);
     
    426454  _computespl = false;
    427455
    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 
    432456  return _nspl;
    433457}
Note: See TracChangeset for help on using the changeset viewer.