36 #define SWAP(a,b) tempr=(a); (a)=(b); (b)=tempr 37 #define TWOPI 6.28318530717959 51 unsigned int dimCount = nn[idim];
52 if (!dimCount || (dimCount & (dimCount - 1)))
55 <<
"number of elements in direction " << idim
56 <<
" is not a power of 2" <<
endl 57 <<
" Number of elements in each direction = " << nn
64 label i1, i2, i3, i2rev, i3rev, ip1, ip2, ip3, ifp1, ifp2;
65 label ibit, k1, k2,
n, nprev, nrem, idim;
67 scalar theta, wi, wpi, wpr, wr, wtemp;
68 scalar*
data =
reinterpret_cast<scalar*
>(field.
begin()) - 1;
73 if (isign == REVERSE_TRANSFORM)
88 for (idim=ndim; idim>=1; idim--)
91 nrem = ntot/(n*nprev);
97 for (i2=1; i2<=ip2; i2+=ip1)
101 for (i1=i2; i1<=i2 + ip1 - 2; i1+=2)
103 for (i3=i1; i3<=ip3; i3+=ip2)
105 i3rev = i2rev + i3 - i2;
106 SWAP(data[i3], data[i3rev]);
107 SWAP(data[i3 + 1], data[i3rev + 1]);
113 while (ibit >= ip1 && i2rev > ibit)
127 theta = isign*
TWOPI/(ifp2/ip1);
128 wtemp =
sin(0.5*theta);
129 wpr = -2.0*wtemp*wtemp;
134 for (i3 = 1; i3 <= ifp1; i3 += ip1)
136 for (i1 = i3; i1 <= i3 + ip1 - 2; i1 += 2)
138 for (i2 = i1; i2 <= ip3; i2 += ifp2)
142 tempr = scalar(wr*data[k2]) - scalar(wi*data[k2 + 1]);
143 tempi = scalar(wr*data[k2 + 1]) + scalar(wi*data[k2]);
144 data[k2] = data[k1] - tempr;
145 data[k2 + 1] = data[k1 + 1] - tempi;
147 data[k1 + 1] += tempi;
151 wr = (wtemp = wr)*wpr - wi*wpi + wr;
152 wi = wi*wpr + wtemp*wpi + wi;
162 if (isign == FORWARD_TRANSFORM)
170 scalar recRootN = 1.0/
sqrt(scalar(ntot));
174 field[i] *= recRootN;
237 forwardTransform(tfield().
component(cmpt), nn)
243 return tfftVectorField;
266 reverseTransform(tfield().
component(cmpt), nn)
272 return tifftVectorField;
void fftRenumber(List< complex > &data, const labelList &nn)
#define forAll(list, i)
Loop across all elements in list.
void clear() const
If object pointer points to valid object:
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Field< complex > complexField
Specialisation of Field<T> for complex.
T & ref() const
Return non-const reference or generate a fatal error.
void size(const label)
Override size to be inconsistent with allocated storage.
Multi-dimensional renumbering used in the Numerical Recipes fft routine.
dimensionedScalar sqrt(const dimensionedScalar &ds)
Ostream & endl(Ostream &os)
Add newline and flush stream.
static tmp< complexField > reverseTransform(const tmp< complexField > &field, const labelList &nn)
void replace(const direction, const UList< cmptType > &)
Replace a component field of the field.
static tmp< complexField > forwardTransform(const tmp< complexField > &field, const labelList &nn)
static const direction nComponents
Number of components in this vector space.
Pre-declare SubField and related Field type.
iterator begin()
Return an iterator to begin traversing the UList.
errorManip< error > abort(error &err)
dimensionedScalar sin(const dimensionedScalar &ds)
static void transform(complexField &field, const labelList &nn, transformDirection fftDirection)
Database for solution and other reduced data.
A class for managing temporary objects.
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
dimensionSet transform(const dimensionSet &)