Skip to content

Commit 4e1a054

Browse files
committed
Introduce interface IFFT to FFT
1 parent 018c41c commit 4e1a054

File tree

5 files changed

+40
-9
lines changed

5 files changed

+40
-9
lines changed

include/openpfc/core/decomposition.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ using pfc::types::Real3;
5353
using World = pfc::world::World<CartesianTag>;
5454
using Int3 = pfc::types::Int3;
5555

56+
using heffte::proc_setup_min_surface;
57+
5658
/**
5759
* @brief Describes a static, pure partitioning of the global simulation domain
5860
* into local subdomains.
@@ -188,11 +190,11 @@ inline const auto create(const World &world, const Int3 &grid) noexcept {
188190

189191
inline const auto create(const World &world, const int &nparts) noexcept {
190192
auto indices = to_indices(world);
191-
auto grid = heffte::proc_setup_min_surface(indices, nparts);
193+
auto grid = proc_setup_min_surface(indices, nparts);
192194
return create(world, grid);
193195
}
194196

195-
inline const auto get_num_domains(const Decomposition &decomposition) noexcept {
197+
inline int get_num_domains(const Decomposition &decomposition) noexcept {
196198
return get_subworlds(decomposition).size();
197199
}
198200

include/openpfc/core/world.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ template <typename T> int get_size(const World<T> &world, int index) {
295295
* @param w World object.
296296
* @return The total number of grid points.
297297
*/
298-
template <typename T> int total_size(const World<T> &world) noexcept {
298+
template <typename T> size_t get_total_size(const World<T> &world) noexcept {
299299
return get_size(world, 0) * get_size(world, 1) * get_size(world, 2);
300300
}
301301

include/openpfc/fft.hpp

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ using pfc::types::Int3;
2727
* real-to-complex symmetry, and the boxes for real and complex FFT data.
2828
*/
2929
struct FFTLayout {
30-
const Decomposition m_decomposition; ///< The Decomposition object.
31-
const int m_r2c_direction = 0; ///< Real-to-complex symmetry direction.
32-
const std::vector<box3di> m_real_boxes; ///< Real boxes for FFT.
33-
const std::vector<box3di> m_complex_boxes; ///< Complex boxes for FFT.
30+
const Decomposition m_decomposition; ///< The Decomposition object.
31+
const int m_r2c_direction = 0; ///< Real-to-complex symmetry direction.
32+
const std::vector<heffte::box3d<int>> m_real_boxes; ///< Real boxes for FFT.
33+
const std::vector<heffte::box3d<int>> m_complex_boxes; ///< Complex boxes for FFT.
3434
};
3535

3636
/**
@@ -62,15 +62,43 @@ using pfc::types::Int3;
6262
using pfc::types::Real3;
6363

6464
using Decomposition = pfc::decomposition::Decomposition;
65+
using RealVector = std::vector<double>;
6566
using ComplexVector = std::vector<std::complex<double>>;
6667
using fft_r2c = heffte::fft3d_r2c<heffte::backend::fftw>;
6768
using box3di = heffte::box3d<int>; ///< Type alias for 3D integer box.
6869

70+
struct IFFT {
71+
virtual ~IFFT() = default;
72+
73+
/**
74+
* @brief Performs the forward FFT transformation.
75+
*
76+
* @param in Input vector of real values.
77+
* @param out Output vector of complex values.
78+
*/
79+
virtual void forward(const RealVector &in, ComplexVector &out) = 0;
80+
81+
/**
82+
* @brief Performs the backward (inverse) FFT transformation.
83+
*
84+
* @param in Input vector of complex values.
85+
* @param out Output vector of real values.
86+
*/
87+
virtual void backward(const ComplexVector &in, RealVector &out) = 0;
88+
89+
virtual void reset_fft_time() = 0;
90+
virtual double get_fft_time() const = 0;
91+
92+
virtual size_t size_inbox() const = 0;
93+
virtual size_t size_outbox() const = 0;
94+
virtual size_t size_workspace() const = 0;
95+
};
96+
6997
/**
7098
* @brief FFT class for performing forward and backward Fast Fourier
7199
* Transformations.
72100
*/
73-
struct FFT {
101+
struct FFT : IFFT {
74102

75103
// const Decomposition m_decomposition; /**< The Decomposition object. */
76104
// const box3di m_inbox, m_outbox; /**< Local inbox and outbox boxes. */

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ add_executable(openpfc-tests
1010
test_world.cpp
1111
test_box3d.cpp
1212
test_decomposition.cpp
13+
test_field.cpp
1314
test_fft.cpp
1415
test_fft_setting.cpp
1516
test_arraynd.cpp

tests/test_world.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ TEST_CASE("World - Total Size", "[world]") {
8585
SECTION("Correct total size calculation") {
8686
Int3 dimensions = {10, 20, 30};
8787
World world = world::create(dimensions);
88-
REQUIRE(total_size(world) == 10 * 20 * 30);
88+
REQUIRE(get_total_size(world) == 10 * 20 * 30);
8989
}
9090
}
9191

0 commit comments

Comments
 (0)