Quantum Phenomena Explorer 7.9.8
Interactive quantum-phenomena Explorer Tutor — source documentation
Loading...
Searching...
No Matches
fft2d.h
Go to the documentation of this file.
1/**
2 * @file fft2d.h
3 * @brief Declares the two-dimensional FFT utility used by spectral quantum propagators and diagnostics.
4 * @ingroup qpe_math
5 *
6 * Source: @c core/math/fft2d.h. This file is part of Quantum Phenomena Explorer (QPE),
7 * maintained by Officina Turini. See LICENSE_IT.txt / LICENSE.txt for the
8 * QPE freeware source-available terms and THIRD_PARTY_NOTICES.txt for
9 * third-party components.
10 */
11
12#pragma once
13
14#include "complexfield2d.h"
15
16#include <cstddef>
17
18namespace qpe {
19
20// Lightweight radix-2 FFT backend used by the first TDSE solver.
21//
22// Conventions:
23// forward: X[k] = sum_n x[n] exp(-i 2*pi*k*n/N)
24// inverse: x[n] = (1/N) sum_k X[k] exp(+i 2*pi*k*n/N)
25//
26// The 2D transform is separable: rows followed by columns. Therefore the
27// inverse 2D transform is normalized by 1/(width*height) in total.
28/**
29 * @brief In-place separable radix-2 complex FFT for QPE Cartesian fields.
30 *
31 * The forward convention is
32 * \f[
33 * X_k = \sum_n x_n e^{-i2\pi kn/N}.
34 * \f]
35 * while the inverse carries the `1/N` factor. A 2D transform applies the 1D
36 * transform to rows and then columns, giving total inverse normalization
37 * `1/(width*height)`. The current implementation requires power-of-two grid
38 * dimensions, matching QPE's real-time 256x256/512x512 design target.
39 */
40class FFT2D
41{
42public:
43 /** @brief Selects forward or inverse Fourier-transform convention. */
44 enum class Direction
45 {
46 Forward,
48 };
49
50 // Current implementation is radix-2, so both dimensions must be powers
51 // of two. This is intentional: 256x256 and 512x512 are the target grids
52 // for the real-time explorer.
53 /**
54 * @brief Tests whether an integer is a non-zero power of two.
55 * @param value Integer dimension to test.
56 */
57 static bool isPowerOfTwo(std::size_t value) noexcept;
58 /**
59 * @brief Returns whether both grid dimensions are supported by the radix-2 backend.
60 * @param width Number of samples along X.
61 * @param height Number of samples along Y.
62 */
63 static bool supportsSize(std::size_t width, std::size_t height) noexcept;
64
65 /**
66 * @brief Applies an in-place 2D Fourier transform.
67 * @param field Complex grid transformed in place.
68 * @param direction Forward or inverse transform convention.
69 */
70 static void transform(ComplexField2D &field, Direction direction);
71 /** @brief Convenience wrapper for an in-place forward transform. @param field Complex grid transformed in place. */
72 static void forward(ComplexField2D &field);
73 /** @brief Convenience wrapper for an in-place normalized inverse transform. @param field Complex grid transformed in place. */
74 static void inverse(ComplexField2D &field);
75
76private:
77 /**
78 * @brief Carries out transform 1 d.
79 * @param base The base value used by the operation.
80 * @param count The count value used by the operation.
81 * @param stride The stride value used by the operation.
82 * @param direction The direction value used by the operation.
83 */
84 static void transform1D(ComplexField2D::Value *base,
85 std::size_t count,
86 std::size_t stride,
87 Direction direction);
88};
89
90} // namespace qpe
Owning Cartesian grid of complex scalar samples.
std::complex< float > Value
In-place separable radix-2 complex FFT for QPE Cartesian fields.
Definition fft2d.h:41
static bool supportsSize(std::size_t width, std::size_t height) noexcept
Returns whether both grid dimensions are supported by the radix-2 backend.
Definition fft2d.cpp:30
static void forward(ComplexField2D &field)
Convenience wrapper for an in-place forward transform.
Definition fft2d.cpp:59
static void inverse(ComplexField2D &field)
Convenience wrapper for an in-place normalized inverse transform.
Definition fft2d.cpp:64
static void transform1D(ComplexField2D::Value *base, std::size_t count, std::size_t stride, Direction direction)
Carries out transform 1 d.
Definition fft2d.cpp:69
static bool isPowerOfTwo(std::size_t value) noexcept
Tests whether an integer is a non-zero power of two.
Definition fft2d.cpp:25
Direction
Selects forward or inverse Fourier-transform convention.
Definition fft2d.h:45
static void transform(ComplexField2D &field, Direction direction)
Applies an in-place 2D Fourier transform.
Definition fft2d.cpp:35
Declares the complex scalar field container representing two-dimensional wave functions.