From 49ed40b5610705c7f587fdad7c33349df4f7a878 Mon Sep 17 00:00:00 2001 From: Edoardo Zoni <59625522+EZoni@users.noreply.github.com> Date: Wed, 7 Oct 2020 09:22:47 -0700 Subject: Do not store first Fornberg coefficient (#1419) --- .../FieldSolver/SpectralSolver/SpectralKSpace.cpp | 56 ++++++++++------------ 1 file changed, 26 insertions(+), 30 deletions(-) (limited to 'Source/FieldSolver/SpectralSolver/SpectralKSpace.cpp') diff --git a/Source/FieldSolver/SpectralSolver/SpectralKSpace.cpp b/Source/FieldSolver/SpectralSolver/SpectralKSpace.cpp index d907152dc..8e296531e 100644 --- a/Source/FieldSolver/SpectralSolver/SpectralKSpace.cpp +++ b/Source/FieldSolver/SpectralSolver/SpectralKSpace.cpp @@ -202,7 +202,7 @@ SpectralKSpace::getModifiedKComponent( const DistributionMapping& dm, } else { // Compute real-space stencil coefficients - Vector h_stencil_coef = getFonbergStencilCoefficients(n_order, nodal); + Vector h_stencil_coef = getFornbergStencilCoefficients(n_order, nodal); DeviceVector d_stencil_coef(h_stencil_coef.size()); Gpu::copyAsync(Gpu::hostToDevice, h_stencil_coef.begin(), h_stencil_coef.end(), d_stencil_coef.begin()); @@ -227,13 +227,13 @@ SpectralKSpace::getModifiedKComponent( const DistributionMapping& dm, amrex::ParallelFor(N, [=] AMREX_GPU_DEVICE (int i) noexcept { p_modified_k[i] = 0; - for (int n=1; n -getFonbergStencilCoefficients( const int n_order, const bool nodal ) +getFornbergStencilCoefficients(const int n_order, const bool nodal) { - AMREX_ALWAYS_ASSERT_WITH_MESSAGE( n_order%2 == 0, - "n_order should be even."); - const int m = n_order/2; + AMREX_ALWAYS_ASSERT_WITH_MESSAGE(n_order % 2 == 0, "n_order must be even"); + + const int m = n_order / 2; Vector coefs; - coefs.resize( m+1 ); + coefs.resize(m); - // Note: there are closed-form formula for these coefficients, - // but they result in an overflow when evaluated numerically. - // One way to avoid the overflow is to calculate the coefficients - // by recurrence. + // There are closed-form formula for these coefficients, but they result in + // an overflow when evaluated numerically. One way to avoid the overflow is + // to calculate the coefficients by recurrence. - // Coefficients for nodal (a.k.a. centered) finite-difference + // Coefficients for nodal (that is, centered) finite-difference approximation if (nodal == true) { - coefs[0] = -2.; // First coefficient - for (int n=1; n