mirror of
https://github.com/cosmo-sims/MUSIC.git
synced 2024-09-19 17:03:46 +02:00
improved accuracy when using single precision mode by explicitly avoiding a possible truncation error in the FFT
This commit is contained in:
parent
44cdfc728b
commit
59fb3b2b8a
1 changed files with 19 additions and 6 deletions
|
@ -97,6 +97,9 @@ namespace convolution{
|
|||
}
|
||||
|
||||
//.............................................
|
||||
|
||||
std::complex<double> dcmode(RE(cdata[0]),IM(cdata[0]));
|
||||
|
||||
if( !pk->is_ksampled() ) {
|
||||
|
||||
#pragma omp parallel for
|
||||
|
@ -130,7 +133,6 @@ namespace convolution{
|
|||
}else{
|
||||
|
||||
|
||||
std::complex<double> dcmode(RE(cdata[0]),IM(cdata[0]));
|
||||
|
||||
#pragma omp parallel
|
||||
{
|
||||
|
@ -181,9 +183,9 @@ namespace convolution{
|
|||
delete[] argvec;
|
||||
}
|
||||
|
||||
|
||||
RE(cdata[0]) = dcmode.real() * fftnorm;
|
||||
IM(cdata[0]) = dcmode.imag() * fftnorm;
|
||||
// we now set the correct DC mode below...
|
||||
RE(cdata[0]) = 0.0;
|
||||
IM(cdata[0]) = 0.0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -210,6 +212,17 @@ namespace convolution{
|
|||
rfftwnd_destroy_plan(plan);
|
||||
rfftwnd_destroy_plan(iplan);
|
||||
#endif
|
||||
|
||||
|
||||
// set the DC mode here to avoid a possible truncation error in single precision
|
||||
if( pk->is_ksampled() ) {
|
||||
size_t nelem = (size_t)cparam_.nx * (size_t)cparam_.ny * (size_t)cparam_.nz;
|
||||
real_t mean = dcmode.real() * fftnorm / (real_t)nelem;
|
||||
|
||||
#pragma omp parallel for
|
||||
for( size_t i=0; i<nelem; ++i )
|
||||
data[i] += mean;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue