Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F64136268
fftransform.hh
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
Fri, May 24, 20:15
Size
3 KB
Mime Type
text/x-c++
Expires
Sun, May 26, 20:15 (2 d)
Engine
blob
Format
Raw Data
Handle
17859930
Attached To
rTAMAAS tamaas
fftransform.hh
View Options
/**
* @file
* @section LICENSE
*
* Copyright (©) 2016-19 EPFL (École Polytechnique Fédérale de Lausanne),
* Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://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>
/* -------------------------------------------------------------------------- */
namespace 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);
#pragma omp parallel for // to get rid of a compilation warning from nvcc
for (UInt i = 0; i < freq.getNbPoints(); ++i) {
UInt index = i;
VectorProxy<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;
}
/* -------------------------------------------------------------------------- */
} // namespace tamaas
/* -------------------------------------------------------------------------- */
#endif // FFTRANSFORM_HH
Event Timeline
Log In to Comment