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 : 9 : #pragma once 10 : 11 : #include "ComplexTypes.h" 12 : 13 : // helper template to select the corresponding scalar type 14 : template <typename T> 15 : struct FFTScalarType 16 : { 17 : using type = Real; 18 : }; 19 : 20 : template <typename T> 21 : struct FFTScalarType<std::complex<T>> 22 : { 23 : using type = Complex; 24 : }; 25 : 26 : /** 27 : * Helper class to hold the reciprocal space data 28 : */ 29 : template <typename T> 30 9 : class FFTData 31 : { 32 : using ScalarT = typename FFTScalarType<T>::type; 33 : 34 : public: 35 84 : FFTData(std::size_t size = 0) { resize(size); } 36 126 : void resize(std::size_t size) { _buffer.resize(size); } 37 : 38 : ///@{ data access by index 39 0 : const T & operator[](std::size_t i) const { return _buffer[i]; } 40 0 : T & operator[](std::size_t i) { return _buffer[i]; } 41 : ///@} 42 : 43 : ///@{ convenience math operators 44 : FFTData<T> & operator+=(FFTData<T> const & rhs); 45 : FFTData<T> & operator-=(FFTData<T> const & rhs); 46 : FFTData<T> & operator*=(FFTData<ScalarT> const & rhs); 47 : FFTData<T> & operator/=(FFTData<ScalarT> const & rhs); 48 : FFTData<T> & operator*=(Real rhs); 49 : FFTData<T> & operator/=(Real rhs); 50 : FFTData<T> & operator=(FFTData<T> const & rhs); 51 : FFTData<T> & operator=(const T & rhs); 52 : ///@} 53 : 54 : /// Templated product of FFTData 55 : template <typename T1, typename T2> 56 : void setToProductRealSpace(const FFTData<T1> & m1, const FFTData<T2> & m2); 57 : 58 : // Apply a lambda to the reciprocal space of 59 : template <typename T1> 60 : void applyLambdaReciprocalSpace(T1 lambda); 61 : 62 : /// return the number of proper grid cells 63 0 : std::size_t size() const { return _buffer.size(); } 64 : 65 : /// get the addres of the first data element of the ith object in the buffer 66 : void * start(std::size_t i); 67 : 68 : /// get the number of transforms required for type T 69 : std::size_t howMany() const; 70 : 71 : protected: 72 : /// FFT data buffer 73 : std::vector<T> _buffer; 74 : }; 75 : 76 : template <typename T> 77 : template <typename T1> 78 : void 79 15 : FFTData<T>::applyLambdaReciprocalSpace(T1 lambda) 80 : { 81 261135 : for (size_t index = 0; index < _buffer.size(); index++) 82 261120 : _buffer[index] = lambda(index); 83 15 : }