Templatized the test for future, to also test floats
This commit is contained in:
parent
d8734b2a59
commit
db2ad96752
@ -17,14 +17,16 @@ double spectrum_generator(double k)
|
|||||||
return 1/(0.01+pow(k, 3.0));
|
return 1/(0.01+pow(k, 3.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
void test_2d(int Nx, int Ny)
|
void test_2d(int Nx, int Ny)
|
||||||
{
|
{
|
||||||
EuclidianFourierTransform_2d<double> dft(Nx,Ny,1.0,1.0);
|
EuclidianFourierTransform_2d<T> dft(Nx,Ny,1.0,1.0);
|
||||||
EuclidianSpectrum_1D<double> spectrum(spectrum_generator);
|
EuclidianSpectrum_1D<T> spectrum(spectrum_generator);
|
||||||
double volume = Nx*Ny;
|
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.fourierSpace().scale(std::complex<T>(0,0));
|
||||||
dft.analysis();
|
dft.analysis();
|
||||||
cout << format("Testing (%d,%d)") % Nx % Ny << endl;
|
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;
|
||||||
@ -35,17 +37,19 @@ void test_2d(int Nx, int Ny)
|
|||||||
dft.realSpace().scale(2.0);
|
dft.realSpace().scale(2.0);
|
||||||
dft.fourierSpace().scale(0.2);
|
dft.fourierSpace().scale(0.2);
|
||||||
|
|
||||||
SpectrumFunction<double>::FourierMapPtr m = spectrum.newRandomFourier(rng, dft.fourierSpace());
|
typename SpectrumFunction<T>::FourierMapPtr m = spectrum.newRandomFourier(rng, dft.fourierSpace());
|
||||||
dft.fourierSpace() = *m.get();
|
dft.fourierSpace() = *m.get();
|
||||||
dft.synthesis();
|
dft.synthesis();
|
||||||
|
|
||||||
uint32_t dims[2] = { Ny, Nx };
|
uint32_t dims[2] = { Ny, Nx };
|
||||||
CosmoTool::saveArray(str(format("generated_map_%d_%d.nc") %Nx % Ny) , dft.realSpace().data(), dims, 2);
|
CosmoTool::saveArray(str(format("generated_map_%d_%d.nc") %Nx % Ny) , dft.realSpace().data(), dims, 2);
|
||||||
|
|
||||||
|
gsl_rng_free(rng);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
test_2d(128,128);
|
test_2d<double>(128,128);
|
||||||
test_2d(131,128);
|
test_2d<double>(131,128);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user