
[Sponsors] 
November 3, 2011, 04:56 
FFT in OpenFOAM

#1 
Senior Member
Hisham Elsafti
Join Date: Apr 2011
Location: Braunschweig, Germany
Posts: 253
Blog Entries: 10
Rep Power: 10 
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:
00048 forAll(nn, idim) 00049 { 00050 // Check for power of two 00051 unsigned int dimCount = nn[idim]; 00052 if (!dimCount  (dimCount & (dimCount  1))) 00053 { 00054 FatalErrorIn 00055 ( 00056 "fft::transform(complexField&, const labelList&, " 00057 "transformDirection)" 00058 ) << "number of elements in direction " << idim 00059 << " is not a power of 2" << endl 00060 << " Number of elements in each direction = " << nn 00061 << abort(FatalError); 00062 } 00063 } 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 

November 3, 2011, 07:57 

#2 
Senior Member
Hisham Elsafti
Join Date: Apr 2011
Location: Braunschweig, Germany
Posts: 253
Blog Entries: 10
Rep Power: 10 
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?? Last edited by Hisham; November 13, 2011 at 16:28. 

November 13, 2011, 18:13 

#3 
Senior Member
Hisham Elsafti
Join Date: Apr 2011
Location: Braunschweig, Germany
Posts: 253
Blog Entries: 10
Rep Power: 10 
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 

March 15, 2012, 08:47 

#4 
New Member
lishijie
Join Date: Mar 2012
Posts: 4
Rep Power: 7 
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


March 16, 2012, 05:55 

#5 
Senior Member
Hisham Elsafti
Join Date: Apr 2011
Location: Braunschweig, Germany
Posts: 253
Blog Entries: 10
Rep Power: 10 
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 

March 19, 2012, 18:52 

#6 
Senior Member
Kyle Mooney
Join Date: Jul 2009
Location: Amherst, MA USA  San Diego, CA USA
Posts: 321
Rep Power: 11 
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.


March 20, 2012, 06:17 

#8 
New Member
lishijie
Join Date: Mar 2012
Posts: 4
Rep Power: 7 
Oh~ it is so nice of you! I will try to make fft on GPU, thank you so much!!!


July 2, 2012, 13:59 

#9 
Senior Member
Mahdi Hosseinali
Join Date: Apr 2009
Location: NB, Canada
Posts: 271
Rep Power: 11 
Hisham can you tell me how you test openfoam fft? you made a custom solver? or you are approaching classes directly?


July 6, 2012, 06:58 

#10 
Senior Member
Hisham Elsafti
Join Date: Apr 2011
Location: Braunschweig, Germany
Posts: 253
Blog Entries: 10
Rep Power: 10 
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 

July 6, 2012, 12:28 

#11 
Senior Member
Mahdi Hosseinali
Join Date: Apr 2009
Location: NB, Canada
Posts: 271
Rep Power: 11 
I would be grateful if you do that


October 23, 2013, 11:51 

#12 
New Member
subhendu
Join Date: May 2012
Posts: 10
Rep Power: 7 
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. 

October 24, 2013, 01:48 

#13 
Senior Member
Bernhard
Join Date: Sep 2009
Location: Delft
Posts: 790
Rep Power: 15 
You need to write the Fourier coefficients with higher precision. You probably truncate these, which is loss of information.


October 24, 2013, 05:18 

#14  
New Member
subhendu
Join Date: May 2012
Posts: 10
Rep Power: 7 
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 

February 22, 2016, 23:03 

#15 
New Member
Huey
Join Date: Oct 2015
Posts: 2
Rep Power: 0 
Hello Hisham, would you please email me a copy of your fft test solver? I've send you my address through a pm. Thanks~


January 9, 2017, 11:14 
Inlet with turbulence

#16 
New Member
Join Date: May 2016
Posts: 27
Rep Power: 3 
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? 

Tags 
fast fourier transform, fft 
Thread Tools  
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
New OpenFOAM Forum Structure  jola  OpenFOAM  2  October 19, 2011 06:55 
parallel FFT with OpenFoam?  henman  OpenFOAM  0  February 8, 2011 07:24 
Crosscompiling OpenFOAM 1.7.0 on Linux for Windows 32 and 64bits with Mingww64  wyldckat  OpenFOAM Announcements from Other Sources  3  September 8, 2010 06:25 
Modified OpenFOAM Forum Structure and New MailingList  pete  Site News & Announcements  0  June 29, 2009 05:56 
64bitrhel5 OF installation instructions  mirko  OpenFOAM Installation  2  August 12, 2008 18:07 