Page MenuHomec4science

fftransform.hh
No OneTemporary

File Metadata

Created
Thu, May 9, 11:32

fftransform.hh

/**
* @file
*
* @author Lucas Frérot <lucas.frerot@epfl.ch>
*
* @section LICENSE
*
* Copyright (©) 2016 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/>.
*
*/
/* -------------------------------------------------------------------------- */
#ifndef FFTRANSFORM_HH
#define FFTRANSFORM_HH
/* -------------------------------------------------------------------------- */
#include "grid.hh"
#include "grid_hermitian.hh"
#include "tamaas.hh"
#include "static_types.hh"
#include <thrust/execution_policy.h>
#include <vector>
/* -------------------------------------------------------------------------- */
__BEGIN_TAMAAS__
/* -------------------------------------------------------------------------- */
/**
* @brief Generic class for FFT interface wrapping
*/
template <typename T, UInt dim>
class FFTransform {
public:
/// Constructor
FFTransform(Grid<T, dim>& real, GridHermitian<T, dim>& spectral);
/// Destructor
virtual ~FFTransform();
public:
/// Perform FFT
virtual void forwardTransform() = 0;
/// Perform IFFT
virtual void backwardTransform() = 0;
/// Normalize the real surface after backward transform
virtual void normalize();
public:
/// Fill a grid with modevectors: boolean if grid has hermitian dimensions
template <bool hermitian>
static Grid<T, dim> computeFrequencies(const std::array<UInt, dim>& sizes);
protected:
Grid<T, dim>& real;
GridHermitian<T, dim>& spectral;
};
/* -------------------------------------------------------------------------- */
template <typename T, UInt dim>
template <bool hermitian>
Grid<T, dim>
FFTransform<T, dim>::computeFrequencies(const std::array<UInt, dim>& sizes) {
// If hermitian is true, we suppose the dimensions of freq are
// reduced based on hermitian symetry and that it has dim components
auto& n = sizes;
Grid<T, dim> freq(n, dim);
constexpr UInt dmax = dim - static_cast<UInt>(hermitian);
static_assert(is_policy<decltype(thrust::host)>::value, "is_policy problem");
#pragma omp parallel for // to get rid of a compilation warning from nvcc
for (UInt index = 0; index < freq.getNbPoints(); ++index) {
StaticVector<T, dim> wavevector(freq(index * freq.getNbComponents()));
std::array<UInt, dim> tuple{{0}};
/// Computing tuple from index
for (Int d = dim - 1; d >= 0; d--) {
tuple[d] = index % n[d];
index -= tuple[d];
index /= n[d];
}
if (hermitian)
wavevector(dim - 1) = tuple[dim - 1];
for (UInt d = 0; d < dmax; d++) {
// Type conversion
T td = tuple[d];
T nd = n[d];
T q = (tuple[d] < n[d] / 2) ? td : td - nd;
wavevector(d) = q;
}
}
return freq;
}
/* -------------------------------------------------------------------------- */
__END_TAMAAS__
/* -------------------------------------------------------------------------- */
#endif // FFTRANSFORM_HH

Event Timeline