Line data Source code
1 : /**********************************************************************/ 2 : /* DO NOT MODIFY THIS HEADER */ 3 : /* MAGPIE - Mesoscale Atomistic Glue Program for Integrated Execution */ 4 : /* */ 5 : /* Copyright 2017 Battelle Energy Alliance, LLC */ 6 : /* ALL RIGHTS RESERVED */ 7 : /**********************************************************************/ 8 : #ifdef FFTW3_ENABLED 9 : 10 : #include "FFTWBufferBase.h" 11 : #include "MyTRIMMesh.h" 12 : #include "MooseTypes.h" 13 : #include "RankTwoTensor.h" 14 : #include "RankThreeTensor.h" 15 : #include "RankFourTensor.h" 16 : 17 : template <typename T> 18 42 : FFTWBufferBase<T>::FFTWBufferBase(const InputParameters & parameters) 19 : : FFTBufferBase<T>(parameters), 20 42 : _perf_plan(this->registerTimedSection("fftw_plan_r2c", 2)), 21 84 : _perf_fft(this->registerTimedSection("fftw_execute", 2)) 22 : { 23 : // create plans 24 : { 25 42 : TIME_SECTION(_perf_plan); 26 : 27 : // Note: These plans do not preserve the input. Additional caching may be required. 28 42 : _forward_plan = 29 42 : fftw_plan_many_dft_r2c(_dim, 30 : _grid.data(), 31 42 : _how_many, 32 : _real_space_data_start, 33 : nullptr, 34 42 : _real_space_data_stride, 35 : 1, 36 42 : reinterpret_cast<double(*)[2]>(_reciprocal_space_data_start), 37 : nullptr, 38 42 : _reciprocal_space_data_stride, 39 : 1, 40 : FFTW_ESTIMATE); 41 : 42 42 : _backward_plan = 43 42 : fftw_plan_many_dft_c2r(_dim, 44 : _grid.data(), 45 42 : _how_many, 46 42 : reinterpret_cast<double(*)[2]>(_reciprocal_space_data_start), 47 : nullptr, 48 42 : _reciprocal_space_data_stride, 49 : 1, 50 : _real_space_data_start, 51 : nullptr, 52 42 : _real_space_data_stride, 53 : 1, 54 : FFTW_ESTIMATE); 55 : } 56 : 57 42 : _scaling = 1.0 / (_real_space_data.size()); 58 42 : } 59 : 60 : template <typename T> 61 84 : FFTWBufferBase<T>::~FFTWBufferBase() 62 : { 63 : // destroy FFTW plans 64 42 : fftw_destroy_plan(_forward_plan); 65 42 : fftw_destroy_plan(_backward_plan); 66 126 : } 67 : 68 : template <typename T> 69 : void 70 93 : FFTWBufferBase<T>::forwardRaw() 71 : { 72 : // execute plan 73 : { 74 93 : TIME_SECTION(_perf_fft); 75 93 : fftw_execute(_forward_plan); 76 : } 77 93 : } 78 : 79 : template <typename T> 80 : void 81 93 : FFTWBufferBase<T>::backwardRaw() 82 : { 83 : // execute plan 84 : { 85 93 : TIME_SECTION(_perf_fft); 86 93 : fftw_execute(_backward_plan); 87 : } 88 93 : } 89 : 90 : // explicit instantiation and registration 91 : #define FFTWBufferInstance(T) \ 92 : template class FFTWBufferBase<T>; \ 93 : using T##FFTWBuffer = FFTWBufferBase<T>; \ 94 : registerMooseObject("MagpieApp", T##FFTWBuffer) 95 : 96 : FFTWBufferInstance(Real); 97 : FFTWBufferInstance(RealVectorValue); 98 : FFTWBufferInstance(RankTwoTensor); 99 : FFTWBufferInstance(RankThreeTensor); 100 : FFTWBufferInstance(RankFourTensor); 101 : 102 : #endif