FFT in OpenFOAM
Dear Foamers,
I have been trying to use the fft class. I have hard time understanding how the code checks for a 2^n number of samples. The code uses (I think) the bitwise "and" operator: from fft.C Code:
I would appreciate it if the complementary code for using the fft class is shared. Is there any? I mean zeropadding or whatever trick to prepare data for FFT (i.e. the 2^n). Also, it would be nice to look at post fft code. Best regards, Hisham 
I got it!
Regards Edit: Comparing results from FOAM's fft class with Octave, there is something wrong. The results are not even close and Octave numbers look logical. Has anyone experienced problems with fft output?? 
Hi Foamers,
After using the fft class, it does not give the same results as Matlab or Octave. As a simple example I fft the following: [0.1000 2.0000 0.1000 5.0000 6.0000 7.0000 8.0000 9.0000 5.0000 3.0000 5.0000 7.0000 5.0000 3.0000 5.0000 4.0000 8.0000 ] The results from Octave and Matlab are identical. OF is not near the results of either. To do the fft, I make all imaginary components zeros. I pad zeros until 2^n. Then I make the call with the label list size = 1 and the only label set to the number of elements = 2^n. Doing an ifft of the results from OF with the OF class, I get the original. Comparing ifft in OF with external sources. OF results are not good even when I construct the signal from cosine components. I have some doubts about fft in OF. Can someone please help??? Best regards, Hisham Matlab magnitude OF's fft class magnitude 
Hi,i am a student,i want to make the fft lib faster, but i don't know how can i run a program with fft lib, could you tell me which case will use fft lib?thanks

Hi lishijie
Unfortunately, I believe that the fft class in OpenFOAM is bugged because it gives different results compared to Matlab and Octave as I illustrated in my previous post. To know how to use the class, please read the numerical recipes book (the fft part very clear indeed). Take care that the fft is the full implementation "for a complex data set". Another option is to link an external fft class (e.g. fftw or fftw++). I have not done that because I am now involved with something else. Nevertheless, there are posts here about the topic. Not many (any afaik) solvers use the fft class. Good luck and please keep me updated with your progress in this area Best regards Hisham Edit: this post should be useful: http://www.cfdonline.com/Forums/ope...blemsfft.html 
If your interested in fast, accurate FFTs, the FFTW lib is probably the best choice. I have some simple C code that loads and runs fftw if you would like to see some syntax. Just send me a PM with your email address and I can send it over if you want. I'm not sure if it would be difficult or not to call it from within foam.

An update: The dnsFoam solver uses the fft class.
@ kmooney: This is extremely nice of you :) 
Oh~ it is so nice of you! I will try to make fft on GPU, thank you so much!!!

Hisham can you tell me how you test openfoam fft? you made a custom solver? or you are approaching classes directly?

Hi anishtain4
Sorry for the late reply .... Yes I made a test solver (say fftFoam) and tested some numbers on an fft object. I can email it to you if you would like Thanks Hisham 
I would be grateful if you do that

Hello,
I am tring to do the fft of channel flow velocity data in Openfoam. I use fftW library to perform that. This is the procedure 1. I do the fourier tranform of data. 2. To check whether its right or not I perform the inverse fft and cross check with the original velocity field of Openfoam. These two fields are not mathcing after 4th significan digit. 3. When I do the same for another code that is spectral I get very high accuracy with FFTw. Can any one explain this to me. I am sure that my fftW subroutine is good. Then why is that fft and ifft velocity field of Openfoam does not match after 4th significant digit. 
You need to write the Fourier coefficients with higher precision. You probably truncate these, which is loss of information.

Quote:
Thanks for your reply. I use write precision 16 to write my velocity field in Openfoam. In my fortran code I read that file and just perform fft and ifft and write velocity field again without writing the fortier coefficients in a data file. This is a issue for me because I have to use newton method on the velocity field in fourier space and whatever correction I will do to my solution will be lost when I will perform ifft to write the data for Openfoam. Thanks 
Quote:

Inlet with turbulence
Dear Hisham,
I'm trying to simulate the bypass transition and I have to use the fft to get disturbances at the inlet of the computational domain so if your solver will be suitable for me to get these disturbances using the Orr Sommerfield and Squire operator method? By the way I'm new in Fourier modes. Or do you recommend any other method to get these disturbances? 
All times are GMT 4. The time now is 21:46. 