diff options
author | 2019-04-18 12:00:44 -0700 | |
---|---|---|
committer | 2019-04-23 12:43:53 -0700 | |
commit | fe5d51efb7661d701fe90630ae13787ab2e0d900 (patch) | |
tree | 574d0787478e61663d16783476ff73686061e06e /Source/FieldSolver/SpectralSolver/SpectralData.cpp | |
parent | 4af49e9d6da63c4791877f334e6db09eefdf6db4 (diff) | |
download | WarpX-fe5d51efb7661d701fe90630ae13787ab2e0d900.tar.gz WarpX-fe5d51efb7661d701fe90630ae13787ab2e0d900.tar.zst WarpX-fe5d51efb7661d701fe90630ae13787ab2e0d900.zip |
Add backward transform
Diffstat (limited to 'Source/FieldSolver/SpectralSolver/SpectralData.cpp')
-rw-r--r-- | Source/FieldSolver/SpectralSolver/SpectralData.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/Source/FieldSolver/SpectralSolver/SpectralData.cpp b/Source/FieldSolver/SpectralSolver/SpectralData.cpp index 75863c99a..0a0b8527e 100644 --- a/Source/FieldSolver/SpectralSolver/SpectralData.cpp +++ b/Source/FieldSolver/SpectralSolver/SpectralData.cpp @@ -115,6 +115,54 @@ SpectralData::ForwardTransform( const MultiFab& mf, const int field_index ) } +/* TODO: Documentation + */ +void +SpectralData::BackwardTransform( MultiFab& mf, const int field_index ) +{ + // Loop over boxes + for ( MFIter mfi(mf); mfi.isValid(); ++mfi ){ + + // Copy the appropriate field (specified by the input argument field_index) + // to the spectral-space field `tmpSpectralField` + { + SpectralField& field = getSpectralField( field_index ); + Array4<const Complex> field_arr = field[mfi].array(); + Array4<Complex> tmp_arr = tmpSpectralField[mfi].array(); + const Box spectralspace_bx = tmpSpectralField[mfi].box(); + ParallelFor( spectralspace_bx, + [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + tmp_arr(i,j,k) = field_arr(i,j,k); + }); + } + + // Perform Fourier transform from `tmpSpectralField` to `tmpRealField` +#ifdef AMREX_USE_GPU + // Add cuFFT-specific code ; make sure that this is done on the same + // GPU stream as the above copy +#else + fftw_execute( backward_plan[mfi] ); +#endif + + // Copy the temporary field `tmpRealField` to the real-space field `mf` + // The copy does *not* fill the *last* point of `mf` + // in any direction that has *nodal* index type (but this point is + // in the guard cells and will be filled by guard cell exchange) + { + Box bx = mf[mfi].box(); + const Box realspace_bx = bx.enclosedCells(); // discards last point in each nodal direction + AMREX_ALWAYS_ASSERT( realspace_bx == tmpRealField[mfi].box() ); + Array4<Real> mf_arr = mf[mfi].array(); + Array4<const Complex> tmp_arr = tmpRealField[mfi].array(); + ParallelFor( realspace_bx, + [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { + mf_arr(i,j,k) = tmp_arr(i,j,k); + }); + } + } +} + + SpectralField& SpectralData::getSpectralField( const int field_index ) { |