Improved the test to check different size of maps

This commit is contained in:
Guilhem Lavaux 2012-11-11 13:30:29 -05:00
parent b161ab0990
commit ff7b8dc45e

View File

@ -1,3 +1,4 @@
#include <boost/format.hpp>
#include "yorick.hpp" #include "yorick.hpp"
#include <gsl/gsl_rng.h> #include <gsl/gsl_rng.h>
#include <iostream> #include <iostream>
@ -5,6 +6,8 @@
#include "fourier/euclidian.hpp" #include "fourier/euclidian.hpp"
using namespace CosmoTool; using namespace CosmoTool;
using boost::format;
using boost::str;
using namespace std; using namespace std;
double spectrum_generator(double k) double spectrum_generator(double k)
@ -14,15 +17,16 @@ double spectrum_generator(double k)
return 1/(0.01+pow(k, 3.0)); return 1/(0.01+pow(k, 3.0));
} }
int main() void test_2d(int Nx, int Ny)
{ {
EuclidianFourierTransform_2d<double> dft(1024,1024,1.0,1.0); EuclidianFourierTransform_2d<double> dft(Nx,Ny,1.0,1.0);
EuclidianSpectrum_1D<double> spectrum(spectrum_generator); EuclidianSpectrum_1D<double> spectrum(spectrum_generator);
double volume = 1024*1024; double volume = Nx*Ny;
gsl_rng *rng = gsl_rng_alloc(gsl_rng_default); gsl_rng *rng = gsl_rng_alloc(gsl_rng_default);
dft.realSpace().eigen().setRandom(); dft.realSpace().eigen().setRandom();
dft.analysis(); dft.analysis();
cout << format("Testing (%d,%d)") % Nx % Ny << endl;
cout << "Map dot-product = " << dft.realSpace().dot_product(dft.realSpace()) << 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; cout << "Fourier dot-product = " << dft.fourierSpace().dot_product(dft.fourierSpace()).real()*volume << endl;
dft.synthesis(); dft.synthesis();
@ -35,9 +39,13 @@ int main()
dft.fourierSpace() = *m.get(); dft.fourierSpace() = *m.get();
dft.synthesis(); dft.synthesis();
uint32_t dims[2] = { 1024, 1024 }; uint32_t dims[2] = { Ny, Nx };
CosmoTool::saveArray("generated_map.nc", dft.realSpace().data(), dims, 2); CosmoTool::saveArray(str(format("generated_map_%d_%d.nc") %Nx % Ny) , dft.realSpace().data(), dims, 2);
}
return 0;
int main(int argc, char **argv)
{
test_2d(128,128);
test_2d(131,128);
return 0;
} }