CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM Programming & Development

FFT in OpenFOAM

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   November 3, 2011, 04:56
Default FFT in OpenFOAM
  #1
Senior Member
 
Hisham's Avatar
 
Hisham El Safti
Join Date: Apr 2011
Location: Braunschweig, Germany
Posts: 247
Blog Entries: 10
Rep Power: 8
Hisham is on a distinguished road
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     }
So can I use that too to do zero padding?

I would appreciate it if the complementary code for using the fft class is shared. Is there any?

I mean zero-padding 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
Hisham is offline   Reply With Quote

Old   November 3, 2011, 07:57
Default
  #2
Senior Member
 
Hisham's Avatar
 
Hisham El Safti
Join Date: Apr 2011
Location: Braunschweig, Germany
Posts: 247
Blog Entries: 10
Rep Power: 8
Hisham is on a distinguished road
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.
Hisham is offline   Reply With Quote

Old   November 13, 2011, 18:13
Default
  #3
Senior Member
 
Hisham's Avatar
 
Hisham El Safti
Join Date: Apr 2011
Location: Braunschweig, Germany
Posts: 247
Blog Entries: 10
Rep Power: 8
Hisham is on a distinguished road
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
Hisham is offline   Reply With Quote

Old   March 15, 2012, 08:47
Default
  #4
New Member
 
lishijie
Join Date: Mar 2012
Posts: 4
Rep Power: 5
lishijie is on a distinguished road
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
lishijie is offline   Reply With Quote

Old   March 16, 2012, 05:55
Default
  #5
Senior Member
 
Hisham's Avatar
 
Hisham El Safti
Join Date: Apr 2011
Location: Braunschweig, Germany
Posts: 247
Blog Entries: 10
Rep Power: 8
Hisham is on a distinguished road
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: Problems with fft
Hisham is offline   Reply With Quote

Old   March 19, 2012, 18:52
Default
  #6
Senior Member
 
kmooney's Avatar
 
Kyle Mooney
Join Date: Jul 2009
Location: Amherst, MA USA - San Diego, CA USA
Posts: 280
Rep Power: 9
kmooney is on a distinguished road
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.
kmooney is offline   Reply With Quote

Old   March 19, 2012, 19:32
Default
  #7
Senior Member
 
Hisham's Avatar
 
Hisham El Safti
Join Date: Apr 2011
Location: Braunschweig, Germany
Posts: 247
Blog Entries: 10
Rep Power: 8
Hisham is on a distinguished road
An update: The dnsFoam solver uses the fft class.

@ kmooney: This is extremely nice of you
Hisham is offline   Reply With Quote

Old   March 20, 2012, 06:17
Default
  #8
New Member
 
lishijie
Join Date: Mar 2012
Posts: 4
Rep Power: 5
lishijie is on a distinguished road
Oh~ it is so nice of you! I will try to make fft on GPU, thank you so much!!!
lishijie is offline   Reply With Quote

Old   July 2, 2012, 13:59
Default
  #9
Senior Member
 
Mahdi Hosseinali
Join Date: Apr 2009
Posts: 124
Rep Power: 8
anishtain4 is on a distinguished road
Hisham can you tell me how you test openfoam fft? you made a custom solver? or you are approaching classes directly?
anishtain4 is offline   Reply With Quote

Old   July 6, 2012, 06:58
Default
  #10
Senior Member
 
Hisham's Avatar
 
Hisham El Safti
Join Date: Apr 2011
Location: Braunschweig, Germany
Posts: 247
Blog Entries: 10
Rep Power: 8
Hisham is on a distinguished road
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
Hisham is offline   Reply With Quote

Old   July 6, 2012, 12:28
Default
  #11
Senior Member
 
Mahdi Hosseinali
Join Date: Apr 2009
Posts: 124
Rep Power: 8
anishtain4 is on a distinguished road
I would be grateful if you do that
anishtain4 is offline   Reply With Quote

Old   October 23, 2013, 11:51
Default
  #12
New Member
 
subhendu
Join Date: May 2012
Posts: 10
Rep Power: 5
raw17 is on a distinguished road
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.
raw17 is offline   Reply With Quote

Old   October 24, 2013, 01:48
Default
  #13
Senior Member
 
Bernhard
Join Date: Sep 2009
Location: Delft
Posts: 790
Rep Power: 12
Bernhard is on a distinguished road
You need to write the Fourier coefficients with higher precision. You probably truncate these, which is loss of information.
Bernhard is offline   Reply With Quote

Old   October 24, 2013, 05:18
Default
  #14
New Member
 
subhendu
Join Date: May 2012
Posts: 10
Rep Power: 5
raw17 is on a distinguished road
Quote:
Originally Posted by Bernhard View Post
You need to write the Fourier coefficients with higher precision. You probably truncate these, which is loss of information.
Hello Bernhard,
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
raw17 is offline   Reply With Quote

Reply

Tags
fast fourier transform, fft

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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
Cross-compiling OpenFOAM 1.7.0 on Linux for Windows 32 and 64bits with Mingw-w64 wyldckat OpenFOAM Announcements from Other Sources 3 September 8, 2010 06:25
Modified OpenFOAM Forum Structure and New Mailing-List pete Site News & Announcements 0 June 29, 2009 05:56
64bitrhel5 OF installation instructions mirko OpenFOAM Installation 2 August 12, 2008 18:07


All times are GMT -4. The time now is 14:06.