NESSi  v1.0.2
The NonEquilibrium Systems Simulation Library

◆ sample()

template<class function >
void fourier::adft_func::sample ( double  w,
double  a,
double  b,
function &  fz,
int  n,
int  limit 
)
inline

Fourier samples the given function to determine the individual intervals.

Purpose

Computes the Fourier integral for fixed frequency \(\omega\). The interval \([a,b]\) is iteratively split until the error of the Fourier integral over each subinterval is smaller or equal than the smallest error.

Parameters
w

frequency \(\omega\) in the Fourier integral

a

lower interval bound

b

upper interval bound

fz

[template class function] scalar complex function

n

number of points in each interval

limit

max number of intervals

Definition at line 366 of file fourier.hpp.

References fourier::dft_cplx().

Referenced by cntr::green_equilibrium_mat(), and cntr::smooth_box::set_norm().

366  {
367  // n: number of points in each interval
368  // limit: max number of intervals
369  int i,n_cur,isplit;
370  double abserr,abserr_i;
371  cplx z,res_i,err_i,res_l,err_l,res_r,err_r;
372  std::vector<cplx> results(limit),errors(limit);
373 
374  if(n<ADFT_MINPTS || n%2!=0){ std::cerr << "adft_cplx_sample: n<16 || n%2!=0" << std::endl; abort();}
375  if(limit<1){std::cerr << "adft_cplx_sample: limit<1" << std::endl; abort();}
376  if(a>=b){ std::cerr << "adft_cplx_sample: a>=b" << std::endl;abort();}
377 
378  if(limit != nmax_ || (n+1)*limit != size_ ) resize((n+1)*limit,limit);
379  // Sample f in first interval
380  init(a,b,n,fz);
381  if(limit==1) return;
382  // split first interval
383  split(0,fz);
384  // do the first fourier transform
385  fourier::dft_cplx(w,n,a_[0],b_[0],interval_data(0),results[0],errors[0]);
386  fourier::dft_cplx(w,n,a_[1],b_[1],interval_data(1),results[1],errors[1]);
387  while(n_+1<limit){
388  // look for largest error in res-table
389  n_cur=n_;
390  abserr=-1.0;
391  isplit=-1;
392  for(i=0;i<n_cur;i++){
393  z=errors[i];
394  abserr_i=sqrt(z.real()*z.real()+z.imag()*z.imag());
395  if(abserr_i>abserr){
396  isplit=i;
397  abserr=abserr_i;
398  }
399  }
400  // split interval isplit and integrate partial intervals
401 
402  //std::cout << "isplit= "<< isplit << "n= "<< n_ << std::endl;
403 // std::cout << "n " << n_ << "i " << isplit << "[ " << a_[isplit] << "," << b_[isplit] << "]" << std::endl;
404  split(isplit,fz);
405 
406  fourier::dft_cplx(w,n,a_[isplit],b_[isplit],interval_data(isplit),res_l,err_l);
407  fourier::dft_cplx(w,n,a_[isplit+1],b_[isplit+1],interval_data(isplit+1),res_r,err_r);
408  // update res-table
409  for(i=n_cur-1;i>isplit;i--){
410  results[i+1]=results[i];
411  errors[i+1]=errors[i];
412  }
413  results[isplit+1]=res_r;
414  errors[isplit+1]=err_r;
415  results[isplit]=res_l;
416  errors[isplit]=err_l;
417  }
418  }
std::complex< double > cplx
Definition: fourier.hpp:44
void dft_cplx(double w, int n, double a, double b, cplx *f, cplx &res, cplx &err)
Computes the Fourier integral using cubically corrected DFT.
Definition: fourier.cpp:283
+ Here is the call graph for this function:
+ Here is the caller graph for this function: