2012-11-11 19:30:29 +01:00
|
|
|
#include <boost/format.hpp>
|
2012-11-10 23:35:27 +01:00
|
|
|
#include "yorick.hpp"
|
|
|
|
#include <gsl/gsl_rng.h>
|
2012-11-10 16:56:47 +01:00
|
|
|
#include <iostream>
|
2012-11-10 23:35:27 +01:00
|
|
|
#include <cmath>
|
2012-10-06 18:56:33 +02:00
|
|
|
#include "fourier/euclidian.hpp"
|
|
|
|
|
|
|
|
using namespace CosmoTool;
|
2012-11-11 19:30:29 +01:00
|
|
|
using boost::format;
|
|
|
|
using boost::str;
|
2012-11-10 16:56:47 +01:00
|
|
|
using namespace std;
|
2012-10-06 18:56:33 +02:00
|
|
|
|
2012-11-10 23:35:27 +01:00
|
|
|
double spectrum_generator(double k)
|
|
|
|
{
|
2012-11-11 01:11:34 +01:00
|
|
|
if (k==0)
|
|
|
|
return 0;
|
|
|
|
return 1/(0.01+pow(k, 3.0));
|
2012-11-10 23:35:27 +01:00
|
|
|
}
|
|
|
|
|
2012-11-11 20:26:05 +01:00
|
|
|
template<typename T>
|
2012-11-11 19:30:29 +01:00
|
|
|
void test_2d(int Nx, int Ny)
|
2012-10-06 18:56:33 +02:00
|
|
|
{
|
2012-11-11 20:26:05 +01:00
|
|
|
EuclidianFourierTransform_2d<T> dft(Nx,Ny,1.0,1.0);
|
|
|
|
EuclidianSpectrum_1D<T> spectrum(spectrum_generator);
|
2012-11-11 19:30:29 +01:00
|
|
|
double volume = Nx*Ny;
|
2012-11-10 23:35:27 +01:00
|
|
|
gsl_rng *rng = gsl_rng_alloc(gsl_rng_default);
|
2012-10-06 18:56:33 +02:00
|
|
|
|
|
|
|
dft.realSpace().eigen().setRandom();
|
2012-11-11 20:26:05 +01:00
|
|
|
dft.fourierSpace().scale(std::complex<T>(0,0));
|
2012-10-06 18:56:33 +02:00
|
|
|
dft.analysis();
|
2012-11-11 19:30:29 +01:00
|
|
|
cout << format("Testing (%d,%d)") % Nx % Ny << endl;
|
2012-11-10 16:56:47 +01:00
|
|
|
cout << "Map dot-product = " << dft.realSpace().dot_product(dft.realSpace()) << endl;
|
|
|
|
cout << "Fourier dot-product = " << dft.fourierSpace().dot_product(dft.fourierSpace()).real()*volume << endl;
|
2012-11-10 17:10:04 +01:00
|
|
|
dft.synthesis();
|
|
|
|
cout << "Resynthesis dot-product = " << dft.realSpace().dot_product(dft.realSpace()) << endl;
|
2012-11-10 23:35:27 +01:00
|
|
|
|
|
|
|
dft.realSpace().scale(2.0);
|
|
|
|
dft.fourierSpace().scale(0.2);
|
|
|
|
|
2012-11-11 21:46:03 +01:00
|
|
|
spectrum.newRandomFourier(rng, dft.fourierSpace());
|
2012-11-10 23:35:27 +01:00
|
|
|
dft.synthesis();
|
|
|
|
|
2012-11-11 19:30:29 +01:00
|
|
|
uint32_t dims[2] = { Ny, Nx };
|
|
|
|
CosmoTool::saveArray(str(format("generated_map_%d_%d.nc") %Nx % Ny) , dft.realSpace().data(), dims, 2);
|
2012-11-11 20:26:05 +01:00
|
|
|
|
|
|
|
gsl_rng_free(rng);
|
2012-11-11 19:30:29 +01:00
|
|
|
}
|
2012-11-10 17:10:04 +01:00
|
|
|
|
2012-11-11 19:30:29 +01:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2012-11-11 20:26:05 +01:00
|
|
|
test_2d<double>(128,128);
|
|
|
|
test_2d<double>(131,128);
|
2012-11-11 20:30:45 +01:00
|
|
|
test_2d<double>(130,128);
|
2012-11-11 20:26:26 +01:00
|
|
|
test_2d<float>(128,128);
|
2012-11-11 20:30:45 +01:00
|
|
|
test_2d<float>(128,131);
|
|
|
|
test_2d<float>(128,130);
|
2012-11-11 19:30:29 +01:00
|
|
|
return 0;
|
2012-10-06 18:56:33 +02:00
|
|
|
}
|