#include #include "yorick.hpp" #include #include #include #include "fourier/euclidian.hpp" using namespace CosmoTool; using boost::format; using boost::str; using namespace std; double spectrum_generator(double k) { if (k==0) return 0; return 1/(0.01+pow(k, 3.0)); } void test_2d(int Nx, int Ny) { EuclidianFourierTransform_2d dft(Nx,Ny,1.0,1.0); EuclidianSpectrum_1D spectrum(spectrum_generator); double volume = Nx*Ny; gsl_rng *rng = gsl_rng_alloc(gsl_rng_default); dft.realSpace().eigen().setRandom(); dft.analysis(); cout << format("Testing (%d,%d)") % Nx % Ny << endl; cout << "Map dot-product = " << dft.realSpace().dot_product(dft.realSpace()) << endl; cout << "Fourier dot-product = " << dft.fourierSpace().dot_product(dft.fourierSpace()).real()*volume << endl; dft.synthesis(); cout << "Resynthesis dot-product = " << dft.realSpace().dot_product(dft.realSpace()) << endl; dft.realSpace().scale(2.0); dft.fourierSpace().scale(0.2); SpectrumFunction::FourierMapPtr m = spectrum.newRandomFourier(rng, dft.fourierSpace()); dft.fourierSpace() = *m.get(); dft.synthesis(); uint32_t dims[2] = { Ny, Nx }; CosmoTool::saveArray(str(format("generated_map_%d_%d.nc") %Nx % Ny) , dft.realSpace().data(), dims, 2); } int main(int argc, char **argv) { test_2d(128,128); test_2d(131,128); return 0; }