Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F80781083
fftw_engine.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
Mon, Sep 2, 13:52
Size
3 KB
Mime Type
text/x-c++
Expires
Wed, Sep 4, 13:52 (2 d)
Engine
blob
Format
Raw Data
Handle
20298351
Attached To
rTAMAAS tamaas
fftw_engine.hh
View Options
/**
* @file
* @section LICENSE
*
* Copyright (©) 2016-2020 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
Log In to Comment