Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F98988304
test_fft.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Jan 18, 06:51
Size
2 KB
Mime Type
text/x-c
Expires
Mon, Jan 20, 06:51 (2 d)
Engine
blob
Format
Raw Data
Handle
23680843
Attached To
rTAMAAS tamaas
test_fft.cpp
View Options
/**
*
* @author Lucas Frérot <lucas.frerot@epfl.ch>
*
* @section LICENSE
*
* Copyright (©) 2017 EPFL (Ecole Polytechnique Fédérale de
* Lausanne) Laboratory (LSMS - Laboratoire de Simulation en Mécanique des
* Solides)
*
* Tamaas is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* Tamaas is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Tamaas. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* -------------------------------------------------------------------------- */
#include "grid.hh"
#include "grid_hermitian.hh"
#include "fft_plan_manager.hh"
#include <array>
#include <algorithm>
#include <numeric>
#include <fftw3.h>
#include "test.hh"
using namespace tamaas;
/* -------------------------------------------------------------------------- */
TestSuite(fft_interface, .init = tamaas_init, .fini = tamaas_teardown);
Test(fft_1d, fft_interface) {
constexpr UInt size = 20;
double data[size] = {0};
fftw_complex solution[size/2 + 1] = {{0}};
std::iota(std::begin(data), std::end(data), 0);
fftw_plan solution_plan = fftw_plan_dft_r2c_1d(size, data, solution, FFTW_ESTIMATE);
fftw_execute(solution_plan);
Grid<Real, 1> grid({size}, 1);
std::iota(grid.begin(), grid.end(), 0);
GridHermitian<Real, 1> result({size/2 + 1}, 1);
FFTPlanManager::get().createPlan(grid, result).forwardTransform();
#ifdef USE_CUDA
cudaDeviceSynchronize();
#endif
cr_assert(compare(result, solution, AreComplexEqual()), "1D FFTW transform failed");
fftw_destroy_plan(solution_plan);
FFTPlanManager::get().destroyPlan(grid, result);
}
Test(fft_2d, fft_interface) {
constexpr UInt size = 10;
double data[size * size] = {0};
fftw_complex solution[size * (size/2 + 1)] = {{0}};
std::iota(std::begin(data), std::end(data), 0);
fftw_plan solution_plan = fftw_plan_dft_r2c_2d(size, size, data, solution, FFTW_ESTIMATE);
fftw_execute(solution_plan);
Grid<Real, 2> grid({size, size}, 1);
std::iota(grid.begin(), grid.end(), 0);
GridHermitian<Real, 2> result({size, size/2 + 1}, 1);
FFTPlanManager::get().createPlan(grid, result).forwardTransform();
#ifdef USE_CUDA
cudaDeviceSynchronize();
#endif
cr_assert(compare(result, solution, AreComplexEqual()), "2D FFTW transform failed");
fftw_destroy_plan(solution_plan);
FFTPlanManager::get().destroyPlan(grid, result);
}
Event Timeline
Log In to Comment