From 76f3c0cb1ba717de8fa571a06fbb0267b4f83237 Mon Sep 17 00:00:00 2001 From: Remi Lehe Date: Mon, 22 Apr 2019 09:56:04 -0700 Subject: Add calculation of Fonberg coefficients --- .../FieldSolver/SpectralSolver/SpectralKSpace.cpp | 76 +++++++++++++++------- 1 file changed, 54 insertions(+), 22 deletions(-) (limited to 'Source/FieldSolver/SpectralSolver/SpectralKSpace.cpp') diff --git a/Source/FieldSolver/SpectralSolver/SpectralKSpace.cpp b/Source/FieldSolver/SpectralSolver/SpectralKSpace.cpp index 90c20b01d..77aa7342f 100644 --- a/Source/FieldSolver/SpectralSolver/SpectralKSpace.cpp +++ b/Source/FieldSolver/SpectralSolver/SpectralKSpace.cpp @@ -66,9 +66,38 @@ SpectralKSpace::getKComponent( const DistributionMapping& dm, const int i_dim ) return k_comp; } +SpectralShiftFactor +SpectralKSpace::getSpectralShiftFactor( + const DistributionMapping& dm, const int i_dim, const int shift_type ) const +{ + // Initialize an empty ManagedVector in each box + SpectralShiftFactor shift_factor = SpectralShiftFactor( spectralspace_ba, dm ); + // Loop over boxes + for ( MFIter mfi(spectralspace_ba, dm); mfi.isValid(); ++mfi ){ + const ManagedVector& k = k_vec[i_dim][mfi]; + ManagedVector& shift = shift_factor[mfi]; + + // Allocate shift coefficients + shift.resize( k.size() ); + + // Fill the shift coefficients + Real sign = 0; + switch (shift_type){ + case ShiftType::CenteredToNodal: sign = -1.; break; + case ShiftType::NodalToCentered: sign = 1.; + } + constexpr Complex I{0,1}; + for (int i=0; i +getFonbergStencilCoefficients( const int n_order, const bool nodal ) { - // Initialize an empty ManagedVector in each box - SpectralShiftFactor shift_factor = SpectralShiftFactor( spectralspace_ba, dm ); - // Loop over boxes - for ( MFIter mfi(spectralspace_ba, dm); mfi.isValid(); ++mfi ){ - const ManagedVector& k = k_vec[i_dim][mfi]; - ManagedVector& shift = shift_factor[mfi]; + AMREX_ALWAYS_ASSERT_WITH_MESSAGE( n_order%2 == 0, "n_order should be even."); + const int m = n_order/2; + Array stencil_coef; + stencil_coef.resize( m+1 ); - // Allocate shift coefficients - shift.resize( k.size() ); - - // Fill the shift coefficients - Real sign = 0; - switch (shift_type){ - case ShiftType::CenteredToNodal: sign = -1.; break; - case ShiftType::NodalToCentered: sign = 1.; + // Coefficients for nodal (a.k.a. centered) finite-difference + if (nodal == true) { + stencil_coef[0] = -2.; // First coefficient + for (int n=1; n