1
0
Fork 0
mirror of https://github.com/cosmo-sims/MUSIC.git synced 2024-09-19 17:03:46 +02:00

a few fixes.

This commit is contained in:
Oliver Hahn 2013-11-05 17:06:45 +01:00
parent df94ef9fac
commit 35046923eb
5 changed files with 86 additions and 164 deletions

View file

@ -10,7 +10,7 @@ BOXLIB_HOME = ${HOME}/nyx_tot_sterben/BoxLib
##############################################################################
### compiler and path settings
CC = g++
OPT = -Wall -Wno-unknown-pragmas -O3 -g -mtune=native
OPT = -Wall -Wno-unknown-pragmas -O0 -g -mtune=native
CFLAGS =
LFLAGS = -lgsl -lgslcblas
CPATHS = -I. -I$(HOME)/local/include -I/opt/local/include -I/usr/local/include

View file

@ -216,11 +216,12 @@ namespace convolution{
template void perform<double>( kernel* pk, void *pd, bool shift );
template void perform<float>( kernel* pk, void *pd, bool shift );
/*****************************************************************************************\
*** SPECIFIC KERNEL IMPLEMENTATIONS *********************************************
\*****************************************************************************************/
/*****************************************************************************************/
/*** SPECIFIC KERNEL IMPLEMENTATIONS *********************************************/
/*****************************************************************************************/
template< typename real_t >
class kernel_k_new : public kernel
class kernel_k : public kernel
{
protected:
/**/
@ -228,7 +229,7 @@ namespace convolution{
TransferFunction_k *tfk_;
public:
kernel_k_new( config_file& cf, transfer_function* ptf, refinement_hierarchy& refh, tf_type type )
kernel_k( config_file& cf, transfer_function* ptf, refinement_hierarchy& refh, tf_type type )
: kernel( cf, ptf, refh, type )
{
boxlength_ = pcf_->getValue<double>("setup","boxlength");
@ -283,7 +284,6 @@ namespace convolution{
return this;
}
void *get_ptr() { return NULL; }
bool is_ksampled() { return true; }
@ -293,14 +293,11 @@ namespace convolution{
for( size_t i=0; i<len; ++i )
{
double kk = kfac_ * in_k[i];
/*if( kk > kmax_ )
out_Tk[i] = 0.0;
else*/
out_Tk[i] = volfac_ * tfk_->compute( kk );
}
}
~kernel_k_new() { delete tfk_; }
~kernel_k() { delete tfk_; }
void deallocate() { }
@ -309,107 +306,6 @@ namespace convolution{
template< typename real_t >
class kernel_k : public kernel
{
protected:
std::vector<real_t> kdata_;
void compute_kernel( tf_type type );
public:
kernel_k( config_file& cf, transfer_function* ptf, refinement_hierarchy& refh, tf_type type )
: kernel( cf, ptf, refh, type )
{ }
kernel* fetch_kernel( int ilevel, bool isolated=false );
void *get_ptr()
{ return reinterpret_cast<void*> (&kdata_[0]); }
bool is_ksampled()
{ return false; }
void at_k( size_t, const double*, double * ) { }
~kernel_k()
{ deallocate(); }
void deallocate()
{ std::vector<real_t>().swap( kdata_ ); }
};
template< typename real_t >
kernel* kernel_k<real_t>::fetch_kernel( int ilevel, bool isolated )
{
double
boxlength = pcf_->getValue<double>("setup","boxlength"),
nspec = pcf_->getValue<double>("cosmology","nspec"),
pnorm = pcf_->getValue<double>("cosmology","pnorm"),
fac = pow(boxlength,3)/pow(2.0*M_PI,3);
TransferFunction_k *tfk = new TransferFunction_k(type_,ptf_,nspec,pnorm);
int
nx = prefh_->size(prefh_->levelmax(),0),
ny = prefh_->size(prefh_->levelmax(),1),
nz = prefh_->size(prefh_->levelmax(),2);
cparam_.nx = nx;
cparam_.ny = ny;
cparam_.nz = nz;
cparam_.lx = boxlength;
cparam_.ly = boxlength;
cparam_.lz = boxlength;
cparam_.pcf = pcf_;
kdata_.assign( (size_t)nx*(size_t)ny*(size_t)(nz+2), 0.0 );
fftw_complex *kdata = reinterpret_cast<fftw_complex*> ( this->get_ptr() );
unsigned nzp = (nz/2+1);
fac =1.0;
double kfac = 2.0*M_PI/boxlength, ksum = 0.0;
size_t kcount = 0;
#pragma omp parallel for reduction(+:ksum,kcount)
for( int i=0; i<nx; ++i )
for( int j=0; j<ny; ++j )
for( int k=0; k<nz/2+1; ++k )
{
double kx,ky,kz;
kx = (double)i;
ky = (double)j;
kz = (double)k;
if( kx > nx/2 ) kx -= nx;
if( ky > ny/2 ) ky -= ny;
size_t q = ((size_t)i*ny+(size_t)j)*nzp+(size_t)k;
RE(kdata[q]) = fac*tfk->compute(kfac*sqrt(kx*kx+ky*ky+kz*kz));
IM(kdata[q]) = 0.0;
if( k==0 || k==nz/2 )
{
ksum += RE(kdata[q]);
kcount++;
}else{
ksum += 2.0*(RE(kdata[q]));
kcount+=2;
}
}
delete tfk;
return this;
}
////////////////////////////////////////////////////////////////////////////
template< typename real_t >
@ -662,12 +558,14 @@ namespace convolution{
LOGUSER("Computing fine kernel (level %d)...", levelmax);
#ifdef OLD_KERNEL_SAMPLING
int ref_fac = (deconv&&kspacepoisson)? 2 : 0;
const int ql = -ref_fac/2+1, qr = ql+ref_fac;
const double rf8 = pow(ref_fac,3);
const double dx05 = 0.5*dx, dx025 = 0.25*dx;
std::cerr << ">>>>>>>>>>>> " << ref_fac << " <<<<<<<<<<<<<<<<" << std::endl;
#endif
if( bperiodic )
{
@ -1282,11 +1180,9 @@ namespace
{
convolution::kernel_creator_concrete< convolution::kernel_real_cached<double> > creator_d("tf_kernel_real_double");
convolution::kernel_creator_concrete< convolution::kernel_real_cached<float> > creator_f("tf_kernel_real_float");
convolution::kernel_creator_concrete< convolution::kernel_k<double> > creator_kd("tf_kernel_k_double");
convolution::kernel_creator_concrete< convolution::kernel_k<float> > creator_kf("tf_kernel_k_float");
convolution::kernel_creator_concrete< convolution::kernel_k_new<double> > creator_knd("tf_kernel_k_new_double");
convolution::kernel_creator_concrete< convolution::kernel_k_new<float> > creator_knf("tf_kernel_k_new_float");
}

View file

@ -18,6 +18,8 @@
#define DEF_RAN_CUBE_SIZE 32
//#define NO_COARSE_OVERLAP
template< typename m1, typename m2 >
void fft_interpolate( m1& V, m2& v, bool from_basegrid=false )
{
@ -27,9 +29,21 @@ void fft_interpolate( m1& V, m2& v, bool from_basegrid=false )
if( !from_basegrid )
{
#ifdef NO_COARSE_OVERLAP
oxf += nxF/4;
oyf += nyF/4;
ozf += nzF/4;
#else
oxf += nxF/4 - nxf/8;
oyf += nyF/4 - nyf/8;
ozf += nzF/4 - nzf/8;
}else{
oxf -= nxf/8;
oyf -= nyf/8;
ozf -= nzf/8;
#endif
}
LOGUSER("FFT interpolate: offset=%d,%d,%d size=%d,%d,%d",oxf,oyf,ozf,nxf,nyf,nzf);
@ -47,6 +61,8 @@ void fft_interpolate( m1& V, m2& v, bool from_basegrid=false )
// copy coarse data to rcoarse[.]
memset( rcoarse, 0, sizeof(fftw_real) * nxc*nyc*nzcp );
#ifdef NO_COARSE_OVERLAP
#pragma omp parallel for
for( int i=0; i<(int)nxc/2; ++i )
for( int j=0; j<(int)nyc/2; ++j )
@ -58,6 +74,20 @@ void fft_interpolate( m1& V, m2& v, bool from_basegrid=false )
size_t q = ((size_t)ii*nyc+(size_t)jj)*nzcp+(size_t)kk;
rcoarse[q] = V( oxf+i, oyf+j, ozf+k );
}
#else
#pragma omp parallel for
for( int i=0; i<(int)nxc; ++i )
for( int j=0; j<(int)nyc; ++j )
for( int k=0; k<(int)nzc; ++k )
{
int ii(i);
int jj(j);
int kk(k);
size_t q = ((size_t)ii*nyc+(size_t)jj)*nzcp+(size_t)kk;
rcoarse[q] = V( oxf+i, oyf+j, ozf+k );
}
#endif
#pragma omp parallel for
for( int i=0; i<(int)nxf; ++i )
@ -276,9 +306,9 @@ void GenerateDensityUnigrid( config_file& cf, transfer_function *ptf, tf_type ty
LOGUSER("Using k-space transfer function kernel.");
#ifdef SINGLE_PRECISION
the_kernel_creator = convolution::get_kernel_map()[ "tf_kernel_k_new_float" ];
the_kernel_creator = convolution::get_kernel_map()[ "tf_kernel_k_float" ];
#else
the_kernel_creator = convolution::get_kernel_map()[ "tf_kernel_k_new_double" ];
the_kernel_creator = convolution::get_kernel_map()[ "tf_kernel_k_double" ];
#endif
}
else
@ -363,9 +393,9 @@ void GenerateDensityHierarchy( config_file& cf, transfer_function *ptf, tf_type
LOGUSER("Using k-space transfer function kernel.");
#ifdef SINGLE_PRECISION
the_kernel_creator = convolution::get_kernel_map()[ "tf_kernel_k_new_float" ];
the_kernel_creator = convolution::get_kernel_map()[ "tf_kernel_k_float" ];
#else
the_kernel_creator = convolution::get_kernel_map()[ "tf_kernel_k_new_double" ];
the_kernel_creator = convolution::get_kernel_map()[ "tf_kernel_k_double" ];
#endif
}
else

11
mesh.hh
View file

@ -775,17 +775,12 @@ public:
*/
bool is_refined( unsigned ilevel, int i, int j, int k ) const
{
if( ilevel == levelmax() )
return false;
if( bhave_refmask )
return !(*m_ref_masks[ilevel-1])(offset(ilevel,0)+i/2,offset(ilevel,1)+j/2,offset(ilevel,2)+k/2);
/*if( ilevel == levelmax() ){
if( !bhave_refmask ) return false;
else if( ref_mask(offset(levelmax(),0)+i/2,offset(levelmax(),1)+j/2,offset(levelmax(),2)+k/2) )
return false;
else
return true;
}*/
if( ilevel == levelmax()-1 && bhave_refmask )
return (*m_ref_masks[ilevel])(i,j,k);

View file

@ -800,8 +800,9 @@ struct HDFHyperslabWriter3Ds
hid_t memspace = H5Screate_simple(4, counts, NULL);
H5Sselect_hyperslab( filespace, H5S_SELECT_SET, offsets, NULL, counts, NULL );
herr_t status;
status = H5Dwrite(dset_id_, type_id_, memspace, filespace, H5P_DEFAULT, reinterpret_cast<void*>(data));
//herr_t status;
//status =
H5Dwrite(dset_id_, type_id_, memspace, filespace, H5P_DEFAULT, reinterpret_cast<void*>(data));
H5Sclose(filespace);
H5Sclose(memspace);
}