Page MenuHomec4science

fftw_engine.hh
No OneTemporary

File Metadata

Created
Sat, Apr 27, 14:04

fftw_engine.hh

/**
* @file
* @section LICENSE
*
* Copyright (©) 2016-2021 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 FFTW_ENGINE_H
#define FFTW_ENGINE_H
/* -------------------------------------------------------------------------- */
#include "fft_engine.hh"
/* -------------------------------------------------------------------------- */
namespace tamaas {
class FFTWEngine : public FFTEngine {
private:
/// Perform forward (R2C) transform
template <UInt dim>
void forwardImpl(Grid<Real, dim>& real, GridHermitian<Real, dim>& spectral);
/// Perform backward (C2R) transform
template <UInt dim>
void backwardImpl(Grid<Real, dim>& real, GridHermitian<Real, dim>& spectral);
/// Return the plans pair for a given transform signature
plan_t& getPlans(key_t key);
public:
/// Initialize with flags
explicit FFTWEngine(unsigned int flags = FFTW_ESTIMATE) noexcept
: _flags(flags), plans() {}
void forward(Grid<Real, 1>& real, GridHermitian<Real, 1>& spectral) override {
forwardImpl(real, spectral);
}
void forward(Grid<Real, 2>& real, GridHermitian<Real, 2>& spectral) override {
forwardImpl(real, spectral);
}
void backward(Grid<Real, 1>& real,
GridHermitian<Real, 1>& spectral) override {
backwardImpl(real, spectral);
}
void backward(Grid<Real, 2>& real,
GridHermitian<Real, 2>& spectral) override {
backwardImpl(real, spectral);
}
unsigned int flags() const { return _flags; }
protected:
unsigned int _flags; ///< FFTW flags
std::map<key_t, plan_t> plans; ///< plans corresponding to signatures
};
/* -------------------------------------------------------------------------- */
template <UInt dim>
void FFTWEngine::forwardImpl(Grid<Real, dim>& real,
GridHermitian<Real, dim>& spectral) {
auto& plans = getPlans(make_key(real, spectral));
fftw::execute(plans.first, real.getInternalData(),
cast(spectral.getInternalData()));
}
template <UInt dim>
void FFTWEngine::backwardImpl(Grid<Real, dim>& real,
GridHermitian<Real, dim>& spectral) {
auto& plans = getPlans(make_key(real, spectral));
fftw::execute(plans.second, cast(spectral.getInternalData()),
real.getInternalData());
// Normalize
real *= (1. / real.getNbPoints());
}
} // namespace tamaas
#endif

Event Timeline