Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify fft full normalization #663

Merged
merged 8 commits into from
Oct 15, 2024
Merged
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions include/ddc/kernels/fft.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,18 @@ void rescale(
});
}

template <class DDim>
Real forward_full_norm_coef(DiscreteDomain<DDim> const& ddom) noexcept
tpadioleau marked this conversation as resolved.
Show resolved Hide resolved
yasahi-hpc marked this conversation as resolved.
Show resolved Hide resolved
{
return rlength(ddom) / Kokkos::sqrt(2 * Kokkos::numbers::pi) / (ddom.extents() - 1).value();
}

template <class DDim>
Real backward_full_norm_coef(DiscreteDomain<DDim> const& ddom) noexcept
{
return 1 / (forward_full_norm_coef(ddom) * ddom.extents().value());
}

/// @brief Core internal function to perform the FFT.
template <
typename Tin,
Expand Down Expand Up @@ -257,20 +269,11 @@ void impl(
if (kwargs.normalization == ddc::FFT_Normalization::FULL) {
real_type_t<Tout> norm_coef;
if (kwargs.direction == ddc::FFT_Direction::FORWARD) {
norm_coef
= (((coordinate(ddc::select<DDimIn>(in.domain()).back())
- coordinate(ddc::select<DDimIn>(in.domain()).front()))
/ (ddc::get<DDimIn>(in.domain().extents()) - 1)
/ Kokkos::sqrt(2 * Kokkos::numbers::pi))
* ...);
DiscreteDomain<DDimIn...> const ddom_in = in.domain();
norm_coef = (forward_full_norm_coef(DiscreteDomain<DDimIn>(ddom_in)) * ...);
} else {
norm_coef
= ((Kokkos::sqrt(2 * Kokkos::numbers::pi)
/ (coordinate(ddc::select<DDimOut>(out.domain()).back())
- coordinate(ddc::select<DDimOut>(out.domain()).front()))
* (ddc::get<DDimOut>(out.domain().extents()) - 1)
/ ddc::get<DDimOut>(out.domain().extents()))
* ...);
DiscreteDomain<DDimOut...> const ddom_out = out.domain();
norm_coef = (backward_full_norm_coef(DiscreteDomain<DDimOut>(ddom_out)) * ...);
}

rescale(exec_space, out, norm_coef);
Expand Down