44 lines
1.2 KiB
C++
44 lines
1.2 KiB
C++
#include "yorick.hpp"
|
|
#include <gsl/gsl_rng.h>
|
|
#include <iostream>
|
|
#include <cmath>
|
|
#include "fourier/euclidian.hpp"
|
|
|
|
using namespace CosmoTool;
|
|
using namespace std;
|
|
|
|
double spectrum_generator(double k)
|
|
{
|
|
if (k==0)
|
|
return 0;
|
|
return 1/(0.01+pow(k, 3.0));
|
|
}
|
|
|
|
int main()
|
|
{
|
|
EuclidianFourierTransform_2d<double> dft(1024,1024,1.0,1.0);
|
|
EuclidianSpectrum_1D<double> spectrum(spectrum_generator);
|
|
double volume = 1024*1024;
|
|
gsl_rng *rng = gsl_rng_alloc(gsl_rng_default);
|
|
|
|
dft.realSpace().eigen().setRandom();
|
|
dft.analysis();
|
|
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<double>::FourierMapPtr m = spectrum.newRandomFourier(rng, dft.fourierSpace());
|
|
dft.fourierSpace() = *m.get();
|
|
dft.synthesis();
|
|
|
|
uint32_t dims[2] = { 1024, 1024 };
|
|
CosmoTool::saveArray("generated_map.nc", dft.realSpace().data(), dims, 2);
|
|
|
|
return 0;
|
|
|
|
}
|